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

Commit c00d6ab7 authored by Ming-Shin Lu's avatar Ming-Shin Lu
Browse files

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
parent 9b4fcde9
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -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
+8 −3
Original line number Diff line number Diff line
@@ -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) {
                        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 {