diff options
3 files changed, 124 insertions, 0 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 6e9f859c202b..d5a395436271 100644 --- a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessDialog.java +++ b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessDialog.java @@ -20,6 +20,7 @@ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; import android.app.Activity; +import android.graphics.Rect; import android.os.Bundle; import android.os.Handler; import android.view.Gravity; @@ -36,6 +37,8 @@ import com.android.systemui.R; import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.dagger.qualifiers.Background; +import java.util.List; + import javax.inject.Inject; /** A dialog that provides controls for adjusting the screen brightness. */ @@ -83,6 +86,15 @@ public class BrightnessDialog extends Activity { lp.leftMargin = horizontalMargin; lp.rightMargin = horizontalMargin; frame.setLayoutParams(lp); + Rect bounds = new Rect(); + frame.addOnLayoutChangeListener( + (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> { + // Exclude this view (and its horizontal margins) from triggering gestures. + // This prevents back gesture from being triggered by dragging close to the + // edge of the slider (0% or 100%). + bounds.set(-horizontalMargin, 0, right - left + horizontalMargin, bottom - top); + v.setSystemGestureExclusionRects(List.of(bounds)); + }); BrightnessSliderController controller = mToggleSliderFactory.create(this, frame); controller.init(); diff --git a/packages/SystemUI/tests/AndroidManifest.xml b/packages/SystemUI/tests/AndroidManifest.xml index 0fa3d366df8a..c55ee61cfe7f 100644 --- a/packages/SystemUI/tests/AndroidManifest.xml +++ b/packages/SystemUI/tests/AndroidManifest.xml @@ -88,6 +88,11 @@ android:excludeFromRecents="true" /> + <activity android:name=".settings.brightness.BrightnessDialogTest$TestDialog" + android:exported="false" + android:excludeFromRecents="true" + /> + <activity android:name="com.android.systemui.screenshot.ScrollViewActivity" android:exported="false" /> 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 new file mode 100644 index 000000000000..1130bda9b881 --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/settings/brightness/BrightnessDialogTest.kt @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.settings.brightness + +import android.content.Intent +import android.graphics.Rect +import android.os.Handler +import android.testing.AndroidTestingRunner +import android.testing.TestableLooper +import android.view.View +import android.view.ViewGroup +import androidx.test.filters.SmallTest +import androidx.test.rule.ActivityTestRule +import androidx.test.runner.intercepting.SingleActivityFactory +import com.android.systemui.R +import com.android.systemui.SysuiTestCase +import com.android.systemui.broadcast.BroadcastDispatcher +import com.android.systemui.util.mockito.any +import com.google.common.truth.Truth.assertThat +import org.junit.After +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.Mockito.`when` +import org.mockito.MockitoAnnotations + +@SmallTest +@RunWith(AndroidTestingRunner::class) +@TestableLooper.RunWithLooper +class BrightnessDialogTest : SysuiTestCase() { + + @Mock private lateinit var brightnessSliderControllerFactory: BrightnessSliderController.Factory + @Mock private lateinit var backgroundHandler: Handler + @Mock private lateinit var brightnessSliderController: BrightnessSliderController + + @Rule + @JvmField + var activityRule = + ActivityTestRule( + object : SingleActivityFactory<TestDialog>(TestDialog::class.java) { + override fun create(intent: Intent?): TestDialog { + return TestDialog( + fakeBroadcastDispatcher, + brightnessSliderControllerFactory, + backgroundHandler + ) + } + }, + false, + false + ) + + @Before + fun setUp() { + MockitoAnnotations.initMocks(this) + `when`(brightnessSliderControllerFactory.create(any(), any())) + .thenReturn(brightnessSliderController) + `when`(brightnessSliderController.rootView).thenReturn(View(context)) + + activityRule.launchActivity(null) + } + + @After + fun tearDown() { + activityRule.finishActivity() + } + + @Test + fun testGestureExclusion() { + val frame = activityRule.activity.requireViewById<View>(R.id.brightness_mirror_container) + + val lp = frame.layoutParams as ViewGroup.MarginLayoutParams + val horizontalMargin = + activityRule.activity.resources.getDimensionPixelSize( + R.dimen.notification_side_paddings + ) + assertThat(lp.leftMargin).isEqualTo(horizontalMargin) + assertThat(lp.rightMargin).isEqualTo(horizontalMargin) + + assertThat(frame.systemGestureExclusionRects.size).isEqualTo(1) + val exclusion = frame.systemGestureExclusionRects[0] + assertThat(exclusion) + .isEqualTo(Rect(-horizontalMargin, 0, frame.width + horizontalMargin, frame.height)) + } + + class TestDialog( + broadcastDispatcher: BroadcastDispatcher, + brightnessSliderControllerFactory: BrightnessSliderController.Factory, + backgroundHandler: Handler + ) : BrightnessDialog(broadcastDispatcher, brightnessSliderControllerFactory, backgroundHandler) +} |