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

Commit d0aa5ae5 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

Pointer Icon Refactor: Add displayId parameter to getCursorPosition

Now that we can have multiple mouse cursors on different displays, the
getCursorPosition() API needs to be updated accordingly.

Bug: 311651709
Test: atest InputControllerTest
Test: atest VirtualDeviceManagerServiceTest
Change-Id: I4074b3257f4bc9f7cb064558374c59ced9dcf7e2
parent 5737f20f
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -412,7 +412,8 @@ class InputController {
            if (inputDeviceDescriptor.getDisplayId() != getVirtualMousePointerDisplayId()) {
                setVirtualMousePointerDisplayId(inputDeviceDescriptor.getDisplayId());
            }
            return LocalServices.getService(InputManagerInternal.class).getCursorPosition();
            return LocalServices.getService(InputManagerInternal.class).getCursorPosition(
                    inputDeviceDescriptor.getDisplayId());
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -105,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.
+2 −2
Original line number Diff line number Diff line
@@ -3343,8 +3343,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
@@ -229,14 +229,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);
@@ -504,7 +505,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
@@ -307,7 +307,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 --- */
@@ -1764,10 +1764,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};
@@ -2717,9 +2719,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());
@@ -2847,7 +2850,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},