summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/LauncherModel.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/LauncherModel.java')
-rw-r--r--src/com/android/launcher3/LauncherModel.java486
1 files changed, 149 insertions, 337 deletions
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index c39bcee09..2fd9db2c3 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -36,7 +36,6 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Environment;
@@ -75,7 +74,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
-import java.util.TreeMap;
/**
* Maintains in-memory state of the Launcher. It is expected that there should be only one
@@ -91,9 +89,6 @@ public class LauncherModel extends BroadcastReceiver
static final String TAG = "Launcher.Model";
- // true = use a "More Apps" folder for non-workspace apps on upgrade
- // false = strew non-workspace apps across the workspace on upgrade
- public static final boolean UPGRADE_USE_MORE_APPS_FOLDER = false;
public static final int LOADER_FLAG_NONE = 0;
public static final int LOADER_FLAG_CLEAR_WORKSPACE = 1 << 0;
public static final int LOADER_FLAG_MIGRATE_SHORTCUTS = 1 << 1;
@@ -167,9 +162,6 @@ public class LauncherModel extends BroadcastReceiver
// sBgFolders is all FolderInfos created by LauncherModel. Passed to bindFolders()
static final HashMap<Long, FolderInfo> sBgFolders = new HashMap<Long, FolderInfo>();
- // sBgDbIconCache is the set of ItemInfos that need to have their icons updated in the database
- static final HashMap<Object, byte[]> sBgDbIconCache = new HashMap<Object, byte[]>();
-
// sBgWorkspaceScreens is the ordered set of workspace screens.
static final ArrayList<Long> sBgWorkspaceScreens = new ArrayList<Long>();
@@ -198,7 +190,7 @@ public class LauncherModel extends BroadcastReceiver
public void bindScreens(ArrayList<Long> orderedScreenIds);
public void bindAddScreens(ArrayList<Long> orderedScreenIds);
public void bindFolders(HashMap<Long,FolderInfo> folders);
- public void finishBindingItems(boolean upgradePath);
+ public void finishBindingItems();
public void bindAppWidget(LauncherAppWidgetInfo info);
public void bindAllApplications(ArrayList<AppInfo> apps);
public void bindAppsAdded(ArrayList<Long> newScreens,
@@ -490,13 +482,7 @@ public class LauncherModel extends BroadcastReceiver
Runnable r = new Runnable() {
public void run() {
final ArrayList<Long> addedWorkspaceScreensFinal = new ArrayList<Long>();
-
- ArrayList<Long> workspaceScreens = new ArrayList<Long>();
- TreeMap<Integer, Long> orderedScreens = loadWorkspaceScreensDb(context);
- for (Integer i : orderedScreens.keySet()) {
- long screenId = orderedScreens.get(i);
- workspaceScreens.add(screenId);
- }
+ ArrayList<Long> workspaceScreens = loadWorkspaceScreensDb(context);
// Find appropriate space for the item.
Pair<Long, int[]> coords = findSpaceForItem(context, preferredScreen,
@@ -548,13 +534,7 @@ public class LauncherModel extends BroadcastReceiver
// Get the list of workspace screens. We need to append to this list and
// can not use sBgWorkspaceScreens because loadWorkspace() may not have been
// called.
- ArrayList<Long> workspaceScreens = new ArrayList<Long>();
- TreeMap<Integer, Long> orderedScreens = loadWorkspaceScreensDb(context);
- for (Integer i : orderedScreens.keySet()) {
- long screenId = orderedScreens.get(i);
- workspaceScreens.add(screenId);
- }
-
+ ArrayList<Long> workspaceScreens = loadWorkspaceScreensDb(context);
synchronized(sBgLock) {
for (ItemInfo item : workspaceApps) {
if (!allowDuplicate) {
@@ -1146,7 +1126,6 @@ public class LauncherModel extends BroadcastReceiver
break;
}
sBgItemsIdMap.remove(item.id);
- sBgDbIconCache.remove(item);
}
}
}
@@ -1219,7 +1198,6 @@ public class LauncherModel extends BroadcastReceiver
synchronized (sBgLock) {
sBgItemsIdMap.remove(info.id);
sBgFolders.remove(info.id);
- sBgDbIconCache.remove(info);
sBgWorkspaceItems.remove(info);
}
@@ -1229,7 +1207,6 @@ public class LauncherModel extends BroadcastReceiver
synchronized (sBgLock) {
for (ItemInfo childInfo : info.contents) {
sBgItemsIdMap.remove(childInfo.id);
- sBgDbIconCache.remove(childInfo);
}
}
}
@@ -1442,40 +1419,31 @@ public class LauncherModel extends BroadcastReceiver
}
}
- /** Loads the workspace screens db into a map of Rank -> ScreenId */
- private static TreeMap<Integer, Long> loadWorkspaceScreensDb(Context context) {
+ /**
+ * Loads the workspace screen ids in an ordered list.
+ */
+ private static ArrayList<Long> loadWorkspaceScreensDb(Context context) {
final ContentResolver contentResolver = context.getContentResolver();
final Uri screensUri = LauncherSettings.WorkspaceScreens.CONTENT_URI;
- final Cursor sc = contentResolver.query(screensUri, null, null, null, null);
- TreeMap<Integer, Long> orderedScreens = new TreeMap<Integer, Long>();
+ // Get screens ordered by rank.
+ final Cursor sc = contentResolver.query(screensUri, null, null, null,
+ LauncherSettings.WorkspaceScreens.SCREEN_RANK);
+ ArrayList<Long> screenIds = new ArrayList<Long>();
try {
- final int idIndex = sc.getColumnIndexOrThrow(
- LauncherSettings.WorkspaceScreens._ID);
- final int rankIndex = sc.getColumnIndexOrThrow(
- LauncherSettings.WorkspaceScreens.SCREEN_RANK);
+ final int idIndex = sc.getColumnIndexOrThrow(LauncherSettings.WorkspaceScreens._ID);
while (sc.moveToNext()) {
try {
- long screenId = sc.getLong(idIndex);
- int rank = sc.getInt(rankIndex);
- orderedScreens.put(rank, screenId);
+ screenIds.add(sc.getLong(idIndex));
} catch (Exception e) {
- Launcher.addDumpLog(TAG, "Desktop items loading interrupted - invalid screens: " + e, true);
+ Launcher.addDumpLog(TAG, "Desktop items loading interrupted"
+ + " - invalid screens: " + e, true);
}
}
} finally {
sc.close();
}
-
- // Log to disk
- Launcher.addDumpLog(TAG, "11683562 - loadWorkspaceScreensDb()", true);
- ArrayList<String> orderedScreensPairs= new ArrayList<String>();
- for (Integer i : orderedScreens.keySet()) {
- orderedScreensPairs.add("{ " + i + ": " + orderedScreens.get(i) + " }");
- }
- Launcher.addDumpLog(TAG, "11683562 - screens: " +
- TextUtils.join(", ", orderedScreensPairs), true);
- return orderedScreens;
+ return screenIds;
}
public boolean isAllAppsLoaded() {
@@ -1505,12 +1473,9 @@ public class LauncherModel extends BroadcastReceiver
private boolean mLoadAndBindStepFinished;
private int mFlags;
- private HashMap<Object, CharSequence> mLabelCache;
-
LoaderTask(Context context, boolean isLaunching, int flags) {
mContext = context;
mIsLaunching = isLaunching;
- mLabelCache = new HashMap<Object, CharSequence>();
mFlags = flags;
}
@@ -1522,8 +1487,7 @@ public class LauncherModel extends BroadcastReceiver
return mIsLoadingAndBindingWorkspace;
}
- /** Returns whether this is an upgrade path */
- private boolean loadAndBindWorkspace() {
+ private void loadAndBindWorkspace() {
mIsLoadingAndBindingWorkspace = true;
// Load the workspace
@@ -1531,20 +1495,18 @@ public class LauncherModel extends BroadcastReceiver
Log.d(TAG, "loadAndBindWorkspace mWorkspaceLoaded=" + mWorkspaceLoaded);
}
- boolean isUpgradePath = false;
if (!mWorkspaceLoaded) {
- isUpgradePath = loadWorkspace();
+ loadWorkspace();
synchronized (LoaderTask.this) {
if (mStopped) {
- return isUpgradePath;
+ return;
}
mWorkspaceLoaded = true;
}
}
// Bind the workspace
- bindWorkspace(-1, isUpgradePath);
- return isUpgradePath;
+ bindWorkspace(-1);
}
private void waitForIdle() {
@@ -1613,15 +1575,13 @@ public class LauncherModel extends BroadcastReceiver
// Divide the set of loaded items into those that we are binding synchronously, and
// everything else that is to be bound normally (asynchronously).
- bindWorkspace(synchronousBindPage, false);
+ bindWorkspace(synchronousBindPage);
// XXX: For now, continue posting the binding of AllApps as there are other issues that
// arise from that.
onlyBindAllApps();
}
public void run() {
- boolean isUpgrade = false;
-
synchronized (mLock) {
mIsLoaderTaskRunning = true;
}
@@ -1638,7 +1598,7 @@ public class LauncherModel extends BroadcastReceiver
? Process.THREAD_PRIORITY_DEFAULT : Process.THREAD_PRIORITY_BACKGROUND);
}
if (DEBUG_LOADERS) Log.d(TAG, "step 1: loading workspace");
- isUpgrade = loadAndBindWorkspace();
+ loadAndBindWorkspace();
if (mStopped) {
break keep_running;
@@ -1664,23 +1624,6 @@ public class LauncherModel extends BroadcastReceiver
}
}
- // Update the saved icons if necessary
- if (DEBUG_LOADERS) Log.d(TAG, "Comparing loaded icons to database icons");
- synchronized (sBgLock) {
- for (Object key : sBgDbIconCache.keySet()) {
- updateSavedIcon(mContext, (ShortcutInfo) key, sBgDbIconCache.get(key));
- }
- sBgDbIconCache.clear();
- }
-
- if (LauncherAppState.isDisableAllApps()) {
- // Ensure that all the applications that are in the system are
- // represented on the home screen.
- if (!UPGRADE_USE_MORE_APPS_FOLDER || !isUpgrade) {
- verifyApplications();
- }
- }
-
// Clear out this reference, otherwise we end up holding it until all of the
// callback runnables are done.
mContext = null;
@@ -1731,28 +1674,6 @@ public class LauncherModel extends BroadcastReceiver
}
}
- private void verifyApplications() {
- final Context context = mApp.getContext();
-
- // Cross reference all the applications in our apps list with items in the workspace
- ArrayList<ItemInfo> tmpInfos;
- ArrayList<ItemInfo> added = new ArrayList<ItemInfo>();
- synchronized (sBgLock) {
- for (AppInfo app : mBgAllAppsList.data) {
- tmpInfos = getItemInfoForComponentName(app.componentName, app.user);
- if (tmpInfos.isEmpty()) {
- // We are missing an application icon, so add this to the workspace
- added.add(app);
- // This is a rare event, so lets log it
- Log.e(TAG, "Missing Application on load: " + app);
- }
- }
- }
- if (!added.isEmpty()) {
- addAndBindAddedWorkspaceApps(context, added);
- }
- }
-
// check & update map of what's occupied; used to discard overlapping/invalid items
private boolean checkItemPlacement(HashMap<Long, ItemInfo[][]> occupied, ItemInfo item) {
LauncherAppState app = LauncherAppState.getInstance();
@@ -1850,13 +1771,11 @@ public class LauncherModel extends BroadcastReceiver
sBgAppWidgets.clear();
sBgFolders.clear();
sBgItemsIdMap.clear();
- sBgDbIconCache.clear();
sBgWorkspaceScreens.clear();
}
}
- /** Returns whether this is an upgrade path */
- private boolean loadWorkspace() {
+ private void loadWorkspace() {
// Log to disk
Launcher.addDumpLog(TAG, "11683562 - loadWorkspace()", true);
@@ -1890,12 +1809,6 @@ public class LauncherModel extends BroadcastReceiver
LauncherAppState.getLauncherProvider().loadDefaultFavoritesIfNecessary();
}
- // This code path is for our old migration code and should no longer be exercised
- boolean loadedOldDb = false;
-
- // Log to disk
- Launcher.addDumpLog(TAG, "11683562 - loadedOldDb: " + loadedOldDb, true);
-
synchronized (sBgLock) {
clearSBgDataStructures();
final HashSet<String> installingPkgs = PackageInstallerCompat
@@ -1976,6 +1889,7 @@ public class LauncherModel extends BroadcastReceiver
user = mUserManager.getUserForSerialNumber(serialNumber);
int promiseType = c.getInt(restoredIndex);
int disabledState = 0;
+ boolean itemReplaced = false;
if (user == null) {
// User has been deleted remove the item.
itemsToRemove.add(id);
@@ -2007,9 +1921,7 @@ public class LauncherModel extends BroadcastReceiver
ContentValues values = new ContentValues();
values.put(LauncherSettings.Favorites.INTENT,
intent.toUri(0));
- String where = BaseColumns._ID + "= ?";
- String[] args = {Long.toString(id)};
- contentResolver.update(contentUri, values, where, args);
+ updateItem(id, values);
}
}
@@ -2039,10 +1951,27 @@ public class LauncherModel extends BroadcastReceiver
ContentValues values = new ContentValues();
values.put(LauncherSettings.Favorites.RESTORED,
promiseType);
- String where = BaseColumns._ID + "= ?";
- String[] args = {Long.toString(id)};
- contentResolver.update(contentUri, values, where, args);
-
+ updateItem(id, values);
+ } else if ((promiseType & ShortcutInfo.FLAG_RESTORED_APP_TYPE) != 0) {
+ // This is a common app. Try to replace this.
+ int appType = CommonAppTypeParser.decodeItemTypeFromFlag(promiseType);
+ CommonAppTypeParser parser = new CommonAppTypeParser(id, appType, context);
+ if (parser.findDefaultApp()) {
+ // Default app found. Replace it.
+ intent = parser.parsedIntent;
+ cn = intent.getComponent();
+ ContentValues values = parser.parsedValues;
+ values.put(LauncherSettings.Favorites.RESTORED, 0);
+ updateItem(id, values);
+ restored = false;
+ itemReplaced = true;
+
+ } else if (REMOVE_UNRESTORED_ICONS) {
+ Launcher.addDumpLog(TAG,
+ "Unrestored package removed: " + cn, true);
+ itemsToRemove.add(id);
+ continue;
+ }
} else if (REMOVE_UNRESTORED_ICONS) {
Launcher.addDumpLog(TAG,
"Unrestored package removed: " + cn, true);
@@ -2088,7 +2017,16 @@ public class LauncherModel extends BroadcastReceiver
continue;
}
- if (restored) {
+ if (itemReplaced) {
+ if (user.equals(UserHandleCompat.myUserHandle())) {
+ info = getAppShortcutInfo(manager, intent, user, context, null,
+ iconIndex, titleIndex, false);
+ } else {
+ // Don't replace items for other profiles.
+ itemsToRemove.add(id);
+ continue;
+ }
+ } else if (restored) {
if (user.equals(UserHandleCompat.myUserHandle())) {
Launcher.addDumpLog(TAG,
"constructing info for partially restored package",
@@ -2102,8 +2040,8 @@ public class LauncherModel extends BroadcastReceiver
}
} else if (itemType ==
LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
- info = getShortcutInfo(manager, intent, user, context, c,
- iconIndex, titleIndex, mLabelCache, allowMissingTarget);
+ info = getAppShortcutInfo(manager, intent, user, context, c,
+ iconIndex, titleIndex, allowMissingTarget);
} else {
info = getShortcutInfo(c, context, iconTypeIndex,
iconPackageIndex, iconResourceIndex, iconIndex,
@@ -2158,10 +2096,6 @@ public class LauncherModel extends BroadcastReceiver
break;
}
sBgItemsIdMap.put(info.id, info);
-
- // now that we've loaded everthing re-save it with the
- // icon in case it disappears somehow.
- queueIconToBeChecked(sBgDbIconCache, info, c, iconIndex);
} else {
throw new RuntimeException("Unexpected null ShortcutInfo");
}
@@ -2322,9 +2256,7 @@ public class LauncherModel extends BroadcastReceiver
providerName);
values.put(LauncherSettings.Favorites.RESTORED,
appWidgetInfo.restoreStatus);
- String where = BaseColumns._ID + "= ?";
- String[] args = {Long.toString(id)};
- contentResolver.update(contentUri, values, where, args);
+ updateItem(id, values);
}
}
sBgItemsIdMap.put(appWidgetInfo.id, appWidgetInfo);
@@ -2345,7 +2277,7 @@ public class LauncherModel extends BroadcastReceiver
// Break early if we've stopped loading
if (mStopped) {
clearSBgDataStructures();
- return false;
+ return;
}
if (itemsToRemove.size() > 0) {
@@ -2391,63 +2323,29 @@ public class LauncherModel extends BroadcastReceiver
null, sWorker);
}
- if (loadedOldDb) {
- long maxScreenId = 0;
- // If we're importing we use the old screen order.
- for (ItemInfo item: sBgItemsIdMap.values()) {
- long screenId = item.screenId;
- if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP &&
- !sBgWorkspaceScreens.contains(screenId)) {
- sBgWorkspaceScreens.add(screenId);
- if (screenId > maxScreenId) {
- maxScreenId = screenId;
- }
- }
- }
- Collections.sort(sBgWorkspaceScreens);
- // Log to disk
- Launcher.addDumpLog(TAG, "11683562 - maxScreenId: " + maxScreenId, true);
- Launcher.addDumpLog(TAG, "11683562 - sBgWorkspaceScreens: " +
- TextUtils.join(", ", sBgWorkspaceScreens), true);
+ sBgWorkspaceScreens.addAll(loadWorkspaceScreensDb(mContext));
+ // Log to disk
+ Launcher.addDumpLog(TAG, "11683562 - sBgWorkspaceScreens: " +
+ TextUtils.join(", ", sBgWorkspaceScreens), true);
- LauncherAppState.getLauncherProvider().updateMaxScreenId(maxScreenId);
- updateWorkspaceScreenOrder(context, sBgWorkspaceScreens);
-
- // Update the max item id after we load an old db
- long maxItemId = 0;
- // If we're importing we use the old screen order.
- for (ItemInfo item: sBgItemsIdMap.values()) {
- maxItemId = Math.max(maxItemId, item.id);
- }
- LauncherAppState.getLauncherProvider().updateMaxItemId(maxItemId);
- } else {
- TreeMap<Integer, Long> orderedScreens = loadWorkspaceScreensDb(mContext);
- for (Integer i : orderedScreens.keySet()) {
- sBgWorkspaceScreens.add(orderedScreens.get(i));
- }
- // Log to disk
- Launcher.addDumpLog(TAG, "11683562 - sBgWorkspaceScreens: " +
- TextUtils.join(", ", sBgWorkspaceScreens), true);
-
- // Remove any empty screens
- ArrayList<Long> unusedScreens = new ArrayList<Long>(sBgWorkspaceScreens);
- for (ItemInfo item: sBgItemsIdMap.values()) {
- long screenId = item.screenId;
- if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP &&
- unusedScreens.contains(screenId)) {
- unusedScreens.remove(screenId);
- }
+ // Remove any empty screens
+ ArrayList<Long> unusedScreens = new ArrayList<Long>(sBgWorkspaceScreens);
+ for (ItemInfo item: sBgItemsIdMap.values()) {
+ long screenId = item.screenId;
+ if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP &&
+ unusedScreens.contains(screenId)) {
+ unusedScreens.remove(screenId);
}
+ }
- // If there are any empty screens remove them, and update.
- if (unusedScreens.size() != 0) {
- // Log to disk
- Launcher.addDumpLog(TAG, "11683562 - unusedScreens (to be removed): " +
- TextUtils.join(", ", unusedScreens), true);
+ // If there are any empty screens remove them, and update.
+ if (unusedScreens.size() != 0) {
+ // Log to disk
+ Launcher.addDumpLog(TAG, "11683562 - unusedScreens (to be removed): " +
+ TextUtils.join(", ", unusedScreens), true);
- sBgWorkspaceScreens.removeAll(unusedScreens);
- updateWorkspaceScreenOrder(context, sBgWorkspaceScreens);
- }
+ sBgWorkspaceScreens.removeAll(unusedScreens);
+ updateWorkspaceScreenOrder(context, sBgWorkspaceScreens);
}
if (DEBUG_LOADERS) {
@@ -2476,7 +2374,17 @@ public class LauncherModel extends BroadcastReceiver
}
}
}
- return loadedOldDb;
+ }
+
+ /**
+ * Partially updates the item without any notification. Must be called on the worker thread.
+ */
+ private void updateItem(long itemId, ContentValues update) {
+ mContext.getContentResolver().update(
+ LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION,
+ update,
+ BaseColumns._ID + "= ?",
+ new String[]{Long.toString(itemId)});
}
/** Filters the set of items who are directly or indirectly (via another container) on the
@@ -2673,7 +2581,7 @@ public class LauncherModel extends BroadcastReceiver
/**
* Binds all loaded data to actual views on the main thread.
*/
- private void bindWorkspace(int synchronizeBindPage, final boolean isUpgradePath) {
+ private void bindWorkspace(int synchronizeBindPage) {
final long t = SystemClock.uptimeMillis();
Runnable r;
@@ -2777,7 +2685,7 @@ public class LauncherModel extends BroadcastReceiver
public void run() {
Callbacks callbacks = tryGetCallbacks(oldCallbacks);
if (callbacks != null) {
- callbacks.finishBindingItems(isUpgradePath);
+ callbacks.finishBindingItems();
}
// If we're profiling, ensure this is the last thing in the queue.
@@ -2881,20 +2789,48 @@ public class LauncherModel extends BroadcastReceiver
if (apps == null || apps.isEmpty()) {
return;
}
- // Sort the applications by name
- final long sortTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;
- Collections.sort(apps,
- new LauncherModel.ShortcutNameComparator(mLabelCache));
- if (DEBUG_LOADERS) {
- Log.d(TAG, "sort took "
- + (SystemClock.uptimeMillis()-sortTime) + "ms");
+
+ // Update icon cache
+ HashSet<String> updatedPackages = mIconCache.updateDBIcons(user, apps);
+
+ // If any package icon has changed (app was updated while launcher was dead),
+ // update the corresponding shortcuts.
+ if (!updatedPackages.isEmpty()) {
+ final ArrayList<ShortcutInfo> updates = new ArrayList<ShortcutInfo>();
+ synchronized (sBgLock) {
+ for (ItemInfo info : sBgItemsIdMap.values()) {
+ if (info instanceof ShortcutInfo && user.equals(info.user)
+ && info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
+ ShortcutInfo si = (ShortcutInfo) info;
+ ComponentName cn = si.getTargetComponent();
+ if (cn != null && updatedPackages.contains(cn.getPackageName())) {
+ si.updateIcon(mIconCache);
+ updates.add(si);
+ }
+ }
+ }
+ }
+
+ if (!updates.isEmpty()) {
+ final UserHandleCompat userFinal = user;
+ mHandler.post(new Runnable() {
+
+ public void run() {
+ Callbacks cb = getCallback();
+ if (cb != null) {
+ cb.bindShortcutsChanged(
+ updates, new ArrayList<ShortcutInfo>(), userFinal);
+ }
+ }
+ });
+ }
}
// Create the ApplicationInfos
for (int i = 0; i < apps.size(); i++) {
LauncherActivityInfoCompat app = apps.get(i);
// This builds the icon bitmaps.
- mBgAllAppsList.add(new AppInfo(mContext, app, user, mIconCache, mLabelCache));
+ mBgAllAppsList.add(new AppInfo(mContext, app, user, mIconCache));
}
if (ADD_MANAGED_PROFILE_SHORTCUTS && !user.equals(UserHandleCompat.myUserHandle())) {
@@ -3026,7 +2962,7 @@ public class LauncherModel extends BroadcastReceiver
case OP_ADD:
for (int i=0; i<N; i++) {
if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.addPackage " + packages[i]);
- mIconCache.remove(packages[i], mUser);
+ mIconCache.updateIconsForPkg(packages[i], mUser);
mBgAllAppsList.addPackage(context, packages[i], mUser);
}
@@ -3058,6 +2994,7 @@ public class LauncherModel extends BroadcastReceiver
case OP_UPDATE:
for (int i=0; i<N; i++) {
if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.updatePackage " + packages[i]);
+ mIconCache.updateIconsForPkg(packages[i], mUser);
mBgAllAppsList.updatePackage(context, packages[i], mUser);
WidgetPreviewLoader.removePackageFromDb(
mApp.getWidgetPreviewCacheDb(), packages[i]);
@@ -3077,12 +3014,15 @@ public class LauncherModel extends BroadcastReceiver
shortcutSet.removeAll(Arrays.asList(mPackages));
prefs.edit().putStringSet(shortcutsSetKey, shortcutSet).commit();
}
+ for (int i=0; i<N; i++) {
+ if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.removePackage " + packages[i]);
+ mIconCache.removeIconsForPkg(packages[i], mUser);
+ }
// Fall through
case OP_UNAVAILABLE:
- boolean clearCache = mOp == OP_REMOVE;
for (int i=0; i<N; i++) {
if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.removePackage " + packages[i]);
- mBgAllAppsList.removePackage(packages[i], mUser, clearCache);
+ mBgAllAppsList.removePackage(packages[i], mUser);
WidgetPreviewLoader.removePackageFromDb(
mApp.getWidgetPreviewCacheDb(), packages[i]);
}
@@ -3116,13 +3056,7 @@ public class LauncherModel extends BroadcastReceiver
new HashMap<ComponentName, AppInfo>();
if (added != null) {
- // Ensure that we add all the workspace applications to the db
- if (LauncherAppState.isDisableAllApps()) {
- final ArrayList<ItemInfo> addedInfos = new ArrayList<ItemInfo>(added);
- addAndBindAddedWorkspaceApps(context, addedInfos);
- } else {
- addAppsToAllApps(context, added);
- }
+ addAppsToAllApps(context, added);
for (AppInfo ai : added) {
addedOrUpdatedApps.put(ai.componentName, ai);
}
@@ -3175,7 +3109,6 @@ public class LauncherModel extends BroadcastReceiver
AppInfo appInfo = addedOrUpdatedApps.get(cn);
if (si.isPromise()) {
- mIconCache.deletePreloadedIcon(cn, mUser);
if (si.hasStatusFlag(ShortcutInfo.FLAG_AUTOINTALL_ICON)) {
// Auto install icon
PackageManager pm = context.getPackageManager();
@@ -3420,7 +3353,7 @@ public class LauncherModel extends BroadcastReceiver
int promiseType) {
final ShortcutInfo info = new ShortcutInfo();
info.user = UserHandleCompat.myUserHandle();
- mIconCache.getTitleAndIcon(info, intent, info.user, true);
+ mIconCache.getTitleAndIcon(info, intent, info.user);
if ((promiseType & ShortcutInfo.FLAG_RESTORED_ICON) != 0) {
String title = (cursor != null) ? cursor.getString(titleIndex) : null;
@@ -3463,22 +3396,13 @@ public class LauncherModel extends BroadcastReceiver
}
/**
- * This is called from the code that adds shortcuts from the intent receiver. This
- * doesn't have a Cursor, but
- */
- public ShortcutInfo getShortcutInfo(PackageManager manager, Intent intent,
- UserHandleCompat user, Context context) {
- return getShortcutInfo(manager, intent, user, context, null, -1, -1, null, false);
- }
-
- /**
* Make an ShortcutInfo object for a shortcut that is an application.
*
* If c is not null, then it will be used to fill in missing data like the title and icon.
*/
- public ShortcutInfo getShortcutInfo(PackageManager manager, Intent intent,
+ public ShortcutInfo getAppShortcutInfo(PackageManager manager, Intent intent,
UserHandleCompat user, Context context, Cursor c, int iconIndex, int titleIndex,
- HashMap<Object, CharSequence> labelCache, boolean allowMissingTarget) {
+ boolean allowMissingTarget) {
if (user == null) {
Log.d(TAG, "Null user found in getShortcutInfo");
return null;
@@ -3500,48 +3424,22 @@ public class LauncherModel extends BroadcastReceiver
}
final ShortcutInfo info = new ShortcutInfo();
-
- // the resource -- This may implicitly give us back the fallback icon,
- // but don't worry about that. All we're doing with usingFallbackIcon is
- // to avoid saving lots of copies of that in the database, and most apps
- // have icons anyway.
- Bitmap icon = mIconCache.getIcon(componentName, lai, labelCache);
-
- // the db
- if (icon == null) {
- if (c != null) {
- icon = getIconFromCursor(c, iconIndex, context);
- }
+ mIconCache.getTitleAndIcon(info, componentName, lai, user, false);
+ if (mIconCache.isDefaultIcon(info.getIcon(mIconCache), user) && c != null) {
+ Bitmap icon = Utilities.createIconBitmap(c, iconIndex, context);
+ info.setIcon(icon == null ? mIconCache.getDefaultIcon(user) : icon);
}
- // the fallback icon
- if (icon == null) {
- icon = mIconCache.getDefaultIcon(user);
- info.usingFallbackIcon = true;
- }
- info.setIcon(icon);
- // From the cache.
- if (labelCache != null) {
- info.title = labelCache.get(componentName);
- }
-
- // from the resource
- if (info.title == null && lai != null) {
- info.title = lai.getLabel();
- if (labelCache != null) {
- labelCache.put(componentName, info.title);
- }
- }
// from the db
- if (info.title == null) {
- if (c != null) {
- info.title = c.getString(titleIndex);
- }
+ if (TextUtils.isEmpty(info.title) && c != null) {
+ info.title = c.getString(titleIndex);
}
+
// fall back to the class name of the activity
if (info.title == null) {
info.title = componentName.getClassName();
}
+
info.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
info.user = user;
info.contentDescription = mUserManager.getBadgedLabelForUser(
@@ -3620,7 +3518,7 @@ public class LauncherModel extends BroadcastReceiver
icon = Utilities.createIconBitmap(packageName, resourceName, mIconCache, context);
// the db
if (icon == null) {
- icon = getIconFromCursor(c, iconIndex, context);
+ icon = Utilities.createIconBitmap(c, iconIndex, context);
}
// the fallback icon
if (icon == null) {
@@ -3629,7 +3527,7 @@ public class LauncherModel extends BroadcastReceiver
}
break;
case LauncherSettings.Favorites.ICON_TYPE_BITMAP:
- icon = getIconFromCursor(c, iconIndex, context);
+ icon = Utilities.createIconBitmap(c, iconIndex, context);
if (icon == null) {
icon = mIconCache.getDefaultIcon(info.user);
info.customIcon = false;
@@ -3648,22 +3546,6 @@ public class LauncherModel extends BroadcastReceiver
return info;
}
- Bitmap getIconFromCursor(Cursor c, int iconIndex, Context context) {
- @SuppressWarnings("all") // suppress dead code warning
- final boolean debug = false;
- if (debug) {
- Log.d(TAG, "getIconFromCursor app="
- + c.getString(c.getColumnIndexOrThrow(LauncherSettings.Favorites.TITLE)));
- }
- byte[] data = c.getBlob(iconIndex);
- try {
- return Utilities.createIconBitmap(
- BitmapFactory.decodeByteArray(data, 0, data.length), context);
- } catch (Exception e) {
- return null;
- }
- }
-
ShortcutInfo infoFromShortcutIntent(Context context, Intent data) {
Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
@@ -3712,45 +3594,6 @@ public class LauncherModel extends BroadcastReceiver
return info;
}
- boolean queueIconToBeChecked(HashMap<Object, byte[]> cache, ShortcutInfo info, Cursor c,
- int iconIndex) {
- // If apps can't be on SD, don't even bother.
- if (!mAppsCanBeOnRemoveableStorage) {
- return false;
- }
- // If this icon doesn't have a custom icon, check to see
- // what's stored in the DB, and if it doesn't match what
- // we're going to show, store what we are going to show back
- // into the DB. We do this so when we're loading, if the
- // package manager can't find an icon (for example because
- // the app is on SD) then we can use that instead.
- if (!info.customIcon && !info.usingFallbackIcon) {
- cache.put(info, c.getBlob(iconIndex));
- return true;
- }
- return false;
- }
- void updateSavedIcon(Context context, ShortcutInfo info, byte[] data) {
- boolean needSave = false;
- try {
- if (data != null) {
- Bitmap saved = BitmapFactory.decodeByteArray(data, 0, data.length);
- Bitmap loaded = info.getIcon(mIconCache);
- needSave = !saved.sameAs(loaded);
- } else {
- needSave = true;
- }
- } catch (Exception e) {
- needSave = true;
- }
- if (needSave) {
- Log.d(TAG, "going to save icon bitmap for info=" + info);
- // This is slower than is ideal, but this only happens once
- // or when the app is updated with a new icon.
- updateItemInDatabase(context, info);
- }
- }
-
/**
* Return an existing FolderInfo object if we have encountered this ID previously,
* or make a new one.
@@ -3800,38 +3643,7 @@ public class LauncherModel extends BroadcastReceiver
return new ComponentName(info.serviceInfo.packageName, info.serviceInfo.name);
}
}
- public static class ShortcutNameComparator implements Comparator<LauncherActivityInfoCompat> {
- private Collator mCollator;
- private HashMap<Object, CharSequence> mLabelCache;
- ShortcutNameComparator(PackageManager pm) {
- mLabelCache = new HashMap<Object, CharSequence>();
- mCollator = Collator.getInstance();
- }
- ShortcutNameComparator(HashMap<Object, CharSequence> labelCache) {
- mLabelCache = labelCache;
- mCollator = Collator.getInstance();
- }
- public final int compare(LauncherActivityInfoCompat a, LauncherActivityInfoCompat b) {
- String labelA, labelB;
- ComponentName keyA = a.getComponentName();
- ComponentName keyB = b.getComponentName();
- if (mLabelCache.containsKey(keyA)) {
- labelA = mLabelCache.get(keyA).toString();
- } else {
- labelA = a.getLabel().toString().trim();
-
- mLabelCache.put(keyA, labelA);
- }
- if (mLabelCache.containsKey(keyB)) {
- labelB = mLabelCache.get(keyB).toString();
- } else {
- labelB = b.getLabel().toString().trim();
- mLabelCache.put(keyB, labelB);
- }
- return mCollator.compare(labelA, labelB);
- }
- };
public static class WidgetAndShortcutNameComparator implements Comparator<Object> {
private final AppWidgetManagerCompat mManager;
private final PackageManager mPackageManager;