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

Commit 1b3b97d9 authored by Mark Renouf's avatar Mark Renouf Committed by Automerger Merge Worker
Browse files

[conflict] Prevent sharesheet from previewing unowned URIs am: 3062b80f am:...

[conflict] Prevent sharesheet from previewing unowned URIs am: 3062b80f am: b4f4ac8e am: f4b4fbea

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21787171



Change-Id: I05d1c8abf2aa032153da5224ce31ba78044e0c77
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents d1283341 f4b4fbea
Loading
Loading
Loading
Loading
+34 −2
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.internal.app;

import static android.content.ContentProvider.getUserIdFromUri;

import static java.lang.annotation.RetentionPolicy.SOURCE;

import android.animation.Animator;
@@ -149,6 +151,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * The Chooser Activity handles intent resolution specifically for sharing intents -
@@ -1375,7 +1378,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);
@@ -1403,6 +1406,10 @@ 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;
            }
            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);
@@ -1412,7 +1419,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);
                }
            }
@@ -1521,9 +1528,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) {
@@ -1577,6 +1591,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/");