diff options
| author | 2024-11-26 22:29:40 +0000 | |
|---|---|---|
| committer | 2025-01-23 11:22:19 +0000 | |
| commit | a5c1ce980df7e1df06e297ca656c8bb4894e5dc7 (patch) | |
| tree | da9ae9b02f8b3bf6d3901cb240bc5f7cafaa6c32 | |
| parent | 406336989d7ed25475afbb7a5585ad69c0122349 (diff) | |
Force RONs to always be expanded
Bug: 380901479
Test: Presubmit (new tests in ENRTest and NotificationStackSizeCalculatorTest)
Flag: android.app.ui_rich_ongoing
Change-Id: I304095d67de5c1a9d1afadc9555e0f818c760989
7 files changed, 253 insertions, 3 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/stack/NotificationStackSizeCalculatorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/stack/NotificationStackSizeCalculatorTest.kt index 50db9f7268e4..4b8a0c21f03d 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/stack/NotificationStackSizeCalculatorTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/stack/NotificationStackSizeCalculatorTest.kt @@ -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 @@ -152,6 +154,29 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() { } @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) val shelfHeight = shelfHeight + dividerHeight @@ -257,6 +282,26 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() { } @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) // No divider height since we're testing one element where index = 0 @@ -296,6 +341,26 @@ class NotificationStackSizeCalculatorTest : SysuiTestCase() { } @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) // No divider height since we're testing one element where index = 0 @@ -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 } diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index f9904e336f24..3f7ea0acb105 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -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> diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java index 417e57d2205f..5cc79df9130a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java @@ -836,6 +836,14 @@ public final class NotificationEntry extends ListEntry { } /** + * 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). */ diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java index 598ff09ba3b0..dc6cd789b914 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java @@ -106,6 +106,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; @@ -163,6 +164,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. */ @@ -196,6 +199,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView private int mMaxSmallHeightBeforeS; private int mMaxSmallHeight; private int mMaxExpandedHeight; + private int mMaxExpandedHeightForPromotedOngoing; private int mNotificationLaunchHeight; private boolean mMustStayOnScreen; @@ -330,6 +334,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. */ private boolean mIgnoreLockscreenConstraints; @@ -803,6 +816,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() @@ -823,7 +843,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView smallHeight = mMaxSmallHeightBeforeS; } } else if (isCallLayout) { - smallHeight = mMaxExpandedHeight; + smallHeight = maxExpandedHeight; } else { smallHeight = mMaxSmallHeight; } @@ -847,7 +867,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 @@ -1257,6 +1278,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() @@ -2072,6 +2096,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, @@ -2757,6 +2783,9 @@ public class ExpandableNotificationRow extends ActivatableNotificationView if (mIsSummaryWithChildren && !shouldShowPublic()) { return !mChildrenExpanded; } + if (isPromotedOngoing()) { + return false; + } return mEnableNonGroupedNotificationExpand && mExpandable; } @@ -2765,6 +2794,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()); @@ -2834,6 +2875,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 @@ -2995,6 +3038,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 @@ -3008,6 +3080,10 @@ public class ExpandableNotificationRow extends ActivatableNotificationView } public boolean isExpanded(boolean allowOnKeyguard) { + if (isPromotedOngoing()) { + return isPromotedNotificationExpanded(allowOnKeyguard); + } + return (!shouldShowPublic()) && (!mOnKeyguard || allowOnKeyguard) && (!hasUserChangedExpansion() && (isSystemExpanded() || isSystemChildExpanded()) @@ -4006,6 +4082,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) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentInflater.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentInflater.java index 57fe24f40acb..c0dbb37c1b36 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentInflater.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentInflater.java @@ -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); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackSizeCalculator.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackSizeCalculator.kt index a96d972af2c4..08bc8f5d5bb9 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackSizeCalculator.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackSizeCalculator.kt @@ -29,6 +29,7 @@ import com.android.systemui.statusbar.LockscreenShadeTransitionController import com.android.systemui.statusbar.StatusBarState.KEYGUARD import com.android.systemui.statusbar.SysuiStatusBarStateController 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.notification.shared.NotificationMinimalism @@ -463,7 +464,12 @@ constructor( var size = if (onLockscreen) { - if (view is ExpandableNotificationRow && view.entry.isStickyAndNotDemoted) { + if ( + view is ExpandableNotificationRow && + (view.entry.isStickyAndNotDemoted || + (PromotedNotificationUiForceExpanded.isEnabled && + view.isPromotedOngoing)) + ) { height } else { view.getMinHeight(/* ignoreTemporaryStates= */ true).toFloat() diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java index 5aee92939ed5..5fa3e2055686 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java @@ -69,6 +69,7 @@ import com.android.systemui.statusbar.notification.FeedbackIcon; import com.android.systemui.statusbar.notification.SourceType; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.notification.headsup.PinnedStatus; +import com.android.systemui.statusbar.notification.promoted.PromotedNotificationUiForceExpanded; import com.android.systemui.statusbar.notification.row.ExpandableView.OnHeightChangedListener; import com.android.systemui.statusbar.notification.row.wrapper.NotificationViewWrapper; import com.android.systemui.statusbar.notification.shared.NotificationContentAlphaOptimization; @@ -878,6 +879,85 @@ public class ExpandableNotificationRowTest extends SysuiTestCase { } @Test + @EnableFlags(PromotedNotificationUiForceExpanded.FLAG_NAME) + public void isExpanded_sensitivePromotedNotification_notExpanded() throws Exception { + // GIVEN + final ExpandableNotificationRow row = mNotificationTestHelper.createRow(); + row.setPromotedOngoing(true); + row.setSensitive(/* sensitive= */true, /* hideSensitive= */false); + row.setHideSensitiveForIntrinsicHeight(/* hideSensitive= */true); + + // THEN + assertThat(row.isExpanded()).isFalse(); + } + + @Test + @EnableFlags(PromotedNotificationUiForceExpanded.FLAG_NAME) + public void isExpanded_promotedNotificationNotOnKeyguard_expanded() throws Exception { + // GIVEN + final ExpandableNotificationRow row = mNotificationTestHelper.createRow(); + row.setPromotedOngoing(true); + row.setOnKeyguard(false); + + // THEN + assertThat(row.isExpanded()).isTrue(); + } + + @Test + @EnableFlags(PromotedNotificationUiForceExpanded.FLAG_NAME) + public void isExpanded_promotedNotificationAllowOnKeyguard_expanded() throws Exception { + // GIVEN + final ExpandableNotificationRow row = mNotificationTestHelper.createRow(); + row.setPromotedOngoing(true); + row.setOnKeyguard(true); + + // THEN + assertThat(row.isExpanded(/* allowOnKeyguard = */ true)).isTrue(); + } + + @Test + @EnableFlags(PromotedNotificationUiForceExpanded.FLAG_NAME) + public void isExpanded_promotedNotificationIgnoreLockscreenConstraints_expanded() + throws Exception { + // GIVEN + final ExpandableNotificationRow row = mNotificationTestHelper.createRow(); + row.setPromotedOngoing(true); + row.setOnKeyguard(true); + row.setIgnoreLockscreenConstraints(true); + + // THEN + assertThat(row.isExpanded()).isTrue(); + } + + @Test + @EnableFlags(PromotedNotificationUiForceExpanded.FLAG_NAME) + public void isExpanded_promotedNotificationSaveSpaceOnLockScreen_notExpanded() + throws Exception { + // GIVEN + final ExpandableNotificationRow row = mNotificationTestHelper.createRow(); + row.setPromotedOngoing(true); + row.setOnKeyguard(true); + row.setSaveSpaceOnLockscreen(true); + + // THEN + assertThat(row.isExpanded()).isFalse(); + } + + @Test + @EnableFlags(PromotedNotificationUiForceExpanded.FLAG_NAME) + public void isExpanded_promotedNotificationNotSaveSpaceOnLockScreen_expanded() + throws Exception { + // GIVEN + final ExpandableNotificationRow row = mNotificationTestHelper.createRow(); + row.setPromotedOngoing(true); + row.setOnKeyguard(true); + row.setSaveSpaceOnLockscreen(false); + + // THEN + assertThat(row.isExpanded()).isTrue(); + } + + @Test public void onDisappearAnimationFinished_shouldSetFalse_headsUpAnimatingAway() throws Exception { final ExpandableNotificationRow row = mNotificationTestHelper.createRow(); |