Skip to content

Commit ee3f2dd

Browse files
Ioana AlexandruAndroid Build Coastguard Worker
authored andcommitted
Verify URI permissions for EXTRA_REMOTE_INPUT_HISTORY_ITEMS.
Also added the person URIs in the test, since they weren't being checked. Test: atest NotificationManagerServiceTest & tested with POC from bug Bug: 276729064 (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:43b1711332763788c7abf05c3baa931296c45bbb) Merged-In: I848545f7aee202495c515f47a32871a2cb6ae707 Change-Id: I848545f7aee202495c515f47a32871a2cb6ae707
1 parent b75a5c6 commit ee3f2dd

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

core/java/android/app/Notification.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2853,6 +2853,17 @@ public void visitUris(@NonNull Consumer<Uri> visitor) {
28532853
if (person != null) {
28542854
visitor.accept(person.getIconUri());
28552855
}
2856+
2857+
final RemoteInputHistoryItem[] history = (RemoteInputHistoryItem[])
2858+
extras.getParcelableArray(Notification.EXTRA_REMOTE_INPUT_HISTORY_ITEMS);
2859+
if (history != null) {
2860+
for (int i = 0; i < history.length; i++) {
2861+
RemoteInputHistoryItem item = history[i];
2862+
if (item.getUri() != null) {
2863+
visitor.accept(item.getUri());
2864+
}
2865+
}
2866+
}
28562867
}
28572868

28582869
if (isStyle(MessagingStyle.class) && extras != null) {

services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
import android.app.PendingIntent;
129129
import android.app.Person;
130130
import android.app.RemoteInput;
131+
import android.app.RemoteInputHistoryItem;
131132
import android.app.StatsManager;
132133
import android.app.admin.DevicePolicyManagerInternal;
133134
import android.app.usage.UsageStatsManagerInternal;
@@ -5373,10 +5374,36 @@ public void updateUriPermissions_posterDoesNotOwnUri() throws Exception {
53735374
public void testVisitUris() throws Exception {
53745375
final Uri audioContents = Uri.parse("content://com.example/audio");
53755376
final Uri backgroundImage = Uri.parse("content://com.example/background");
5377+
final Icon personIcon1 = Icon.createWithContentUri("content://media/person1");
5378+
final Icon personIcon2 = Icon.createWithContentUri("content://media/person2");
5379+
final Icon personIcon3 = Icon.createWithContentUri("content://media/person3");
5380+
final Person person1 = new Person.Builder()
5381+
.setName("Messaging Person")
5382+
.setIcon(personIcon1)
5383+
.build();
5384+
final Person person2 = new Person.Builder()
5385+
.setName("People List Person 1")
5386+
.setIcon(personIcon2)
5387+
.build();
5388+
final Person person3 = new Person.Builder()
5389+
.setName("People List Person 2")
5390+
.setIcon(personIcon3)
5391+
.build();
5392+
final Uri historyUri1 = Uri.parse("content://com.example/history1");
5393+
final Uri historyUri2 = Uri.parse("content://com.example/history2");
5394+
final RemoteInputHistoryItem historyItem1 = new RemoteInputHistoryItem(null, historyUri1,
5395+
"a");
5396+
final RemoteInputHistoryItem historyItem2 = new RemoteInputHistoryItem(null, historyUri2,
5397+
"b");
53765398

53775399
Bundle extras = new Bundle();
53785400
extras.putParcelable(Notification.EXTRA_AUDIO_CONTENTS_URI, audioContents);
53795401
extras.putString(Notification.EXTRA_BACKGROUND_IMAGE_URI, backgroundImage.toString());
5402+
extras.putParcelable(Notification.EXTRA_MESSAGING_PERSON, person1);
5403+
extras.putParcelableArrayList(Notification.EXTRA_PEOPLE_LIST,
5404+
new ArrayList<>(Arrays.asList(person2, person3)));
5405+
extras.putParcelableArray(Notification.EXTRA_REMOTE_INPUT_HISTORY_ITEMS,
5406+
new RemoteInputHistoryItem[]{historyItem1, historyItem2});
53805407

53815408
Notification n = new Notification.Builder(mContext, "a")
53825409
.setContentTitle("notification with uris")
@@ -5388,6 +5415,11 @@ public void testVisitUris() throws Exception {
53885415
n.visitUris(visitor);
53895416
verify(visitor, times(1)).accept(eq(audioContents));
53905417
verify(visitor, times(1)).accept(eq(backgroundImage));
5418+
verify(visitor, times(1)).accept(eq(personIcon1.getUri()));
5419+
verify(visitor, times(1)).accept(eq(personIcon2.getUri()));
5420+
verify(visitor, times(1)).accept(eq(personIcon3.getUri()));
5421+
verify(visitor, times(1)).accept(eq(historyUri1));
5422+
verify(visitor, times(1)).accept(eq(historyUri2));
53915423
}
53925424

53935425
@Test

0 commit comments

Comments
 (0)