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";
// 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();
}
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();
+ }
+ }
}
private HashMap<ComponentName, AppWidgetProviderInfo> mWidgetMap;
- private ArrayList<Key> mKeys;
+ private final ArrayList<Key> mKeys;
public LauncherBackupHelper(Context context, boolean restoreEnabled) {
mContext = context;
mRestoreEnabled = restoreEnabled;
+ mKeys = new ArrayList<Key>();
}
private void dataChanged() {
@Override
public void restoreEntity(BackupDataInputStream data) {
if (VERBOSE) Log.v(TAG, "restoreEntity");
- if (mKeys == null) {
- mKeys = new ArrayList<Key>();
- }
byte[] buffer = new byte[512];
String backupKey = data.getKey();
int dataSize = data.size();
}
/**
+ * Clears all the data for a fresh start.
+ */
+ synchronized public void createEmptyDB() {
+ mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
+ }
+
+ /**
* Loads the default workspace based on the following priority scheme:
* 1) From a package provided by play store
* 2) From a partner configuration APK, already in the system image
// This shouldn't happen -- throw our hands up in the air and start over.
Log.w(TAG, "Database version downgrade from: " + oldVersion + " to " + newVersion +
". Wiping databse.");
+ createEmptyDB(db);
+ }
+
+ /**
+ * Clears all the data for a fresh start.
+ */
+ public void createEmptyDB(SQLiteDatabase db) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_FAVORITES);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_WORKSPACE_SCREENS);
onCreate(db);