Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1 | /* |
| 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 Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 17 | package com.android.launcher3; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 18 | |
Winson Chung | d83f5f4 | 2012-02-13 14:27:42 -0800 | [diff] [blame] | 19 | import android.app.ActivityManager; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 20 | import android.content.ComponentName; |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 21 | import android.content.ContentValues; |
Winson Chung | d83f5f4 | 2012-02-13 14:27:42 -0800 | [diff] [blame] | 22 | import android.content.Context; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 23 | import android.content.Intent; |
Michael Jurka | dac8591 | 2012-05-18 15:04:49 -0700 | [diff] [blame] | 24 | import android.content.pm.ActivityInfo; |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 25 | import android.content.pm.ApplicationInfo; |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 26 | import android.content.pm.PackageInfo; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 27 | import android.content.pm.PackageManager; |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 28 | import android.content.pm.PackageManager.NameNotFoundException; |
Michael Jurka | c9a9619 | 2010-11-01 11:52:08 -0700 | [diff] [blame] | 29 | import android.content.res.Resources; |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 30 | import android.database.Cursor; |
| 31 | import android.database.sqlite.SQLiteDatabase; |
| 32 | import android.database.sqlite.SQLiteOpenHelper; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 33 | import android.graphics.Bitmap; |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 34 | import android.graphics.BitmapFactory; |
Romain Guy | a28fd3f | 2010-03-15 14:44:42 -0700 | [diff] [blame] | 35 | import android.graphics.Canvas; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 36 | import android.graphics.drawable.Drawable; |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 37 | import android.os.Handler; |
Sunny Goyal | 75b0f55 | 2015-05-20 21:57:06 -0700 | [diff] [blame] | 38 | import android.os.SystemClock; |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 39 | import android.text.TextUtils; |
Chris Wren | 6d0dde0 | 2014-02-10 12:16:54 -0500 | [diff] [blame] | 40 | import android.util.Log; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 41 | |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 42 | import com.android.launcher3.compat.LauncherActivityInfoCompat; |
| 43 | import com.android.launcher3.compat.LauncherAppsCompat; |
| 44 | import com.android.launcher3.compat.UserHandleCompat; |
| 45 | import com.android.launcher3.compat.UserManagerCompat; |
Hyunyoung Song | 2bd3d7d | 2015-05-21 13:04:53 -0700 | [diff] [blame] | 46 | import com.android.launcher3.model.PackageItemInfo; |
Sunny Goyal | b4cd42a | 2015-03-16 14:10:24 -0700 | [diff] [blame] | 47 | import com.android.launcher3.util.ComponentKey; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 48 | import com.android.launcher3.util.Thunk; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 49 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 50 | import java.util.HashMap; |
Chris Wren | 6d0dde0 | 2014-02-10 12:16:54 -0500 | [diff] [blame] | 51 | import java.util.HashSet; |
Adam Cohen | b6d33df | 2013-10-15 10:18:02 -0700 | [diff] [blame] | 52 | import java.util.Iterator; |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 53 | import java.util.List; |
Sunny Goyal | 0c9a354 | 2015-04-01 16:04:21 -0700 | [diff] [blame] | 54 | import java.util.Locale; |
Adam Cohen | b6d33df | 2013-10-15 10:18:02 -0700 | [diff] [blame] | 55 | import java.util.Map.Entry; |
Sunny Goyal | 9ff9808 | 2015-05-15 16:59:36 -0700 | [diff] [blame] | 56 | import java.util.Stack; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 57 | |
| 58 | /** |
| 59 | * Cache of application icons. Icons can be made from any thread. |
| 60 | */ |
| 61 | public class IconCache { |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 62 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 63 | private static final String TAG = "Launcher.IconCache"; |
| 64 | |
| 65 | private static final int INITIAL_ICON_CACHE_CAPACITY = 50; |
Chris Wren | 6d0dde0 | 2014-02-10 12:16:54 -0500 | [diff] [blame] | 66 | |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 67 | // Empty class name is used for storing package default entry. |
| 68 | private static final String EMPTY_CLASS_NAME = "."; |
| 69 | |
Sunny Goyal | bbef77d | 2014-09-09 16:27:55 -0700 | [diff] [blame] | 70 | private static final boolean DEBUG = false; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 71 | |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 72 | private static final int LOW_RES_SCALE_FACTOR = 8; |
| 73 | |
Sunny Goyal | 75b0f55 | 2015-05-20 21:57:06 -0700 | [diff] [blame] | 74 | private static final Object ICON_UPDATE_TOKEN = new Object(); |
| 75 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 76 | @Thunk static class CacheEntry { |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 77 | public Bitmap icon; |
Kenny Guy | d6fe526 | 2014-07-21 17:11:41 +0100 | [diff] [blame] | 78 | public CharSequence title; |
| 79 | public CharSequence contentDescription; |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 80 | public boolean isLowResIcon; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Sunny Goyal | 8758ea0 | 2015-03-18 10:07:49 -0700 | [diff] [blame] | 83 | private final HashMap<UserHandleCompat, Bitmap> mDefaultIcons = new HashMap<>(); |
| 84 | private final MainThreadExecutor mMainThreadExecutor = new MainThreadExecutor(); |
| 85 | |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 86 | private final Context mContext; |
Romain Guy | a28fd3f | 2010-03-15 14:44:42 -0700 | [diff] [blame] | 87 | private final PackageManager mPackageManager; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 88 | private final UserManagerCompat mUserManager; |
| 89 | private final LauncherAppsCompat mLauncherApps; |
Sunny Goyal | b4cd42a | 2015-03-16 14:10:24 -0700 | [diff] [blame] | 90 | private final HashMap<ComponentKey, CacheEntry> mCache = |
| 91 | new HashMap<ComponentKey, CacheEntry>(INITIAL_ICON_CACHE_CAPACITY); |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 92 | private final int mIconDpi; |
| 93 | private final IconDB mIconDb; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 94 | |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 95 | private final Handler mWorkerHandler; |
| 96 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 97 | public IconCache(Context context, InvariantDeviceProfile inv) { |
Winson Chung | d83f5f4 | 2012-02-13 14:27:42 -0800 | [diff] [blame] | 98 | ActivityManager activityManager = |
| 99 | (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
| 100 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 101 | mContext = context; |
| 102 | mPackageManager = context.getPackageManager(); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 103 | mUserManager = UserManagerCompat.getInstance(mContext); |
| 104 | mLauncherApps = LauncherAppsCompat.getInstance(mContext); |
Winson Chung | d83f5f4 | 2012-02-13 14:27:42 -0800 | [diff] [blame] | 105 | mIconDpi = activityManager.getLauncherLargeIconDensity(); |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 106 | mIconDb = new IconDB(context); |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 107 | |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 108 | mWorkerHandler = new Handler(LauncherModel.getWorkerLooper()); |
Romain Guy | a28fd3f | 2010-03-15 14:44:42 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 111 | private Drawable getFullResDefaultActivityIcon() { |
Sunny Goyal | 736f5af | 2014-10-16 14:07:29 -0700 | [diff] [blame] | 112 | return getFullResIcon(Resources.getSystem(), android.R.mipmap.sym_def_app_icon); |
Michael Jurka | c9a9619 | 2010-11-01 11:52:08 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 115 | private Drawable getFullResIcon(Resources resources, int iconId) { |
Michael Jurka | 721d972 | 2011-08-03 11:49:59 -0700 | [diff] [blame] | 116 | Drawable d; |
Michael Jurka | 4842ed0 | 2011-07-07 15:33:20 -0700 | [diff] [blame] | 117 | try { |
Michael Jurka | 721d972 | 2011-08-03 11:49:59 -0700 | [diff] [blame] | 118 | d = resources.getDrawableForDensity(iconId, mIconDpi); |
Michael Jurka | 4842ed0 | 2011-07-07 15:33:20 -0700 | [diff] [blame] | 119 | } catch (Resources.NotFoundException e) { |
Michael Jurka | 721d972 | 2011-08-03 11:49:59 -0700 | [diff] [blame] | 120 | d = null; |
Michael Jurka | 4842ed0 | 2011-07-07 15:33:20 -0700 | [diff] [blame] | 121 | } |
Michael Jurka | 721d972 | 2011-08-03 11:49:59 -0700 | [diff] [blame] | 122 | |
| 123 | return (d != null) ? d : getFullResDefaultActivityIcon(); |
Michael Jurka | c9a9619 | 2010-11-01 11:52:08 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Winson Chung | 0b9fcf5 | 2011-10-31 13:05:15 -0700 | [diff] [blame] | 126 | public Drawable getFullResIcon(String packageName, int iconId) { |
Michael Jurka | c9a9619 | 2010-11-01 11:52:08 -0700 | [diff] [blame] | 127 | Resources resources; |
| 128 | try { |
Winson Chung | 0b9fcf5 | 2011-10-31 13:05:15 -0700 | [diff] [blame] | 129 | resources = mPackageManager.getResourcesForApplication(packageName); |
| 130 | } catch (PackageManager.NameNotFoundException e) { |
| 131 | resources = null; |
| 132 | } |
| 133 | if (resources != null) { |
| 134 | if (iconId != 0) { |
| 135 | return getFullResIcon(resources, iconId); |
| 136 | } |
| 137 | } |
| 138 | return getFullResDefaultActivityIcon(); |
| 139 | } |
| 140 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 141 | public int getFullResIconDpi() { |
| 142 | return mIconDpi; |
| 143 | } |
| 144 | |
Michael Jurka | dac8591 | 2012-05-18 15:04:49 -0700 | [diff] [blame] | 145 | public Drawable getFullResIcon(ActivityInfo info) { |
Winson Chung | 0b9fcf5 | 2011-10-31 13:05:15 -0700 | [diff] [blame] | 146 | Resources resources; |
| 147 | try { |
| 148 | resources = mPackageManager.getResourcesForApplication( |
Michael Jurka | dac8591 | 2012-05-18 15:04:49 -0700 | [diff] [blame] | 149 | info.applicationInfo); |
Michael Jurka | c9a9619 | 2010-11-01 11:52:08 -0700 | [diff] [blame] | 150 | } catch (PackageManager.NameNotFoundException e) { |
| 151 | resources = null; |
| 152 | } |
| 153 | if (resources != null) { |
Michael Jurka | dac8591 | 2012-05-18 15:04:49 -0700 | [diff] [blame] | 154 | int iconId = info.getIconResource(); |
Michael Jurka | c9a9619 | 2010-11-01 11:52:08 -0700 | [diff] [blame] | 155 | if (iconId != 0) { |
| 156 | return getFullResIcon(resources, iconId); |
| 157 | } |
| 158 | } |
Chris Wren | 6d0dde0 | 2014-02-10 12:16:54 -0500 | [diff] [blame] | 159 | |
Michael Jurka | c9a9619 | 2010-11-01 11:52:08 -0700 | [diff] [blame] | 160 | return getFullResDefaultActivityIcon(); |
| 161 | } |
| 162 | |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 163 | private Bitmap makeDefaultIcon(UserHandleCompat user) { |
| 164 | Drawable unbadged = getFullResDefaultActivityIcon(); |
| 165 | Drawable d = mUserManager.getBadgedDrawableForUser(unbadged, user); |
Romain Guy | a28fd3f | 2010-03-15 14:44:42 -0700 | [diff] [blame] | 166 | Bitmap b = Bitmap.createBitmap(Math.max(d.getIntrinsicWidth(), 1), |
| 167 | Math.max(d.getIntrinsicHeight(), 1), |
| 168 | Bitmap.Config.ARGB_8888); |
| 169 | Canvas c = new Canvas(b); |
| 170 | d.setBounds(0, 0, b.getWidth(), b.getHeight()); |
| 171 | d.draw(c); |
Adam Cohen | aaf473c | 2011-08-03 12:02:47 -0700 | [diff] [blame] | 172 | c.setBitmap(null); |
Romain Guy | a28fd3f | 2010-03-15 14:44:42 -0700 | [diff] [blame] | 173 | return b; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Remove any records for the supplied ComponentName. |
| 178 | */ |
Sunny Goyal | 736f5af | 2014-10-16 14:07:29 -0700 | [diff] [blame] | 179 | public synchronized void remove(ComponentName componentName, UserHandleCompat user) { |
Sunny Goyal | b4cd42a | 2015-03-16 14:10:24 -0700 | [diff] [blame] | 180 | mCache.remove(new ComponentKey(componentName, user)); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | /** |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 184 | * Remove any records for the supplied package name from memory. |
Chris Wren | 6d0dde0 | 2014-02-10 12:16:54 -0500 | [diff] [blame] | 185 | */ |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 186 | private void removeFromMemCacheLocked(String packageName, UserHandleCompat user) { |
Sunny Goyal | b4cd42a | 2015-03-16 14:10:24 -0700 | [diff] [blame] | 187 | HashSet<ComponentKey> forDeletion = new HashSet<ComponentKey>(); |
| 188 | for (ComponentKey key: mCache.keySet()) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 189 | if (key.componentName.getPackageName().equals(packageName) |
| 190 | && key.user.equals(user)) { |
| 191 | forDeletion.add(key); |
Chris Wren | 6d0dde0 | 2014-02-10 12:16:54 -0500 | [diff] [blame] | 192 | } |
| 193 | } |
Sunny Goyal | b4cd42a | 2015-03-16 14:10:24 -0700 | [diff] [blame] | 194 | for (ComponentKey condemned: forDeletion) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 195 | mCache.remove(condemned); |
Chris Wren | 6d0dde0 | 2014-02-10 12:16:54 -0500 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | |
| 199 | /** |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 200 | * Updates the entries related to the given package in memory and persistent DB. |
| 201 | */ |
| 202 | public synchronized void updateIconsForPkg(String packageName, UserHandleCompat user) { |
| 203 | removeIconsForPkg(packageName, user); |
| 204 | try { |
| 205 | PackageInfo info = mPackageManager.getPackageInfo(packageName, |
| 206 | PackageManager.GET_UNINSTALLED_PACKAGES); |
| 207 | long userSerial = mUserManager.getSerialNumberForUser(user); |
| 208 | for (LauncherActivityInfoCompat app : mLauncherApps.getActivityList(packageName, user)) { |
Sunny Goyal | d180cf7 | 2015-04-06 12:45:40 -0700 | [diff] [blame] | 209 | addIconToDBAndMemCache(app, info, userSerial); |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 210 | } |
| 211 | } catch (NameNotFoundException e) { |
| 212 | Log.d(TAG, "Package not found", e); |
| 213 | return; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * Removes the entries related to the given package in memory and persistent DB. |
| 219 | */ |
| 220 | public synchronized void removeIconsForPkg(String packageName, UserHandleCompat user) { |
| 221 | removeFromMemCacheLocked(packageName, user); |
| 222 | long userSerial = mUserManager.getSerialNumberForUser(user); |
| 223 | mIconDb.getWritableDatabase().delete(IconDB.TABLE_NAME, |
| 224 | IconDB.COLUMN_COMPONENT + " LIKE ? AND " + IconDB.COLUMN_USER + " = ?", |
| 225 | new String[] {packageName + "/%", Long.toString(userSerial)}); |
| 226 | } |
| 227 | |
Sunny Goyal | 75b0f55 | 2015-05-20 21:57:06 -0700 | [diff] [blame] | 228 | public void updateDbIcons() { |
| 229 | // Remove all active icon update tasks. |
| 230 | mWorkerHandler.removeCallbacksAndMessages(ICON_UPDATE_TOKEN); |
| 231 | |
| 232 | mIconDb.updateSystemStateString(mContext); |
| 233 | for (UserHandleCompat user : mUserManager.getUserProfiles()) { |
| 234 | // Query for the set of apps |
| 235 | final List<LauncherActivityInfoCompat> apps = mLauncherApps.getActivityList(null, user); |
| 236 | // Fail if we don't have any apps |
| 237 | // TODO: Fix this. Only fail for the current user. |
| 238 | if (apps == null || apps.isEmpty()) { |
| 239 | return; |
| 240 | } |
| 241 | |
| 242 | // Update icon cache. This happens in segments and {@link #onPackageIconsUpdated} |
| 243 | // is called by the icon cache when the job is complete. |
| 244 | updateDBIcons(user, apps); |
| 245 | } |
| 246 | } |
| 247 | |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 248 | /** |
| 249 | * Updates the persistent DB, such that only entries corresponding to {@param apps} remain in |
| 250 | * the DB and are updated. |
| 251 | * @return The set of packages for which icons have updated. |
| 252 | */ |
Sunny Goyal | 75b0f55 | 2015-05-20 21:57:06 -0700 | [diff] [blame] | 253 | private void updateDBIcons(UserHandleCompat user, List<LauncherActivityInfoCompat> apps) { |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 254 | long userSerial = mUserManager.getSerialNumberForUser(user); |
| 255 | PackageManager pm = mContext.getPackageManager(); |
| 256 | HashMap<String, PackageInfo> pkgInfoMap = new HashMap<String, PackageInfo>(); |
| 257 | for (PackageInfo info : pm.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES)) { |
| 258 | pkgInfoMap.put(info.packageName, info); |
| 259 | } |
| 260 | |
| 261 | HashMap<ComponentName, LauncherActivityInfoCompat> componentMap = new HashMap<>(); |
| 262 | for (LauncherActivityInfoCompat app : apps) { |
| 263 | componentMap.put(app.getComponentName(), app); |
| 264 | } |
| 265 | |
| 266 | Cursor c = mIconDb.getReadableDatabase().query(IconDB.TABLE_NAME, |
| 267 | new String[] {IconDB.COLUMN_ROWID, IconDB.COLUMN_COMPONENT, |
Sunny Goyal | 0c9a354 | 2015-04-01 16:04:21 -0700 | [diff] [blame] | 268 | IconDB.COLUMN_LAST_UPDATED, IconDB.COLUMN_VERSION, |
| 269 | IconDB.COLUMN_SYSTEM_STATE}, |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 270 | IconDB.COLUMN_USER + " = ? ", |
| 271 | new String[] {Long.toString(userSerial)}, |
| 272 | null, null, null); |
| 273 | |
| 274 | final int indexComponent = c.getColumnIndex(IconDB.COLUMN_COMPONENT); |
| 275 | final int indexLastUpdate = c.getColumnIndex(IconDB.COLUMN_LAST_UPDATED); |
| 276 | final int indexVersion = c.getColumnIndex(IconDB.COLUMN_VERSION); |
| 277 | final int rowIndex = c.getColumnIndex(IconDB.COLUMN_ROWID); |
Sunny Goyal | 0c9a354 | 2015-04-01 16:04:21 -0700 | [diff] [blame] | 278 | final int systemStateIndex = c.getColumnIndex(IconDB.COLUMN_SYSTEM_STATE); |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 279 | |
| 280 | HashSet<Integer> itemsToRemove = new HashSet<Integer>(); |
Sunny Goyal | 75b0f55 | 2015-05-20 21:57:06 -0700 | [diff] [blame] | 281 | Stack<LauncherActivityInfoCompat> appsToUpdate = new Stack<>(); |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 282 | |
| 283 | while (c.moveToNext()) { |
| 284 | String cn = c.getString(indexComponent); |
| 285 | ComponentName component = ComponentName.unflattenFromString(cn); |
| 286 | PackageInfo info = pkgInfoMap.get(component.getPackageName()); |
| 287 | if (info == null) { |
| 288 | itemsToRemove.add(c.getInt(rowIndex)); |
| 289 | continue; |
| 290 | } |
| 291 | if ((info.applicationInfo.flags & ApplicationInfo.FLAG_IS_DATA_ONLY) != 0) { |
| 292 | // Application is not present |
| 293 | continue; |
| 294 | } |
| 295 | |
| 296 | long updateTime = c.getLong(indexLastUpdate); |
| 297 | int version = c.getInt(indexVersion); |
| 298 | LauncherActivityInfoCompat app = componentMap.remove(component); |
Sunny Goyal | 0c9a354 | 2015-04-01 16:04:21 -0700 | [diff] [blame] | 299 | if (version == info.versionCode && updateTime == info.lastUpdateTime && |
| 300 | TextUtils.equals(mIconDb.mSystemState, c.getString(systemStateIndex))) { |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 301 | continue; |
| 302 | } |
| 303 | if (app == null) { |
| 304 | itemsToRemove.add(c.getInt(rowIndex)); |
Sunny Goyal | 75b0f55 | 2015-05-20 21:57:06 -0700 | [diff] [blame] | 305 | } else { |
| 306 | appsToUpdate.add(app); |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 307 | } |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 308 | } |
| 309 | c.close(); |
| 310 | if (!itemsToRemove.isEmpty()) { |
| 311 | mIconDb.getWritableDatabase().delete(IconDB.TABLE_NAME, |
| 312 | IconDB.COLUMN_ROWID + " IN ( " + TextUtils.join(", ", itemsToRemove) +" )", |
| 313 | null); |
| 314 | } |
| 315 | |
| 316 | // Insert remaining apps. |
Sunny Goyal | 75b0f55 | 2015-05-20 21:57:06 -0700 | [diff] [blame] | 317 | if (!componentMap.isEmpty() || !appsToUpdate.isEmpty()) { |
| 318 | Stack<LauncherActivityInfoCompat> appsToAdd = new Stack<>(); |
| 319 | appsToAdd.addAll(componentMap.values()); |
| 320 | new SerializedIconUpdateTask(userSerial, pkgInfoMap, |
| 321 | appsToAdd, appsToUpdate).scheduleNext(); |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 322 | } |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 323 | } |
| 324 | |
Sunny Goyal | d180cf7 | 2015-04-06 12:45:40 -0700 | [diff] [blame] | 325 | private void addIconToDBAndMemCache(LauncherActivityInfoCompat app, PackageInfo info, |
| 326 | long userSerial) { |
Sunny Goyal | 9ff9808 | 2015-05-15 16:59:36 -0700 | [diff] [blame] | 327 | // Reuse the existing entry if it already exists in the DB. This ensures that we do not |
| 328 | // create bitmap if it was already created during loader. |
| 329 | ContentValues values = updateCacheAndGetContentValues(app, false); |
Sunny Goyal | d180cf7 | 2015-04-06 12:45:40 -0700 | [diff] [blame] | 330 | addIconToDB(values, app.getComponentName(), info, userSerial); |
Sunny Goyal | d180cf7 | 2015-04-06 12:45:40 -0700 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | /** |
| 334 | * Updates {@param values} to contain versoning information and adds it to the DB. |
| 335 | * @param values {@link ContentValues} containing icon & title |
| 336 | */ |
| 337 | private void addIconToDB(ContentValues values, ComponentName key, |
| 338 | PackageInfo info, long userSerial) { |
| 339 | values.put(IconDB.COLUMN_COMPONENT, key.flattenToString()); |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 340 | values.put(IconDB.COLUMN_USER, userSerial); |
| 341 | values.put(IconDB.COLUMN_LAST_UPDATED, info.lastUpdateTime); |
| 342 | values.put(IconDB.COLUMN_VERSION, info.versionCode); |
| 343 | mIconDb.getWritableDatabase().insertWithOnConflict(IconDB.TABLE_NAME, null, values, |
| 344 | SQLiteDatabase.CONFLICT_REPLACE); |
| 345 | } |
| 346 | |
Sunny Goyal | 9ff9808 | 2015-05-15 16:59:36 -0700 | [diff] [blame] | 347 | private ContentValues updateCacheAndGetContentValues(LauncherActivityInfoCompat app, |
| 348 | boolean replaceExisting) { |
| 349 | final ComponentKey key = new ComponentKey(app.getComponentName(), app.getUser()); |
| 350 | CacheEntry entry = null; |
| 351 | if (!replaceExisting) { |
| 352 | entry = mCache.get(key); |
| 353 | // We can't reuse the entry if the high-res icon is not present. |
| 354 | if (entry == null || entry.isLowResIcon || entry.icon == null) { |
| 355 | entry = null; |
| 356 | } |
| 357 | } |
| 358 | if (entry == null) { |
| 359 | entry = new CacheEntry(); |
| 360 | entry.icon = Utilities.createIconBitmap(app.getBadgedIcon(mIconDpi), mContext); |
| 361 | } |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 362 | entry.title = app.getLabel(); |
| 363 | entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, app.getUser()); |
Sunny Goyal | b4cd42a | 2015-03-16 14:10:24 -0700 | [diff] [blame] | 364 | mCache.put(new ComponentKey(app.getComponentName(), app.getUser()), entry); |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 365 | |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 366 | return mIconDb.newContentValues(entry.icon, entry.title.toString()); |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 367 | } |
| 368 | |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 369 | /** |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 370 | * Empty out the cache. |
| 371 | */ |
Sunny Goyal | 736f5af | 2014-10-16 14:07:29 -0700 | [diff] [blame] | 372 | public synchronized void flush() { |
| 373 | mCache.clear(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | /** |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 377 | * Fetches high-res icon for the provided ItemInfo and updates the caller when done. |
| 378 | * @return a request ID that can be used to cancel the request. |
| 379 | */ |
| 380 | public IconLoadRequest updateIconInBackground(final BubbleTextView caller, final ItemInfo info) { |
| 381 | Runnable request = new Runnable() { |
| 382 | |
| 383 | @Override |
| 384 | public void run() { |
| 385 | if (info instanceof AppInfo) { |
| 386 | getTitleAndIcon((AppInfo) info, null, false); |
| 387 | } else if (info instanceof ShortcutInfo) { |
| 388 | ShortcutInfo st = (ShortcutInfo) info; |
| 389 | getTitleAndIcon(st, |
| 390 | st.promisedIntent != null ? st.promisedIntent : st.intent, |
| 391 | st.user, false); |
Sunny Goyal | 0e08f16 | 2015-05-12 11:32:39 -0700 | [diff] [blame] | 392 | } else if (info instanceof PackageItemInfo) { |
| 393 | PackageItemInfo pti = (PackageItemInfo) info; |
| 394 | getTitleAndIconForApp(pti.packageName, pti.user, false, pti); |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 395 | } |
Sunny Goyal | 8758ea0 | 2015-03-18 10:07:49 -0700 | [diff] [blame] | 396 | mMainThreadExecutor.execute(new Runnable() { |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 397 | |
| 398 | @Override |
| 399 | public void run() { |
| 400 | caller.reapplyItemInfo(info); |
| 401 | } |
| 402 | }); |
| 403 | } |
| 404 | }; |
| 405 | mWorkerHandler.post(request); |
| 406 | return new IconLoadRequest(request, mWorkerHandler); |
| 407 | } |
| 408 | |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 409 | private Bitmap getNonNullIcon(CacheEntry entry, UserHandleCompat user) { |
| 410 | return entry.icon == null ? getDefaultIcon(user) : entry.icon; |
| 411 | } |
| 412 | |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 413 | /** |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 414 | * Fill in "application" with the icon and label for "info." |
| 415 | */ |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 416 | public synchronized void getTitleAndIcon(AppInfo application, |
| 417 | LauncherActivityInfoCompat info, boolean useLowResIcon) { |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 418 | UserHandleCompat user = info == null ? application.user : info.getUser(); |
| 419 | CacheEntry entry = cacheLocked(application.componentName, info, user, |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 420 | false, useLowResIcon); |
Winson Chung | 82b016c | 2015-05-08 17:00:10 -0700 | [diff] [blame] | 421 | application.title = Utilities.trim(entry.title); |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 422 | application.iconBitmap = getNonNullIcon(entry, user); |
Sunny Goyal | 736f5af | 2014-10-16 14:07:29 -0700 | [diff] [blame] | 423 | application.contentDescription = entry.contentDescription; |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 424 | application.usingLowResIcon = entry.isLowResIcon; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 425 | } |
| 426 | |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 427 | /** |
Sunny Goyal | 77919b9 | 2015-05-06 16:53:21 -0700 | [diff] [blame] | 428 | * Updates {@param application} only if a valid entry is found. |
| 429 | */ |
| 430 | public synchronized void updateTitleAndIcon(AppInfo application) { |
| 431 | CacheEntry entry = cacheLocked(application.componentName, null, application.user, |
| 432 | false, application.usingLowResIcon); |
| 433 | if (entry.icon != null && !isDefaultIcon(entry.icon, application.user)) { |
Winson Chung | 82b016c | 2015-05-08 17:00:10 -0700 | [diff] [blame] | 434 | application.title = Utilities.trim(entry.title); |
Sunny Goyal | 77919b9 | 2015-05-06 16:53:21 -0700 | [diff] [blame] | 435 | application.iconBitmap = entry.icon; |
| 436 | application.contentDescription = entry.contentDescription; |
| 437 | application.usingLowResIcon = entry.isLowResIcon; |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | /** |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 442 | * Returns a high res icon for the given intent and user |
| 443 | */ |
Sunny Goyal | 736f5af | 2014-10-16 14:07:29 -0700 | [diff] [blame] | 444 | public synchronized Bitmap getIcon(Intent intent, UserHandleCompat user) { |
| 445 | ComponentName component = intent.getComponent(); |
| 446 | // null info means not installed, but if we have a component from the intent then |
| 447 | // we should still look in the cache for restored app icons. |
| 448 | if (component == null) { |
| 449 | return getDefaultIcon(user); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 450 | } |
Sunny Goyal | 736f5af | 2014-10-16 14:07:29 -0700 | [diff] [blame] | 451 | |
| 452 | LauncherActivityInfoCompat launcherActInfo = mLauncherApps.resolveActivity(intent, user); |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 453 | CacheEntry entry = cacheLocked(component, launcherActInfo, user, true, true); |
Sunny Goyal | 736f5af | 2014-10-16 14:07:29 -0700 | [diff] [blame] | 454 | return entry.icon; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 455 | } |
| 456 | |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 457 | /** |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 458 | * Fill in {@param shortcutInfo} with the icon and label for {@param intent}. If the |
| 459 | * corresponding activity is not found, it reverts to the package icon. |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 460 | */ |
Sunny Goyal | 736f5af | 2014-10-16 14:07:29 -0700 | [diff] [blame] | 461 | public synchronized void getTitleAndIcon(ShortcutInfo shortcutInfo, Intent intent, |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 462 | UserHandleCompat user, boolean useLowResIcon) { |
Sunny Goyal | 736f5af | 2014-10-16 14:07:29 -0700 | [diff] [blame] | 463 | ComponentName component = intent.getComponent(); |
| 464 | // null info means not installed, but if we have a component from the intent then |
| 465 | // we should still look in the cache for restored app icons. |
| 466 | if (component == null) { |
| 467 | shortcutInfo.setIcon(getDefaultIcon(user)); |
| 468 | shortcutInfo.title = ""; |
| 469 | shortcutInfo.usingFallbackIcon = true; |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 470 | shortcutInfo.usingLowResIcon = false; |
Sunny Goyal | 736f5af | 2014-10-16 14:07:29 -0700 | [diff] [blame] | 471 | } else { |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 472 | LauncherActivityInfoCompat info = mLauncherApps.resolveActivity(intent, user); |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 473 | getTitleAndIcon(shortcutInfo, component, info, user, true, useLowResIcon); |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 477 | /** |
| 478 | * Fill in {@param shortcutInfo} with the icon and label for {@param info} |
| 479 | */ |
| 480 | public synchronized void getTitleAndIcon( |
| 481 | ShortcutInfo shortcutInfo, ComponentName component, LauncherActivityInfoCompat info, |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 482 | UserHandleCompat user, boolean usePkgIcon, boolean useLowResIcon) { |
| 483 | CacheEntry entry = cacheLocked(component, info, user, usePkgIcon, useLowResIcon); |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 484 | shortcutInfo.setIcon(getNonNullIcon(entry, user)); |
Winson Chung | 82b016c | 2015-05-08 17:00:10 -0700 | [diff] [blame] | 485 | shortcutInfo.title = Utilities.trim(entry.title); |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 486 | shortcutInfo.usingFallbackIcon = isDefaultIcon(entry.icon, user); |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 487 | shortcutInfo.usingLowResIcon = entry.isLowResIcon; |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 488 | } |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 489 | |
Sunny Goyal | d180cf7 | 2015-04-06 12:45:40 -0700 | [diff] [blame] | 490 | /** |
| 491 | * Fill in {@param appInfo} with the icon and label for {@param packageName} |
| 492 | */ |
| 493 | public synchronized void getTitleAndIconForApp( |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 494 | String packageName, UserHandleCompat user, boolean useLowResIcon, |
| 495 | PackageItemInfo infoOut) { |
Sunny Goyal | d180cf7 | 2015-04-06 12:45:40 -0700 | [diff] [blame] | 496 | CacheEntry entry = getEntryForPackageLocked(packageName, user, useLowResIcon); |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 497 | infoOut.iconBitmap = getNonNullIcon(entry, user); |
Winson Chung | 82b016c | 2015-05-08 17:00:10 -0700 | [diff] [blame] | 498 | infoOut.title = Utilities.trim(entry.title); |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 499 | infoOut.usingLowResIcon = entry.isLowResIcon; |
| 500 | infoOut.contentDescription = entry.contentDescription; |
Sunny Goyal | d180cf7 | 2015-04-06 12:45:40 -0700 | [diff] [blame] | 501 | } |
| 502 | |
Sunny Goyal | 736f5af | 2014-10-16 14:07:29 -0700 | [diff] [blame] | 503 | public synchronized Bitmap getDefaultIcon(UserHandleCompat user) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 504 | if (!mDefaultIcons.containsKey(user)) { |
| 505 | mDefaultIcons.put(user, makeDefaultIcon(user)); |
| 506 | } |
| 507 | return mDefaultIcons.get(user); |
| 508 | } |
| 509 | |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 510 | public boolean isDefaultIcon(Bitmap icon, UserHandleCompat user) { |
| 511 | return mDefaultIcons.get(user) == icon; |
Joe Onorato | ddc9c1f | 2010-08-30 18:30:15 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Sunny Goyal | 736f5af | 2014-10-16 14:07:29 -0700 | [diff] [blame] | 514 | /** |
| 515 | * Retrieves the entry from the cache. If the entry is not present, it creates a new entry. |
| 516 | * This method is not thread safe, it must be called from a synchronized method. |
| 517 | */ |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 518 | private CacheEntry cacheLocked(ComponentName componentName, LauncherActivityInfoCompat info, |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 519 | UserHandleCompat user, boolean usePackageIcon, boolean useLowResIcon) { |
Sunny Goyal | b4cd42a | 2015-03-16 14:10:24 -0700 | [diff] [blame] | 520 | ComponentKey cacheKey = new ComponentKey(componentName, user); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 521 | CacheEntry entry = mCache.get(cacheKey); |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 522 | if (entry == null || (entry.isLowResIcon && !useLowResIcon)) { |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 523 | entry = new CacheEntry(); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 524 | mCache.put(cacheKey, entry); |
Joe Onorato | 84f6a8d | 2010-02-12 17:53:35 -0500 | [diff] [blame] | 525 | |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 526 | // Check the DB first. |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 527 | if (!getEntryFromDB(componentName, user, entry, useLowResIcon)) { |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 528 | if (info != null) { |
| 529 | entry.icon = Utilities.createIconBitmap(info.getBadgedIcon(mIconDpi), mContext); |
Chris Wren | 6d0dde0 | 2014-02-10 12:16:54 -0500 | [diff] [blame] | 530 | } else { |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 531 | if (usePackageIcon) { |
Sunny Goyal | d180cf7 | 2015-04-06 12:45:40 -0700 | [diff] [blame] | 532 | CacheEntry packageEntry = getEntryForPackageLocked( |
| 533 | componentName.getPackageName(), user, false); |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 534 | if (packageEntry != null) { |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 535 | if (DEBUG) Log.d(TAG, "using package default icon for " + |
| 536 | componentName.toShortString()); |
| 537 | entry.icon = packageEntry.icon; |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 538 | entry.title = packageEntry.title; |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 539 | entry.contentDescription = packageEntry.contentDescription; |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 540 | } |
| 541 | } |
| 542 | if (entry.icon == null) { |
| 543 | if (DEBUG) Log.d(TAG, "using default icon for " + |
| 544 | componentName.toShortString()); |
| 545 | entry.icon = getDefaultIcon(user); |
| 546 | } |
Winson Chung | c3eecff | 2011-07-11 17:44:15 -0700 | [diff] [blame] | 547 | } |
| 548 | } |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 549 | |
| 550 | if (TextUtils.isEmpty(entry.title) && info != null) { |
Winson Chung | 82b016c | 2015-05-08 17:00:10 -0700 | [diff] [blame] | 551 | entry.title = info.getLabel(); |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 552 | entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user); |
| 553 | } |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 554 | } |
| 555 | return entry; |
| 556 | } |
Daniel Sandler | 4e1cd23 | 2011-05-12 00:06:32 -0400 | [diff] [blame] | 557 | |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 558 | /** |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 559 | * Adds a default package entry in the cache. This entry is not persisted and will be removed |
| 560 | * when the cache is flushed. |
| 561 | */ |
Sunny Goyal | 736f5af | 2014-10-16 14:07:29 -0700 | [diff] [blame] | 562 | public synchronized void cachePackageInstallInfo(String packageName, UserHandleCompat user, |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 563 | Bitmap icon, CharSequence title) { |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 564 | removeFromMemCacheLocked(packageName, user); |
Sunny Goyal | a22666f | 2014-09-18 13:25:15 -0700 | [diff] [blame] | 565 | |
Sunny Goyal | d180cf7 | 2015-04-06 12:45:40 -0700 | [diff] [blame] | 566 | CacheEntry entry = getEntryForPackageLocked(packageName, user, false); |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 567 | if (!TextUtils.isEmpty(title)) { |
| 568 | entry.title = title; |
| 569 | } |
| 570 | if (icon != null) { |
Sunny Goyal | 2fce90c | 2014-10-07 12:01:58 -0700 | [diff] [blame] | 571 | entry.icon = Utilities.createIconBitmap(icon, mContext); |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 572 | } |
| 573 | } |
| 574 | |
| 575 | /** |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 576 | * Gets an entry for the package, which can be used as a fallback entry for various components. |
Sunny Goyal | 736f5af | 2014-10-16 14:07:29 -0700 | [diff] [blame] | 577 | * This method is not thread safe, it must be called from a synchronized method. |
Sunny Goyal | d180cf7 | 2015-04-06 12:45:40 -0700 | [diff] [blame] | 578 | * |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 579 | */ |
Sunny Goyal | d180cf7 | 2015-04-06 12:45:40 -0700 | [diff] [blame] | 580 | private CacheEntry getEntryForPackageLocked(String packageName, UserHandleCompat user, |
| 581 | boolean useLowResIcon) { |
| 582 | ComponentName cn = new ComponentName(packageName, EMPTY_CLASS_NAME); |
Sunny Goyal | b4cd42a | 2015-03-16 14:10:24 -0700 | [diff] [blame] | 583 | ComponentKey cacheKey = new ComponentKey(cn, user); |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 584 | CacheEntry entry = mCache.get(cacheKey); |
Sunny Goyal | d180cf7 | 2015-04-06 12:45:40 -0700 | [diff] [blame] | 585 | if (entry == null || (entry.isLowResIcon && !useLowResIcon)) { |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 586 | entry = new CacheEntry(); |
| 587 | mCache.put(cacheKey, entry); |
| 588 | |
Sunny Goyal | d180cf7 | 2015-04-06 12:45:40 -0700 | [diff] [blame] | 589 | // Check the DB first. |
| 590 | if (!getEntryFromDB(cn, user, entry, useLowResIcon)) { |
| 591 | try { |
| 592 | PackageInfo info = mPackageManager.getPackageInfo(packageName, 0); |
| 593 | ApplicationInfo appInfo = info.applicationInfo; |
| 594 | if (appInfo == null) { |
| 595 | throw new NameNotFoundException("ApplicationInfo is null"); |
| 596 | } |
| 597 | Drawable drawable = mUserManager.getBadgedDrawableForUser( |
| 598 | appInfo.loadIcon(mPackageManager), user); |
| 599 | entry.icon = Utilities.createIconBitmap(drawable, mContext); |
| 600 | entry.title = appInfo.loadLabel(mPackageManager); |
| 601 | entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user); |
| 602 | entry.isLowResIcon = false; |
| 603 | |
| 604 | // Add the icon in the DB here, since these do not get written during |
| 605 | // package updates. |
| 606 | ContentValues values = |
| 607 | mIconDb.newContentValues(entry.icon, entry.title.toString()); |
| 608 | addIconToDB(values, cn, info, mUserManager.getSerialNumberForUser(user)); |
| 609 | |
| 610 | } catch (NameNotFoundException e) { |
| 611 | if (DEBUG) Log.d(TAG, "Application not installed " + packageName); |
| 612 | } |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 613 | } |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 614 | } |
| 615 | return entry; |
| 616 | } |
| 617 | |
Chris Wren | 6d0dde0 | 2014-02-10 12:16:54 -0500 | [diff] [blame] | 618 | /** |
| 619 | * Pre-load an icon into the persistent cache. |
| 620 | * |
| 621 | * <P>Queries for a component that does not exist in the package manager |
| 622 | * will be answered by the persistent cache. |
| 623 | * |
Chris Wren | 6d0dde0 | 2014-02-10 12:16:54 -0500 | [diff] [blame] | 624 | * @param componentName the icon should be returned for this component |
| 625 | * @param icon the icon to be persisted |
| 626 | * @param dpi the native density of the icon |
| 627 | */ |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 628 | public void preloadIcon(ComponentName componentName, Bitmap icon, int dpi, String label, |
| 629 | long userSerial) { |
Chris Wren | 6d0dde0 | 2014-02-10 12:16:54 -0500 | [diff] [blame] | 630 | // TODO rescale to the correct native DPI |
| 631 | try { |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 632 | PackageManager packageManager = mContext.getPackageManager(); |
Chris Wren | 6d0dde0 | 2014-02-10 12:16:54 -0500 | [diff] [blame] | 633 | packageManager.getActivityIcon(componentName); |
| 634 | // component is present on the system already, do nothing |
| 635 | return; |
| 636 | } catch (PackageManager.NameNotFoundException e) { |
| 637 | // pass |
| 638 | } |
| 639 | |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 640 | ContentValues values = mIconDb.newContentValues(icon, label); |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 641 | values.put(IconDB.COLUMN_COMPONENT, componentName.flattenToString()); |
| 642 | values.put(IconDB.COLUMN_USER, userSerial); |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 643 | mIconDb.getWritableDatabase().insertWithOnConflict(IconDB.TABLE_NAME, null, values, |
| 644 | SQLiteDatabase.CONFLICT_REPLACE); |
| 645 | } |
| 646 | |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 647 | private boolean getEntryFromDB(ComponentName component, UserHandleCompat user, |
| 648 | CacheEntry entry, boolean lowRes) { |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 649 | Cursor c = mIconDb.getReadableDatabase().query(IconDB.TABLE_NAME, |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 650 | new String[] {lowRes ? IconDB.COLUMN_ICON_LOW_RES : IconDB.COLUMN_ICON, |
| 651 | IconDB.COLUMN_LABEL}, |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 652 | IconDB.COLUMN_COMPONENT + " = ? AND " + IconDB.COLUMN_USER + " = ?", |
| 653 | new String[] {component.flattenToString(), |
| 654 | Long.toString(mUserManager.getSerialNumberForUser(user))}, |
| 655 | null, null, null); |
Chris Wren | 6d0dde0 | 2014-02-10 12:16:54 -0500 | [diff] [blame] | 656 | try { |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 657 | if (c.moveToNext()) { |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 658 | entry.icon = loadIconNoResize(c, 0); |
| 659 | entry.isLowResIcon = lowRes; |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 660 | entry.title = c.getString(1); |
| 661 | if (entry.title == null) { |
| 662 | entry.title = ""; |
| 663 | entry.contentDescription = ""; |
| 664 | } else { |
| 665 | entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user); |
Chris Wren | 6d0dde0 | 2014-02-10 12:16:54 -0500 | [diff] [blame] | 666 | } |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 667 | return true; |
Chris Wren | 6d0dde0 | 2014-02-10 12:16:54 -0500 | [diff] [blame] | 668 | } |
Chris Wren | 6d0dde0 | 2014-02-10 12:16:54 -0500 | [diff] [blame] | 669 | } finally { |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 670 | c.close(); |
| 671 | } |
| 672 | return false; |
| 673 | } |
| 674 | |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 675 | public static class IconLoadRequest { |
| 676 | private final Runnable mRunnable; |
| 677 | private final Handler mHandler; |
| 678 | |
| 679 | IconLoadRequest(Runnable runnable, Handler handler) { |
| 680 | mRunnable = runnable; |
| 681 | mHandler = handler; |
| 682 | } |
| 683 | |
| 684 | public void cancel() { |
| 685 | mHandler.removeCallbacks(mRunnable); |
| 686 | } |
| 687 | } |
| 688 | |
Sunny Goyal | 9ff9808 | 2015-05-15 16:59:36 -0700 | [diff] [blame] | 689 | /** |
Sunny Goyal | 75b0f55 | 2015-05-20 21:57:06 -0700 | [diff] [blame] | 690 | * A runnable that updates invalid icons and adds missing icons in the DB for the provided |
| 691 | * LauncherActivityInfoCompat list. Items are updated/added one at a time, so that the |
| 692 | * worker thread doesn't get blocked. |
Sunny Goyal | 9ff9808 | 2015-05-15 16:59:36 -0700 | [diff] [blame] | 693 | */ |
Sunny Goyal | 75b0f55 | 2015-05-20 21:57:06 -0700 | [diff] [blame] | 694 | private class SerializedIconUpdateTask implements Runnable { |
Sunny Goyal | 9ff9808 | 2015-05-15 16:59:36 -0700 | [diff] [blame] | 695 | private final long mUserSerial; |
| 696 | private final HashMap<String, PackageInfo> mPkgInfoMap; |
| 697 | private final Stack<LauncherActivityInfoCompat> mAppsToAdd; |
Sunny Goyal | 75b0f55 | 2015-05-20 21:57:06 -0700 | [diff] [blame] | 698 | private final Stack<LauncherActivityInfoCompat> mAppsToUpdate; |
| 699 | private final HashSet<String> mUpdatedPackages = new HashSet<String>(); |
Sunny Goyal | 9ff9808 | 2015-05-15 16:59:36 -0700 | [diff] [blame] | 700 | |
Sunny Goyal | 75b0f55 | 2015-05-20 21:57:06 -0700 | [diff] [blame] | 701 | private SerializedIconUpdateTask(long userSerial, HashMap<String, PackageInfo> pkgInfoMap, |
| 702 | Stack<LauncherActivityInfoCompat> appsToAdd, |
| 703 | Stack<LauncherActivityInfoCompat> appsToUpdate) { |
Sunny Goyal | 9ff9808 | 2015-05-15 16:59:36 -0700 | [diff] [blame] | 704 | mUserSerial = userSerial; |
| 705 | mPkgInfoMap = pkgInfoMap; |
Sunny Goyal | 75b0f55 | 2015-05-20 21:57:06 -0700 | [diff] [blame] | 706 | mAppsToAdd = appsToAdd; |
| 707 | mAppsToUpdate = appsToUpdate; |
Sunny Goyal | 9ff9808 | 2015-05-15 16:59:36 -0700 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | @Override |
| 711 | public void run() { |
Sunny Goyal | 75b0f55 | 2015-05-20 21:57:06 -0700 | [diff] [blame] | 712 | if (!mAppsToUpdate.isEmpty()) { |
| 713 | LauncherActivityInfoCompat app = mAppsToUpdate.pop(); |
| 714 | String cn = app.getComponentName().flattenToString(); |
| 715 | ContentValues values = updateCacheAndGetContentValues(app, true); |
| 716 | mIconDb.getWritableDatabase().update(IconDB.TABLE_NAME, values, |
| 717 | IconDB.COLUMN_COMPONENT + " = ? AND " + IconDB.COLUMN_USER + " = ?", |
| 718 | new String[] {cn, Long.toString(mUserSerial)}); |
| 719 | mUpdatedPackages.add(app.getComponentName().getPackageName()); |
| 720 | |
| 721 | if (mAppsToUpdate.isEmpty() && !mUpdatedPackages.isEmpty()) { |
| 722 | // No more app to update. Notify model. |
| 723 | LauncherAppState.getInstance().getModel().onPackageIconsUpdated( |
| 724 | mUpdatedPackages, mUserManager.getUserForSerialNumber(mUserSerial)); |
| 725 | } |
| 726 | |
| 727 | // Let it run one more time. |
| 728 | scheduleNext(); |
| 729 | } else if (!mAppsToAdd.isEmpty()) { |
Sunny Goyal | 9ff9808 | 2015-05-15 16:59:36 -0700 | [diff] [blame] | 730 | LauncherActivityInfoCompat app = mAppsToAdd.pop(); |
| 731 | PackageInfo info = mPkgInfoMap.get(app.getComponentName().getPackageName()); |
| 732 | if (info != null) { |
| 733 | synchronized (IconCache.this) { |
| 734 | addIconToDBAndMemCache(app, info, mUserSerial); |
| 735 | } |
| 736 | } |
Sunny Goyal | 75b0f55 | 2015-05-20 21:57:06 -0700 | [diff] [blame] | 737 | |
| 738 | if (!mAppsToAdd.isEmpty()) { |
| 739 | scheduleNext(); |
| 740 | } |
Sunny Goyal | 9ff9808 | 2015-05-15 16:59:36 -0700 | [diff] [blame] | 741 | } |
Sunny Goyal | 75b0f55 | 2015-05-20 21:57:06 -0700 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | public void scheduleNext() { |
| 745 | mWorkerHandler.postAtTime(this, ICON_UPDATE_TOKEN, SystemClock.uptimeMillis() + 1); |
Sunny Goyal | 9ff9808 | 2015-05-15 16:59:36 -0700 | [diff] [blame] | 746 | } |
| 747 | } |
| 748 | |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 749 | private static final class IconDB extends SQLiteOpenHelper { |
Sunny Goyal | 77919b9 | 2015-05-06 16:53:21 -0700 | [diff] [blame] | 750 | private final static int DB_VERSION = 4; |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 751 | |
| 752 | private final static String TABLE_NAME = "icons"; |
| 753 | private final static String COLUMN_ROWID = "rowid"; |
| 754 | private final static String COLUMN_COMPONENT = "componentName"; |
| 755 | private final static String COLUMN_USER = "profileId"; |
| 756 | private final static String COLUMN_LAST_UPDATED = "lastUpdated"; |
| 757 | private final static String COLUMN_VERSION = "version"; |
| 758 | private final static String COLUMN_ICON = "icon"; |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 759 | private final static String COLUMN_ICON_LOW_RES = "icon_low_res"; |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 760 | private final static String COLUMN_LABEL = "label"; |
Sunny Goyal | 0c9a354 | 2015-04-01 16:04:21 -0700 | [diff] [blame] | 761 | private final static String COLUMN_SYSTEM_STATE = "system_state"; |
| 762 | |
| 763 | public String mSystemState; |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 764 | |
| 765 | public IconDB(Context context) { |
| 766 | super(context, LauncherFiles.APP_ICONS_DB, null, DB_VERSION); |
Sunny Goyal | 0c9a354 | 2015-04-01 16:04:21 -0700 | [diff] [blame] | 767 | updateSystemStateString(context); |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 768 | } |
| 769 | |
Sunny Goyal | 0c9a354 | 2015-04-01 16:04:21 -0700 | [diff] [blame] | 770 | public void updateSystemStateString(Context c) { |
| 771 | mSystemState = Locale.getDefault().toString() + "," |
| 772 | + c.getResources().getConfiguration().mcc; |
| 773 | } |
| 774 | |
| 775 | |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 776 | @Override |
| 777 | public void onCreate(SQLiteDatabase db) { |
| 778 | db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " (" + |
| 779 | COLUMN_COMPONENT + " TEXT NOT NULL, " + |
| 780 | COLUMN_USER + " INTEGER NOT NULL, " + |
| 781 | COLUMN_LAST_UPDATED + " INTEGER NOT NULL DEFAULT 0, " + |
| 782 | COLUMN_VERSION + " INTEGER NOT NULL DEFAULT 0, " + |
| 783 | COLUMN_ICON + " BLOB, " + |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 784 | COLUMN_ICON_LOW_RES + " BLOB, " + |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 785 | COLUMN_LABEL + " TEXT, " + |
Sunny Goyal | 0c9a354 | 2015-04-01 16:04:21 -0700 | [diff] [blame] | 786 | COLUMN_SYSTEM_STATE + " TEXT, " + |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 787 | "PRIMARY KEY (" + COLUMN_COMPONENT + ", " + COLUMN_USER + ") " + |
| 788 | ");"); |
| 789 | } |
| 790 | |
| 791 | @Override |
| 792 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { |
| 793 | if (oldVersion != newVersion) { |
| 794 | clearDB(db); |
Chris Wren | 6d0dde0 | 2014-02-10 12:16:54 -0500 | [diff] [blame] | 795 | } |
| 796 | } |
| 797 | |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 798 | @Override |
| 799 | public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) { |
| 800 | if (oldVersion != newVersion) { |
| 801 | clearDB(db); |
| 802 | } |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 803 | } |
Chris Wren | 6d0dde0 | 2014-02-10 12:16:54 -0500 | [diff] [blame] | 804 | |
Sunny Goyal | 4fbc382 | 2015-02-18 16:46:50 -0800 | [diff] [blame] | 805 | private void clearDB(SQLiteDatabase db) { |
| 806 | db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME); |
| 807 | onCreate(db); |
| 808 | } |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 809 | |
| 810 | public ContentValues newContentValues(Bitmap icon, String label) { |
| 811 | ContentValues values = new ContentValues(); |
Sunny Goyal | 0c9a354 | 2015-04-01 16:04:21 -0700 | [diff] [blame] | 812 | values.put(COLUMN_ICON, Utilities.flattenBitmap(icon)); |
| 813 | values.put(COLUMN_ICON_LOW_RES, Utilities.flattenBitmap( |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 814 | Bitmap.createScaledBitmap(icon, |
| 815 | icon.getWidth() / LOW_RES_SCALE_FACTOR, |
| 816 | icon.getHeight() / LOW_RES_SCALE_FACTOR, true))); |
Sunny Goyal | 0c9a354 | 2015-04-01 16:04:21 -0700 | [diff] [blame] | 817 | values.put(COLUMN_LABEL, label); |
| 818 | values.put(COLUMN_SYSTEM_STATE, mSystemState); |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 819 | return values; |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | private static Bitmap loadIconNoResize(Cursor c, int iconIndex) { |
| 824 | byte[] data = c.getBlob(iconIndex); |
| 825 | try { |
| 826 | return BitmapFactory.decodeByteArray(data, 0, data.length); |
| 827 | } catch (Exception e) { |
| 828 | return null; |
| 829 | } |
Chris Wren | 6d0dde0 | 2014-02-10 12:16:54 -0500 | [diff] [blame] | 830 | } |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 831 | } |