diff options
| author | 2022-10-17 01:13:38 +0800 | |
|---|---|---|
| committer | 2023-01-09 05:43:01 +0000 | |
| commit | 351bf0fa35fd563ce2d99229a4cdc78a7d3ef76f (patch) | |
| tree | 1b2bea098b61cb85d75a29c3bebe15956bfdf73c | |
| parent | baebf0fecf959b93981fbf43e6c7fa156cdbdbea (diff) | |
Migrate to IME visibility settings
Move following fields from IMMS to ImeVisibilityComputer.ImePolicy
- mImeHiddenByDisplayPolicy
- mAccessibilityRequestingNoKeyboard
Bug: 246309664
Test: atest CtsInputMethodTestCases
Change-Id: I2aea907b60f51829fbe8c1e8386dab77388e9694
| -rw-r--r-- | services/core/java/com/android/server/inputmethod/ImeVisibilityStateComputer.java | 37 | ||||
| -rw-r--r-- | services/core/java/com/android/server/inputmethod/InputMethodManagerService.java | 34 |
2 files changed, 41 insertions, 30 deletions
diff --git a/services/core/java/com/android/server/inputmethod/ImeVisibilityStateComputer.java b/services/core/java/com/android/server/inputmethod/ImeVisibilityStateComputer.java index 237499584300..8a90ae02b357 100644 --- a/services/core/java/com/android/server/inputmethod/ImeVisibilityStateComputer.java +++ b/services/core/java/com/android/server/inputmethod/ImeVisibilityStateComputer.java @@ -16,6 +16,8 @@ package com.android.server.inputmethod; +import static android.accessibilityservice.AccessibilityService.SHOW_MODE_HIDDEN; +import static android.server.inputmethod.InputMethodManagerServiceProto.ACCESSIBILITY_REQUESTING_NO_SOFT_KEYBOARD; import static android.server.inputmethod.InputMethodManagerServiceProto.SHOW_EXPLICITLY_REQUESTED; import static android.server.inputmethod.InputMethodManagerServiceProto.SHOW_FORCED; import static android.view.Display.DEFAULT_DISPLAY; @@ -24,6 +26,7 @@ import static android.view.WindowManager.LayoutParams.SoftInputModeFlags; import static com.android.internal.inputmethod.InputMethodDebug.softInputModeToString; +import android.accessibilityservice.AccessibilityService; import android.annotation.IntDef; import android.annotation.NonNull; import android.os.IBinder; @@ -123,14 +126,21 @@ public final class ImeVisibilityStateComputer { * @param statsToken The token for tracking this show request * @param showFlags The additional operation flags to indicate whether this show request mode is * implicit or explicit. + * @return {@code true} when the computer has proceed this show request operation. */ - void onImeShowFlags(int showFlags) { + boolean onImeShowFlags(@NonNull ImeTracker.Token statsToken, int showFlags) { + if (mPolicy.mA11yRequestingNoSoftKeyboard || mPolicy.mImeHiddenByDisplayPolicy) { + ImeTracker.get().onFailed(statsToken, ImeTracker.PHASE_SERVER_ACCESSIBILITY); + return false; + } + ImeTracker.get().onProgress(statsToken, ImeTracker.PHASE_SERVER_ACCESSIBILITY); if ((showFlags & InputMethodManager.SHOW_FORCED) != 0) { mRequestedShowExplicitly = true; mShowForced = true; } else if ((showFlags & InputMethodManager.SHOW_IMPLICIT) == 0) { mRequestedShowExplicitly = true; } + return true; } /** @@ -229,12 +239,15 @@ public final class ImeVisibilityStateComputer { void dumpDebug(ProtoOutputStream proto, long fieldId) { proto.write(SHOW_EXPLICITLY_REQUESTED, mRequestedShowExplicitly); proto.write(SHOW_FORCED, mShowForced); + proto.write(ACCESSIBILITY_REQUESTING_NO_SOFT_KEYBOARD, + mPolicy.isA11yRequestNoSoftKeyboard()); } void dump(PrintWriter pw) { final Printer p = new PrintWriterPrinter(pw); p.println(" mRequestedShowExplicitly=" + mRequestedShowExplicitly + " mShowForced=" + mShowForced); + p.println(" mImeHiddenByDisplayPolicy=" + mPolicy.isImeHiddenByDisplayPolicy()); } /** @@ -254,17 +267,31 @@ public final class ImeVisibilityStateComputer { private boolean mImeHiddenByDisplayPolicy; /** - * Set when a11y requests to hide IME by A11yService#setShowMode(SHOW_MODE_HIDDEN) + * Set when the accessibility service requests to hide IME by + * {@link AccessibilityService.SoftKeyboardController#setShowMode} */ - private boolean mAccessibilityRequestingNoSoftKeyboard; + private boolean mA11yRequestingNoSoftKeyboard; void setImeHiddenByDisplayPolicy(boolean hideIme) { mImeHiddenByDisplayPolicy = hideIme; } - void setA11yRequestNoSoftKeyboard(boolean a11yRequestNoIme) { - mAccessibilityRequestingNoSoftKeyboard = a11yRequestNoIme; + boolean isImeHiddenByDisplayPolicy() { + return mImeHiddenByDisplayPolicy; + } + + void setA11yRequestNoSoftKeyboard(int keyboardShowMode) { + mA11yRequestingNoSoftKeyboard = + (keyboardShowMode & AccessibilityService.SHOW_MODE_MASK) == SHOW_MODE_HIDDEN; } + + boolean isA11yRequestNoSoftKeyboard() { + return mA11yRequestingNoSoftKeyboard; + } + } + + ImeVisibilityPolicy getImePolicy() { + return mPolicy; } /** diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 5ca08b878f9d..f26a9bb0f632 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -20,7 +20,6 @@ import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_CRITICAL; import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_NORMAL; import static android.os.IServiceManager.DUMP_FLAG_PROTO; import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; -import static android.server.inputmethod.InputMethodManagerServiceProto.ACCESSIBILITY_REQUESTING_NO_SOFT_KEYBOARD; import static android.server.inputmethod.InputMethodManagerServiceProto.BACK_DISPOSITION; import static android.server.inputmethod.InputMethodManagerServiceProto.BOUND_TO_METHOD; import static android.server.inputmethod.InputMethodManagerServiceProto.CUR_ATTRIBUTE; @@ -54,7 +53,6 @@ import static com.android.server.inputmethod.InputMethodUtils.isSoftInputModeSta import static java.lang.annotation.RetentionPolicy.SOURCE; import android.Manifest; -import android.accessibilityservice.AccessibilityService; import android.annotation.AnyThread; import android.annotation.BinderThread; import android.annotation.DrawableRes; @@ -531,13 +529,6 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub } /** - * {@code true} if the Ime policy has been set to {@link WindowManager#DISPLAY_IME_POLICY_HIDE}. - * - * This prevents the IME from showing when it otherwise may have shown. - */ - boolean mImeHiddenByDisplayPolicy; - - /** * The client that is currently bound to an input method. */ private ClientState mCurClient; @@ -777,7 +768,6 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub int mImeWindowVis; private LocaleList mLastSystemLocales; - private boolean mAccessibilityRequestingNoSoftKeyboard; private final MyPackageMonitor mMyPackageMonitor = new MyPackageMonitor(); private final String mSlotIme; @@ -1182,11 +1172,10 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub } else if (accessibilityRequestingNoImeUri.equals(uri)) { final int accessibilitySoftKeyboardSetting = Settings.Secure.getIntForUser( mContext.getContentResolver(), - Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE, 0 /* def */, mUserId); - mAccessibilityRequestingNoSoftKeyboard = - (accessibilitySoftKeyboardSetting & AccessibilityService.SHOW_MODE_MASK) - == AccessibilityService.SHOW_MODE_HIDDEN; - if (mAccessibilityRequestingNoSoftKeyboard) { + Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE, 0, mUserId); + mVisibilityStateComputer.getImePolicy().setA11yRequestNoSoftKeyboard( + accessibilitySoftKeyboardSetting); + if (mVisibilityStateComputer.getImePolicy().isA11yRequestNoSoftKeyboard()) { final boolean showRequested = mShowRequested; hideCurrentInputLocked(mCurFocusedWindow, null /* statsToken */, 0 /* flags */, null /* resultReceiver */, @@ -2477,15 +2466,15 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub // session & other conditions. mDisplayIdToShowIme = computeImeDisplayIdForTarget(cs.mSelfReportedDisplayId, mImeDisplayValidator); + final boolean imeHiddenByPolicy = mDisplayIdToShowIme == INVALID_DISPLAY; + mVisibilityStateComputer.getImePolicy().setImeHiddenByDisplayPolicy(imeHiddenByPolicy); - if (mDisplayIdToShowIme == INVALID_DISPLAY) { - mImeHiddenByDisplayPolicy = true; + if (imeHiddenByPolicy) { hideCurrentInputLocked(mCurFocusedWindow, null /* statsToken */, 0 /* flags */, null /* resultReceiver */, SoftInputShowHideReason.HIDE_DISPLAY_IME_POLICY_HIDE); return InputBindResult.NO_IME; } - mImeHiddenByDisplayPolicy = false; if (mCurClient != cs) { prepareClientSwitchLocked(cs); @@ -3383,13 +3372,11 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub // TODO(b/246309664): make mShowRequested as per-window state. mShowRequested = true; - if (mAccessibilityRequestingNoSoftKeyboard || mImeHiddenByDisplayPolicy) { - ImeTracker.get().onFailed(statsToken, ImeTracker.PHASE_SERVER_ACCESSIBILITY); + + if (!mVisibilityStateComputer.onImeShowFlags(statsToken, flags)) { return false; } - ImeTracker.get().onProgress(statsToken, ImeTracker.PHASE_SERVER_ACCESSIBILITY); - mVisibilityStateComputer.onImeShowFlags(flags); if (!mSystemReady) { ImeTracker.get().onFailed(statsToken, ImeTracker.PHASE_SERVER_SYSTEM_READY); return false; @@ -4678,8 +4665,6 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub proto.write(BACK_DISPOSITION, mBackDisposition); proto.write(IME_WINDOW_VISIBILITY, mImeWindowVis); proto.write(SHOW_IME_WITH_HARD_KEYBOARD, mMenuController.getShowImeWithHardKeyboard()); - proto.write(ACCESSIBILITY_REQUESTING_NO_SOFT_KEYBOARD, - mAccessibilityRequestingNoSoftKeyboard); proto.end(token); } } @@ -5909,7 +5894,6 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub p.println(" mInFullscreenMode=" + mInFullscreenMode); p.println(" mSystemReady=" + mSystemReady + " mInteractive=" + mIsInteractive); p.println(" mSettingsObserver=" + mSettingsObserver); - p.println(" mImeHiddenByDisplayPolicy=" + mImeHiddenByDisplayPolicy); p.println(" mStylusIds=" + (mStylusIds != null ? Arrays.toString(mStylusIds.toArray()) : "")); p.println(" mSwitchingController:"); |