Search in sources :

Example 11 with IconRequestInfo

use of com.android.launcher3.model.data.IconRequestInfo in project android_packages_apps_Launcher3 by ArrowOS.

the class IconCache method getTitlesAndIconsInBulk.

/**
 * Load and fill icons requested in iconRequestInfos using a single bulk sql query.
 */
public synchronized <T extends ItemInfoWithIcon> void getTitlesAndIconsInBulk(List<IconRequestInfo<T>> iconRequestInfos) {
    Map<Pair<UserHandle, Boolean>, List<IconRequestInfo<T>>> iconLoadSubsectionsMap = iconRequestInfos.stream().collect(groupingBy(iconRequest -> Pair.create(iconRequest.itemInfo.user, iconRequest.useLowResIcon)));
    Trace.beginSection("loadIconsInBulk");
    iconLoadSubsectionsMap.forEach((sectionKey, filteredList) -> {
        Map<ComponentName, List<IconRequestInfo<T>>> duplicateIconRequestsMap = filteredList.stream().collect(groupingBy(iconRequest -> iconRequest.itemInfo.getTargetComponent()));
        Trace.beginSection("loadIconSubsectionInBulk");
        try (Cursor c = createBulkQueryCursor(filteredList, /* user = */
        sectionKey.first, /* useLowResIcons = */
        sectionKey.second)) {
            int componentNameColumnIndex = c.getColumnIndexOrThrow(IconDB.COLUMN_COMPONENT);
            while (c.moveToNext()) {
                ComponentName cn = ComponentName.unflattenFromString(c.getString(componentNameColumnIndex));
                List<IconRequestInfo<T>> duplicateIconRequests = duplicateIconRequestsMap.get(cn);
                if (cn != null) {
                    CacheEntry entry = cacheLocked(cn, /* user = */
                    sectionKey.first, () -> duplicateIconRequests.get(0).launcherActivityInfo, mLauncherActivityInfoCachingLogic, c, /* usePackageIcon= */
                    false, /* useLowResIcons = */
                    sectionKey.second);
                    for (IconRequestInfo<T> iconRequest : duplicateIconRequests) {
                        applyCacheEntry(entry, iconRequest.itemInfo);
                    }
                }
            }
        } catch (SQLiteException e) {
            Log.d(TAG, "Error reading icon cache", e);
        } finally {
            Trace.endSection();
        }
    });
    Trace.endSection();
}
Also used : Trace(android.os.Trace) IconRequestInfo(com.android.launcher3.model.data.IconRequestInfo) PackageManager(android.content.pm.PackageManager) NonNull(androidx.annotation.NonNull) Preconditions(com.android.launcher3.util.Preconditions) Drawable(android.graphics.drawable.Drawable) Process(android.os.Process) LauncherFiles(com.android.launcher3.LauncherFiles) ShortcutKey(com.android.launcher3.shortcuts.ShortcutKey) SQLiteException(android.database.sqlite.SQLiteException) Map(java.util.Map) MAIN_EXECUTOR(com.android.launcher3.util.Executors.MAIN_EXECUTOR) WidgetSection(com.android.launcher3.widget.WidgetSections.WidgetSection) Log(android.util.Log) Utilities(com.android.launcher3.Utilities) Predicate(java.util.function.Predicate) InstantAppResolver(com.android.launcher3.util.InstantAppResolver) UserCache(com.android.launcher3.pm.UserCache) LauncherApps(android.content.pm.LauncherApps) ComponentCachingLogic(com.android.launcher3.icons.ComponentWithLabel.ComponentCachingLogic) Objects(java.util.Objects) PackageInstaller(android.content.pm.PackageInstaller) List(java.util.List) Stream(java.util.stream.Stream) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) WidgetSections(com.android.launcher3.widget.WidgetSections) ApplicationInfo(android.content.pm.ApplicationInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Context(android.content.Context) MODEL_EXECUTOR(com.android.launcher3.util.Executors.MODEL_EXECUTOR) NO_CATEGORY(com.android.launcher3.widget.WidgetSections.NO_CATEGORY) AppInfo(com.android.launcher3.model.data.AppInfo) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Pair(android.util.Pair) Intent(android.content.Intent) PackageInfo(android.content.pm.PackageInfo) Supplier(java.util.function.Supplier) PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) UserHandle(android.os.UserHandle) CachingLogic(com.android.launcher3.icons.cache.CachingLogic) Cursor(android.database.Cursor) ComponentName(android.content.ComponentName) ShortcutInfo(android.content.pm.ShortcutInfo) PackageUserKey(com.android.launcher3.util.PackageUserKey) TextUtils(android.text.TextUtils) FeatureFlags(com.android.launcher3.config.FeatureFlags) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) HandlerRunnable(com.android.launcher3.icons.cache.HandlerRunnable) Collections(java.util.Collections) BaseIconCache(com.android.launcher3.icons.cache.BaseIconCache) ItemInfoWithIcon(com.android.launcher3.model.data.ItemInfoWithIcon) IconRequestInfo(com.android.launcher3.model.data.IconRequestInfo) Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException) List(java.util.List) ComponentName(android.content.ComponentName) Pair(android.util.Pair)

Example 12 with IconRequestInfo

use of com.android.launcher3.model.data.IconRequestInfo in project android_packages_apps_Launcher3 by AOSPA.

the class LoaderTask method loadAllApps.

private List<LauncherActivityInfo> loadAllApps() {
    final List<UserHandle> profiles = mUserCache.getUserProfiles();
    List<LauncherActivityInfo> allActivityList = new ArrayList<>();
    // Clear the list of apps
    mBgAllAppsList.clear();
    List<IconRequestInfo<AppInfo>> iconRequestInfos = new ArrayList<>();
    for (UserHandle user : profiles) {
        // Query for the set of apps
        final List<LauncherActivityInfo> apps = mLauncherApps.getActivityList(null, user);
        // TODO: Fix this. Only fail for the current user.
        if (apps == null || apps.isEmpty()) {
            return allActivityList;
        }
        boolean quietMode = mUserManagerState.isUserQuiet(user);
        // Create the ApplicationInfos
        for (int i = 0; i < apps.size(); i++) {
            LauncherActivityInfo app = apps.get(i);
            AppInfo appInfo = new AppInfo(app, user, quietMode);
            iconRequestInfos.add(new IconRequestInfo<>(appInfo, app, /* useLowResIcon= */
            false));
            mBgAllAppsList.add(appInfo, app, !FeatureFlags.ENABLE_BULK_ALL_APPS_ICON_LOADING.get());
        }
        allActivityList.addAll(apps);
    }
    if (FeatureFlags.PROMISE_APPS_IN_ALL_APPS.get()) {
        // get all active sessions and add them to the all apps list
        for (PackageInstaller.SessionInfo info : mSessionHelper.getAllVerifiedSessions()) {
            AppInfo promiseAppInfo = mBgAllAppsList.addPromiseApp(mApp.getContext(), PackageInstallInfo.fromInstallingState(info), !FeatureFlags.ENABLE_BULK_ALL_APPS_ICON_LOADING.get());
            if (promiseAppInfo != null) {
                iconRequestInfos.add(new IconRequestInfo<>(promiseAppInfo, /* launcherActivityInfo= */
                null, promiseAppInfo.usingLowResIcon()));
            }
        }
    }
    if (FeatureFlags.ENABLE_BULK_ALL_APPS_ICON_LOADING.get()) {
        Trace.beginSection("LoadAllAppsIconsInBulk");
        try {
            mIconCache.getTitlesAndIconsInBulk(iconRequestInfos);
            iconRequestInfos.forEach(iconRequestInfo -> mBgAllAppsList.updateSectionName(iconRequestInfo.itemInfo));
        } finally {
            Trace.endSection();
        }
    }
    mBgAllAppsList.setFlags(FLAG_QUIET_MODE_ENABLED, mUserManagerState.isAnyProfileQuietModeEnabled());
    mBgAllAppsList.setFlags(FLAG_HAS_SHORTCUT_PERMISSION, hasShortcutsPermission(mApp.getContext()));
    mBgAllAppsList.setFlags(FLAG_QUIET_MODE_CHANGE_PERMISSION, mApp.getContext().checkSelfPermission("android.permission.MODIFY_QUIET_MODE") == PackageManager.PERMISSION_GRANTED);
    mBgAllAppsList.getAndResetChangeFlag();
    return allActivityList;
}
Also used : ArrayList(java.util.ArrayList) IconRequestInfo(com.android.launcher3.model.data.IconRequestInfo) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) AppInfo(com.android.launcher3.model.data.AppInfo) SessionInfo(android.content.pm.PackageInstaller.SessionInfo) UserHandle(android.os.UserHandle) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) PackageInstaller(android.content.pm.PackageInstaller)

Aggregations

LauncherActivityInfo (android.content.pm.LauncherActivityInfo)12 UserHandle (android.os.UserHandle)12 IconRequestInfo (com.android.launcher3.model.data.IconRequestInfo)12 SuppressLint (android.annotation.SuppressLint)8 ComponentName (android.content.ComponentName)8 Context (android.content.Context)8 Intent (android.content.Intent)8 PackageInstaller (android.content.pm.PackageInstaller)8 SessionInfo (android.content.pm.PackageInstaller.SessionInfo)8 ShortcutInfo (android.content.pm.ShortcutInfo)8 Point (android.graphics.Point)8 AppInfo (com.android.launcher3.model.data.AppInfo)8 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)8 ShortcutKey (com.android.launcher3.shortcuts.ShortcutKey)8 PackageUserKey (com.android.launcher3.util.PackageUserKey)8 ArrayList (java.util.ArrayList)8 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)4 ContentResolver (android.content.ContentResolver)4 ApplicationInfo (android.content.pm.ApplicationInfo)4 LauncherApps (android.content.pm.LauncherApps)4