summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/LauncherModel.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2015-01-15 12:00:14 -0800
committerSunny Goyal <sunnygoyal@google.com>2015-01-22 10:54:50 -0800
commitbb3b02f562bef4de063099c085d3199a77d06cfd (patch)
tree2f6406ed5a6ab27e7fc038e5ab993a398c8f51ac /src/com/android/launcher3/LauncherModel.java
parent3862e4d88bf7c8673ed6bc129d21417eaf77a4b9 (diff)
downloadandroid_packages_apps_Trebuchet-bb3b02f562bef4de063099c085d3199a77d06cfd.tar.gz
android_packages_apps_Trebuchet-bb3b02f562bef4de063099c085d3199a77d06cfd.tar.bz2
android_packages_apps_Trebuchet-bb3b02f562bef4de063099c085d3199a77d06cfd.zip
Replacing hotseat icon to an appropriate system app
> During backupi, store the hotseat target app type, based on some predefined common system apps > During restore, save this app type in the restore flag, if it is a hotseat app > During first launcher load, if an app is not being restored, try to replace it with an appropriate replacement for that type, otherwise delete it. Bug: 18764649 Change-Id: Ic49e40bd707bd8d7de18bbab8b1e58a0a36426a2
Diffstat (limited to 'src/com/android/launcher3/LauncherModel.java')
-rw-r--r--src/com/android/launcher3/LauncherModel.java56
1 files changed, 45 insertions, 11 deletions
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 2e879bcec..78790688a 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -1955,6 +1955,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);
@@ -1986,9 +1987,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);
}
}
@@ -2018,10 +2017,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);
@@ -2067,7 +2083,16 @@ public class LauncherModel extends BroadcastReceiver
continue;
}
- if (restored) {
+ if (itemReplaced) {
+ if (user.equals(UserHandleCompat.myUserHandle())) {
+ info = getShortcutInfo(manager, intent, user, context, null,
+ iconIndex, titleIndex, mLabelCache, 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",
@@ -2301,9 +2326,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);
@@ -2455,6 +2478,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
* specified screen. */
private void filterCurrentWorkspaceItems(long currentScreenId,