diff options
| author | 2023-05-22 13:52:01 +0000 | |
|---|---|---|
| committer | 2023-05-22 13:52:01 +0000 | |
| commit | 4a37a12b05a2fa0f8e28cb4015178658c488795c (patch) | |
| tree | 2650419a3ad43fb629198b798a3188d43bab3fe6 | |
| parent | e043e8b713974661771719b8bb78068e502279a4 (diff) | |
| parent | 1bdbb6be7bd0ca4da825e01eb6a2d23454ff7aaf (diff) | |
Merge changes from topic "b169435530-ExtrasOverriden" into udc-dev am: d62eae979e am: 1bdbb6be7b
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21928002
Change-Id: I3c0257ea180308f7f7f465149ee892acd2b8b71b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | core/java/android/app/Notification.java | 17 | ||||
| -rw-r--r-- | core/tests/coretests/src/android/app/NotificationTest.java | 107 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/flags/Flags.kt | 10 |
3 files changed, 126 insertions, 8 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index df9257c1b18a..5c1b3ee0134b 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -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(); diff --git a/core/tests/coretests/src/android/app/NotificationTest.java b/core/tests/coretests/src/android/app/NotificationTest.java index c5b00c9bfb22..eba7f587bb8b 100644 --- a/core/tests/coretests/src/android/app/NotificationTest.java +++ b/core/tests/coretests/src/android/app/NotificationTest.java @@ -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); diff --git a/packages/SystemUI/src/com/android/systemui/flags/Flags.kt b/packages/SystemUI/src/com/android/systemui/flags/Flags.kt index 23cc182b22c6..2f9f2ac9a08d 100644 --- a/packages/SystemUI/src/com/android/systemui/flags/Flags.kt +++ b/packages/SystemUI/src/com/android/systemui/flags/Flags.kt @@ -100,6 +100,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 = |