From b09c329afb471a1393425066734474c63656c68e Mon Sep 17 00:00:00 2001 From: Shawn Lee Date: Mon, 14 Nov 2022 16:26:11 -0800 Subject: [PATCH] Removed calls to NPVC.getView() Got rid of most NPVC.getView calls except for the ones in FoldAodAnimationController, to get closer to deleting it entirely. Bug: 254878364 Test: existing tests Change-Id: If8070d9ec766e7116178febd23cb3f9910d5affb --- .../NotificationPanelViewController.java | 26 ++++++++++++++++--- ...NotificationShadeWindowViewController.java | 2 +- .../systemui/shade/ShadeControllerImpl.java | 2 +- .../phone/StatusBarHeadsUpChangeListener.java | 4 +-- .../phone/StatusBarKeyguardViewManager.java | 3 +-- .../unfold/FoldAodAnimationController.kt | 2 ++ .../phone/CentralSurfacesImplTest.java | 1 - .../phone/PhoneStatusBarViewControllerTest.kt | 1 - .../statusbar/phone/PhoneStatusBarViewTest.kt | 4 --- .../unfold/FoldAodAnimationControllerTest.kt | 1 + 10 files changed, 31 insertions(+), 15 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java index 32c8f3bba6c1a..a1f076544c41f 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java +++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java @@ -672,7 +672,7 @@ public final class NotificationPanelViewController implements Dumpable { }; private final Runnable mMaybeHideExpandedRunnable = () -> { if (getExpansionFraction() == 0.0f) { - getView().post(mHideExpandedRunnable); + postToView(mHideExpandedRunnable); } }; @@ -2779,7 +2779,7 @@ public final class NotificationPanelViewController implements Dumpable { return top + mNotificationStackScrollLayoutController.getHeight() + mSplitShadeNotificationsScrimMarginBottom; } else { - return getView().getBottom(); + return mView.getBottom(); } } @@ -2794,7 +2794,7 @@ public final class NotificationPanelViewController implements Dumpable { private int calculateRightQsClippingBound() { if (mIsFullWidth) { - return getView().getRight() + mDisplayRightInset; + return mView.getRight() + mDisplayRightInset; } else { return mNotificationStackScrollLayoutController.getRight(); } @@ -5162,6 +5162,26 @@ public final class NotificationPanelViewController implements Dumpable { return mView; } + /** */ + public boolean postToView(Runnable action) { + return mView.post(action); + } + + /** */ + public boolean sendInterceptTouchEventToView(MotionEvent event) { + return mView.onInterceptTouchEvent(event); + } + + /** */ + public void requestLayoutOnView() { + mView.requestLayout(); + } + + /** */ + public void resetViewAlphas() { + ViewGroupFadeHelper.reset(mView); + } + private void beginJankMonitoring() { if (mInteractionJankMonitor == null) { return; diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowViewController.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowViewController.java index bb67280c07b84..27e56fb8003d3 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowViewController.java +++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowViewController.java @@ -311,7 +311,7 @@ public class NotificationShadeWindowViewController { MotionEvent cancellation = MotionEvent.obtain(ev); cancellation.setAction(MotionEvent.ACTION_CANCEL); mStackScrollLayout.onInterceptTouchEvent(cancellation); - mNotificationPanelViewController.getView().onInterceptTouchEvent(cancellation); + mNotificationPanelViewController.sendInterceptTouchEventToView(cancellation); cancellation.recycle(); } diff --git a/packages/SystemUI/src/com/android/systemui/shade/ShadeControllerImpl.java b/packages/SystemUI/src/com/android/systemui/shade/ShadeControllerImpl.java index eaf7faecd5b3a..d783293b95d43 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/ShadeControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/shade/ShadeControllerImpl.java @@ -160,7 +160,7 @@ public class ShadeControllerImpl implements ShadeController { if (getCentralSurfaces().getNotificationShadeWindowView() .isVisibleToUser()) { getNotificationPanelViewController().removeOnGlobalLayoutListener(this); - getNotificationPanelViewController().getView().post(executable); + getNotificationPanelViewController().postToView(executable); } } }); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeadsUpChangeListener.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeadsUpChangeListener.java index 5512bedb5dd41..3d6bebbe998c6 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeadsUpChangeListener.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeadsUpChangeListener.java @@ -72,9 +72,9 @@ public class StatusBarHeadsUpChangeListener implements OnHeadsUpChangedListener //resize the layout. Let's // make sure that the window stays small for one frame until the //touchableRegion is set. - mNotificationPanelViewController.getView().requestLayout(); + mNotificationPanelViewController.requestLayoutOnView(); mNotificationShadeWindowController.setForceWindowCollapsed(true); - mNotificationPanelViewController.getView().post(() -> { + mNotificationPanelViewController.postToView(() -> { mNotificationShadeWindowController.setForceWindowCollapsed(false); }); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java index 01a1ebe7fd686..78674f7b31a0a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java @@ -77,7 +77,6 @@ import com.android.systemui.statusbar.NotificationShadeWindowController; import com.android.systemui.statusbar.RemoteInputController; import com.android.systemui.statusbar.StatusBarState; import com.android.systemui.statusbar.SysuiStatusBarStateController; -import com.android.systemui.statusbar.notification.ViewGroupFadeHelper; import com.android.systemui.statusbar.phone.KeyguardBouncer.PrimaryBouncerExpansionCallback; import com.android.systemui.statusbar.policy.ConfigurationController; import com.android.systemui.statusbar.policy.KeyguardStateController; @@ -1009,7 +1008,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb public void onKeyguardFadedAway() { mNotificationContainer.postDelayed(() -> mNotificationShadeWindowController .setKeyguardFadingAway(false), 100); - ViewGroupFadeHelper.reset(mNotificationPanelViewController.getView()); + mNotificationPanelViewController.resetViewAlphas(); mCentralSurfaces.finishKeyguardFadingAway(); mBiometricUnlockController.finishKeyguardFadingAway(); WindowManagerGlobal.getInstance().trimMemory( diff --git a/packages/SystemUI/src/com/android/systemui/unfold/FoldAodAnimationController.kt b/packages/SystemUI/src/com/android/systemui/unfold/FoldAodAnimationController.kt index 0f0614414a3fc..6216acd6081e7 100644 --- a/packages/SystemUI/src/com/android/systemui/unfold/FoldAodAnimationController.kt +++ b/packages/SystemUI/src/com/android/systemui/unfold/FoldAodAnimationController.kt @@ -92,6 +92,7 @@ constructor( deviceStateManager.registerCallback(executor, FoldListener()) wakefulnessLifecycle.addObserver(this) + // TODO(b/254878364): remove this call to NPVC.getView() centralSurfaces.notificationPanelViewController.view.repeatWhenAttached { repeatOnLifecycle(Lifecycle.State.STARTED) { listenForDozing(this) } } @@ -157,6 +158,7 @@ constructor( // We don't need to wait for the scrim as it is already displayed // but we should wait for the initial animation preparations to be drawn // (setting initial alpha/translation) + // TODO(b/254878364): remove this call to NPVC.getView() OneShotPreDrawListener.add( centralSurfaces.notificationPanelViewController.view, onReady diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java index 41912f51db565..157b99dd3ef4e 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java @@ -355,7 +355,6 @@ public class CentralSurfacesImplTest extends SysuiTestCase { when(mStackScrollerController.getView()).thenReturn(mStackScroller); when(mStackScroller.generateLayoutParams(any())).thenReturn(new LayoutParams(0, 0)); - when(mNotificationPanelViewController.getView()).thenReturn(mNotificationPanelView); when(mNotificationPanelView.getLayoutParams()).thenReturn(new LayoutParams(0, 0)); when(powerManagerService.isInteractive()).thenReturn(true); when(mStackScroller.getActivatedChild()).thenReturn(null); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewControllerTest.kt index a61fba5c40000..c40bc88d3ee52 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewControllerTest.kt @@ -76,7 +76,6 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() { @Before fun setUp() { MockitoAnnotations.initMocks(this) - `when`(notificationPanelViewController.view).thenReturn(panelView) `when`(sysuiUnfoldComponent.getStatusBarMoveFromCenterAnimationController()) .thenReturn(moveFromCenterAnimation) // create the view on main thread as it requires main looper diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewTest.kt index 5aa7f92d22e87..27b1da0cb8967 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewTest.kt @@ -25,7 +25,6 @@ import com.google.common.truth.Truth.assertThat import org.junit.Before import org.junit.Test import org.mockito.Mock -import org.mockito.Mockito.`when` import org.mockito.MockitoAnnotations @SmallTest @@ -41,9 +40,6 @@ class PhoneStatusBarViewTest : SysuiTestCase() { @Before fun setUp() { MockitoAnnotations.initMocks(this) - // TODO(b/197137564): Setting up a panel view and its controller feels unnecessary when - // testing just [PhoneStatusBarView]. - `when`(notificationPanelViewController.view).thenReturn(panelView) view = PhoneStatusBarView(mContext, null) } diff --git a/packages/SystemUI/tests/src/com/android/systemui/unfold/FoldAodAnimationControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/unfold/FoldAodAnimationControllerTest.kt index 8645298682d60..89402de792dc1 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/unfold/FoldAodAnimationControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/unfold/FoldAodAnimationControllerTest.kt @@ -88,6 +88,7 @@ class FoldAodAnimationControllerTest : SysuiTestCase() { deviceStates = FoldableTestUtils.findDeviceStates(context) + // TODO(b/254878364): remove this call to NPVC.getView() whenever(notificationPanelViewController.view).thenReturn(viewGroup) whenever(viewGroup.viewTreeObserver).thenReturn(viewTreeObserver) whenever(wakefulnessLifecycle.lastSleepReason)