Search in sources :

Example 6 with BaseIconFactory

use of com.android.launcher3.icons.BaseIconFactory in project Neo-Launcher by NeoApplications.

the class BaseIconCache method cachePackageInstallInfo.

/**
 * Adds a default package entry in the cache. This entry is not persisted and will be removed
 * when the cache is flushed.
 */
public synchronized void cachePackageInstallInfo(String packageName, UserHandle user, Bitmap icon, CharSequence title) {
    removeFromMemCacheLocked(packageName, user);
    ComponentKey cacheKey = getPackageKey(packageName, user);
    CacheEntry entry = mCache.get(cacheKey);
    // For icon caching, do not go through DB. Just update the in-memory entry.
    if (entry == null) {
        entry = new CacheEntry();
    }
    if (!TextUtils.isEmpty(title)) {
        entry.title = title;
    }
    if (icon != null) {
        BaseIconFactory li = getIconFactory();
        li.createIconBitmap(icon).applyTo(entry);
        li.close();
    }
    if (!TextUtils.isEmpty(title) && entry.icon != null) {
        mCache.put(cacheKey, entry);
    }
}
Also used : ComponentKey(com.android.launcher3.util.ComponentKey) BaseIconFactory(com.android.launcher3.icons.BaseIconFactory)

Example 7 with BaseIconFactory

use of com.android.launcher3.icons.BaseIconFactory in project Neo-Launcher by NeoApplications.

the class BaseIconCache method getEntryForPackageLocked.

/**
 * Gets an entry for the package, which can be used as a fallback entry for various components.
 * This method is not thread safe, it must be called from a synchronized method.
 */
protected CacheEntry getEntryForPackageLocked(String packageName, UserHandle user, boolean useLowResIcon) {
    assertWorkerThread();
    ComponentKey cacheKey = getPackageKey(packageName, user);
    CacheEntry entry = mCache.get(cacheKey);
    if (entry == null || (entry.isLowRes() && !useLowResIcon)) {
        entry = new CacheEntry();
        boolean entryUpdated = true;
        // Check the DB first.
        if (!getEntryFromDB(cacheKey, entry, useLowResIcon)) {
            try {
                int flags = Process.myUserHandle().equals(user) ? 0 : PackageManager.GET_UNINSTALLED_PACKAGES;
                PackageInfo info = mPackageManager.getPackageInfo(packageName, flags);
                ApplicationInfo appInfo = info.applicationInfo;
                if (appInfo == null) {
                    throw new NameNotFoundException("ApplicationInfo is null");
                }
                BaseIconFactory li = getIconFactory();
                // Load the full res icon for the application, but if useLowResIcon is set, then
                // only keep the low resolution icon instead of the larger full-sized icon
                BitmapInfo iconInfo = li.createBadgedIconBitmap(appInfo.loadIcon(mPackageManager), user, appInfo.targetSdkVersion, isInstantApp(appInfo));
                li.close();
                entry.title = appInfo.loadLabel(mPackageManager);
                entry.contentDescription = mPackageManager.getUserBadgedLabel(entry.title, user);
                entry.icon = useLowResIcon ? LOW_RES_ICON : iconInfo.icon;
                entry.color = iconInfo.color;
                // Add the icon in the DB here, since these do not get written during
                // package updates.
                ContentValues values = newContentValues(iconInfo, entry.title.toString(), packageName, null);
                addIconToDB(values, cacheKey.componentName, info, getSerialNumberForUser(user));
            } catch (NameNotFoundException e) {
                if (DEBUG)
                    Log.d(TAG, "Application not installed " + packageName);
                entryUpdated = false;
            }
        }
        // Only add a filled-out entry to the cache
        if (entryUpdated) {
            mCache.put(cacheKey, entry);
        }
    }
    return entry;
}
Also used : ContentValues(android.content.ContentValues) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) ComponentKey(com.android.launcher3.util.ComponentKey) ApplicationInfo(android.content.pm.ApplicationInfo) BaseIconFactory(com.android.launcher3.icons.BaseIconFactory) BitmapInfo(com.android.launcher3.icons.BitmapInfo)

Aggregations

BaseIconFactory (com.android.launcher3.icons.BaseIconFactory)7 WorkerThread (androidx.annotation.WorkerThread)5 ComponentKey (com.android.launcher3.util.ComponentKey)2 ContentValues (android.content.ContentValues)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 PackageInfo (android.content.pm.PackageInfo)1 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 BitmapInfo (com.android.launcher3.icons.BitmapInfo)1