diff options
5 files changed, 45 insertions, 1 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index ddfbb44e44a6..4ad6da69a799 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -53105,7 +53105,7 @@ package android.view.inputmethod { field public static final int RESULT_SHOWN = 2; // 0x2 field public static final int RESULT_UNCHANGED_HIDDEN = 1; // 0x1 field public static final int RESULT_UNCHANGED_SHOWN = 0; // 0x0 - field public static final int SHOW_FORCED = 2; // 0x2 + field @Deprecated public static final int SHOW_FORCED = 2; // 0x2 field public static final int SHOW_IMPLICIT = 1; // 0x1 } diff --git a/core/api/test-current.txt b/core/api/test-current.txt index 9757b2ff318f..f0a8b9e68b70 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -3082,6 +3082,7 @@ package android.view.inputmethod { method @NonNull @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) public java.util.List<android.view.inputmethod.InputMethodInfo> getInputMethodListAsUser(int); method public boolean hasActiveInputConnection(@Nullable android.view.View); method public boolean isInputMethodPickerShown(); + field public static final long CLEAR_SHOW_FORCED_FLAG_WHEN_LEAVING = 214016041L; // 0xcc1a029L } } diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java index 27174630bfa3..017b8aa3cf6c 100644 --- a/core/java/android/view/inputmethod/InputMethodManager.java +++ b/core/java/android/view/inputmethod/InputMethodManager.java @@ -46,6 +46,8 @@ import android.annotation.SystemService; import android.annotation.TestApi; import android.annotation.UserIdInt; import android.app.ActivityThread; +import android.compat.annotation.ChangeId; +import android.compat.annotation.EnabledSince; import android.compat.annotation.UnsupportedAppUsage; import android.content.ComponentName; import android.content.ContentResolver; @@ -356,6 +358,21 @@ public final class InputMethodManager { /** @hide */ public static final int SHOW_IM_PICKER_MODE_EXCLUDE_AUXILIARY_SUBTYPES = 2; + /** + * Clear {@link #SHOW_FORCED} flag when the next IME focused application changed. + * + * <p> + * Note that when this flag enabled in server side, {@link #SHOW_FORCED} will no longer + * affect the next focused application to keep showing IME, in case of unexpected IME visible + * when the next focused app isn't be the IME requester. </p> + * + * @hide + */ + @TestApi + @ChangeId + @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) + public static final long CLEAR_SHOW_FORCED_FLAG_WHEN_LEAVING = 214016041L; // This is a bug id. + @UnsupportedAppUsage final IInputMethodManager mService; final Looper mMainLooper; @@ -1646,7 +1663,14 @@ public final class InputMethodManager { * Flag for {@link #showSoftInput} to indicate that the user has forced * the input method open (such as by long-pressing menu) so it should * not be closed until they explicitly do so. + * + * @deprecated Use {@link #showSoftInput} without this flag instead. Using this flag can lead + * to the soft input remaining visible even when the calling application is closed. The + * use of this flag can make the soft input remains visible globally. Starting in + * {@link Build.VERSION_CODES#TIRAMISU Android T}, this flag only has an effect while the + * caller is currently focused. */ + @Deprecated public static final int SHOW_FORCED = 0x0002; /** diff --git a/services/core/java/com/android/server/inputmethod/ImePlatformCompatUtils.java b/services/core/java/com/android/server/inputmethod/ImePlatformCompatUtils.java index ae77b9dc5c82..83ca16d72c9b 100644 --- a/services/core/java/com/android/server/inputmethod/ImePlatformCompatUtils.java +++ b/services/core/java/com/android/server/inputmethod/ImePlatformCompatUtils.java @@ -17,6 +17,7 @@ package com.android.server.inputmethod; import static android.inputmethodservice.InputMethodService.FINISH_INPUT_NO_FALLBACK_CONNECTION; +import static android.view.inputmethod.InputMethodManager.CLEAR_SHOW_FORCED_FLAG_WHEN_LEAVING; import android.content.Context; import android.os.RemoteException; @@ -42,6 +43,16 @@ final class ImePlatformCompatUtils { return isChangeEnabledByUid(FINISH_INPUT_NO_FALLBACK_CONNECTION, imeUid); } + /** + * Whether to clear {@link android.view.inputmethod.InputMethodManager#SHOW_FORCED} flag + * when the next IME focused application changed. + * + * @param clientUid The uid of the app + */ + public boolean shouldClearShowForcedFlag(int clientUid) { + return isChangeEnabledByUid(CLEAR_SHOW_FORCED_FLAG_WHEN_LEAVING, clientUid); + } + private boolean isChangeEnabledByUid(long changeFlag, int uid) { boolean result = false; try { diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index afcbd8984e1d..eb1de2a9bf91 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -3617,6 +3617,14 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub return InputBindResult.INVALID_USER; } + final boolean shouldClearFlag = mImePlatformCompatUtils.shouldClearShowForcedFlag(cs.uid); + // In case mShowForced flag affects the next client to keep IME visible, when the current + // client is leaving due to the next focused client, we clear mShowForced flag when the + // next client's targetSdkVersion is T or higher. + if (mCurFocusedWindow != windowToken && mShowForced && shouldClearFlag) { + mShowForced = false; + } + // cross-profile access is always allowed here to allow profile-switching. if (!mSettings.isCurrentProfile(userId)) { Slog.w(TAG, "A background user is requesting window. Hiding IME."); |