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

Commit 7979e1a8 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Log user IDs for both IME and IME-client in StartInputHistory

This is a follow up CL to my recent CL [1], which added an @hide API
EditorInfo#targetInputMethodUser for privileged components such as
System UI to be able to override the expected IME user, based on their
INTERACT_ACROSS_USERS_FULL permission.  This is critical for
per-profile IME mode and direct-reply to coexist.

To make it easier to diagnose this new scenario, this CL updates our
retrospective debugging mechanism called StartInputHistory [2].  With
this CL, InputMethodManagerService starts keeping track of both IME
user ID and IME client user ID for each StartInput so that we can see
them later into the StartInputHistory section of the bugreport.

For Direct-Reply scenario for instance, we would see a log like this:

  ... imeUserId=10 ... targetUserId=0 ...

There should be no user-visible behavior change.

 [1]: Ia7ea944438d69669ccdf9111b34ba400e786a602
      0f5eade4
 [2]: Icb29c4ef0703553ead8654d3255a554de6d1a9b4
      357b2f60

Bug: 35079353
Bug: 120744418
Test: Manually verified as follows.
  1. Build aosp_taimen-userdebug and flash it.
  2. adb shell pm create-user test_user
  3. adb shell am switch-user 10
  4. make -j EditTextVariations
  5. adb install -r \
       $ANDROID_TARGET_OUT_TESTCASES/EditTextVariations/EditTextVariations.apk
  6. adb shell am start \
       -n com.android.inputmethod.tools.edittextvariations/.EditTextVariations
  7. Tap the menu icon on the EditTextVariations then click "Direct Reply"
  8. Open notification shade.
  9. Tap reply icon on "Message from UserHandle{10}".
 10. Make sure that AOSP Keyboard is shown.
 11. adb shell dumpsys input_method
 12. Make sure that you can see both "imeUserId=10" and
     "targetUserId=0" in the last StartInputHistory.
Change-Id: Ica21e2f4cb41c7a5f4195f08f05220e2f65c1bf1
parent 557afbb6
Loading
Loading
Loading
Loading
+23 −7
Original line number Diff line number Diff line
@@ -667,6 +667,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        final int mSequenceNumber;
        final long mTimestamp;
        final long mWallTime;
        @UserIdInt
        final int mImeUserId;
        @NonNull
        final IBinder mImeToken;
        final int mImeDisplayId;
@@ -675,6 +677,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        @StartInputReason
        final int mStartInputReason;
        final boolean mRestarting;
        @UserIdInt
        final int mTargetUserId;
        final int mTargetDisplayId;
        @Nullable
        final IBinder mTargetWindow;
@@ -684,18 +688,21 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        final int mTargetWindowSoftInputMode;
        final int mClientBindSequenceNumber;

        StartInputInfo(@NonNull IBinder imeToken, int imeDisplayId, @NonNull String imeId,
                @StartInputReason int startInputReason, boolean restarting, int targetDisplayId,
                @Nullable IBinder targetWindow, @NonNull EditorInfo editorInfo,
                @SoftInputModeFlags int targetWindowSoftInputMode, int clientBindSequenceNumber) {
        StartInputInfo(@UserIdInt int imeUserId, @NonNull IBinder imeToken, int imeDisplayId,
                @NonNull String imeId, @StartInputReason int startInputReason, boolean restarting,
                @UserIdInt int targetUserId, int targetDisplayId, @Nullable IBinder targetWindow,
                @NonNull EditorInfo editorInfo, @SoftInputModeFlags int targetWindowSoftInputMode,
                int clientBindSequenceNumber) {
            mSequenceNumber = sSequenceNumber.getAndIncrement();
            mTimestamp = SystemClock.uptimeMillis();
            mWallTime = System.currentTimeMillis();
            mImeUserId = imeUserId;
            mImeToken = imeToken;
            mImeDisplayId = imeDisplayId;
            mImeId = imeId;
            mStartInputReason = startInputReason;
            mRestarting = restarting;
            mTargetUserId = targetUserId;
            mTargetDisplayId = targetDisplayId;
            mTargetWindow = targetWindow;
            mEditorInfo = editorInfo;
@@ -753,6 +760,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            int mSequenceNumber;
            long mTimestamp;
            long mWallTime;
            @UserIdInt
            int mImeUserId;
            @NonNull
            String mImeTokenString;
            int mImeDisplayId;
@@ -761,6 +770,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            @StartInputReason
            int mStartInputReason;
            boolean mRestarting;
            @UserIdInt
            int mTargetUserId;
            int mTargetDisplayId;
            @NonNull
            String mTargetWindowString;
@@ -778,6 +789,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                mSequenceNumber = original.mSequenceNumber;
                mTimestamp = original.mTimestamp;
                mWallTime = original.mWallTime;
                mImeUserId = original.mImeUserId;
                // Intentionally convert to String so as not to keep a strong reference to a Binder
                // object.
                mImeTokenString = String.valueOf(original.mImeToken);
@@ -785,6 +797,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                mImeId = original.mImeId;
                mStartInputReason = original.mStartInputReason;
                mRestarting = original.mRestarting;
                mTargetUserId = original.mTargetUserId;
                mTargetDisplayId = original.mTargetDisplayId;
                // Intentionally convert to String so as not to keep a strong reference to a Binder
                // object.
@@ -830,11 +843,13 @@ public class InputMethodManagerService extends IInputMethodManager.Stub

                pw.print(prefix);
                pw.print(" imeToken=" + entry.mImeTokenString + " [" + entry.mImeId + "]");
                pw.print(" imeUserId=" + entry.mImeUserId);
                pw.println(" imeDisplayId=" + entry.mImeDisplayId);

                pw.print(prefix);
                pw.println(" targetWin=" + entry.mTargetWindowString
                        + " [" + entry.mEditorInfo.packageName + "]"
                        + " targetUserId=" + entry.mTargetUserId
                        + " targetDisplayId=" + entry.mTargetDisplayId
                        + " clientBindSeq=" + entry.mClientBindSequenceNumber);

@@ -1914,9 +1929,10 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        }

        final Binder startInputToken = new Binder();
        final StartInputInfo info = new StartInputInfo(mCurToken, mCurTokenDisplayId, mCurId,
                startInputReason, !initial, mCurClient.selfReportedDisplayId, mCurFocusedWindow,
                mCurAttribute, mCurFocusedWindowSoftInputMode, mCurSeq);
        final StartInputInfo info = new StartInputInfo(mSettings.getCurrentUserId(), mCurToken,
                mCurTokenDisplayId, mCurId, startInputReason, !initial,
                UserHandle.getUserId(mCurClient.uid), mCurClient.selfReportedDisplayId,
                mCurFocusedWindow, mCurAttribute, mCurFocusedWindowSoftInputMode, mCurSeq);
        mImeTargetWindowMap.put(startInputToken, mCurFocusedWindow);
        mStartInputHistory.addEntry(info);