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

Commit 6ded2f2e authored by Prabir Pradhan's avatar Prabir Pradhan Committed by Android (Google) Code Review
Browse files

Merge changes from topic "pointer-icon-refactor-vdm" into main

* changes:
  Pointer Icon Refactor: Add displayId parameter to getCursorPosition
  Pointer Icon Refactor: Remove get/setVirtualMousePointerDisplayId
parents 2e8b8853 d0aa5ae5
Loading
Loading
Loading
Loading
+33 −22
Original line number Diff line number Diff line
@@ -163,7 +163,7 @@ class InputController {
        createDeviceInternal(InputDeviceDescriptor.TYPE_MOUSE, deviceName, vendorId, productId,
                deviceToken, displayId, phys,
                () -> mNativeWrapper.openUinputMouse(deviceName, vendorId, productId, phys));
        mInputManagerInternal.setVirtualMousePointerDisplayId(displayId);
        setVirtualMousePointerDisplayId(displayId);
    }

    void createTouchscreen(@NonNull String deviceName, int vendorId, int productId,
@@ -235,8 +235,7 @@ class InputController {
        // id if there's another mouse (choose the most recent). The inputDeviceDescriptor must be
        // removed from the mInputDeviceDescriptors instance variable prior to this point.
        if (inputDeviceDescriptor.isMouse()) {
            if (mInputManagerInternal.getVirtualMousePointerDisplayId()
                    == inputDeviceDescriptor.getDisplayId()) {
            if (getVirtualMousePointerDisplayId() == inputDeviceDescriptor.getDisplayId()) {
                updateActivePointerDisplayIdLocked();
            }
        }
@@ -271,6 +270,7 @@ class InputController {
        mWindowManager.setDisplayImePolicy(displayId, policy);
    }

    // TODO(b/293587049): Remove after pointer icon refactor is complete.
    @GuardedBy("mLock")
    private void updateActivePointerDisplayIdLocked() {
        InputDeviceDescriptor mostRecentlyCreatedMouse = null;
@@ -285,11 +285,11 @@ class InputController {
            }
        }
        if (mostRecentlyCreatedMouse != null) {
            mInputManagerInternal.setVirtualMousePointerDisplayId(
            setVirtualMousePointerDisplayId(
                    mostRecentlyCreatedMouse.getDisplayId());
        } else {
            // All mice have been unregistered
            mInputManagerInternal.setVirtualMousePointerDisplayId(Display.INVALID_DISPLAY);
            setVirtualMousePointerDisplayId(Display.INVALID_DISPLAY);
        }
    }

@@ -349,10 +349,8 @@ class InputController {
            if (inputDeviceDescriptor == null) {
                return false;
            }
            if (inputDeviceDescriptor.getDisplayId()
                    != mInputManagerInternal.getVirtualMousePointerDisplayId()) {
                mInputManagerInternal.setVirtualMousePointerDisplayId(
                        inputDeviceDescriptor.getDisplayId());
            if (inputDeviceDescriptor.getDisplayId() != getVirtualMousePointerDisplayId()) {
                setVirtualMousePointerDisplayId(inputDeviceDescriptor.getDisplayId());
            }
            return mNativeWrapper.writeButtonEvent(inputDeviceDescriptor.getNativePointer(),
                    event.getButtonCode(), event.getAction(), event.getEventTimeNanos());
@@ -380,10 +378,8 @@ class InputController {
            if (inputDeviceDescriptor == null) {
                return false;
            }
            if (inputDeviceDescriptor.getDisplayId()
                    != mInputManagerInternal.getVirtualMousePointerDisplayId()) {
                mInputManagerInternal.setVirtualMousePointerDisplayId(
                        inputDeviceDescriptor.getDisplayId());
            if (inputDeviceDescriptor.getDisplayId() != getVirtualMousePointerDisplayId()) {
                setVirtualMousePointerDisplayId(inputDeviceDescriptor.getDisplayId());
            }
            return mNativeWrapper.writeRelativeEvent(inputDeviceDescriptor.getNativePointer(),
                    event.getRelativeX(), event.getRelativeY(), event.getEventTimeNanos());
@@ -397,10 +393,8 @@ class InputController {
            if (inputDeviceDescriptor == null) {
                return false;
            }
            if (inputDeviceDescriptor.getDisplayId()
                    != mInputManagerInternal.getVirtualMousePointerDisplayId()) {
                mInputManagerInternal.setVirtualMousePointerDisplayId(
                        inputDeviceDescriptor.getDisplayId());
            if (inputDeviceDescriptor.getDisplayId() != getVirtualMousePointerDisplayId()) {
                setVirtualMousePointerDisplayId(inputDeviceDescriptor.getDisplayId());
            }
            return mNativeWrapper.writeScrollEvent(inputDeviceDescriptor.getNativePointer(),
                    event.getXAxisMovement(), event.getYAxisMovement(), event.getEventTimeNanos());
@@ -415,12 +409,11 @@ class InputController {
                throw new IllegalArgumentException(
                        "Could not get cursor position for input device for given token");
            }
            if (inputDeviceDescriptor.getDisplayId()
                    != mInputManagerInternal.getVirtualMousePointerDisplayId()) {
                mInputManagerInternal.setVirtualMousePointerDisplayId(
                        inputDeviceDescriptor.getDisplayId());
            if (inputDeviceDescriptor.getDisplayId() != getVirtualMousePointerDisplayId()) {
                setVirtualMousePointerDisplayId(inputDeviceDescriptor.getDisplayId());
            }
            return LocalServices.getService(InputManagerInternal.class).getCursorPosition();
            return LocalServices.getService(InputManagerInternal.class).getCursorPosition(
                    inputDeviceDescriptor.getDisplayId());
        }
    }

@@ -847,4 +840,22 @@ class InputController {
        /** Returns true if the calling thread is a valid thread for device creation. */
        boolean isValidThread();
    }

    // TODO(b/293587049): Remove after pointer icon refactor is complete.
    private void setVirtualMousePointerDisplayId(int displayId) {
        if (com.android.input.flags.Flags.enablePointerChoreographer()) {
            // We no longer need to set the pointer display when pointer choreographer is enabled.
            return;
        }
        mInputManagerInternal.setVirtualMousePointerDisplayId(displayId);
    }

    // TODO(b/293587049): Remove after pointer icon refactor is complete.
    private int getVirtualMousePointerDisplayId() {
        if (com.android.input.flags.Flags.enablePointerChoreographer()) {
            // We no longer need to get the pointer display when pointer choreographer is enabled.
            return Display.INVALID_DISPLAY;
        }
        return mInputManagerInternal.getVirtualMousePointerDisplayId();
    }
}
+5 −1
Original line number Diff line number Diff line
@@ -87,12 +87,16 @@ public abstract class InputManagerInternal {
     * connected, the caller may be blocked for an arbitrary period of time.
     *
     * @return true if the pointer displayId was set successfully, or false if it fails.
     *
     * @deprecated TODO(b/293587049): Not needed - remove after Pointer Icon Refactor is complete.
     */
    public abstract boolean setVirtualMousePointerDisplayId(int pointerDisplayId);

    /**
     * Gets the display id that the MouseCursorController is being forced to target. Returns
     * {@link android.view.Display#INVALID_DISPLAY} if there is no override
     *
     * @deprecated TODO(b/293587049): Not needed - remove after Pointer Icon Refactor is complete.
     */
    public abstract int getVirtualMousePointerDisplayId();

@@ -101,7 +105,7 @@ public abstract class InputManagerInternal {
     *
     * Returns NaN-s as the coordinates if the cursor is not available.
     */
    public abstract PointF getCursorPosition();
    public abstract PointF getCursorPosition(int displayId);

    /**
     * Enables or disables pointer acceleration for mouse movements.
+10 −2
Original line number Diff line number Diff line
@@ -1448,6 +1448,10 @@ public class InputManagerService extends IInputManager.Stub
    }

    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.
@@ -1486,6 +1490,10 @@ public class InputManagerService extends IInputManager.Stub
    }

    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;
        }
@@ -3332,8 +3340,8 @@ public class InputManagerService extends IInputManager.Stub
        }

        @Override
        public PointF getCursorPosition() {
            final float[] p = mNative.getMouseCursorPosition();
        public PointF getCursorPosition(int displayId) {
            final float[] p = mNative.getMouseCursorPosition(displayId);
            if (p == null || p.length != 2) {
                throw new IllegalStateException("Failed to get mouse cursor position");
            }
+5 −4
Original line number Diff line number Diff line
@@ -233,14 +233,15 @@ interface NativeInputManagerService {
    void setStylusButtonMotionEventsEnabled(boolean enabled);

    /**
     * Get the current position of the mouse cursor.
     * Get the current position of the mouse cursor on the given display.
     *
     * If the mouse cursor is not currently shown, the coordinate values will be NaN-s.
     * If the mouse cursor is not currently shown, the coordinate values will be NaN-s. Use
     * {@link android.view.Display#INVALID_DISPLAY} to get the position of the default mouse cursor.
     *
     * NOTE: This will grab the PointerController's lock, so we must be careful about calling this
     * from the InputReader or Display threads, which may result in a deadlock.
     */
    float[] getMouseCursorPosition();
    float[] getMouseCursorPosition(int displayId);

    /** Set whether showing a pointer icon for styluses is enabled. */
    void setStylusPointerIconEnabled(boolean enabled);
@@ -519,7 +520,7 @@ interface NativeInputManagerService {
        public native void setStylusButtonMotionEventsEnabled(boolean enabled);

        @Override
        public native float[] getMouseCursorPosition();
        public native float[] getMouseCursorPosition(int displayId);

        @Override
        public native void setStylusPointerIconEnabled(boolean enabled);
+9 −6
Original line number Diff line number Diff line
@@ -306,7 +306,7 @@ public:
    void setMotionClassifierEnabled(bool enabled);
    std::optional<std::string> getBluetoothAddress(int32_t deviceId);
    void setStylusButtonMotionEventsEnabled(bool enabled);
    FloatPoint getMouseCursorPosition();
    FloatPoint getMouseCursorPosition(int32_t displayId);
    void setStylusPointerIconEnabled(bool enabled);

    /* --- InputReaderPolicyInterface implementation --- */
@@ -1784,10 +1784,12 @@ void NativeInputManager::setStylusButtonMotionEventsEnabled(bool enabled) {
            InputReaderConfiguration::Change::STYLUS_BUTTON_REPORTING);
}

FloatPoint NativeInputManager::getMouseCursorPosition() {
FloatPoint NativeInputManager::getMouseCursorPosition(int32_t displayId) {
    if (ENABLE_POINTER_CHOREOGRAPHER) {
        return mInputManager->getChoreographer().getMouseCursorPosition(ADISPLAY_ID_NONE);
        return mInputManager->getChoreographer().getMouseCursorPosition(displayId);
    }
    // To maintain the status-quo, the displayId parameter (used when PointerChoreographer is
    // enabled) is ignored in the old pipeline.
    std::scoped_lock _l(mLock);
    const auto pc = mLocked.legacyPointerController.lock();
    if (!pc) return {AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION};
@@ -2751,9 +2753,10 @@ static void nativeSetStylusButtonMotionEventsEnabled(JNIEnv* env, jobject native
    im->setStylusButtonMotionEventsEnabled(enabled);
}

static jfloatArray nativeGetMouseCursorPosition(JNIEnv* env, jobject nativeImplObj) {
static jfloatArray nativeGetMouseCursorPosition(JNIEnv* env, jobject nativeImplObj,
                                                jint displayId) {
    NativeInputManager* im = getNativeInputManager(env, nativeImplObj);
    const auto p = im->getMouseCursorPosition();
    const auto p = im->getMouseCursorPosition(displayId);
    const std::array<float, 2> arr = {{p.x, p.y}};
    jfloatArray outArr = env->NewFloatArray(2);
    env->SetFloatArrayRegion(outArr, 0, arr.size(), arr.data());
@@ -2892,7 +2895,7 @@ static const JNINativeMethod gInputManagerMethods[] = {
        {"getBluetoothAddress", "(I)Ljava/lang/String;", (void*)nativeGetBluetoothAddress},
        {"setStylusButtonMotionEventsEnabled", "(Z)V",
         (void*)nativeSetStylusButtonMotionEventsEnabled},
        {"getMouseCursorPosition", "()[F", (void*)nativeGetMouseCursorPosition},
        {"getMouseCursorPosition", "(I)[F", (void*)nativeGetMouseCursorPosition},
        {"setStylusPointerIconEnabled", "(Z)V", (void*)nativeSetStylusPointerIconEnabled},
        {"setAccessibilityBounceKeysThreshold", "(I)V",
         (void*)nativeSetAccessibilityBounceKeysThreshold},
Loading