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

Commit 0516a9ec authored by Eric Laurent's avatar Eric Laurent
Browse files

Fix safe volume warning message flickering

Do not display a new warning message when one is already showing.

Bug 7064975.

Change-Id: I920656c6d742a969c29e8f42a438ecbc794d1114
parent 4dd3c379
Loading
Loading
Loading
Loading
+31 −22
Original line number Diff line number Diff line
@@ -214,6 +214,7 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
    private Vibrator mVibrator;

    private static AlertDialog sConfirmSafeVolumeDialog;
    private static Object sConfirmSafeVolumeLock = new Object();

    private static class WarningDialogReceiver extends BroadcastReceiver
            implements DialogInterface.OnDismissListener {
@@ -230,10 +231,16 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
        @Override
        public void onReceive(Context context, Intent intent) {
            mDialog.cancel();
            synchronized (sConfirmSafeVolumeLock) {
                sConfirmSafeVolumeDialog = null;
            }
        }

        public void onDismiss(DialogInterface unused) {
            mContext.unregisterReceiver(this);
            synchronized (sConfirmSafeVolumeLock) {
                sConfirmSafeVolumeDialog = null;
            }
        }
    }

@@ -556,6 +563,7 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
    }

    public void postDisplaySafeVolumeWarning() {
        if (hasMessages(MSG_DISPLAY_SAFE_VOLUME_WARNING)) return;
        obtainMessage(MSG_DISPLAY_SAFE_VOLUME_WARNING, 0, 0).sendToTarget();
    }

@@ -828,8 +836,9 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
    }

    protected void onDisplaySafeVolumeWarning() {
        synchronized (sConfirmSafeVolumeLock) {
            if (sConfirmSafeVolumeDialog != null) {
            sConfirmSafeVolumeDialog.dismiss();
                return;
            }
            sConfirmSafeVolumeDialog = new AlertDialog.Builder(mContext)
                    .setMessage(com.android.internal.R.string.safe_media_volume_warning)
@@ -842,7 +851,6 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
                    .setNegativeButton(com.android.internal.R.string.no, null)
                    .setIconAttribute(android.R.attr.alertDialogIcon)
                    .create();

            final WarningDialogReceiver warning = new WarningDialogReceiver(mContext,
                    sConfirmSafeVolumeDialog);

@@ -851,6 +859,7 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
                                                    WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
            sConfirmSafeVolumeDialog.show();
        }
    }

    /**
     * Lock on this VolumePanel instance as long as you use the returned ToneGenerator.