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

Commit a56bfd34 authored by Jeff DeCew's avatar Jeff DeCew Committed by Android (Google) Code Review
Browse files

Merge changes from topics "RONs-require-ongoing", "hasPromotableCharacteristics-api" into main

* changes:
  Add Notification.hasPromotableCharacteristics to public API
  Notifications require FLAG_ONGOING_EVENT to be eligible for FLAG_PROMOTED_ONGOING.
parents c291e00c f6427ebf
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6482,6 +6482,7 @@ package android.app {
    method public String getSortKey();
    method public long getTimeoutAfter();
    method public boolean hasImage();
    method @FlaggedApi("android.app.api_rich_ongoing") public boolean hasPromotableCharacteristics();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.media.AudioAttributes AUDIO_ATTRIBUTES_DEFAULT;
    field public static final int BADGE_ICON_LARGE = 2; // 0x2
+15 −5
Original line number Diff line number Diff line
@@ -3221,7 +3221,6 @@ public class Notification implements Parcelable
    /**
     * @hide
     */
    @FlaggedApi(Flags.FLAG_UI_RICH_ONGOING)
    public boolean containsCustomViews() {
        return contentView != null
                || bigContentView != null
@@ -3235,7 +3234,6 @@ public class Notification implements Parcelable
    /**
     * @hide
     */
    @FlaggedApi(Flags.FLAG_UI_RICH_ONGOING)
    public boolean hasTitle() {
        return extras != null
                && (!TextUtils.isEmpty(extras.getCharSequence(EXTRA_TITLE))
@@ -3245,7 +3243,7 @@ public class Notification implements Parcelable
    /**
     * @hide
     */
    @FlaggedApi(Flags.FLAG_UI_RICH_ONGOING)
    @FlaggedApi(Flags.FLAG_API_RICH_ONGOING)
    public boolean hasPromotableStyle() {
        final Class<? extends Style> notificationStyle = getNotificationStyle();
@@ -3257,11 +3255,16 @@ public class Notification implements Parcelable
    }
    /**
     * @hide
     * Returns whether the notification has all the characteristics that make it eligible for
     * {@link #FLAG_PROMOTED_ONGOING}. This method does not factor in other criteria such user
     * preferences for the app or channel. If this returns true, it does not guarantee that the
     * notification will be assigned FLAG_PROMOTED_ONGOING by the system, but if this returns false,
     * it will not.
     */
    @FlaggedApi(Flags.FLAG_UI_RICH_ONGOING)
    @FlaggedApi(Flags.FLAG_API_RICH_ONGOING)
    public boolean hasPromotableCharacteristics() {
        return isColorizedRequested()
                && isOngoingEvent()
                && hasTitle()
                && !isGroupSummary()
                && !containsCustomViews()
@@ -4155,6 +4158,13 @@ public class Notification implements Parcelable
        return extras.getString(EXTRA_SHORT_CRITICAL_TEXT);
    }
    /**
     * @hide
     */
    public boolean isOngoingEvent() {
        return (flags & FLAG_ONGOING_EVENT) != 0;
    }
    /**
     * @hide
     */
+17 −0
Original line number Diff line number Diff line
@@ -467,10 +467,23 @@ public class NotificationTest {
                .setStyle(new Notification.BigTextStyle().setBigContentTitle("BIG"))
                .setColor(Color.WHITE)
                .setColorized(true)
                .setOngoing(true)
                .build();
        assertThat(n.hasPromotableCharacteristics()).isTrue();
    }

    @Test
    @EnableFlags(Flags.FLAG_UI_RICH_ONGOING)
    public void testHasPromotableCharacteristics_notOngoing() {
        Notification n = new Notification.Builder(mContext, "test")
                .setSmallIcon(android.R.drawable.sym_def_app_icon)
                .setStyle(new Notification.BigTextStyle().setBigContentTitle("BIG"))
                .setColor(Color.WHITE)
                .setColorized(true)
                .build();
        assertThat(n.hasPromotableCharacteristics()).isFalse();
    }

    @Test
    @EnableFlags(Flags.FLAG_UI_RICH_ONGOING)
    public void testHasPromotableCharacteristics_wrongStyle() {
@@ -480,6 +493,7 @@ public class NotificationTest {
                .setContentTitle("TITLE")
                .setColor(Color.WHITE)
                .setColorized(true)
                .setOngoing(true)
                .build();
        assertThat(n.hasPromotableCharacteristics()).isFalse();
    }
@@ -491,6 +505,7 @@ public class NotificationTest {
                .setSmallIcon(android.R.drawable.sym_def_app_icon)
                .setStyle(new Notification.BigTextStyle().setBigContentTitle("BIG"))
                .setColor(Color.WHITE)
                .setOngoing(true)
                .build();
        assertThat(n.hasPromotableCharacteristics()).isFalse();
    }
@@ -503,6 +518,7 @@ public class NotificationTest {
                .setStyle(new Notification.BigTextStyle())
                .setColor(Color.WHITE)
                .setColorized(true)
                .setOngoing(true)
                .build();
        assertThat(n.hasPromotableCharacteristics()).isFalse();
    }
@@ -515,6 +531,7 @@ public class NotificationTest {
                .setStyle(new Notification.BigTextStyle().setBigContentTitle("BIG"))
                .setColor(Color.WHITE)
                .setColorized(true)
                .setOngoing(true)
                .setGroup("someGroup")
                .setGroupSummary(true)
                .build();
+10 −0
Original line number Diff line number Diff line
@@ -17314,6 +17314,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .setStyle(new Notification.BigTextStyle().setBigContentTitle("BIG"))
                .setColor(Color.WHITE)
                .setColorized(true)
                .setOngoing(true)
                .setFlag(FLAG_CAN_COLORIZE, true) // add manually since we're skipping post
                .build();
@@ -17327,6 +17328,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .setStyle(new Notification.BigTextStyle().setBigContentTitle("BIG"))
                .setColor(Color.WHITE)
                .setColorized(true)
                .setOngoing(true)
                .setFlag(FLAG_CAN_COLORIZE, true) // add manually since we're skipping post
                .build();
        StatusBarNotification sbn1 = new StatusBarNotification(mPkg, mPkg, 7, null, mUid, 0,
@@ -17339,6 +17341,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .setStyle(new Notification.BigTextStyle().setBigContentTitle("BIG"))
                .setColor(Color.WHITE)
                .setColorized(true)
                .setOngoing(true)
                .setFlag(FLAG_CAN_COLORIZE, true) // add manually since we're skipping post
                .build();
        StatusBarNotification sbn2 = new StatusBarNotification(PKG_O, PKG_O, 7, null, UID_O, 0,
@@ -17388,6 +17391,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .setStyle(new Notification.BigTextStyle().setBigContentTitle("BIG"))
                .setColor(Color.WHITE)
                .setColorized(true)
                .setOngoing(true)
                .setFlag(FLAG_CAN_COLORIZE, true) // add manually since we're skipping post
                .build();
@@ -17420,6 +17424,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .setStyle(new Notification.BigTextStyle().setBigContentTitle("BIG"))
                .setColor(Color.WHITE)
                .setColorized(true)
                .setOngoing(true)
                .setFlag(FLAG_PROMOTED_ONGOING, true) // add manually since we're skipping post
                .setFlag(FLAG_CAN_COLORIZE, true) // add manually since we're skipping post
                .build();
@@ -17434,6 +17439,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .setStyle(new Notification.BigTextStyle().setBigContentTitle("BIG"))
                .setColor(Color.WHITE)
                .setColorized(true)
                .setOngoing(true)
                .setFlag(FLAG_PROMOTED_ONGOING, true) // add manually since we're skipping post
                .setFlag(FLAG_CAN_COLORIZE, true) // add manually since we're skipping post
                .build();
@@ -17483,6 +17489,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .setStyle(new Notification.BigTextStyle().setBigContentTitle("BIG"))
                .setColor(Color.WHITE)
                .setColorized(true)
                .setOngoing(true)
                .setFlag(FLAG_PROMOTED_ONGOING, true) // add manually since we're skipping post
                .setFlag(FLAG_CAN_COLORIZE, true) // add manually since we're skipping post
                .build();
@@ -17515,6 +17522,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .setStyle(new Notification.BigTextStyle().setBigContentTitle("BIG"))
                .setColor(Color.WHITE)
                .setColorized(true)
                .setOngoing(true)
                .build();
        StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 9, null, mUid, 0,
                n, UserHandle.getUserHandleForUid(mUid), null, 0);
@@ -17543,6 +17551,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .setStyle(new Notification.BigTextStyle().setBigContentTitle("BIG"))
                .setColor(Color.WHITE)
                .setColorized(true)
                .setOngoing(true)
                .build();
        StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 9, null, mUid, 0,
@@ -17570,6 +17579,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .setStyle(new Notification.BigTextStyle().setBigContentTitle("BIG"))
                .setColor(Color.WHITE)
                .setColorized(true)
                .setOngoing(true)
                .build();
        StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 9, null, mUid, 0,