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

Commit 1d61cdf3 authored by Ibrahim Yilmaz's avatar Ibrahim Yilmaz Committed by Android (Google) Code Review
Browse files

Merge "Force RONs to always be expanded" into main

parents b60b3606 a5c1ce98
Loading
Loading
Loading
Loading
+67 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.statusbar.notification.stack

import android.annotation.DimenRes
import android.platform.test.annotations.EnableFlags
import android.service.notification.StatusBarNotification
import android.view.View.VISIBLE
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -30,6 +31,7 @@ import com.android.systemui.statusbar.StatusBarState
import com.android.systemui.statusbar.SysuiStatusBarStateController
import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.domain.interactor.SeenNotificationsInteractor
import com.android.systemui.statusbar.notification.promoted.PromotedNotificationUiForceExpanded
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
import com.android.systemui.statusbar.notification.row.ExpandableView
import com.android.systemui.statusbar.policy.ResourcesSplitShadeStateController
@@ -151,6 +153,29 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() {
        assertThat(maxNotifications).isEqualTo(1)
    }

    @Test
    @EnableFlags(PromotedNotificationUiForceExpanded.FLAG_NAME)
    fun maxKeyguardNotificationsForPromotedOngoing_onLockscreenSpaceForMinHeightButNotIntrinsicHeight_returnsOne() {
        setGapHeight(0f)
        // No divider height since we're testing one element where index = 0

        whenever(sysuiStatusBarStateController.state).thenReturn(StatusBarState.KEYGUARD)
        whenever(lockscreenShadeTransitionController.fractionToShade).thenReturn(0f)

        val row = createMockRow(10f, isPromotedOngoing = true)
        whenever(row.getMinHeight(any())).thenReturn(5)

        val maxNotifications =
            computeMaxKeyguardNotifications(
                listOf(row),
                /* spaceForNotifications= */ 5f,
                /* spaceForShelf= */ 0f,
                /* shelfHeight= */ 0f,
            )

        assertThat(maxNotifications).isEqualTo(1)
    }

    @Test
    fun computeMaxKeyguardNotifications_spaceForTwo_returnsTwo() {
        setGapHeight(gapHeight)
@@ -256,6 +281,26 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() {
        assertThat(space.whenEnoughSpace).isEqualTo(10f)
    }

    @Test
    @EnableFlags(PromotedNotificationUiForceExpanded.FLAG_NAME)
    fun getSpaceNeeded_onLockscreenEnoughSpacePromotedOngoing_intrinsicHeight() {
        setGapHeight(0f)
        // No divider height since we're testing one element where index = 0

        val row = createMockRow(10f, isPromotedOngoing = true)
        whenever(row.getMinHeight(any())).thenReturn(5)

        val space =
            sizeCalculator.getSpaceNeeded(
                row,
                visibleIndex = 0,
                previousView = null,
                stack = stackLayout,
                onLockscreen = true,
            )
        assertThat(space.whenEnoughSpace).isEqualTo(10f)
    }

    @Test
    fun getSpaceNeeded_onLockscreenEnoughSpaceNotStickyHun_minHeight() {
        setGapHeight(0f)
@@ -295,6 +340,26 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() {
        assertThat(space.whenSavingSpace).isEqualTo(5)
    }

    @Test
    @EnableFlags(PromotedNotificationUiForceExpanded.FLAG_NAME)
    fun getSpaceNeeded_onLockscreenSavingSpacePromotedOngoing_minHeight() {
        setGapHeight(0f)
        // No divider height since we're testing one element where index = 0

        val expandableView = createMockRow(10f, isPromotedOngoing = true)
        whenever(expandableView.getMinHeight(any())).thenReturn(5)

        val space =
            sizeCalculator.getSpaceNeeded(
                expandableView,
                visibleIndex = 0,
                previousView = null,
                stack = stackLayout,
                onLockscreen = true,
            )
        assertThat(space.whenSavingSpace).isEqualTo(5)
    }

    @Test
    fun getSpaceNeeded_onLockscreenSavingSpaceNotStickyHun_minHeight() {
        setGapHeight(0f)
@@ -366,6 +431,7 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() {
        isSticky: Boolean = false,
        isRemoved: Boolean = false,
        visibility: Int = VISIBLE,
        isPromotedOngoing: Boolean = false,
    ): ExpandableNotificationRow {
        val row = mock(ExpandableNotificationRow::class.java)
        val entry = mock(NotificationEntry::class.java)
@@ -378,6 +444,7 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() {
        whenever(row.getMinHeight(any())).thenReturn(height.toInt())
        whenever(row.intrinsicHeight).thenReturn(height.toInt())
        whenever(row.heightWithoutLockscreenConstraints).thenReturn(height.toInt())
        whenever(row.isPromotedOngoing).thenReturn(isPromotedOngoing)
        return row
    }

+3 −0
Original line number Diff line number Diff line
@@ -266,6 +266,9 @@
    <!-- Height of a large notification in the status bar -->
    <dimen name="notification_max_height">358dp</dimen>

    <!-- Height of a large promoted ongoing notification in the status bar -->
    <dimen name="notification_max_height_for_promoted_ongoing">218dp</dimen>

    <!-- Height of a heads up notification in the status bar for legacy custom views -->
    <dimen name="notification_max_heads_up_height_legacy">128dp</dimen>

+8 −0
Original line number Diff line number Diff line
@@ -835,6 +835,14 @@ public final class NotificationEntry extends ListEntry {
        return false;
    }

    /**
     * Returns whether the NotificationEntry is promoted ongoing.
     */
    @FlaggedApi(Flags.FLAG_API_RICH_ONGOING)
    public boolean isOngoingPromoted() {
        return mSbn.getNotification().isPromotedOngoing();
    }

    /**
     * Returns whether this row is considered blockable (i.e. it's not a system notif
     * or is not in an allowList).
+83 −2
Original line number Diff line number Diff line
@@ -107,6 +107,7 @@ import com.android.systemui.statusbar.notification.headsup.HeadsUpManager;
import com.android.systemui.statusbar.notification.headsup.PinnedStatus;
import com.android.systemui.statusbar.notification.logging.NotificationCounters;
import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier;
import com.android.systemui.statusbar.notification.promoted.PromotedNotificationUiForceExpanded;
import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationFlag;
import com.android.systemui.statusbar.notification.row.shared.AsyncGroupHeaderViewInflation;
import com.android.systemui.statusbar.notification.row.shared.LockscreenOtpRedaction;
@@ -164,6 +165,8 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
    private boolean mShowSnooze = false;
    private boolean mIsFaded;

    private boolean mIsPromotedOngoing = false;

    /**
     * Listener for when {@link ExpandableNotificationRow} is laid out.
     */
@@ -197,6 +200,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
    private int mMaxSmallHeightBeforeS;
    private int mMaxSmallHeight;
    private int mMaxExpandedHeight;
    private int mMaxExpandedHeightForPromotedOngoing;
    private int mNotificationLaunchHeight;
    private boolean mMustStayOnScreen;

@@ -331,6 +335,15 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
     */
    private boolean mSaveSpaceOnLockscreen;

    /**
     * It is added for unit testing purpose.
     * Please do not use it for other purposes.
     */
    @VisibleForTesting
    public void setIgnoreLockscreenConstraints(boolean ignoreLockscreenConstraints) {
        mIgnoreLockscreenConstraints = ignoreLockscreenConstraints;
    }

    /**
     * True if we use intrinsic height regardless of vertical space available on lockscreen.
     */
@@ -805,6 +818,13 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
    }

    private void updateLimitsForView(NotificationContentView layout) {
        final int maxExpandedHeight;
        if (isPromotedOngoing()) {
            maxExpandedHeight = mMaxExpandedHeightForPromotedOngoing;
        } else {
            maxExpandedHeight = mMaxExpandedHeight;
        }

        View contractedView = layout.getContractedChild();
        boolean customView = contractedView != null
                && contractedView.getId()
@@ -825,7 +845,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
                smallHeight = mMaxSmallHeightBeforeS;
            }
        } else if (isCallLayout) {
            smallHeight = mMaxExpandedHeight;
            smallHeight = maxExpandedHeight;
        } else {
            smallHeight = mMaxSmallHeight;
        }
@@ -849,7 +869,8 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        if (headsUpWrapper != null) {
            headsUpHeight = Math.max(headsUpHeight, headsUpWrapper.getMinLayoutHeight());
        }
        layout.setHeights(smallHeight, headsUpHeight, mMaxExpandedHeight);

        layout.setHeights(smallHeight, headsUpHeight, maxExpandedHeight);
    }

    @NonNull
@@ -1259,6 +1280,9 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        if (mIsSummaryWithChildren) {
            return mChildrenContainer.getIntrinsicHeight();
        }
        if (isPromotedOngoing()) {
            return getMaxExpandHeight();
        }
        if (mExpandedWhenPinned) {
            return Math.max(getMaxExpandHeight(), getHeadsUpHeight());
        } else if (android.app.Flags.compactHeadsUpNotification()
@@ -2078,6 +2102,8 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        }
        mMaxExpandedHeight = NotificationUtils.getFontScaledHeight(mContext,
                R.dimen.notification_max_height);
        mMaxExpandedHeightForPromotedOngoing = NotificationUtils.getFontScaledHeight(mContext,
                R.dimen.notification_max_height_for_promoted_ongoing);
        mMaxHeadsUpHeightBeforeN = NotificationUtils.getFontScaledHeight(mContext,
                R.dimen.notification_max_heads_up_height_legacy);
        mMaxHeadsUpHeightBeforeP = NotificationUtils.getFontScaledHeight(mContext,
@@ -2763,6 +2789,9 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        if (mIsSummaryWithChildren && !shouldShowPublic()) {
            return !mChildrenExpanded;
        }
        if (isPromotedOngoing()) {
            return false;
        }
        return mEnableNonGroupedNotificationExpand && mExpandable;
    }

@@ -2771,6 +2800,18 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        mPrivateLayout.updateExpandButtons(isExpandable());
    }

    /**
     * Set this notification to be promoted ongoing
     */
    public void setPromotedOngoing(boolean promotedOngoing) {
        if (PromotedNotificationUiForceExpanded.isUnexpectedlyInLegacyMode()) {
            return;
        }

        mIsPromotedOngoing = promotedOngoing;
        setExpandable(!mIsPromotedOngoing);
    }

    @Override
    public void setClipToActualHeight(boolean clipToActualHeight) {
        super.setClipToActualHeight(clipToActualHeight || isUserLocked());
@@ -2840,6 +2881,8 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
    }

    public void setUserLocked(boolean userLocked) {
        if (isPromotedOngoing()) return;

        mUserLocked = userLocked;
        mPrivateLayout.setUserExpanding(userLocked);
        // This is intentionally not guarded with mIsSummaryWithChildren since we might have had
@@ -3001,6 +3044,35 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        }
    }

    public boolean isPromotedOngoing() {
        return PromotedNotificationUiForceExpanded.isEnabled() && mIsPromotedOngoing;
    }

    private boolean isPromotedNotificationExpanded(boolean allowOnKeyguard) {
        // public view in non group notifications is always collapsed.
        if (shouldShowPublic()) {
            return false;
        }
        // RON will always be expanded when it is not on keyguard.
        if (!mOnKeyguard) {
            return true;
        }
        // RON will always be expanded when it is allowed on keyguard.
        // allowOnKeyguard is used for getting the maximum height by NotificationContentView and
        // NotificationChildrenContainer.
        if (allowOnKeyguard) {
            return true;
        }

        // RON will be expanded when it needs to ignore lockscreen constraints.
        if (mIgnoreLockscreenConstraints) {
            return true;
        }

        // RON will need be collapsed when it needs to save space on the lock screen.
        return !mSaveSpaceOnLockscreen;
    }

    /**
     * Check whether the view state is currently expanded. This is given by the system in {@link
     * #setSystemExpanded(boolean)} and can be overridden by user expansion or
@@ -3014,6 +3086,10 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
    }

    public boolean isExpanded(boolean allowOnKeyguard) {
        if (isPromotedOngoing()) {
            return isPromotedNotificationExpanded(allowOnKeyguard);
        }

        return (!shouldShowPublic()) && (!mOnKeyguard || allowOnKeyguard)
                && (!hasUserChangedExpansion()
                && (isSystemExpanded() || isSystemChildExpanded())
@@ -4015,6 +4091,11 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
                    + (!shouldShowPublic() && mIsSummaryWithChildren));
            pw.print(", mShowNoBackground: " + mShowNoBackground);
            pw.print(", clipBounds: " + getClipBounds());
            if (PromotedNotificationUiForceExpanded.isEnabled()) {
                pw.print(", isPromotedOngoing: " + isPromotedOngoing());
                pw.print(", isExpandable: " + isExpandable());
                pw.print(", mExpandable: " + mExpandable);
            }

            pw.println();
            if (NotificationContentView.INCLUDE_HEIGHTS_TO_DUMP) {
+5 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ import com.android.systemui.statusbar.notification.ConversationNotificationProce
import com.android.systemui.statusbar.notification.InflationException;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.promoted.PromotedNotificationContentExtractor;
import com.android.systemui.statusbar.notification.promoted.PromotedNotificationUiForceExpanded;
import com.android.systemui.statusbar.notification.promoted.shared.model.PromotedNotificationContentModel;
import com.android.systemui.statusbar.notification.row.shared.AsyncGroupHeaderViewInflation;
import com.android.systemui.statusbar.notification.row.shared.AsyncHybridViewInflation;
@@ -1111,6 +1112,10 @@ public class NotificationContentInflater implements NotificationRowContentBinder

        entry.setHeadsUpStatusBarText(result.headsUpStatusBarText);
        entry.setHeadsUpStatusBarTextPublic(result.headsUpStatusBarTextPublic);
        if (PromotedNotificationUiForceExpanded.isEnabled()) {
            row.setPromotedOngoing(entry.isOngoingPromoted());
        }

        Trace.endAsyncSection(APPLY_TRACE_METHOD, System.identityHashCode(row));
        if (endListener != null) {
            endListener.onAsyncInflationFinished(entry);
Loading