Search in sources :

Example 26 with LauncherActivityInfo

use of android.content.pm.LauncherActivityInfo in project android_packages_apps_Trebuchet by LineageOS.

the class LoaderCursor method getAppShortcutInfo.

/**
 * Make an WorkspaceItemInfo object for a shortcut that is an application.
 */
public WorkspaceItemInfo getAppShortcutInfo(Intent intent, boolean allowMissingTarget, boolean useLowResIcon) {
    if (user == null) {
        Log.d(TAG, "Null user found in getShortcutInfo");
        return null;
    }
    ComponentName componentName = intent.getComponent();
    if (componentName == null) {
        Log.d(TAG, "Missing component found in getShortcutInfo");
        return null;
    }
    Intent newIntent = new Intent(Intent.ACTION_MAIN, null);
    newIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    newIntent.setComponent(componentName);
    LauncherActivityInfo lai = mContext.getSystemService(LauncherApps.class).resolveActivity(newIntent, user);
    if ((lai == null) && !allowMissingTarget) {
        Log.d(TAG, "Missing activity found in getShortcutInfo: " + componentName);
        return null;
    }
    final WorkspaceItemInfo info = new WorkspaceItemInfo();
    info.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
    info.user = user;
    info.intent = newIntent;
    mIconCache.getTitleAndIcon(info, lai, useLowResIcon);
    if (mIconCache.isDefaultIcon(info.bitmap, user)) {
        loadIcon(info);
    }
    if (lai != null) {
        AppInfo.updateRuntimeFlagsForActivityTarget(info, lai);
    }
    // from the db
    if (TextUtils.isEmpty(info.title)) {
        info.title = getTitle();
    }
    // fall back to the class name of the activity
    if (info.title == null) {
        info.title = componentName.getClassName();
    }
    info.contentDescription = mPM.getUserBadgedLabel(info.title, info.user);
    return info;
}
Also used : LauncherActivityInfo(android.content.pm.LauncherActivityInfo) ComponentName(android.content.ComponentName) Intent(android.content.Intent) LauncherApps(android.content.pm.LauncherApps) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 27 with LauncherActivityInfo

use of android.content.pm.LauncherActivityInfo 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 28 with LauncherActivityInfo

use of android.content.pm.LauncherActivityInfo 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 29 with LauncherActivityInfo

use of android.content.pm.LauncherActivityInfo in project android_packages_apps_Trebuchet by LineageOS.

the class IconCache method updateIconsForPkg.

/**
 * Updates the entries related to the given package in memory and persistent DB.
 */
public synchronized void updateIconsForPkg(String packageName, UserHandle user) {
    removeIconsForPkg(packageName, user);
    try {
        PackageInfo info = mPackageManager.getPackageInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
        long userSerial = mUserManager.getSerialNumberForUser(user);
        for (LauncherActivityInfo app : mLauncherApps.getActivityList(packageName, user)) {
            addIconToDBAndMemCache(app, mLauncherActivityInfoCachingLogic, info, userSerial, false);
        }
    } catch (NameNotFoundException e) {
        Log.d(TAG, "Package not found", e);
    }
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) LauncherActivityInfo(android.content.pm.LauncherActivityInfo)

Example 30 with LauncherActivityInfo

use of android.content.pm.LauncherActivityInfo in project AppIconLoader by zhanghai.

the class AppListLoader method loadAppList.

@NonNull
public static List<Pair<PackageInfo, String>> loadAppList(@NonNull Context context) {
    PackageManager packageManager = context.getPackageManager();
    List<PackageInfo> packageInfos = packageManager.getInstalledPackages(0);
    Iterator<PackageInfo> iterator = packageInfos.iterator();
    while (iterator.hasNext()) {
        PackageInfo packageInfo = iterator.next();
        if (packageInfo.applicationInfo == null) {
            iterator.remove();
        }
    }
    LauncherApps launcherApps = ContextCompat.getSystemService(context, LauncherApps.class);
    List<UserHandle> profiles = LauncherAppsCompat.getProfiles(launcherApps, context);
    profiles.remove(Process.myUserHandle());
    if (!profiles.isEmpty()) {
        ArrayMap<String, PackageInfo> packageInfoMap = new ArrayMap<>();
        for (PackageInfo packageInfo : packageInfos) {
            packageInfoMap.put(packageInfo.packageName, packageInfo);
        }
        for (UserHandle profile : profiles) {
            List<LauncherActivityInfo> activityList = launcherApps.getActivityList(null, profile);
            ArrayMap<String, ApplicationInfo> applicationInfoMap = new ArrayMap<>();
            for (LauncherActivityInfo launcherActivityInfo : activityList) {
                ApplicationInfo applicationInfo = launcherActivityInfo.getApplicationInfo();
                if (!applicationInfoMap.containsKey(applicationInfo.packageName)) {
                    applicationInfoMap.put(applicationInfo.packageName, applicationInfo);
                }
            }
            for (ApplicationInfo applicationInfo : applicationInfoMap.values()) {
                PackageInfo packageInfo;
                String packageName = applicationInfo.packageName;
                if (packageInfoMap.containsKey(packageName)) {
                    packageInfo = ParcelableCloner.cloneParcelable(packageInfoMap.get(packageName), PackageInfo.class.getClassLoader());
                } else {
                    try {
                        packageInfo = packageManager.getPackageInfo(packageName, PackageManagerCompat.MATCH_UNINSTALLED_PACKAGES);
                    } catch (PackageManager.NameNotFoundException e) {
                        continue;
                    }
                }
                packageInfo.applicationInfo = applicationInfo;
                packageInfos.add(packageInfo);
            }
        }
    }
    List<Pair<PackageInfo, String>> apps = new ArrayList<>();
    for (PackageInfo packageInfo : packageInfos) {
        String label = packageInfo.applicationInfo.loadLabel(packageManager).toString();
        apps.add(new Pair<>(packageInfo, label));
    }
    Collator collator = Collator.getInstance();
    Collections.sort(apps, (first, second) -> {
        int result = collator.compare(first.second, second.second);
        if (result == 0) {
            result = first.first.packageName.compareTo(second.first.packageName);
        }
        if (result == 0) {
            result = Integer.compare(first.first.applicationInfo.uid, second.first.applicationInfo.uid);
        }
        return result;
    });
    return apps;
}
Also used : PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) ArrayList(java.util.ArrayList) ArrayMap(android.util.ArrayMap) LauncherApps(android.content.pm.LauncherApps) Collator(java.text.Collator) PackageManager(android.content.pm.PackageManager) UserHandle(android.os.UserHandle) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) Pair(androidx.core.util.Pair) NonNull(androidx.annotation.NonNull)

Aggregations

LauncherActivityInfo (android.content.pm.LauncherActivityInfo)122 LauncherApps (android.content.pm.LauncherApps)62 ArrayList (java.util.ArrayList)51 UserHandle (android.os.UserHandle)44 Intent (android.content.Intent)32 ComponentName (android.content.ComponentName)27 List (java.util.List)26 AppInfo (com.android.launcher3.model.data.AppInfo)23 ShortcutInfo (android.content.pm.ShortcutInfo)22 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)21 Context (android.content.Context)19 Point (android.graphics.Point)19 SessionInfo (android.content.pm.PackageInstaller.SessionInfo)16 SuppressLint (android.annotation.SuppressLint)14 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)13 PackageManager (android.content.pm.PackageManager)12 PackageUserKey (com.android.launcher3.util.PackageUserKey)11 UserManager (android.os.UserManager)10 CancellationException (java.util.concurrent.CancellationException)10 PackageInstaller (android.content.pm.PackageInstaller)9