From cbb774dc6e8e1127b3cc038534f934713d4599c2 Mon Sep 17 00:00:00 2001 From: Heemin Seog Date: Thu, 2 Apr 2020 12:44:30 -0700 Subject: [PATCH] Allow nav bar to consume touch events based on configuration This is particularly useful for OEMs that want to ensure that OEMs can override the touch behavior of the system bars without impacting the notification panel touch behavior. Bug: 150613278 Test: manual, atest CarNavigationBarViewTest Change-Id: Icb5ae3388f4004b4f465e9a9e85e8d175bbe7d78 --- packages/CarSystemUI/res/values/config.xml | 4 + .../NotificationPanelViewController.java | 5 + .../NotificationPanelViewMediator.java | 16 ++- .../car/CarNavigationBarController.java | 3 + .../car/CarNavigationBarView.java | 13 ++- .../layout/car_navigation_bar_view_test.xml | 58 ++++++++++ .../car/CarNavigationBarViewTest.java | 100 ++++++++++++++++++ 7 files changed, 192 insertions(+), 7 deletions(-) create mode 100644 packages/CarSystemUI/tests/res/layout/car_navigation_bar_view_test.xml create mode 100644 packages/CarSystemUI/tests/src/com/android/systemui/navigationbar/car/CarNavigationBarViewTest.java diff --git a/packages/CarSystemUI/res/values/config.xml b/packages/CarSystemUI/res/values/config.xml index 43e2918bd98da..0b56d05cc66f7 100644 --- a/packages/CarSystemUI/res/values/config.xml +++ b/packages/CarSystemUI/res/values/config.xml @@ -32,6 +32,10 @@ false + + false + true + + + + + + + + + + + + diff --git a/packages/CarSystemUI/tests/src/com/android/systemui/navigationbar/car/CarNavigationBarViewTest.java b/packages/CarSystemUI/tests/src/com/android/systemui/navigationbar/car/CarNavigationBarViewTest.java new file mode 100644 index 0000000000000..9e2131c9ccfbb --- /dev/null +++ b/packages/CarSystemUI/tests/src/com/android/systemui/navigationbar/car/CarNavigationBarViewTest.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2020 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.navigationbar.car; + +import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.Mockito.when; + +import android.testing.AndroidTestingRunner; +import android.testing.TestableLooper; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; + +import androidx.test.filters.SmallTest; + +import com.android.systemui.R; +import com.android.systemui.SysuiTestCase; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +@RunWith(AndroidTestingRunner.class) +@TestableLooper.RunWithLooper +@SmallTest +public class CarNavigationBarViewTest extends SysuiTestCase { + + private CarNavigationBarView mNavBarView; + + @Mock + private CarNavigationBarController.NotificationsShadeController mNotificationsShadeController; + + @Mock + private View.OnTouchListener mNavBarTouchListener; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + @After + public void tearDown() { + getContext().getOrCreateTestableResources().addOverride( + R.bool.config_consumeNavigationBarTouchWhenNotificationPanelOpen, false); + } + + @Test + public void dispatchTouch_shadeOpen_flagOff_doesNotConsumeTouch() { + getContext().getOrCreateTestableResources().addOverride( + R.bool.config_consumeNavigationBarTouchWhenNotificationPanelOpen, false); + when(mNotificationsShadeController.isNotificationPanelOpen()).thenReturn(true); + mNavBarView = (CarNavigationBarView) LayoutInflater.from(getContext()).inflate( + R.layout.car_navigation_bar_view_test, /* root= */ null); + mNavBarView.setNotificationsPanelController(mNotificationsShadeController); + mNavBarView.setStatusBarWindowTouchListener(mNavBarTouchListener); + + boolean consume = mNavBarView.onInterceptTouchEvent( + MotionEvent.obtain(/* downTime= */ 200, /* eventTime= */ 300, + MotionEvent.ACTION_MOVE, mNavBarView.getX(), + mNavBarView.getY(), /* metaState= */ 0)); + + assertThat(consume).isFalse(); + } + + @Test + public void dispatchTouch_shadeOpen_flagOn_consumesTouch() { + getContext().getOrCreateTestableResources().addOverride( + R.bool.config_consumeNavigationBarTouchWhenNotificationPanelOpen, true); + when(mNotificationsShadeController.isNotificationPanelOpen()).thenReturn(true); + mNavBarView = (CarNavigationBarView) LayoutInflater.from(getContext()).inflate( + R.layout.car_navigation_bar_view_test, /* root= */ null); + mNavBarView.setNotificationsPanelController(mNotificationsShadeController); + mNavBarView.setStatusBarWindowTouchListener(mNavBarTouchListener); + + boolean consume = mNavBarView.onInterceptTouchEvent( + MotionEvent.obtain(/* downTime= */ 200, /* eventTime= */ 300, + MotionEvent.ACTION_MOVE, mNavBarView.getX(), + mNavBarView.getY(), /* metaState= */ 0)); + + assertThat(consume).isTrue(); + } +}