summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/LauncherBackupAgentHelper.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/LauncherBackupAgentHelper.java')
-rw-r--r--src/com/android/launcher3/LauncherBackupAgentHelper.java28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/com/android/launcher3/LauncherBackupAgentHelper.java b/src/com/android/launcher3/LauncherBackupAgentHelper.java
index de6aedddd..c20c6939d 100644
--- a/src/com/android/launcher3/LauncherBackupAgentHelper.java
+++ b/src/com/android/launcher3/LauncherBackupAgentHelper.java
@@ -17,13 +17,16 @@
package com.android.launcher3;
import android.app.backup.BackupAgentHelper;
+import android.app.backup.BackupDataInput;
import android.app.backup.BackupManager;
-import android.app.backup.SharedPreferencesBackupHelper;
import android.content.Context;
-import android.content.SharedPreferences;
+import android.database.Cursor;
+import android.os.ParcelFileDescriptor;
import android.provider.Settings;
import android.util.Log;
+import java.io.IOException;
+
public class LauncherBackupAgentHelper extends BackupAgentHelper {
private static final String TAG = "LauncherBackupAgentHelper";
@@ -54,14 +57,14 @@ public class LauncherBackupAgentHelper extends BackupAgentHelper {
// modifies the file outside the normal codepaths, so it looks like another
// process. This forces a reload of the file, in case this process persists.
String spKey = LauncherAppState.getSharedPreferencesKey();
- SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_MULTI_PROCESS);
+ getSharedPreferences(spKey, Context.MODE_MULTI_PROCESS);
super.onDestroy();
}
@Override
public void onCreate() {
boolean restoreEnabled = 0 != Settings.Secure.getInt(
- getContentResolver(), SETTING_RESTORE_ENABLED, 0);
+ getContentResolver(), SETTING_RESTORE_ENABLED, 1);
if (VERBOSE) Log.v(TAG, "restore is " + (restoreEnabled ? "enabled" : "disabled"));
addHelper(LauncherBackupHelper.LAUNCHER_PREFS_PREFIX,
@@ -71,4 +74,21 @@ public class LauncherBackupAgentHelper extends BackupAgentHelper {
addHelper(LauncherBackupHelper.LAUNCHER_PREFIX,
new LauncherBackupHelper(this, restoreEnabled));
}
+
+ @Override
+ public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
+ throws IOException {
+ super.onRestore(data, appVersionCode, newState);
+
+ // If no favorite was migrated, clear the data and start fresh.
+ final Cursor c = getContentResolver().query(
+ LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION, null, null, null, null);
+ boolean hasData = c.moveToNext();
+ c.close();
+
+ if (!hasData) {
+ if (VERBOSE) Log.v(TAG, "Nothing was restored, clearing DB");
+ LauncherAppState.getLauncherProvider().createEmptyDB();
+ }
+ }
}