From 6be5368b67f8b6bee2be56373f97df7969bb97a2 Mon Sep 17 00:00:00 2001 From: Amin Shaikh Date: Wed, 2 May 2018 15:59:44 -0400 Subject: [PATCH] Dismiss systemui QS dialogs on screen off. CLOSE_SYSTEM_DIALOGS may not be sent if the user turns off and on the screen quickly, resulting in systemui dialogs being displayed over the lock screen. Dismissing these system dialogs when the SCREEN_OFF broadcast is sent prevents this bug. Change-Id: I097d0997d1538002b23bdd8f7aa32ecf4d32e0d4 Fixes: 78915648 Test: manual --- .../statusbar/phone/SystemUIDialog.java | 58 ++++++++++++------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/SystemUIDialog.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/SystemUIDialog.java index 6a8d3a50eddde..48a9fb67c17b8 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/SystemUIDialog.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/SystemUIDialog.java @@ -20,6 +20,7 @@ import android.app.AlertDialog; import android.app.Dialog; import android.content.BroadcastReceiver; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.os.UserHandle; @@ -30,6 +31,7 @@ import com.android.systemui.Dependency; import com.android.systemui.R; import com.android.systemui.statusbar.policy.KeyguardMonitor; + /** * Base class for dialogs that should appear over panels and keyguard. */ @@ -99,24 +101,40 @@ public class SystemUIDialog extends AlertDialog { } public static void registerDismissListener(Dialog dialog) { - boolean[] registered = new boolean[1]; - Context context = dialog.getContext(); - final BroadcastReceiver mReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - if (dialog != null) { - dialog.dismiss(); - } - } - }; - context.registerReceiverAsUser(mReceiver, UserHandle.CURRENT, - new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS), null, null); - registered[0] = true; - dialog.setOnDismissListener(d -> { - if (registered[0]) { - context.unregisterReceiver(mReceiver); - registered[0] = false; - } - }); + DismissReceiver dismissReceiver = new DismissReceiver(dialog); + dismissReceiver.register(); } -} + + private static class DismissReceiver extends BroadcastReceiver implements OnDismissListener { + private static final IntentFilter INTENT_FILTER = new IntentFilter(); + static { + INTENT_FILTER.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); + INTENT_FILTER.addAction(Intent.ACTION_SCREEN_OFF); + } + + private final Dialog mDialog; + private boolean mRegistered; + + DismissReceiver(Dialog dialog) { + mDialog = dialog; + } + + void register() { + mDialog.getContext() + .registerReceiverAsUser(this, UserHandle.CURRENT, INTENT_FILTER, null, null); + mRegistered = true; + } + + @Override + public void onReceive(Context context, Intent intent) { + mDialog.dismiss(); + } + + @Override + public void onDismiss(DialogInterface dialog) { + if (mRegistered) { + mDialog.getContext().unregisterReceiver(this); + mRegistered = false; + } + } + }}