Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e6540d2b authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

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
      d2bc309f
 [2]: Ieb7217f5e1dddb65f8987242e675c3dff0a80aab
      2bdc21e6

Fix: 251459998
Test: presubmit
Change-Id: Ia29e303fe07fd876ea2ecfb937c1fb5b867a0e89
parent 8148cabc
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -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;
+2 −5
Original line number Diff line number Diff line
@@ -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<String, InputMethodInfo> 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() {
+10 −0
Original line number Diff line number Diff line
@@ -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.
     *
+5 −0
Original line number Diff line number Diff line
@@ -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();