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

Commit 8b4b6340 authored by Mattias Petersson's avatar Mattias Petersson Committed by Johan Redestig
Browse files

Avoid memory leak in the Shutdown confirmation dialog.

How to reproduce:
1) Lock the screen.
2) Open the Phone options menu by long pressing the power
   button.
3) Tap "Power off" to display the confirmation dialog.
4) Repeat step 2 and 3 a few times (without closing the
   confirmation dialog.

Each time the confirmation dialog is displayed, a new
instance is created. A stack of confirmation dialogs are
created on the screen.

This is fixed by making sure the previous dialog is
dismissed before launching a new dialog.

Change-Id: I6b6c61ccc56364b66eed3528019f761e75bbe268
parent 0748a569
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -77,6 +77,8 @@ public final class ShutdownThread extends Thread {
    private PowerManager.WakeLock mScreenWakeLock;
    private Handler mHandler;

    private static AlertDialog sConfirmDialog;
    
    private ShutdownThread() {
    }
 
@@ -108,7 +110,10 @@ public final class ShutdownThread extends Thread {

        if (confirm) {
            final CloseDialogReceiver closer = new CloseDialogReceiver(context);
            final AlertDialog dialog = new AlertDialog.Builder(context)
            if (sConfirmDialog != null) {
                sConfirmDialog.dismiss();
            }
            sConfirmDialog = new AlertDialog.Builder(context)
                    .setTitle(com.android.internal.R.string.power_off)
                    .setMessage(resourceId)
                    .setPositiveButton(com.android.internal.R.string.yes, new DialogInterface.OnClickListener() {
@@ -118,10 +123,10 @@ public final class ShutdownThread extends Thread {
                    })
                    .setNegativeButton(com.android.internal.R.string.no, null)
                    .create();
            closer.dialog = dialog;
            dialog.setOnDismissListener(closer);
            dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
            dialog.show();
            closer.dialog = sConfirmDialog;
            sConfirmDialog.setOnDismissListener(closer);
            sConfirmDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
            sConfirmDialog.show();
        } else {
            beginShutdownSequence(context);
        }