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

Commit 2ee31543 authored by Alexander Roederer's avatar Alexander Roederer Committed by Automerger Merge Worker
Browse files

Merge changes from topic "b169435530-ExtrasOverriden" into udc-dev am: d62eae97

parents d8aae500 d62eae97
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -5006,12 +5006,6 @@ public class Notification implements Parcelable
            return mUserExtras;
        }
        private Bundle getAllExtras() {
            final Bundle saveExtras = (Bundle) mUserExtras.clone();
            saveExtras.putAll(mN.extras);
            return saveExtras;
        }
        /**
         * Add an action to this notification. Actions are typically displayed by
         * the system as a button adjacent to the notification content.
@@ -6617,9 +6611,16 @@ public class Notification implements Parcelable
                                + " vs bubble: " + mN.mBubbleMetadata.getShortcutId());
            }
            // first, add any extras from the calling code
            // Adds any new extras provided by the user.
            if (mUserExtras != null) {
                mN.extras = getAllExtras();
                final Bundle saveExtras = (Bundle) mUserExtras.clone();
                if (SystemProperties.getBoolean(
                        "persist.sysui.notification.builder_extras_override", false)) {
                    mN.extras.putAll(saveExtras);
                } else {
                    saveExtras.putAll(mN.extras);
                    mN.extras = saveExtras;
                }
            }
            mN.creationTime = System.currentTimeMillis();
+107 −0
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ import static android.app.Notification.EXTRA_MESSAGING_PERSON;
import static android.app.Notification.EXTRA_PEOPLE_LIST;
import static android.app.Notification.EXTRA_PICTURE;
import static android.app.Notification.EXTRA_PICTURE_ICON;
import static android.app.Notification.EXTRA_SUMMARY_TEXT;
import static android.app.Notification.EXTRA_TITLE;
import static android.app.Notification.MessagingStyle.Message.KEY_DATA_URI;
import static android.app.Notification.MessagingStyle.Message.KEY_SENDER_PERSON;
import static android.app.Notification.MessagingStyle.Message.KEY_TEXT;
@@ -76,6 +78,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.SystemProperties;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
@@ -111,6 +114,9 @@ public class NotificationTest {
    @Before
    public void setUp() {
        mContext = InstrumentationRegistry.getContext();
        // TODO(b/169435530): remove this flag set once resolved.
        SystemProperties.set("persist.sysui.notification.builder_extras_override",
                Boolean.toString(false));
    }

    @Test
@@ -1481,6 +1487,107 @@ public class NotificationTest {
        Assert.assertEquals(actionWithFreeformRemoteInput, remoteInputActionPair.second);
    }

    // Ensures that extras in a Notification Builder can be updated.
    @Test
    public void testExtras_cachedExtrasOverwrittenByUserProvided() {
        // Sets the flag to new state.
        // TODO(b/169435530): remove this set value once resolved.
        SystemProperties.set("persist.sysui.notification.builder_extras_override",
                Boolean.toString(true));
        Bundle extras = new Bundle();
        extras.putCharSequence(EXTRA_TITLE, "test title");
        extras.putCharSequence(EXTRA_SUMMARY_TEXT, "summary text");

        Notification.Builder builder = new Notification.Builder(mContext, "test id")
                .addExtras(extras);

        Notification notification = builder.build();
        assertThat(notification.extras.getCharSequence(EXTRA_TITLE).toString()).isEqualTo(
                "test title");
        assertThat(notification.extras.getCharSequence(EXTRA_SUMMARY_TEXT).toString()).isEqualTo(
                "summary text");

        extras.putCharSequence(EXTRA_TITLE, "new title");
        builder.addExtras(extras);
        notification = builder.build();
        assertThat(notification.extras.getCharSequence(EXTRA_TITLE).toString()).isEqualTo(
                "new title");
        assertThat(notification.extras.getCharSequence(EXTRA_SUMMARY_TEXT).toString()).isEqualTo(
                "summary text");
    }

    // Ensures that extras in a Notification Builder can be updated by an extender.
    @Test
    public void testExtras_cachedExtrasOverwrittenByExtender() {
        // Sets the flag to new state.
        // TODO(b/169435530): remove this set value once resolved.
        SystemProperties.set("persist.sysui.notification.builder_extras_override",
                Boolean.toString(true));
        Notification.CarExtender extender = new Notification.CarExtender().setColor(1234);

        Notification notification = new Notification.Builder(mContext, "test id")
                .extend(extender).build();

        extender.setColor(5678);

        Notification.Builder.recoverBuilder(mContext, notification).extend(extender).build();

        Notification.CarExtender recoveredExtender = new Notification.CarExtender(notification);
        assertThat(recoveredExtender.getColor()).isEqualTo(5678);
    }

    // Validates pre-flag flip behavior, that extras in a Notification Builder cannot be updated.
    // TODO(b/169435530): remove this test once resolved.
    @Test
    public void testExtras_cachedExtrasOverwrittenByUserProvidedOld() {
        // Sets the flag to old state.
        SystemProperties.set("persist.sysui.notification.builder_extras_override",
                Boolean.toString(false));

        Bundle extras = new Bundle();
        extras.putCharSequence(EXTRA_TITLE, "test title");
        extras.putCharSequence(EXTRA_SUMMARY_TEXT, "summary text");

        Notification.Builder builder = new Notification.Builder(mContext, "test id")
                .addExtras(extras);

        Notification notification = builder.build();
        assertThat(notification.extras.getCharSequence(EXTRA_TITLE).toString()).isEqualTo(
                "test title");
        assertThat(notification.extras.getCharSequence(EXTRA_SUMMARY_TEXT).toString()).isEqualTo(
                "summary text");

        extras.putCharSequence(EXTRA_TITLE, "new title");
        builder.addExtras(extras);
        notification = builder.build();
        assertThat(notification.extras.getCharSequence(EXTRA_TITLE).toString()).isEqualTo(
                "test title");
        assertThat(notification.extras.getCharSequence(EXTRA_SUMMARY_TEXT).toString()).isEqualTo(
                "summary text");
    }

    // Validates pre-flag flip behavior, that extras in a Notification Builder cannot be updated
    // by an extender.
    // TODO(b/169435530): remove this test once resolved.
    @Test
    public void testExtras_cachedExtrasOverwrittenByExtenderOld() {
        // Sets the flag to old state.
        SystemProperties.set("persist.sysui.notification.builder_extras_override",
                Boolean.toString(false));

        Notification.CarExtender extender = new Notification.CarExtender().setColor(1234);

        Notification notification = new Notification.Builder(mContext, "test id")
                .extend(extender).build();

        extender.setColor(5678);

        Notification.Builder.recoverBuilder(mContext, notification).extend(extender).build();

        Notification.CarExtender recoveredExtender = new Notification.CarExtender(notification);
        assertThat(recoveredExtender.getColor()).isEqualTo(1234);
    }

    private void assertValid(Notification.Colors c) {
        // Assert that all colors are populated
        assertThat(c.getBackgroundColor()).isNotEqualTo(Notification.COLOR_INVALID);
+10 −0
Original line number Diff line number Diff line
@@ -104,6 +104,16 @@ object Flags {
    val SENSITIVE_REVEAL_ANIM =
        unreleasedFlag(268005230, "sensitive_reveal_anim", teamfood = true)

    // TODO(b/280783617): Tracking Bug
    @Keep
    @JvmField
    val BUILDER_EXTRAS_OVERRIDE =
            sysPropBooleanFlag(
                    128,
                    "persist.sysui.notification.builder_extras_override",
                    default = false
            )

    // 200 - keyguard/lockscreen
    // ** Flag retired **
    // public static final BooleanFlag KEYGUARD_LAYOUT =