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

Commit f10903e6 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Removing static reference of deep shortcut manager" into ub-launcher3-master

parents 1ff53859 fa395365
Loading
Loading
Loading
Loading
+0 −119
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.launcher3.shortcuts;

import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ShortcutInfo;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.UserHandle;

import com.android.launcher3.ItemInfo;
import com.android.launcher3.notification.NotificationKeyData;

import java.util.ArrayList;
import java.util.List;

/**
 * Performs operations related to deep shortcuts, such as querying for them, pinning them, etc.
 */
public class DeepShortcutManager {

    private static final DeepShortcutManager sInstance = new DeepShortcutManager();

    public static DeepShortcutManager getInstance(Context context) {
        return sInstance;
    }

    private final QueryResult mFailure = new QueryResult();

    private DeepShortcutManager() { }

    /**
     * Queries for the shortcuts with the package name and provided ids.
     *
     * This method is intended to get the full details for shortcuts when they are added or updated,
     * because we only get "key" fields in onShortcutsChanged().
     */
    public QueryResult queryForFullDetails(String packageName,
            List<String> shortcutIds, UserHandle user) {
        return mFailure;
    }

    /**
     * Gets all the manifest and dynamic shortcuts associated with the given package and user,
     * to be displayed in the shortcuts container on long press.
     */
    public QueryResult queryForShortcutsContainer(ComponentName activity,
            UserHandle user) {
        return mFailure;
    }

    /**
     * Removes the given shortcut from the current list of pinned shortcuts.
     * (Runs on background thread)
     */
    public void unpinShortcut(final ShortcutKey key) {
    }

    /**
     * Adds the given shortcut to the current list of pinned shortcuts.
     * (Runs on background thread)
     */
    public void pinShortcut(final ShortcutKey key) {
    }

    public void startShortcut(String packageName, String id, Rect sourceBounds,
            Bundle startActivityOptions, UserHandle user) {
    }

    public Drawable getShortcutIconDrawable(ShortcutInfo shortcutInfo, int density) {
        return null;
    }

    /**
     * Returns the id's of pinned shortcuts associated with the given package and user.
     *
     * If packageName is null, returns all pinned shortcuts regardless of package.
     */
    public QueryResult queryForPinnedShortcuts(String packageName, UserHandle user) {
        return mFailure;
    }

    public QueryResult queryForPinnedShortcuts(String packageName,
            List<String> shortcutIds, UserHandle user) {
        return mFailure;
    }

    public QueryResult queryForAllShortcuts(UserHandle user) {
        return mFailure;
    }

    public boolean hasHostPermission() {
        return false;
    }


    public static class QueryResult extends ArrayList<ShortcutInfo> {

        public boolean wasSuccess() {
            return true;
        }
    }
}
+2 −6
Original line number Diff line number Diff line
@@ -44,8 +44,8 @@ import com.android.launcher3.WorkspaceItemInfo;
import com.android.launcher3.allapps.AllAppsStore;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.icons.LauncherIcons;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.shortcuts.ShortcutKey;
import com.android.launcher3.shortcuts.ShortcutRequest;
import com.android.launcher3.util.InstantAppResolver;

import java.util.ArrayList;
@@ -167,11 +167,7 @@ public class DynamicItemCache {

    @WorkerThread
    private WorkspaceItemInfo loadShortcutWorker(ShortcutKey shortcutKey) {
        DeepShortcutManager mgr = DeepShortcutManager.getInstance(mContext);
        List<ShortcutInfo> details = mgr.queryForFullDetails(
                shortcutKey.componentName.getPackageName(),
                Collections.<String>singletonList(shortcutKey.getId()),
                shortcutKey.user);
        List<ShortcutInfo> details = shortcutKey.buildRequest(mContext).query(ShortcutRequest.ALL);
        if (!details.isEmpty()) {
            WorkspaceItemInfo si = new WorkspaceItemInfo(details.get(0), mContext);
            try (LauncherIcons li = LauncherIcons.obtain(mContext)) {
+24 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.launcher3;

import static com.android.launcher3.model.WidgetsModel.GO_DISABLE_WIDGETS;
import static com.android.launcher3.util.SystemUiController.UI_STATE_OVERVIEW;

import static java.lang.annotation.RetentionPolicy.SOURCE;
@@ -24,7 +25,12 @@ import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.pm.LauncherApps;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.UserHandle;
import android.util.Log;
import android.view.ContextThemeWrapper;

import androidx.annotation.IntDef;
@@ -47,6 +53,8 @@ import java.util.ArrayList;
public abstract class BaseActivity extends Activity
        implements UserEventDelegate, LogStateProvider, ActivityContext {

    private static final String TAG = "BaseActivity";

    public static final int INVISIBLE_BY_STATE_HANDLER = 1 << 0;
    public static final int INVISIBLE_BY_APP_TRANSITIONS = 1 << 1;
    public static final int INVISIBLE_BY_PENDING_FLAGS = 1 << 2;
@@ -312,6 +320,22 @@ public abstract class BaseActivity extends Activity
        writer.println(prefix + "mForceInvisible: " + mForceInvisible);
    }

    /**
     * A wrapper around the platform method with Launcher specific checks
     */
    public void startShortcut(String packageName, String id, Rect sourceBounds,
            Bundle startActivityOptions, UserHandle user) {
        if (GO_DISABLE_WIDGETS) {
            return;
        }
        try {
            getSystemService(LauncherApps.class).startShortcut(packageName, id, sourceBounds,
                    startActivityOptions, user);
        } catch (SecurityException | IllegalStateException e) {
            Log.e(TAG, "Failed to start shortcut", e);
        }
    }

    public static <T extends BaseActivity> T fromContext(Context context) {
        if (context instanceof BaseActivity) {
            return (T) context;
+1 −3
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ import androidx.annotation.Nullable;

import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.model.AppLaunchTracker;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.uioverrides.DisplayRotationListener;
import com.android.launcher3.uioverrides.WallpaperColorInfo;
import com.android.launcher3.util.PackageManagerHelper;
@@ -198,8 +197,7 @@ public abstract class BaseDraggingActivity extends BaseActivity
                if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
                    String id = ((WorkspaceItemInfo) info).getDeepShortcutId();
                    String packageName = intent.getPackage();
                    DeepShortcutManager.getInstance(this).startShortcut(
                            packageName, id, intent.getSourceBounds(), optsBundle, info.user);
                    startShortcut(packageName, id, intent.getSourceBounds(), optsBundle, info.user);
                    AppLaunchTracker.INSTANCE.get(this).onStartShortcut(packageName, id, info.user,
                            sourceContainer);
                } else {
+4 −7
Original line number Diff line number Diff line
@@ -49,8 +49,8 @@ import com.android.launcher3.icons.BitmapInfo;
import com.android.launcher3.icons.GraphicsUtils;
import com.android.launcher3.icons.LauncherIcons;
import com.android.launcher3.pm.UserCache;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.shortcuts.ShortcutKey;
import com.android.launcher3.shortcuts.ShortcutRequest;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.Preconditions;
import com.android.launcher3.util.Thunk;
@@ -538,12 +538,9 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
                    return new PendingInstallShortcutInfo(info, context);
                }
            } else if (decoder.optBoolean(DEEPSHORTCUT_TYPE_KEY)) {
                DeepShortcutManager sm = DeepShortcutManager.getInstance(context);
                List<ShortcutInfo> si = sm.queryForFullDetails(
                        decoder.launcherIntent.getPackage(),
                        Arrays.asList(decoder.launcherIntent.getStringExtra(
                                ShortcutKey.EXTRA_SHORTCUT_ID)),
                        decoder.user);
                List<ShortcutInfo> si = ShortcutKey.fromIntent(decoder.launcherIntent, decoder.user)
                        .buildRequest(context)
                        .query(ShortcutRequest.ALL);
                if (si.isEmpty()) {
                    return null;
                } else {
Loading