Skip to content

Commit 6730c3c

Browse files
Eric LaurentAndroid (Google) Code Review
authored andcommitted
Merge "Fix safe volume warning message flickering" into jb-mr1-dev
2 parents 77f6677 + 0516a9e commit 6730c3c

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

core/java/android/view/VolumePanel.java

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ private class StreamControl {
214214
private Vibrator mVibrator;
215215

216216
private static AlertDialog sConfirmSafeVolumeDialog;
217+
private static Object sConfirmSafeVolumeLock = new Object();
217218

218219
private static class WarningDialogReceiver extends BroadcastReceiver
219220
implements DialogInterface.OnDismissListener {
@@ -230,10 +231,16 @@ private static class WarningDialogReceiver extends BroadcastReceiver
230231
@Override
231232
public void onReceive(Context context, Intent intent) {
232233
mDialog.cancel();
234+
synchronized (sConfirmSafeVolumeLock) {
235+
sConfirmSafeVolumeDialog = null;
236+
}
233237
}
234238

235239
public void onDismiss(DialogInterface unused) {
236240
mContext.unregisterReceiver(this);
241+
synchronized (sConfirmSafeVolumeLock) {
242+
sConfirmSafeVolumeDialog = null;
243+
}
237244
}
238245
}
239246

@@ -556,6 +563,7 @@ public void postMasterMuteChanged(int flags) {
556563
}
557564

558565
public void postDisplaySafeVolumeWarning() {
566+
if (hasMessages(MSG_DISPLAY_SAFE_VOLUME_WARNING)) return;
559567
obtainMessage(MSG_DISPLAY_SAFE_VOLUME_WARNING, 0, 0).sendToTarget();
560568
}
561569

@@ -828,28 +836,29 @@ synchronized protected void onSliderVisibilityChanged(int streamType, int visibl
828836
}
829837

830838
protected void onDisplaySafeVolumeWarning() {
831-
if (sConfirmSafeVolumeDialog != null) {
832-
sConfirmSafeVolumeDialog.dismiss();
833-
}
834-
sConfirmSafeVolumeDialog = new AlertDialog.Builder(mContext)
835-
.setMessage(com.android.internal.R.string.safe_media_volume_warning)
836-
.setPositiveButton(com.android.internal.R.string.yes,
837-
new DialogInterface.OnClickListener() {
838-
public void onClick(DialogInterface dialog, int which) {
839-
mAudioService.disableSafeMediaVolume();
840-
}
841-
})
842-
.setNegativeButton(com.android.internal.R.string.no, null)
843-
.setIconAttribute(android.R.attr.alertDialogIcon)
844-
.create();
845-
846-
final WarningDialogReceiver warning = new WarningDialogReceiver(mContext,
847-
sConfirmSafeVolumeDialog);
848-
849-
sConfirmSafeVolumeDialog.setOnDismissListener(warning);
850-
sConfirmSafeVolumeDialog.getWindow().setType(
851-
WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
852-
sConfirmSafeVolumeDialog.show();
839+
synchronized (sConfirmSafeVolumeLock) {
840+
if (sConfirmSafeVolumeDialog != null) {
841+
return;
842+
}
843+
sConfirmSafeVolumeDialog = new AlertDialog.Builder(mContext)
844+
.setMessage(com.android.internal.R.string.safe_media_volume_warning)
845+
.setPositiveButton(com.android.internal.R.string.yes,
846+
new DialogInterface.OnClickListener() {
847+
public void onClick(DialogInterface dialog, int which) {
848+
mAudioService.disableSafeMediaVolume();
849+
}
850+
})
851+
.setNegativeButton(com.android.internal.R.string.no, null)
852+
.setIconAttribute(android.R.attr.alertDialogIcon)
853+
.create();
854+
final WarningDialogReceiver warning = new WarningDialogReceiver(mContext,
855+
sConfirmSafeVolumeDialog);
856+
857+
sConfirmSafeVolumeDialog.setOnDismissListener(warning);
858+
sConfirmSafeVolumeDialog.getWindow().setType(
859+
WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
860+
sConfirmSafeVolumeDialog.show();
861+
}
853862
}
854863

855864
/**

0 commit comments

Comments
 (0)