|
| 1 | +From 3d87913569b4102bbbd3b3542f0d1104e7e3c13a Mon Sep 17 00:00:00 2001 |
| 2 | +From: Ioana Alexandru <aioana@google.com> |
| 3 | +Date: Wed, 31 Jul 2024 13:46:30 +0000 |
| 4 | +Subject: [PATCH] Check more URIs in notifications |
| 5 | + |
| 6 | +Bug: 281044385 |
| 7 | +Test: presubmit + tested in current release |
| 8 | + |
| 9 | +(cherry picked from commit f47b41a138ebd60f7b518fb6a9d8aa8230488422, |
| 10 | +includes changes from commit 57bf60dd7b6a0a0e9785231f8ec25a458fedde64 |
| 11 | +and commit 47fa2f79584b0a4e9ca7e9c6b237c4e5cf699032) |
| 12 | +(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:e6ed8a4bef3ec5a2517fc80ac88e2fc09b67c226) |
| 13 | +Merged-In: I1ce6bebd9452466d005505dc5b99a0fdc0e05e80 |
| 14 | +Change-Id: I1ce6bebd9452466d005505dc5b99a0fdc0e05e80 |
| 15 | +--- |
| 16 | + core/java/android/app/Notification.java | 32 ++++++++++++----------- |
| 17 | + core/java/android/app/Person.java | 17 ++++++++++++ |
| 18 | + core/java/android/widget/RemoteViews.java | 23 ++++++++++++++++ |
| 19 | + 3 files changed, 57 insertions(+), 15 deletions(-) |
| 20 | + |
| 21 | +diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java |
| 22 | +index ed8c6be73256..3aeb363b627b 100644 |
| 23 | +--- a/core/java/android/app/Notification.java |
| 24 | ++++ b/core/java/android/app/Notification.java |
| 25 | +@@ -2799,7 +2799,7 @@ public class Notification implements Parcelable |
| 26 | + ArrayList<Person> people = extras.getParcelableArrayList(EXTRA_PEOPLE_LIST); |
| 27 | + if (people != null && !people.isEmpty()) { |
| 28 | + for (Person p : people) { |
| 29 | +- visitor.accept(p.getIconUri()); |
| 30 | ++ p.visitUris(visitor); |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | +@@ -2818,19 +2818,14 @@ public class Notification implements Parcelable |
| 35 | + // Notification Listeners might use directly (without the isStyle check). |
| 36 | + final Person person = extras.getParcelable(EXTRA_MESSAGING_PERSON); |
| 37 | + if (person != null) { |
| 38 | +- visitor.accept(person.getIconUri()); |
| 39 | ++ person.visitUris(visitor); |
| 40 | + } |
| 41 | + |
| 42 | + final Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES); |
| 43 | + if (!ArrayUtils.isEmpty(messages)) { |
| 44 | + for (MessagingStyle.Message message : MessagingStyle.Message |
| 45 | + .getMessagesFromBundleArray(messages)) { |
| 46 | +- visitor.accept(message.getDataUri()); |
| 47 | +- |
| 48 | +- Person senderPerson = message.getSenderPerson(); |
| 49 | +- if (senderPerson != null) { |
| 50 | +- visitor.accept(senderPerson.getIconUri()); |
| 51 | +- } |
| 52 | ++ message.visitUris(visitor); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | +@@ -2838,12 +2833,7 @@ public class Notification implements Parcelable |
| 57 | + if (!ArrayUtils.isEmpty(historic)) { |
| 58 | + for (MessagingStyle.Message message : MessagingStyle.Message |
| 59 | + .getMessagesFromBundleArray(historic)) { |
| 60 | +- visitor.accept(message.getDataUri()); |
| 61 | +- |
| 62 | +- Person senderPerson = message.getSenderPerson(); |
| 63 | +- if (senderPerson != null) { |
| 64 | +- visitor.accept(senderPerson.getIconUri()); |
| 65 | +- } |
| 66 | ++ message.visitUris(visitor); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | +@@ -2852,7 +2842,7 @@ public class Notification implements Parcelable |
| 71 | + // Extras for CallStyle (same reason for visiting without checking isStyle). |
| 72 | + Person callPerson = extras.getParcelable(EXTRA_CALL_PERSON); |
| 73 | + if (callPerson != null) { |
| 74 | +- visitor.accept(callPerson.getIconUri()); |
| 75 | ++ callPerson.visitUris(visitor); |
| 76 | + } |
| 77 | + visitIconUri(visitor, extras.getParcelable(EXTRA_VERIFICATION_ICON)); |
| 78 | + } |
| 79 | +@@ -8557,6 +8547,18 @@ public class Notification implements Parcelable |
| 80 | + return bundles; |
| 81 | + } |
| 82 | + |
| 83 | ++ /** |
| 84 | ++ * See {@link Notification#visitUris(Consumer)}. |
| 85 | ++ * |
| 86 | ++ * @hide |
| 87 | ++ */ |
| 88 | ++ public void visitUris(@NonNull Consumer<Uri> visitor) { |
| 89 | ++ visitor.accept(getDataUri()); |
| 90 | ++ if (mSender != null) { |
| 91 | ++ mSender.visitUris(visitor); |
| 92 | ++ } |
| 93 | ++ } |
| 94 | ++ |
| 95 | + /** |
| 96 | + * Returns a list of messages read from the given bundle list, e.g. |
| 97 | + * {@link #EXTRA_MESSAGES} or {@link #EXTRA_HISTORIC_MESSAGES}. |
| 98 | +diff --git a/core/java/android/app/Person.java b/core/java/android/app/Person.java |
| 99 | +index 97a794d4e4ea..c7432c571e43 100644 |
| 100 | +--- a/core/java/android/app/Person.java |
| 101 | ++++ b/core/java/android/app/Person.java |
| 102 | +@@ -24,6 +24,7 @@ import android.os.Parcel; |
| 103 | + import android.os.Parcelable; |
| 104 | + |
| 105 | + import java.util.Objects; |
| 106 | ++import java.util.function.Consumer; |
| 107 | + |
| 108 | + /** |
| 109 | + * Provides an immutable reference to an entity that appears repeatedly on different surfaces of the |
| 110 | +@@ -177,6 +178,22 @@ public final class Person implements Parcelable { |
| 111 | + dest.writeBoolean(mIsBot); |
| 112 | + } |
| 113 | + |
| 114 | ++ /** |
| 115 | ++ * Note all {@link Uri} that are referenced internally, with the expectation that Uri permission |
| 116 | ++ * grants will need to be issued to ensure the recipient of this object is able to render its |
| 117 | ++ * contents. |
| 118 | ++ * See b/281044385 for more context and examples about what happens when this isn't done |
| 119 | ++ * correctly. |
| 120 | ++ * |
| 121 | ++ * @hide |
| 122 | ++ */ |
| 123 | ++ public void visitUris(@NonNull Consumer<Uri> visitor) { |
| 124 | ++ visitor.accept(getIconUri()); |
| 125 | ++ if (mUri != null && !mUri.isEmpty()) { |
| 126 | ++ visitor.accept(Uri.parse(mUri)); |
| 127 | ++ } |
| 128 | ++ } |
| 129 | ++ |
| 130 | + /** Builder for the immutable {@link Person} class. */ |
| 131 | + public static class Builder { |
| 132 | + @Nullable private CharSequence mName; |
| 133 | +diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java |
| 134 | +index cecfa08c6e20..0747308eb93a 100644 |
| 135 | +--- a/core/java/android/widget/RemoteViews.java |
| 136 | ++++ b/core/java/android/widget/RemoteViews.java |
| 137 | +@@ -934,6 +934,13 @@ public class RemoteViews implements Parcelable, Filter { |
| 138 | + return SET_REMOTE_VIEW_ADAPTER_LIST_TAG; |
| 139 | + } |
| 140 | + |
| 141 | ++ @Override |
| 142 | ++ public void visitUris(@NonNull Consumer<Uri> visitor) { |
| 143 | ++ for (RemoteViews remoteViews : list) { |
| 144 | ++ remoteViews.visitUris(visitor); |
| 145 | ++ } |
| 146 | ++ } |
| 147 | ++ |
| 148 | + int viewTypeCount; |
| 149 | + ArrayList<RemoteViews> list; |
| 150 | + } |
| 151 | +@@ -1009,6 +1016,13 @@ public class RemoteViews implements Parcelable, Filter { |
| 152 | + public int getActionTag() { |
| 153 | + return SET_REMOTE_COLLECTION_ITEMS_ADAPTER_TAG; |
| 154 | + } |
| 155 | ++ |
| 156 | ++ @Override |
| 157 | ++ public void visitUris(@NonNull Consumer<Uri> visitor) { |
| 158 | ++ if (mItems != null) { |
| 159 | ++ mItems.visitUris(visitor); |
| 160 | ++ } |
| 161 | ++ } |
| 162 | + } |
| 163 | + |
| 164 | + private class SetRemoteViewsAdapterIntent extends Action { |
| 165 | +@@ -6757,6 +6771,15 @@ public class RemoteViews implements Parcelable, Filter { |
| 166 | + Math.max(mViewTypeCount, 1)); |
| 167 | + } |
| 168 | + } |
| 169 | ++ |
| 170 | ++ /** |
| 171 | ++ * See {@link RemoteViews#visitUris(Consumer)}. |
| 172 | ++ */ |
| 173 | ++ private void visitUris(@NonNull Consumer<Uri> visitor) { |
| 174 | ++ for (RemoteViews view : mViews) { |
| 175 | ++ view.visitUris(visitor); |
| 176 | ++ } |
| 177 | ++ } |
| 178 | + } |
| 179 | + |
| 180 | + /** |
| 181 | +-- |
| 182 | +2.46.1.824.gd892dcdcdd-goog |
| 183 | + |
0 commit comments