blob: fff07c6ed4a73017de42610acec17cfb621a34da [file] [log] [blame]
Joe Onorato0589f0f2010-02-08 13:44:00 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
Joe Onorato0589f0f2010-02-08 13:44:00 -080018
Winson Chungd83f5f42012-02-13 14:27:42 -080019import android.app.ActivityManager;
Joe Onorato0589f0f2010-02-08 13:44:00 -080020import android.content.ComponentName;
Sunny Goyal4fbc3822015-02-18 16:46:50 -080021import android.content.ContentValues;
Winson Chungd83f5f42012-02-13 14:27:42 -080022import android.content.Context;
Joe Onorato0589f0f2010-02-08 13:44:00 -080023import android.content.Intent;
Michael Jurkadac85912012-05-18 15:04:49 -070024import android.content.pm.ActivityInfo;
Sunny Goyal0fc1be12014-08-11 17:05:23 -070025import android.content.pm.ApplicationInfo;
Sunny Goyal4fbc3822015-02-18 16:46:50 -080026import android.content.pm.PackageInfo;
Joe Onorato0589f0f2010-02-08 13:44:00 -080027import android.content.pm.PackageManager;
Sunny Goyal0fc1be12014-08-11 17:05:23 -070028import android.content.pm.PackageManager.NameNotFoundException;
Michael Jurkac9a96192010-11-01 11:52:08 -070029import android.content.res.Resources;
Sunny Goyal4fbc3822015-02-18 16:46:50 -080030import android.database.Cursor;
31import android.database.sqlite.SQLiteDatabase;
32import android.database.sqlite.SQLiteOpenHelper;
Joe Onorato0589f0f2010-02-08 13:44:00 -080033import android.graphics.Bitmap;
Sunny Goyal34b65272015-03-11 16:56:52 -070034import android.graphics.BitmapFactory;
Romain Guya28fd3f2010-03-15 14:44:42 -070035import android.graphics.Canvas;
Joe Onorato0589f0f2010-02-08 13:44:00 -080036import android.graphics.drawable.Drawable;
Sunny Goyal34b65272015-03-11 16:56:52 -070037import android.os.Handler;
Sunny Goyal34942622014-08-29 17:20:55 -070038import android.text.TextUtils;
Chris Wren6d0dde02014-02-10 12:16:54 -050039import android.util.Log;
Joe Onorato0589f0f2010-02-08 13:44:00 -080040
Kenny Guyed131872014-04-30 03:02:21 +010041import com.android.launcher3.compat.LauncherActivityInfoCompat;
42import com.android.launcher3.compat.LauncherAppsCompat;
43import com.android.launcher3.compat.UserHandleCompat;
44import com.android.launcher3.compat.UserManagerCompat;
Sunny Goyalb4cd42a2015-03-16 14:10:24 -070045import com.android.launcher3.util.ComponentKey;
Adam Cohen091440a2015-03-18 14:16:05 -070046import com.android.launcher3.util.Thunk;
Hyunyoung Song3f471442015-04-08 19:01:34 -070047import com.android.launcher3.widget.PackageItemInfo;
Kenny Guyed131872014-04-30 03:02:21 +010048
Joe Onorato0589f0f2010-02-08 13:44:00 -080049import java.util.HashMap;
Chris Wren6d0dde02014-02-10 12:16:54 -050050import java.util.HashSet;
Adam Cohenb6d33df2013-10-15 10:18:02 -070051import java.util.Iterator;
Sunny Goyal4fbc3822015-02-18 16:46:50 -080052import java.util.List;
Sunny Goyal0c9a3542015-04-01 16:04:21 -070053import java.util.Locale;
Adam Cohenb6d33df2013-10-15 10:18:02 -070054import java.util.Map.Entry;
Joe Onorato0589f0f2010-02-08 13:44:00 -080055
56/**
57 * Cache of application icons. Icons can be made from any thread.
58 */
59public class IconCache {
Sunny Goyal0fc1be12014-08-11 17:05:23 -070060
Joe Onorato0589f0f2010-02-08 13:44:00 -080061 private static final String TAG = "Launcher.IconCache";
62
63 private static final int INITIAL_ICON_CACHE_CAPACITY = 50;
Chris Wren6d0dde02014-02-10 12:16:54 -050064
Sunny Goyal0fc1be12014-08-11 17:05:23 -070065 // Empty class name is used for storing package default entry.
66 private static final String EMPTY_CLASS_NAME = ".";
67
Sunny Goyalbbef77d2014-09-09 16:27:55 -070068 private static final boolean DEBUG = false;
Joe Onorato0589f0f2010-02-08 13:44:00 -080069
Sunny Goyal34b65272015-03-11 16:56:52 -070070 private static final int LOW_RES_SCALE_FACTOR = 8;
71
Adam Cohen091440a2015-03-18 14:16:05 -070072 @Thunk static class CacheEntry {
Joe Onorato0589f0f2010-02-08 13:44:00 -080073 public Bitmap icon;
Kenny Guyd6fe5262014-07-21 17:11:41 +010074 public CharSequence title;
75 public CharSequence contentDescription;
Sunny Goyal34b65272015-03-11 16:56:52 -070076 public boolean isLowResIcon;
Joe Onorato0589f0f2010-02-08 13:44:00 -080077 }
78
Sunny Goyal8758ea02015-03-18 10:07:49 -070079 private final HashMap<UserHandleCompat, Bitmap> mDefaultIcons = new HashMap<>();
80 private final MainThreadExecutor mMainThreadExecutor = new MainThreadExecutor();
81
Daniel Sandlercc8befa2013-06-11 14:45:48 -040082 private final Context mContext;
Romain Guya28fd3f2010-03-15 14:44:42 -070083 private final PackageManager mPackageManager;
Kenny Guyed131872014-04-30 03:02:21 +010084 private final UserManagerCompat mUserManager;
85 private final LauncherAppsCompat mLauncherApps;
Sunny Goyalb4cd42a2015-03-16 14:10:24 -070086 private final HashMap<ComponentKey, CacheEntry> mCache =
87 new HashMap<ComponentKey, CacheEntry>(INITIAL_ICON_CACHE_CAPACITY);
Sunny Goyal4fbc3822015-02-18 16:46:50 -080088 private final int mIconDpi;
89 private final IconDB mIconDb;
Joe Onorato0589f0f2010-02-08 13:44:00 -080090
Sunny Goyal34b65272015-03-11 16:56:52 -070091 private final Handler mWorkerHandler;
92
Daniel Sandlercc8befa2013-06-11 14:45:48 -040093 public IconCache(Context context) {
Winson Chungd83f5f42012-02-13 14:27:42 -080094 ActivityManager activityManager =
95 (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
96
Joe Onorato0589f0f2010-02-08 13:44:00 -080097 mContext = context;
98 mPackageManager = context.getPackageManager();
Kenny Guyed131872014-04-30 03:02:21 +010099 mUserManager = UserManagerCompat.getInstance(mContext);
100 mLauncherApps = LauncherAppsCompat.getInstance(mContext);
Winson Chungd83f5f42012-02-13 14:27:42 -0800101 mIconDpi = activityManager.getLauncherLargeIconDensity();
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800102 mIconDb = new IconDB(context);
Sunny Goyal34b65272015-03-11 16:56:52 -0700103
Sunny Goyal756adbc2015-04-16 15:20:51 -0700104 mWorkerHandler = new Handler(LauncherModel.getWorkerLooper());
Romain Guya28fd3f2010-03-15 14:44:42 -0700105 }
106
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800107 private Drawable getFullResDefaultActivityIcon() {
Sunny Goyal736f5af2014-10-16 14:07:29 -0700108 return getFullResIcon(Resources.getSystem(), android.R.mipmap.sym_def_app_icon);
Michael Jurkac9a96192010-11-01 11:52:08 -0700109 }
110
Sunny Goyalb50cc8c2014-10-06 16:23:56 -0700111 private Drawable getFullResIcon(Resources resources, int iconId) {
Michael Jurka721d9722011-08-03 11:49:59 -0700112 Drawable d;
Michael Jurka4842ed02011-07-07 15:33:20 -0700113 try {
Michael Jurka721d9722011-08-03 11:49:59 -0700114 d = resources.getDrawableForDensity(iconId, mIconDpi);
Michael Jurka4842ed02011-07-07 15:33:20 -0700115 } catch (Resources.NotFoundException e) {
Michael Jurka721d9722011-08-03 11:49:59 -0700116 d = null;
Michael Jurka4842ed02011-07-07 15:33:20 -0700117 }
Michael Jurka721d9722011-08-03 11:49:59 -0700118
119 return (d != null) ? d : getFullResDefaultActivityIcon();
Michael Jurkac9a96192010-11-01 11:52:08 -0700120 }
121
Winson Chung0b9fcf52011-10-31 13:05:15 -0700122 public Drawable getFullResIcon(String packageName, int iconId) {
Michael Jurkac9a96192010-11-01 11:52:08 -0700123 Resources resources;
124 try {
Winson Chung0b9fcf52011-10-31 13:05:15 -0700125 resources = mPackageManager.getResourcesForApplication(packageName);
126 } catch (PackageManager.NameNotFoundException e) {
127 resources = null;
128 }
129 if (resources != null) {
130 if (iconId != 0) {
131 return getFullResIcon(resources, iconId);
132 }
133 }
134 return getFullResDefaultActivityIcon();
135 }
136
Sunny Goyalffe83f12014-08-14 17:39:34 -0700137 public int getFullResIconDpi() {
138 return mIconDpi;
139 }
140
Michael Jurkadac85912012-05-18 15:04:49 -0700141 public Drawable getFullResIcon(ActivityInfo info) {
Winson Chung0b9fcf52011-10-31 13:05:15 -0700142 Resources resources;
143 try {
144 resources = mPackageManager.getResourcesForApplication(
Michael Jurkadac85912012-05-18 15:04:49 -0700145 info.applicationInfo);
Michael Jurkac9a96192010-11-01 11:52:08 -0700146 } catch (PackageManager.NameNotFoundException e) {
147 resources = null;
148 }
149 if (resources != null) {
Michael Jurkadac85912012-05-18 15:04:49 -0700150 int iconId = info.getIconResource();
Michael Jurkac9a96192010-11-01 11:52:08 -0700151 if (iconId != 0) {
152 return getFullResIcon(resources, iconId);
153 }
154 }
Chris Wren6d0dde02014-02-10 12:16:54 -0500155
Michael Jurkac9a96192010-11-01 11:52:08 -0700156 return getFullResDefaultActivityIcon();
157 }
158
Kenny Guyed131872014-04-30 03:02:21 +0100159 private Bitmap makeDefaultIcon(UserHandleCompat user) {
160 Drawable unbadged = getFullResDefaultActivityIcon();
161 Drawable d = mUserManager.getBadgedDrawableForUser(unbadged, user);
Romain Guya28fd3f2010-03-15 14:44:42 -0700162 Bitmap b = Bitmap.createBitmap(Math.max(d.getIntrinsicWidth(), 1),
163 Math.max(d.getIntrinsicHeight(), 1),
164 Bitmap.Config.ARGB_8888);
165 Canvas c = new Canvas(b);
166 d.setBounds(0, 0, b.getWidth(), b.getHeight());
167 d.draw(c);
Adam Cohenaaf473c2011-08-03 12:02:47 -0700168 c.setBitmap(null);
Romain Guya28fd3f2010-03-15 14:44:42 -0700169 return b;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800170 }
171
172 /**
173 * Remove any records for the supplied ComponentName.
174 */
Sunny Goyal736f5af2014-10-16 14:07:29 -0700175 public synchronized void remove(ComponentName componentName, UserHandleCompat user) {
Sunny Goyalb4cd42a2015-03-16 14:10:24 -0700176 mCache.remove(new ComponentKey(componentName, user));
Joe Onorato0589f0f2010-02-08 13:44:00 -0800177 }
178
179 /**
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800180 * Remove any records for the supplied package name from memory.
Chris Wren6d0dde02014-02-10 12:16:54 -0500181 */
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800182 private void removeFromMemCacheLocked(String packageName, UserHandleCompat user) {
Sunny Goyalb4cd42a2015-03-16 14:10:24 -0700183 HashSet<ComponentKey> forDeletion = new HashSet<ComponentKey>();
184 for (ComponentKey key: mCache.keySet()) {
Kenny Guyed131872014-04-30 03:02:21 +0100185 if (key.componentName.getPackageName().equals(packageName)
186 && key.user.equals(user)) {
187 forDeletion.add(key);
Chris Wren6d0dde02014-02-10 12:16:54 -0500188 }
189 }
Sunny Goyalb4cd42a2015-03-16 14:10:24 -0700190 for (ComponentKey condemned: forDeletion) {
Kenny Guyed131872014-04-30 03:02:21 +0100191 mCache.remove(condemned);
Chris Wren6d0dde02014-02-10 12:16:54 -0500192 }
193 }
194
195 /**
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800196 * Updates the entries related to the given package in memory and persistent DB.
197 */
198 public synchronized void updateIconsForPkg(String packageName, UserHandleCompat user) {
199 removeIconsForPkg(packageName, user);
200 try {
201 PackageInfo info = mPackageManager.getPackageInfo(packageName,
202 PackageManager.GET_UNINSTALLED_PACKAGES);
203 long userSerial = mUserManager.getSerialNumberForUser(user);
204 for (LauncherActivityInfoCompat app : mLauncherApps.getActivityList(packageName, user)) {
Sunny Goyald180cf72015-04-06 12:45:40 -0700205 addIconToDBAndMemCache(app, info, userSerial);
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800206 }
207 } catch (NameNotFoundException e) {
208 Log.d(TAG, "Package not found", e);
209 return;
210 }
211 }
212
213 /**
214 * Removes the entries related to the given package in memory and persistent DB.
215 */
216 public synchronized void removeIconsForPkg(String packageName, UserHandleCompat user) {
217 removeFromMemCacheLocked(packageName, user);
218 long userSerial = mUserManager.getSerialNumberForUser(user);
219 mIconDb.getWritableDatabase().delete(IconDB.TABLE_NAME,
220 IconDB.COLUMN_COMPONENT + " LIKE ? AND " + IconDB.COLUMN_USER + " = ?",
221 new String[] {packageName + "/%", Long.toString(userSerial)});
222 }
223
224 /**
225 * Updates the persistent DB, such that only entries corresponding to {@param apps} remain in
226 * the DB and are updated.
227 * @return The set of packages for which icons have updated.
228 */
229 public HashSet<String> updateDBIcons(UserHandleCompat user, List<LauncherActivityInfoCompat> apps) {
Sunny Goyal0c9a3542015-04-01 16:04:21 -0700230 mIconDb.updateSystemStateString(mContext);
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800231 long userSerial = mUserManager.getSerialNumberForUser(user);
232 PackageManager pm = mContext.getPackageManager();
233 HashMap<String, PackageInfo> pkgInfoMap = new HashMap<String, PackageInfo>();
234 for (PackageInfo info : pm.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES)) {
235 pkgInfoMap.put(info.packageName, info);
236 }
237
238 HashMap<ComponentName, LauncherActivityInfoCompat> componentMap = new HashMap<>();
239 for (LauncherActivityInfoCompat app : apps) {
240 componentMap.put(app.getComponentName(), app);
241 }
242
243 Cursor c = mIconDb.getReadableDatabase().query(IconDB.TABLE_NAME,
244 new String[] {IconDB.COLUMN_ROWID, IconDB.COLUMN_COMPONENT,
Sunny Goyal0c9a3542015-04-01 16:04:21 -0700245 IconDB.COLUMN_LAST_UPDATED, IconDB.COLUMN_VERSION,
246 IconDB.COLUMN_SYSTEM_STATE},
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800247 IconDB.COLUMN_USER + " = ? ",
248 new String[] {Long.toString(userSerial)},
249 null, null, null);
250
251 final int indexComponent = c.getColumnIndex(IconDB.COLUMN_COMPONENT);
252 final int indexLastUpdate = c.getColumnIndex(IconDB.COLUMN_LAST_UPDATED);
253 final int indexVersion = c.getColumnIndex(IconDB.COLUMN_VERSION);
254 final int rowIndex = c.getColumnIndex(IconDB.COLUMN_ROWID);
Sunny Goyal0c9a3542015-04-01 16:04:21 -0700255 final int systemStateIndex = c.getColumnIndex(IconDB.COLUMN_SYSTEM_STATE);
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800256
257 HashSet<Integer> itemsToRemove = new HashSet<Integer>();
258 HashSet<String> updatedPackages = new HashSet<String>();
259
260 while (c.moveToNext()) {
261 String cn = c.getString(indexComponent);
262 ComponentName component = ComponentName.unflattenFromString(cn);
263 PackageInfo info = pkgInfoMap.get(component.getPackageName());
264 if (info == null) {
265 itemsToRemove.add(c.getInt(rowIndex));
266 continue;
267 }
268 if ((info.applicationInfo.flags & ApplicationInfo.FLAG_IS_DATA_ONLY) != 0) {
269 // Application is not present
270 continue;
271 }
272
273 long updateTime = c.getLong(indexLastUpdate);
274 int version = c.getInt(indexVersion);
275 LauncherActivityInfoCompat app = componentMap.remove(component);
Sunny Goyal0c9a3542015-04-01 16:04:21 -0700276 if (version == info.versionCode && updateTime == info.lastUpdateTime &&
277 TextUtils.equals(mIconDb.mSystemState, c.getString(systemStateIndex))) {
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800278 continue;
279 }
280 if (app == null) {
281 itemsToRemove.add(c.getInt(rowIndex));
282 continue;
283 }
284 ContentValues values = updateCacheAndGetContentValues(app);
285 mIconDb.getWritableDatabase().update(IconDB.TABLE_NAME, values,
Sunny Goyalece6c8b2015-04-13 11:47:00 -0700286 IconDB.COLUMN_COMPONENT + " = ? AND " + IconDB.COLUMN_USER + " = ?",
287 new String[] {cn, Long.toString(userSerial)});
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800288
289 updatedPackages.add(component.getPackageName());
290 }
291 c.close();
292 if (!itemsToRemove.isEmpty()) {
293 mIconDb.getWritableDatabase().delete(IconDB.TABLE_NAME,
294 IconDB.COLUMN_ROWID + " IN ( " + TextUtils.join(", ", itemsToRemove) +" )",
295 null);
296 }
297
298 // Insert remaining apps.
299 for (LauncherActivityInfoCompat app : componentMap.values()) {
300 PackageInfo info = pkgInfoMap.get(app.getComponentName().getPackageName());
301 if (info == null) {
302 continue;
303 }
Sunny Goyald180cf72015-04-06 12:45:40 -0700304 addIconToDBAndMemCache(app, info, userSerial);
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800305 }
306 return updatedPackages;
307 }
308
Sunny Goyald180cf72015-04-06 12:45:40 -0700309 private void addIconToDBAndMemCache(LauncherActivityInfoCompat app, PackageInfo info,
310 long userSerial) {
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800311 ContentValues values = updateCacheAndGetContentValues(app);
Sunny Goyald180cf72015-04-06 12:45:40 -0700312 addIconToDB(values, app.getComponentName(), info, userSerial);
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800313 values.put(IconDB.COLUMN_COMPONENT, app.getComponentName().flattenToString());
Sunny Goyald180cf72015-04-06 12:45:40 -0700314 }
315
316 /**
317 * Updates {@param values} to contain versoning information and adds it to the DB.
318 * @param values {@link ContentValues} containing icon & title
319 */
320 private void addIconToDB(ContentValues values, ComponentName key,
321 PackageInfo info, long userSerial) {
322 values.put(IconDB.COLUMN_COMPONENT, key.flattenToString());
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800323 values.put(IconDB.COLUMN_USER, userSerial);
324 values.put(IconDB.COLUMN_LAST_UPDATED, info.lastUpdateTime);
325 values.put(IconDB.COLUMN_VERSION, info.versionCode);
326 mIconDb.getWritableDatabase().insertWithOnConflict(IconDB.TABLE_NAME, null, values,
327 SQLiteDatabase.CONFLICT_REPLACE);
328 }
329
330 private ContentValues updateCacheAndGetContentValues(LauncherActivityInfoCompat app) {
331 CacheEntry entry = new CacheEntry();
332 entry.icon = Utilities.createIconBitmap(app.getBadgedIcon(mIconDpi), mContext);
333 entry.title = app.getLabel();
334 entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, app.getUser());
Sunny Goyalb4cd42a2015-03-16 14:10:24 -0700335 mCache.put(new ComponentKey(app.getComponentName(), app.getUser()), entry);
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800336
Sunny Goyal34b65272015-03-11 16:56:52 -0700337 return mIconDb.newContentValues(entry.icon, entry.title.toString());
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800338 }
339
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800340 /**
Joe Onorato0589f0f2010-02-08 13:44:00 -0800341 * Empty out the cache.
342 */
Sunny Goyal736f5af2014-10-16 14:07:29 -0700343 public synchronized void flush() {
344 mCache.clear();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800345 }
346
347 /**
Winson Chunge5467dc2013-10-14 17:03:04 -0700348 * Empty out the cache that aren't of the correct grid size
349 */
Sunny Goyal736f5af2014-10-16 14:07:29 -0700350 public synchronized void flushInvalidIcons(DeviceProfile grid) {
Sunny Goyalb4cd42a2015-03-16 14:10:24 -0700351 Iterator<Entry<ComponentKey, CacheEntry>> it = mCache.entrySet().iterator();
Sunny Goyal736f5af2014-10-16 14:07:29 -0700352 while (it.hasNext()) {
353 final CacheEntry e = it.next().getValue();
354 if ((e.icon != null) && (e.icon.getWidth() < grid.iconSizePx
355 || e.icon.getHeight() < grid.iconSizePx)) {
356 it.remove();
Winson Chunge5467dc2013-10-14 17:03:04 -0700357 }
358 }
359 }
360
361 /**
Sunny Goyal34b65272015-03-11 16:56:52 -0700362 * Fetches high-res icon for the provided ItemInfo and updates the caller when done.
363 * @return a request ID that can be used to cancel the request.
364 */
365 public IconLoadRequest updateIconInBackground(final BubbleTextView caller, final ItemInfo info) {
366 Runnable request = new Runnable() {
367
368 @Override
369 public void run() {
370 if (info instanceof AppInfo) {
371 getTitleAndIcon((AppInfo) info, null, false);
372 } else if (info instanceof ShortcutInfo) {
373 ShortcutInfo st = (ShortcutInfo) info;
374 getTitleAndIcon(st,
375 st.promisedIntent != null ? st.promisedIntent : st.intent,
376 st.user, false);
Sunny Goyal0e08f162015-05-12 11:32:39 -0700377 } else if (info instanceof PackageItemInfo) {
378 PackageItemInfo pti = (PackageItemInfo) info;
379 getTitleAndIconForApp(pti.packageName, pti.user, false, pti);
Sunny Goyal34b65272015-03-11 16:56:52 -0700380 }
Sunny Goyal8758ea02015-03-18 10:07:49 -0700381 mMainThreadExecutor.execute(new Runnable() {
Sunny Goyal34b65272015-03-11 16:56:52 -0700382
383 @Override
384 public void run() {
385 caller.reapplyItemInfo(info);
386 }
387 });
388 }
389 };
390 mWorkerHandler.post(request);
391 return new IconLoadRequest(request, mWorkerHandler);
392 }
393
Sunny Goyal756adbc2015-04-16 15:20:51 -0700394 private Bitmap getNonNullIcon(CacheEntry entry, UserHandleCompat user) {
395 return entry.icon == null ? getDefaultIcon(user) : entry.icon;
396 }
397
Sunny Goyal34b65272015-03-11 16:56:52 -0700398 /**
Joe Onorato0589f0f2010-02-08 13:44:00 -0800399 * Fill in "application" with the icon and label for "info."
400 */
Sunny Goyal34b65272015-03-11 16:56:52 -0700401 public synchronized void getTitleAndIcon(AppInfo application,
402 LauncherActivityInfoCompat info, boolean useLowResIcon) {
Sunny Goyal756adbc2015-04-16 15:20:51 -0700403 UserHandleCompat user = info == null ? application.user : info.getUser();
404 CacheEntry entry = cacheLocked(application.componentName, info, user,
Sunny Goyal34b65272015-03-11 16:56:52 -0700405 false, useLowResIcon);
Winson Chung82b016c2015-05-08 17:00:10 -0700406 application.title = Utilities.trim(entry.title);
Sunny Goyal756adbc2015-04-16 15:20:51 -0700407 application.iconBitmap = getNonNullIcon(entry, user);
Sunny Goyal736f5af2014-10-16 14:07:29 -0700408 application.contentDescription = entry.contentDescription;
Sunny Goyal34b65272015-03-11 16:56:52 -0700409 application.usingLowResIcon = entry.isLowResIcon;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800410 }
411
Sunny Goyal34b65272015-03-11 16:56:52 -0700412 /**
Sunny Goyal77919b92015-05-06 16:53:21 -0700413 * Updates {@param application} only if a valid entry is found.
414 */
415 public synchronized void updateTitleAndIcon(AppInfo application) {
416 CacheEntry entry = cacheLocked(application.componentName, null, application.user,
417 false, application.usingLowResIcon);
418 if (entry.icon != null && !isDefaultIcon(entry.icon, application.user)) {
Winson Chung82b016c2015-05-08 17:00:10 -0700419 application.title = Utilities.trim(entry.title);
Sunny Goyal77919b92015-05-06 16:53:21 -0700420 application.iconBitmap = entry.icon;
421 application.contentDescription = entry.contentDescription;
422 application.usingLowResIcon = entry.isLowResIcon;
423 }
424 }
425
426 /**
Sunny Goyal34b65272015-03-11 16:56:52 -0700427 * Returns a high res icon for the given intent and user
428 */
Sunny Goyal736f5af2014-10-16 14:07:29 -0700429 public synchronized Bitmap getIcon(Intent intent, UserHandleCompat user) {
430 ComponentName component = intent.getComponent();
431 // null info means not installed, but if we have a component from the intent then
432 // we should still look in the cache for restored app icons.
433 if (component == null) {
434 return getDefaultIcon(user);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800435 }
Sunny Goyal736f5af2014-10-16 14:07:29 -0700436
437 LauncherActivityInfoCompat launcherActInfo = mLauncherApps.resolveActivity(intent, user);
Sunny Goyal34b65272015-03-11 16:56:52 -0700438 CacheEntry entry = cacheLocked(component, launcherActInfo, user, true, true);
Sunny Goyal736f5af2014-10-16 14:07:29 -0700439 return entry.icon;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800440 }
441
Sunny Goyal34942622014-08-29 17:20:55 -0700442 /**
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800443 * Fill in {@param shortcutInfo} with the icon and label for {@param intent}. If the
444 * corresponding activity is not found, it reverts to the package icon.
Sunny Goyal34942622014-08-29 17:20:55 -0700445 */
Sunny Goyal736f5af2014-10-16 14:07:29 -0700446 public synchronized void getTitleAndIcon(ShortcutInfo shortcutInfo, Intent intent,
Sunny Goyal34b65272015-03-11 16:56:52 -0700447 UserHandleCompat user, boolean useLowResIcon) {
Sunny Goyal736f5af2014-10-16 14:07:29 -0700448 ComponentName component = intent.getComponent();
449 // null info means not installed, but if we have a component from the intent then
450 // we should still look in the cache for restored app icons.
451 if (component == null) {
452 shortcutInfo.setIcon(getDefaultIcon(user));
453 shortcutInfo.title = "";
454 shortcutInfo.usingFallbackIcon = true;
Sunny Goyal34b65272015-03-11 16:56:52 -0700455 shortcutInfo.usingLowResIcon = false;
Sunny Goyal736f5af2014-10-16 14:07:29 -0700456 } else {
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800457 LauncherActivityInfoCompat info = mLauncherApps.resolveActivity(intent, user);
Sunny Goyal34b65272015-03-11 16:56:52 -0700458 getTitleAndIcon(shortcutInfo, component, info, user, true, useLowResIcon);
Sunny Goyal34942622014-08-29 17:20:55 -0700459 }
460 }
461
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800462 /**
463 * Fill in {@param shortcutInfo} with the icon and label for {@param info}
464 */
465 public synchronized void getTitleAndIcon(
466 ShortcutInfo shortcutInfo, ComponentName component, LauncherActivityInfoCompat info,
Sunny Goyal34b65272015-03-11 16:56:52 -0700467 UserHandleCompat user, boolean usePkgIcon, boolean useLowResIcon) {
468 CacheEntry entry = cacheLocked(component, info, user, usePkgIcon, useLowResIcon);
Sunny Goyal756adbc2015-04-16 15:20:51 -0700469 shortcutInfo.setIcon(getNonNullIcon(entry, user));
Winson Chung82b016c2015-05-08 17:00:10 -0700470 shortcutInfo.title = Utilities.trim(entry.title);
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800471 shortcutInfo.usingFallbackIcon = isDefaultIcon(entry.icon, user);
Sunny Goyal34b65272015-03-11 16:56:52 -0700472 shortcutInfo.usingLowResIcon = entry.isLowResIcon;
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800473 }
Sunny Goyal34942622014-08-29 17:20:55 -0700474
Sunny Goyald180cf72015-04-06 12:45:40 -0700475 /**
476 * Fill in {@param appInfo} with the icon and label for {@param packageName}
477 */
478 public synchronized void getTitleAndIconForApp(
Hyunyoung Song3f471442015-04-08 19:01:34 -0700479 String packageName, UserHandleCompat user, boolean useLowResIcon,
480 PackageItemInfo infoOut) {
Sunny Goyald180cf72015-04-06 12:45:40 -0700481 CacheEntry entry = getEntryForPackageLocked(packageName, user, useLowResIcon);
Sunny Goyal756adbc2015-04-16 15:20:51 -0700482 infoOut.iconBitmap = getNonNullIcon(entry, user);
Winson Chung82b016c2015-05-08 17:00:10 -0700483 infoOut.title = Utilities.trim(entry.title);
Hyunyoung Song3f471442015-04-08 19:01:34 -0700484 infoOut.usingLowResIcon = entry.isLowResIcon;
485 infoOut.contentDescription = entry.contentDescription;
Sunny Goyald180cf72015-04-06 12:45:40 -0700486 }
487
Sunny Goyal736f5af2014-10-16 14:07:29 -0700488 public synchronized Bitmap getDefaultIcon(UserHandleCompat user) {
Kenny Guyed131872014-04-30 03:02:21 +0100489 if (!mDefaultIcons.containsKey(user)) {
490 mDefaultIcons.put(user, makeDefaultIcon(user));
491 }
492 return mDefaultIcons.get(user);
493 }
494
Kenny Guyed131872014-04-30 03:02:21 +0100495 public boolean isDefaultIcon(Bitmap icon, UserHandleCompat user) {
496 return mDefaultIcons.get(user) == icon;
Joe Onoratoddc9c1f2010-08-30 18:30:15 -0700497 }
498
Sunny Goyal736f5af2014-10-16 14:07:29 -0700499 /**
500 * Retrieves the entry from the cache. If the entry is not present, it creates a new entry.
501 * This method is not thread safe, it must be called from a synchronized method.
502 */
Kenny Guyed131872014-04-30 03:02:21 +0100503 private CacheEntry cacheLocked(ComponentName componentName, LauncherActivityInfoCompat info,
Sunny Goyal34b65272015-03-11 16:56:52 -0700504 UserHandleCompat user, boolean usePackageIcon, boolean useLowResIcon) {
Sunny Goyalb4cd42a2015-03-16 14:10:24 -0700505 ComponentKey cacheKey = new ComponentKey(componentName, user);
Kenny Guyed131872014-04-30 03:02:21 +0100506 CacheEntry entry = mCache.get(cacheKey);
Sunny Goyal34b65272015-03-11 16:56:52 -0700507 if (entry == null || (entry.isLowResIcon && !useLowResIcon)) {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800508 entry = new CacheEntry();
Kenny Guyed131872014-04-30 03:02:21 +0100509 mCache.put(cacheKey, entry);
Joe Onorato84f6a8d2010-02-12 17:53:35 -0500510
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800511 // Check the DB first.
Sunny Goyal34b65272015-03-11 16:56:52 -0700512 if (!getEntryFromDB(componentName, user, entry, useLowResIcon)) {
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800513 if (info != null) {
514 entry.icon = Utilities.createIconBitmap(info.getBadgedIcon(mIconDpi), mContext);
Chris Wren6d0dde02014-02-10 12:16:54 -0500515 } else {
Sunny Goyal0fc1be12014-08-11 17:05:23 -0700516 if (usePackageIcon) {
Sunny Goyald180cf72015-04-06 12:45:40 -0700517 CacheEntry packageEntry = getEntryForPackageLocked(
518 componentName.getPackageName(), user, false);
Sunny Goyal34942622014-08-29 17:20:55 -0700519 if (packageEntry != null) {
Sunny Goyal0fc1be12014-08-11 17:05:23 -0700520 if (DEBUG) Log.d(TAG, "using package default icon for " +
521 componentName.toShortString());
522 entry.icon = packageEntry.icon;
Sunny Goyal34942622014-08-29 17:20:55 -0700523 entry.title = packageEntry.title;
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800524 entry.contentDescription = packageEntry.contentDescription;
Sunny Goyal0fc1be12014-08-11 17:05:23 -0700525 }
526 }
527 if (entry.icon == null) {
528 if (DEBUG) Log.d(TAG, "using default icon for " +
529 componentName.toShortString());
530 entry.icon = getDefaultIcon(user);
531 }
Winson Chungc3eecff2011-07-11 17:44:15 -0700532 }
533 }
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800534
535 if (TextUtils.isEmpty(entry.title) && info != null) {
Winson Chung82b016c2015-05-08 17:00:10 -0700536 entry.title = info.getLabel();
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800537 entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user);
538 }
Joe Onorato0589f0f2010-02-08 13:44:00 -0800539 }
540 return entry;
541 }
Daniel Sandler4e1cd232011-05-12 00:06:32 -0400542
Sunny Goyal0fc1be12014-08-11 17:05:23 -0700543 /**
Sunny Goyal34942622014-08-29 17:20:55 -0700544 * Adds a default package entry in the cache. This entry is not persisted and will be removed
545 * when the cache is flushed.
546 */
Sunny Goyal736f5af2014-10-16 14:07:29 -0700547 public synchronized void cachePackageInstallInfo(String packageName, UserHandleCompat user,
Sunny Goyal34942622014-08-29 17:20:55 -0700548 Bitmap icon, CharSequence title) {
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800549 removeFromMemCacheLocked(packageName, user);
Sunny Goyala22666f2014-09-18 13:25:15 -0700550
Sunny Goyald180cf72015-04-06 12:45:40 -0700551 CacheEntry entry = getEntryForPackageLocked(packageName, user, false);
Sunny Goyal34942622014-08-29 17:20:55 -0700552 if (!TextUtils.isEmpty(title)) {
553 entry.title = title;
554 }
555 if (icon != null) {
Sunny Goyal2fce90c2014-10-07 12:01:58 -0700556 entry.icon = Utilities.createIconBitmap(icon, mContext);
Sunny Goyal34942622014-08-29 17:20:55 -0700557 }
558 }
559
560 /**
Sunny Goyal0fc1be12014-08-11 17:05:23 -0700561 * Gets an entry for the package, which can be used as a fallback entry for various components.
Sunny Goyal736f5af2014-10-16 14:07:29 -0700562 * This method is not thread safe, it must be called from a synchronized method.
Sunny Goyald180cf72015-04-06 12:45:40 -0700563 *
Sunny Goyal0fc1be12014-08-11 17:05:23 -0700564 */
Sunny Goyald180cf72015-04-06 12:45:40 -0700565 private CacheEntry getEntryForPackageLocked(String packageName, UserHandleCompat user,
566 boolean useLowResIcon) {
567 ComponentName cn = new ComponentName(packageName, EMPTY_CLASS_NAME);
Sunny Goyalb4cd42a2015-03-16 14:10:24 -0700568 ComponentKey cacheKey = new ComponentKey(cn, user);
Sunny Goyal0fc1be12014-08-11 17:05:23 -0700569 CacheEntry entry = mCache.get(cacheKey);
Sunny Goyald180cf72015-04-06 12:45:40 -0700570 if (entry == null || (entry.isLowResIcon && !useLowResIcon)) {
Sunny Goyal0fc1be12014-08-11 17:05:23 -0700571 entry = new CacheEntry();
572 mCache.put(cacheKey, entry);
573
Sunny Goyald180cf72015-04-06 12:45:40 -0700574 // Check the DB first.
575 if (!getEntryFromDB(cn, user, entry, useLowResIcon)) {
576 try {
577 PackageInfo info = mPackageManager.getPackageInfo(packageName, 0);
578 ApplicationInfo appInfo = info.applicationInfo;
579 if (appInfo == null) {
580 throw new NameNotFoundException("ApplicationInfo is null");
581 }
582 Drawable drawable = mUserManager.getBadgedDrawableForUser(
583 appInfo.loadIcon(mPackageManager), user);
584 entry.icon = Utilities.createIconBitmap(drawable, mContext);
585 entry.title = appInfo.loadLabel(mPackageManager);
586 entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user);
587 entry.isLowResIcon = false;
588
589 // Add the icon in the DB here, since these do not get written during
590 // package updates.
591 ContentValues values =
592 mIconDb.newContentValues(entry.icon, entry.title.toString());
593 addIconToDB(values, cn, info, mUserManager.getSerialNumberForUser(user));
594
595 } catch (NameNotFoundException e) {
596 if (DEBUG) Log.d(TAG, "Application not installed " + packageName);
597 }
Sunny Goyal0fc1be12014-08-11 17:05:23 -0700598 }
Sunny Goyal0fc1be12014-08-11 17:05:23 -0700599 }
600 return entry;
601 }
602
Chris Wren6d0dde02014-02-10 12:16:54 -0500603 /**
604 * Pre-load an icon into the persistent cache.
605 *
606 * <P>Queries for a component that does not exist in the package manager
607 * will be answered by the persistent cache.
608 *
Chris Wren6d0dde02014-02-10 12:16:54 -0500609 * @param componentName the icon should be returned for this component
610 * @param icon the icon to be persisted
611 * @param dpi the native density of the icon
612 */
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800613 public void preloadIcon(ComponentName componentName, Bitmap icon, int dpi, String label,
614 long userSerial) {
Chris Wren6d0dde02014-02-10 12:16:54 -0500615 // TODO rescale to the correct native DPI
616 try {
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800617 PackageManager packageManager = mContext.getPackageManager();
Chris Wren6d0dde02014-02-10 12:16:54 -0500618 packageManager.getActivityIcon(componentName);
619 // component is present on the system already, do nothing
620 return;
621 } catch (PackageManager.NameNotFoundException e) {
622 // pass
623 }
624
Sunny Goyal34b65272015-03-11 16:56:52 -0700625 ContentValues values = mIconDb.newContentValues(icon, label);
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800626 values.put(IconDB.COLUMN_COMPONENT, componentName.flattenToString());
627 values.put(IconDB.COLUMN_USER, userSerial);
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800628 mIconDb.getWritableDatabase().insertWithOnConflict(IconDB.TABLE_NAME, null, values,
629 SQLiteDatabase.CONFLICT_REPLACE);
630 }
631
Sunny Goyal34b65272015-03-11 16:56:52 -0700632 private boolean getEntryFromDB(ComponentName component, UserHandleCompat user,
633 CacheEntry entry, boolean lowRes) {
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800634 Cursor c = mIconDb.getReadableDatabase().query(IconDB.TABLE_NAME,
Sunny Goyal34b65272015-03-11 16:56:52 -0700635 new String[] {lowRes ? IconDB.COLUMN_ICON_LOW_RES : IconDB.COLUMN_ICON,
636 IconDB.COLUMN_LABEL},
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800637 IconDB.COLUMN_COMPONENT + " = ? AND " + IconDB.COLUMN_USER + " = ?",
638 new String[] {component.flattenToString(),
639 Long.toString(mUserManager.getSerialNumberForUser(user))},
640 null, null, null);
Chris Wren6d0dde02014-02-10 12:16:54 -0500641 try {
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800642 if (c.moveToNext()) {
Sunny Goyal34b65272015-03-11 16:56:52 -0700643 entry.icon = loadIconNoResize(c, 0);
644 entry.isLowResIcon = lowRes;
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800645 entry.title = c.getString(1);
646 if (entry.title == null) {
647 entry.title = "";
648 entry.contentDescription = "";
649 } else {
650 entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user);
Chris Wren6d0dde02014-02-10 12:16:54 -0500651 }
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800652 return true;
Chris Wren6d0dde02014-02-10 12:16:54 -0500653 }
Chris Wren6d0dde02014-02-10 12:16:54 -0500654 } finally {
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800655 c.close();
656 }
657 return false;
658 }
659
Sunny Goyal34b65272015-03-11 16:56:52 -0700660 public static class IconLoadRequest {
661 private final Runnable mRunnable;
662 private final Handler mHandler;
663
664 IconLoadRequest(Runnable runnable, Handler handler) {
665 mRunnable = runnable;
666 mHandler = handler;
667 }
668
669 public void cancel() {
670 mHandler.removeCallbacks(mRunnable);
671 }
672 }
673
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800674 private static final class IconDB extends SQLiteOpenHelper {
Sunny Goyal77919b92015-05-06 16:53:21 -0700675 private final static int DB_VERSION = 4;
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800676
677 private final static String TABLE_NAME = "icons";
678 private final static String COLUMN_ROWID = "rowid";
679 private final static String COLUMN_COMPONENT = "componentName";
680 private final static String COLUMN_USER = "profileId";
681 private final static String COLUMN_LAST_UPDATED = "lastUpdated";
682 private final static String COLUMN_VERSION = "version";
683 private final static String COLUMN_ICON = "icon";
Sunny Goyal34b65272015-03-11 16:56:52 -0700684 private final static String COLUMN_ICON_LOW_RES = "icon_low_res";
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800685 private final static String COLUMN_LABEL = "label";
Sunny Goyal0c9a3542015-04-01 16:04:21 -0700686 private final static String COLUMN_SYSTEM_STATE = "system_state";
687
688 public String mSystemState;
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800689
690 public IconDB(Context context) {
691 super(context, LauncherFiles.APP_ICONS_DB, null, DB_VERSION);
Sunny Goyal0c9a3542015-04-01 16:04:21 -0700692 updateSystemStateString(context);
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800693 }
694
Sunny Goyal0c9a3542015-04-01 16:04:21 -0700695 public void updateSystemStateString(Context c) {
696 mSystemState = Locale.getDefault().toString() + ","
697 + c.getResources().getConfiguration().mcc;
698 }
699
700
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800701 @Override
702 public void onCreate(SQLiteDatabase db) {
703 db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " (" +
704 COLUMN_COMPONENT + " TEXT NOT NULL, " +
705 COLUMN_USER + " INTEGER NOT NULL, " +
706 COLUMN_LAST_UPDATED + " INTEGER NOT NULL DEFAULT 0, " +
707 COLUMN_VERSION + " INTEGER NOT NULL DEFAULT 0, " +
708 COLUMN_ICON + " BLOB, " +
Sunny Goyal34b65272015-03-11 16:56:52 -0700709 COLUMN_ICON_LOW_RES + " BLOB, " +
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800710 COLUMN_LABEL + " TEXT, " +
Sunny Goyal0c9a3542015-04-01 16:04:21 -0700711 COLUMN_SYSTEM_STATE + " TEXT, " +
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800712 "PRIMARY KEY (" + COLUMN_COMPONENT + ", " + COLUMN_USER + ") " +
713 ");");
714 }
715
716 @Override
717 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
718 if (oldVersion != newVersion) {
719 clearDB(db);
Chris Wren6d0dde02014-02-10 12:16:54 -0500720 }
721 }
722
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800723 @Override
724 public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
725 if (oldVersion != newVersion) {
726 clearDB(db);
727 }
Kenny Guyed131872014-04-30 03:02:21 +0100728 }
Chris Wren6d0dde02014-02-10 12:16:54 -0500729
Sunny Goyal4fbc3822015-02-18 16:46:50 -0800730 private void clearDB(SQLiteDatabase db) {
731 db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
732 onCreate(db);
733 }
Sunny Goyal34b65272015-03-11 16:56:52 -0700734
735 public ContentValues newContentValues(Bitmap icon, String label) {
736 ContentValues values = new ContentValues();
Sunny Goyal0c9a3542015-04-01 16:04:21 -0700737 values.put(COLUMN_ICON, Utilities.flattenBitmap(icon));
738 values.put(COLUMN_ICON_LOW_RES, Utilities.flattenBitmap(
Sunny Goyal34b65272015-03-11 16:56:52 -0700739 Bitmap.createScaledBitmap(icon,
740 icon.getWidth() / LOW_RES_SCALE_FACTOR,
741 icon.getHeight() / LOW_RES_SCALE_FACTOR, true)));
Sunny Goyal0c9a3542015-04-01 16:04:21 -0700742 values.put(COLUMN_LABEL, label);
743 values.put(COLUMN_SYSTEM_STATE, mSystemState);
Sunny Goyal34b65272015-03-11 16:56:52 -0700744 return values;
745 }
746 }
747
748 private static Bitmap loadIconNoResize(Cursor c, int iconIndex) {
749 byte[] data = c.getBlob(iconIndex);
750 try {
751 return BitmapFactory.decodeByteArray(data, 0, data.length);
752 } catch (Exception e) {
753 return null;
754 }
Chris Wren6d0dde02014-02-10 12:16:54 -0500755 }
Joe Onorato0589f0f2010-02-08 13:44:00 -0800756}