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

Commit 55a7ccb6 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

InputManagerInternal: Add API to get the last used input device

This will be used by the InputMethodManagerService to notify the IME of
the last input device type that was used to interact with Android when
the IME is shown. This API eliminates the need for IMMS to add another
global spy window to solve this problem.

Bug: 336615195
Test: atest inputflinger_tests
Change-Id: I29b25df7df47603a9c8a92bd192f7d81668d8605
parent 9d6d954f
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -218,4 +218,13 @@ public abstract class InputManagerInternal {
     * display, external peripherals, fingerprint sensor, etc.
     */
    public abstract void notifyUserActivity();

    /**
     * Get the device ID of the {@link InputDevice} that used most recently.
     *
     * @return the last used input device ID, or
     *     {@link android.os.IInputConstants#INVALID_INPUT_DEVICE_ID} if no device has been used
     *     since boot.
     */
    public abstract int getLastUsedInputDeviceId();
}
+5 −0
Original line number Diff line number Diff line
@@ -3204,6 +3204,11 @@ public class InputManagerService extends IInputManager.Stub
        public void setStylusButtonMotionEventsEnabled(boolean enabled) {
            mNative.setStylusButtonMotionEventsEnabled(enabled);
        }

        @Override
        public int getLastUsedInputDeviceId() {
            return mNative.getLastUsedInputDeviceId();
        }
    }

    @Override
+12 −0
Original line number Diff line number Diff line
@@ -271,6 +271,15 @@ interface NativeInputManagerService {

    void setInputMethodConnectionIsActive(boolean isActive);

    /**
     * Get the device ID of the InputDevice that used most recently.
     *
     * @return the last used input device ID, or
     *     {@link android.os.IInputConstants#INVALID_INPUT_DEVICE_ID} if no device has been used
     *     since boot.
     */
    int getLastUsedInputDeviceId();

    /** The native implementation of InputManagerService methods. */
    class NativeImpl implements NativeInputManagerService {
        /** Pointer to native input manager service object, used by native code. */
@@ -544,5 +553,8 @@ interface NativeInputManagerService {

        @Override
        public native void setInputMethodConnectionIsActive(boolean isActive);

        @Override
        public native int getLastUsedInputDeviceId();
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -2727,6 +2727,11 @@ static void nativeSetInputMethodConnectionIsActive(JNIEnv* env, jobject nativeIm
    im->setInputMethodConnectionIsActive(isActive);
}

static jint nativeGetLastUsedInputDeviceId(JNIEnv* env, jobject nativeImplObj) {
    NativeInputManager* im = getNativeInputManager(env, nativeImplObj);
    return static_cast<jint>(im->getInputManager()->getReader().getLastUsedInputDeviceId());
}

// ----------------------------------------------------------------------------

static const JNINativeMethod gInputManagerMethods[] = {
@@ -2835,6 +2840,7 @@ static const JNINativeMethod gInputManagerMethods[] = {
        {"setAccessibilityStickyKeysEnabled", "(Z)V",
         (void*)nativeSetAccessibilityStickyKeysEnabled},
        {"setInputMethodConnectionIsActive", "(Z)V", (void*)nativeSetInputMethodConnectionIsActive},
        {"getLastUsedInputDeviceId", "()I", (void*)nativeGetLastUsedInputDeviceId},
};

#define FIND_CLASS(var, className) \