Compare commits
4 Commits
exec_path
...
reschange.
Author | SHA1 | Date | |
---|---|---|---|
8825220b2e | |||
a0e2160437 | |||
391f2de3fa | |||
762ed2755a |
@ -1,26 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2019 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.view;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
oneway interface IDisplayFoldListener
|
|
||||||
{
|
|
||||||
/** Called when the foldedness of a display changes */
|
|
||||||
void onDisplayFoldChanged(int displayId, boolean folded);
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
/* //device/java/android/android/hardware/ISensorListener.aidl
|
|
||||||
**
|
|
||||||
** Copyright 2008, The Android Open Source Project
|
|
||||||
**
|
|
||||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
** you may not use this file except in compliance with the License.
|
|
||||||
** You may obtain a copy of the License at
|
|
||||||
**
|
|
||||||
** http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
**
|
|
||||||
** Unless required by applicable law or agreed to in writing, software
|
|
||||||
** distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
** See the License for the specific language governing permissions and
|
|
||||||
** limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.view;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
interface IRotationWatcher {
|
|
||||||
oneway void onRotationChanged(int rotation);
|
|
||||||
}
|
|
@ -2,6 +2,7 @@ package com.genymobile.scrcpy;
|
|||||||
|
|
||||||
import com.genymobile.scrcpy.wrappers.ClipboardManager;
|
import com.genymobile.scrcpy.wrappers.ClipboardManager;
|
||||||
import com.genymobile.scrcpy.wrappers.DisplayControl;
|
import com.genymobile.scrcpy.wrappers.DisplayControl;
|
||||||
|
import com.genymobile.scrcpy.wrappers.DisplayManager;
|
||||||
import com.genymobile.scrcpy.wrappers.InputManager;
|
import com.genymobile.scrcpy.wrappers.InputManager;
|
||||||
import com.genymobile.scrcpy.wrappers.ServiceManager;
|
import com.genymobile.scrcpy.wrappers.ServiceManager;
|
||||||
import com.genymobile.scrcpy.wrappers.SurfaceControl;
|
import com.genymobile.scrcpy.wrappers.SurfaceControl;
|
||||||
@ -10,10 +11,10 @@ import com.genymobile.scrcpy.wrappers.WindowManager;
|
|||||||
import android.content.IOnPrimaryClipChangedListener;
|
import android.content.IOnPrimaryClipChangedListener;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.HandlerThread;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.view.IDisplayFoldListener;
|
|
||||||
import android.view.IRotationWatcher;
|
|
||||||
import android.view.InputDevice;
|
import android.view.InputDevice;
|
||||||
import android.view.InputEvent;
|
import android.view.InputEvent;
|
||||||
import android.view.KeyCharacterMap;
|
import android.view.KeyCharacterMap;
|
||||||
@ -33,26 +34,21 @@ public final class Device {
|
|||||||
public static final int LOCK_VIDEO_ORIENTATION_UNLOCKED = -1;
|
public static final int LOCK_VIDEO_ORIENTATION_UNLOCKED = -1;
|
||||||
public static final int LOCK_VIDEO_ORIENTATION_INITIAL = -2;
|
public static final int LOCK_VIDEO_ORIENTATION_INITIAL = -2;
|
||||||
|
|
||||||
public interface RotationListener {
|
public interface DisplayChangeListener {
|
||||||
void onRotationChanged(int rotation);
|
void onDisplayChanged();
|
||||||
}
|
|
||||||
|
|
||||||
public interface FoldListener {
|
|
||||||
void onFoldChanged(int displayId, boolean folded);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ClipboardListener {
|
public interface ClipboardListener {
|
||||||
void onClipboardTextChanged(String text);
|
void onClipboardTextChanged(String text);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Size deviceSize;
|
|
||||||
private final Rect crop;
|
private final Rect crop;
|
||||||
private int maxSize;
|
private int maxSize;
|
||||||
private final int lockVideoOrientation;
|
private final int lockVideoOrientation;
|
||||||
|
|
||||||
|
private Size deviceSize;
|
||||||
private ScreenInfo screenInfo;
|
private ScreenInfo screenInfo;
|
||||||
private RotationListener rotationListener;
|
private DisplayChangeListener displayChangeListener;
|
||||||
private FoldListener foldListener;
|
|
||||||
private ClipboardListener clipboardListener;
|
private ClipboardListener clipboardListener;
|
||||||
private final AtomicBoolean isSettingClipboard = new AtomicBoolean();
|
private final AtomicBoolean isSettingClipboard = new AtomicBoolean();
|
||||||
|
|
||||||
@ -86,46 +82,26 @@ public final class Device {
|
|||||||
screenInfo = ScreenInfo.computeScreenInfo(displayInfo.getRotation(), deviceSize, crop, maxSize, lockVideoOrientation);
|
screenInfo = ScreenInfo.computeScreenInfo(displayInfo.getRotation(), deviceSize, crop, maxSize, lockVideoOrientation);
|
||||||
layerStack = displayInfo.getLayerStack();
|
layerStack = displayInfo.getLayerStack();
|
||||||
|
|
||||||
ServiceManager.getWindowManager().registerRotationWatcher(new IRotationWatcher.Stub() {
|
HandlerThread displayListenerThread = new HandlerThread("DisplayListenerThread");
|
||||||
@Override
|
displayListenerThread.start();
|
||||||
public void onRotationChanged(int rotation) {
|
|
||||||
synchronized (Device.this) {
|
|
||||||
screenInfo = screenInfo.withDeviceRotation(rotation);
|
|
||||||
|
|
||||||
// notify
|
Handler displayListenerHandler = new Handler(displayListenerThread.getLooper());
|
||||||
if (rotationListener != null) {
|
ServiceManager.getDisplayManager().registerDisplayListener(new DisplayManager.DisplayListener() {
|
||||||
rotationListener.onRotationChanged(rotation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, displayId);
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
||||||
ServiceManager.getWindowManager().registerDisplayFoldListener(new IDisplayFoldListener.Stub() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisplayFoldChanged(int displayId, boolean folded) {
|
public void onDisplayChanged(int displayId) {
|
||||||
if (Device.this.displayId != displayId) {
|
if (Device.this.displayId != displayId) {
|
||||||
// Ignore events related to other display ids
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (Device.this) {
|
|
||||||
DisplayInfo displayInfo = ServiceManager.getDisplayManager().getDisplayInfo(displayId);
|
DisplayInfo displayInfo = ServiceManager.getDisplayManager().getDisplayInfo(displayId);
|
||||||
if (displayInfo == null) {
|
deviceSize = displayInfo.getSize();
|
||||||
Ln.e("Display " + displayId + " not found\n" + LogUtils.buildDisplayListMessage());
|
screenInfo = ScreenInfo.computeScreenInfo(displayInfo.getRotation(), deviceSize, crop, maxSize, lockVideoOrientation);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
screenInfo = ScreenInfo.computeScreenInfo(displayInfo.getRotation(), displayInfo.getSize(), options.getCrop(),
|
if (displayChangeListener != null) {
|
||||||
options.getMaxSize(), options.getLockVideoOrientation());
|
displayChangeListener.onDisplayChanged();
|
||||||
// notify
|
|
||||||
if (foldListener != null) {
|
|
||||||
foldListener.onFoldChanged(displayId, folded);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}, displayListenerHandler);
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.getControl() && options.getClipboardAutosync()) {
|
if (options.getControl() && options.getClipboardAutosync()) {
|
||||||
// If control and autosync are enabled, synchronize Android clipboard to the computer automatically
|
// If control and autosync are enabled, synchronize Android clipboard to the computer automatically
|
||||||
@ -254,12 +230,8 @@ public final class Device {
|
|||||||
return ServiceManager.getPowerManager().isScreenOn();
|
return ServiceManager.getPowerManager().isScreenOn();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void setRotationListener(RotationListener rotationListener) {
|
public synchronized void setDisplayChangeListener(DisplayChangeListener displayChangeListener) {
|
||||||
this.rotationListener = rotationListener;
|
this.displayChangeListener = displayChangeListener;
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void setFoldListener(FoldListener foldlistener) {
|
|
||||||
this.foldListener = foldlistener;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void setClipboardListener(ClipboardListener clipboardListener) {
|
public synchronized void setClipboardListener(ClipboardListener clipboardListener) {
|
||||||
|
@ -7,7 +7,7 @@ import android.os.Build;
|
|||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
|
|
||||||
public class ScreenCapture extends SurfaceCapture implements Device.RotationListener, Device.FoldListener {
|
public class ScreenCapture extends SurfaceCapture implements Device.DisplayChangeListener {
|
||||||
|
|
||||||
private final Device device;
|
private final Device device;
|
||||||
private IBinder display;
|
private IBinder display;
|
||||||
@ -18,8 +18,7 @@ public class ScreenCapture extends SurfaceCapture implements Device.RotationList
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
device.setRotationListener(this);
|
device.setDisplayChangeListener(this);
|
||||||
device.setFoldListener(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -41,8 +40,7 @@ public class ScreenCapture extends SurfaceCapture implements Device.RotationList
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void release() {
|
public void release() {
|
||||||
device.setRotationListener(null);
|
device.setDisplayChangeListener(null);
|
||||||
device.setFoldListener(null);
|
|
||||||
if (display != null) {
|
if (display != null) {
|
||||||
SurfaceControl.destroyDisplay(display);
|
SurfaceControl.destroyDisplay(display);
|
||||||
}
|
}
|
||||||
@ -60,12 +58,7 @@ public class ScreenCapture extends SurfaceCapture implements Device.RotationList
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFoldChanged(int displayId, boolean folded) {
|
public void onDisplayChanged() {
|
||||||
requestReset();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRotationChanged(int rotation) {
|
|
||||||
requestReset();
|
requestReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,13 +5,20 @@ import com.genymobile.scrcpy.DisplayInfo;
|
|||||||
import com.genymobile.scrcpy.Ln;
|
import com.genymobile.scrcpy.Ln;
|
||||||
import com.genymobile.scrcpy.Size;
|
import com.genymobile.scrcpy.Size;
|
||||||
|
|
||||||
|
import android.os.Build;
|
||||||
|
import android.os.Handler;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public final class DisplayManager {
|
public final class DisplayManager {
|
||||||
|
|
||||||
|
// Constant copied from AOSP framework_base: core/java/android/hardware/display/DisplayManager.java
|
||||||
|
private static final long EVENT_FLAG_DISPLAY_CHANGED = 1L << 2;
|
||||||
|
|
||||||
private final Object manager; // instance of hidden class android.hardware.display.DisplayManagerGlobal
|
private final Object manager; // instance of hidden class android.hardware.display.DisplayManagerGlobal
|
||||||
|
|
||||||
public DisplayManager(Object manager) {
|
public DisplayManager(Object manager) {
|
||||||
@ -94,4 +101,47 @@ public final class DisplayManager {
|
|||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void registerDisplayListener(DisplayListener listener, Handler handler) {
|
||||||
|
try {
|
||||||
|
Class<?> displayListenerClass = Class.forName("android.hardware.display.DisplayManager$DisplayListener");
|
||||||
|
Object displayListenerProxy = Proxy.newProxyInstance(ClassLoader.getSystemClassLoader(),
|
||||||
|
new Class[]{displayListenerClass},
|
||||||
|
(proxy, method, args) -> {
|
||||||
|
if ("onDisplayChanged".equals(method.getName())) {
|
||||||
|
listener.onDisplayChanged((int) args[0]);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
||||||
|
try {
|
||||||
|
manager.getClass()
|
||||||
|
.getMethod("registerDisplayListener", displayListenerClass, Handler.class, long.class)
|
||||||
|
.invoke(manager, displayListenerProxy, handler, EVENT_FLAG_DISPLAY_CHANGED);
|
||||||
|
return;
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
// fall-through
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
manager.getClass()
|
||||||
|
.getMethod("registerDisplayListener", displayListenerClass, Handler.class)
|
||||||
|
.invoke(manager, displayListenerProxy, handler);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Screen size won't be updated, not a fatal error
|
||||||
|
Ln.e("Could not register display listener", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Partially copied from AOSP framework_base: core/java/android/hardware/display/DisplayManager.java
|
||||||
|
public interface DisplayListener {
|
||||||
|
/**
|
||||||
|
* Called whenever the properties of a logical {@link android.view.Display},
|
||||||
|
* such as size and density, have changed.
|
||||||
|
*
|
||||||
|
* @param displayId The id of the logical display that changed.
|
||||||
|
*/
|
||||||
|
void onDisplayChanged(int displayId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,7 @@ package com.genymobile.scrcpy.wrappers;
|
|||||||
|
|
||||||
import com.genymobile.scrcpy.Ln;
|
import com.genymobile.scrcpy.Ln;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.os.IInterface;
|
import android.os.IInterface;
|
||||||
import android.view.IDisplayFoldListener;
|
|
||||||
import android.view.IRotationWatcher;
|
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@ -94,30 +91,4 @@ public final class WindowManager {
|
|||||||
Ln.e("Could not invoke method", e);
|
Ln.e("Could not invoke method", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerRotationWatcher(IRotationWatcher rotationWatcher, int displayId) {
|
|
||||||
try {
|
|
||||||
Class<?> cls = manager.getClass();
|
|
||||||
try {
|
|
||||||
// display parameter added since this commit:
|
|
||||||
// https://android.googlesource.com/platform/frameworks/base/+/35fa3c26adcb5f6577849fd0df5228b1f67cf2c6%5E%21/#F1
|
|
||||||
cls.getMethod("watchRotation", IRotationWatcher.class, int.class).invoke(manager, rotationWatcher, displayId);
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
// old version
|
|
||||||
cls.getMethod("watchRotation", IRotationWatcher.class).invoke(manager, rotationWatcher);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
Ln.e("Could not register rotation watcher", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@TargetApi(29)
|
|
||||||
public void registerDisplayFoldListener(IDisplayFoldListener foldListener) {
|
|
||||||
try {
|
|
||||||
Class<?> cls = manager.getClass();
|
|
||||||
cls.getMethod("registerDisplayFoldListener", IDisplayFoldListener.class).invoke(manager, foldListener);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Ln.e("Could not register display fold listener", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user