Loading core/java/android/hardware/input/IInputManager.aidl +3 −1 Original line number Diff line number Diff line Loading @@ -315,5 +315,7 @@ interface IInputManager { void setMouseScalingEnabled(boolean enabled, int displayId); PointF getCursorPosition(int displayId); PointF getCursorPositionInPhysicalDisplay(int displayId); PointF getCursorPositionInLogicalDisplay(int displayId); } core/java/android/hardware/input/IVirtualInputDevice.aidl +9 −3 Original line number Diff line number Diff line Loading @@ -98,8 +98,14 @@ interface IVirtualInputDevice { boolean sendRotaryEncoderScrollEvent(in VirtualRotaryEncoderScrollEvent event); /** * Returns the current cursor position of the mouse corresponding to this device, in x and y * coordinates. * Returns the current cursor position of the mouse corresponding to this device, in the * physical display coordinates. */ PointF getCursorPosition(); PointF getCursorPositionInPhysicalDisplay(); /** * Returns the current cursor position of the mouse corresponding to this device, in the * logical display coordinates. */ PointF getCursorPositionInLogicalDisplay(); } core/java/android/hardware/input/InputManager.java +3 −1 Original line number Diff line number Diff line Loading @@ -1645,6 +1645,8 @@ public final class InputManager { /** * Gets the current position of the mouse cursor on the specified display. * * <p>Returned values are in logical display coordinates in pixels. * * <p>Returns null if no cursor is available, or if existing cursor is not on the supplied * `displayId`. * Loading @@ -1657,7 +1659,7 @@ public final class InputManager { @Nullable public PointF getCursorPosition(int displayId) { try { return mIm.getCursorPosition(displayId); return mIm.getCursorPositionInLogicalDisplay(displayId); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } Loading core/java/android/hardware/input/VirtualMouse.java +23 −2 Original line number Diff line number Diff line Loading @@ -18,7 +18,11 @@ package android.hardware.input; import android.annotation.NonNull; import android.annotation.SystemApi; import android.app.compat.CompatChanges; import android.compat.annotation.ChangeId; import android.compat.annotation.EnabledSince; import android.graphics.PointF; import android.os.Build; import android.os.RemoteException; import android.util.Log; import android.view.MotionEvent; Loading @@ -35,6 +39,14 @@ import android.view.MotionEvent; @SystemApi public class VirtualMouse extends VirtualInputDevice { /** * If enabled, the {@link #getCursorPosition()} API now returns in logical display coordinates * instead of in physical display coordinates, which is an old behavior. */ @ChangeId @EnabledSince(targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT) static final long VIRTUAL_MOUSE_CURSOR_POTION_IN_LOGICAL_COORDINATES = 431622043; /** @hide */ public VirtualMouse(VirtualMouseConfig config, IVirtualInputDevice virtualInputDevice) { super(config, virtualInputDevice); Loading Loading @@ -96,7 +108,10 @@ public class VirtualMouse extends VirtualInputDevice { } /** * Gets the current cursor position. * Gets the current cursor position in logical display coordinates in pixels. * * <p>Note that if {@code VIRTUAL_MOUSE_CURSOR_POTION_IN_LOGICAL_COORDINATES} is disabled, * this returns a position in the physical display coordinates instead. * * @return the position, expressed as x and y coordinates * @throws IllegalStateException if the display this mouse is associated with is not currently Loading @@ -104,7 +119,13 @@ public class VirtualMouse extends VirtualInputDevice { */ public @NonNull PointF getCursorPosition() { try { PointF cursorPosition = mVirtualInputDevice.getCursorPosition(); final PointF cursorPosition; if (CompatChanges.isChangeEnabled( VIRTUAL_MOUSE_CURSOR_POTION_IN_LOGICAL_COORDINATES)) { cursorPosition = mVirtualInputDevice.getCursorPositionInLogicalDisplay(); } else { cursorPosition = mVirtualInputDevice.getCursorPositionInPhysicalDisplay(); } // TODO(b/410677781): Returning PointF(NaN, NaN) on invalid displayId is different with // what the javadoc states, consider updating this (or the javadoc). return cursorPosition != null ? cursorPosition : new PointF(Float.NaN, Float.NaN); Loading services/core/java/com/android/server/input/InputManagerService.java +20 −2 Original line number Diff line number Diff line Loading @@ -3274,7 +3274,7 @@ public class InputManagerService extends IInputManager.Stub @Override // Binder call @Nullable public PointF getCursorPosition(int displayId) { public PointF getCursorPositionInPhysicalDisplay(int displayId) { if (!checkCallingPermission( Manifest.permission.INJECT_EVENTS, "getCursorPosition()", Loading @@ -3283,7 +3283,25 @@ public class InputManagerService extends IInputManager.Stub "The INJECT_EVENTS permission is required to access cursor outside the " + "intermediate window / display."); } final float[] p = mNative.getMouseCursorPosition(displayId); final float[] p = mNative.getMouseCursorPositionInPhysicalDisplay(displayId); if (p == null || p.length != 2) { return null; } return new PointF(p[0], p[1]); } @Override // Binder call @Nullable public PointF getCursorPositionInLogicalDisplay(int displayId) { if (!checkCallingPermission( Manifest.permission.INJECT_EVENTS, "getCursorPositionInLogicalDisplay()", true /*checkInstrumentationSource*/)) { throw new SecurityException( "The INJECT_EVENTS permission is required to access cursor outside the " + "intermediate window / display."); } final float[] p = mNative.getMouseCursorPositionInLogicalDisplay(displayId); if (p == null || p.length != 2) { return null; } Loading Loading
core/java/android/hardware/input/IInputManager.aidl +3 −1 Original line number Diff line number Diff line Loading @@ -315,5 +315,7 @@ interface IInputManager { void setMouseScalingEnabled(boolean enabled, int displayId); PointF getCursorPosition(int displayId); PointF getCursorPositionInPhysicalDisplay(int displayId); PointF getCursorPositionInLogicalDisplay(int displayId); }
core/java/android/hardware/input/IVirtualInputDevice.aidl +9 −3 Original line number Diff line number Diff line Loading @@ -98,8 +98,14 @@ interface IVirtualInputDevice { boolean sendRotaryEncoderScrollEvent(in VirtualRotaryEncoderScrollEvent event); /** * Returns the current cursor position of the mouse corresponding to this device, in x and y * coordinates. * Returns the current cursor position of the mouse corresponding to this device, in the * physical display coordinates. */ PointF getCursorPosition(); PointF getCursorPositionInPhysicalDisplay(); /** * Returns the current cursor position of the mouse corresponding to this device, in the * logical display coordinates. */ PointF getCursorPositionInLogicalDisplay(); }
core/java/android/hardware/input/InputManager.java +3 −1 Original line number Diff line number Diff line Loading @@ -1645,6 +1645,8 @@ public final class InputManager { /** * Gets the current position of the mouse cursor on the specified display. * * <p>Returned values are in logical display coordinates in pixels. * * <p>Returns null if no cursor is available, or if existing cursor is not on the supplied * `displayId`. * Loading @@ -1657,7 +1659,7 @@ public final class InputManager { @Nullable public PointF getCursorPosition(int displayId) { try { return mIm.getCursorPosition(displayId); return mIm.getCursorPositionInLogicalDisplay(displayId); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } Loading
core/java/android/hardware/input/VirtualMouse.java +23 −2 Original line number Diff line number Diff line Loading @@ -18,7 +18,11 @@ package android.hardware.input; import android.annotation.NonNull; import android.annotation.SystemApi; import android.app.compat.CompatChanges; import android.compat.annotation.ChangeId; import android.compat.annotation.EnabledSince; import android.graphics.PointF; import android.os.Build; import android.os.RemoteException; import android.util.Log; import android.view.MotionEvent; Loading @@ -35,6 +39,14 @@ import android.view.MotionEvent; @SystemApi public class VirtualMouse extends VirtualInputDevice { /** * If enabled, the {@link #getCursorPosition()} API now returns in logical display coordinates * instead of in physical display coordinates, which is an old behavior. */ @ChangeId @EnabledSince(targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT) static final long VIRTUAL_MOUSE_CURSOR_POTION_IN_LOGICAL_COORDINATES = 431622043; /** @hide */ public VirtualMouse(VirtualMouseConfig config, IVirtualInputDevice virtualInputDevice) { super(config, virtualInputDevice); Loading Loading @@ -96,7 +108,10 @@ public class VirtualMouse extends VirtualInputDevice { } /** * Gets the current cursor position. * Gets the current cursor position in logical display coordinates in pixels. * * <p>Note that if {@code VIRTUAL_MOUSE_CURSOR_POTION_IN_LOGICAL_COORDINATES} is disabled, * this returns a position in the physical display coordinates instead. * * @return the position, expressed as x and y coordinates * @throws IllegalStateException if the display this mouse is associated with is not currently Loading @@ -104,7 +119,13 @@ public class VirtualMouse extends VirtualInputDevice { */ public @NonNull PointF getCursorPosition() { try { PointF cursorPosition = mVirtualInputDevice.getCursorPosition(); final PointF cursorPosition; if (CompatChanges.isChangeEnabled( VIRTUAL_MOUSE_CURSOR_POTION_IN_LOGICAL_COORDINATES)) { cursorPosition = mVirtualInputDevice.getCursorPositionInLogicalDisplay(); } else { cursorPosition = mVirtualInputDevice.getCursorPositionInPhysicalDisplay(); } // TODO(b/410677781): Returning PointF(NaN, NaN) on invalid displayId is different with // what the javadoc states, consider updating this (or the javadoc). return cursorPosition != null ? cursorPosition : new PointF(Float.NaN, Float.NaN); Loading
services/core/java/com/android/server/input/InputManagerService.java +20 −2 Original line number Diff line number Diff line Loading @@ -3274,7 +3274,7 @@ public class InputManagerService extends IInputManager.Stub @Override // Binder call @Nullable public PointF getCursorPosition(int displayId) { public PointF getCursorPositionInPhysicalDisplay(int displayId) { if (!checkCallingPermission( Manifest.permission.INJECT_EVENTS, "getCursorPosition()", Loading @@ -3283,7 +3283,25 @@ public class InputManagerService extends IInputManager.Stub "The INJECT_EVENTS permission is required to access cursor outside the " + "intermediate window / display."); } final float[] p = mNative.getMouseCursorPosition(displayId); final float[] p = mNative.getMouseCursorPositionInPhysicalDisplay(displayId); if (p == null || p.length != 2) { return null; } return new PointF(p[0], p[1]); } @Override // Binder call @Nullable public PointF getCursorPositionInLogicalDisplay(int displayId) { if (!checkCallingPermission( Manifest.permission.INJECT_EVENTS, "getCursorPositionInLogicalDisplay()", true /*checkInstrumentationSource*/)) { throw new SecurityException( "The INJECT_EVENTS permission is required to access cursor outside the " + "intermediate window / display."); } final float[] p = mNative.getMouseCursorPositionInLogicalDisplay(displayId); if (p == null || p.length != 2) { return null; } Loading