diff options
| author | Christine Franks <christyfranks@google.com> | 2021-11-29 12:08:12 -0800 |
|---|---|---|
| committer | Christine Franks <christyfranks@google.com> | 2022-01-20 21:43:50 -0800 |
| commit | 488d915febd4ff156786a4b8d301d92f9a115659 (patch) | |
| tree | e4362ed3bf0fd64f3b365b6109a48eef8b1e1db6 /core/java/android | |
| parent | c84373611f32d587730f7ac43ab8dc5a7543081f (diff) | |
Add mouse handling APIs
Bug: 202273865
Test: atest FrameworksCoreTests:android.hardware.input
CTS-Coverage-Bug: 208247880
Change-Id: Ic70f5f9e914492cb512095abb5687727b3bb3f09
Diffstat (limited to 'core/java/android')
4 files changed, 45 insertions, 1 deletions
diff --git a/core/java/android/companion/virtual/IVirtualDevice.aidl b/core/java/android/companion/virtual/IVirtualDevice.aidl index 85855bedfbeb..339e9a2ff1bc 100644 --- a/core/java/android/companion/virtual/IVirtualDevice.aidl +++ b/core/java/android/companion/virtual/IVirtualDevice.aidl @@ -18,6 +18,7 @@ package android.companion.virtual; import android.app.PendingIntent; import android.graphics.Point; +import android.graphics.PointF; import android.hardware.input.VirtualKeyEvent; import android.hardware.input.VirtualMouseButtonEvent; import android.hardware.input.VirtualMouseRelativeEvent; @@ -75,4 +76,5 @@ interface IVirtualDevice { */ void launchPendingIntent( int displayId, in PendingIntent pendingIntent, in ResultReceiver resultReceiver); + PointF getCursorPosition(IBinder token); } diff --git a/core/java/android/companion/virtual/VirtualDeviceManager.java b/core/java/android/companion/virtual/VirtualDeviceManager.java index 8ab668873f33..1ca83fc09c24 100644 --- a/core/java/android/companion/virtual/VirtualDeviceManager.java +++ b/core/java/android/companion/virtual/VirtualDeviceManager.java @@ -179,7 +179,9 @@ public final class VirtualDeviceManager { /** * Creates a virtual display for this virtual device. All displays created on the same - * device belongs to the same display group. + * device belongs to the same display group. Requires the ADD_TRUSTED_DISPLAY permission + * to create a virtual display which is not in the default DisplayGroup, and to create + * trusted displays. * * @param width The width of the virtual display in pixels, must be greater than 0. * @param height The height of the virtual display in pixels, must be greater than 0. diff --git a/core/java/android/hardware/input/InputManagerInternal.java b/core/java/android/hardware/input/InputManagerInternal.java index 1173c311bd26..f866a2e1c691 100644 --- a/core/java/android/hardware/input/InputManagerInternal.java +++ b/core/java/android/hardware/input/InputManagerInternal.java @@ -17,6 +17,7 @@ package android.hardware.input; import android.annotation.NonNull; +import android.graphics.PointF; import android.hardware.display.DisplayViewport; import android.os.IBinder; import android.view.InputEvent; @@ -79,6 +80,22 @@ public abstract class InputManagerInternal { public abstract boolean transferTouchFocus(@NonNull IBinder fromChannelToken, @NonNull IBinder toChannelToken); + /** + * Sets the display id that the MouseCursorController will be forced to target. Pass + * {@link android.view.Display#INVALID_DISPLAY} to clear the override. + */ + public abstract void setVirtualMousePointerDisplayId(int pointerDisplayId); + + /** Gets the current position of the mouse cursor. */ + public abstract PointF getCursorPosition(); + + /** + * Sets the eligibility of windows on a given display for pointer capture. If a display is + * marked ineligible, requests to enable pointer capture for windows on that display will be + * ignored. + */ + public abstract void setDisplayEligibilityForPointerCapture(int displayId, boolean isEligible); + /** Registers the {@link LidSwitchCallback} to begin receiving notifications. */ public abstract void registerLidSwitchCallback(@NonNull LidSwitchCallback callbacks); diff --git a/core/java/android/hardware/input/VirtualMouse.java b/core/java/android/hardware/input/VirtualMouse.java index 6599dd2e28eb..6e2b56a2b5bc 100644 --- a/core/java/android/hardware/input/VirtualMouse.java +++ b/core/java/android/hardware/input/VirtualMouse.java @@ -20,6 +20,7 @@ import android.annotation.NonNull; import android.annotation.RequiresPermission; import android.annotation.SystemApi; import android.companion.virtual.IVirtualDevice; +import android.graphics.PointF; import android.os.IBinder; import android.os.RemoteException; import android.view.MotionEvent; @@ -61,6 +62,8 @@ public class VirtualMouse implements Closeable { * Send a mouse button event to the system. * * @param event the event + * @throws IllegalStateException if the display this mouse is associated with is not currently + * targeted */ @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) public void sendButtonEvent(@NonNull VirtualMouseButtonEvent event) { @@ -76,6 +79,8 @@ public class VirtualMouse implements Closeable { * {@link MotionEvent#AXIS_SCROLL}. * * @param event the event + * @throws IllegalStateException if the display this mouse is associated with is not currently + * targeted */ @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) public void sendScrollEvent(@NonNull VirtualMouseScrollEvent event) { @@ -90,6 +95,8 @@ public class VirtualMouse implements Closeable { * Sends a relative movement event to the system. * * @param event the event + * @throws IllegalStateException if the display this mouse is associated with is not currently + * targeted */ @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) public void sendRelativeEvent(@NonNull VirtualMouseRelativeEvent event) { @@ -99,4 +106,20 @@ public class VirtualMouse implements Closeable { throw e.rethrowFromSystemServer(); } } + + /** + * Gets the current cursor position. + * + * @return the position, expressed as x and y coordinates + * @throws IllegalStateException if the display this mouse is associated with is not currently + * targeted + */ + @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) + public @NonNull PointF getCursorPosition() { + try { + return mVirtualDevice.getCursorPosition(mToken); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } } |
