Merge "Visit Uris in RemoteViews for granting purposes." into pi-dev

This commit is contained in:
Jeff Sharkey
2018-04-19 14:58:02 +00:00
committed by Android (Google) Code Review
3 changed files with 95 additions and 35 deletions

View File

@@ -91,6 +91,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;
/**
* A class that represents how a persistent notification is to be presented to
@@ -2305,6 +2306,45 @@ public class Notification implements Parcelable
}
}
/**
* 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.
*
* @hide
*/
public void visitUris(@NonNull Consumer<Uri> visitor) {
visitor.accept(sound);
if (tickerView != null) tickerView.visitUris(visitor);
if (contentView != null) contentView.visitUris(visitor);
if (bigContentView != null) bigContentView.visitUris(visitor);
if (headsUpContentView != null) headsUpContentView.visitUris(visitor);
if (extras != null) {
visitor.accept(extras.getParcelable(EXTRA_AUDIO_CONTENTS_URI));
visitor.accept(extras.getParcelable(EXTRA_BACKGROUND_IMAGE_URI));
}
if (MessagingStyle.class.equals(getNotificationStyle()) && extras != null) {
final Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES);
if (!ArrayUtils.isEmpty(messages)) {
for (MessagingStyle.Message message : MessagingStyle.Message
.getMessagesFromBundleArray(messages)) {
visitor.accept(message.getDataUri());
}
}
final Parcelable[] historic = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES);
if (!ArrayUtils.isEmpty(historic)) {
for (MessagingStyle.Message message : MessagingStyle.Message
.getMessagesFromBundleArray(historic)) {
visitor.accept(message.getDataUri());
}
}
}
}
/**
* Removes heavyweight parts of the Notification object for archival or for sending to
* listeners when the full contents are not necessary.

View File

@@ -83,6 +83,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Stack;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
/**
* A class that describes a view hierarchy that can be displayed in
@@ -444,6 +445,10 @@ public class RemoteViews implements Parcelable, Filter {
return true;
}
public void visitUris(@NonNull Consumer<Uri> visitor) {
// Nothing to visit by default
}
int viewId;
}
@@ -517,6 +522,27 @@ public class RemoteViews implements Parcelable, Filter {
setBitmapCache(mBitmapCache);
}
/**
* 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.
*
* @hide
*/
public void visitUris(@NonNull Consumer<Uri> visitor) {
if (mActions != null) {
for (int i = 0; i < mActions.size(); i++) {
mActions.get(i).visitUris(visitor);
}
}
}
private static void visitIconUri(Icon icon, @NonNull Consumer<Uri> visitor) {
if (icon != null && icon.getType() == Icon.TYPE_URI) {
visitor.accept(icon.getUri());
}
}
private static class RemoteViewsContextWrapper extends ContextWrapper {
private final Context mContextForResources;
@@ -1485,6 +1511,20 @@ public class RemoteViews implements Parcelable, Filter {
public boolean prefersAsyncApply() {
return this.type == URI || this.type == ICON;
}
@Override
public void visitUris(@NonNull Consumer<Uri> visitor) {
switch (this.type) {
case URI:
final Uri uri = (Uri) this.value;
visitor.accept(uri);
break;
case ICON:
final Icon icon = (Icon) this.value;
visitIconUri(icon, visitor);
break;
}
}
}
/**
@@ -1849,6 +1889,16 @@ public class RemoteViews implements Parcelable, Filter {
return TEXT_VIEW_DRAWABLE_ACTION_TAG;
}
@Override
public void visitUris(@NonNull Consumer<Uri> visitor) {
if (useIcons) {
visitIconUri(i1, visitor);
visitIconUri(i2, visitor);
visitIconUri(i3, visitor);
visitIconUri(i4, visitor);
}
}
boolean isRelative = false;
boolean useIcons = false;
int d1, d2, d3, d4;