From e6540d2bcb85740083aeed40a07726a8b6703e37 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Thu, 13 Oct 2022 09:07:08 -0700 Subject: [PATCH] Let IMMS call isKeyguardSecure() for the correct user InputMethodManagerService has been using KeyguardManager#isKeyguardSecure() to fine tune when the IME swicher icon should be shown on the lock screen [1]. However a recent CL made that API @UserHandleAware [2], which was not reflected in InputMethodManagerService yet. With this CL, InputMethodManagerService can query isKeyguardSecure() for the correct user. A bonus is that this CL removes the direct dependency on KeyguardManager from InputMethodManagerService. [1]: I2ae7fc7676e5b64d8910dbc6833d3042e8d2329a d2bc309f0680c72731cf79f1abb300daebf1ec92 [2]: Ieb7217f5e1dddb65f8987242e675c3dff0a80aab 2bdc21e6a996ae1287c2151ac2353146b0815401 Fix: 251459998 Test: presubmit Change-Id: Ia29e303fe07fd876ea2ecfb937c1fb5b867a0e89 --- .../server/inputmethod/InputMethodManagerService.java | 7 +++---- .../server/inputmethod/InputMethodMenuController.java | 7 ++----- .../com/android/server/wm/WindowManagerInternal.java | 10 ++++++++++ .../com/android/server/wm/WindowManagerService.java | 5 +++++ 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 848156047f0d9..605a2038339c6 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -69,7 +69,6 @@ import android.annotation.UiThread; import android.annotation.UserIdInt; import android.app.ActivityManager; import android.app.ActivityManagerInternal; -import android.app.KeyguardManager; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; @@ -337,7 +336,6 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub // Ongoing notification private NotificationManager mNotificationManager; - KeyguardManager mKeyguardManager; @Nullable private StatusBarManagerInternal mStatusBarManagerInternal; private final Notification.Builder mImeSwitcherNotification; private final PendingIntent mImeSwitchPendingIntent; @@ -1941,7 +1939,6 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub final int currentUserId = mSettings.getCurrentUserId(); mSettings.switchCurrentUser(currentUserId, !mUserManagerInternal.isUserUnlockingOrUnlocked(currentUserId)); - mKeyguardManager = mContext.getSystemService(KeyguardManager.class); mNotificationManager = mContext.getSystemService(NotificationManager.class); mStatusBarManagerInternal = LocalServices.getService(StatusBarManagerInternal.class); @@ -3005,7 +3002,9 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub if (!mShowOngoingImeSwitcherForPhones) return false; if (mMenuController.getSwitchingDialogLocked() != null) return false; if (mWindowManagerInternal.isKeyguardShowingAndNotOccluded() - && mKeyguardManager != null && mKeyguardManager.isKeyguardSecure()) return false; + && mWindowManagerInternal.isKeyguardSecure(mSettings.getCurrentUserId())) { + return false; + } if ((visibility & InputMethodService.IME_ACTIVE) == 0 || (visibility & InputMethodService.IME_INVISIBLE) != 0) { return false; diff --git a/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java b/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java index a25630ffefa1a..c212e8e3c82cc 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java @@ -21,7 +21,6 @@ import static com.android.server.inputmethod.InputMethodUtils.NOT_A_SUBTYPE_ID; import android.annotation.Nullable; import android.app.AlertDialog; -import android.app.KeyguardManager; import android.content.Context; import android.content.DialogInterface; import android.content.res.TypedArray; @@ -56,7 +55,6 @@ final class InputMethodMenuController { private final InputMethodUtils.InputMethodSettings mSettings; private final InputMethodSubtypeSwitchingController mSwitchingController; private final ArrayMap mMethodMap; - private final KeyguardManager mKeyguardManager; private final WindowManagerInternal mWindowManagerInternal; private AlertDialog.Builder mDialogBuilder; @@ -76,7 +74,6 @@ final class InputMethodMenuController { mSettings = mService.mSettings; mSwitchingController = mService.mSwitchingController; mMethodMap = mService.mMethodMap; - mKeyguardManager = mService.mKeyguardManager; mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); } @@ -209,8 +206,8 @@ final class InputMethodMenuController { } private boolean isScreenLocked() { - return mKeyguardManager != null && mKeyguardManager.isKeyguardLocked() - && mKeyguardManager.isKeyguardSecure(); + return mWindowManagerInternal.isKeyguardLocked() + && mWindowManagerInternal.isKeyguardSecure(mSettings.getCurrentUserId()); } void updateKeyboardFromSettingsLocked() { diff --git a/services/core/java/com/android/server/wm/WindowManagerInternal.java b/services/core/java/com/android/server/wm/WindowManagerInternal.java index 1e6c7207e34a5..32feb6c98b241 100644 --- a/services/core/java/com/android/server/wm/WindowManagerInternal.java +++ b/services/core/java/com/android/server/wm/WindowManagerInternal.java @@ -21,6 +21,7 @@ import static java.lang.annotation.RetentionPolicy.SOURCE; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.UserIdInt; import android.content.ClipData; import android.content.Context; import android.graphics.Matrix; @@ -451,6 +452,15 @@ public abstract class WindowManagerInternal { */ public abstract boolean isKeyguardShowingAndNotOccluded(); + /** + * Return whether the keyguard is secured by a PIN, pattern or password or a SIM card is + * currently locked. + * + * @param userId User ID to be queried about. + * @return {@code true} if a PIN, pattern or password is set or a SIM card is locked. + */ + public abstract boolean isKeyguardSecure(@UserIdInt int userId); + /** * Gets the frame of a window given its token. * diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 961c320dabe63..5ac034b8954f4 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -7762,6 +7762,11 @@ public class WindowManagerService extends IWindowManager.Stub return WindowManagerService.this.isKeyguardShowingAndNotOccluded(); } + @Override + public boolean isKeyguardSecure(@UserIdInt int userId) { + return mPolicy.isKeyguardSecure(userId); + } + @Override public void showGlobalActions() { WindowManagerService.this.showGlobalActions();