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

Commit dbb28b2b authored by Sunny Goyal's avatar Sunny Goyal Committed by Android (Google) Code Review
Browse files

Merge "Adding support for new APIs in O related to configurable shortcuts" into ub-launcher3-master

parents a2441e88 782f0c9a
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -189,6 +189,10 @@ public class IconCache {
        return getFullResDefaultActivityIcon();
    }

    public Drawable getFullResIcon(LauncherActivityInfo info) {
        return mIconProvider.getIcon(info, mIconDpi);
    }

    protected Bitmap makeDefaultIcon(UserHandle user) {
        Drawable unbadged = getFullResDefaultActivityIcon();
        return LauncherIcons.createBadgedIconBitmap(unbadged, user, mContext);
@@ -376,8 +380,7 @@ public class IconCache {
        }
        if (entry == null) {
            entry = new CacheEntry();
            entry.icon = LauncherIcons.createBadgedIconBitmap(
                    mIconProvider.getIcon(app, mIconDpi), app.getUser(),
            entry.icon = LauncherIcons.createBadgedIconBitmap(getFullResIcon(app), app.getUser(),
                    mContext);
        }
        entry.title = app.getLabel();
@@ -535,8 +538,7 @@ public class IconCache {

                if (info != null) {
                    entry.icon = LauncherIcons.createBadgedIconBitmap(
                            mIconProvider.getIcon(info, mIconDpi), info.getUser(),
                            mContext);
                            getFullResIcon(info), info.getUser(), mContext);
                } else {
                    if (usePackageIcon) {
                        CacheEntry packageEntry = getEntryForPackageLocked(
+40 −11
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ import com.android.launcher3.allapps.DefaultAppSearchController;
import com.android.launcher3.anim.AnimationLayerSet;
import com.android.launcher3.compat.AppWidgetManagerCompat;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.PinItemRequestCompat;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.config.ProviderConfig;
@@ -96,6 +97,7 @@ import com.android.launcher3.dragndrop.DragView;
import com.android.launcher3.dynamicui.ExtractedColors;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.graphics.LauncherIcons;
import com.android.launcher3.keyboard.CustomActionsPopup;
import com.android.launcher3.keyboard.ViewGroupFocusHelper;
import com.android.launcher3.logging.FileLog;
@@ -105,6 +107,7 @@ import com.android.launcher3.model.WidgetItem;
import com.android.launcher3.pageindicators.PageIndicator;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.shortcuts.DeepShortcutsContainer;
import com.android.launcher3.shortcuts.ShortcutInfoCompat;
import com.android.launcher3.shortcuts.ShortcutKey;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
@@ -118,6 +121,7 @@ import com.android.launcher3.util.PendingRequestArgs;
import com.android.launcher3.util.TestingUtils;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.util.ViewOnDrawExecutor;
import com.android.launcher3.widget.PendingAddShortcutInfo;
import com.android.launcher3.widget.PendingAddWidgetInfo;
import com.android.launcher3.widget.WidgetHostViewLoader;
import com.android.launcher3.widget.WidgetsContainerView;
@@ -1430,19 +1434,42 @@ public class Launcher extends BaseActivity
        int[] cellXY = mTmpAddItemCellCoordinates;
        CellLayout layout = getCellLayout(container, screenId);

        ShortcutInfo info = InstallShortcutReceiver.fromShortcutIntent(this, data);
        if (info == null || args.getRequestCode() != REQUEST_CREATE_SHORTCUT ||
        if (args.getRequestCode() != REQUEST_CREATE_SHORTCUT ||
                args.getPendingIntent().getComponent() == null) {
            return;
        }
        if (!PackageManagerHelper.hasPermissionForActivity(

        ShortcutInfo info = null;
        if (Utilities.isAtLeastO()) {
            PinItemRequestCompat request = PinItemRequestCompat.getPinItemRequest(data);
            // request.accept will initiate a shortcutChanged callback. To ensure that the model is
            // consistent, that callback must be processed by the model, after the ShortcutInfo is
            // added to the model. This is guaranteed here the callback comes on the UI thread, and
            // we will add the shortcut on the UI thread as well.
            if (request != null &&
                    request.getRequestType() == PinItemRequestCompat.REQUEST_TYPE_SHORTCUT &&
                    request.isValid() && request.accept()) {
                ShortcutInfoCompat compat = new ShortcutInfoCompat(request.getShortcutInfo());
                info = new ShortcutInfo(compat, this);
                // Apply the unbadged icon and fetch the actual icon asynchronously.
                info.iconBitmap = LauncherIcons
                        .createShortcutIcon(compat, this, false /* badged */);
                getModel().updateAndBindShortcutInfo(info, compat);
            }
        }

        if (info == null) {
            info = InstallShortcutReceiver.fromShortcutIntent(this, data);

            if (info == null || !PackageManagerHelper.hasPermissionForActivity(
                    this, info.intent, args.getPendingIntent().getComponent().getPackageName())) {
                // The app is trying to add a shortcut without sufficient permissions
                Log.e(TAG, "Ignoring malicious intent " + info.intent.toUri(0));
                return;
            }
        final View view = createShortcut(info);
        }

        final View view = createShortcut(info);
        boolean foundCellSpan = false;
        // First we check if we already know the exact location where we want to add this item.
        if (cellX >= 0 && cellY >= 0) {
@@ -2025,7 +2052,7 @@ public class Launcher extends BaseActivity
                addAppWidgetFromDrop((PendingAddWidgetInfo) info);
                break;
            case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
                processShortcutFromDrop(info);
                processShortcutFromDrop((PendingAddShortcutInfo) info);
                break;
            default:
                throw new IllegalStateException("Unknown item type: " + info.itemType);
@@ -2035,10 +2062,12 @@ public class Launcher extends BaseActivity
    /**
     * Process a shortcut drop.
     */
    private void processShortcutFromDrop(PendingAddItemInfo info) {
    private void processShortcutFromDrop(PendingAddShortcutInfo info) {
        Intent intent = new Intent(Intent.ACTION_CREATE_SHORTCUT).setComponent(info.componentName);
        setWaitingForResult(PendingRequestArgs.forIntent(REQUEST_CREATE_SHORTCUT, intent, info));
        Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
        if (!info.activityInfo.startConfigActivity(this, REQUEST_CREATE_SHORTCUT)) {
            handleActivityResult(REQUEST_CREATE_SHORTCUT, RESULT_CANCELED, null);
        }
    }

    /**
+0 −17
Original line number Diff line number Diff line
@@ -16,9 +16,7 @@

package com.android.launcher3;

import android.app.Activity;
import android.app.WallpaperManager;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -53,7 +51,6 @@ import android.util.TypedValue;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.widget.Toast;

import com.android.launcher3.config.ProviderConfig;

@@ -262,20 +259,6 @@ public final class Utilities {
        return scale;
    }

    public static void startActivityForResultSafely(
            Activity activity, Intent intent, int requestCode) {
        try {
            activity.startActivityForResult(intent, requestCode);
        } catch (ActivityNotFoundException e) {
            Toast.makeText(activity, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
        } catch (SecurityException e) {
            Toast.makeText(activity, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
            Log.e(TAG, "Launcher does not have the permission to launch " + intent +
                    ". Make sure to create a MAIN intent-filter for the corresponding activity " +
                    "or use the exported attribute for this activity.", e);
        }
    }

    static boolean isSystemApp(Context context, Intent intent) {
        PackageManager pm = context.getPackageManager();
        ComponentName cn = intent.getComponent();
+4 −4
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@ package com.android.launcher3;
import android.content.ComponentName;
import android.content.ContentValues;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
@@ -30,6 +29,7 @@ import android.util.Log;
import android.util.LongSparseArray;

import com.android.launcher3.compat.AppWidgetManagerCompat;
import com.android.launcher3.compat.ShortcutConfigActivityInfo;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.model.WidgetItem;
import com.android.launcher3.util.ComponentKey;
@@ -415,8 +415,8 @@ public class WidgetPreviewLoader {
        return preview;
    }

    private Bitmap generateShortcutPreview(
            BaseActivity launcher, ActivityInfo info, int maxWidth, int maxHeight, Bitmap preview) {
    private Bitmap generateShortcutPreview(BaseActivity launcher, ShortcutConfigActivityInfo info,
            int maxWidth, int maxHeight, Bitmap preview) {
        final Canvas c = new Canvas();
        if (preview == null) {
            preview = Bitmap.createBitmap(maxWidth, maxHeight, Config.ARGB_8888);
@@ -429,7 +429,7 @@ public class WidgetPreviewLoader {
            c.drawColor(0, PorterDuff.Mode.CLEAR);
        }

        Drawable icon = mutateOnMainThread(mIconCache.getFullResIcon(info));
        Drawable icon = mutateOnMainThread(info.getFullResIcon(mIconCache));
        icon.setFilterBitmap(true);

        // Draw a desaturated/scaled version of the icon in the background as a watermark
+7 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.graphics.Rect;
import android.os.Bundle;
import android.os.UserHandle;

import com.android.launcher3.Utilities;
import com.android.launcher3.shortcuts.ShortcutInfoCompat;

import java.util.List;
@@ -51,8 +52,12 @@ public abstract class LauncherAppsCompat {
    public static LauncherAppsCompat getInstance(Context context) {
        synchronized (sInstanceLock) {
            if (sInstance == null) {
                if (Utilities.isAtLeastO()) {
                    sInstance = new LauncherAppsCompatVO(context.getApplicationContext());
                } else {
                    sInstance = new LauncherAppsCompatVL(context.getApplicationContext());
                }
            }
            return sInstance;
        }
    }
@@ -69,4 +74,5 @@ public abstract class LauncherAppsCompat {
    public abstract boolean isPackageEnabledForProfile(String packageName, UserHandle user);
    public abstract boolean isActivityEnabledForProfile(ComponentName component,
            UserHandle user);
    public abstract List<ShortcutConfigActivityInfo> getCustomShortcutActivityList();
}
Loading