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