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();