Loading core/java/android/app/Notification.java +17 −15 Original line number Diff line number Diff line Loading @@ -2850,18 +2850,14 @@ public class Notification implements Parcelable visitor.accept(Uri.parse(extras.getString(EXTRA_BACKGROUND_IMAGE_URI))); } ArrayList<Person> people = extras.getParcelableArrayList(EXTRA_PEOPLE_LIST); ArrayList<Person> people = extras.getParcelableArrayList(EXTRA_PEOPLE_LIST, Person.class); if (people != null && !people.isEmpty()) { for (Person p : people) { visitor.accept(p.getIconUri()); } } final Person person = extras.getParcelable(EXTRA_MESSAGING_PERSON, Person.class); if (person != null) { visitor.accept(person.getIconUri()); } final RemoteInputHistoryItem[] history = extras.getParcelableArray( Notification.EXTRA_REMOTE_INPUT_HISTORY_ITEMS, RemoteInputHistoryItem.class); Loading @@ -2873,10 +2869,16 @@ public class Notification implements Parcelable } } } // Extras for MessagingStyle. We visit them even if not isStyle(MessagingStyle), since // Notification Listeners might use directly (without the isStyle check). final Person person = extras.getParcelable(EXTRA_MESSAGING_PERSON, Person.class); if (person != null) { visitor.accept(person.getIconUri()); } if (isStyle(MessagingStyle.class) && extras != null) { final Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES); final Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES, Parcelable.class); if (!ArrayUtils.isEmpty(messages)) { for (MessagingStyle.Message message : MessagingStyle.Message .getMessagesFromBundleArray(messages)) { Loading @@ -2889,7 +2891,8 @@ public class Notification implements Parcelable } } final Parcelable[] historic = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES); final Parcelable[] historic = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES, Parcelable.class); if (!ArrayUtils.isEmpty(historic)) { for (MessagingStyle.Message message : MessagingStyle.Message .getMessagesFromBundleArray(historic)) { Loading @@ -2902,15 +2905,14 @@ public class Notification implements Parcelable } } visitIconUri(visitor, extras.getParcelable(EXTRA_CONVERSATION_ICON)); } visitIconUri(visitor, extras.getParcelable(EXTRA_CONVERSATION_ICON, Icon.class)); if (isStyle(CallStyle.class) & extras != null) { Person callPerson = extras.getParcelable(EXTRA_CALL_PERSON); // Extras for CallStyle (same reason for visiting without checking isStyle). Person callPerson = extras.getParcelable(EXTRA_CALL_PERSON, Person.class); if (callPerson != null) { visitor.accept(callPerson.getIconUri()); } visitIconUri(visitor, extras.getParcelable(EXTRA_VERIFICATION_ICON)); visitIconUri(visitor, extras.getParcelable(EXTRA_VERIFICATION_ICON, Icon.class)); } if (mBubbleMetadata != null) { Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +43 −0 Original line number Diff line number Diff line Loading @@ -5355,6 +5355,49 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { verify(visitor, times(1)).accept(eq(verificationIcon.getUri())); } @Test public void testVisitUris_styleExtrasWithoutStyle() { Notification notification = new Notification.Builder(mContext, "a") .setSmallIcon(android.R.drawable.sym_def_app_icon) .build(); Notification.MessagingStyle messagingStyle = new Notification.MessagingStyle( personWithIcon("content://user")) .addHistoricMessage(new Notification.MessagingStyle.Message("Heyhey!", System.currentTimeMillis(), personWithIcon("content://historicalMessenger"))) .addMessage(new Notification.MessagingStyle.Message("Are you there", System.currentTimeMillis(), personWithIcon("content://messenger"))) .setShortcutIcon( Icon.createWithContentUri("content://conversationShortcut")); messagingStyle.addExtras(notification.extras); // Instead of Builder.setStyle(style). Notification.CallStyle callStyle = Notification.CallStyle.forOngoingCall( personWithIcon("content://caller"), PendingIntent.getActivity(mContext, 0, new Intent(), PendingIntent.FLAG_IMMUTABLE)) .setVerificationIcon(Icon.createWithContentUri("content://callVerification")); callStyle.addExtras(notification.extras); // Same. Consumer<Uri> visitor = (Consumer<Uri>) spy(Consumer.class); notification.visitUris(visitor); verify(visitor).accept(eq(Uri.parse("content://user"))); verify(visitor).accept(eq(Uri.parse("content://historicalMessenger"))); verify(visitor).accept(eq(Uri.parse("content://messenger"))); verify(visitor).accept(eq(Uri.parse("content://conversationShortcut"))); verify(visitor).accept(eq(Uri.parse("content://caller"))); verify(visitor).accept(eq(Uri.parse("content://callVerification"))); } private static Person personWithIcon(String iconUri) { return new Person.Builder() .setName("Mr " + iconUri) .setIcon(Icon.createWithContentUri(iconUri)) .build(); } @Test public void testVisitUris_wearableExtender() { Icon actionIcon = Icon.createWithContentUri("content://media/action"); Loading Loading
core/java/android/app/Notification.java +17 −15 Original line number Diff line number Diff line Loading @@ -2850,18 +2850,14 @@ public class Notification implements Parcelable visitor.accept(Uri.parse(extras.getString(EXTRA_BACKGROUND_IMAGE_URI))); } ArrayList<Person> people = extras.getParcelableArrayList(EXTRA_PEOPLE_LIST); ArrayList<Person> people = extras.getParcelableArrayList(EXTRA_PEOPLE_LIST, Person.class); if (people != null && !people.isEmpty()) { for (Person p : people) { visitor.accept(p.getIconUri()); } } final Person person = extras.getParcelable(EXTRA_MESSAGING_PERSON, Person.class); if (person != null) { visitor.accept(person.getIconUri()); } final RemoteInputHistoryItem[] history = extras.getParcelableArray( Notification.EXTRA_REMOTE_INPUT_HISTORY_ITEMS, RemoteInputHistoryItem.class); Loading @@ -2873,10 +2869,16 @@ public class Notification implements Parcelable } } } // Extras for MessagingStyle. We visit them even if not isStyle(MessagingStyle), since // Notification Listeners might use directly (without the isStyle check). final Person person = extras.getParcelable(EXTRA_MESSAGING_PERSON, Person.class); if (person != null) { visitor.accept(person.getIconUri()); } if (isStyle(MessagingStyle.class) && extras != null) { final Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES); final Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES, Parcelable.class); if (!ArrayUtils.isEmpty(messages)) { for (MessagingStyle.Message message : MessagingStyle.Message .getMessagesFromBundleArray(messages)) { Loading @@ -2889,7 +2891,8 @@ public class Notification implements Parcelable } } final Parcelable[] historic = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES); final Parcelable[] historic = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES, Parcelable.class); if (!ArrayUtils.isEmpty(historic)) { for (MessagingStyle.Message message : MessagingStyle.Message .getMessagesFromBundleArray(historic)) { Loading @@ -2902,15 +2905,14 @@ public class Notification implements Parcelable } } visitIconUri(visitor, extras.getParcelable(EXTRA_CONVERSATION_ICON)); } visitIconUri(visitor, extras.getParcelable(EXTRA_CONVERSATION_ICON, Icon.class)); if (isStyle(CallStyle.class) & extras != null) { Person callPerson = extras.getParcelable(EXTRA_CALL_PERSON); // Extras for CallStyle (same reason for visiting without checking isStyle). Person callPerson = extras.getParcelable(EXTRA_CALL_PERSON, Person.class); if (callPerson != null) { visitor.accept(callPerson.getIconUri()); } visitIconUri(visitor, extras.getParcelable(EXTRA_VERIFICATION_ICON)); visitIconUri(visitor, extras.getParcelable(EXTRA_VERIFICATION_ICON, Icon.class)); } if (mBubbleMetadata != null) { Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +43 −0 Original line number Diff line number Diff line Loading @@ -5355,6 +5355,49 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { verify(visitor, times(1)).accept(eq(verificationIcon.getUri())); } @Test public void testVisitUris_styleExtrasWithoutStyle() { Notification notification = new Notification.Builder(mContext, "a") .setSmallIcon(android.R.drawable.sym_def_app_icon) .build(); Notification.MessagingStyle messagingStyle = new Notification.MessagingStyle( personWithIcon("content://user")) .addHistoricMessage(new Notification.MessagingStyle.Message("Heyhey!", System.currentTimeMillis(), personWithIcon("content://historicalMessenger"))) .addMessage(new Notification.MessagingStyle.Message("Are you there", System.currentTimeMillis(), personWithIcon("content://messenger"))) .setShortcutIcon( Icon.createWithContentUri("content://conversationShortcut")); messagingStyle.addExtras(notification.extras); // Instead of Builder.setStyle(style). Notification.CallStyle callStyle = Notification.CallStyle.forOngoingCall( personWithIcon("content://caller"), PendingIntent.getActivity(mContext, 0, new Intent(), PendingIntent.FLAG_IMMUTABLE)) .setVerificationIcon(Icon.createWithContentUri("content://callVerification")); callStyle.addExtras(notification.extras); // Same. Consumer<Uri> visitor = (Consumer<Uri>) spy(Consumer.class); notification.visitUris(visitor); verify(visitor).accept(eq(Uri.parse("content://user"))); verify(visitor).accept(eq(Uri.parse("content://historicalMessenger"))); verify(visitor).accept(eq(Uri.parse("content://messenger"))); verify(visitor).accept(eq(Uri.parse("content://conversationShortcut"))); verify(visitor).accept(eq(Uri.parse("content://caller"))); verify(visitor).accept(eq(Uri.parse("content://callVerification"))); } private static Person personWithIcon(String iconUri) { return new Person.Builder() .setName("Mr " + iconUri) .setIcon(Icon.createWithContentUri(iconUri)) .build(); } @Test public void testVisitUris_wearableExtender() { Icon actionIcon = Icon.createWithContentUri("content://media/action"); Loading