summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/core/java/com/android/server/input/InputManagerService.java207
-rw-r--r--services/core/java/com/android/server/input/NativeInputManagerService.java10
-rw-r--r--services/core/jni/com_android_server_input_InputManagerService.cpp11
-rw-r--r--tests/Input/src/com/android/server/input/InputManagerServiceTests.kt215
4 files changed, 16 insertions, 427 deletions
diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java
index eb719527b06d..caa2c8d84c6e 100644
--- a/services/core/java/com/android/server/input/InputManagerService.java
+++ b/services/core/java/com/android/server/input/InputManagerService.java
@@ -282,33 +282,9 @@ public class InputManagerService extends IInputManager.Stub
// WARNING: Do not call other services outside of input while holding this lock.
private final Object mAdditionalDisplayInputPropertiesLock = new Object();
- // Forces the PointerController to target a specific display id.
- @GuardedBy("mAdditionalDisplayInputPropertiesLock")
- private int mOverriddenPointerDisplayId = Display.INVALID_DISPLAY;
-
- // PointerController is the source of truth of the pointer display. This is the value of the
- // latest pointer display id reported by PointerController.
- @GuardedBy("mAdditionalDisplayInputPropertiesLock")
- private int mAcknowledgedPointerDisplayId = Display.INVALID_DISPLAY;
- // This is the latest display id that IMS has requested PointerController to use. If there are
- // no devices that can control the pointer, PointerController may end up disregarding this
- // value.
- @GuardedBy("mAdditionalDisplayInputPropertiesLock")
- private int mRequestedPointerDisplayId = Display.INVALID_DISPLAY;
@GuardedBy("mAdditionalDisplayInputPropertiesLock")
private final SparseArray<AdditionalDisplayInputProperties> mAdditionalDisplayInputProperties =
new SparseArray<>();
- // This contains the per-display properties that are currently applied by native code. It should
- // be kept in sync with the properties for mRequestedPointerDisplayId.
- @GuardedBy("mAdditionalDisplayInputPropertiesLock")
- private final AdditionalDisplayInputProperties mCurrentDisplayProperties =
- new AdditionalDisplayInputProperties();
- // TODO(b/293587049): Pointer Icon Refactor: There can be more than one pointer icon
- // visible at once. Update this to support multi-pointer use cases.
- @GuardedBy("mAdditionalDisplayInputPropertiesLock")
- private int mPointerIconType = PointerIcon.TYPE_NOT_SPECIFIED;
- @GuardedBy("mAdditionalDisplayInputPropertiesLock")
- private PointerIcon mPointerIcon;
// Holds all the registered gesture monitors that are implemented as spy windows. The spy
// windows are mapped by their InputChannel tokens.
@@ -617,14 +593,9 @@ public class InputManagerService extends IInputManager.Stub
}
mNative.setDisplayViewports(vArray);
- // Attempt to update the pointer display when viewports change when there is no override.
+ // Attempt to update the default pointer display when the viewports change.
// Take care to not make calls to window manager while holding internal locks.
- final int pointerDisplayId = mWindowManagerCallbacks.getPointerDisplayId();
- synchronized (mAdditionalDisplayInputPropertiesLock) {
- if (mOverriddenPointerDisplayId == Display.INVALID_DISPLAY) {
- updatePointerDisplayIdLocked(pointerDisplayId);
- }
- }
+ mNative.setPointerDisplayId(mWindowManagerCallbacks.getPointerDisplayId());
}
/**
@@ -1353,84 +1324,11 @@ public class InputManagerService extends IInputManager.Stub
properties -> properties.pointerIconVisible = visible);
}
- /**
- * Update the display on which the mouse pointer is shown.
- *
- * @return true if the pointer displayId changed, false otherwise.
- */
- @GuardedBy("mAdditionalDisplayInputPropertiesLock")
- private boolean updatePointerDisplayIdLocked(int pointerDisplayId) {
- if (mRequestedPointerDisplayId == pointerDisplayId) {
- return false;
- }
- mRequestedPointerDisplayId = pointerDisplayId;
- mNative.setPointerDisplayId(pointerDisplayId);
- applyAdditionalDisplayInputProperties();
- return true;
- }
-
private void handlePointerDisplayIdChanged(PointerDisplayIdChangedArgs args) {
- synchronized (mAdditionalDisplayInputPropertiesLock) {
- mAcknowledgedPointerDisplayId = args.mPointerDisplayId;
- // Notify waiting threads that the display of the mouse pointer has changed.
- mAdditionalDisplayInputPropertiesLock.notifyAll();
- }
mWindowManagerCallbacks.notifyPointerDisplayIdChanged(
args.mPointerDisplayId, args.mXPosition, args.mYPosition);
}
- private boolean setVirtualMousePointerDisplayIdBlocking(int overrideDisplayId) {
- if (com.android.input.flags.Flags.enablePointerChoreographer()) {
- throw new IllegalStateException(
- "This must not be used when PointerChoreographer is enabled");
- }
- final boolean isRemovingOverride = overrideDisplayId == Display.INVALID_DISPLAY;
-
- // Take care to not make calls to window manager while holding internal locks.
- final int resolvedDisplayId = isRemovingOverride
- ? mWindowManagerCallbacks.getPointerDisplayId()
- : overrideDisplayId;
-
- synchronized (mAdditionalDisplayInputPropertiesLock) {
- mOverriddenPointerDisplayId = overrideDisplayId;
-
- if (!updatePointerDisplayIdLocked(resolvedDisplayId)
- && mAcknowledgedPointerDisplayId == resolvedDisplayId) {
- // The requested pointer display is already set.
- return true;
- }
- if (isRemovingOverride && mAcknowledgedPointerDisplayId == Display.INVALID_DISPLAY) {
- // The pointer display override is being removed, but the current pointer display
- // is already invalid. This can happen when the PointerController is destroyed as a
- // result of the removal of all input devices that can control the pointer.
- return true;
- }
- try {
- // The pointer display changed, so wait until the change has propagated.
- mAdditionalDisplayInputPropertiesLock.wait(5_000 /*mills*/);
- } catch (InterruptedException ignored) {
- }
- // This request succeeds in two cases:
- // - This request was to remove the override, in which case the new pointer display
- // could be anything that WM has set.
- // - We are setting a new override, in which case the request only succeeds if the
- // reported new displayId is the one we requested. This check ensures that if two
- // competing overrides are requested in succession, the caller can be notified if one
- // of them fails.
- return isRemovingOverride || mAcknowledgedPointerDisplayId == overrideDisplayId;
- }
- }
-
- private int getVirtualMousePointerDisplayId() {
- if (com.android.input.flags.Flags.enablePointerChoreographer()) {
- throw new IllegalStateException(
- "This must not be used when PointerChoreographer is enabled");
- }
- synchronized (mAdditionalDisplayInputPropertiesLock) {
- return mOverriddenPointerDisplayId;
- }
- }
-
private void setDisplayEligibilityForPointerCapture(int displayId, boolean isEligible) {
mNative.setDisplayEligibilityForPointerCapture(displayId, isEligible);
}
@@ -1715,31 +1613,13 @@ public class InputManagerService extends IInputManager.Stub
// Binder call
@Override
public void setPointerIconType(int iconType) {
- if (iconType == PointerIcon.TYPE_CUSTOM) {
- throw new IllegalArgumentException("Use setCustomPointerIcon to set custom pointers");
- }
- synchronized (mAdditionalDisplayInputPropertiesLock) {
- mPointerIcon = null;
- mPointerIconType = iconType;
-
- if (!mCurrentDisplayProperties.pointerIconVisible) return;
-
- mNative.setPointerIconType(mPointerIconType);
- }
+ // TODO(b/311416205): Remove.
}
// Binder call
@Override
public void setCustomPointerIcon(PointerIcon icon) {
- Objects.requireNonNull(icon);
- synchronized (mAdditionalDisplayInputPropertiesLock) {
- mPointerIconType = PointerIcon.TYPE_CUSTOM;
- mPointerIcon = icon;
-
- if (!mCurrentDisplayProperties.pointerIconVisible) return;
-
- mNative.setCustomPointerIcon(mPointerIcon);
- }
+ // TODO(b/311416205): Remove.
}
// Binder call
@@ -1747,12 +1627,7 @@ public class InputManagerService extends IInputManager.Stub
public boolean setPointerIcon(PointerIcon icon, int displayId, int deviceId, int pointerId,
IBinder inputToken) {
Objects.requireNonNull(icon);
- synchronized (mAdditionalDisplayInputPropertiesLock) {
- mPointerIconType = icon.getType();
- mPointerIcon = mPointerIconType == PointerIcon.TYPE_CUSTOM ? icon : null;
-
- return mNative.setPointerIcon(icon, displayId, deviceId, pointerId, inputToken);
- }
+ return mNative.setPointerIcon(icon, displayId, deviceId, pointerId, inputToken);
}
/**
@@ -2281,28 +2156,24 @@ public class InputManagerService extends IInputManager.Stub
private void dumpDisplayInputPropertiesValues(IndentingPrintWriter pw) {
synchronized (mAdditionalDisplayInputPropertiesLock) {
- if (mAdditionalDisplayInputProperties.size() != 0) {
- pw.println("mAdditionalDisplayInputProperties:");
- pw.increaseIndent();
+ pw.println("mAdditionalDisplayInputProperties:");
+ pw.increaseIndent();
+ try {
+ if (mAdditionalDisplayInputProperties.size() == 0) {
+ pw.println("<none>");
+ return;
+ }
for (int i = 0; i < mAdditionalDisplayInputProperties.size(); i++) {
- pw.println("displayId: "
- + mAdditionalDisplayInputProperties.keyAt(i));
+ pw.println("displayId: " + mAdditionalDisplayInputProperties.keyAt(i));
final AdditionalDisplayInputProperties properties =
mAdditionalDisplayInputProperties.valueAt(i);
pw.println("mousePointerAccelerationEnabled: "
+ properties.mousePointerAccelerationEnabled);
pw.println("pointerIconVisible: " + properties.pointerIconVisible);
}
+ } finally {
pw.decreaseIndent();
}
- if (mOverriddenPointerDisplayId != Display.INVALID_DISPLAY) {
- pw.println("mOverriddenPointerDisplayId: " + mOverriddenPointerDisplayId);
- }
-
- pw.println("mAcknowledgedPointerDisplayId=" + mAcknowledgedPointerDisplayId);
- pw.println("mRequestedPointerDisplayId=" + mRequestedPointerDisplayId);
- pw.println("mPointerIconType=" + PointerIcon.typeToString(mPointerIconType));
- pw.println("mPointerIcon=" + mPointerIcon);
}
}
private boolean checkCallingPermission(String permission, String func) {
@@ -3268,13 +3139,12 @@ public class InputManagerService extends IInputManager.Stub
@Override
public boolean setVirtualMousePointerDisplayId(int pointerDisplayId) {
- return InputManagerService.this
- .setVirtualMousePointerDisplayIdBlocking(pointerDisplayId);
+ return false;
}
@Override
public int getVirtualMousePointerDisplayId() {
- return InputManagerService.this.getVirtualMousePointerDisplayId();
+ return Display.INVALID_DISPLAY;
}
@Override
@@ -3413,44 +3283,6 @@ public class InputManagerService extends IInputManager.Stub
}
}
- private void applyAdditionalDisplayInputProperties() {
- synchronized (mAdditionalDisplayInputPropertiesLock) {
- AdditionalDisplayInputProperties properties =
- mAdditionalDisplayInputProperties.get(mRequestedPointerDisplayId);
- if (properties == null) properties = DEFAULT_ADDITIONAL_DISPLAY_INPUT_PROPERTIES;
- applyAdditionalDisplayInputPropertiesLocked(properties);
- }
- }
-
- @GuardedBy("mAdditionalDisplayInputPropertiesLock")
- private void applyAdditionalDisplayInputPropertiesLocked(
- AdditionalDisplayInputProperties properties) {
- // Handle changes to each of the individual properties.
- // TODO(b/293587049): This approach for updating pointer display properties is only for when
- // PointerChoreographer is disabled. Remove this logic when PointerChoreographer is
- // permanently enabled.
-
- if (properties.pointerIconVisible != mCurrentDisplayProperties.pointerIconVisible) {
- mCurrentDisplayProperties.pointerIconVisible = properties.pointerIconVisible;
- if (properties.pointerIconVisible) {
- if (mPointerIconType == PointerIcon.TYPE_CUSTOM) {
- Objects.requireNonNull(mPointerIcon);
- mNative.setCustomPointerIcon(mPointerIcon);
- } else {
- mNative.setPointerIconType(mPointerIconType);
- }
- } else {
- mNative.setPointerIconType(PointerIcon.TYPE_NULL);
- }
- }
-
- if (properties.mousePointerAccelerationEnabled
- != mCurrentDisplayProperties.mousePointerAccelerationEnabled) {
- mCurrentDisplayProperties.mousePointerAccelerationEnabled =
- properties.mousePointerAccelerationEnabled;
- }
- }
-
private void updateAdditionalDisplayInputProperties(int displayId,
Consumer<AdditionalDisplayInputProperties> updater) {
synchronized (mAdditionalDisplayInputPropertiesLock) {
@@ -3473,13 +3305,6 @@ public class InputManagerService extends IInputManager.Stub
if (properties.allDefaults()) {
mAdditionalDisplayInputProperties.remove(displayId);
}
- if (displayId != mRequestedPointerDisplayId) {
- Log.i(TAG, "Not applying additional properties for display " + displayId
- + " because the pointer is currently targeting display "
- + mRequestedPointerDisplayId + ".");
- return;
- }
- applyAdditionalDisplayInputPropertiesLocked(properties);
}
}
diff --git a/services/core/java/com/android/server/input/NativeInputManagerService.java b/services/core/java/com/android/server/input/NativeInputManagerService.java
index 32d5044d9e41..f742360484f5 100644
--- a/services/core/java/com/android/server/input/NativeInputManagerService.java
+++ b/services/core/java/com/android/server/input/NativeInputManagerService.java
@@ -189,12 +189,8 @@ interface NativeInputManagerService {
void disableInputDevice(int deviceId);
- void setPointerIconType(int iconId);
-
void reloadPointerIcons();
- void setCustomPointerIcon(@NonNull PointerIcon icon);
-
boolean setPointerIcon(@NonNull PointerIcon icon, int displayId, int deviceId, int pointerId,
@NonNull IBinder inputToken);
@@ -467,15 +463,9 @@ interface NativeInputManagerService {
public native void disableInputDevice(int deviceId);
@Override
- public native void setPointerIconType(int iconId);
-
- @Override
public native void reloadPointerIcons();
@Override
- public native void setCustomPointerIcon(PointerIcon icon);
-
- @Override
public native boolean setPointerIcon(PointerIcon icon, int displayId, int deviceId,
int pointerId, IBinder inputToken);
diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp
index fac08eb78726..62f5b89e701c 100644
--- a/services/core/jni/com_android_server_input_InputManagerService.cpp
+++ b/services/core/jni/com_android_server_input_InputManagerService.cpp
@@ -2463,20 +2463,12 @@ static void nativeDisableInputDevice(JNIEnv* env, jobject nativeImplObj, jint de
im->setInputDeviceEnabled(deviceId, false);
}
-static void nativeSetPointerIconType(JNIEnv* env, jobject nativeImplObj, jint iconId) {
- // TODO(b/311416205): Remove
-}
-
static void nativeReloadPointerIcons(JNIEnv* env, jobject nativeImplObj) {
NativeInputManager* im = getNativeInputManager(env, nativeImplObj);
im->reloadPointerIcons();
}
-static void nativeSetCustomPointerIcon(JNIEnv* env, jobject nativeImplObj, jobject iconObj) {
- // TODO(b/311416205): Remove
-}
-
static bool nativeSetPointerIcon(JNIEnv* env, jobject nativeImplObj, jobject iconObj,
jint displayId, jint deviceId, jint pointerId,
jobject inputTokenObj) {
@@ -2796,10 +2788,7 @@ static const JNINativeMethod gInputManagerMethods[] = {
{"isInputDeviceEnabled", "(I)Z", (void*)nativeIsInputDeviceEnabled},
{"enableInputDevice", "(I)V", (void*)nativeEnableInputDevice},
{"disableInputDevice", "(I)V", (void*)nativeDisableInputDevice},
- {"setPointerIconType", "(I)V", (void*)nativeSetPointerIconType},
{"reloadPointerIcons", "()V", (void*)nativeReloadPointerIcons},
- {"setCustomPointerIcon", "(Landroid/view/PointerIcon;)V",
- (void*)nativeSetCustomPointerIcon},
{"setPointerIcon", "(Landroid/view/PointerIcon;IIILandroid/os/IBinder;)Z",
(void*)nativeSetPointerIcon},
{"setPointerIconVisibility", "(IZ)V", (void*)nativeSetPointerIconVisibility},
diff --git a/tests/Input/src/com/android/server/input/InputManagerServiceTests.kt b/tests/Input/src/com/android/server/input/InputManagerServiceTests.kt
index 0fc9d6ff1501..3b9ee807077e 100644
--- a/tests/Input/src/com/android/server/input/InputManagerServiceTests.kt
+++ b/tests/Input/src/com/android/server/input/InputManagerServiceTests.kt
@@ -28,14 +28,11 @@ import android.os.InputEventInjectionSync
import android.os.SystemClock
import android.os.test.TestLooper
import android.platform.test.annotations.Presubmit
-import android.platform.test.annotations.RequiresFlagsDisabled
import android.platform.test.flag.junit.DeviceFlagsValueProvider
import android.provider.Settings
import android.view.View.OnKeyListener
-import android.view.Display
import android.view.InputDevice
import android.view.KeyEvent
-import android.view.PointerIcon
import android.view.SurfaceHolder
import android.view.SurfaceView
import android.test.mock.MockContentResolver
@@ -44,7 +41,6 @@ import com.android.internal.util.test.FakeSettingsProvider
import com.google.common.truth.Truth.assertThat
import com.android.compatibility.common.util.SystemUtil.runWithShellPermissionIdentity
import org.junit.After
-import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
@@ -53,22 +49,16 @@ import org.mockito.ArgumentMatchers.any
import org.mockito.ArgumentMatchers.anyBoolean
import org.mockito.ArgumentMatchers.anyFloat
import org.mockito.ArgumentMatchers.anyInt
-import org.mockito.ArgumentMatchers.eq
import org.mockito.Mock
import org.mockito.Mockito.`when`
-import org.mockito.Mockito.clearInvocations
-import org.mockito.Mockito.doAnswer
import org.mockito.Mockito.mock
import org.mockito.Mockito.never
import org.mockito.Mockito.spy
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
-import org.mockito.Mockito.verifyNoMoreInteractions
import org.mockito.Mockito.verifyZeroInteractions
import org.mockito.junit.MockitoJUnit
import org.mockito.stubbing.OngoingStubbing
-import java.util.concurrent.CountDownLatch
-import java.util.concurrent.TimeUnit
/**
* Tests for {@link InputManagerService}.
@@ -187,197 +177,6 @@ class InputManagerServiceTests {
verify(wmCallbacks).notifyPointerDisplayIdChanged(displayId, x, y)
}
- @RequiresFlagsDisabled(com.android.input.flags.Flags.FLAG_ENABLE_POINTER_CHOREOGRAPHER)
- @Test
- fun testSetVirtualMousePointerDisplayId() {
- // Set the virtual mouse pointer displayId, and ensure that the calling thread is blocked
- // until the native callback happens.
- var countDownLatch = CountDownLatch(1)
- val overrideDisplayId = 123
- Thread {
- assertTrue("Setting virtual pointer display should succeed",
- localService.setVirtualMousePointerDisplayId(overrideDisplayId))
- countDownLatch.countDown()
- }.start()
- assertFalse("Setting virtual pointer display should block",
- countDownLatch.await(100, TimeUnit.MILLISECONDS))
-
- val x = 42f
- val y = 314f
- service.onPointerDisplayIdChanged(overrideDisplayId, x, y)
- testLooper.dispatchNext()
- verify(wmCallbacks).notifyPointerDisplayIdChanged(overrideDisplayId, x, y)
- assertTrue("Native callback unblocks calling thread",
- countDownLatch.await(100, TimeUnit.MILLISECONDS))
- verify(native).setPointerDisplayId(overrideDisplayId)
-
- // Ensure that setting the same override again succeeds immediately.
- assertTrue("Setting the same virtual mouse pointer displayId again should succeed",
- localService.setVirtualMousePointerDisplayId(overrideDisplayId))
-
- // Ensure that we did not query WM for the pointerDisplayId when setting the override
- verify(wmCallbacks, never()).pointerDisplayId
-
- // Unset the virtual mouse pointer displayId, and ensure that we query WM for the new
- // pointer displayId and the calling thread is blocked until the native callback happens.
- countDownLatch = CountDownLatch(1)
- val pointerDisplayId = 42
- `when`(wmCallbacks.pointerDisplayId).thenReturn(pointerDisplayId)
- Thread {
- assertTrue("Unsetting virtual mouse pointer displayId should succeed",
- localService.setVirtualMousePointerDisplayId(Display.INVALID_DISPLAY))
- countDownLatch.countDown()
- }.start()
- assertFalse("Unsetting virtual mouse pointer displayId should block",
- countDownLatch.await(100, TimeUnit.MILLISECONDS))
-
- service.onPointerDisplayIdChanged(pointerDisplayId, x, y)
- testLooper.dispatchNext()
- verify(wmCallbacks).notifyPointerDisplayIdChanged(pointerDisplayId, x, y)
- assertTrue("Native callback unblocks calling thread",
- countDownLatch.await(100, TimeUnit.MILLISECONDS))
- verify(native).setPointerDisplayId(pointerDisplayId)
- }
-
- @RequiresFlagsDisabled(com.android.input.flags.Flags.FLAG_ENABLE_POINTER_CHOREOGRAPHER)
- @Test
- fun testSetVirtualMousePointerDisplayId_unsuccessfulUpdate() {
- // Set the virtual mouse pointer displayId, and ensure that the calling thread is blocked
- // until the native callback happens.
- val countDownLatch = CountDownLatch(1)
- val overrideDisplayId = 123
- Thread {
- assertFalse("Setting virtual pointer display should be unsuccessful",
- localService.setVirtualMousePointerDisplayId(overrideDisplayId))
- countDownLatch.countDown()
- }.start()
- assertFalse("Setting virtual pointer display should block",
- countDownLatch.await(100, TimeUnit.MILLISECONDS))
-
- val x = 42f
- val y = 314f
- // Assume the native callback updates the pointerDisplayId to the incorrect value.
- service.onPointerDisplayIdChanged(Display.INVALID_DISPLAY, x, y)
- testLooper.dispatchNext()
- verify(wmCallbacks).notifyPointerDisplayIdChanged(Display.INVALID_DISPLAY, x, y)
- assertTrue("Native callback unblocks calling thread",
- countDownLatch.await(100, TimeUnit.MILLISECONDS))
- verify(native).setPointerDisplayId(overrideDisplayId)
- }
-
- @RequiresFlagsDisabled(com.android.input.flags.Flags.FLAG_ENABLE_POINTER_CHOREOGRAPHER)
- @Test
- fun testSetVirtualMousePointerDisplayId_competingRequests() {
- val firstRequestSyncLatch = CountDownLatch(1)
- doAnswer {
- firstRequestSyncLatch.countDown()
- }.`when`(native).setPointerDisplayId(anyInt())
-
- val firstRequestLatch = CountDownLatch(1)
- val firstOverride = 123
- Thread {
- assertFalse("Setting virtual pointer display from thread 1 should be unsuccessful",
- localService.setVirtualMousePointerDisplayId(firstOverride))
- firstRequestLatch.countDown()
- }.start()
- assertFalse("Setting virtual pointer display should block",
- firstRequestLatch.await(100, TimeUnit.MILLISECONDS))
-
- assertTrue("Wait for first thread's request should succeed",
- firstRequestSyncLatch.await(100, TimeUnit.MILLISECONDS))
-
- val secondRequestLatch = CountDownLatch(1)
- val secondOverride = 42
- Thread {
- assertTrue("Setting virtual mouse pointer from thread 2 should be successful",
- localService.setVirtualMousePointerDisplayId(secondOverride))
- secondRequestLatch.countDown()
- }.start()
- assertFalse("Setting virtual mouse pointer should block",
- secondRequestLatch.await(100, TimeUnit.MILLISECONDS))
-
- val x = 42f
- val y = 314f
- // Assume the native callback updates directly to the second request.
- service.onPointerDisplayIdChanged(secondOverride, x, y)
- testLooper.dispatchNext()
- verify(wmCallbacks).notifyPointerDisplayIdChanged(secondOverride, x, y)
- assertTrue("Native callback unblocks first thread",
- firstRequestLatch.await(100, TimeUnit.MILLISECONDS))
- assertTrue("Native callback unblocks second thread",
- secondRequestLatch.await(100, TimeUnit.MILLISECONDS))
- verify(native, times(2)).setPointerDisplayId(anyInt())
- }
-
- @RequiresFlagsDisabled(com.android.input.flags.Flags.FLAG_ENABLE_POINTER_CHOREOGRAPHER)
- @Test
- fun onDisplayRemoved_resetAllAdditionalInputProperties() {
- setVirtualMousePointerDisplayIdAndVerify(10)
-
- localService.setPointerIconVisible(false, 10)
- verify(native).setPointerIconVisibility(10, false)
- verify(native).setPointerIconType(eq(PointerIcon.TYPE_NULL))
- localService.setMousePointerAccelerationEnabled(false, 10)
- verify(native).setMousePointerAccelerationEnabled(10, false)
-
- service.onDisplayRemoved(10)
- verify(native).setPointerIconVisibility(10, true)
- verify(native).displayRemoved(eq(10))
- verify(native).setPointerIconType(eq(PointerIcon.TYPE_NOT_SPECIFIED))
- verify(native).setMousePointerAccelerationEnabled(10, true)
- verifyNoMoreInteractions(native)
-
- // This call should not block because the virtual mouse pointer override was never removed.
- localService.setVirtualMousePointerDisplayId(10)
-
- verify(native).setPointerDisplayId(eq(10))
- verifyNoMoreInteractions(native)
- }
-
- @RequiresFlagsDisabled(com.android.input.flags.Flags.FLAG_ENABLE_POINTER_CHOREOGRAPHER)
- @Test
- fun updateAdditionalInputPropertiesForOverrideDisplay() {
- setVirtualMousePointerDisplayIdAndVerify(10)
-
- localService.setPointerIconVisible(false, 10)
- verify(native).setPointerIconType(eq(PointerIcon.TYPE_NULL))
- verify(native).setPointerIconVisibility(10, false)
- localService.setMousePointerAccelerationEnabled(false, 10)
- verify(native).setMousePointerAccelerationEnabled(10, false)
-
- localService.setPointerIconVisible(true, 10)
- verify(native).setPointerIconType(eq(PointerIcon.TYPE_NOT_SPECIFIED))
- verify(native).setPointerIconVisibility(10, true)
- localService.setMousePointerAccelerationEnabled(true, 10)
- verify(native).setMousePointerAccelerationEnabled(10, true)
-
- localService.setPointerIconVisible(false, 20)
- verify(native).setPointerIconVisibility(20, false)
- localService.setMousePointerAccelerationEnabled(false, 20)
- verify(native).setMousePointerAccelerationEnabled(20, false)
- verifyNoMoreInteractions(native)
-
- clearInvocations(native)
- setVirtualMousePointerDisplayIdAndVerify(20)
-
- verify(native).setPointerIconType(eq(PointerIcon.TYPE_NULL))
- }
-
- @RequiresFlagsDisabled(com.android.input.flags.Flags.FLAG_ENABLE_POINTER_CHOREOGRAPHER)
- @Test
- fun setAdditionalInputPropertiesBeforeOverride() {
- localService.setPointerIconVisible(false, 10)
- localService.setMousePointerAccelerationEnabled(false, 10)
-
- verify(native).setPointerIconVisibility(10, false)
- verify(native).setMousePointerAccelerationEnabled(10, false)
- verifyNoMoreInteractions(native)
-
- setVirtualMousePointerDisplayIdAndVerify(10)
-
- verify(native).setPointerIconType(eq(PointerIcon.TYPE_NULL))
- }
-
@Test
fun setDeviceTypeAssociation_setsDeviceTypeAssociation() {
val inputPort = "inputPort"
@@ -412,20 +211,6 @@ class InputManagerServiceTests {
verify(native, times(2)).changeKeyboardLayoutAssociation()
}
- private fun setVirtualMousePointerDisplayIdAndVerify(overrideDisplayId: Int) {
- val thread = Thread { localService.setVirtualMousePointerDisplayId(overrideDisplayId) }
- thread.start()
-
- // Allow some time for the set override call to park while waiting for the native callback.
- Thread.sleep(100 /*millis*/)
- verify(native).setPointerDisplayId(overrideDisplayId)
-
- service.onPointerDisplayIdChanged(overrideDisplayId, 0f, 0f)
- testLooper.dispatchNext()
- verify(wmCallbacks).notifyPointerDisplayIdChanged(overrideDisplayId, 0f, 0f)
- thread.join(100 /*millis*/)
- }
-
private fun createVirtualDisplays(count: Int): List<VirtualDisplay> {
val displayManager: DisplayManager = context.getSystemService(
DisplayManager::class.java