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

Commit 26db4177 authored by Jeff DeCew's avatar Jeff DeCew
Browse files

[RONs] Fixes for promoted notification logic

Default for CAN_HAVE_PROMOTED_NOTIFS will initially be false, since the UI features do not exist.  When the UI features are enabled, the default will be true.  The value will not persist until the UI features are enabled.

Change-Id: I7a24581c4ba304e8b318408737d45e043c1fcceb
Flag: android.app.api_rich_ongoing
Flag: android.app.ui_rich_ongoing
Bug: 379335139
Test: atest PreferencesHelperTest
Test: atest NotificationManagerServiceTest
parent 2e1e9cd8
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -184,6 +184,7 @@ public class PreferencesHelper implements RankingConfig {
    private static final boolean DEFAULT_SHOW_BADGE = true;

    private static final boolean DEFAULT_APP_LOCKED_IMPORTANCE  = false;
    private static final boolean DEFAULT_CAN_HAVE_PROMOTED_NOTIFS = true;

    static final boolean DEFAULT_BUBBLES_ENABLED = true;
    @VisibleForTesting
@@ -369,8 +370,8 @@ public class PreferencesHelper implements RankingConfig {
                    null, ATT_USER_DEMOTED_INVALID_MSG_APP, false);
            r.hasSentValidBubble = parser.getAttributeBoolean(null, ATT_SENT_VALID_BUBBLE, false);
            if (android.app.Flags.uiRichOngoing()) {
                r.canHavePromotedNotifs =
                        parser.getAttributeBoolean(null, ATT_PROMOTE_NOTIFS, false);
                r.canHavePromotedNotifs = parser.getAttributeBoolean(null, ATT_PROMOTE_NOTIFS,
                        DEFAULT_CAN_HAVE_PROMOTED_NOTIFS);
            }

            final int innerDepth = parser.getDepth();
@@ -748,7 +749,7 @@ public class PreferencesHelper implements RankingConfig {
                r.userDemotedMsgApp);
        out.attributeBoolean(null, ATT_SENT_VALID_BUBBLE, r.hasSentValidBubble);
        if (android.app.Flags.uiRichOngoing()) {
            if (r.canHavePromotedNotifs) {
            if (r.canHavePromotedNotifs != DEFAULT_CAN_HAVE_PROMOTED_NOTIFS) {
                out.attributeBoolean(null, ATT_PROMOTE_NOTIFS, r.canHavePromotedNotifs);
            }
        }
@@ -2331,7 +2332,8 @@ public class PreferencesHelper implements RankingConfig {
                    pw.print(" fixedImportance=");
                    pw.print(r.fixedImportance);
                }
                if (android.app.Flags.uiRichOngoing() && r.canHavePromotedNotifs) {
                if (android.app.Flags.uiRichOngoing()
                        && r.canHavePromotedNotifs != DEFAULT_CAN_HAVE_PROMOTED_NOTIFS) {
                    pw.print(" promoted=");
                    pw.print(r.canHavePromotedNotifs);
                }
@@ -3184,7 +3186,8 @@ public class PreferencesHelper implements RankingConfig {
        long creationTime;

        @FlaggedApi(android.app.Flags.FLAG_API_RICH_ONGOING)
        boolean canHavePromotedNotifs = false;
        // Until we enable the UI, we should return false.
        boolean canHavePromotedNotifs = android.app.Flags.uiRichOngoing();

        @UserIdInt int userId;

+3 −0
Original line number Diff line number Diff line
@@ -17405,6 +17405,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    @Test
    @EnableFlags(android.app.Flags.FLAG_API_RICH_ONGOING)
    public void testPostPromotableNotification_noPermission() throws Exception {
        mBinderService.setCanBePromoted(mPkg, mUid, false, true);
        assertThat(mBinderService.appCanBePromoted(mPkg, mUid)).isFalse();
        Notification n = new Notification.Builder(mContext, mTestNotificationChannel.getId())
                .setSmallIcon(android.R.drawable.sym_def_app_icon)
                .setStyle(new Notification.BigTextStyle().setBigContentTitle("BIG"))
+10 −0
Original line number Diff line number Diff line
@@ -256,6 +256,7 @@ public class PreferencesHelperTest extends UiServiceTestCase {
    @Parameters(name = "{0}")
    public static List<FlagsParameterization> getParams() {
        return FlagsParameterization.allCombinationsOf(
                android.app.Flags.FLAG_API_RICH_ONGOING,
                FLAG_NOTIFICATION_CLASSIFICATION, FLAG_MODES_UI);
    }

@@ -6511,11 +6512,20 @@ public class PreferencesHelperTest extends UiServiceTestCase {

    @Test
    @EnableFlags(android.app.Flags.FLAG_API_RICH_ONGOING)
    @DisableFlags(android.app.Flags.FLAG_UI_RICH_ONGOING)
    public void testNoAppHasPermissionToPromoteByDefault() {
        mHelper.setShowBadge(PKG_P, UID_P, true);
        assertThat(mHelper.canBePromoted(PKG_P, UID_P)).isFalse();
    }

    @Test
    @EnableFlags({android.app.Flags.FLAG_API_RICH_ONGOING,
            android.app.Flags.FLAG_UI_RICH_ONGOING})
    public void testAllAppsHavePermissionToPromoteByDefault() {
        mHelper.setShowBadge(PKG_P, UID_P, true);
        assertThat(mHelper.canBePromoted(PKG_P, UID_P)).isTrue();
    }

    @Test
    @EnableFlags(android.app.Flags.FLAG_API_RICH_ONGOING)
    public void testSetCanBePromoted() {