
QPR3 is delayed a week now Patches pulled from GrapheneOS and checked against CalyxOS Signed-off-by: Tad <tad@spotco.us>
106 lines
5.1 KiB
Diff
106 lines
5.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Mark Renouf <mrenouf@google.com>
|
|
Date: Wed, 22 Feb 2023 14:48:51 +0000
|
|
Subject: [PATCH 01/10] Prevent sharesheet from previewing unowned URIs
|
|
|
|
Bug: 261036568
|
|
Test: manually via supplied tool (see bug)
|
|
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:fa83e125d14e458545086d16f2e7d1051812dabc)
|
|
Merged-In: Ib3f5839d00c7cf09bca3b01fc0a8a6f0f4960993
|
|
Change-Id: Ib3f5839d00c7cf09bca3b01fc0a8a6f0f4960993
|
|
---
|
|
.../android/internal/app/ChooserActivity.java | 35 +++++++++++++++++--
|
|
1 file changed, 33 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java
|
|
index bfff93b5f7a4..b68e4f4956d0 100644
|
|
--- a/core/java/com/android/internal/app/ChooserActivity.java
|
|
+++ b/core/java/com/android/internal/app/ChooserActivity.java
|
|
@@ -21,6 +21,7 @@ import static android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_CANT
|
|
import static android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_CANT_SHARE_WITH_PERSONAL;
|
|
import static android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_CANT_SHARE_WITH_WORK;
|
|
import static android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_CROSS_PROFILE_BLOCKED_TITLE;
|
|
+import static android.content.ContentProvider.getUserIdFromUri;
|
|
import static android.stats.devicepolicy.DevicePolicyEnums.RESOLVER_EMPTY_STATE_NO_SHARING_TO_PERSONAL;
|
|
import static android.stats.devicepolicy.DevicePolicyEnums.RESOLVER_EMPTY_STATE_NO_SHARING_TO_WORK;
|
|
|
|
@@ -161,6 +162,7 @@ import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Objects;
|
|
import java.util.function.Supplier;
|
|
+import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* The Chooser Activity handles intent resolution specifically for sharing intents -
|
|
@@ -1395,7 +1397,7 @@ public class ChooserActivity extends ResolverActivity implements
|
|
|
|
ImageView previewThumbnailView = contentPreviewLayout.findViewById(
|
|
R.id.content_preview_thumbnail);
|
|
- if (previewThumbnail == null) {
|
|
+ if (!validForContentPreview(previewThumbnail)) {
|
|
previewThumbnailView.setVisibility(View.GONE);
|
|
} else {
|
|
mPreviewCoord = new ContentPreviewCoordinator(contentPreviewLayout, false);
|
|
@@ -1428,6 +1430,10 @@ public class ChooserActivity extends ResolverActivity implements
|
|
|
|
if (Intent.ACTION_SEND.equals(action)) {
|
|
Uri uri = targetIntent.getParcelableExtra(Intent.EXTRA_STREAM);
|
|
+ if (!validForContentPreview(uri)) {
|
|
+ contentPreviewLayout.setVisibility(View.GONE);
|
|
+ return contentPreviewLayout;
|
|
+ }
|
|
imagePreview.findViewById(R.id.content_preview_image_1_large)
|
|
.setTransitionName(ChooserActivity.FIRST_IMAGE_PREVIEW_TRANSITION_NAME);
|
|
mPreviewCoord.loadUriIntoView(R.id.content_preview_image_1_large, uri, 0);
|
|
@@ -1437,7 +1443,7 @@ public class ChooserActivity extends ResolverActivity implements
|
|
List<Uri> uris = targetIntent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
|
List<Uri> imageUris = new ArrayList<>();
|
|
for (Uri uri : uris) {
|
|
- if (isImageType(resolver.getType(uri))) {
|
|
+ if (validForContentPreview(uri) && isImageType(resolver.getType(uri))) {
|
|
imageUris.add(uri);
|
|
}
|
|
}
|
|
@@ -1547,9 +1553,16 @@ public class ChooserActivity extends ResolverActivity implements
|
|
String action = targetIntent.getAction();
|
|
if (Intent.ACTION_SEND.equals(action)) {
|
|
Uri uri = targetIntent.getParcelableExtra(Intent.EXTRA_STREAM);
|
|
+ if (!validForContentPreview(uri)) {
|
|
+ contentPreviewLayout.setVisibility(View.GONE);
|
|
+ return contentPreviewLayout;
|
|
+ }
|
|
loadFileUriIntoView(uri, contentPreviewLayout);
|
|
} else {
|
|
List<Uri> uris = targetIntent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
|
+ uris = uris.stream()
|
|
+ .filter(ChooserActivity::validForContentPreview)
|
|
+ .collect(Collectors.toList());
|
|
int uriCount = uris.size();
|
|
|
|
if (uriCount == 0) {
|
|
@@ -1608,6 +1621,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
|
|
protected boolean isImageType(String mimeType) {
|
|
return mimeType != null && mimeType.startsWith("image/");
|