Clear SHOW_FORCED flag when the app's targetSdk >= T
As the legacy flag SHOW_FORCED when calling showSoftInput keeps
remaining soft-keyboard visible, even though switching focus to another
application the situation still remains, unless someone calls
hideSoftInputFromWindow explicitly.
In case SHOW_FORCED flag affects the next client to keep IME visible and
hard to handle for the app developer, we introduce a platform
compatibility flag, when enabled, if the current client is leaving due
to the next focused client, in IMMS side will clear mShowForced flag when
the next client's targetSdkVersion is T or higher.
Also, deprecated SHOW_FORCED flag with updating the reason in
the documentation.
Fix: 214016041
Test: atest KeyboardVisibilityControlTest#\
testShowSoftInputWithShowForcedFlagWhenAppIsLeaving
Change-Id: I47efe5cb02ba69cbe018619e5bdc8f3995a55b4b
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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.");
|
||||
|
||||
Reference in New Issue
Block a user