Search in sources :

Example 51 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project android_packages_apps_Trebuchet by LineageOS.

the class CacheDataUpdatedTaskTest method testCacheUpdate_update_apps.

@Test
public void testCacheUpdate_update_apps() throws Exception {
    // Clear all icons from apps list so that its easy to check what was updated
    for (AppInfo info : mModelHelper.getAllAppsList().data) {
        info.bitmap = BitmapInfo.LOW_RES_INFO;
    }
    mModelHelper.executeTaskForTest(newTask(CacheDataUpdatedTask.OP_CACHE_UPDATE, "app1"));
    // Verify that only the app icons of app1 (id 1 & 2) are updated. Custom shortcut (id 7)
    // is not updated
    verifyUpdate(1, 2);
    // Verify that only app1 var updated in allAppsList
    assertFalse(mModelHelper.getAllAppsList().data.isEmpty());
    for (AppInfo info : mModelHelper.getAllAppsList().data) {
        if (info.componentName.getPackageName().equals("app1")) {
            assertFalse(info.bitmap.isNullOrLowRes());
        } else {
            assertTrue(info.bitmap.isNullOrLowRes());
        }
    }
}
Also used : AppInfo(com.android.launcher3.model.data.AppInfo) Test(org.junit.Test)

Example 52 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project android_packages_apps_Trebuchet by LineageOS.

the class LoaderTask method loadCachedPredictions.

@WorkerThread
private void loadCachedPredictions() {
    synchronized (mBgDataModel) {
        List<ComponentKey> componentKeys = mApp.getPredictionModel().getPredictionComponentKeys();
        List<LauncherActivityInfo> l;
        mBgDataModel.cachedPredictedItems.clear();
        for (ComponentKey key : componentKeys) {
            l = mLauncherApps.getActivityList(key.componentName.getPackageName(), key.user);
            if (l.size() == 0)
                continue;
            AppInfo info = new AppInfo(l.get(0), key.user, mUserManagerState.isUserQuiet(key.user));
            mBgDataModel.cachedPredictedItems.add(info);
            mIconCache.getTitleAndIcon(info, false);
        }
    }
}
Also used : ComponentKey(com.android.launcher3.util.ComponentKey) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) AppInfo(com.android.launcher3.model.data.AppInfo) WorkerThread(androidx.annotation.WorkerThread)

Example 53 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project android_packages_apps_Trebuchet by LineageOS.

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);
                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.setInstallProgress((int) sessionInfo.getProgress());
                }
                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);
        }
    }
    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 54 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project android_packages_apps_Trebuchet by LineageOS.

the class AllAppsList method updatePromiseInstallInfo.

public PromiseAppInfo updatePromiseInstallInfo(PackageInstallInfo installInfo) {
    UserHandle user = Process.myUserHandle();
    for (int i = 0; i < data.size(); i++) {
        final AppInfo appInfo = data.get(i);
        final ComponentName tgtComp = appInfo.getTargetComponent();
        if (tgtComp != null && tgtComp.getPackageName().equals(installInfo.packageName) && appInfo.user.equals(user) && appInfo instanceof PromiseAppInfo) {
            final PromiseAppInfo promiseAppInfo = (PromiseAppInfo) appInfo;
            if (installInfo.state == PackageInstallInfo.STATUS_INSTALLING) {
                promiseAppInfo.level = installInfo.progress;
                return promiseAppInfo;
            } else if (installInfo.state == PackageInstallInfo.STATUS_FAILED) {
                removeApp(i);
            }
        }
    }
    return null;
}
Also used : UserHandle(android.os.UserHandle) PromiseAppInfo(com.android.launcher3.model.data.PromiseAppInfo) ComponentName(android.content.ComponentName) AppInfo(com.android.launcher3.model.data.AppInfo) PromiseAppInfo(com.android.launcher3.model.data.PromiseAppInfo)

Example 55 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project android_packages_apps_Trebuchet by LineageOS.

the class AllAppsList method updateDisabledFlags.

/**
 * Updates the disabled flags of apps matching {@param matcher} based on {@param op}.
 */
public void updateDisabledFlags(ItemInfoMatcher matcher, FlagOp op) {
    final List<AppInfo> data = this.data;
    for (int i = data.size() - 1; i >= 0; i--) {
        AppInfo info = data.get(i);
        if (matcher.matches(info, info.componentName)) {
            info.runtimeStatusFlags = op.apply(info.runtimeStatusFlags);
            mDataChanged = true;
        }
    }
}
Also used : AppInfo(com.android.launcher3.model.data.AppInfo) PromiseAppInfo(com.android.launcher3.model.data.PromiseAppInfo)

Aggregations

AppInfo (com.android.launcher3.model.data.AppInfo)181 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)86 ItemInfo (com.android.launcher3.model.data.ItemInfo)46 ArrayList (java.util.ArrayList)46 ComponentName (android.content.ComponentName)36 AppInfo (com.android.launcher3.AppInfo)33 View (android.view.View)32 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)31 Intent (android.content.Intent)30 FolderInfo (com.android.launcher3.model.data.FolderInfo)30 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)30 UserHandle (android.os.UserHandle)21 PackageItemInfo (com.android.launcher3.model.data.PackageItemInfo)21 PendingAddShortcutInfo (com.android.launcher3.widget.PendingAddShortcutInfo)21 Point (android.graphics.Point)19 BubbleTextView (com.android.launcher3.BubbleTextView)19 LauncherApps (android.content.pm.LauncherApps)17 ItemInfoWithIcon (com.android.launcher3.model.data.ItemInfoWithIcon)17 PendingAddItemInfo (com.android.launcher3.PendingAddItemInfo)15 AppWidgetHostView (android.appwidget.AppWidgetHostView)14