Commit e7599d69 authored by Sunny Goyal's avatar Sunny Goyal Committed by Android Git Automerger
Browse files

am 6d467e27: Merge "Resetting launcherProvider data if restore set was empty" into ub-now-porkchop

* commit '6d467e27':
  Resetting launcherProvider data if restore set was empty
parents ab474588 6d467e27
......@@ -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,7 +57,7 @@ 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();
}
......@@ -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();
}
}
}
......@@ -148,11 +148,12 @@ public class LauncherBackupHelper implements BackupHelper {
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() {
......@@ -218,9 +219,6 @@ public class LauncherBackupHelper implements BackupHelper {
@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();
......
......@@ -307,6 +307,13 @@ public class LauncherProvider extends ContentProvider {
return loadedOldDb;
}
/**
* 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
......@@ -908,7 +915,14 @@ public class LauncherProvider extends ContentProvider {
// 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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment