From 71cd8f7d9f32fb068b8b512801639d17c19853e3 Mon Sep 17 00:00:00 2001 From: David Krska Date: Wed, 29 Mar 2023 13:07:44 +0000 Subject: [PATCH] Remove @VisibleForTesting from Message#toBundle to make it public. This changes the method from private to public to allow other platform components to depend on it. Test: atest FrameworksCoreTests:NotificationTest Bug: 275303162 Change-Id: I8fb45b5ab1a42921ae19b904f83013e2f0ca4449 --- core/java/android/app/Notification.java | 4 +++- .../src/android/app/NotificationTest.java | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) 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() {