Search in sources :

Example 96 with WorkspaceItemInfo

use of com.android.launcher3.model.data.WorkspaceItemInfo in project Neo-Launcher by NeoApplications.

the class PackageUpdatedTask method updateWorkspaceItemIntent.

/**
 * Updates {@param si}'s intent to point to a new ComponentName.
 * @return Whether the shortcut intent was changed.
 */
private boolean updateWorkspaceItemIntent(Context context, WorkspaceItemInfo si, String packageName) {
    // Try to find the best match activity.
    Intent intent = new PackageManagerHelper(context).getAppLaunchIntent(packageName, mUser);
    if (intent != null) {
        si.intent = intent;
        si.status = WorkspaceItemInfo.DEFAULT;
        return true;
    }
    return false;
}
Also used : Intent(android.content.Intent) PackageManagerHelper(com.android.launcher3.util.PackageManagerHelper)

Example 97 with WorkspaceItemInfo

use of com.android.launcher3.model.data.WorkspaceItemInfo in project Neo-Launcher by NeoApplications.

the class PackageUpdatedTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList appsList) {
    if (TestProtocol.sDebugTracing) {
        Log.d(TestProtocol.APP_NOT_DISABLED, "PackageUpdatedTask: " + mOp + ", " + Arrays.toString(mPackages));
    }
    final Context context = app.getContext();
    final IconCache iconCache = app.getIconCache();
    final String[] packages = mPackages;
    final int N = packages.length;
    FlagOp flagOp = FlagOp.NO_OP;
    final HashSet<String> packageSet = new HashSet<>(Arrays.asList(packages));
    ItemInfoMatcher matcher = ItemInfoMatcher.ofPackages(packageSet, mUser);
    final HashSet<ComponentName> removedComponents = new HashSet<>();
    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.LAUNCHER3_PROMISE_APPS_IN_ALL_APPS) {
                        appsList.removePackage(packages[i], mUser);
                    }
                    appsList.addPackage(context, packages[i], mUser);
                    OmegaPreferences prefs = Utilities.getOmegaPrefs(context);
                    // Automatically add homescreen icon for work profile apps for below O device.
                    if (Utilities.ATLEAST_OREO && prefs.getAutoAddInstalled() && !OmegaUtilsKt.workspaceContains(dataModel, packages[i])) {
                        SessionCommitReceiver.queueAppIconAddition(context, packages[i], mUser);
                    } else if (!Utilities.ATLEAST_OREO && !Process.myUserHandle().equals(mUser)) {
                        SessionCommitReceiver.queueAppIconAddition(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 (String aPackage : packages) {
                    if (DEBUG)
                        Log.d(TAG, "mAllAppsList.updatePackage " + aPackage);
                    iconCache.updateIconsForPkg(aPackage, mUser);
                    appsList.updatePackage(context, aPackage, mUser);
                    app.getWidgetCache().removePackage(aPackage, 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 (String aPackage : packages) {
                    FileLog.d(TAG, "Removing app icon" + aPackage);
                    iconCache.removeIconsForPkg(aPackage, 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);
                app.getWidgetCache().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:
            flagOp = UserManagerCompat.getInstance(context).isQuietModeEnabled(mUser) ? FlagOp.addFlag(WorkspaceItemInfo.FLAG_DISABLED_QUIET_USER) : FlagOp.removeFlag(WorkspaceItemInfo.FLAG_DISABLED_QUIET_USER);
            // We want to update all packages for this user.
            matcher = ItemInfoMatcher.ofUser(mUser);
            appsList.updateDisabledFlags(matcher, flagOp);
            break;
        case OP_RELOAD:
            if (DEBUG)
                Log.d(TAG, "mAllAppsList.reloadPackages");
            appsList.reloadPackages(context, mUser);
            break;
    }
    bindApplicationsIfNeeded();
    final IntSparseArrayMap<Boolean> removedShortcuts = new IntSparseArrayMap<>();
    // 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) {
            for (ItemInfo info : dataModel.itemsIdMap) {
                if (info instanceof WorkspaceItemInfo && mUser.equals(info.user)) {
                    WorkspaceItemInfo si = (WorkspaceItemInfo) info;
                    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.applyFrom(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)) {
                            removedShortcuts.put(si.id, false);
                            if (mOp == OP_REMOVE) {
                                continue;
                            }
                        }
                        if (si.isPromise() && isNewApkAvailable) {
                            boolean isTargetValid = true;
                            if (si.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
                                List<ShortcutInfo> shortcut = DeepShortcutManager.getInstance(context).queryForPinnedShortcuts(cn.getPackageName(), Arrays.asList(si.getDeepShortcutId()), mUser);
                                if (shortcut.isEmpty()) {
                                    isTargetValid = false;
                                } else {
                                    si.updateFromDeepShortcutInfo(shortcut.get(0), context);
                                    infoUpdated = true;
                                }
                            } else if (!cn.getClassName().equals(IconCache.EMPTY_CLASS_NAME)) {
                                isTargetValid = LauncherAppsCompat.getInstance(context).isActivityEnabledForProfile(cn, mUser);
                            }
                            if (si.hasStatusFlag(FLAG_RESTORED_ICON | FLAG_AUTOINSTALL_ICON)) {
                                if (updateWorkspaceItemIntent(context, si, packageName)) {
                                    infoUpdated = true;
                                } else if (si.hasPromiseIconUi()) {
                                    removedShortcuts.put(si.id, true);
                                    continue;
                                }
                            } else if (!isTargetValid) {
                                removedShortcuts.put(si.id, true);
                                FileLog.e(TAG, "Restored shortcut no longer valid " + si.intent);
                                continue;
                            } else {
                                si.status = WorkspaceItemInfo.DEFAULT;
                                infoUpdated = true;
                            }
                        } else if (isNewApkAvailable && removedComponents.contains(cn)) {
                            if (updateWorkspaceItemIntent(context, si, packageName)) {
                                infoUpdated = true;
                            }
                        }
                        if (isNewApkAvailable && 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) {
                        getModelWriter().updateItemInDatabase(si);
                    }
                } else if (info instanceof LauncherAppWidgetInfo && isNewApkAvailable) {
                    LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) info;
                    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, false));
        }
        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 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context);
        for (int i = 0; i < N; i++) {
            if (!launcherApps.isPackageEnabledForProfile(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(removedShortcuts, true));
        deleteAndBindComponentsRemoved(removeMatch);
        // Remove any queued items from the install queue
        InstallShortcutReceiver.removeFromInstallQueue(context, removedPackages, mUser);
    }
    if (Utilities.ATLEAST_OREO && 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 : LauncherAppsCompat(com.android.launcher3.compat.LauncherAppsCompat) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo) ItemInfo(com.android.launcher3.ItemInfo) IntSparseArrayMap(com.android.launcher3.util.IntSparseArrayMap) ArrayList(java.util.ArrayList) OmegaPreferences(com.saggitt.omega.OmegaPreferences) IconCache(com.android.launcher3.icons.IconCache) ItemInfoMatcher(com.android.launcher3.util.ItemInfoMatcher) ComponentName(android.content.ComponentName) FlagOp(com.android.launcher3.util.FlagOp) HashSet(java.util.HashSet) Context(android.content.Context) ShortcutInfo(android.content.pm.ShortcutInfo) LauncherAppWidgetInfo(com.android.launcher3.LauncherAppWidgetInfo) PackageUserKey(com.android.launcher3.util.PackageUserKey) LauncherIcons(com.android.launcher3.icons.LauncherIcons) SafeCloseable(com.android.launcher3.util.SafeCloseable) BitmapInfo(com.android.launcher3.icons.BitmapInfo) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo)

Example 98 with WorkspaceItemInfo

use of com.android.launcher3.model.data.WorkspaceItemInfo in project Neo-Launcher by NeoApplications.

the class ShortcutsChangedTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
    final Context context = app.getContext();
    DeepShortcutManager deepShortcutManager = DeepShortcutManager.getInstance(context);
    // Find WorkspaceItemInfo's that have changed on the workspace.
    HashSet<ShortcutKey> removedKeys = new HashSet<>();
    MultiHashMap<ShortcutKey, WorkspaceItemInfo> keyToShortcutInfo = new MultiHashMap<>();
    HashSet<String> allIds = new HashSet<>();
    for (ItemInfo itemInfo : dataModel.itemsIdMap) {
        if (itemInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
            WorkspaceItemInfo si = (WorkspaceItemInfo) itemInfo;
            if (mPackageName.equals(si.getIntent().getPackage()) && si.user.equals(mUser)) {
                keyToShortcutInfo.addToList(ShortcutKey.fromItemInfo(si), si);
                allIds.add(si.getDeepShortcutId());
            }
        }
    }
    final ArrayList<WorkspaceItemInfo> updatedWorkspaceItemInfos = new ArrayList<>();
    if (!keyToShortcutInfo.isEmpty()) {
        // Update the workspace to reflect the changes to updated shortcuts residing on it.
        List<ShortcutInfo> shortcuts = deepShortcutManager.queryForFullDetails(mPackageName, new ArrayList<>(allIds), mUser);
        for (ShortcutInfo fullDetails : shortcuts) {
            ShortcutKey key = ShortcutKey.fromInfo(fullDetails);
            List<WorkspaceItemInfo> workspaceItemInfos = keyToShortcutInfo.remove(key);
            if (!fullDetails.isPinned()) {
                // The shortcut was previously pinned but is no longer, so remove it from
                // the workspace and our pinned shortcut counts.
                // Note that we put this check here, after querying for full details,
                // because there's a possible race condition between pinning and
                // receiving this callback.
                removedKeys.add(key);
                continue;
            }
            for (final WorkspaceItemInfo workspaceItemInfo : workspaceItemInfos) {
                workspaceItemInfo.updateFromDeepShortcutInfo(fullDetails, context);
                // If the shortcut is pinned but no longer has an icon in the system,
                // keep the current icon instead of reverting to the default icon.
                LauncherIcons li = LauncherIcons.obtain(context);
                workspaceItemInfo.applyFrom(li.createShortcutIcon(fullDetails, true, () -> workspaceItemInfo));
                li.recycle();
                updatedWorkspaceItemInfos.add(workspaceItemInfo);
            }
        }
    }
    // If there are still entries in keyToShortcutInfo, that means that
    // the corresponding shortcuts weren't passed in onShortcutsChanged(). This
    // means they were cleared, so we remove and unpin them now.
    removedKeys.addAll(keyToShortcutInfo.keySet());
    bindUpdatedWorkspaceItems(updatedWorkspaceItemInfos);
    if (!keyToShortcutInfo.isEmpty()) {
        deleteAndBindComponentsRemoved(ItemInfoMatcher.ofShortcutKeys(removedKeys));
    }
    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) ShortcutInfo(android.content.pm.ShortcutInfo) ItemInfo(com.android.launcher3.ItemInfo) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo) ArrayList(java.util.ArrayList) MultiHashMap(com.android.launcher3.util.MultiHashMap) ShortcutKey(com.android.launcher3.shortcuts.ShortcutKey) LauncherIcons(com.android.launcher3.icons.LauncherIcons) DeepShortcutManager(com.android.launcher3.shortcuts.DeepShortcutManager) HashSet(java.util.HashSet) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo)

Example 99 with WorkspaceItemInfo

use of com.android.launcher3.model.data.WorkspaceItemInfo in project Neo-Launcher by NeoApplications.

the class ItemClickHandler method startAppShortcutOrInfoActivity.

private static void startAppShortcutOrInfoActivity(View v, ItemInfo item, Launcher launcher, @Nullable String sourceContainer) {
    Intent intent;
    if (item instanceof PromiseAppInfo) {
        PromiseAppInfo promiseAppInfo = (PromiseAppInfo) item;
        intent = promiseAppInfo.getMarketIntent(launcher);
    } else {
        intent = item.getIntent();
    }
    if (intent == null) {
        throw new IllegalArgumentException("Input must have a valid intent");
    }
    if (item instanceof WorkspaceItemInfo) {
        WorkspaceItemInfo si = (WorkspaceItemInfo) item;
        if (si.hasStatusFlag(WorkspaceItemInfo.FLAG_SUPPORTS_WEB_UI) && Intent.ACTION_VIEW.equals(intent.getAction())) {
            // make a copy of the intent that has the package set to null
            // we do this because the platform sometimes disables instant
            // apps temporarily (triggered by the user) and fallbacks to the
            // web ui. This only works though if the package isn't set
            intent = new Intent(intent);
            intent.setPackage(null);
        }
    }
    if (v != null && launcher.getAppTransitionManager().supportsAdaptiveIconAnimation()) {
        // Preload the icon to reduce latency b/w swapping the floating view with the original.
        FloatingIconView.fetchIcon(launcher, v, item, true);
    }
    if (item instanceof AppInfo) {
        Log.i(TAG, "Clicking App " + item.title);
        DbHelper db = new DbHelper(launcher.getApplicationContext());
        db.updateAppCount(((AppInfo) item).componentName.getPackageName());
        db.close();
    }
    launcher.startActivitySafely(v, intent, item, sourceContainer);
    launcher.getUserEventDispatcher().logAppLaunch(v, intent, item.user);
}
Also used : PromiseAppInfo(com.android.launcher3.PromiseAppInfo) Intent(android.content.Intent) DbHelper(com.saggitt.omega.util.DbHelper) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo) AppInfo(com.android.launcher3.AppInfo) PromiseAppInfo(com.android.launcher3.PromiseAppInfo)

Example 100 with WorkspaceItemInfo

use of com.android.launcher3.model.data.WorkspaceItemInfo in project Neo-Launcher by NeoApplications.

the class LoaderCursorTest method getAppShortcutInfo_dontAllowMissing_validComponent.

@Test
public void getAppShortcutInfo_dontAllowMissing_validComponent() {
    initCursor(ITEM_TYPE_APPLICATION, "");
    assertTrue(mLoaderCursor.moveToNext());
    ComponentName cn = mLauncherApps.getActivityList(null, mLoaderCursor.user).get(0).getComponentName();
    WorkspaceItemInfo info = mLoaderCursor.getAppShortcutInfo(new Intent().setComponent(cn), false, /* allowMissingTarget */
    true);
    assertNotNull(info);
    assertTrue(PackageManagerHelper.isLauncherAppTarget(info.intent));
}
Also used : ComponentName(android.content.ComponentName) Intent(android.content.Intent) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Aggregations

WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)348 View (android.view.View)142 ArrayList (java.util.ArrayList)125 ItemInfo (com.android.launcher3.model.data.ItemInfo)105 Intent (android.content.Intent)101 FolderInfo (com.android.launcher3.model.data.FolderInfo)83 AppInfo (com.android.launcher3.model.data.AppInfo)79 AppWidgetHostView (android.appwidget.AppWidgetHostView)73 BubbleTextView (com.android.launcher3.BubbleTextView)72 SuppressLint (android.annotation.SuppressLint)68 DragView (com.android.launcher3.dragndrop.DragView)67 ComponentName (android.content.ComponentName)66 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)62 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)61 Rect (android.graphics.Rect)58 FolderIcon (com.android.launcher3.folder.FolderIcon)58 HashSet (java.util.HashSet)54 Context (android.content.Context)53 Point (android.graphics.Point)51 WorkspaceItemInfo (com.android.launcher3.WorkspaceItemInfo)50