diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 63795cfcdf714..43aebb6a94fa8 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -8723,9 +8723,11 @@ public class Notification implements Parcelable } /** + * Converts the message into a {@link Bundle}. To extract the message back, + * check {@link #getMessageFromBundle()} * @hide */ - @VisibleForTesting + @NonNull public Bundle toBundle() { Bundle bundle = new Bundle(); if (mText != null) { diff --git a/core/tests/coretests/src/android/app/NotificationTest.java b/core/tests/coretests/src/android/app/NotificationTest.java index c5b00c9bfb22f..1b570dad19042 100644 --- a/core/tests/coretests/src/android/app/NotificationTest.java +++ b/core/tests/coretests/src/android/app/NotificationTest.java @@ -931,6 +931,27 @@ public class NotificationTest { // no crash, good } + @Test + public void testToBundle_getMessageFromBundle_returnsSameData() { + Notification.MessagingStyle.Message message = + new Notification.MessagingStyle.Message( + "a", 100, new Person.Builder().setName("hi").build()); + message.setData("text", Uri.parse("http://test/uri")); + + Notification.MessagingStyle.Message convertedMessage = + Notification.MessagingStyle.Message.getMessageFromBundle(message.toBundle()); + + assertThat(convertedMessage).isNotNull(); + assertThat(message.getText()).isEqualTo(convertedMessage.getText()); + assertThat(message.getTimestamp()).isEqualTo(convertedMessage.getTimestamp()); + assertThat(message.getExtras().size()).isEqualTo(convertedMessage.getExtras().size()); + assertThat(message.getSender()).isEqualTo(convertedMessage.getSender()); + assertThat(message.getSenderPerson()).isEqualTo(convertedMessage.getSenderPerson()); + assertThat(message.getDataMimeType()).isEqualTo(convertedMessage.getDataMimeType()); + assertThat(message.getDataUri()).isEqualTo(convertedMessage.getDataUri()); + assertThat(message.isRemoteInputHistory()) + .isEqualTo(convertedMessage.isRemoteInputHistory()); + } @Test public void testDoesNotStripsExtenders() {