Skip to content

Commit cf066d7

Browse files
Mark RenoufAndroid Build Coastguard Worker
authored andcommitted
Revert "Prevent sharesheet from previewing unowned URIs [RESTRICT AUTOMERGE]"
This reverts commit cef32a8. Reason for revert: incomplete cherry pick Bug: 276129326 Bug: 261036568 (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:2864439551d1c86636ecfd3fa466328512b9ead5) Merged-In: I493c610e60bb3c60851d09c85340822039723829 Change-Id: I493c610e60bb3c60851d09c85340822039723829
1 parent e24735c commit cf066d7

1 file changed

Lines changed: 2 additions & 33 deletions

File tree

core/java/com/android/internal/app/ChooserActivity.java

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import static android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_CANT_SHARE_WITH_PERSONAL;
2222
import static android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_CANT_SHARE_WITH_WORK;
2323
import static android.app.admin.DevicePolicyResources.Strings.Core.RESOLVER_CROSS_PROFILE_BLOCKED_TITLE;
24-
import static android.content.ContentProvider.getUserIdFromUri;
2524
import static android.stats.devicepolicy.DevicePolicyEnums.RESOLVER_EMPTY_STATE_NO_SHARING_TO_PERSONAL;
2625
import static android.stats.devicepolicy.DevicePolicyEnums.RESOLVER_EMPTY_STATE_NO_SHARING_TO_WORK;
2726

@@ -162,7 +161,6 @@
162161
import java.util.Map;
163162
import java.util.Objects;
164163
import java.util.function.Supplier;
165-
import java.util.stream.Collectors;
166164

167165
/**
168166
* The Chooser Activity handles intent resolution specifically for sharing intents -
@@ -1426,11 +1424,7 @@ private ViewGroup displayImageContentPreview(Intent targetIntent, LayoutInflater
14261424

14271425
String action = targetIntent.getAction();
14281426
if (Intent.ACTION_SEND.equals(action)) {
1429-
Uri uri = targetIntent.getParcelableExtra(Intent.EXTRA_STREAM, android.net.Uri.class);
1430-
if (!validForContentPreview(uri)) {
1431-
contentPreviewLayout.setVisibility(View.GONE);
1432-
return contentPreviewLayout;
1433-
}
1427+
Uri uri = targetIntent.getParcelableExtra(Intent.EXTRA_STREAM);
14341428
imagePreview.findViewById(R.id.content_preview_image_1_large)
14351429
.setTransitionName(ChooserActivity.FIRST_IMAGE_PREVIEW_TRANSITION_NAME);
14361430
mPreviewCoord.loadUriIntoView(R.id.content_preview_image_1_large, uri, 0);
@@ -1440,7 +1434,7 @@ private ViewGroup displayImageContentPreview(Intent targetIntent, LayoutInflater
14401434
List<Uri> uris = targetIntent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
14411435
List<Uri> imageUris = new ArrayList<>();
14421436
for (Uri uri : uris) {
1443-
if (validForContentPreview(uri) && isImageType(resolver.getType(uri))) {
1437+
if (isImageType(resolver.getType(uri))) {
14441438
imageUris.add(uri);
14451439
}
14461440
}
@@ -1550,16 +1544,9 @@ private ViewGroup displayFileContentPreview(Intent targetIntent, LayoutInflater
15501544
String action = targetIntent.getAction();
15511545
if (Intent.ACTION_SEND.equals(action)) {
15521546
Uri uri = targetIntent.getParcelableExtra(Intent.EXTRA_STREAM);
1553-
if (!validForContentPreview(uri)) {
1554-
contentPreviewLayout.setVisibility(View.GONE);
1555-
return contentPreviewLayout;
1556-
}
15571547
loadFileUriIntoView(uri, contentPreviewLayout);
15581548
} else {
15591549
List<Uri> uris = targetIntent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
1560-
uris = uris.stream()
1561-
.filter(ChooserActivity::validForContentPreview)
1562-
.collect(Collectors.toList());
15631550
int uriCount = uris.size();
15641551

15651552
if (uriCount == 0) {
@@ -1618,24 +1605,6 @@ private void loadFileUriIntoView(final Uri uri, final View parent) {
16181605
}
16191606
}
16201607

1621-
/**
1622-
* Indicate if the incoming content URI should be allowed.
1623-
*
1624-
* @param uri the uri to test
1625-
* @return true if the URI is allowed for content preview
1626-
*/
1627-
private static boolean validForContentPreview(Uri uri) throws SecurityException {
1628-
if (uri == null) {
1629-
return false;
1630-
}
1631-
int userId = getUserIdFromUri(uri, UserHandle.USER_CURRENT);
1632-
if (userId != UserHandle.USER_CURRENT && userId != UserHandle.myUserId()) {
1633-
Log.e(TAG, "dropped invalid content URI belonging to user " + userId);
1634-
return false;
1635-
}
1636-
return true;
1637-
}
1638-
16391608
@VisibleForTesting
16401609
protected boolean isImageType(String mimeType) {
16411610
return mimeType != null && mimeType.startsWith("image/");

0 commit comments

Comments
 (0)