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

Commit 183b4303 authored by Andrey Yepin's avatar Andrey Yepin Committed by Evelyn Torres
Browse files

Verify that the caller has permissions for the icons it provided.

Bug: 277207798
Test: manual testing: first reroduce the issue as described in the
 ticket then check that it is not reproduceable after the fix.
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:e73bb60fed12daa78ddad8308b31b0c78f1c3c66)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:855bfe0dc6e7d2e1528c97ab53b06b6a32cea575)
Merged-In: Ic8cb75ed586e94c5895065f772bfb21013396dd0
Change-Id: Ic8cb75ed586e94c5895065f772bfb21013396dd0
parent 833e77ac
Loading
Loading
Loading
Loading
+48 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.internal.app;

import static android.content.ContentProvider.getUriWithoutUserId;
import static android.content.ContentProvider.getUserIdFromUri;

import static java.lang.annotation.RetentionPolicy.SOURCE;
@@ -30,7 +31,9 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.IUriGrantsManager;
import android.app.SharedElementCallback;
import android.app.UriGrantsManager;
import android.app.prediction.AppPredictionContext;
import android.app.prediction.AppPredictionManager;
import android.app.prediction.AppPredictor;
@@ -67,6 +70,7 @@ import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.drawable.AnimatedVectorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.metrics.LogMaker;
import android.net.Uri;
import android.os.AsyncTask;
@@ -745,7 +749,11 @@ public class ChooserActivity extends ResolverActivity implements
                    targets = null;
                    break;
                }
                targets[i] = (ChooserTarget) pa[i];
                ChooserTarget chooserTarget = (ChooserTarget) pa[i];
                if (!hasValidIcon(chooserTarget)) {
                    chooserTarget = removeIcon(chooserTarget);
                }
                targets[i] = chooserTarget;
            }
            mCallerChooserTargets = targets;
        }
@@ -4275,4 +4283,43 @@ public class ChooserActivity extends ResolverActivity implements
    protected void maybeLogProfileChange() {
        getChooserActivityLogger().logShareheetProfileChanged();
    }

    private boolean hasValidIcon(ChooserTarget target) {
        Icon icon = target.getIcon();
        if (icon == null) {
            return true;
        }
        if (icon.getType() == Icon.TYPE_URI || icon.getType() == Icon.TYPE_URI_ADAPTIVE_BITMAP) {
            Uri uri = icon.getUri();
            try {
                getUriGrantsManager().checkGrantUriPermission_ignoreNonSystem(
                        getLaunchedFromUid(),
                        getPackageName(),
                        getUriWithoutUserId(uri),
                        Intent.FLAG_GRANT_READ_URI_PERMISSION,
                        getUserIdFromUri(uri)
                );
            } catch (SecurityException | RemoteException e) {
                Log.e(TAG, "Failed to get URI permission for: " + uri, e);
                return false;
            }
        }
        return true;
    }

    private IUriGrantsManager getUriGrantsManager() {
        return UriGrantsManager.getService();
    }

    private static ChooserTarget removeIcon(ChooserTarget target) {
        if (target == null) {
            return null;
        }
        return new ChooserTarget(
                target.getTitle(),
                null,
                target.getScore(),
                target.getComponentName(),
                target.getIntentExtras());
    }
}