Search in sources :

Example 31 with LauncherActivityInfo

use of android.content.pm.LauncherActivityInfo in project android_packages_apps_Launcher3 by ArrowOS.

the class PredictionUpdateTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
    Context context = app.getContext();
    // TODO: remove this
    Utilities.getDevicePrefs(context).edit().putBoolean(LAST_PREDICTION_ENABLED_STATE, !mTargets.isEmpty()).apply();
    FixedContainerItems fci = mPredictorState.items;
    Set<UserHandle> usersForChangedShortcuts = new HashSet<>(fci.items.stream().filter(info -> info.itemType == ITEM_TYPE_DEEP_SHORTCUT).map(info -> info.user).collect(Collectors.toSet()));
    fci.items.clear();
    for (AppTarget target : mTargets) {
        WorkspaceItemInfo itemInfo;
        ShortcutInfo si = target.getShortcutInfo();
        if (si != null) {
            usersForChangedShortcuts.add(si.getUserHandle());
            itemInfo = new WorkspaceItemInfo(si, context);
            app.getIconCache().getShortcutIcon(itemInfo, si);
        } else {
            String className = target.getClassName();
            if (COMPONENT_CLASS_MARKER.equals(className)) {
                // TODO: Implement this
                continue;
            }
            ComponentName cn = new ComponentName(target.getPackageName(), className);
            UserHandle user = target.getUser();
            itemInfo = apps.data.stream().filter(info -> user.equals(info.user) && cn.equals(info.componentName)).map(ai -> {
                app.getIconCache().getTitleAndIcon(ai, false);
                return ai.makeWorkspaceItem();
            }).findAny().orElseGet(() -> {
                LauncherActivityInfo lai = context.getSystemService(LauncherApps.class).resolveActivity(AppInfo.makeLaunchIntent(cn), user);
                if (lai == null) {
                    return null;
                }
                AppInfo ai = new AppInfo(context, lai, user);
                app.getIconCache().getTitleAndIcon(ai, lai, false);
                return ai.makeWorkspaceItem();
            });
            if (itemInfo == null) {
                continue;
            }
        }
        itemInfo.container = fci.containerId;
        fci.items.add(itemInfo);
    }
    bindExtraContainerItems(fci);
    usersForChangedShortcuts.forEach(u -> dataModel.updateShortcutPinnedState(app.getContext(), u));
    // Save to disk
    mPredictorState.storage.write(context, fci.items);
}
Also used : Context(android.content.Context) Utilities(com.android.launcher3.Utilities) Context(android.content.Context) AppInfo(com.android.launcher3.model.data.AppInfo) ComponentName(android.content.ComponentName) ShortcutInfo(android.content.pm.ShortcutInfo) ITEM_TYPE_DEEP_SHORTCUT(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) LauncherAppState(com.android.launcher3.LauncherAppState) Set(java.util.Set) Collectors(java.util.stream.Collectors) AppTarget(android.app.prediction.AppTarget) LauncherApps(android.content.pm.LauncherApps) HashSet(java.util.HashSet) List(java.util.List) COMPONENT_CLASS_MARKER(com.android.quickstep.InstantAppResolverImpl.COMPONENT_CLASS_MARKER) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) UserHandle(android.os.UserHandle) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems) LAST_PREDICTION_ENABLED_STATE(com.android.launcher3.model.QuickstepModelDelegate.LAST_PREDICTION_ENABLED_STATE) PredictorState(com.android.launcher3.model.QuickstepModelDelegate.PredictorState) ShortcutInfo(android.content.pm.ShortcutInfo) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems) AppInfo(com.android.launcher3.model.data.AppInfo) AppTarget(android.app.prediction.AppTarget) UserHandle(android.os.UserHandle) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) ComponentName(android.content.ComponentName) HashSet(java.util.HashSet) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 32 with LauncherActivityInfo

use of android.content.pm.LauncherActivityInfo in project android_packages_apps_Launcher3 by ArrowOS.

the class ShortcutConfigActivityInfo method queryList.

public static List<ShortcutConfigActivityInfo> queryList(Context context, @Nullable PackageUserKey packageUser) {
    List<ShortcutConfigActivityInfo> result = new ArrayList<>();
    UserHandle myUser = Process.myUserHandle();
    final List<UserHandle> users;
    final String packageName;
    if (packageUser == null) {
        users = UserCache.INSTANCE.get(context).getUserProfiles();
        packageName = null;
    } else {
        users = Collections.singletonList(packageUser.mUser);
        packageName = packageUser.mPackageName;
    }
    LauncherApps launcherApps = context.getSystemService(LauncherApps.class);
    for (UserHandle user : users) {
        boolean ignoreTargetSdk = myUser.equals(user);
        for (LauncherActivityInfo activityInfo : launcherApps.getShortcutConfigActivityList(packageName, user)) {
            if (ignoreTargetSdk || activityInfo.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) {
                result.add(new ShortcutConfigActivityInfoVO(activityInfo));
            }
        }
    }
    return result;
}
Also used : UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) LauncherApps(android.content.pm.LauncherApps)

Example 33 with LauncherActivityInfo

use of android.content.pm.LauncherActivityInfo in project android_packages_apps_Launcher3 by ArrowOS.

the class AddWorkspaceItemsTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
    if (mItemList.isEmpty()) {
        return;
    }
    final ArrayList<ItemInfo> addedItemsFinal = new ArrayList<>();
    final IntArray addedWorkspaceScreensFinal = new IntArray();
    synchronized (dataModel) {
        IntArray workspaceScreens = dataModel.collectWorkspaceScreens();
        List<ItemInfo> filteredItems = new ArrayList<>();
        for (Pair<ItemInfo, Object> entry : mItemList) {
            ItemInfo item = entry.first;
            if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION || item.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) {
                // Short-circuit this logic if the icon exists somewhere on the workspace
                if (shortcutExists(dataModel, item.getIntent(), item.user)) {
                    continue;
                }
                // b/139663018 Short-circuit this logic if the icon is a system app
                if (PackageManagerHelper.isSystemApp(app.getContext(), item.getIntent())) {
                    continue;
                }
            }
            if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
                if (item instanceof AppInfo) {
                    item = ((AppInfo) item).makeWorkspaceItem();
                }
            }
            if (item != null) {
                filteredItems.add(item);
            }
        }
        InstallSessionHelper packageInstaller = InstallSessionHelper.INSTANCE.get(app.getContext());
        LauncherApps launcherApps = app.getContext().getSystemService(LauncherApps.class);
        for (ItemInfo item : filteredItems) {
            // Find appropriate space for the item.
            int[] coords = findSpaceForItem(app, dataModel, workspaceScreens, addedWorkspaceScreensFinal, item.spanX, item.spanY);
            int screenId = coords[0];
            ItemInfo itemInfo;
            if (item instanceof WorkspaceItemInfo || item instanceof FolderInfo || item instanceof LauncherAppWidgetInfo) {
                itemInfo = item;
            } else if (item instanceof AppInfo) {
                itemInfo = ((AppInfo) item).makeWorkspaceItem();
            } else {
                throw new RuntimeException("Unexpected info type");
            }
            if (item instanceof WorkspaceItemInfo && ((WorkspaceItemInfo) item).isPromise()) {
                WorkspaceItemInfo workspaceInfo = (WorkspaceItemInfo) item;
                String packageName = item.getTargetComponent() != null ? item.getTargetComponent().getPackageName() : null;
                if (packageName == null) {
                    continue;
                }
                SessionInfo sessionInfo = packageInstaller.getActiveSessionInfo(item.user, packageName);
                if (!packageInstaller.verifySessionInfo(sessionInfo)) {
                    FileLog.d(LOG, "Item info failed session info verification. " + "Skipping : " + workspaceInfo);
                    continue;
                }
                List<LauncherActivityInfo> activities = launcherApps.getActivityList(packageName, item.user);
                boolean hasActivity = activities != null && !activities.isEmpty();
                if (sessionInfo == null) {
                    if (!hasActivity) {
                        // Session was cancelled, do not add.
                        continue;
                    }
                } else {
                    workspaceInfo.setProgressLevel((int) (sessionInfo.getProgress() * 100), PackageInstallInfo.STATUS_INSTALLING);
                }
                if (hasActivity) {
                    // App was installed while launcher was in the background,
                    // or app was already installed for another user.
                    itemInfo = new AppInfo(app.getContext(), activities.get(0), item.user).makeWorkspaceItem();
                    if (shortcutExists(dataModel, itemInfo.getIntent(), itemInfo.user)) {
                        // Icon already exists on the workspace and should not be auto-added.
                        continue;
                    }
                    WorkspaceItemInfo wii = (WorkspaceItemInfo) itemInfo;
                    wii.title = "";
                    wii.bitmap = app.getIconCache().getDefaultIcon(item.user);
                    app.getIconCache().getTitleAndIcon(wii, ((WorkspaceItemInfo) itemInfo).usingLowResIcon());
                }
            }
            // Add the shortcut to the db
            getModelWriter().addItemToDatabase(itemInfo, LauncherSettings.Favorites.CONTAINER_DESKTOP, screenId, coords[1], coords[2]);
            // Save the WorkspaceItemInfo for binding in the workspace
            addedItemsFinal.add(itemInfo);
            // log bitmap and label
            FileLog.d(LOG, "Adding item info to workspace: " + itemInfo);
        }
    }
    if (!addedItemsFinal.isEmpty()) {
        scheduleCallbackTask(new CallbackTask() {

            @Override
            public void execute(Callbacks callbacks) {
                final ArrayList<ItemInfo> addAnimated = new ArrayList<>();
                final ArrayList<ItemInfo> addNotAnimated = new ArrayList<>();
                if (!addedItemsFinal.isEmpty()) {
                    ItemInfo info = addedItemsFinal.get(addedItemsFinal.size() - 1);
                    int lastScreenId = info.screenId;
                    for (ItemInfo i : addedItemsFinal) {
                        if (i.screenId == lastScreenId) {
                            addAnimated.add(i);
                        } else {
                            addNotAnimated.add(i);
                        }
                    }
                }
                callbacks.bindAppsAdded(addedWorkspaceScreensFinal, addNotAnimated, addAnimated);
            }
        });
    }
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ArrayList(java.util.ArrayList) SessionInfo(android.content.pm.PackageInstaller.SessionInfo) IntArray(com.android.launcher3.util.IntArray) Callbacks(com.android.launcher3.model.BgDataModel.Callbacks) CallbackTask(com.android.launcher3.LauncherModel.CallbackTask) LauncherApps(android.content.pm.LauncherApps) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) FolderInfo(com.android.launcher3.model.data.FolderInfo) AppInfo(com.android.launcher3.model.data.AppInfo) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) InstallSessionHelper(com.android.launcher3.pm.InstallSessionHelper) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 34 with LauncherActivityInfo

use of android.content.pm.LauncherActivityInfo in project android_packages_apps_Launcher3 by ArrowOS.

the class LoaderTask method run.

public void run() {
    synchronized (this) {
        // Skip fast if we are already stopped.
        if (mStopped) {
            return;
        }
    }
    Object traceToken = TraceHelper.INSTANCE.beginSection(TAG);
    TimingLogger logger = new TimingLogger(TAG, "run");
    LoaderMemoryLogger memoryLogger = new LoaderMemoryLogger();
    try (LauncherModel.LoaderTransaction transaction = mApp.getModel().beginLoader(this)) {
        List<ShortcutInfo> allShortcuts = new ArrayList<>();
        Trace.beginSection("LoadWorkspace");
        try {
            loadWorkspace(allShortcuts, memoryLogger);
        } finally {
            Trace.endSection();
        }
        logASplit(logger, "loadWorkspace");
        // (e.g. both grid preview and minimal device mode uses a different db)
        if (mApp.getInvariantDeviceProfile().dbFile.equals(mDbName)) {
            verifyNotStopped();
            sanitizeData();
            logASplit(logger, "sanitizeData");
        }
        verifyNotStopped();
        mResults.bindWorkspace(true);
        logASplit(logger, "bindWorkspace");
        mModelDelegate.workspaceLoadComplete();
        // Notify the installer packages of packages with active installs on the first screen.
        sendFirstScreenActiveInstallsBroadcast();
        logASplit(logger, "sendFirstScreenActiveInstallsBroadcast");
        // Take a break
        waitForIdle();
        logASplit(logger, "step 1 complete");
        verifyNotStopped();
        // second step
        Trace.beginSection("LoadAllApps");
        List<LauncherActivityInfo> allActivityList;
        try {
            allActivityList = loadAllApps();
        } finally {
            Trace.endSection();
        }
        logASplit(logger, "loadAllApps");
        verifyNotStopped();
        mResults.bindAllApps();
        logASplit(logger, "bindAllApps");
        verifyNotStopped();
        IconCacheUpdateHandler updateHandler = mIconCache.getUpdateHandler();
        setIgnorePackages(updateHandler);
        updateHandler.updateIcons(allActivityList, LauncherActivityCachingLogic.newInstance(mApp.getContext()), mApp.getModel()::onPackageIconsUpdated);
        logASplit(logger, "update icon cache");
        if (FeatureFlags.ENABLE_DEEP_SHORTCUT_ICON_CACHE.get()) {
            verifyNotStopped();
            logASplit(logger, "save shortcuts in icon cache");
            updateHandler.updateIcons(allShortcuts, new ShortcutCachingLogic(), mApp.getModel()::onPackageIconsUpdated);
        }
        // Take a break
        waitForIdle();
        logASplit(logger, "step 2 complete");
        verifyNotStopped();
        // third step
        List<ShortcutInfo> allDeepShortcuts = loadDeepShortcuts();
        logASplit(logger, "loadDeepShortcuts");
        verifyNotStopped();
        mResults.bindDeepShortcuts();
        logASplit(logger, "bindDeepShortcuts");
        if (FeatureFlags.ENABLE_DEEP_SHORTCUT_ICON_CACHE.get()) {
            verifyNotStopped();
            logASplit(logger, "save deep shortcuts in icon cache");
            updateHandler.updateIcons(allDeepShortcuts, new ShortcutCachingLogic(), (pkgs, user) -> {
            });
        }
        // Take a break
        waitForIdle();
        logASplit(logger, "step 3 complete");
        verifyNotStopped();
        // fourth step
        List<ComponentWithLabelAndIcon> allWidgetsList = mBgDataModel.widgetsModel.update(mApp, null);
        logASplit(logger, "load widgets");
        verifyNotStopped();
        mResults.bindWidgets();
        logASplit(logger, "bindWidgets");
        verifyNotStopped();
        updateHandler.updateIcons(allWidgetsList, new ComponentWithIconCachingLogic(mApp.getContext(), true), mApp.getModel()::onWidgetLabelsUpdated);
        logASplit(logger, "save widgets in icon cache");
        // fifth step
        if (FeatureFlags.FOLDER_NAME_SUGGEST.get()) {
            loadFolderNames();
        }
        verifyNotStopped();
        updateHandler.finish();
        logASplit(logger, "finish icon update");
        mModelDelegate.modelLoadComplete();
        transaction.commit();
        memoryLogger.clearLogs();
    } catch (CancellationException e) {
        // Loader stopped, ignore
        logASplit(logger, "Cancelled");
    } catch (Exception e) {
        memoryLogger.printLogs();
        throw e;
    } finally {
        logger.dumpToLog();
    }
    TraceHelper.INSTANCE.endSection(traceToken);
}
Also used : LauncherModel(com.android.launcher3.LauncherModel) ShortcutInfo(android.content.pm.ShortcutInfo) ArrayList(java.util.ArrayList) ShortcutCachingLogic(com.android.launcher3.icons.ShortcutCachingLogic) CancellationException(java.util.concurrent.CancellationException) ComponentWithIconCachingLogic(com.android.launcher3.icons.ComponentWithLabelAndIcon.ComponentWithIconCachingLogic) TimingLogger(android.util.TimingLogger) CancellationException(java.util.concurrent.CancellationException) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) ComponentWithLabelAndIcon(com.android.launcher3.icons.ComponentWithLabelAndIcon) IconCacheUpdateHandler(com.android.launcher3.icons.cache.IconCacheUpdateHandler)

Example 35 with LauncherActivityInfo

use of android.content.pm.LauncherActivityInfo in project android_packages_apps_Launcher3 by ArrowOS.

the class AllAppsList method updatePackage.

/**
 * Add and remove icons for this package which has been updated.
 */
public List<LauncherActivityInfo> updatePackage(Context context, String packageName, UserHandle user) {
    final List<LauncherActivityInfo> matches = context.getSystemService(LauncherApps.class).getActivityList(packageName, user);
    if (matches.size() > 0) {
        // to the removed list.
        for (int i = data.size() - 1; i >= 0; i--) {
            final AppInfo applicationInfo = data.get(i);
            if (user.equals(applicationInfo.user) && packageName.equals(applicationInfo.componentName.getPackageName())) {
                if (!findActivity(matches, applicationInfo.componentName)) {
                    Log.w(TAG, "Changing shortcut target due to app component name change.");
                    removeApp(i);
                }
            }
        }
        // Also updates existing activities with new labels/icons
        for (final LauncherActivityInfo info : matches) {
            AppInfo applicationInfo = findAppInfo(info.getComponentName(), user);
            if (applicationInfo == null) {
                add(new AppInfo(context, info, user), info);
            } else {
                Intent launchIntent = AppInfo.makeLaunchIntent(info);
                mIconCache.getTitleAndIcon(applicationInfo, info, false);
                applicationInfo.sectionName = mIndex.computeSectionName(applicationInfo.title);
                applicationInfo.setProgressLevel(PackageManagerHelper.getLoadingProgress(info), PackageInstallInfo.STATUS_INSTALLED_DOWNLOADING);
                applicationInfo.intent = launchIntent;
                mDataChanged = true;
            }
        }
    } else {
        // Remove all data for this package.
        for (int i = data.size() - 1; i >= 0; i--) {
            final AppInfo applicationInfo = data.get(i);
            if (user.equals(applicationInfo.user) && packageName.equals(applicationInfo.componentName.getPackageName())) {
                mIconCache.remove(applicationInfo.componentName, user);
                removeApp(i);
            }
        }
    }
    return matches;
}
Also used : LauncherActivityInfo(android.content.pm.LauncherActivityInfo) LauncherApps(android.content.pm.LauncherApps) Intent(android.content.Intent) AppInfo(com.android.launcher3.model.data.AppInfo)

Aggregations

LauncherActivityInfo (android.content.pm.LauncherActivityInfo)134 LauncherApps (android.content.pm.LauncherApps)70 ArrayList (java.util.ArrayList)57 UserHandle (android.os.UserHandle)50 Intent (android.content.Intent)36 ComponentName (android.content.ComponentName)31 List (java.util.List)30 AppInfo (com.android.launcher3.model.data.AppInfo)28 ShortcutInfo (android.content.pm.ShortcutInfo)27 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)26 Context (android.content.Context)23 Point (android.graphics.Point)22 SessionInfo (android.content.pm.PackageInstaller.SessionInfo)19 SuppressLint (android.annotation.SuppressLint)16 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)16 PackageUserKey (com.android.launcher3.util.PackageUserKey)14 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)13 IconRequestInfo (com.android.launcher3.model.data.IconRequestInfo)12 CancellationException (java.util.concurrent.CancellationException)12 PackageInstaller (android.content.pm.PackageInstaller)11