From 53f2c5ac8a2dcabe629656227de59af1466920b9 Mon Sep 17 00:00:00 2001 From: Caitlin Cassidy Date: Thu, 29 Jul 2021 12:49:27 +0000 Subject: [PATCH] [Dagger] Move CommandQueue out of PhoneStatusBarView. Test: atest and manual Bug: 138786270 Change-Id: I79d2b0e3f4751cdf816059da9d52aa6d624d9c75 --- .../statusbar/phone/PhoneStatusBarView.java | 23 +++++-- .../phone/PhoneStatusBarViewController.java | 7 ++- .../systemui/statusbar/phone/StatusBar.java | 2 +- .../phone/PhoneStatusBarViewControllerTest.kt | 60 +++++++++++++++++++ .../statusbar/phone/PhoneStatusBarViewTest.kt | 54 +++++++++++++++++ 5 files changed, 140 insertions(+), 6 deletions(-) create mode 100644 packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewControllerTest.kt create mode 100644 packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewTest.kt diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java index c300b11b9a34b..70a46b25c1eb7 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java @@ -27,6 +27,7 @@ import android.graphics.Point; import android.graphics.Rect; import android.util.AttributeSet; import android.util.EventLog; +import android.util.Log; import android.util.Pair; import android.view.DisplayCutout; import android.view.Gravity; @@ -42,7 +43,6 @@ import com.android.systemui.EventLogTags; import com.android.systemui.R; import com.android.systemui.plugins.DarkIconDispatcher; import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver; -import com.android.systemui.statusbar.CommandQueue; import com.android.systemui.util.leak.RotationUtils; import java.util.List; @@ -52,7 +52,6 @@ public class PhoneStatusBarView extends PanelBar { private static final String TAG = "PhoneStatusBarView"; private static final boolean DEBUG = StatusBar.DEBUG; private static final boolean DEBUG_GESTURES = false; - private final CommandQueue mCommandQueue; private final StatusBarContentInsetsProvider mContentInsetsProvider; StatusBar mBar; @@ -81,6 +80,8 @@ public class PhoneStatusBarView extends PanelBar { @Nullable private List mExpansionChangedListeners; + private PanelEnabledProvider mPanelEnabledProvider; + /** * Draw this many pixels into the left/right side of the cutout to optimally use the space */ @@ -89,7 +90,6 @@ public class PhoneStatusBarView extends PanelBar { public PhoneStatusBarView(Context context, AttributeSet attrs) { super(context, attrs); - mCommandQueue = Dependency.get(CommandQueue.class); mContentInsetsProvider = Dependency.get(StatusBarContentInsetsProvider.class); } @@ -177,7 +177,11 @@ public class PhoneStatusBarView extends PanelBar { @Override public boolean panelEnabled() { - return mCommandQueue.panelsEnabled(); + if (mPanelEnabledProvider == null) { + Log.e(TAG, "panelEnabledProvider is null; defaulting to super class."); + return super.panelEnabled(); + } + return mPanelEnabledProvider.panelEnabled(); } @Override @@ -294,6 +298,11 @@ public class PhoneStatusBarView extends PanelBar { } } + /** Set the {@link PanelEnabledProvider} to use. */ + public void setPanelEnabledProvider(PanelEnabledProvider panelEnabledProvider) { + mPanelEnabledProvider = panelEnabledProvider; + } + private void updateScrimFraction() { float scrimFraction = mPanelFraction; if (mMinFraction < 1.0f) { @@ -391,4 +400,10 @@ public class PhoneStatusBarView extends PanelBar { protected boolean shouldPanelBeVisible() { return mHeadsUpVisible || super.shouldPanelBeVisible(); } + + /** An interface that will provide whether panel is enabled. */ + interface PanelEnabledProvider { + /** Returns true if the panel is enabled and false otherwise. */ + boolean panelEnabled(); + } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewController.java index 55b5670930dbd..b36b67dc02c01 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewController.java @@ -16,12 +16,17 @@ package com.android.systemui.statusbar.phone; +import com.android.systemui.statusbar.CommandQueue; import com.android.systemui.util.ViewController; /** Controller for {@link PhoneStatusBarView}. */ public class PhoneStatusBarViewController extends ViewController { - protected PhoneStatusBarViewController(PhoneStatusBarView view) { + + protected PhoneStatusBarViewController( + PhoneStatusBarView view, + CommandQueue commandQueue) { super(view); + mView.setPanelEnabledProvider(commandQueue::panelsEnabled); } @Override diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index 8684033620a3a..9d75655c83c52 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -1206,7 +1206,7 @@ public class StatusBar extends SystemUI implements mStatusBarView.setScrimController(mScrimController); mStatusBarView.setExpansionChangedListeners(mExpansionChangedListeners); mPhoneStatusBarViewController = - new PhoneStatusBarViewController(mStatusBarView); + new PhoneStatusBarViewController(mStatusBarView, mCommandQueue); mPhoneStatusBarViewController.init(); // CollapsedStatusBarFragment re-inflated PhoneStatusBarView and both of 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 new file mode 100644 index 0000000000000..50cea073c7015 --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewControllerTest.kt @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2021 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.statusbar.phone + +import androidx.test.filters.SmallTest +import com.android.systemui.SysuiTestCase +import com.android.systemui.statusbar.CommandQueue +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 +class PhoneStatusBarViewControllerTest : SysuiTestCase() { + + @Mock + private lateinit var commandQueue: CommandQueue + + private lateinit var view: PhoneStatusBarView + private lateinit var controller: PhoneStatusBarViewController + + @Before + fun setUp() { + MockitoAnnotations.initMocks(this) + + view = PhoneStatusBarView(mContext, null) + controller = PhoneStatusBarViewController(view, commandQueue) + } + + @Test + fun constructor_setsPanelEnabledProviderOnView() { + var providerUsed = false + `when`(commandQueue.panelsEnabled()).then { + providerUsed = true + true + } + + // If the constructor correctly set a [PanelEnabledProvider], then it should be used + // when [PhoneStatusBarView.panelEnabled] is called. + view.panelEnabled() + + assertThat(providerUsed).isTrue() + } +} 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 new file mode 100644 index 0000000000000..49ab6ebbde93e --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewTest.kt @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2021 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.statusbar.phone + +import androidx.test.filters.SmallTest +import com.android.systemui.SysuiTestCase +import com.google.common.truth.Truth.assertThat +import org.junit.Before +import org.junit.Test + +@SmallTest +class PhoneStatusBarViewTest : SysuiTestCase() { + + private lateinit var view: PhoneStatusBarView + + @Before + fun setUp() { + view = PhoneStatusBarView(mContext, null) + } + + @Test + fun panelEnabled_providerReturnsTrue_returnsTrue() { + view.setPanelEnabledProvider { true } + + assertThat(view.panelEnabled()).isTrue() + } + + @Test + fun panelEnabled_providerReturnsFalse_returnsFalse() { + view.setPanelEnabledProvider { false } + + assertThat(view.panelEnabled()).isFalse() + } + + @Test + fun panelEnabled_noProvider_noCrash() { + view.panelEnabled() + // No assert needed, just testing no crash + } +}