diff options
| author | 2024-11-13 18:21:32 +0000 | |
|---|---|---|
| committer | 2024-11-13 18:32:17 +0000 | |
| commit | c00d6ab759bda49bc71ed9f35a48beec4fa86d46 (patch) | |
| tree | 36aee269f6a9d6e87f48d13cc5e60df8a841cf1b | |
| parent | 9b4fcde939472adb8816e202f4a7b97c639492bc (diff) | |
Some fixes related to BrightnessWarningToast
1. Calling WM#removeViewImmediate when the toastView is attached
and shown to avoid the crash
2. Respect resId parameter in BrightnessController#showToast
Flag: com.android.systemui.show_toast_when_app_control_brightness
Bug: 363225340
Test: atest SystemUITests:BrightnessControllerTest
Change-Id: Ib712bf5a10279d02079d3be0f0488fa4c4d45cd6
2 files changed, 9 insertions, 5 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSliderController.java b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSliderController.java index 3a90d2b9df7b..503d0bfbc301 100644 --- a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSliderController.java +++ b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSliderController.java @@ -235,8 +235,7 @@ public class BrightnessSliderController extends ViewController<BrightnessSliderV if (mBrightnessWarningToast.isToastActive()) { return; } - mBrightnessWarningToast.show(mView.getContext(), - R.string.quick_settings_brightness_unable_adjust_msg); + mBrightnessWarningToast.show(mView.getContext(), resId); } @Override diff --git a/packages/SystemUI/src/com/android/systemui/settings/brightness/ui/BrightnessWarningToast.kt b/packages/SystemUI/src/com/android/systemui/settings/brightness/ui/BrightnessWarningToast.kt index dfbdaa62ec44..a57b8ddf5ab3 100644 --- a/packages/SystemUI/src/com/android/systemui/settings/brightness/ui/BrightnessWarningToast.kt +++ b/packages/SystemUI/src/com/android/systemui/settings/brightness/ui/BrightnessWarningToast.kt @@ -37,6 +37,9 @@ constructor( private var toastView: View? = null fun show(viewContext: Context, @StringRes resId: Int) { + if (isToastActive()) { + return + } val res = viewContext.resources // Show the brightness warning toast with passing the toast inflation required context, // userId and resId from SystemUI package. @@ -79,13 +82,15 @@ constructor( val inAnimator = systemUIToast.inAnimation inAnimator?.start() - toastView!!.postDelayed({ + toastView?.postDelayed({ val outAnimator = systemUIToast.outAnimation if (outAnimator != null) { outAnimator.start() outAnimator.addListener(object : AnimatorListenerAdapter() { override fun onAnimationEnd(animator: Animator) { - windowManager.removeViewImmediate(toastView) + if (isToastActive()) { + windowManager.removeViewImmediate(toastView) + } toastView = null } }) @@ -94,7 +99,7 @@ constructor( } fun isToastActive(): Boolean { - return toastView != null && toastView!!.isAttachedToWindow + return toastView?.isAttachedToWindow == true } companion object { |