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

Commit 7606a412 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Verifying the install shortcut intent before casting the extras to various object types

Bug: 26043109
Change-Id: I95f127d62a6a508a850e11d6728afc7509fb07d1
parent 39b700fc
Loading
Loading
Loading
Loading
+28 −12
Original line number Diff line number Diff line
@@ -144,29 +144,45 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
        if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
            return;
        }
        PendingInstallShortcutInfo info = createPendingInfo(context, data);
        if (info != null) {
            queuePendingShortcutInfo(info, context);
        }
    }

        PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, context);
        if (info.launchIntent == null || info.label == null) {
            if (DBG) Log.e(TAG, "Invalid install shortcut intent");
            return;
    /**
     * @return true is the extra is either null or is of type {@param type}
     */
    private static boolean isValidExtraType(Intent intent, String key, Class type) {
        Object extra = intent.getParcelableExtra(key);
        return extra == null || type.isInstance(extra);
    }

        info = convertToLauncherActivityIfPossible(info);
        queuePendingShortcutInfo(info, context);
    /**
     * Verifies the intent and creates a {@link PendingInstallShortcutInfo}
     */
    private static PendingInstallShortcutInfo createPendingInfo(Context context, Intent data) {
        if (!isValidExtraType(data, Intent.EXTRA_SHORTCUT_INTENT, Intent.class) ||
                !(isValidExtraType(data, Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                        Intent.ShortcutIconResource.class)) ||
                !(isValidExtraType(data, Intent.EXTRA_SHORTCUT_ICON, Bitmap.class))) {

            if (DBG) Log.e(TAG, "Invalid install shortcut intent");
            return null;
        }

    public static ShortcutInfo fromShortcutIntent(Context context, Intent data) {
        PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, context);
        if (info.launchIntent == null || info.label == null) {
            if (DBG) Log.e(TAG, "Invalid install shortcut intent");
            return null;
        }
        info = convertToLauncherActivityIfPossible(info);
        return info.getShortcutInfo();

        return convertToLauncherActivityIfPossible(info);
    }

    static void queueInstallShortcut(LauncherActivityInfoCompat info, Context context) {
        queuePendingShortcutInfo(new PendingInstallShortcutInfo(info, context), context);
    public static ShortcutInfo fromShortcutIntent(Context context, Intent data) {
        PendingInstallShortcutInfo info = createPendingInfo(context, data);
        return info == null ? null : info.getShortcutInfo();
    }

    private static void queuePendingShortcutInfo(PendingInstallShortcutInfo info, Context context) {