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

Commit cad68c69 authored by Olivier St-Onge's avatar Olivier St-Onge
Browse files

Finish BrightnessDialog when shade is opened.

This ensures that BrightnessDialog won't appear in the background when
controlling the brightness from QS.
Also removes the unused lazy ShadeInteractor from the test.

Fixes: 243630115
Test: Manually, opening both brightness sliders at the same time
Test: Added unit test
Flag: NONE
Change-Id: I4d1a62fcd87ac4836df9c4a5bb0648b4eced47cc
parent 48cb75e8
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
import static android.view.WindowManagerPolicyConstants.EXTRA_FROM_BRIGHTNESS_KEY;

import static com.android.systemui.util.kotlin.JavaAdapterKt.collectFlow;

import android.app.Activity;
import android.content.res.Configuration;
import android.graphics.Rect;
@@ -87,6 +89,17 @@ public class BrightnessDialog extends Activity {
        if (mShadeInteractor.isQsExpanded().getValue()) {
            finish();
        }

        View view = findViewById(R.id.brightness_mirror_container);
        if (view != null) {
            collectFlow(view, mShadeInteractor.isQsExpanded(), this::onShadeStateChange);
        }
    }

    private void onShadeStateChange(boolean isQsExpanded) {
        if (isQsExpanded) {
            requestFinish();
        }
    }

    private void setWindowAttributes() {
+17 −3
Original line number Diff line number Diff line
@@ -36,8 +36,10 @@ import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.whenever
import com.android.systemui.util.time.FakeSystemClock
import com.google.common.truth.Truth.assertThat
import dagger.Lazy
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.advanceUntilIdle
import kotlinx.coroutines.test.runTest
import org.junit.After
import org.junit.Before
import org.junit.Rule
@@ -59,7 +61,6 @@ class BrightnessDialogTest : SysuiTestCase() {
    @Mock private lateinit var brightnessControllerFactory: BrightnessController.Factory
    @Mock private lateinit var brightnessController: BrightnessController
    @Mock private lateinit var accessibilityMgr: AccessibilityManagerWrapper
    @Mock private lateinit var shadeInteractorLazy: Lazy<ShadeInteractor>
    @Mock private lateinit var shadeInteractor: ShadeInteractor

    private val clock = FakeSystemClock()
@@ -89,7 +90,6 @@ class BrightnessDialogTest : SysuiTestCase() {
            .thenReturn(brightnessSliderController)
        `when`(brightnessSliderController.rootView).thenReturn(View(context))
        `when`(brightnessControllerFactory.create(any())).thenReturn(brightnessController)
        whenever(shadeInteractorLazy.get()).thenReturn(shadeInteractor)
        whenever(shadeInteractor.isQsExpanded).thenReturn(MutableStateFlow(false))
    }

@@ -180,6 +180,20 @@ class BrightnessDialogTest : SysuiTestCase() {
        assertThat(activityRule.activity.isFinishing()).isFalse()
    }

    @OptIn(ExperimentalCoroutinesApi::class)
    @Test
    fun testFinishOnQSExpanded() = runTest {
        val isQSExpanded = MutableStateFlow(false)
        `when`(shadeInteractor.isQsExpanded).thenReturn(isQSExpanded)
        activityRule.launchActivity(Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG))

        assertThat(activityRule.activity.isFinishing()).isFalse()

        isQSExpanded.value = true
        advanceUntilIdle()
        assertThat(activityRule.activity.isFinishing()).isTrue()
    }

    class TestDialog(
        brightnessSliderControllerFactory: BrightnessSliderController.Factory,
        brightnessControllerFactory: BrightnessController.Factory,