Search in sources :

Example 31 with INSTALL

use of com.android.launcher3.popup.SystemShortcut.INSTALL in project android_packages_apps_Launcher3 by ProtonAOSP.

the class TaskbarPopupController method showForIcon.

/**
 * Shows the notifications and deep shortcuts associated with a Taskbar {@param icon}.
 * @return the container if shown or null.
 */
public PopupContainerWithArrow<TaskbarActivityContext> showForIcon(BubbleTextView icon) {
    TaskbarActivityContext context = ActivityContext.lookupContext(icon.getContext());
    if (PopupContainerWithArrow.getOpen(context) != null) {
        // There is already an items container open, so don't open this one.
        icon.clearFocus();
        return null;
    }
    ItemInfo item = (ItemInfo) icon.getTag();
    if (!PopupContainerWithArrow.canShow(icon, item)) {
        return null;
    }
    final PopupContainerWithArrow<TaskbarActivityContext> container = (PopupContainerWithArrow) context.getLayoutInflater().inflate(R.layout.popup_container, context.getDragLayer(), false);
    // TODO (b/198438631): configure for taskbar/context
    container.populateAndShow(icon, mPopupDataProvider.getShortcutCountForItem(item), mPopupDataProvider.getNotificationKeysForItem(item), // TODO (b/198438631): add support for INSTALL shortcut factory
    Stream.of(APP_INFO).map(s -> s.getShortcut(context, item)).filter(Objects::nonNull).collect(Collectors.toList()));
    container.requestFocus();
    return container;
}
Also used : PopupDataProvider(com.android.launcher3.popup.PopupDataProvider) ActivityContext(com.android.launcher3.views.ActivityContext) NonNull(androidx.annotation.NonNull) ItemInfo(com.android.launcher3.model.data.ItemInfo) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) BubbleTextView(com.android.launcher3.BubbleTextView) PopupContainerWithArrow(com.android.launcher3.popup.PopupContainerWithArrow) Objects(java.util.Objects) Stream(java.util.stream.Stream) R(com.android.launcher3.R) ComponentKey(com.android.launcher3.util.ComponentKey) SystemShortcut(com.android.launcher3.popup.SystemShortcut) ItemInfo(com.android.launcher3.model.data.ItemInfo) Objects(java.util.Objects) PopupContainerWithArrow(com.android.launcher3.popup.PopupContainerWithArrow)

Example 32 with INSTALL

use of com.android.launcher3.popup.SystemShortcut.INSTALL in project android_packages_apps_Launcher3 by ProtonAOSP.

the class SessionCommitReceiver method processIntent.

@WorkerThread
private static void processIntent(Context context, Intent intent) {
    if (!isEnabled(context)) {
        // User has decided to not add icons on homescreen.
        return;
    }
    SessionInfo info = intent.getParcelableExtra(PackageInstaller.EXTRA_SESSION);
    UserHandle user = intent.getParcelableExtra(Intent.EXTRA_USER);
    if (!PackageInstaller.ACTION_SESSION_COMMITTED.equals(intent.getAction()) || info == null || user == null) {
        // Invalid intent.
        return;
    }
    InstallSessionHelper packageInstallerCompat = InstallSessionHelper.INSTANCE.get(context);
    packageInstallerCompat.restoreDbIfApplicable(info);
    if (TextUtils.isEmpty(info.getAppPackageName()) || info.getInstallReason() != PackageManager.INSTALL_REASON_USER || packageInstallerCompat.promiseIconAddedForId(info.getSessionId())) {
        packageInstallerCompat.removePromiseIconId(info.getSessionId());
        return;
    }
    FileLog.d(LOG, "Adding package name to install queue. Package name: " + info.getAppPackageName() + ", has app icon: " + (info.getAppIcon() != null) + ", has app label: " + !TextUtils.isEmpty(info.getAppLabel()));
    ItemInstallQueue.INSTANCE.get(context).queueItem(info.getAppPackageName(), user);
}
Also used : UserHandle(android.os.UserHandle) SessionInfo(android.content.pm.PackageInstaller.SessionInfo) InstallSessionHelper(com.android.launcher3.pm.InstallSessionHelper) WorkerThread(androidx.annotation.WorkerThread)

Example 33 with INSTALL

use of com.android.launcher3.popup.SystemShortcut.INSTALL in project android_packages_apps_Launcher3 by ProtonAOSP.

the class PackageUpdatedTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList appsList) {
    final Context context = app.getContext();
    final IconCache iconCache = app.getIconCache();
    final String[] packages = mPackages;
    final int N = packages.length;
    final FlagOp flagOp;
    final HashSet<String> packageSet = new HashSet<>(Arrays.asList(packages));
    final ItemInfoMatcher matcher = mOp == OP_USER_AVAILABILITY_CHANGE ? // We want to update all packages for this user
    ItemInfoMatcher.ofUser(mUser) : ItemInfoMatcher.ofPackages(packageSet, mUser);
    final HashSet<ComponentName> removedComponents = new HashSet<>();
    final HashMap<String, List<LauncherActivityInfo>> activitiesLists = new HashMap<>();
    switch(mOp) {
        case OP_ADD:
            {
                for (int i = 0; i < N; i++) {
                    if (DEBUG)
                        Log.d(TAG, "mAllAppsList.addPackage " + packages[i]);
                    iconCache.updateIconsForPkg(packages[i], mUser);
                    if (FeatureFlags.PROMISE_APPS_IN_ALL_APPS.get()) {
                        appsList.removePackage(packages[i], mUser);
                    }
                    activitiesLists.put(packages[i], appsList.addPackage(context, packages[i], mUser));
                }
                flagOp = FlagOp.removeFlag(WorkspaceItemInfo.FLAG_DISABLED_NOT_AVAILABLE);
                break;
            }
        case OP_UPDATE:
            try (SafeCloseable t = appsList.trackRemoves(a -> removedComponents.add(a.componentName))) {
                for (int i = 0; i < N; i++) {
                    if (DEBUG)
                        Log.d(TAG, "mAllAppsList.updatePackage " + packages[i]);
                    iconCache.updateIconsForPkg(packages[i], mUser);
                    activitiesLists.put(packages[i], appsList.updatePackage(context, packages[i], mUser));
                    // The update may have changed which shortcuts/widgets are available.
                    // Refresh the widgets for the package if we have an activity running.
                    Launcher launcher = Launcher.ACTIVITY_TRACKER.getCreatedActivity();
                    if (launcher != null) {
                        launcher.refreshAndBindWidgetsForPackageUser(new PackageUserKey(packages[i], mUser));
                    }
                }
            }
            // Since package was just updated, the target must be available now.
            flagOp = FlagOp.removeFlag(WorkspaceItemInfo.FLAG_DISABLED_NOT_AVAILABLE);
            break;
        case OP_REMOVE:
            {
                for (int i = 0; i < N; i++) {
                    FileLog.d(TAG, "Removing app icon" + packages[i]);
                    iconCache.removeIconsForPkg(packages[i], mUser);
                }
            // Fall through
            }
        case OP_UNAVAILABLE:
            for (int i = 0; i < N; i++) {
                if (DEBUG)
                    Log.d(TAG, "mAllAppsList.removePackage " + packages[i]);
                appsList.removePackage(packages[i], mUser);
            }
            flagOp = FlagOp.addFlag(WorkspaceItemInfo.FLAG_DISABLED_NOT_AVAILABLE);
            break;
        case OP_SUSPEND:
        case OP_UNSUSPEND:
            flagOp = mOp == OP_SUSPEND ? FlagOp.addFlag(WorkspaceItemInfo.FLAG_DISABLED_SUSPENDED) : FlagOp.removeFlag(WorkspaceItemInfo.FLAG_DISABLED_SUSPENDED);
            if (DEBUG)
                Log.d(TAG, "mAllAppsList.(un)suspend " + N);
            appsList.updateDisabledFlags(matcher, flagOp);
            break;
        case OP_USER_AVAILABILITY_CHANGE:
            {
                UserManagerState ums = new UserManagerState();
                ums.init(UserCache.INSTANCE.get(context), context.getSystemService(UserManager.class));
                flagOp = ums.isUserQuiet(mUser) ? FlagOp.addFlag(WorkspaceItemInfo.FLAG_DISABLED_QUIET_USER) : FlagOp.removeFlag(WorkspaceItemInfo.FLAG_DISABLED_QUIET_USER);
                appsList.updateDisabledFlags(matcher, flagOp);
                // We are not synchronizing here, as int operations are atomic
                appsList.setFlags(FLAG_QUIET_MODE_ENABLED, ums.isAnyProfileQuietModeEnabled());
                break;
            }
        default:
            flagOp = FlagOp.NO_OP;
            break;
    }
    bindApplicationsIfNeeded();
    final IntSet removedShortcuts = new IntSet();
    // Shortcuts to keep even if the corresponding app was removed
    final IntSet forceKeepShortcuts = new IntSet();
    // Update shortcut infos
    if (mOp == OP_ADD || flagOp != FlagOp.NO_OP) {
        final ArrayList<WorkspaceItemInfo> updatedWorkspaceItems = new ArrayList<>();
        final ArrayList<LauncherAppWidgetInfo> widgets = new ArrayList<>();
        // For system apps, package manager send OP_UPDATE when an app is enabled.
        final boolean isNewApkAvailable = mOp == OP_ADD || mOp == OP_UPDATE;
        synchronized (dataModel) {
            dataModel.forAllWorkspaceItemInfos(mUser, si -> {
                boolean infoUpdated = false;
                boolean shortcutUpdated = false;
                // Update shortcuts which use iconResource.
                if ((si.iconResource != null) && packageSet.contains(si.iconResource.packageName)) {
                    LauncherIcons li = LauncherIcons.obtain(context);
                    BitmapInfo iconInfo = li.createIconBitmap(si.iconResource);
                    li.recycle();
                    if (iconInfo != null) {
                        si.bitmap = iconInfo;
                        infoUpdated = true;
                    }
                }
                ComponentName cn = si.getTargetComponent();
                if (cn != null && matcher.matches(si, cn)) {
                    String packageName = cn.getPackageName();
                    if (si.hasStatusFlag(WorkspaceItemInfo.FLAG_SUPPORTS_WEB_UI)) {
                        forceKeepShortcuts.add(si.id);
                        if (mOp == OP_REMOVE) {
                            return;
                        }
                    }
                    if (si.isPromise() && isNewApkAvailable) {
                        boolean isTargetValid = !cn.getClassName().equals(IconCache.EMPTY_CLASS_NAME);
                        if (si.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
                            List<ShortcutInfo> shortcut = new ShortcutRequest(context, mUser).forPackage(cn.getPackageName(), si.getDeepShortcutId()).query(ShortcutRequest.PINNED);
                            if (shortcut.isEmpty()) {
                                isTargetValid = false;
                            } else {
                                si.updateFromDeepShortcutInfo(shortcut.get(0), context);
                                infoUpdated = true;
                            }
                        } else if (isTargetValid) {
                            isTargetValid = context.getSystemService(LauncherApps.class).isActivityEnabled(cn, mUser);
                        }
                        if (!isTargetValid && si.hasStatusFlag(FLAG_RESTORED_ICON | FLAG_AUTOINSTALL_ICON)) {
                            if (updateWorkspaceItemIntent(context, si, packageName)) {
                                infoUpdated = true;
                            } else if (si.hasPromiseIconUi()) {
                                removedShortcuts.add(si.id);
                                return;
                            }
                        } else if (!isTargetValid) {
                            removedShortcuts.add(si.id);
                            FileLog.e(TAG, "Restored shortcut no longer valid " + si.getIntent());
                            return;
                        } else {
                            si.status = WorkspaceItemInfo.DEFAULT;
                            infoUpdated = true;
                        }
                    } else if (isNewApkAvailable && removedComponents.contains(cn)) {
                        if (updateWorkspaceItemIntent(context, si, packageName)) {
                            infoUpdated = true;
                        }
                    }
                    if (isNewApkAvailable) {
                        List<LauncherActivityInfo> activities = activitiesLists.get(packageName);
                        si.setProgressLevel(activities == null || activities.isEmpty() ? 100 : PackageManagerHelper.getLoadingProgress(activities.get(0)), PackageInstallInfo.STATUS_INSTALLED_DOWNLOADING);
                        if (si.itemType == Favorites.ITEM_TYPE_APPLICATION) {
                            iconCache.getTitleAndIcon(si, si.usingLowResIcon());
                            infoUpdated = true;
                        }
                    }
                    int oldRuntimeFlags = si.runtimeStatusFlags;
                    si.runtimeStatusFlags = flagOp.apply(si.runtimeStatusFlags);
                    if (si.runtimeStatusFlags != oldRuntimeFlags) {
                        shortcutUpdated = true;
                    }
                }
                if (infoUpdated || shortcutUpdated) {
                    updatedWorkspaceItems.add(si);
                }
                if (infoUpdated && si.id != ItemInfo.NO_ID) {
                    getModelWriter().updateItemInDatabase(si);
                }
            });
            for (LauncherAppWidgetInfo widgetInfo : dataModel.appWidgets) {
                if (mUser.equals(widgetInfo.user) && widgetInfo.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) && packageSet.contains(widgetInfo.providerName.getPackageName())) {
                    widgetInfo.restoreStatus &= ~LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY & ~LauncherAppWidgetInfo.FLAG_RESTORE_STARTED;
                    // adding this flag ensures that launcher shows 'click to setup'
                    // if the widget has a config activity. In case there is no config
                    // activity, it will be marked as 'restored' during bind.
                    widgetInfo.restoreStatus |= LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
                    widgets.add(widgetInfo);
                    getModelWriter().updateItemInDatabase(widgetInfo);
                }
            }
        }
        bindUpdatedWorkspaceItems(updatedWorkspaceItems);
        if (!removedShortcuts.isEmpty()) {
            deleteAndBindComponentsRemoved(ItemInfoMatcher.ofItemIds(removedShortcuts));
        }
        if (!widgets.isEmpty()) {
            scheduleCallbackTask(c -> c.bindWidgetsRestored(widgets));
        }
    }
    final HashSet<String> removedPackages = new HashSet<>();
    if (mOp == OP_REMOVE) {
        // Mark all packages in the broadcast to be removed
        Collections.addAll(removedPackages, packages);
    // No need to update the removedComponents as
    // removedPackages is a super-set of removedComponents
    } else if (mOp == OP_UPDATE) {
        // Mark disabled packages in the broadcast to be removed
        final LauncherApps launcherApps = context.getSystemService(LauncherApps.class);
        for (int i = 0; i < N; i++) {
            if (!launcherApps.isPackageEnabled(packages[i], mUser)) {
                removedPackages.add(packages[i]);
            }
        }
    }
    if (!removedPackages.isEmpty() || !removedComponents.isEmpty()) {
        ItemInfoMatcher removeMatch = ItemInfoMatcher.ofPackages(removedPackages, mUser).or(ItemInfoMatcher.ofComponents(removedComponents, mUser)).and(ItemInfoMatcher.ofItemIds(forceKeepShortcuts).negate());
        deleteAndBindComponentsRemoved(removeMatch);
        // Remove any queued items from the install queue
        ItemInstallQueue.INSTANCE.get(context).removeFromInstallQueue(removedPackages, mUser);
    }
    if (mOp == OP_ADD) {
        // AppWidgetHost events, this is just to initialize the long-press options.
        for (int i = 0; i < N; i++) {
            dataModel.widgetsModel.update(app, new PackageUserKey(packages[i], mUser));
        }
        bindUpdatedWidgets(dataModel);
    }
}
Also used : HashMap(java.util.HashMap) IntSet(com.android.launcher3.util.IntSet) ArrayList(java.util.ArrayList) ShortcutRequest(com.android.launcher3.shortcuts.ShortcutRequest) IconCache(com.android.launcher3.icons.IconCache) ItemInfoMatcher(com.android.launcher3.util.ItemInfoMatcher) ComponentName(android.content.ComponentName) ArrayList(java.util.ArrayList) List(java.util.List) FlagOp(com.android.launcher3.util.FlagOp) HashSet(java.util.HashSet) Context(android.content.Context) ShortcutInfo(android.content.pm.ShortcutInfo) PackageUserKey(com.android.launcher3.util.PackageUserKey) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) LauncherApps(android.content.pm.LauncherApps) LauncherIcons(com.android.launcher3.icons.LauncherIcons) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) Launcher(com.android.launcher3.Launcher) SafeCloseable(com.android.launcher3.util.SafeCloseable) BitmapInfo(com.android.launcher3.icons.BitmapInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 34 with INSTALL

use of com.android.launcher3.popup.SystemShortcut.INSTALL in project android_packages_apps_Launcher3 by ProtonAOSP.

the class LauncherModelHelper method initializeData.

/**
 * Initializes mock data for the test.
 */
public void initializeData(String resourceName) throws Exception {
    BgDataModel bgDataModel = getBgDataModel();
    AllAppsList allAppsList = getAllAppsList();
    MODEL_EXECUTOR.submit(() -> {
        // Copy apk from resources to a local file and install from there.
        Resources resources = testContext().getResources();
        int resId = resources.getIdentifier(resourceName, "raw", testContext().getPackageName());
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(resources.openRawResource(resId)))) {
            String line;
            HashMap<String, Class> classMap = new HashMap<>();
            while ((line = reader.readLine()) != null) {
                line = line.trim();
                if (line.startsWith("#") || line.isEmpty()) {
                    continue;
                }
                String[] commands = line.split(" ");
                switch(commands[0]) {
                    case "classMap":
                        classMap.put(commands[1], Class.forName(commands[2]));
                        break;
                    case "bgItem":
                        bgDataModel.addItem(sandboxContext, (ItemInfo) initItem(classMap.get(commands[1]), commands, 2), false);
                        break;
                    case "allApps":
                        allAppsList.add((AppInfo) initItem(AppInfo.class, commands, 1), null);
                        break;
                }
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }).get();
}
Also used : InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) ItemInfo(com.android.launcher3.model.data.ItemInfo) BgDataModel(com.android.launcher3.model.BgDataModel) AllAppsList(com.android.launcher3.model.AllAppsList) BufferedReader(java.io.BufferedReader) Resources(android.content.res.Resources) FileNotFoundException(java.io.FileNotFoundException) ExecutionException(java.util.concurrent.ExecutionException) AppInfo(com.android.launcher3.model.data.AppInfo)

Example 35 with INSTALL

use of com.android.launcher3.popup.SystemShortcut.INSTALL in project android_packages_apps_Launcher3 by AOSPA.

the class PackageUpdatedTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList appsList) {
    final Context context = app.getContext();
    final IconCache iconCache = app.getIconCache();
    final String[] packages = mPackages;
    final int N = packages.length;
    final FlagOp flagOp;
    final HashSet<String> packageSet = new HashSet<>(Arrays.asList(packages));
    final ItemInfoMatcher matcher = mOp == OP_USER_AVAILABILITY_CHANGE ? // We want to update all packages for this user
    ItemInfoMatcher.ofUser(mUser) : ItemInfoMatcher.ofPackages(packageSet, mUser);
    final HashSet<ComponentName> removedComponents = new HashSet<>();
    final HashMap<String, List<LauncherActivityInfo>> activitiesLists = new HashMap<>();
    boolean needsRestart = false;
    switch(mOp) {
        case OP_ADD:
            {
                for (int i = 0; i < N; i++) {
                    if (DEBUG)
                        Log.d(TAG, "mAllAppsList.addPackage " + packages[i]);
                    if (isTargetPackage(packages[i])) {
                        needsRestart = true;
                    }
                    iconCache.updateIconsForPkg(packages[i], mUser);
                    if (FeatureFlags.PROMISE_APPS_IN_ALL_APPS.get()) {
                        appsList.removePackage(packages[i], mUser);
                    }
                    activitiesLists.put(packages[i], appsList.addPackage(context, packages[i], mUser));
                }
                flagOp = FlagOp.removeFlag(WorkspaceItemInfo.FLAG_DISABLED_NOT_AVAILABLE);
                break;
            }
        case OP_UPDATE:
            try (SafeCloseable t = appsList.trackRemoves(a -> removedComponents.add(a.componentName))) {
                for (int i = 0; i < N; i++) {
                    if (DEBUG)
                        Log.d(TAG, "mAllAppsList.updatePackage " + packages[i]);
                    iconCache.updateIconsForPkg(packages[i], mUser);
                    activitiesLists.put(packages[i], appsList.updatePackage(context, packages[i], mUser));
                    // The update may have changed which shortcuts/widgets are available.
                    // Refresh the widgets for the package if we have an activity running.
                    Launcher launcher = Launcher.ACTIVITY_TRACKER.getCreatedActivity();
                    if (launcher != null) {
                        launcher.refreshAndBindWidgetsForPackageUser(new PackageUserKey(packages[i], mUser));
                    }
                }
            }
            // Since package was just updated, the target must be available now.
            flagOp = FlagOp.removeFlag(WorkspaceItemInfo.FLAG_DISABLED_NOT_AVAILABLE);
            break;
        case OP_REMOVE:
            {
                for (int i = 0; i < N; i++) {
                    FileLog.d(TAG, "Removing app icon" + packages[i]);
                    iconCache.removeIconsForPkg(packages[i], mUser);
                    if (isTargetPackage(packages[i])) {
                        needsRestart = true;
                    }
                }
            // Fall through
            }
        case OP_UNAVAILABLE:
            for (int i = 0; i < N; i++) {
                if (DEBUG)
                    Log.d(TAG, "mAllAppsList.removePackage " + packages[i]);
                appsList.removePackage(packages[i], mUser);
            }
            flagOp = FlagOp.addFlag(WorkspaceItemInfo.FLAG_DISABLED_NOT_AVAILABLE);
            break;
        case OP_SUSPEND:
        case OP_UNSUSPEND:
            flagOp = mOp == OP_SUSPEND ? FlagOp.addFlag(WorkspaceItemInfo.FLAG_DISABLED_SUSPENDED) : FlagOp.removeFlag(WorkspaceItemInfo.FLAG_DISABLED_SUSPENDED);
            if (DEBUG)
                Log.d(TAG, "mAllAppsList.(un)suspend " + N);
            appsList.updateDisabledFlags(matcher, flagOp);
            for (int i = 0; i < N; i++) {
                if (isTargetPackage(packages[i])) {
                    needsRestart = true;
                }
            }
            break;
        case OP_USER_AVAILABILITY_CHANGE:
            {
                UserManagerState ums = new UserManagerState();
                ums.init(UserCache.INSTANCE.get(context), context.getSystemService(UserManager.class));
                flagOp = ums.isUserQuiet(mUser) ? FlagOp.addFlag(WorkspaceItemInfo.FLAG_DISABLED_QUIET_USER) : FlagOp.removeFlag(WorkspaceItemInfo.FLAG_DISABLED_QUIET_USER);
                appsList.updateDisabledFlags(matcher, flagOp);
                // We are not synchronizing here, as int operations are atomic
                appsList.setFlags(FLAG_QUIET_MODE_ENABLED, ums.isAnyProfileQuietModeEnabled());
                break;
            }
        default:
            flagOp = FlagOp.NO_OP;
            break;
    }
    bindApplicationsIfNeeded();
    final IntSet removedShortcuts = new IntSet();
    // Shortcuts to keep even if the corresponding app was removed
    final IntSet forceKeepShortcuts = new IntSet();
    // Update shortcut infos
    if (mOp == OP_ADD || flagOp != FlagOp.NO_OP) {
        final ArrayList<WorkspaceItemInfo> updatedWorkspaceItems = new ArrayList<>();
        final ArrayList<LauncherAppWidgetInfo> widgets = new ArrayList<>();
        // For system apps, package manager send OP_UPDATE when an app is enabled.
        final boolean isNewApkAvailable = mOp == OP_ADD || mOp == OP_UPDATE;
        synchronized (dataModel) {
            dataModel.forAllWorkspaceItemInfos(mUser, si -> {
                boolean infoUpdated = false;
                boolean shortcutUpdated = false;
                // Update shortcuts which use iconResource.
                if ((si.iconResource != null) && packageSet.contains(si.iconResource.packageName)) {
                    LauncherIcons li = LauncherIcons.obtain(context);
                    BitmapInfo iconInfo = li.createIconBitmap(si.iconResource);
                    li.recycle();
                    if (iconInfo != null) {
                        si.bitmap = iconInfo;
                        infoUpdated = true;
                    }
                }
                ComponentName cn = si.getTargetComponent();
                if (cn != null && matcher.matches(si, cn)) {
                    String packageName = cn.getPackageName();
                    if (si.hasStatusFlag(WorkspaceItemInfo.FLAG_SUPPORTS_WEB_UI)) {
                        forceKeepShortcuts.add(si.id);
                        if (mOp == OP_REMOVE) {
                            return;
                        }
                    }
                    if (si.isPromise() && isNewApkAvailable) {
                        boolean isTargetValid = !cn.getClassName().equals(IconCache.EMPTY_CLASS_NAME);
                        if (si.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
                            List<ShortcutInfo> shortcut = new ShortcutRequest(context, mUser).forPackage(cn.getPackageName(), si.getDeepShortcutId()).query(ShortcutRequest.PINNED);
                            if (shortcut.isEmpty()) {
                                isTargetValid = false;
                            } else {
                                si.updateFromDeepShortcutInfo(shortcut.get(0), context);
                                infoUpdated = true;
                            }
                        } else if (isTargetValid) {
                            isTargetValid = context.getSystemService(LauncherApps.class).isActivityEnabled(cn, mUser);
                        }
                        if (!isTargetValid && si.hasStatusFlag(FLAG_RESTORED_ICON | FLAG_AUTOINSTALL_ICON)) {
                            if (updateWorkspaceItemIntent(context, si, packageName)) {
                                infoUpdated = true;
                            } else if (si.hasPromiseIconUi()) {
                                removedShortcuts.add(si.id);
                                return;
                            }
                        } else if (!isTargetValid) {
                            removedShortcuts.add(si.id);
                            FileLog.e(TAG, "Restored shortcut no longer valid " + si.getIntent());
                            return;
                        } else {
                            si.status = WorkspaceItemInfo.DEFAULT;
                            infoUpdated = true;
                        }
                    } else if (isNewApkAvailable && removedComponents.contains(cn)) {
                        if (updateWorkspaceItemIntent(context, si, packageName)) {
                            infoUpdated = true;
                        }
                    }
                    if (isNewApkAvailable) {
                        List<LauncherActivityInfo> activities = activitiesLists.get(packageName);
                        si.setProgressLevel(activities == null || activities.isEmpty() ? 100 : PackageManagerHelper.getLoadingProgress(activities.get(0)), PackageInstallInfo.STATUS_INSTALLED_DOWNLOADING);
                        if (si.itemType == Favorites.ITEM_TYPE_APPLICATION) {
                            iconCache.getTitleAndIcon(si, si.usingLowResIcon());
                            infoUpdated = true;
                        }
                    }
                    int oldRuntimeFlags = si.runtimeStatusFlags;
                    si.runtimeStatusFlags = flagOp.apply(si.runtimeStatusFlags);
                    if (si.runtimeStatusFlags != oldRuntimeFlags) {
                        shortcutUpdated = true;
                    }
                }
                if (infoUpdated || shortcutUpdated) {
                    updatedWorkspaceItems.add(si);
                }
                if (infoUpdated && si.id != ItemInfo.NO_ID) {
                    getModelWriter().updateItemInDatabase(si);
                }
            });
            for (LauncherAppWidgetInfo widgetInfo : dataModel.appWidgets) {
                if (mUser.equals(widgetInfo.user) && widgetInfo.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) && packageSet.contains(widgetInfo.providerName.getPackageName())) {
                    widgetInfo.restoreStatus &= ~LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY & ~LauncherAppWidgetInfo.FLAG_RESTORE_STARTED;
                    // adding this flag ensures that launcher shows 'click to setup'
                    // if the widget has a config activity. In case there is no config
                    // activity, it will be marked as 'restored' during bind.
                    widgetInfo.restoreStatus |= LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
                    widgets.add(widgetInfo);
                    getModelWriter().updateItemInDatabase(widgetInfo);
                }
            }
        }
        bindUpdatedWorkspaceItems(updatedWorkspaceItems);
        if (!removedShortcuts.isEmpty()) {
            deleteAndBindComponentsRemoved(ItemInfoMatcher.ofItemIds(removedShortcuts));
        }
        if (!widgets.isEmpty()) {
            scheduleCallbackTask(c -> c.bindWidgetsRestored(widgets));
        }
    }
    final HashSet<String> removedPackages = new HashSet<>();
    if (mOp == OP_REMOVE) {
        // Mark all packages in the broadcast to be removed
        Collections.addAll(removedPackages, packages);
    // No need to update the removedComponents as
    // removedPackages is a super-set of removedComponents
    } else if (mOp == OP_UPDATE) {
        // Mark disabled packages in the broadcast to be removed
        final LauncherApps launcherApps = context.getSystemService(LauncherApps.class);
        for (int i = 0; i < N; i++) {
            if (!launcherApps.isPackageEnabled(packages[i], mUser)) {
                removedPackages.add(packages[i]);
            }
        }
    }
    if (!removedPackages.isEmpty() || !removedComponents.isEmpty()) {
        ItemInfoMatcher removeMatch = ItemInfoMatcher.ofPackages(removedPackages, mUser).or(ItemInfoMatcher.ofComponents(removedComponents, mUser)).and(ItemInfoMatcher.ofItemIds(forceKeepShortcuts).negate());
        deleteAndBindComponentsRemoved(removeMatch);
        // Remove any queued items from the install queue
        ItemInstallQueue.INSTANCE.get(context).removeFromInstallQueue(removedPackages, mUser);
    }
    if (mOp == OP_ADD) {
        // AppWidgetHost events, this is just to initialize the long-press options.
        for (int i = 0; i < N; i++) {
            dataModel.widgetsModel.update(app, new PackageUserKey(packages[i], mUser));
        }
        bindUpdatedWidgets(dataModel);
    }
    if (needsRestart) {
        Utilities.restart(context);
    }
}
Also used : HashMap(java.util.HashMap) IntSet(com.android.launcher3.util.IntSet) ArrayList(java.util.ArrayList) ShortcutRequest(com.android.launcher3.shortcuts.ShortcutRequest) IconCache(com.android.launcher3.icons.IconCache) ItemInfoMatcher(com.android.launcher3.util.ItemInfoMatcher) ComponentName(android.content.ComponentName) ArrayList(java.util.ArrayList) List(java.util.List) FlagOp(com.android.launcher3.util.FlagOp) HashSet(java.util.HashSet) Context(android.content.Context) ShortcutInfo(android.content.pm.ShortcutInfo) PackageUserKey(com.android.launcher3.util.PackageUserKey) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) LauncherApps(android.content.pm.LauncherApps) LauncherIcons(com.android.launcher3.icons.LauncherIcons) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) Launcher(com.android.launcher3.Launcher) SafeCloseable(com.android.launcher3.util.SafeCloseable) BitmapInfo(com.android.launcher3.icons.BitmapInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Aggregations

ItemInfo (com.android.launcher3.model.data.ItemInfo)15 HashSet (java.util.HashSet)14 HashMap (java.util.HashMap)13 BitmapInfo (com.android.launcher3.icons.BitmapInfo)12 LauncherIcons (com.android.launcher3.icons.LauncherIcons)12 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)12 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)12 ComponentName (android.content.ComponentName)9 Launcher (com.android.launcher3.Launcher)9 AppInfo (com.android.launcher3.model.data.AppInfo)9 Context (android.content.Context)7 ShortcutInfo (android.content.pm.ShortcutInfo)7 IconCache (com.android.launcher3.icons.IconCache)7 FlagOp (com.android.launcher3.util.FlagOp)7 ItemInfoMatcher (com.android.launcher3.util.ItemInfoMatcher)7 PackageUserKey (com.android.launcher3.util.PackageUserKey)7 SafeCloseable (com.android.launcher3.util.SafeCloseable)7 ArrayList (java.util.ArrayList)7 ApplicationInfo (android.content.pm.ApplicationInfo)6 LauncherApps (android.content.pm.LauncherApps)6