diff options
| author | 2023-12-01 16:13:29 +0000 | |
|---|---|---|
| committer | 2023-12-01 16:13:29 +0000 | |
| commit | 71dac058dd93b62076c8dcae4bb5740b220b34fd (patch) | |
| tree | be1efb7a50135854f376f7b822c3a862c0c51265 | |
| parent | 9d8f68c5181782e7a606b2a9063f054a0b9567cb (diff) | |
| parent | cad68c695d1e88e33115c70c755469e0d7749141 (diff) | |
Merge "Finish BrightnessDialog when shade is opened." into main
2 files changed, 30 insertions, 3 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessDialog.java b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessDialog.java index d13edf01cc4a..d382b7ae2bf0 100644 --- a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessDialog.java +++ b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessDialog.java @@ -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() { diff --git a/packages/SystemUI/tests/src/com/android/systemui/settings/brightness/BrightnessDialogTest.kt b/packages/SystemUI/tests/src/com/android/systemui/settings/brightness/BrightnessDialogTest.kt index 88c728fd1b66..569c8d9d350d 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/settings/brightness/BrightnessDialogTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/settings/brightness/BrightnessDialogTest.kt @@ -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, |