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

Commit 68fd88e3 authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Ongoing CallStyle notifications can be promoted even without being colorized.

Also fixes an issue where a "title" was defined incorrectly. It allowed non-BigTextStyle notifications to use EXTRA_TITLE_BIG to circumvent the requirement for a title, and it required calls to set a title even though it would never be set.

Flag: android.app.api_rich_ongoing
Bug: 367705002
Test: atest NotificationTest
Change-Id: Ie063bca8508538dd4515d3f7bf2e284548085040
parent d8aa8b99
Loading
Loading
Loading
Loading
+35 −9
Original line number Diff line number Diff line
@@ -3253,9 +3253,24 @@ public class Notification implements Parcelable
     * @hide
     */
    public boolean hasTitle() {
        return extras != null
                && (!TextUtils.isEmpty(extras.getCharSequence(EXTRA_TITLE))
                || !TextUtils.isEmpty(extras.getCharSequence(EXTRA_TITLE_BIG)));
        if (extras == null) {
            return false;
        }
        // CallStyle notifications only use the other person's name as the title.
        if (isStyle(CallStyle.class)) {
            Person person = extras.getParcelable(EXTRA_CALL_PERSON, Person.class);
            return person != null && !TextUtils.isEmpty(person.getName());
        }
        // non-CallStyle notifications can use EXTRA_TITLE
        if (!TextUtils.isEmpty(extras.getCharSequence(EXTRA_TITLE))) {
            return true;
        }
        // BigTextStyle notifications first use EXTRA_TITLE_BIG
        if (isStyle(BigTextStyle.class)) {
            return !TextUtils.isEmpty(extras.getCharSequence(EXTRA_TITLE_BIG));
        } else {
            return false;
        }
    }
    /**
@@ -3280,12 +3295,23 @@ public class Notification implements Parcelable
     */
    @FlaggedApi(Flags.FLAG_API_RICH_ONGOING)
    public boolean hasPromotableCharacteristics() {
        return isColorizedRequested()
                && isOngoingEvent()
                && hasTitle()
                && !isGroupSummary()
                && !containsCustomViews()
                && hasPromotableStyle();
        if (!isOngoingEvent() || isGroupSummary() || containsCustomViews() || !hasTitle()) {
            return false;
        }
        // Only "Ongoing CallStyle" notifications are promotable without EXTRA_COLORIZED
        if (isOngoingCallStyle()) {
            return true;
        }
        return isColorizedRequested() && hasPromotableStyle();
    }
    /** Returns whether the notification is CallStyle.forOngoingCall(). */
    private boolean isOngoingCallStyle() {
        if (!isStyle(CallStyle.class)) {
            return false;
        }
        int callType = extras.getInt(EXTRA_CALL_TYPE, CallStyle.CALL_TYPE_UNKNOWN);
        return callType == CallStyle.CALL_TYPE_ONGOING;
    }
    /**
+60 −1
Original line number Diff line number Diff line
@@ -462,7 +462,7 @@ public class NotificationTest {

    @Test
    @EnableFlags(Flags.FLAG_UI_RICH_ONGOING)
    public void testHasPromotableCharacteristics() {
    public void testHasPromotableCharacteristics_bigText_bigTitle() {
        Notification n = new Notification.Builder(mContext, "test")
                .setSmallIcon(android.R.drawable.sym_def_app_icon)
                .setStyle(new Notification.BigTextStyle().setBigContentTitle("BIG"))
@@ -473,6 +473,20 @@ public class NotificationTest {
        assertThat(n.hasPromotableCharacteristics()).isTrue();
    }

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

    @Test
    @EnableFlags(Flags.FLAG_UI_RICH_ONGOING)
    public void testHasPromotableCharacteristics_notOngoing() {
@@ -524,6 +538,51 @@ public class NotificationTest {
        assertThat(n.hasPromotableCharacteristics()).isFalse();
    }

    @Test
    @EnableFlags(Flags.FLAG_UI_RICH_ONGOING)
    public void testHasPromotableCharacteristics_noStyle_onlyBigTitle() {
        Bundle extras = new Bundle();
        extras.putString(Notification.EXTRA_TITLE_BIG, "BIG");
        Notification n = new Notification.Builder(mContext, "test")
                .setSmallIcon(android.R.drawable.sym_def_app_icon)
                .setColor(Color.WHITE)
                .setColorized(true)
                .setOngoing(true)
                .addExtras(extras)
                .build();
        assertThat(n.hasPromotableCharacteristics()).isFalse();
    }

    @Test
    @EnableFlags(Flags.FLAG_UI_RICH_ONGOING)
    public void testHasPromotableCharacteristics_ongoingCallStyle_notColorized() {
        PendingIntent intent = PendingIntent.getActivity(
                mContext, 0, new Intent("test1"), PendingIntent.FLAG_IMMUTABLE);
        Person person = new Person.Builder().setName("Caller").build();
        Notification n = new Notification.Builder(mContext, "test")
                .setSmallIcon(android.R.drawable.sym_def_app_icon)
                .setStyle(Notification.CallStyle.forOngoingCall(person, intent))
                .setColor(Color.WHITE)
                .setOngoing(true)
                .build();
        assertThat(n.hasPromotableCharacteristics()).isTrue();
    }

    @Test
    @EnableFlags(Flags.FLAG_UI_RICH_ONGOING)
    public void testHasPromotableCharacteristics_incomingCallStyle_notColorized() {
        PendingIntent intent = PendingIntent.getActivity(
                mContext, 0, new Intent("test1"), PendingIntent.FLAG_IMMUTABLE);
        Person person = new Person.Builder().setName("Caller").build();
        Notification n = new Notification.Builder(mContext, "test")
                .setSmallIcon(android.R.drawable.sym_def_app_icon)
                .setStyle(Notification.CallStyle.forIncomingCall(person, intent, intent))
                .setColor(Color.WHITE)
                .setOngoing(true)
                .build();
        assertThat(n.hasPromotableCharacteristics()).isFalse();
    }

    @Test
    @EnableFlags(Flags.FLAG_UI_RICH_ONGOING)
    public void testHasPromotableCharacteristics_groupSummary() {