You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
scrcpy/server/src/com/genymobile/scrcpy/Device.java

75 lines
2.3 KiB
Java

package com.genymobile.scrcpy;
import android.os.Build;
import android.os.RemoteException;
import android.view.IRotationWatcher;
import com.genymobile.scrcpy.wrappers.InputManager;
import com.genymobile.scrcpy.wrappers.ServiceManager;
public class Device {
public interface RotationListener {
void onRotationChanged(int rotation);
}
private final ServiceManager serviceManager = new ServiceManager();
private ScreenInfo screenInfo;
private RotationListener rotationListener;
public Device() {
screenInfo = readScreenInfo();
registerRotationWatcher(new IRotationWatcher.Stub() {
@Override
public void onRotationChanged(int rotation) throws RemoteException {
synchronized (Device.this) {
// update screenInfo cache
screenInfo = screenInfo.withRotation(rotation);
// notify
if (rotationListener != null) {
rotationListener.onRotationChanged(rotation);
}
}
}
});
}
public synchronized ScreenInfo getScreenInfo() {
if (screenInfo == null) {
screenInfo = readScreenInfo();
}
return screenInfo;
}
public Point getPhysicalPoint(Position position) {
ScreenInfo screenInfo = getScreenInfo();
int deviceWidth = screenInfo.getLogicalWidth();
int deviceHeight = screenInfo.getLogicalHeight();
int scaledX = position.getX() * deviceWidth / position.getScreenWidth();
int scaledY = position.getY() * deviceHeight / position.getScreenHeight();
return new Point(scaledX, scaledY);
}
private ScreenInfo readScreenInfo() {
return serviceManager.getDisplayManager().getScreenInfo();
}
public static String getDeviceName() {
return Build.MODEL;
}
public InputManager getInputManager() {
return serviceManager.getInputManager();
}
public void registerRotationWatcher(IRotationWatcher rotationWatcher) {
serviceManager.getWindowManager().registerRotationWatcher(rotationWatcher);
}
public synchronized void setRotationListener(RotationListener rotationListener) {
this.rotationListener = rotationListener;
}
}