From e6d0f7501734c37d0150aceafca99aaf1cf2c14b Mon Sep 17 00:00:00 2001 From: Suprabh Shukla Date: Mon, 15 Jun 2020 15:00:43 -0700 Subject: Request keyguard dismissal from suspend dialog Sometimes a suspended app may be started while the device is locked. The suspend dialog should request the user to unlock in these cases. Test: Manual: 1. Suspend camera app. 2. Lock the screen. 3. Try to launch the camera while the screen is locked, e.g., by double tapping the power button. Bug: 157867645 Change-Id: Ie3b5e2903804bc8b385de4fc9276dd55a8108c0f Merged-In: Ie3b5e2903804bc8b385de4fc9276dd55a8108c0f --- .../android/internal/app/SuspendedAppActivity.java | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/core/java/com/android/internal/app/SuspendedAppActivity.java b/core/java/com/android/internal/app/SuspendedAppActivity.java index 0589baa76b8a..d8eaeda2b549 100644 --- a/core/java/com/android/internal/app/SuspendedAppActivity.java +++ b/core/java/com/android/internal/app/SuspendedAppActivity.java @@ -26,6 +26,7 @@ import android.Manifest; import android.annotation.Nullable; import android.app.AlertDialog; import android.app.AppGlobals; +import android.app.KeyguardManager; import android.content.DialogInterface; import android.content.Intent; import android.content.IntentSender; @@ -208,9 +209,32 @@ public class SuspendedAppActivity extends AlertActivity ap.mPositiveButtonText = getString(android.R.string.ok); ap.mNeutralButtonText = resolveNeutralButtonText(); ap.mPositiveButtonListener = ap.mNeutralButtonListener = this; + + requestDismissKeyguardIfNeeded(ap.mMessage); + setupAlert(); } + private void requestDismissKeyguardIfNeeded(CharSequence dismissMessage) { + final KeyguardManager km = getSystemService(KeyguardManager.class); + if (km.isKeyguardLocked()) { + km.requestDismissKeyguard(this, dismissMessage, + new KeyguardManager.KeyguardDismissCallback() { + @Override + public void onDismissError() { + Slog.e(TAG, "Error while dismissing keyguard." + + " Keeping the dialog visible."); + } + + @Override + public void onDismissCancelled() { + Slog.w(TAG, "Keyguard dismiss was cancelled. Finishing."); + SuspendedAppActivity.this.finish(); + } + }); + } + } + @Override public void onClick(DialogInterface dialog, int which) { switch (which) { -- cgit v1.2.3-59-g8ed1b