From f41e7664a2102e706014df2f519d66e8bebc5373 Mon Sep 17 00:00:00 2001 From: Jorim Jaggi Date: Thu, 27 Apr 2017 14:30:39 +0200 Subject: [PATCH] Implement API council feedback for dismissKeyguard Test: KeyguardLockedTests CTS Change-Id: Ibc6923ebe8363644e9b52b2b53b45d918124f52d Fixes: 37673408 --- api/current.txt | 3 +- api/system-current.txt | 3 +- api/test-current.txt | 3 +- 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 943510f2bd276..77efc597f9898 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 3a1f4b13a61aa..066e39375ee52 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 69391a900e140..38c65f24f712f 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 b8a5f572ccfc8..4de6e44b04005 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. + *

+ * 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. + *

+ * 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) {