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

Commit 8642a8db authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Revert^2 [SB] Remove Dependency.get(SBContentInsetsProvider) from PhoneSBView." into main

parents 3a22eabd 6b476c18
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ import com.android.systemui.statusbar.notification.stack.AmbientState;
import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager;
import com.android.systemui.statusbar.phone.LightBarController;
import com.android.systemui.statusbar.phone.ScreenOffAnimationController;
import com.android.systemui.statusbar.phone.StatusBarContentInsetsProvider;
import com.android.systemui.statusbar.phone.SystemUIDialogManager;
import com.android.systemui.statusbar.policy.BluetoothController;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
@@ -140,7 +139,6 @@ public class Dependency {
    @Inject Lazy<SysUiState> mSysUiStateFlagsContainer;
    @Inject Lazy<CommandQueue> mCommandQueue;
    @Inject Lazy<UiEventLogger> mUiEventLogger;
    @Inject Lazy<StatusBarContentInsetsProvider> mContentInsetsProviderLazy;
    @Inject Lazy<FeatureFlags> mFeatureFlagsLazy;
    @Inject Lazy<NotificationSectionsManager> mNotificationSectionsManagerLazy;
    @Inject Lazy<ScreenOffAnimationController> mScreenOffAnimationController;
@@ -186,7 +184,6 @@ public class Dependency {
        mProviders.put(CommandQueue.class, mCommandQueue::get);
        mProviders.put(UiEventLogger.class, mUiEventLogger::get);
        mProviders.put(FeatureFlags.class, mFeatureFlagsLazy::get);
        mProviders.put(StatusBarContentInsetsProvider.class, mContentInsetsProviderLazy::get);
        mProviders.put(NotificationSectionsManager.class, mNotificationSectionsManagerLazy::get);
        mProviders.put(ScreenOffAnimationController.class, mScreenOffAnimationController::get);
        mProviders.put(AmbientState.class, mAmbientStateLazy::get);
+38 −5
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ import android.view.accessibility.AccessibilityEvent;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;

import com.android.internal.policy.SystemBarUtils;
import com.android.systemui.Dependency;
import com.android.systemui.Flags;
@@ -47,7 +49,6 @@ import java.util.Objects;

public class PhoneStatusBarView extends FrameLayout {
    private static final String TAG = "PhoneStatusBarView";
    private final StatusBarContentInsetsProvider mContentInsetsProvider;
    private final StatusBarWindowController mStatusBarWindowController;

    private int mRotationOrientation = -1;
@@ -60,6 +61,10 @@ public class PhoneStatusBarView extends FrameLayout {
    private int mStatusBarHeight;
    @Nullable
    private Gefingerpoken mTouchEventHandler;
    @Nullable
    private HasCornerCutoutFetcher mHasCornerCutoutFetcher;
    @Nullable
    private InsetsFetcher mInsetsFetcher;
    private int mDensity;
    private float mFontScale;

@@ -70,7 +75,6 @@ public class PhoneStatusBarView extends FrameLayout {

    public PhoneStatusBarView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContentInsetsProvider = Dependency.get(StatusBarContentInsetsProvider.class);
        mStatusBarWindowController = Dependency.get(StatusBarWindowController.class);
    }

@@ -78,6 +82,16 @@ public class PhoneStatusBarView extends FrameLayout {
        mTouchEventHandler = handler;
    }

    void setHasCornerCutoutFetcher(@NonNull HasCornerCutoutFetcher cornerCutoutFetcher) {
        mHasCornerCutoutFetcher = cornerCutoutFetcher;
        updateCutoutLocation();
    }

    void setInsetsFetcher(@NonNull InsetsFetcher insetsFetcher) {
        mInsetsFetcher = insetsFetcher;
        updateSafeInsets();
    }

    void init(StatusBarUserChipViewModel viewModel) {
        StatusBarUserSwitcherContainer container = findViewById(R.id.user_switcher_container);
        StatusBarUserChipViewBinder.bind(container, viewModel);
@@ -270,7 +284,14 @@ public class PhoneStatusBarView extends FrameLayout {
            return;
        }

        boolean hasCornerCutout = mContentInsetsProvider.currentRotationHasCornerCutout();
        boolean hasCornerCutout;
        if (mHasCornerCutoutFetcher != null) {
            hasCornerCutout = mHasCornerCutoutFetcher.fetchHasCornerCutout();
        } else {
            Log.e(TAG, "mHasCornerCutoutFetcher unexpectedly null");
            hasCornerCutout = true;
        }

        if (mDisplayCutout == null || mDisplayCutout.isEmpty() || hasCornerCutout) {
            mCutoutSpace.setVisibility(View.GONE);
            return;
@@ -288,8 +309,12 @@ public class PhoneStatusBarView extends FrameLayout {
    }

    private void updateSafeInsets() {
        Insets insets = mContentInsetsProvider
                .getStatusBarContentInsetsForCurrentRotation();
        if (mInsetsFetcher == null) {
            Log.e(TAG, "mInsetsFetcher unexpectedly null");
            return;
        }

        Insets insets  = mInsetsFetcher.fetchInsets();
        setPadding(
                insets.left,
                insets.top,
@@ -303,4 +328,12 @@ public class PhoneStatusBarView extends FrameLayout {
        }
        mStatusBarWindowController.refreshStatusBarHeight();
    }

    interface HasCornerCutoutFetcher {
        boolean fetchHasCornerCutout();
    }

    interface InsetsFetcher {
        Insets fetchInsets();
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ private constructor(
    private val configurationController: ConfigurationController,
    private val statusOverlayHoverListenerFactory: StatusOverlayHoverListenerFactory,
    private val darkIconDispatcher: DarkIconDispatcher,
    private val statusBarContentInsetsProvider: StatusBarContentInsetsProvider,
) : ViewController<PhoneStatusBarView>(view) {

    private lateinit var battery: BatteryMeterView
@@ -155,7 +156,14 @@ private constructor(
    }

    init {
        // These should likely be done in `onInit`, not `init`.
        mView.setTouchEventHandler(PhoneStatusBarViewTouchHandler())
        mView.setHasCornerCutoutFetcher {
            statusBarContentInsetsProvider.currentRotationHasCornerCutout()
        }
        mView.setInsetsFetcher {
            statusBarContentInsetsProvider.getStatusBarContentInsetsForCurrentRotation()
        }
        mView.init(userChipViewModel)
    }

@@ -310,6 +318,7 @@ private constructor(
        private val configurationController: ConfigurationController,
        private val statusOverlayHoverListenerFactory: StatusOverlayHoverListenerFactory,
        private val darkIconDispatcher: DarkIconDispatcher,
        private val statusBarContentInsetsProvider: StatusBarContentInsetsProvider,
    ) {
        fun create(view: PhoneStatusBarView): PhoneStatusBarViewController {
            val statusBarMoveFromCenterAnimationController =
@@ -335,6 +344,7 @@ private constructor(
                configurationController,
                statusOverlayHoverListenerFactory,
                darkIconDispatcher,
                statusBarContentInsetsProvider,
            )
        }
    }
+6 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.app.StatusBarManager.WINDOW_STATE_HIDDEN
import android.app.StatusBarManager.WINDOW_STATE_HIDING
import android.app.StatusBarManager.WINDOW_STATE_SHOWING
import android.app.StatusBarManager.WINDOW_STATUS_BAR
import android.graphics.Insets
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.view.InputDevice
@@ -92,6 +93,7 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() {
    @Mock private lateinit var windowRootView: Provider<WindowRootView>
    @Mock private lateinit var shadeLogger: ShadeLogger
    @Mock private lateinit var viewUtil: ViewUtil
    @Mock private lateinit var statusBarContentInsetsProvider: StatusBarContentInsetsProvider
    private lateinit var statusBarWindowStateController: StatusBarWindowStateController

    private lateinit var view: PhoneStatusBarView
@@ -111,6 +113,9 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() {

        statusBarWindowStateController = StatusBarWindowStateController(DISPLAY_ID, commandQueue)

        `when`(statusBarContentInsetsProvider.getStatusBarContentInsetsForCurrentRotation())
            .thenReturn(Insets.NONE)

        `when`(sysuiUnfoldComponent.getStatusBarMoveFromCenterAnimationController())
            .thenReturn(moveFromCenterAnimation)
        // create the view and controller on main thread as it requires main looper
@@ -391,6 +396,7 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() {
                configurationController,
                mStatusOverlayHoverListenerFactory,
                fakeDarkIconDispatcher,
                statusBarContentInsetsProvider,
            )
            .create(view)
            .also { it.init() }
+87 −29
Original line number Diff line number Diff line
@@ -56,21 +56,14 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
    private val systemIconsContainer: View
        get() = view.requireViewById(R.id.system_icons)

    private val contentInsetsProvider = mock<StatusBarContentInsetsProvider>()
    private val windowController = mock<StatusBarWindowController>()

    @Before
    fun setUp() {
        mDependency.injectTestDependency(
            StatusBarContentInsetsProvider::class.java,
            contentInsetsProvider
        )
        mDependency.injectTestDependency(StatusBarWindowController::class.java, windowController)
        context.ensureTestableResources()
        view = spy(createStatusBarView())
        whenever(view.rootWindowInsets).thenReturn(emptyWindowInsets())
        whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation())
            .thenReturn(Insets.NONE)
    }

    @Test
@@ -241,8 +234,7 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
    @Test
    fun onAttachedToWindow_updatesLeftTopRightPaddingsBasedOnInsets() {
        val insets = Insets.of(/* left= */ 10, /* top= */ 20, /* right= */ 30, /* bottom= */ 40)
        whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation())
            .thenReturn(insets)
        view.setInsetsFetcher { insets }

        view.onAttachedToWindow()

@@ -252,11 +244,40 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
        assertThat(view.paddingBottom).isEqualTo(0)
    }

    @Test
    fun onAttachedToWindow_noInsetsFetcher_noCrash() {
        // Don't call `PhoneStatusBarView.setInsetsFetcher`

        // WHEN the view is attached
        view.onAttachedToWindow()

        // THEN there's no crash, and the padding stays as it was
        assertThat(view.paddingLeft).isEqualTo(0)
        assertThat(view.paddingTop).isEqualTo(0)
        assertThat(view.paddingRight).isEqualTo(0)
        assertThat(view.paddingBottom).isEqualTo(0)
    }

    @Test
    fun onAttachedToWindow_thenGetsInsetsFetcher_insetsUpdated() {
        view.onAttachedToWindow()

        // WHEN the insets fetcher is set after the view is attached
        val insets = Insets.of(/* left= */ 10, /* top= */ 20, /* right= */ 30, /* bottom= */ 40)
        view.setInsetsFetcher { insets }

        // THEN the insets are updated
        assertThat(view.paddingLeft).isEqualTo(insets.left)
        assertThat(view.paddingTop).isEqualTo(insets.top)
        assertThat(view.paddingRight).isEqualTo(insets.right)
        assertThat(view.paddingBottom).isEqualTo(0)
    }


    @Test
    fun onConfigurationChanged_updatesLeftTopRightPaddingsBasedOnInsets() {
        val insets = Insets.of(/* left= */ 40, /* top= */ 30, /* right= */ 20, /* bottom= */ 10)
        whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation())
            .thenReturn(insets)
        view.setInsetsFetcher { insets }

        view.onConfigurationChanged(Configuration())

@@ -266,18 +287,40 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
        assertThat(view.paddingBottom).isEqualTo(0)
    }

    @Test
    fun onConfigurationChanged_noInsetsFetcher_noCrash() {
        // Don't call `PhoneStatusBarView.setInsetsFetcher`

        // WHEN the view is attached
        view.onConfigurationChanged(Configuration())

        // THEN there's no crash, and the padding stays as it was
        assertThat(view.paddingLeft).isEqualTo(0)
        assertThat(view.paddingTop).isEqualTo(0)
        assertThat(view.paddingRight).isEqualTo(0)
        assertThat(view.paddingBottom).isEqualTo(0)
    }

    @Test
    fun onConfigurationChanged_noRelevantChange_doesNotUpdateInsets() {
        val previousInsets =
            Insets.of(/* left= */ 40, /* top= */ 30, /* right= */ 20, /* bottom= */ 10)
        whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation())
            .thenReturn(previousInsets)
        val newInsets = Insets.NONE

        var useNewInsets = false
        val insetsFetcher = PhoneStatusBarView.InsetsFetcher {
            if (useNewInsets) {
                newInsets
            } else {
                previousInsets
            }
        }
        view.setInsetsFetcher(insetsFetcher)

        context.orCreateTestableResources.overrideConfiguration(Configuration())
        view.onAttachedToWindow()

        val newInsets = Insets.NONE
        whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation())
            .thenReturn(newInsets)
        useNewInsets = true
        view.onConfigurationChanged(Configuration())

        assertThat(view.paddingLeft).isEqualTo(previousInsets.left)
@@ -290,16 +333,24 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
    fun onConfigurationChanged_densityChanged_updatesInsets() {
        val previousInsets =
            Insets.of(/* left= */ 40, /* top= */ 30, /* right= */ 20, /* bottom= */ 10)
        whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation())
            .thenReturn(previousInsets)
        val newInsets = Insets.NONE

        var useNewInsets = false
        val insetsFetcher = PhoneStatusBarView.InsetsFetcher {
            if (useNewInsets) {
                newInsets
            } else {
                previousInsets
            }
        }
        view.setInsetsFetcher(insetsFetcher)

        val configuration = Configuration()
        configuration.densityDpi = 123
        context.orCreateTestableResources.overrideConfiguration(configuration)
        view.onAttachedToWindow()

        val newInsets = Insets.NONE
        whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation())
            .thenReturn(newInsets)
        useNewInsets = true
        configuration.densityDpi = 456
        view.onConfigurationChanged(configuration)

@@ -313,16 +364,24 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
    fun onConfigurationChanged_fontScaleChanged_updatesInsets() {
        val previousInsets =
            Insets.of(/* left= */ 40, /* top= */ 30, /* right= */ 20, /* bottom= */ 10)
        whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation())
            .thenReturn(previousInsets)
        val newInsets = Insets.NONE

        var useNewInsets = false
        val insetsFetcher = PhoneStatusBarView.InsetsFetcher {
            if (useNewInsets) {
                newInsets
            } else {
                previousInsets
            }
        }
        view.setInsetsFetcher(insetsFetcher)

        val configuration = Configuration()
        configuration.fontScale = 1f
        context.orCreateTestableResources.overrideConfiguration(configuration)
        view.onAttachedToWindow()

        val newInsets = Insets.NONE
        whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation())
            .thenReturn(newInsets)
        useNewInsets = true
        configuration.fontScale = 2f
        view.onConfigurationChanged(configuration)

@@ -348,8 +407,7 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
    @Test
    fun onApplyWindowInsets_updatesLeftTopRightPaddingsBasedOnInsets() {
        val insets = Insets.of(/* left= */ 90, /* top= */ 10, /* right= */ 45, /* bottom= */ 50)
        whenever(contentInsetsProvider.getStatusBarContentInsetsForCurrentRotation())
            .thenReturn(insets)
        view.setInsetsFetcher { insets }

        view.onApplyWindowInsets(WindowInsets(Rect()))

@@ -390,7 +448,7 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
            /* typeVisibilityMap = */ booleanArrayOf(),
            /* isRound = */ false,
            /* forceConsumingTypes = */ 0,
            /* forceConsumingCaptionBar = */ false,
            /* forceConsumingOpaqueCaptionBar = */ false,
            /* suppressScrimTypes = */ 0,
            /* displayCutout = */ DisplayCutout.NO_CUTOUT,
            /* roundedCorners = */ RoundedCorners.NO_ROUNDED_CORNERS,