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

Commit 4602686e authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

Notify InputManagerService when an IME is active

Whether the IME is active will determine the tracing level used for
input events on debuggable builds.

Bug: 210460522
Test: manual with perfetto
Change-Id: Iee946285b705e60c87da6e6ee65cc05954c583ae
parent bb7a2170
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -141,6 +141,11 @@ public abstract class InputManagerInternal {
     */
    public abstract void unregisterLidSwitchCallback(@NonNull LidSwitchCallback callbacks);

    /**
     * Notify the input manager that an IME connection is becoming active or is no longer active.
     */
    public abstract void notifyInputMethodConnectionActive(boolean connectionIsActive);

    /** Callback interface for notifications relating to the lid switch. */
    public interface LidSwitchCallback {
        /**
+5 −0
Original line number Diff line number Diff line
@@ -3300,6 +3300,11 @@ public class InputManagerService extends IInputManager.Stub
            unregisterLidSwitchCallbackInternal(callbacks);
        }

        @Override
        public void notifyInputMethodConnectionActive(boolean connectionIsActive) {
            mNative.setInputMethodConnectionIsActive(connectionIsActive);
        }

        @Override
        public InputChannel createInputChannel(String inputChannelName) {
            return InputManagerService.this.createInputChannel(inputChannelName);
+5 −0
Original line number Diff line number Diff line
@@ -273,6 +273,8 @@ interface NativeInputManagerService {
     */
    void setAccessibilityStickyKeysEnabled(boolean enabled);

    void setInputMethodConnectionIsActive(boolean isActive);

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

        @Override
        public native void setAccessibilityStickyKeysEnabled(boolean enabled);

        @Override
        public native void setInputMethodConnectionIsActive(boolean isActive);
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -2156,6 +2156,8 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
            prepareClientSwitchLocked(cs);
        }

        final boolean connectionWasActive = mCurInputConnection != null;

        // Bump up the sequence for this client and attach it.
        advanceSequenceNumberLocked();
        mCurClient = cs;
@@ -2174,6 +2176,12 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
        }
        mCurEditorInfo = editorInfo;

        // Notify input manager if the connection state changes.
        final boolean connectionIsActive = mCurInputConnection != null;
        if (connectionIsActive != connectionWasActive) {
            mInputManagerInternal.notifyInputMethodConnectionActive(connectionIsActive);
        }

        // If configured, we want to avoid starting up the IME if it is not supposed to be showing
        if (shouldPreventImeStartupLocked(selectedMethodId, startInputFlags,
                unverifiedTargetSdkVersion)) {
+7 −0
Original line number Diff line number Diff line
@@ -2854,6 +2854,12 @@ static void nativeSetAccessibilityStickyKeysEnabled(JNIEnv* env, jobject nativeI
    }
}

static void nativeSetInputMethodConnectionIsActive(JNIEnv* env, jobject nativeImplObj,
                                                   jboolean isActive) {
    NativeInputManager* im = getNativeInputManager(env, nativeImplObj);
    im->getInputManager()->getDispatcher().setInputMethodConnectionIsActive(isActive);
}

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

static const JNINativeMethod gInputManagerMethods[] = {
@@ -2964,6 +2970,7 @@ static const JNINativeMethod gInputManagerMethods[] = {
         (void*)nativeSetAccessibilitySlowKeysThreshold},
        {"setAccessibilityStickyKeysEnabled", "(Z)V",
         (void*)nativeSetAccessibilityStickyKeysEnabled},
        {"setInputMethodConnectionIsActive", "(Z)V", (void*)nativeSetInputMethodConnectionIsActive},
};

#define FIND_CLASS(var, className) \