diff options
| -rw-r--r-- | api/current.txt | 3 | ||||
| -rw-r--r-- | api/system-current.txt | 3 | ||||
| -rw-r--r-- | api/test-current.txt | 3 | ||||
| -rw-r--r-- | core/java/android/app/KeyguardManager.java | 43 |
4 files changed, 43 insertions, 9 deletions
diff --git a/api/current.txt b/api/current.txt index b5537ab0b8a4..ed83772142e6 100644 --- a/api/current.txt +++ b/api/current.txt @@ -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 { diff --git a/api/system-current.txt b/api/system-current.txt index eaf3b693b5ea..5ddb64135885 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -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 { diff --git a/api/test-current.txt b/api/test-current.txt index 04384045727c..9439e3872e87 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -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 { diff --git a/core/java/android/app/KeyguardManager.java b/core/java/android/app/KeyguardManager.java index b8a5f572ccfc..4de6e44b0400 100644 --- a/core/java/android/app/KeyguardManager.java +++ b/core/java/android/app/KeyguardManager.java @@ -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) { |