Prevent sharesheet from previewing unowned URIs am: 3062b80fb2
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21535256 Change-Id: Id2dc05799f7a12b6ef2974bdbb6e6f211d6942fe Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.internal.app;
|
package com.android.internal.app;
|
||||||
|
|
||||||
|
import static android.content.ContentProvider.getUserIdFromUri;
|
||||||
|
|
||||||
import static java.lang.annotation.RetentionPolicy.SOURCE;
|
import static java.lang.annotation.RetentionPolicy.SOURCE;
|
||||||
|
|
||||||
import android.animation.Animator;
|
import android.animation.Animator;
|
||||||
@@ -148,6 +150,7 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Chooser Activity handles intent resolution specifically for sharing intents -
|
* The Chooser Activity handles intent resolution specifically for sharing intents -
|
||||||
@@ -1300,7 +1303,7 @@ public class ChooserActivity extends ResolverActivity implements
|
|||||||
|
|
||||||
ImageView previewThumbnailView = contentPreviewLayout.findViewById(
|
ImageView previewThumbnailView = contentPreviewLayout.findViewById(
|
||||||
R.id.content_preview_thumbnail);
|
R.id.content_preview_thumbnail);
|
||||||
if (previewThumbnail == null) {
|
if (!validForContentPreview(previewThumbnail)) {
|
||||||
previewThumbnailView.setVisibility(View.GONE);
|
previewThumbnailView.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
mPreviewCoord = new ContentPreviewCoordinator(contentPreviewLayout, false);
|
mPreviewCoord = new ContentPreviewCoordinator(contentPreviewLayout, false);
|
||||||
@@ -1327,6 +1330,10 @@ public class ChooserActivity extends ResolverActivity implements
|
|||||||
String action = targetIntent.getAction();
|
String action = targetIntent.getAction();
|
||||||
if (Intent.ACTION_SEND.equals(action)) {
|
if (Intent.ACTION_SEND.equals(action)) {
|
||||||
Uri uri = targetIntent.getParcelableExtra(Intent.EXTRA_STREAM);
|
Uri uri = targetIntent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||||
|
if (!validForContentPreview(uri)) {
|
||||||
|
contentPreviewLayout.setVisibility(View.GONE);
|
||||||
|
return contentPreviewLayout;
|
||||||
|
}
|
||||||
mPreviewCoord.loadUriIntoView(R.id.content_preview_image_1_large, uri, 0);
|
mPreviewCoord.loadUriIntoView(R.id.content_preview_image_1_large, uri, 0);
|
||||||
} else {
|
} else {
|
||||||
ContentResolver resolver = getContentResolver();
|
ContentResolver resolver = getContentResolver();
|
||||||
@@ -1334,7 +1341,7 @@ public class ChooserActivity extends ResolverActivity implements
|
|||||||
List<Uri> uris = targetIntent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
List<Uri> uris = targetIntent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
||||||
List<Uri> imageUris = new ArrayList<>();
|
List<Uri> imageUris = new ArrayList<>();
|
||||||
for (Uri uri : uris) {
|
for (Uri uri : uris) {
|
||||||
if (isImageType(resolver.getType(uri))) {
|
if (validForContentPreview(uri) && isImageType(resolver.getType(uri))) {
|
||||||
imageUris.add(uri);
|
imageUris.add(uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1441,9 +1448,16 @@ public class ChooserActivity extends ResolverActivity implements
|
|||||||
String action = targetIntent.getAction();
|
String action = targetIntent.getAction();
|
||||||
if (Intent.ACTION_SEND.equals(action)) {
|
if (Intent.ACTION_SEND.equals(action)) {
|
||||||
Uri uri = targetIntent.getParcelableExtra(Intent.EXTRA_STREAM);
|
Uri uri = targetIntent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||||
|
if (!validForContentPreview(uri)) {
|
||||||
|
contentPreviewLayout.setVisibility(View.GONE);
|
||||||
|
return contentPreviewLayout;
|
||||||
|
}
|
||||||
loadFileUriIntoView(uri, contentPreviewLayout);
|
loadFileUriIntoView(uri, contentPreviewLayout);
|
||||||
} else {
|
} else {
|
||||||
List<Uri> uris = targetIntent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
List<Uri> uris = targetIntent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
||||||
|
uris = uris.stream()
|
||||||
|
.filter(ChooserActivity::validForContentPreview)
|
||||||
|
.collect(Collectors.toList());
|
||||||
int uriCount = uris.size();
|
int uriCount = uris.size();
|
||||||
|
|
||||||
if (uriCount == 0) {
|
if (uriCount == 0) {
|
||||||
@@ -1497,6 +1511,24 @@ public class ChooserActivity extends ResolverActivity implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicate if the incoming content URI should be allowed.
|
||||||
|
*
|
||||||
|
* @param uri the uri to test
|
||||||
|
* @return true if the URI is allowed for content preview
|
||||||
|
*/
|
||||||
|
private static boolean validForContentPreview(Uri uri) throws SecurityException {
|
||||||
|
if (uri == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int userId = getUserIdFromUri(uri, UserHandle.USER_CURRENT);
|
||||||
|
if (userId != UserHandle.USER_CURRENT && userId != UserHandle.myUserId()) {
|
||||||
|
Log.e(TAG, "dropped invalid content URI belonging to user " + userId);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected boolean isImageType(String mimeType) {
|
protected boolean isImageType(String mimeType) {
|
||||||
return mimeType != null && mimeType.startsWith("image/");
|
return mimeType != null && mimeType.startsWith("image/");
|
||||||
|
|||||||
Reference in New Issue
Block a user