Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 03ab62b1 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

Pointer Icon Refactor: Integrate setPointerIconVisible

Before the refactor, pointer icons were hidden when
setPointerIconVisible(display, false) was called by simply blocking all
the calls to set the pointer icon from java to native code.

This appraoch no longer works after the refactor. Instead, we must plumb
the setting down to PointerChoreographer, and let it handle it properly.

Bug: 320449549
Bug: 311651709
Test: atest inputflinger_tests
Change-Id: Ia0d172d9e470ab25b95d5776655779572b464f63
parent d129d9bf
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -1328,8 +1328,7 @@ public class InputManagerService extends IInputManager.Stub
            mPointerIconDisplayContext = null;
        }

        updateAdditionalDisplayInputProperties(displayId,
                AdditionalDisplayInputProperties::reset);
        updateAdditionalDisplayInputProperties(displayId, AdditionalDisplayInputProperties::reset);

        // TODO(b/320763728): Rely on WindowInfosListener to determine when a display has been
        //  removed in InputDispatcher instead of this callback.
@@ -1812,8 +1811,6 @@ public class InputManagerService extends IInputManager.Stub
            mPointerIconType = icon.getType();
            mPointerIcon = mPointerIconType == PointerIcon.TYPE_CUSTOM ? icon : null;

            if (!mCurrentDisplayProperties.pointerIconVisible) return false;

            return mNative.setPointerIcon(icon, displayId, deviceId, pointerId, inputToken);
        }
    }
@@ -3509,7 +3506,11 @@ public class InputManagerService extends IInputManager.Stub
                properties = new AdditionalDisplayInputProperties();
                mAdditionalDisplayInputProperties.put(displayId, properties);
            }
            final boolean oldPointerIconVisible = properties.pointerIconVisible;
            updater.accept(properties);
            if (oldPointerIconVisible != properties.pointerIconVisible) {
                mNative.setPointerIconVisibility(displayId, properties.pointerIconVisible);
            }
            if (properties.allDefaults()) {
                mAdditionalDisplayInputProperties.remove(displayId);
            }
+5 −0
Original line number Diff line number Diff line
@@ -190,6 +190,8 @@ interface NativeInputManagerService {
    boolean setPointerIcon(@NonNull PointerIcon icon, int displayId, int deviceId, int pointerId,
            @NonNull IBinder inputToken);

    void setPointerIconVisibility(int displayId, boolean visible);

    void requestPointerCapture(IBinder windowToken, boolean enabled);

    boolean canDispatchToDisplay(int deviceId, int displayId);
@@ -451,6 +453,9 @@ interface NativeInputManagerService {
        public native boolean setPointerIcon(PointerIcon icon, int displayId, int deviceId,
                int pointerId, IBinder inputToken);

        @Override
        public native void setPointerIconVisibility(int displayId, boolean visible);

        @Override
        public native void requestPointerCapture(IBinder windowToken, boolean enabled);

+16 −0
Original line number Diff line number Diff line
@@ -304,6 +304,7 @@ public:
    bool setPointerIcon(std::variant<std::unique_ptr<SpriteIcon>, PointerIconStyle> icon,
                        int32_t displayId, DeviceId deviceId, int32_t pointerId,
                        const sp<IBinder>& inputToken);
    void setPointerIconVisibility(int32_t displayId, bool visible);
    void setMotionClassifierEnabled(bool enabled);
    std::optional<std::string> getBluetoothAddress(int32_t deviceId);
    void setStylusButtonMotionEventsEnabled(bool enabled);
@@ -1397,6 +1398,13 @@ bool NativeInputManager::setPointerIcon(
    return mInputManager->getChoreographer().setPointerIcon(std::move(icon), displayId, deviceId);
}

void NativeInputManager::setPointerIconVisibility(int32_t displayId, bool visible) {
    if (!ENABLE_POINTER_CHOREOGRAPHER) {
        return;
    }
    mInputManager->getChoreographer().setPointerIconVisibility(displayId, visible);
}

TouchAffineTransformation NativeInputManager::getTouchAffineTransformation(
        JNIEnv *env, jfloatArray matrixArr) {
    ATRACE_CALL();
@@ -2550,6 +2558,13 @@ static bool nativeSetPointerIcon(JNIEnv* env, jobject nativeImplObj, jobject ico
                              ibinderForJavaObject(env, inputTokenObj));
}

static void nativeSetPointerIconVisibility(JNIEnv* env, jobject nativeImplObj, jint displayId,
                                           jboolean visible) {
    NativeInputManager* im = getNativeInputManager(env, nativeImplObj);

    im->setPointerIconVisibility(displayId, visible);
}

static jboolean nativeCanDispatchToDisplay(JNIEnv* env, jobject nativeImplObj, jint deviceId,
                                           jint displayId) {
    NativeInputManager* im = getNativeInputManager(env, nativeImplObj);
@@ -2828,6 +2843,7 @@ static const JNINativeMethod gInputManagerMethods[] = {
         (void*)nativeSetCustomPointerIcon},
        {"setPointerIcon", "(Landroid/view/PointerIcon;IIILandroid/os/IBinder;)Z",
         (void*)nativeSetPointerIcon},
        {"setPointerIconVisibility", "(IZ)V", (void*)nativeSetPointerIconVisibility},
        {"canDispatchToDisplay", "(II)Z", (void*)nativeCanDispatchToDisplay},
        {"notifyPortAssociationsChanged", "()V", (void*)nativeNotifyPortAssociationsChanged},
        {"changeUniqueIdAssociation", "()V", (void*)nativeChangeUniqueIdAssociation},
+6 −0
Original line number Diff line number Diff line
@@ -292,11 +292,13 @@ class InputManagerServiceTests {
        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(eq(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(true)
@@ -315,17 +317,20 @@ class InputManagerServiceTests {

        localService.setPointerIconVisible(false, 10)
        verify(native).setPointerIconType(eq(PointerIcon.TYPE_NULL))
        verify(native).setPointerIconVisibility(10, false)
        localService.setMousePointerAccelerationEnabled(false, 10)
        verify(native).setMousePointerAccelerationEnabled(eq(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(eq(true))

        // Verify that setting properties on a different display is not propagated until the
        // pointer is moved to that display.
        localService.setPointerIconVisible(false, 20)
        verify(native).setPointerIconVisibility(20, false)
        localService.setMousePointerAccelerationEnabled(false, 20)
        verifyNoMoreInteractions(native)

@@ -341,6 +346,7 @@ class InputManagerServiceTests {
        localService.setPointerIconVisible(false, 10)
        localService.setMousePointerAccelerationEnabled(false, 10)

        verify(native).setPointerIconVisibility(10, false)
        verifyNoMoreInteractions(native)

        setVirtualMousePointerDisplayIdAndVerify(10)