diff options
| author | 2022-07-27 05:04:11 +0000 | |
|---|---|---|
| committer | 2022-07-27 05:04:11 +0000 | |
| commit | 6ef60a6c04e6989d620265a275b328646e4d8fde (patch) | |
| tree | 68a6c707b383593a0982a08d853683e995cffce3 | |
| parent | eb1e6ac0e9015418c9170ac0f707e7589e38aace (diff) | |
| parent | d6ce057f18ad18a6f80b9ecef3f93dc55b7f83a4 (diff) | |
Merge "Let startInputOrWindowGainedFocus() take userId"
4 files changed, 35 insertions, 29 deletions
diff --git a/core/java/android/view/inputmethod/IInputMethodManagerInvoker.java b/core/java/android/view/inputmethod/IInputMethodManagerInvoker.java index 8dbaec403de6..60edf357a53d 100644 --- a/core/java/android/view/inputmethod/IInputMethodManagerInvoker.java +++ b/core/java/android/view/inputmethod/IInputMethodManagerInvoker.java @@ -139,11 +139,13 @@ final class IInputMethodManagerInvoker { @WindowManager.LayoutParams.Flags int windowFlags, @Nullable EditorInfo editorInfo, @Nullable IRemoteInputConnection remoteInputConnection, @Nullable IRemoteAccessibilityInputConnection remoteAccessibilityInputConnection, - int unverifiedTargetSdkVersion, @NonNull ImeOnBackInvokedDispatcher imeDispatcher) { + int unverifiedTargetSdkVersion, @UserIdInt int userId, + @NonNull ImeOnBackInvokedDispatcher imeDispatcher) { try { return mTarget.startInputOrWindowGainedFocus(startInputReason, client, windowToken, startInputFlags, softInputMode, windowFlags, editorInfo, remoteInputConnection, - remoteAccessibilityInputConnection, unverifiedTargetSdkVersion, imeDispatcher); + remoteAccessibilityInputConnection, unverifiedTargetSdkVersion, userId, + imeDispatcher); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java index b016157ec9fd..8ce134e7e101 100644 --- a/core/java/android/view/inputmethod/InputMethodManager.java +++ b/core/java/android/view/inputmethod/InputMethodManager.java @@ -285,9 +285,10 @@ public final class InputMethodManager { private static final String SUBTYPE_MODE_VOICE = "voice"; /** - * Provide this to {@link IInputMethodManager#startInputOrWindowGainedFocus( - * int, IInputMethodClient, IBinder, int, int, int, EditorInfo, - * com.android.internal.inputmethod.IRemoteInputConnection, int)} to receive + * Provide this to {@link IInputMethodManagerInvoker#startInputOrWindowGainedFocus(int, + * IInputMethodClient, IBinder, int, int, int, EditorInfo, + * com.android.internal.inputmethod.IRemoteInputConnection, IRemoteAccessibilityInputConnection, + * int, int, ImeOnBackInvokedDispatcher)} to receive * {@link android.window.OnBackInvokedCallback} registrations from IME. */ private final ImeOnBackInvokedDispatcher mImeDispatcher = @@ -790,7 +791,7 @@ public final class InputMethodManager { null, null, null, mCurRootView.mContext.getApplicationInfo().targetSdkVersion, - mImeDispatcher); + UserHandle.myUserId(), mImeDispatcher); } } @@ -2437,12 +2438,14 @@ public final class InputMethodManager { } return false; } + final int targetUserId = editorInfo.targetInputMethodUser != null + ? editorInfo.targetInputMethodUser.getIdentifier() : UserHandle.myUserId(); res = mServiceInvoker.startInputOrWindowGainedFocus( startInputReason, mClient, windowGainingFocus, startInputFlags, softInputMode, windowFlags, editorInfo, servedInputConnection, servedInputConnection == null ? null : servedInputConnection.asIRemoteAccessibilityInputConnection(), - view.getContext().getApplicationInfo().targetSdkVersion, + view.getContext().getApplicationInfo().targetSdkVersion, targetUserId, mImeDispatcher); if (DEBUG) Log.v(TAG, "Starting input: Bind result=" + res); if (res == null) { diff --git a/core/java/com/android/internal/view/IInputMethodManager.aidl b/core/java/com/android/internal/view/IInputMethodManager.aidl index cbfa0e245003..eb8b8603cc30 100644 --- a/core/java/com/android/internal/view/IInputMethodManager.aidl +++ b/core/java/com/android/internal/view/IInputMethodManager.aidl @@ -72,7 +72,8 @@ interface IInputMethodManager { /* @android.view.WindowManager.LayoutParams.Flags */ int windowFlags, in @nullable EditorInfo editorInfo, in @nullable IRemoteInputConnection inputConnection, in @nullable IRemoteAccessibilityInputConnection remoteAccessibilityInputConnection, - int unverifiedTargetSdkVersion, in ImeOnBackInvokedDispatcher imeDispatcher); + int unverifiedTargetSdkVersion, int userId, + in ImeOnBackInvokedDispatcher imeDispatcher); void showInputMethodPickerFromClient(in IInputMethodClient client, int auxiliarySubtypeMode); diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index dea13f948aa9..bbf9410ae63d 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -3574,8 +3574,18 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub int windowFlags, @Nullable EditorInfo editorInfo, IRemoteInputConnection inputConnection, IRemoteAccessibilityInputConnection remoteAccessibilityInputConnection, - int unverifiedTargetSdkVersion, + int unverifiedTargetSdkVersion, @UserIdInt int userId, @NonNull ImeOnBackInvokedDispatcher imeDispatcher) { + if (UserHandle.getCallingUserId() != userId) { + mContext.enforceCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL, null); + + if (editorInfo == null || editorInfo.targetInputMethodUser == null + || editorInfo.targetInputMethodUser.getIdentifier() != userId) { + throw new InvalidParameterException("EditorInfo#targetInputMethodUser must also be " + + "specified for cross-user startInputOrWindowGainedFocus()"); + } + } + if (windowToken == null) { Slog.e(TAG, "windowToken cannot be null."); return InputBindResult.NULL; @@ -3585,26 +3595,6 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub "IMMS.startInputOrWindowGainedFocus"); ImeTracing.getInstance().triggerManagerServiceDump( "InputMethodManagerService#startInputOrWindowGainedFocus"); - final int callingUserId = UserHandle.getCallingUserId(); - final int userId; - if (editorInfo != null && editorInfo.targetInputMethodUser != null - && editorInfo.targetInputMethodUser.getIdentifier() != callingUserId) { - mContext.enforceCallingPermission( - Manifest.permission.INTERACT_ACROSS_USERS_FULL, - "Using EditorInfo.targetInputMethodUser requires" - + " INTERACT_ACROSS_USERS_FULL."); - userId = editorInfo.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; synchronized (ImfLock.class) { final long ident = Binder.clearCallingIdentity(); @@ -3653,9 +3643,19 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub + " softInputMode=" + InputMethodDebug.softInputModeToString(softInputMode) + " windowFlags=#" + Integer.toHexString(windowFlags) + " unverifiedTargetSdkVersion=" + unverifiedTargetSdkVersion + + " userId=" + userId + " imeDispatcher=" + imeDispatcher); } + 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.w(TAG, "User #" + userId + " is not running."); + return InputBindResult.INVALID_USER; + } + final ClientState cs = mClients.get(client.asBinder()); if (cs == null) { throw new IllegalArgumentException("unknown client " + client.asBinder()); |