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

Commit f41e7664 authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Implement API council feedback for dismissKeyguard

Test: KeyguardLockedTests CTS
Change-Id: Ibc6923ebe8363644e9b52b2b53b45d918124f52d
Fixes: 37673408
parent ccac69e1
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -4975,7 +4975,7 @@ package android.app {
  public class KeyguardManager {
    method public android.content.Intent createConfirmDeviceCredentialIntent(java.lang.CharSequence, java.lang.CharSequence);
    method public void dismissKeyguard(android.app.Activity, android.app.KeyguardManager.KeyguardDismissCallback, android.os.Handler);
    method public deprecated void dismissKeyguard(android.app.Activity, android.app.KeyguardManager.KeyguardDismissCallback, android.os.Handler);
    method public deprecated void exitKeyguardSecurely(android.app.KeyguardManager.OnKeyguardExitResult);
    method public boolean inKeyguardRestrictedInputMode();
    method public boolean isDeviceLocked();
@@ -4983,6 +4983,7 @@ package android.app {
    method public boolean isKeyguardLocked();
    method public boolean isKeyguardSecure();
    method public deprecated android.app.KeyguardManager.KeyguardLock newKeyguardLock(java.lang.String);
    method public void requestDismissKeyguard(android.app.Activity, android.app.KeyguardManager.KeyguardDismissCallback);
  }
  public static abstract class KeyguardManager.KeyguardDismissCallback {
+2 −1
Original line number Diff line number Diff line
@@ -5155,7 +5155,7 @@ package android.app {
  public class KeyguardManager {
    method public android.content.Intent createConfirmDeviceCredentialIntent(java.lang.CharSequence, java.lang.CharSequence);
    method public void dismissKeyguard(android.app.Activity, android.app.KeyguardManager.KeyguardDismissCallback, android.os.Handler);
    method public deprecated void dismissKeyguard(android.app.Activity, android.app.KeyguardManager.KeyguardDismissCallback, android.os.Handler);
    method public deprecated void exitKeyguardSecurely(android.app.KeyguardManager.OnKeyguardExitResult);
    method public boolean inKeyguardRestrictedInputMode();
    method public boolean isDeviceLocked();
@@ -5163,6 +5163,7 @@ package android.app {
    method public boolean isKeyguardLocked();
    method public boolean isKeyguardSecure();
    method public deprecated android.app.KeyguardManager.KeyguardLock newKeyguardLock(java.lang.String);
    method public void requestDismissKeyguard(android.app.Activity, android.app.KeyguardManager.KeyguardDismissCallback);
  }
  public static abstract class KeyguardManager.KeyguardDismissCallback {
+2 −1
Original line number Diff line number Diff line
@@ -4988,7 +4988,7 @@ package android.app {
  public class KeyguardManager {
    method public android.content.Intent createConfirmDeviceCredentialIntent(java.lang.CharSequence, java.lang.CharSequence);
    method public void dismissKeyguard(android.app.Activity, android.app.KeyguardManager.KeyguardDismissCallback, android.os.Handler);
    method public deprecated void dismissKeyguard(android.app.Activity, android.app.KeyguardManager.KeyguardDismissCallback, android.os.Handler);
    method public deprecated void exitKeyguardSecurely(android.app.KeyguardManager.OnKeyguardExitResult);
    method public boolean inKeyguardRestrictedInputMode();
    method public boolean isDeviceLocked();
@@ -4996,6 +4996,7 @@ package android.app {
    method public boolean isKeyguardLocked();
    method public boolean isKeyguardSecure();
    method public deprecated android.app.KeyguardManager.KeyguardLock newKeyguardLock(java.lang.String);
    method public void requestDismissKeyguard(android.app.Activity, android.app.KeyguardManager.KeyguardDismissCallback);
  }
  public static abstract class KeyguardManager.KeyguardDismissCallback {
+37 −6
Original line number Diff line number Diff line
@@ -381,27 +381,58 @@ public class KeyguardManager {
     *                 or {@code null} if the caller isn't interested in knowing the result.
     * @param handler The handler to invoke the callback on, or {@code null} to use the main
     *                handler.
     *
     * TO BE REMOVED
     */
    @Deprecated
    public void dismissKeyguard(@NonNull Activity activity,
            @Nullable KeyguardDismissCallback callback, @Nullable Handler handler) {
        requestDismissKeyguard(activity, 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.
     *
     * @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 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.
     */
    public void requestDismissKeyguard(@NonNull Activity activity,
            @Nullable KeyguardDismissCallback callback) {
        try {
            final Handler actualHandler = handler != null
                    ? handler
                    : new Handler(Looper.getMainLooper());
            mAm.dismissKeyguard(activity.getActivityToken(), new IKeyguardDismissCallback.Stub() {
                @Override
                public void onDismissError() throws RemoteException {
                    actualHandler.post(callback::onDismissError);
                    if (callback != null && !activity.isDestroyed()) {
                        activity.mHandler.post(callback::onDismissError);
                    }
                }

                @Override
                public void onDismissSucceeded() throws RemoteException {
                    actualHandler.post(callback::onDismissSucceeded);
                    if (callback != null && !activity.isDestroyed()) {
                        activity.mHandler.post(callback::onDismissSucceeded);
                    }
                }

                @Override
                public void onDismissCancelled() throws RemoteException {
                    actualHandler.post(callback::onDismissCancelled);
                    if (callback != null && !activity.isDestroyed()) {
                        activity.mHandler.post(callback::onDismissCancelled);
                    }
                }
            });
        } catch (RemoteException e) {