From 06a390a1de73324048a54215e2c79c885b5317c4 Mon Sep 17 00:00:00 2001 From: Behnam Heydarshahi Date: Mon, 22 May 2023 14:36:27 +0000 Subject: [PATCH] Dismiss lingering volume dialog (1) Fault tolerance for the state where the dialog is not showing but mShowing flag is set to false. (2) Extra logging for better understanding the state of the dialog. Bug: b/232606092 Test: Manual. Open volume dialog, adjust using volume buttons. Slider should move smoothly and eventually dialog should dismiss smoothly. Change-Id: Ie914f97925d8defb8c57818e5e7ffe958936336c --- .../systemui/volume/VolumeDialogImpl.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java index 5bd965c2f668f..b24a692921861 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java +++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java @@ -404,6 +404,7 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable, @Override public void destroy() { + Log.d(TAG, "destroy() called"); mController.removeCallback(mControllerCallbackH); mHandler.removeCallbacksAndMessages(null); mConfigurationController.removeCallback(this); @@ -465,6 +466,7 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable, } private void initDialog(int lockTaskModeState) { + Log.d(TAG, "initDialog: called!"); mDialog = new CustomDialog(mContext); initDimens(); @@ -1269,7 +1271,7 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable, } protected void tryToRemoveCaptionsTooltip() { - if (mHasSeenODICaptionsTooltip && mODICaptionsTooltipView != null) { + if (mHasSeenODICaptionsTooltip && mODICaptionsTooltipView != null && mDialog != null) { ViewGroup container = mDialog.findViewById(R.id.volume_dialog_container); container.removeView(mODICaptionsTooltipView); mODICaptionsTooltipView = null; @@ -1476,8 +1478,16 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable, mHandler.removeMessages(H.DISMISS); mHandler.removeMessages(H.SHOW); - if (mIsAnimatingDismiss) { - Log.d(TAG, "dismissH: isAnimatingDismiss"); + + boolean showingStateInconsistent = !mShowing && mDialog != null && mDialog.isShowing(); + // If incorrectly assuming dialog is not showing, continue and make the state consistent. + if (showingStateInconsistent) { + Log.d(TAG, "dismissH: volume dialog possible in inconsistent state:" + + "mShowing=" + mShowing + ", mDialog==null?" + (mDialog == null)); + } + if (mIsAnimatingDismiss && !showingStateInconsistent) { + Log.d(TAG, "dismissH: skipping dismiss because isAnimatingDismiss is true" + + " and showingStateInconsistent is false"); Trace.endSection(); return; } @@ -1495,8 +1505,12 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable, .setDuration(mDialogHideAnimationDurationMs) .setInterpolator(new SystemUIInterpolators.LogAccelerateInterpolator()) .withEndAction(() -> mHandler.postDelayed(() -> { - mController.notifyVisible(false); - mDialog.dismiss(); + if (mController != null) { + mController.notifyVisible(false); + } + if (mDialog != null) { + mDialog.dismiss(); + } tryToRemoveCaptionsTooltip(); mIsAnimatingDismiss = false;