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

Commit c80c67e7 authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Allow custom keyguard "prompt reason"

Adds the possibility of presenting a custom message on
the keyboard if you're trying to dismiss the keyguard.

This is particularly useful when you're showing the
bouncer because custom authentication (SmarLock)
failed.

Test: launch FLAG_SHOW_WHEN_LOCKED activity and
      call KeyguardManager#requestDismissKeyguard
Fixes: 63940122
Change-Id: I0d88c0e59521887efa56d74874062b2b14970e4e
parent c9c82958
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -161,6 +161,7 @@ package android {
    field public static final java.lang.String SET_TIME = "android.permission.SET_TIME";
    field public static final java.lang.String SET_VOLUME_KEY_LONG_PRESS_LISTENER = "android.permission.SET_VOLUME_KEY_LONG_PRESS_LISTENER";
    field public static final java.lang.String SET_WALLPAPER_COMPONENT = "android.permission.SET_WALLPAPER_COMPONENT";
    field public static final java.lang.String SHOW_KEYGUARD_MESSAGE = "android.permission.SHOW_KEYGUARD_MESSAGE";
    field public static final java.lang.String SHUTDOWN = "android.permission.SHUTDOWN";
    field public static final java.lang.String SIGNAL_PERSISTENT_PROCESSES = "android.permission.SIGNAL_PERSISTENT_PROCESSES";
    field public static final java.lang.String STATUS_BAR = "android.permission.STATUS_BAR";
@@ -317,6 +318,7 @@ package android.app {

  public class KeyguardManager {
    method public android.content.Intent createConfirmFactoryResetCredentialIntent(java.lang.CharSequence, java.lang.CharSequence, java.lang.CharSequence);
    method public void requestDismissKeyguard(android.app.Activity, java.lang.CharSequence, android.app.KeyguardManager.KeyguardDismissCallback);
  }

  public class Notification implements android.os.Parcelable {
+3 −2
Original line number Diff line number Diff line
@@ -621,7 +621,8 @@ interface IActivityManager {
    void moveStackToDisplay(int stackId, int displayId);
    boolean requestAutofillData(in IAssistDataReceiver receiver, in Bundle receiverExtras,
            in IBinder activityToken, int flags);
    void dismissKeyguard(in IBinder token, in IKeyguardDismissCallback callback);
    void dismissKeyguard(in IBinder token, in IKeyguardDismissCallback callback,
            in CharSequence message);
    int restartUserInBackground(int userId);

    /** Cancels the window transitions for the given task. */
+34 −1
Original line number Diff line number Diff line
@@ -477,6 +477,39 @@ public class KeyguardManager {
     */
    public void requestDismissKeyguard(@NonNull Activity activity,
            @Nullable KeyguardDismissCallback callback) {
        requestDismissKeyguard(activity, null /* message */, callback);
    }

    /**
     * If the device is currently locked (see {@link #isKeyguardLocked()}, requests the Keyguard to
     * be dismissed.
     * <p>
     * If the Keyguard is not secure or the device is currently in a trusted state, calling this
     * method will immediately dismiss the Keyguard without any user interaction.
     * <p>
     * If the Keyguard is secure and the device is not in a trusted state, this will bring up the
     * UI so the user can enter their credentials.
     * <p>
     * If the value set for the {@link Activity} attr {@link android.R.attr#turnScreenOn} is true,
     * the screen will turn on when the keyguard is dismissed.
     *
     * @param activity The activity requesting the dismissal. The activity must be either visible
     *                 by using {@link LayoutParams#FLAG_SHOW_WHEN_LOCKED} or must be in a state in
     *                 which it would be visible if Keyguard would not be hiding it. If that's not
     *                 the case, the request will fail immediately and
     *                 {@link KeyguardDismissCallback#onDismissError} will be invoked.
     * @param message  A message that will be shown in the keyguard explaining why the user
     *                 would want to dismiss it.
     * @param callback The callback to be called if the request to dismiss Keyguard was successful
     *                 or {@code null} if the caller isn't interested in knowing the result. The
     *                 callback will not be invoked if the activity was destroyed before the
     *                 callback was received.
     * @hide
     */
    @RequiresPermission(Manifest.permission.SHOW_KEYGUARD_MESSAGE)
    @SystemApi
    public void requestDismissKeyguard(@NonNull Activity activity, @Nullable CharSequence message,
            @Nullable KeyguardDismissCallback callback) {
        try {
            mAm.dismissKeyguard(activity.getActivityToken(), new IKeyguardDismissCallback.Stub() {
                @Override
@@ -499,7 +532,7 @@ public class KeyguardManager {
                        activity.mHandler.post(callback::onDismissCancelled);
                    }
                }
            });
            }, message);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+1 −1
Original line number Diff line number Diff line
@@ -147,7 +147,7 @@ interface IWindowManager
    void exitKeyguardSecurely(IOnKeyguardExitResult callback);
    boolean isKeyguardLocked();
    boolean isKeyguardSecure();
    void dismissKeyguard(IKeyguardDismissCallback callback);
    void dismissKeyguard(IKeyguardDismissCallback callback, CharSequence message);

    // Requires INTERACT_ACROSS_USERS_FULL permission
    void setSwitchingUser(boolean switching);
+1 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ oneway interface IKeyguardService {

    void addStateMonitorCallback(IKeyguardStateCallback callback);
    void verifyUnlock(IKeyguardExitCallback callback);
    void dismiss(IKeyguardDismissCallback callback);
    void dismiss(IKeyguardDismissCallback callback, CharSequence message);
    void onDreamingStarted();
    void onDreamingStopped();

Loading