summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Wren <cwren@android.com>2013-12-20 17:22:11 -0500
committerDanesh M <daneshm90@gmail.com>2014-06-06 22:54:25 -0700
commit60f748d669be4794afb2b41add3a399973553429 (patch)
tree4d79c6fa1d8790658f07ce6d0afc1b09c3936b98
parent03aec6cf90e244fb88b1b01a3543d4da56742a39 (diff)
downloadandroid_packages_apps_Trebuchet-60f748d669be4794afb2b41add3a399973553429.tar.gz
android_packages_apps_Trebuchet-60f748d669be4794afb2b41add3a399973553429.tar.bz2
android_packages_apps_Trebuchet-60f748d669be4794afb2b41add3a399973553429.zip
restore app favorites and screens
version 0: restore assuming apps are already installed. Bug: 10779035 Change-Id: I7f9aa418a7d3d5460a79a229c0fbc80305b5eb5c
-rw-r--r--src/com/android/launcher3/LauncherBackupHelper.java85
-rw-r--r--src/com/android/launcher3/LauncherProvider.java13
2 files changed, 89 insertions, 9 deletions
diff --git a/src/com/android/launcher3/LauncherBackupHelper.java b/src/com/android/launcher3/LauncherBackupHelper.java
index 5b722c1d3..677855d0f 100644
--- a/src/com/android/launcher3/LauncherBackupHelper.java
+++ b/src/com/android/launcher3/LauncherBackupHelper.java
@@ -39,6 +39,7 @@ import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
import android.content.ComponentName;
import android.content.ContentResolver;
+import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
@@ -332,9 +333,15 @@ public class LauncherBackupHelper implements BackupHelper {
if (DEBUG) Log.d(TAG, "read (" + buffer.length + "): " +
Base64.encodeToString(buffer, 0, dataSize, Base64.NO_WRAP));
+ if (!mRestoreEnabled) {
+ if (DEBUG) Log.v(TAG, "restore not enabled: skipping database mutation");
+ return;
+ }
+
try {
- Favorite favorite = unpackFavorite(buffer, 0, dataSize);
- if (DEBUG) Log.d(TAG, "unpacked " + favorite.itemType);
+ ContentResolver cr = mContext.getContentResolver();
+ ContentValues values = unpackFavorite(buffer, 0, dataSize);
+ cr.insert(Favorites.CONTENT_URI, values);
} catch (InvalidProtocolBufferNanoException e) {
Log.w(TAG, "failed to decode proto", e);
}
@@ -364,6 +371,7 @@ public class LauncherBackupHelper implements BackupHelper {
Set<String> currentIds = new HashSet<String>(cursor.getCount());
try {
cursor.moveToPosition(-1);
+ Log.d(TAG, "dumping screens after: " + in.t);
while(cursor.moveToNext()) {
final long id = cursor.getLong(ID_INDEX);
final long updateTime = cursor.getLong(ID_MODIFIED);
@@ -374,6 +382,9 @@ public class LauncherBackupHelper implements BackupHelper {
if (!savedIds.contains(backupKey) || updateTime >= in.t) {
byte[] blob = packScreen(cursor);
writeRowToBackup(key, blob, out, data);
+ if (DEBUG) Log.d(TAG, "wrote screen " + id);
+ } else {
+ if (DEBUG) Log.d(TAG, "screen " + id + " was too old: " + updateTime);
}
}
} finally {
@@ -400,9 +411,17 @@ public class LauncherBackupHelper implements BackupHelper {
Log.v(TAG, "unpacking screen " + key.id);
if (DEBUG) Log.d(TAG, "read (" + buffer.length + "): " +
Base64.encodeToString(buffer, 0, dataSize, Base64.NO_WRAP));
+
+ if (!mRestoreEnabled) {
+ if (DEBUG) Log.v(TAG, "restore not enabled: skipping database mutation");
+ return;
+ }
+
try {
- Screen screen = unpackScreen(buffer, 0, dataSize);
- if (DEBUG) Log.d(TAG, "unpacked " + screen.rank);
+ ContentResolver cr = mContext.getContentResolver();
+ ContentValues values = unpackScreen(buffer, 0, dataSize);
+ cr.insert(WorkspaceScreens.CONTENT_URI, values);
+
} catch (InvalidProtocolBufferNanoException e) {
Log.w(TAG, "failed to decode proto", e);
}
@@ -520,6 +539,13 @@ public class LauncherBackupHelper implements BackupHelper {
if (icon == null) {
Log.w(TAG, "failed to unpack icon for " + key.name);
}
+
+ if (!mRestoreEnabled) {
+ if (DEBUG) Log.v(TAG, "restore not enabled: skipping database mutation");
+ return;
+ } else {
+ // future site of icon cache mutation
+ }
} catch (InvalidProtocolBufferNanoException e) {
Log.w(TAG, "failed to decode proto", e);
}
@@ -635,6 +661,13 @@ public class LauncherBackupHelper implements BackupHelper {
Log.w(TAG, "failed to unpack widget icon for " + key.name);
}
}
+
+ if (!mRestoreEnabled) {
+ if (DEBUG) Log.v(TAG, "restore not enabled: skipping database mutation");
+ return;
+ } else {
+ // future site of widget table mutation
+ }
} catch (InvalidProtocolBufferNanoException e) {
Log.w(TAG, "failed to decode proto", e);
}
@@ -771,11 +804,43 @@ public class LauncherBackupHelper implements BackupHelper {
}
/** Deserialize a Favorite from persistence, after verifying checksum wrapper. */
- private Favorite unpackFavorite(byte[] buffer, int offset, int dataSize)
+ private ContentValues unpackFavorite(byte[] buffer, int offset, int dataSize)
throws InvalidProtocolBufferNanoException {
Favorite favorite = new Favorite();
MessageNano.mergeFrom(favorite, readCheckedBytes(buffer, offset, dataSize));
- return favorite;
+ if (DEBUG) Log.d(TAG, "unpacked " + favorite.itemType + ", " + favorite.id);
+ ContentValues values = new ContentValues();
+ values.put(Favorites._ID, favorite.id);
+ values.put(Favorites.SCREEN, favorite.screen);
+ values.put(Favorites.CONTAINER, favorite.container);
+ values.put(Favorites.CELLX, favorite.cellX);
+ values.put(Favorites.CELLY, favorite.cellY);
+ values.put(Favorites.SPANX, favorite.spanX);
+ values.put(Favorites.SPANY, favorite.spanY);
+ values.put(Favorites.ICON_TYPE, favorite.iconType);
+ if (favorite.iconType == Favorites.ICON_TYPE_RESOURCE) {
+ values.put(Favorites.ICON_PACKAGE, favorite.iconPackage);
+ values.put(Favorites.ICON_RESOURCE, favorite.iconResource);
+ }
+ if (favorite.iconType == Favorites.ICON_TYPE_BITMAP) {
+ values.put(Favorites.ICON, favorite.icon);
+ }
+ if (!TextUtils.isEmpty(favorite.title)) {
+ values.put(Favorites.TITLE, favorite.title);
+ } else {
+ values.put(Favorites.TITLE, "");
+ }
+ if (!TextUtils.isEmpty(favorite.intent)) {
+ values.put(Favorites.INTENT, favorite.intent);
+ }
+ values.put(Favorites.ITEM_TYPE, favorite.itemType);
+ if (favorite.itemType == Favorites.ITEM_TYPE_APPWIDGET) {
+ if (!TextUtils.isEmpty(favorite.appWidgetProvider)) {
+ values.put(Favorites.APPWIDGET_PROVIDER, favorite.appWidgetProvider);
+ }
+ values.put(Favorites.APPWIDGET_ID, favorite.appWidgetId);
+ }
+ return values;
}
/** Serialize a Screen for persistence, including a checksum wrapper. */
@@ -788,11 +853,15 @@ public class LauncherBackupHelper implements BackupHelper {
}
/** Deserialize a Screen from persistence, after verifying checksum wrapper. */
- private Screen unpackScreen(byte[] buffer, int offset, int dataSize)
+ private ContentValues unpackScreen(byte[] buffer, int offset, int dataSize)
throws InvalidProtocolBufferNanoException {
Screen screen = new Screen();
MessageNano.mergeFrom(screen, readCheckedBytes(buffer, offset, dataSize));
- return screen;
+ if (DEBUG) Log.d(TAG, "unpacked " + screen.id + "/" + screen.rank);
+ ContentValues values = new ContentValues();
+ values.put(WorkspaceScreens._ID, screen.id);
+ values.put(WorkspaceScreens.SCREEN_RANK, screen.rank);
+ return values;
}
/** Serialize an icon Resource for persistence, including a checksum wrapper. */
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java
index 78ad84ecf..e689b2e4c 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -141,9 +141,10 @@ public class LauncherProvider extends ContentProvider {
if (values == null) {
throw new RuntimeException("Error: attempting to insert null values");
}
- if (!values.containsKey(LauncherSettings.Favorites._ID)) {
+ if (!values.containsKey(LauncherSettings.BaseLauncherColumns._ID)) {
throw new RuntimeException("Error: attempting to add item without specifying an id");
}
+ helper.checkId(table, values);
return db.insert(table, nullColumnHack, values);
}
@@ -274,6 +275,7 @@ public class LauncherProvider extends ContentProvider {
SharedPreferences sp = getContext().getSharedPreferences(spKey, Context.MODE_PRIVATE);
if (sp.getBoolean(EMPTY_DATABASE_CREATED, false)) {
+ Log.d(TAG, "loading default workspace");
int workspaceResId = origWorkspaceResId;
// Use default workspace resource if none provided
@@ -960,6 +962,15 @@ public class LauncherProvider extends ContentProvider {
mMaxItemId = id + 1;
}
+ public void checkId(String table, ContentValues values) {
+ long id = values.getAsLong(LauncherSettings.BaseLauncherColumns._ID);
+ if (table == LauncherProvider.TABLE_WORKSPACE_SCREENS) {
+ mMaxScreenId = Math.max(id, mMaxScreenId);
+ } else {
+ mMaxItemId = Math.max(id, mMaxItemId);
+ }
+ }
+
private long initializeMaxItemId(SQLiteDatabase db) {
Cursor c = db.rawQuery("SELECT MAX(_id) FROM favorites", null);