Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 53f2c5ac authored by Caitlin Cassidy's avatar Caitlin Cassidy
Browse files

[Dagger] Move CommandQueue out of PhoneStatusBarView.

Test: atest and manual
Bug: 138786270
Change-Id: I79d2b0e3f4751cdf816059da9d52aa6d624d9c75
parent 3344593e
Loading
Loading
Loading
Loading
+19 −4
Original line number Diff line number Diff line
@@ -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<StatusBar.ExpansionChangedListener> 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();
    }
}
+6 −1
Original line number Diff line number Diff line
@@ -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<PhoneStatusBarView> {
    protected PhoneStatusBarViewController(PhoneStatusBarView view) {

    protected PhoneStatusBarViewController(
            PhoneStatusBarView view,
            CommandQueue commandQueue) {
        super(view);
        mView.setPanelEnabledProvider(commandQueue::panelsEnabled);
    }

    @Override
+1 −1
Original line number Diff line number Diff line
@@ -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
+60 −0
Original line number Diff line number Diff line
/*
 * 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()
    }
}
+54 −0
Original line number Diff line number Diff line
/*
 * 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
    }
}