Skip to content

Commit

Permalink
Check more URIs in notifications
Browse files Browse the repository at this point in the history
Bug: 281044385
Test: presubmit + tested in current release

(cherry picked from commit f47b41a,
includes changes from commit 57bf60d
and commit 47fa2f7)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:986e36ce03b119253e5b7c7fd39bdd0324e0dc8a)
Merged-In: I1ce6bebd9452466d005505dc5b99a0fdc0e05e80
Change-Id: I1ce6bebd9452466d005505dc5b99a0fdc0e05e80
  • Loading branch information
Ioana Alexandru authored and aoleary committed Nov 18, 2024
1 parent 91e9cf9 commit 8648665
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 15 deletions.
32 changes: 17 additions & 15 deletions core/java/android/app/Notification.java
Original file line number Diff line number Diff line change
Expand Up @@ -2854,7 +2854,7 @@ public void visitUris(@NonNull Consumer<Uri> visitor) {
Person.class);
if (people != null && !people.isEmpty()) {
for (Person p : people) {
visitor.accept(p.getIconUri());
p.visitUris(visitor);
}
}

Expand All @@ -2874,20 +2874,15 @@ public void visitUris(@NonNull Consumer<Uri> visitor) {
// 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());
person.visitUris(visitor);
}

final Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES,
Parcelable.class);
if (!ArrayUtils.isEmpty(messages)) {
for (MessagingStyle.Message message : MessagingStyle.Message
.getMessagesFromBundleArray(messages)) {
visitor.accept(message.getDataUri());

Person senderPerson = message.getSenderPerson();
if (senderPerson != null) {
visitor.accept(senderPerson.getIconUri());
}
message.visitUris(visitor);
}
}

Expand All @@ -2896,12 +2891,7 @@ public void visitUris(@NonNull Consumer<Uri> visitor) {
if (!ArrayUtils.isEmpty(historic)) {
for (MessagingStyle.Message message : MessagingStyle.Message
.getMessagesFromBundleArray(historic)) {
visitor.accept(message.getDataUri());

Person senderPerson = message.getSenderPerson();
if (senderPerson != null) {
visitor.accept(senderPerson.getIconUri());
}
message.visitUris(visitor);
}
}

Expand All @@ -2910,7 +2900,7 @@ public void visitUris(@NonNull Consumer<Uri> visitor) {
// 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());
callPerson.visitUris(visitor);
}
visitIconUri(visitor, extras.getParcelable(EXTRA_VERIFICATION_ICON, Icon.class));
}
Expand Down Expand Up @@ -8792,6 +8782,18 @@ static Bundle[] getBundleArrayForMessages(List<Message> messages) {
return bundles;
}

/**
* See {@link Notification#visitUris(Consumer)}.
*
* @hide
*/
public void visitUris(@NonNull Consumer<Uri> visitor) {
visitor.accept(getDataUri());
if (mSender != null) {
mSender.visitUris(visitor);
}
}

/**
* Returns a list of messages read from the given bundle list, e.g.
* {@link #EXTRA_MESSAGES} or {@link #EXTRA_HISTORIC_MESSAGES}.
Expand Down
17 changes: 17 additions & 0 deletions core/java/android/app/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.os.Parcelable;

import java.util.Objects;
import java.util.function.Consumer;

/**
* Provides an immutable reference to an entity that appears repeatedly on different surfaces of the
Expand Down Expand Up @@ -177,6 +178,22 @@ public void writeToParcel(Parcel dest, @WriteFlags int flags) {
dest.writeBoolean(mIsBot);
}

/**
* Note all {@link Uri} that are referenced internally, with the expectation that Uri permission
* grants will need to be issued to ensure the recipient of this object is able to render its
* contents.
* See b/281044385 for more context and examples about what happens when this isn't done
* correctly.
*
* @hide
*/
public void visitUris(@NonNull Consumer<Uri> visitor) {
visitor.accept(getIconUri());
if (mUri != null && !mUri.isEmpty()) {
visitor.accept(Uri.parse(mUri));
}
}

/** Builder for the immutable {@link Person} class. */
public static class Builder {
@Nullable private CharSequence mName;
Expand Down
23 changes: 23 additions & 0 deletions core/java/android/widget/RemoteViews.java
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,13 @@ public int getActionTag() {
return SET_REMOTE_VIEW_ADAPTER_LIST_TAG;
}

@Override
public void visitUris(@NonNull Consumer<Uri> visitor) {
for (RemoteViews remoteViews : list) {
remoteViews.visitUris(visitor);
}
}

int viewTypeCount;
ArrayList<RemoteViews> list;
}
Expand Down Expand Up @@ -1082,6 +1089,13 @@ public void apply(View root, ViewGroup rootParent, ActionApplyParams params)
public int getActionTag() {
return SET_REMOTE_COLLECTION_ITEMS_ADAPTER_TAG;
}

@Override
public void visitUris(@NonNull Consumer<Uri> visitor) {
if (mItems != null) {
mItems.visitUris(visitor);
}
}
}

private class SetRemoteViewsAdapterIntent extends Action {
Expand Down Expand Up @@ -7029,6 +7043,15 @@ public RemoteCollectionItems build() {
Math.max(mViewTypeCount, 1));
}
}

/**
* See {@link RemoteViews#visitUris(Consumer)}.
*/
private void visitUris(@NonNull Consumer<Uri> visitor) {
for (RemoteViews view : mViews) {
view.visitUris(visitor);
}
}
}

/**
Expand Down

0 comments on commit 8648665

Please sign in to comment.