Search in sources :

Example 46 with LauncherAppState

use of com.android.launcher3.LauncherAppState in project android_packages_apps_Launcher3 by ProtonAOSP.

the class ShortcutsChangedTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
    final Context context = app.getContext();
    // Find WorkspaceItemInfo's that have changed on the workspace.
    ArrayList<WorkspaceItemInfo> matchingWorkspaceItems = new ArrayList<>();
    synchronized (dataModel) {
        dataModel.forAllWorkspaceItemInfos(mUser, si -> {
            if ((si.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) && mPackageName.equals(si.getIntent().getPackage())) {
                matchingWorkspaceItems.add(si);
            }
        });
    }
    if (!matchingWorkspaceItems.isEmpty()) {
        if (mShortcuts.isEmpty()) {
            // Verify that the app is indeed installed.
            if (!new PackageManagerHelper(app.getContext()).isAppInstalled(mPackageName, mUser)) {
                // App is not installed, ignoring package events
                return;
            }
        }
        // Update the workspace to reflect the changes to updated shortcuts residing on it.
        List<String> allLauncherKnownIds = matchingWorkspaceItems.stream().map(WorkspaceItemInfo::getDeepShortcutId).distinct().collect(Collectors.toList());
        List<ShortcutInfo> shortcuts = new ShortcutRequest(context, mUser).forPackage(mPackageName, allLauncherKnownIds).query(ShortcutRequest.ALL);
        Set<String> nonPinnedIds = new HashSet<>(allLauncherKnownIds);
        ArrayList<WorkspaceItemInfo> updatedWorkspaceItemInfos = new ArrayList<>();
        for (ShortcutInfo fullDetails : shortcuts) {
            if (!fullDetails.isPinned()) {
                continue;
            }
            String sid = fullDetails.getId();
            nonPinnedIds.remove(sid);
            matchingWorkspaceItems.stream().filter(itemInfo -> sid.equals(itemInfo.getDeepShortcutId())).forEach(workspaceItemInfo -> {
                workspaceItemInfo.updateFromDeepShortcutInfo(fullDetails, context);
                app.getIconCache().getShortcutIcon(workspaceItemInfo, fullDetails);
                updatedWorkspaceItemInfos.add(workspaceItemInfo);
            });
        }
        bindUpdatedWorkspaceItems(updatedWorkspaceItemInfos);
        if (!nonPinnedIds.isEmpty()) {
            deleteAndBindComponentsRemoved(ItemInfoMatcher.ofShortcutKeys(nonPinnedIds.stream().map(id -> new ShortcutKey(mPackageName, mUser, id)).collect(Collectors.toSet())));
        }
    }
    if (mUpdateIdMap) {
        // Update the deep shortcut map if the list of ids has changed for an activity.
        dataModel.updateDeepShortcutCounts(mPackageName, mUser, mShortcuts);
        bindDeepShortcuts(dataModel);
    }
}
Also used : Context(android.content.Context) Context(android.content.Context) ShortcutInfo(android.content.pm.ShortcutInfo) LauncherAppState(com.android.launcher3.LauncherAppState) Set(java.util.Set) LauncherSettings(com.android.launcher3.LauncherSettings) Collectors(java.util.stream.Collectors) ShortcutKey(com.android.launcher3.shortcuts.ShortcutKey) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) UserHandle(android.os.UserHandle) ShortcutRequest(com.android.launcher3.shortcuts.ShortcutRequest) ItemInfoMatcher(com.android.launcher3.util.ItemInfoMatcher) PackageManagerHelper(com.android.launcher3.util.PackageManagerHelper) ShortcutInfo(android.content.pm.ShortcutInfo) ArrayList(java.util.ArrayList) ShortcutRequest(com.android.launcher3.shortcuts.ShortcutRequest) ShortcutKey(com.android.launcher3.shortcuts.ShortcutKey) PackageManagerHelper(com.android.launcher3.util.PackageManagerHelper) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) HashSet(java.util.HashSet)

Example 47 with LauncherAppState

use of com.android.launcher3.LauncherAppState in project android_packages_apps_Launcher3 by ProtonAOSP.

the class UserLockStateChangedTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
    Context context = app.getContext();
    HashMap<ShortcutKey, ShortcutInfo> pinnedShortcuts = new HashMap<>();
    if (mIsUserUnlocked) {
        QueryResult shortcuts = new ShortcutRequest(context, mUser).query(ShortcutRequest.PINNED);
        if (shortcuts.wasSuccess()) {
            for (ShortcutInfo shortcut : shortcuts) {
                pinnedShortcuts.put(ShortcutKey.fromInfo(shortcut), shortcut);
            }
        } else {
            // Shortcut manager can fail due to some race condition when the lock state
            // changes too frequently. For the purpose of the update,
            // consider it as still locked.
            mIsUserUnlocked = false;
        }
    }
    // Update the workspace to reflect the changes to updated shortcuts residing on it.
    ArrayList<WorkspaceItemInfo> updatedWorkspaceItemInfos = new ArrayList<>();
    HashSet<ShortcutKey> removedKeys = new HashSet<>();
    synchronized (dataModel) {
        dataModel.forAllWorkspaceItemInfos(mUser, si -> {
            if (si.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
                if (mIsUserUnlocked) {
                    ShortcutKey key = ShortcutKey.fromItemInfo(si);
                    ShortcutInfo shortcut = pinnedShortcuts.get(key);
                    // (probably due to clear data), delete the workspace item as well
                    if (shortcut == null) {
                        removedKeys.add(key);
                        return;
                    }
                    si.runtimeStatusFlags &= ~FLAG_DISABLED_LOCKED_USER;
                    si.updateFromDeepShortcutInfo(shortcut, context);
                    app.getIconCache().getShortcutIcon(si, shortcut);
                } else {
                    si.runtimeStatusFlags |= FLAG_DISABLED_LOCKED_USER;
                }
                updatedWorkspaceItemInfos.add(si);
            }
        });
    }
    bindUpdatedWorkspaceItems(updatedWorkspaceItemInfos);
    if (!removedKeys.isEmpty()) {
        deleteAndBindComponentsRemoved(ItemInfoMatcher.ofShortcutKeys(removedKeys));
    }
    // Remove shortcut id map for that user
    Iterator<ComponentKey> keysIter = dataModel.deepShortcutMap.keySet().iterator();
    while (keysIter.hasNext()) {
        if (keysIter.next().user.equals(mUser)) {
            keysIter.remove();
        }
    }
    if (mIsUserUnlocked) {
        dataModel.updateDeepShortcutCounts(null, mUser, new ShortcutRequest(context, mUser).query(ShortcutRequest.ALL));
    }
    bindDeepShortcuts(dataModel);
}
Also used : Context(android.content.Context) ShortcutInfo(android.content.pm.ShortcutInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ComponentKey(com.android.launcher3.util.ComponentKey) ShortcutKey(com.android.launcher3.shortcuts.ShortcutKey) ShortcutRequest(com.android.launcher3.shortcuts.ShortcutRequest) QueryResult(com.android.launcher3.shortcuts.ShortcutRequest.QueryResult) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) HashSet(java.util.HashSet)

Example 48 with LauncherAppState

use of com.android.launcher3.LauncherAppState in project android_packages_apps_Launcher3 by ProtonAOSP.

the class WidgetsModel method setWidgetsAndShortcuts.

private synchronized void setWidgetsAndShortcuts(ArrayList<WidgetItem> rawWidgetsShortcuts, LauncherAppState app, @Nullable PackageUserKey packageUser) {
    if (DEBUG) {
        Log.d(TAG, "addWidgetsAndShortcuts, widgetsShortcuts#=" + rawWidgetsShortcuts.size());
    }
    // Temporary cache for {@link PackageItemInfos} to avoid having to go through
    // {@link mPackageItemInfos} to locate the key to be used for {@link #mWidgetsList}
    PackageItemInfoCache packageItemInfoCache = new PackageItemInfoCache();
    if (packageUser == null) {
        // Clear the list if this is an update on all widgets and shortcuts.
        mWidgetsList.clear();
    } else {
        // Otherwise, only clear the widgets and shortcuts for the changed package.
        mWidgetsList.remove(packageItemInfoCache.getOrCreate(packageUser));
    }
    // add and update.
    mWidgetsList.putAll(rawWidgetsShortcuts.stream().filter(new WidgetValidityCheck(app)).flatMap(widgetItem -> getPackageUserKeys(app.getContext(), widgetItem).stream().map(key -> new Pair<>(packageItemInfoCache.getOrCreate(key), widgetItem))).collect(groupingBy(pair -> pair.first, mapping(pair -> pair.second, toList()))));
    // Update each package entry
    IconCache iconCache = app.getIconCache();
    for (PackageItemInfo p : packageItemInfoCache.values()) {
        iconCache.getTitleAndIconForApp(p, true);
    }
}
Also used : Context(android.content.Context) Arrays(java.util.Arrays) NO_CATEGORY(com.android.launcher3.widget.WidgetSections.NO_CATEGORY) PackageManager(android.content.pm.PackageManager) AppFilter(com.android.launcher3.AppFilter) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Pair(android.util.Pair) Preconditions(com.android.launcher3.util.Preconditions) HashMap(java.util.HashMap) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) IconCache(com.android.launcher3.icons.IconCache) PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) ArrayList(java.util.ArrayList) Collectors.mapping(java.util.stream.Collectors.mapping) UserHandle(android.os.UserHandle) Map(java.util.Map) Log(android.util.Log) ArrayMap(androidx.collection.ArrayMap) ShortcutConfigActivityInfo.queryList(com.android.launcher3.pm.ShortcutConfigActivityInfo.queryList) Utilities(com.android.launcher3.Utilities) WidgetsDiffReporter(com.android.launcher3.widget.picker.WidgetsDiffReporter) Iterator(java.util.Iterator) WidgetsListHeaderEntry(com.android.launcher3.widget.model.WidgetsListHeaderEntry) ComponentName(android.content.ComponentName) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) Predicate(java.util.function.Predicate) LauncherAppState(com.android.launcher3.LauncherAppState) Collection(java.util.Collection) PackageUserKey(com.android.launcher3.util.PackageUserKey) WIDGET_FEATURE_HIDE_FROM_PICKER(android.appwidget.AppWidgetProviderInfo.WIDGET_FEATURE_HIDE_FROM_PICKER) Set(java.util.Set) FeatureFlags(com.android.launcher3.config.FeatureFlags) WidgetManagerHelper(com.android.launcher3.widget.WidgetManagerHelper) AlphabeticIndexCompat(com.android.launcher3.compat.AlphabeticIndexCompat) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) IntSet(com.android.launcher3.util.IntSet) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Nullable(androidx.annotation.Nullable) WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) ShortcutConfigActivityInfo(com.android.launcher3.pm.ShortcutConfigActivityInfo) LauncherAppWidgetProviderInfo(com.android.launcher3.widget.LauncherAppWidgetProviderInfo) ComponentWithLabelAndIcon(com.android.launcher3.icons.ComponentWithLabelAndIcon) WidgetSections(com.android.launcher3.widget.WidgetSections) Entry(java.util.Map.Entry) IconCache(com.android.launcher3.icons.IconCache) PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) Pair(android.util.Pair)

Example 49 with LauncherAppState

use of com.android.launcher3.LauncherAppState in project android_packages_apps_Launcher3 by ProtonAOSP.

the class WidgetsModel method update.

/**
 * @param packageUser If null, all widgets and shortcuts are updated and returned, otherwise
 *                    only widgets and shortcuts associated with the package/user are.
 */
public List<ComponentWithLabelAndIcon> update(LauncherAppState app, @Nullable PackageUserKey packageUser) {
    Preconditions.assertWorkerThread();
    Context context = app.getContext();
    final ArrayList<WidgetItem> widgetsAndShortcuts = new ArrayList<>();
    List<ComponentWithLabelAndIcon> updatedItems = new ArrayList<>();
    try {
        InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
        PackageManager pm = app.getContext().getPackageManager();
        // Widgets
        WidgetManagerHelper widgetManager = new WidgetManagerHelper(context);
        for (AppWidgetProviderInfo widgetInfo : widgetManager.getAllProviders(packageUser)) {
            LauncherAppWidgetProviderInfo launcherWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(context, widgetInfo);
            widgetsAndShortcuts.add(new WidgetItem(launcherWidgetInfo, idp, app.getIconCache()));
            updatedItems.add(launcherWidgetInfo);
        }
        // Shortcuts
        for (ShortcutConfigActivityInfo info : queryList(context, packageUser)) {
            widgetsAndShortcuts.add(new WidgetItem(info, app.getIconCache(), pm));
            updatedItems.add(info);
        }
        setWidgetsAndShortcuts(widgetsAndShortcuts, app, packageUser);
    } catch (Exception e) {
        if (!FeatureFlags.IS_STUDIO_BUILD && Utilities.isBinderSizeError(e)) {
        // the returned value may be incomplete and will not be refreshed until the next
        // time Launcher starts.
        // TODO: after figuring out a repro step, introduce a dirty bit to check when
        // onResume is called to refresh the widget provider list.
        } else {
            throw e;
        }
    }
    return updatedItems;
}
Also used : Context(android.content.Context) LauncherAppWidgetProviderInfo(com.android.launcher3.widget.LauncherAppWidgetProviderInfo) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) ArrayList(java.util.ArrayList) PackageManager(android.content.pm.PackageManager) ComponentWithLabelAndIcon(com.android.launcher3.icons.ComponentWithLabelAndIcon) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) LauncherAppWidgetProviderInfo(com.android.launcher3.widget.LauncherAppWidgetProviderInfo) ShortcutConfigActivityInfo(com.android.launcher3.pm.ShortcutConfigActivityInfo) WidgetManagerHelper(com.android.launcher3.widget.WidgetManagerHelper)

Example 50 with LauncherAppState

use of com.android.launcher3.LauncherAppState in project android_packages_apps_Launcher3 by ProtonAOSP.

the class PackageInstallStateChangedTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
    if (mInstallInfo.state == PackageInstallInfo.STATUS_INSTALLED) {
        try {
            // For instant apps we do not get package-add. Use setting events to update
            // any pinned icons.
            ApplicationInfo ai = app.getContext().getPackageManager().getApplicationInfo(mInstallInfo.packageName, 0);
            if (InstantAppResolver.newInstance(app.getContext()).isInstantApp(ai)) {
                app.getModel().onPackageAdded(ai.packageName, mInstallInfo.user);
            }
        } catch (PackageManager.NameNotFoundException e) {
        // Ignore
        }
        // Ignore install success events as they are handled by Package add events.
        return;
    }
    synchronized (apps) {
        List<AppInfo> updatedAppInfos = apps.updatePromiseInstallInfo(mInstallInfo);
        if (!updatedAppInfos.isEmpty()) {
            for (AppInfo appInfo : updatedAppInfos) {
                scheduleCallbackTask(c -> c.bindIncrementalDownloadProgressUpdated(appInfo));
            }
        }
        bindApplicationsIfNeeded();
    }
    synchronized (dataModel) {
        final HashSet<ItemInfo> updates = new HashSet<>();
        dataModel.forAllWorkspaceItemInfos(mInstallInfo.user, si -> {
            if (si.hasPromiseIconUi() && mInstallInfo.packageName.equals(si.getTargetPackage())) {
                si.setProgressLevel(mInstallInfo);
                updates.add(si);
            }
        });
        for (LauncherAppWidgetInfo widget : dataModel.appWidgets) {
            if (widget.providerName.getPackageName().equals(mInstallInfo.packageName)) {
                widget.installProgress = mInstallInfo.progress;
                updates.add(widget);
            }
        }
        if (!updates.isEmpty()) {
            scheduleCallbackTask(callbacks -> callbacks.bindRestoreItemsChange(updates));
        }
    }
}
Also used : PackageManager(android.content.pm.PackageManager) ItemInfo(com.android.launcher3.model.data.ItemInfo) ApplicationInfo(android.content.pm.ApplicationInfo) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) AppInfo(com.android.launcher3.model.data.AppInfo) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)62 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)56 Context (android.content.Context)39 LauncherAppState (com.android.launcher3.LauncherAppState)38 HashSet (java.util.HashSet)37 ShortcutInfo (android.content.pm.ShortcutInfo)33 List (java.util.List)33 ComponentName (android.content.ComponentName)32 ItemInfo (com.android.launcher3.model.data.ItemInfo)30 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)24 Point (android.graphics.Point)24 LauncherApps (android.content.pm.LauncherApps)23 IconCache (com.android.launcher3.icons.IconCache)23 LauncherIcons (com.android.launcher3.icons.LauncherIcons)23 AppInfo (com.android.launcher3.model.data.AppInfo)22 PackageManager (android.content.pm.PackageManager)20 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)20 HashMap (java.util.HashMap)20 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)19 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)19