Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4a52aa1d authored by Ioana Alexandru's avatar Ioana Alexandru Committed by Android Build Coastguard Worker
Browse files

Check more URIs in notifications

Bug: 281044385
Test: presubmit + tested in current release

(cherry picked from commit f47b41a1,
includes changes from commit 57bf60dd
and commit 47fa2f79)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:e779a58c218078ef55c6b9eec3f34066467ae2fb)
Merged-In: I1ce6bebd9452466d005505dc5b99a0fdc0e05e80
Change-Id: I1ce6bebd9452466d005505dc5b99a0fdc0e05e80
parent aece1c1b
Loading
Loading
Loading
Loading
+17 −15
Original line number Original line Diff line number Diff line
@@ -2807,7 +2807,7 @@ public class Notification implements Parcelable
            ArrayList<Person> people = extras.getParcelableArrayList(EXTRA_PEOPLE_LIST);
            ArrayList<Person> people = extras.getParcelableArrayList(EXTRA_PEOPLE_LIST);
            if (people != null && !people.isEmpty()) {
            if (people != null && !people.isEmpty()) {
                for (Person p : people) {
                for (Person p : people) {
                    visitor.accept(p.getIconUri());
                    p.visitUris(visitor);
                }
                }
            }
            }


@@ -2826,19 +2826,14 @@ public class Notification implements Parcelable
            // Notification Listeners might use directly (without the isStyle check).
            // Notification Listeners might use directly (without the isStyle check).
            final Person person = extras.getParcelable(EXTRA_MESSAGING_PERSON);
            final Person person = extras.getParcelable(EXTRA_MESSAGING_PERSON);
            if (person != null) {
            if (person != null) {
                visitor.accept(person.getIconUri());
                person.visitUris(visitor);
            }
            }


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

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


@@ -2846,12 +2841,7 @@ public class Notification implements Parcelable
            if (!ArrayUtils.isEmpty(historic)) {
            if (!ArrayUtils.isEmpty(historic)) {
                for (MessagingStyle.Message message : MessagingStyle.Message
                for (MessagingStyle.Message message : MessagingStyle.Message
                        .getMessagesFromBundleArray(historic)) {
                        .getMessagesFromBundleArray(historic)) {
                    visitor.accept(message.getDataUri());
                    message.visitUris(visitor);

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


@@ -2860,7 +2850,7 @@ public class Notification implements Parcelable
            // Extras for CallStyle (same reason for visiting without checking isStyle).
            // Extras for CallStyle (same reason for visiting without checking isStyle).
            Person callPerson = extras.getParcelable(EXTRA_CALL_PERSON);
            Person callPerson = extras.getParcelable(EXTRA_CALL_PERSON);
            if (callPerson != null) {
            if (callPerson != null) {
                visitor.accept(callPerson.getIconUri());
                callPerson.visitUris(visitor);
            }
            }
            visitIconUri(visitor, extras.getParcelable(EXTRA_VERIFICATION_ICON));
            visitIconUri(visitor, extras.getParcelable(EXTRA_VERIFICATION_ICON));
        }
        }
@@ -8626,6 +8616,18 @@ public class Notification implements Parcelable
                return bundles;
                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.
             * Returns a list of messages read from the given bundle list, e.g.
             * {@link #EXTRA_MESSAGES} or {@link #EXTRA_HISTORIC_MESSAGES}.
             * {@link #EXTRA_MESSAGES} or {@link #EXTRA_HISTORIC_MESSAGES}.
+17 −0
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable;


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


/**
/**
 * Provides an immutable reference to an entity that appears repeatedly on different surfaces of the
 * Provides an immutable reference to an entity that appears repeatedly on different surfaces of the
@@ -177,6 +178,22 @@ public final class Person implements Parcelable {
        dest.writeBoolean(mIsBot);
        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. */
    /** Builder for the immutable {@link Person} class. */
    public static class Builder {
    public static class Builder {
        @Nullable private CharSequence mName;
        @Nullable private CharSequence mName;
+23 −0
Original line number Original line Diff line number Diff line
@@ -946,6 +946,13 @@ public class RemoteViews implements Parcelable, Filter {
            return SET_REMOTE_VIEW_ADAPTER_LIST_TAG;
            return SET_REMOTE_VIEW_ADAPTER_LIST_TAG;
        }
        }


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

        int viewTypeCount;
        int viewTypeCount;
        ArrayList<RemoteViews> list;
        ArrayList<RemoteViews> list;
    }
    }
@@ -1068,6 +1075,13 @@ public class RemoteViews implements Parcelable, Filter {
        public int getActionTag() {
        public int getActionTag() {
            return SET_REMOTE_COLLECTION_ITEMS_ADAPTER_TAG;
            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 {
    private class SetRemoteViewsAdapterIntent extends Action {
@@ -6940,6 +6954,15 @@ public class RemoteViews implements Parcelable, Filter {
                        Math.max(mViewTypeCount, 1));
                        Math.max(mViewTypeCount, 1));
            }
            }
        }
        }

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


    /**
    /**