Verify URI permissions for EXTRA_REMOTE_INPUT_HISTORY_ITEMS. am: 88e597d2b3 am: 99424fe5e1

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23877020

Change-Id: I111ed26520c6b4d00970d8a42c482858917510e7
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Ioana Alexandru
2023-07-07 13:15:02 +00:00
committed by Automerger Merge Worker
2 changed files with 29 additions and 0 deletions

View File

@@ -2807,6 +2807,17 @@ public class Notification implements Parcelable
if (person != null) {
visitor.accept(person.getIconUri());
}
final RemoteInputHistoryItem[] history = getParcelableArrayFromBundle(extras,
Notification.EXTRA_REMOTE_INPUT_HISTORY_ITEMS, RemoteInputHistoryItem.class);
if (history != null) {
for (int i = 0; i < history.length; i++) {
RemoteInputHistoryItem item = history[i];
if (item.getUri() != null) {
visitor.accept(item.getUri());
}
}
}
}
if (isStyle(MessagingStyle.class) && extras != null) {

View File

@@ -117,6 +117,7 @@ import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Person;
import android.app.RemoteInput;
import android.app.RemoteInputHistoryItem;
import android.app.StatsManager;
import android.app.admin.DevicePolicyManagerInternal;
import android.app.usage.UsageStatsManagerInternal;
@@ -4360,6 +4361,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
.setName("People List Person 2")
.setIcon(personIcon3)
.build();
final Uri historyUri1 = Uri.parse("content://com.example/history1");
final Uri historyUri2 = Uri.parse("content://com.example/history2");
final RemoteInputHistoryItem historyItem1 = new RemoteInputHistoryItem(null, historyUri1,
"a");
final RemoteInputHistoryItem historyItem2 = new RemoteInputHistoryItem(null, historyUri2,
"b");
Bundle extras = new Bundle();
extras.putParcelable(Notification.EXTRA_AUDIO_CONTENTS_URI, audioContents);
@@ -4367,6 +4374,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
extras.putParcelable(Notification.EXTRA_MESSAGING_PERSON, person1);
extras.putParcelableArrayList(Notification.EXTRA_PEOPLE_LIST,
new ArrayList<>(Arrays.asList(person2, person3)));
extras.putParcelableArray(Notification.EXTRA_REMOTE_INPUT_HISTORY_ITEMS,
new RemoteInputHistoryItem[]{historyItem1, historyItem2});
Notification n = new Notification.Builder(mContext, "a")
.setContentTitle("notification with uris")
@@ -4375,6 +4384,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
.addExtras(extras)
.build();
// Serialize and deserialize the notification to make sure nothing breaks in the process,
// since that's what will usually happen before we get to call visitUris.
Parcel parcel = Parcel.obtain();
n.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
n = new Notification(parcel);
Consumer<Uri> visitor = (Consumer<Uri>) spy(Consumer.class);
n.visitUris(visitor);
verify(visitor, times(1)).accept(eq(audioContents));
@@ -4384,6 +4400,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
verify(visitor, times(1)).accept(eq(personIcon1.getUri()));
verify(visitor, times(1)).accept(eq(personIcon2.getUri()));
verify(visitor, times(1)).accept(eq(personIcon3.getUri()));
verify(visitor, times(1)).accept(eq(historyUri1));
verify(visitor, times(1)).accept(eq(historyUri2));
}
@Test