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

Commit 31eaa2c2 authored by Alex Florescu's avatar Alex Florescu
Browse files

Cache value of shouldUseSplitNotificationShade

This only changes when the flag value changes (which can happen at any
time, but is strictly for development so we can ignore) or the value of
the boolean resource changes, which only happens on configuration
changed. Instead of checking every time, we can cache the last known
value and update on configuration changes.

Bug: 182254944
Test: manual + atest SystemUITests
Change-Id: Iae54b7680ebfc84c48139bd21e3c7670739802a5
parent ffa06964
Loading
Loading
Loading
Loading
+6 −1
Original line number Original line Diff line number Diff line
@@ -67,6 +67,7 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr
    private final DumpManager mDumpManager;
    private final DumpManager mDumpManager;
    private final FeatureFlags mFeatureFlags;
    private final FeatureFlags mFeatureFlags;
    protected final ArrayList<TileRecord> mRecords = new ArrayList<>();
    protected final ArrayList<TileRecord> mRecords = new ArrayList<>();
    private boolean mShouldUseSplitNotificationShade;


    private int mLastOrientation;
    private int mLastOrientation;
    private String mCachedSpecs = "";
    private String mCachedSpecs = "";
@@ -81,6 +82,8 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr
            new QSPanel.OnConfigurationChangedListener() {
            new QSPanel.OnConfigurationChangedListener() {
                @Override
                @Override
                public void onConfigurationChange(Configuration newConfig) {
                public void onConfigurationChange(Configuration newConfig) {
                    mShouldUseSplitNotificationShade =
                            Utils.shouldUseSplitNotificationShade(mFeatureFlags, getResources());
                    if (newConfig.orientation != mLastOrientation) {
                    if (newConfig.orientation != mLastOrientation) {
                        mLastOrientation = newConfig.orientation;
                        mLastOrientation = newConfig.orientation;
                        switchTileLayout(false);
                        switchTileLayout(false);
@@ -119,6 +122,8 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr
        mDumpManager = dumpManager;
        mDumpManager = dumpManager;
        mFeatureFlags = featureFlags;
        mFeatureFlags = featureFlags;
        mQSLabelFlag = featureFlags.isQSLabelsEnabled();
        mQSLabelFlag = featureFlags.isQSLabelsEnabled();
        mShouldUseSplitNotificationShade =
                Utils.shouldUseSplitNotificationShade(mFeatureFlags, getResources());
    }
    }


    @Override
    @Override
@@ -345,7 +350,7 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr
    }
    }


    boolean shouldUseHorizontalLayout() {
    boolean shouldUseHorizontalLayout() {
        if (Utils.shouldUseSplitNotificationShade(mFeatureFlags, getResources()))  {
        if (mShouldUseSplitNotificationShade)  {
            return false;
            return false;
        }
        }
        return mUsingMediaPlayer && mMediaHost.getVisible()
        return mUsingMediaPlayer && mMediaHost.getVisible()
+8 −5
Original line number Original line Diff line number Diff line
@@ -456,6 +456,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
    private long mNumHeadsUp;
    private long mNumHeadsUp;
    private NotificationStackScrollLayoutController.TouchHandler mTouchHandler;
    private NotificationStackScrollLayoutController.TouchHandler mTouchHandler;
    private final FeatureFlags mFeatureFlags;
    private final FeatureFlags mFeatureFlags;
    private boolean mShouldUseSplitNotificationShade;


    private final ExpandableView.OnHeightChangedListener mOnChildHeightChangedListener =
    private final ExpandableView.OnHeightChangedListener mOnChildHeightChangedListener =
            new ExpandableView.OnHeightChangedListener() {
            new ExpandableView.OnHeightChangedListener() {
@@ -500,7 +501,8 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
        super(context, attrs, 0, 0);
        super(context, attrs, 0, 0);
        Resources res = getResources();
        Resources res = getResources();
        mSectionsManager = notificationSectionsManager;
        mSectionsManager = notificationSectionsManager;

        mFeatureFlags = featureFlags;
        mShouldUseSplitNotificationShade = shouldUseSplitNotificationShade(mFeatureFlags, res);
        mSectionsManager.initialize(this, LayoutInflater.from(context));
        mSectionsManager.initialize(this, LayoutInflater.from(context));
        mSections = mSectionsManager.createSectionsForBuckets();
        mSections = mSectionsManager.createSectionsForBuckets();


@@ -533,7 +535,6 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
        mGroupMembershipManager = groupMembershipManager;
        mGroupMembershipManager = groupMembershipManager;
        mGroupExpansionManager = groupExpansionManager;
        mGroupExpansionManager = groupExpansionManager;
        mStatusbarStateController = statusbarStateController;
        mStatusbarStateController = statusbarStateController;
        mFeatureFlags = featureFlags;
    }
    }


    void initializeForegroundServiceSection(ForegroundServiceDungeonView fgsSectionView) {
    void initializeForegroundServiceSection(ForegroundServiceDungeonView fgsSectionView) {
@@ -1164,7 +1165,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
                if (stackStartPosition <= stackEndPosition) {
                if (stackStartPosition <= stackEndPosition) {
                    stackHeight = stackEndPosition;
                    stackHeight = stackEndPosition;
                } else {
                } else {
                    if (shouldUseSplitNotificationShade(mFeatureFlags, getResources())) {
                    if (mShouldUseSplitNotificationShade) {
                        // This prevents notifications from being collapsed when QS is expanded.
                        // This prevents notifications from being collapsed when QS is expanded.
                        stackHeight = (int) height;
                        stackHeight = (int) height;
                    } else {
                    } else {
@@ -1552,8 +1553,10 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
    @ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
    @ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
    protected void onConfigurationChanged(Configuration newConfig) {
    protected void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        super.onConfigurationChanged(newConfig);
        mStatusBarHeight = getResources().getDimensionPixelOffset(R.dimen.status_bar_height);
        Resources res = getResources();
        float densityScale = getResources().getDisplayMetrics().density;
        mShouldUseSplitNotificationShade = shouldUseSplitNotificationShade(mFeatureFlags, res);
        mStatusBarHeight = res.getDimensionPixelOffset(R.dimen.status_bar_height);
        float densityScale = res.getDisplayMetrics().density;
        mSwipeHelper.setDensityScale(densityScale);
        mSwipeHelper.setDensityScale(densityScale);
        float pagingTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop();
        float pagingTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop();
        mSwipeHelper.setPagingTouchSlop(pagingTouchSlop);
        mSwipeHelper.setPagingTouchSlop(pagingTouchSlop);
+13 −10
Original line number Original line Diff line number Diff line
@@ -305,6 +305,7 @@ public class NotificationPanelViewController extends PanelViewController {
    // Maximum # notifications to show on Keyguard; extras will be collapsed in an overflow card.
    // Maximum # notifications to show on Keyguard; extras will be collapsed in an overflow card.
    // If there are exactly 1 + mMaxKeyguardNotifications, then still shows all notifications
    // If there are exactly 1 + mMaxKeyguardNotifications, then still shows all notifications
    private final int mMaxKeyguardNotifications;
    private final int mMaxKeyguardNotifications;
    private boolean mShouldUseSplitNotificationShade;
    // Current max allowed keyguard notifications determined by measuring the panel
    // Current max allowed keyguard notifications determined by measuring the panel
    private int mMaxAllowedKeyguardNotifications;
    private int mMaxAllowedKeyguardNotifications;


@@ -598,6 +599,8 @@ public class NotificationPanelViewController extends PanelViewController {
                mKeyguardUserSwitcherEnabled && mResources.getBoolean(
                mKeyguardUserSwitcherEnabled && mResources.getBoolean(
                        R.bool.config_keyguard_user_switch_opens_qs_details);
                        R.bool.config_keyguard_user_switch_opens_qs_details);
        keyguardUpdateMonitor.setKeyguardQsUserSwitchEnabled(mKeyguardQsUserSwitchEnabled);
        keyguardUpdateMonitor.setKeyguardQsUserSwitchEnabled(mKeyguardQsUserSwitchEnabled);
        mShouldUseSplitNotificationShade =
                Utils.shouldUseSplitNotificationShade(mFeatureFlags, mResources);
        mView.setWillNotDraw(!DEBUG);
        mView.setWillNotDraw(!DEBUG);
        mLayoutInflater = layoutInflater;
        mLayoutInflater = layoutInflater;
        mFalsingManager = falsingManager;
        mFalsingManager = falsingManager;
@@ -736,7 +739,7 @@ public class NotificationPanelViewController extends PanelViewController {


        mView.setAccessibilityDelegate(mAccessibilityDelegate);
        mView.setAccessibilityDelegate(mAccessibilityDelegate);
        // dynamically apply the split shade value overrides.
        // dynamically apply the split shade value overrides.
        if (Utils.shouldUseSplitNotificationShade(mFeatureFlags, mResources)) {
        if (mShouldUseSplitNotificationShade) {
            updateResources();
            updateResources();
        }
        }
    }
    }
@@ -835,12 +838,13 @@ public class NotificationPanelViewController extends PanelViewController {
    public void updateResources() {
    public void updateResources() {
        int qsWidth = mResources.getDimensionPixelSize(R.dimen.qs_panel_width);
        int qsWidth = mResources.getDimensionPixelSize(R.dimen.qs_panel_width);
        int panelWidth = mResources.getDimensionPixelSize(R.dimen.notification_panel_width);
        int panelWidth = mResources.getDimensionPixelSize(R.dimen.notification_panel_width);

        mShouldUseSplitNotificationShade =
                Utils.shouldUseSplitNotificationShade(mFeatureFlags, mResources);
        // To change the constraints at runtime, all children of the ConstraintLayout must have ids
        // To change the constraints at runtime, all children of the ConstraintLayout must have ids
        ensureAllViewsHaveIds(mNotificationContainerParent);
        ensureAllViewsHaveIds(mNotificationContainerParent);
        ConstraintSet constraintSet = new ConstraintSet();
        ConstraintSet constraintSet = new ConstraintSet();
        constraintSet.clone(mNotificationContainerParent);
        constraintSet.clone(mNotificationContainerParent);
        if (Utils.shouldUseSplitNotificationShade(mFeatureFlags, mResources)) {
        if (mShouldUseSplitNotificationShade) {
            // width = 0 to take up all available space within constraints
            // width = 0 to take up all available space within constraints
            qsWidth = 0;
            qsWidth = 0;
            panelWidth = 0;
            panelWidth = 0;
@@ -1915,7 +1919,7 @@ public class NotificationPanelViewController extends PanelViewController {
                mBarState != KEYGUARD
                mBarState != KEYGUARD
                        && (!mQsExpanded
                        && (!mQsExpanded
                            || mQsExpansionFromOverscroll
                            || mQsExpansionFromOverscroll
                            || Utils.shouldUseSplitNotificationShade(mFeatureFlags, mResources)));
                            || mShouldUseSplitNotificationShade));


        if (mKeyguardUserSwitcherController != null && mQsExpanded
        if (mKeyguardUserSwitcherController != null && mQsExpanded
                && !mStackScrollerOverscrolling) {
                && !mStackScrollerOverscrolling) {
@@ -1987,7 +1991,7 @@ public class NotificationPanelViewController extends PanelViewController {


    private float calculateQsTopPadding() {
    private float calculateQsTopPadding() {
        // in split shade mode we want notifications to be directly below status bar
        // in split shade mode we want notifications to be directly below status bar
        if (Utils.shouldUseSplitNotificationShade(mFeatureFlags, mResources) && !mKeyguardShowing) {
        if (mShouldUseSplitNotificationShade && !mKeyguardShowing) {
            return 0f;
            return 0f;
        }
        }
        if (mKeyguardShowing && (mQsExpandImmediate
        if (mKeyguardShowing && (mQsExpandImmediate
@@ -2203,8 +2207,7 @@ public class NotificationPanelViewController extends PanelViewController {
            return true;
            return true;
        }
        }


        return !Utils.shouldUseSplitNotificationShade(mFeatureFlags, mResources)
        return !mShouldUseSplitNotificationShade && (isInSettings() || mIsPanelCollapseOnQQS);
                && (isInSettings() || mIsPanelCollapseOnQQS);
    }
    }


    @Override
    @Override
@@ -2631,7 +2634,7 @@ public class NotificationPanelViewController extends PanelViewController {
        super.onTrackingStarted();
        super.onTrackingStarted();
        if (mQsFullyExpanded) {
        if (mQsFullyExpanded) {
            mQsExpandImmediate = true;
            mQsExpandImmediate = true;
            if (!Utils.shouldUseSplitNotificationShade(mFeatureFlags, mResources)) {
            if (!mShouldUseSplitNotificationShade) {
                mNotificationStackScrollLayoutController.setShouldShowShelfOnly(true);
                mNotificationStackScrollLayoutController.setShouldShowShelfOnly(true);
            }
            }
        }
        }
@@ -2882,7 +2885,7 @@ public class NotificationPanelViewController extends PanelViewController {
     */
     */
    protected void updateHorizontalPanelPosition(float x) {
    protected void updateHorizontalPanelPosition(float x) {
        if (mNotificationStackScrollLayoutController.getWidth() * 1.75f > mView.getWidth()
        if (mNotificationStackScrollLayoutController.getWidth() * 1.75f > mView.getWidth()
                || Utils.shouldUseSplitNotificationShade(mFeatureFlags, mResources)) {
                || mShouldUseSplitNotificationShade) {
            resetHorizontalPanelPosition();
            resetHorizontalPanelPosition();
            return;
            return;
        }
        }
@@ -3564,7 +3567,7 @@ public class NotificationPanelViewController extends PanelViewController {
        @Override
        @Override
        public void onOverscrollTopChanged(float amount, boolean isRubberbanded) {
        public void onOverscrollTopChanged(float amount, boolean isRubberbanded) {
            // When in split shade, overscroll shouldn't carry through to QS
            // When in split shade, overscroll shouldn't carry through to QS
            if (Utils.shouldUseSplitNotificationShade(mFeatureFlags, mResources)) {
            if (mShouldUseSplitNotificationShade) {
                return;
                return;
            }
            }
            cancelQsAnimation();
            cancelQsAnimation();
+8 −0
Original line number Original line Diff line number Diff line
@@ -242,10 +242,18 @@ public class QSPanelControllerBaseTest extends SysuiTestCase {
        when(mMediaHost.getVisible()).thenReturn(true);
        when(mMediaHost.getVisible()).thenReturn(true);


        when(mFeatureFlags.isTwoColumnNotificationShadeEnabled()).thenReturn(false);
        when(mFeatureFlags.isTwoColumnNotificationShadeEnabled()).thenReturn(false);
        mController = new TestableQSPanelControllerBase(mQSPanel, mQSTileHost,
                mQSCustomizerController, mMediaHost,
                mMetricsLogger, mUiEventLogger, mQSLogger, mDumpManager, mFeatureFlags);

        assertThat(mController.shouldUseHorizontalLayout()).isTrue();
        assertThat(mController.shouldUseHorizontalLayout()).isTrue();


        when(mFeatureFlags.isTwoColumnNotificationShadeEnabled()).thenReturn(true);
        when(mFeatureFlags.isTwoColumnNotificationShadeEnabled()).thenReturn(true);
        when(mResources.getBoolean(R.bool.config_use_split_notification_shade)).thenReturn(true);
        when(mResources.getBoolean(R.bool.config_use_split_notification_shade)).thenReturn(true);
        mController = new TestableQSPanelControllerBase(mQSPanel, mQSTileHost,
                mQSCustomizerController, mMediaHost,
                mMetricsLogger, mUiEventLogger, mQSLogger, mDumpManager, mFeatureFlags);

        assertThat(mController.shouldUseHorizontalLayout()).isFalse();
        assertThat(mController.shouldUseHorizontalLayout()).isFalse();
    }
    }
}
}
+2 −2
Original line number Original line Diff line number Diff line
@@ -536,8 +536,7 @@ public class NotificationPanelViewTest extends SysuiTestCase {
    @Test
    @Test
    public void testCanCollapsePanelOnTouch_falseInDualPaneShade() {
    public void testCanCollapsePanelOnTouch_falseInDualPaneShade() {
        mStatusBarStateController.setState(SHADE);
        mStatusBarStateController.setState(SHADE);
        when(mResources.getBoolean(R.bool.config_use_split_notification_shade)).thenReturn(true);
        enableSplitShade();
        when(mFeatureFlags.isTwoColumnNotificationShadeEnabled()).thenReturn(true);
        mNotificationPanelViewController.setQsExpanded(true);
        mNotificationPanelViewController.setQsExpanded(true);


        assertThat(mNotificationPanelViewController.canCollapsePanelOnTouch()).isFalse();
        assertThat(mNotificationPanelViewController.canCollapsePanelOnTouch()).isFalse();
@@ -562,6 +561,7 @@ public class NotificationPanelViewTest extends SysuiTestCase {
    private void enableSplitShade() {
    private void enableSplitShade() {
        when(mResources.getBoolean(R.bool.config_use_split_notification_shade)).thenReturn(true);
        when(mResources.getBoolean(R.bool.config_use_split_notification_shade)).thenReturn(true);
        when(mFeatureFlags.isTwoColumnNotificationShadeEnabled()).thenReturn(true);
        when(mFeatureFlags.isTwoColumnNotificationShadeEnabled()).thenReturn(true);
        mNotificationPanelViewController.updateResources();
    }
    }


    private void onTouchEvent(MotionEvent ev) {
    private void onTouchEvent(MotionEvent ev) {