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
This commit is contained in:
Mattias Petersson
2011-05-31 16:14:59 +02:00
committed by Johan Redestig
parent 0748a56987
commit 8b4b63403a

View File

@@ -76,6 +76,8 @@ public final class ShutdownThread extends Thread {
private PowerManager.WakeLock mCpuWakeLock;
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);
}