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

Commit 520e266b authored by Pinyao Ting's avatar Pinyao Ting
Browse files

Validate URI-based shortcut icon at creation time.

Bug: 288113797
Test: manual
Change-Id: I392f8e923923bf40827a2b6207c4eaa262694fbc
parent aeb77b50
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.app.usage.UsageStatsManagerInternal;
import android.appwidget.AppWidgetProviderInfo;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentProvider;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -1927,11 +1928,32 @@ public class ShortcutService extends IShortcutService.Stub {
        }
        if (shortcut.getIcon() != null) {
            ShortcutInfo.validateIcon(shortcut.getIcon());
            validateIconURI(shortcut);
        }

        shortcut.replaceFlags(shortcut.getFlags() & ShortcutInfo.FLAG_LONG_LIVED);
    }

    // Validates the calling process has permission to access shortcut icon's image uri
    private void validateIconURI(@NonNull final ShortcutInfo si) {
        final int callingUid = injectBinderCallingUid();
        final Icon icon = si.getIcon();
        if (icon == null) {
            // There's no icon in this shortcut, nothing to validate here.
            return;
        }
        int iconType = icon.getType();
        if (iconType != Icon.TYPE_URI && iconType != Icon.TYPE_URI_ADAPTIVE_BITMAP) {
            // The icon is not URI-based, nothing to validate.
            return;
        }
        final Uri uri = icon.getUri();
        mUriGrantsManagerInternal.checkGrantUriPermission(callingUid, si.getPackage(),
                ContentProvider.getUriWithoutUserId(uri),
                Intent.FLAG_GRANT_READ_URI_PERMISSION,
                ContentProvider.getUserIdFromUri(uri, UserHandle.getUserId(callingUid)));
    }

    private void fixUpIncomingShortcutInfo(@NonNull ShortcutInfo shortcut, boolean forUpdate) {
        fixUpIncomingShortcutInfo(shortcut, forUpdate, /*forPinRequest=*/ false);
    }