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

Commit ce3d956b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I807608d5,I4ccc56f3,I8aa75851,I09022bb2

* changes:
  Simplify IMMS#startInputOrWindowGainedFocusInternal() part 3/5
  Simplify IMMS#startInputOrWindowGainedFocusInternal() part 2/5
  Simplify IMMS#startInputOrWindowGainedFocusInternal() part 1/5
  Fix a typo in an error message in InputMethodManagerService
parents 1e7328e3 13dc12f8
Loading
Loading
Loading
Loading
+216 −216
Original line number Diff line number Diff line
@@ -2757,33 +2757,12 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            Slog.e(TAG, "windowToken cannot be null.");
            return InputBindResult.NULL;
        }
        final InputBindResult result = startInputOrWindowGainedFocusInternal(startInputReason,
                client, windowToken, startInputFlags, softInputMode, windowFlags, attribute,
                inputContext, missingMethods, unverifiedTargetSdkVersion);
        if (result == null) {
            // This must never happen, but just in case.
            Slog.wtf(TAG, "InputBindResult is @NonNull. startInputReason="
                    + InputMethodDebug.startInputReasonToString(startInputReason)
                    + " windowFlags=#" + Integer.toHexString(windowFlags)
                    + " editorInfo=" + attribute);
            return InputBindResult.NULL;
        }
        return result;
    }

    @NonNull
    private InputBindResult startInputOrWindowGainedFocusInternal(
            @StartInputReason int startInputReason, IInputMethodClient client,
            @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.user requires 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
@@ -2795,13 +2774,39 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        } else {
            userId = callingUserId;
        }
        InputBindResult res = null;
        final InputBindResult result;
        synchronized (mMethodMap) {
            final int windowDisplayId =
                    mWindowManagerInternal.getDisplayIdForWindow(windowToken);
            final long ident = Binder.clearCallingIdentity();
            try {
                if (DEBUG) Slog.v(TAG, "startInputOrWindowGainedFocusInternal: reason="
                result = startInputOrWindowGainedFocusInternalLocked(startInputReason, client,
                        windowToken, startInputFlags, softInputMode, windowFlags, attribute,
                        inputContext, missingMethods, unverifiedTargetSdkVersion, userId);
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
        }
        if (result == null) {
            // This must never happen, but just in case.
            Slog.wtf(TAG, "InputBindResult is @NonNull. startInputReason="
                    + InputMethodDebug.startInputReasonToString(startInputReason)
                    + " windowFlags=#" + Integer.toHexString(windowFlags)
                    + " editorInfo=" + attribute);
            return InputBindResult.NULL;
        }
        return result;
    }

    @NonNull
    private InputBindResult startInputOrWindowGainedFocusInternalLocked(
            @StartInputReason int startInputReason, IInputMethodClient client,
            @NonNull IBinder windowToken, @StartInputFlags int startInputFlags,
            @SoftInputModeFlags int softInputMode, int windowFlags, EditorInfo attribute,
            IInputContext inputContext, @MissingMethodFlags int missingMethods,
            int unverifiedTargetSdkVersion, @UserIdInt int userId) {
        InputBindResult res = null;
        final int windowDisplayId =
                mWindowManagerInternal.getDisplayIdForWindow(windowToken);
        if (DEBUG) Slog.v(TAG, "startInputOrWindowGainedFocusInternalLocked: reason="
                + InputMethodDebug.startInputReasonToString(startInputReason)
                + " client=" + client.asBinder()
                + " inputContext=" + inputContext
@@ -3003,11 +3008,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                res = InputBindResult.NULL_EDITOR_INFO;
            }
        }
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
        }

        return res;
    }