From 53f9672b30b8a36bfae9f6492f732ccfb87723a4 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Mon, 13 Jul 2015 19:54:53 -0700 Subject: Fixing widget restore > Widget restore active flag was not cleared when the app was downloaded > Icon from session info was not getting cached Bug: 22413379 Change-Id: Ie096b929252200675a76dadd8c25cc3aa433671b --- src/com/android/launcher3/IconCache.java | 35 +++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'src/com/android/launcher3/IconCache.java') diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java index 916418f18..193f458b5 100644 --- a/src/com/android/launcher3/IconCache.java +++ b/src/com/android/launcher3/IconCache.java @@ -540,7 +540,7 @@ public class IconCache { mCache.put(cacheKey, entry); // Check the DB first. - if (!getEntryFromDB(componentName, user, entry, useLowResIcon)) { + if (!getEntryFromDB(cacheKey, entry, useLowResIcon)) { if (info != null) { entry.icon = Utilities.createIconBitmap(info.getBadgedIcon(mIconDpi), mContext); } else { @@ -579,7 +579,14 @@ public class IconCache { Bitmap icon, CharSequence title) { removeFromMemCacheLocked(packageName, user); - CacheEntry entry = getEntryForPackageLocked(packageName, user, false); + 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(); + mCache.put(cacheKey, entry); + } if (!TextUtils.isEmpty(title)) { entry.title = title; } @@ -588,15 +595,18 @@ public class IconCache { } } + private static ComponentKey getPackageKey(String packageName, UserHandleCompat user) { + ComponentName cn = new ComponentName(packageName, packageName + EMPTY_CLASS_NAME); + return new ComponentKey(cn, user); + } + /** * 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. - * */ private CacheEntry getEntryForPackageLocked(String packageName, UserHandleCompat user, boolean useLowResIcon) { - ComponentName cn = new ComponentName(packageName, packageName + EMPTY_CLASS_NAME); - ComponentKey cacheKey = new ComponentKey(cn, user); + ComponentKey cacheKey = getPackageKey(packageName, user); CacheEntry entry = mCache.get(cacheKey); if (entry == null || (entry.isLowResIcon && !useLowResIcon)) { @@ -604,7 +614,7 @@ public class IconCache { boolean entryUpdated = true; // Check the DB first. - if (!getEntryFromDB(cn, user, entry, useLowResIcon)) { + if (!getEntryFromDB(cacheKey, entry, useLowResIcon)) { try { PackageInfo info = mPackageManager.getPackageInfo(packageName, 0); ApplicationInfo appInfo = info.applicationInfo; @@ -622,7 +632,8 @@ public class IconCache { // package updates. ContentValues values = newContentValues(entry.icon, entry.title.toString(), mPackageBgColor); - addIconToDB(values, cn, info, mUserManager.getSerialNumberForUser(user)); + addIconToDB(values, cacheKey.componentName, info, + mUserManager.getSerialNumberForUser(user)); } catch (NameNotFoundException e) { if (DEBUG) Log.d(TAG, "Application not installed " + packageName); @@ -667,14 +678,13 @@ public class IconCache { SQLiteDatabase.CONFLICT_REPLACE); } - private boolean getEntryFromDB(ComponentName component, UserHandleCompat user, - CacheEntry entry, boolean lowRes) { + private boolean getEntryFromDB(ComponentKey cacheKey, CacheEntry entry, boolean lowRes) { Cursor c = mIconDb.getReadableDatabase().query(IconDB.TABLE_NAME, new String[] {lowRes ? IconDB.COLUMN_ICON_LOW_RES : IconDB.COLUMN_ICON, IconDB.COLUMN_LABEL}, IconDB.COLUMN_COMPONENT + " = ? AND " + IconDB.COLUMN_USER + " = ?", - new String[] {component.flattenToString(), - Long.toString(mUserManager.getSerialNumberForUser(user))}, + new String[] {cacheKey.componentName.flattenToString(), + Long.toString(mUserManager.getSerialNumberForUser(cacheKey.user))}, null, null, null); try { if (c.moveToNext()) { @@ -685,7 +695,8 @@ public class IconCache { entry.title = ""; entry.contentDescription = ""; } else { - entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user); + entry.contentDescription = mUserManager.getBadgedLabelForUser( + entry.title, cacheKey.user); } return true; } -- cgit v1.2.3 From df6ccf81960ab73d46570d56443e94c4df48e0c8 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Mon, 20 Jul 2015 14:32:48 -0700 Subject: Resizing the bitmap before caching it in the DB > The icon size in the backup can be different that what is required by the device. We should resize the icon, before caching it. Bug: 22413328 Change-Id: Id77c53edf8ea5e95a2d32dbe22be553120279ebd --- src/com/android/launcher3/IconCache.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/com/android/launcher3/IconCache.java') diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java index 916418f18..b4ca515d8 100644 --- a/src/com/android/launcher3/IconCache.java +++ b/src/com/android/launcher3/IconCache.java @@ -649,7 +649,7 @@ public class IconCache { * @param dpi the native density of the icon */ public void preloadIcon(ComponentName componentName, Bitmap icon, int dpi, String label, - long userSerial) { + long userSerial, InvariantDeviceProfile idp) { // TODO rescale to the correct native DPI try { PackageManager packageManager = mContext.getPackageManager(); @@ -660,7 +660,9 @@ public class IconCache { // pass } - ContentValues values = newContentValues(icon, label, Color.TRANSPARENT); + ContentValues values = newContentValues( + Bitmap.createScaledBitmap(icon, idp.iconBitmapSize, idp.iconBitmapSize, true), + label, Color.TRANSPARENT); values.put(IconDB.COLUMN_COMPONENT, componentName.flattenToString()); values.put(IconDB.COLUMN_USER, userSerial); mIconDb.getWritableDatabase().insertWithOnConflict(IconDB.TABLE_NAME, null, values, -- cgit v1.2.3 From a8b244e5b83e4e773411c134c7a8df2a2392fb44 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Fri, 28 Aug 2015 10:26:48 -0700 Subject: Using GET_UNINSTALLED_PACKAGES flag when getting packageInfo for a managed profile app Bug: 23515512 Change-Id: I60678eccd4b60225ff30960f7197d633f72c7659 --- src/com/android/launcher3/IconCache.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/com/android/launcher3/IconCache.java') diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java index ea1c0fd3e..59ab8397d 100644 --- a/src/com/android/launcher3/IconCache.java +++ b/src/com/android/launcher3/IconCache.java @@ -616,7 +616,9 @@ public class IconCache { // Check the DB first. if (!getEntryFromDB(cacheKey, entry, useLowResIcon)) { try { - PackageInfo info = mPackageManager.getPackageInfo(packageName, 0); + int flags = UserHandleCompat.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"); @@ -787,7 +789,7 @@ public class IconCache { } private static final class IconDB extends SQLiteOpenHelper { - private final static int DB_VERSION = 6; + private final static int DB_VERSION = 7; private final static String TABLE_NAME = "icons"; private final static String COLUMN_ROWID = "rowid"; -- cgit v1.2.3