Skip to content

Commit 8f00d3e

Browse files
Ioana AlexandruAndroid Build Coastguard Worker
authored andcommitted
Verify URI permissions for EXTRA_REMOTE_INPUT_HISTORY_ITEMS.
Also added a step to serialize & deserialize the notification in the test, to prevent exceptions about not being able to cast e.g. Parcelable[] to RemoteInputHistoryItem[]. Test: atest NotificationManagerServiceTest & tested with POC from bug Bug: 276729064 (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:4e19431a60300c6ea6c7f7dd64299916e4eb09bc) Merged-In: I7053ca59f9c7f1df5226418594109cfb8b609b1e Change-Id: I7053ca59f9c7f1df5226418594109cfb8b609b1e
1 parent 69f018b commit 8f00d3e

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

core/java/android/app/Notification.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2861,6 +2861,18 @@ public void visitUris(@NonNull Consumer<Uri> visitor) {
28612861
if (person != null) {
28622862
visitor.accept(person.getIconUri());
28632863
}
2864+
2865+
final RemoteInputHistoryItem[] history = extras.getParcelableArray(
2866+
Notification.EXTRA_REMOTE_INPUT_HISTORY_ITEMS,
2867+
RemoteInputHistoryItem.class);
2868+
if (history != null) {
2869+
for (int i = 0; i < history.length; i++) {
2870+
RemoteInputHistoryItem item = history[i];
2871+
if (item.getUri() != null) {
2872+
visitor.accept(item.getUri());
2873+
}
2874+
}
2875+
}
28642876
}
28652877

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

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
import android.app.PendingIntent;
130130
import android.app.Person;
131131
import android.app.RemoteInput;
132+
import android.app.RemoteInputHistoryItem;
132133
import android.app.StatsManager;
133134
import android.app.admin.DevicePolicyManagerInternal;
134135
import android.app.usage.UsageStatsManagerInternal;
@@ -5415,13 +5416,21 @@ public void testVisitUris() throws Exception {
54155416
.setName("People List Person 2")
54165417
.setIcon(personIcon3)
54175418
.build();
5419+
final Uri historyUri1 = Uri.parse("content://com.example/history1");
5420+
final Uri historyUri2 = Uri.parse("content://com.example/history2");
5421+
final RemoteInputHistoryItem historyItem1 = new RemoteInputHistoryItem(null, historyUri1,
5422+
"a");
5423+
final RemoteInputHistoryItem historyItem2 = new RemoteInputHistoryItem(null, historyUri2,
5424+
"b");
54185425

54195426
Bundle extras = new Bundle();
54205427
extras.putParcelable(Notification.EXTRA_AUDIO_CONTENTS_URI, audioContents);
54215428
extras.putString(Notification.EXTRA_BACKGROUND_IMAGE_URI, backgroundImage.toString());
54225429
extras.putParcelable(Notification.EXTRA_MESSAGING_PERSON, person1);
54235430
extras.putParcelableArrayList(Notification.EXTRA_PEOPLE_LIST,
54245431
new ArrayList<>(Arrays.asList(person2, person3)));
5432+
extras.putParcelableArray(Notification.EXTRA_REMOTE_INPUT_HISTORY_ITEMS,
5433+
new RemoteInputHistoryItem[]{historyItem1, historyItem2});
54255434

54265435
Notification n = new Notification.Builder(mContext, "a")
54275436
.setContentTitle("notification with uris")
@@ -5430,6 +5439,13 @@ public void testVisitUris() throws Exception {
54305439
.addExtras(extras)
54315440
.build();
54325441

5442+
// Serialize and deserialize the notification to make sure nothing breaks in the process,
5443+
// since that's what will usually happen before we get to call visitUris.
5444+
Parcel parcel = Parcel.obtain();
5445+
n.writeToParcel(parcel, 0);
5446+
parcel.setDataPosition(0);
5447+
n = new Notification(parcel);
5448+
54335449
Consumer<Uri> visitor = (Consumer<Uri>) spy(Consumer.class);
54345450
n.visitUris(visitor);
54355451
verify(visitor, times(1)).accept(eq(audioContents));
@@ -5439,6 +5455,8 @@ public void testVisitUris() throws Exception {
54395455
verify(visitor, times(1)).accept(eq(personIcon1.getUri()));
54405456
verify(visitor, times(1)).accept(eq(personIcon2.getUri()));
54415457
verify(visitor, times(1)).accept(eq(personIcon3.getUri()));
5458+
verify(visitor, times(1)).accept(eq(historyUri1));
5459+
verify(visitor, times(1)).accept(eq(historyUri2));
54425460
}
54435461

54445462
@Test

0 commit comments

Comments
 (0)