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

Commit 4391c204 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Simplify IMMS#startInputOrWindowGainedFocusInternal() part 1/5

This is a series of CLs to reduce the average indentation level of
InputMethodManagerService#startInputOrWindowGainedFocusInternal().

Currently the method in questions has a relatively high indentation
level.  As a preparation to reduce the indentation level, this CL
moves user ID resolution logic from
  IMMS#startInputOrWindowGainedFocusInternal()
to
  IMMS#startInputOrWindowGainedFocus().

This is a mechanical refactoring.  There should be no behavior change.

Bug: 34886274
Test: atest CtsInputMethodTestCases CtsInputMethodServiceHostTestCases
Change-Id: I8aa758519bdf65cdb9ec5964f6b8e7b5a857e269
parent 670abea2
Loading
Loading
Loading
Loading
+21 −22
Original line number Diff line number Diff line
@@ -2755,9 +2755,26 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            Slog.e(TAG, "windowToken cannot be null.");
            return InputBindResult.NULL;
        }
        final int callingUserId = UserHandle.getCallingUserId();
        final int userId;
        if (attribute != null && attribute.targetInputMethodUser != null
                && attribute.targetInputMethodUser.getIdentifier() != callingUserId) {
            mContext.enforceCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL,
                    "Using EditorInfo.targetInputMethodUser requires INTERACT_ACROSS_USERS_FULL.");
            userId = attribute.targetInputMethodUser.getIdentifier();
            if (!mUserManagerInternal.isUserRunning(userId)) {
                // There is a chance that we hit here because of race condition.  Let's just return
                // an error code instead of crashing the caller process, which at least has
                // INTERACT_ACROSS_USERS_FULL permission thus is likely to be an important process.
                Slog.e(TAG, "User #" + userId + " is not running.");
                return InputBindResult.INVALID_USER;
            }
        } else {
            userId = callingUserId;
        }
        final InputBindResult result = startInputOrWindowGainedFocusInternal(startInputReason,
                client, windowToken, startInputFlags, softInputMode, windowFlags, attribute,
                inputContext, missingMethods, unverifiedTargetSdkVersion);
                inputContext, missingMethods, unverifiedTargetSdkVersion, userId);
        if (result == null) {
            // This must never happen, but just in case.
            Slog.wtf(TAG, "InputBindResult is @NonNull. startInputReason="
@@ -2775,26 +2792,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            @NonNull IBinder windowToken, @StartInputFlags int startInputFlags,
            @SoftInputModeFlags int softInputMode, int windowFlags, EditorInfo attribute,
            IInputContext inputContext, @MissingMethodFlags int missingMethods,
            int unverifiedTargetSdkVersion) {
        final int callingUserId = UserHandle.getCallingUserId();
        final int userId;
        if (attribute != null && attribute.targetInputMethodUser != null
                && attribute.targetInputMethodUser.getIdentifier() != callingUserId) {
            mContext.enforceCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL,
                    "Using EditorInfo.targetInputMethodUser requires INTERACT_ACROSS_USERS_FULL.");
            userId = attribute.targetInputMethodUser.getIdentifier();
            if (!mUserManagerInternal.isUserRunning(userId)) {
                // There is a chance that we hit here because of race condition.  Let's just return
                // an error code instead of crashing the caller process, which at least has
                // INTERACT_ACROSS_USERS_FULL permission thus is likely to be an important process.
                Slog.e(TAG, "User #" + userId + " is not running.");
                return InputBindResult.INVALID_USER;
            }
        } else {
            userId = callingUserId;
        }
        InputBindResult res = null;
            int unverifiedTargetSdkVersion, @UserIdInt int userId) {
        synchronized (mMethodMap) {
            InputBindResult res = null;
            final int windowDisplayId =
                    mWindowManagerInternal.getDisplayIdForWindow(windowToken);
            final long ident = Binder.clearCallingIdentity();
@@ -3004,10 +3004,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
        }

            return res;
        }
    }

    private boolean canShowInputMethodPickerLocked(IInputMethodClient client) {
        // TODO(yukawa): multi-display support.