2013-10-04 11:29:36 -04:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2013 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.android.launcher3;
|
|
|
|
|
|
|
|
|
|
import android.app.backup.BackupAgentHelper;
|
2014-09-26 22:09:29 -07:00
|
|
|
import android.app.backup.BackupDataInput;
|
2013-10-04 11:29:36 -04:00
|
|
|
import android.app.backup.BackupManager;
|
|
|
|
|
import android.content.Context;
|
2014-09-26 22:09:29 -07:00
|
|
|
import android.database.Cursor;
|
|
|
|
|
import android.os.ParcelFileDescriptor;
|
2014-01-15 16:10:39 -05:00
|
|
|
import android.util.Log;
|
2013-10-04 11:29:36 -04:00
|
|
|
|
2014-09-26 22:09:29 -07:00
|
|
|
import java.io.IOException;
|
|
|
|
|
|
2013-10-04 11:29:36 -04:00
|
|
|
public class LauncherBackupAgentHelper extends BackupAgentHelper {
|
|
|
|
|
|
2013-10-17 15:16:48 -04:00
|
|
|
private static final String TAG = "LauncherBackupAgentHelper";
|
2014-10-16 09:24:19 -07:00
|
|
|
|
|
|
|
|
private static final String LAUNCHER_DATA_PREFIX = "L";
|
|
|
|
|
|
2014-01-15 16:10:39 -05:00
|
|
|
static final boolean VERBOSE = true;
|
|
|
|
|
static final boolean DEBUG = false;
|
2013-10-17 15:16:48 -04:00
|
|
|
|
2013-10-04 11:29:36 -04:00
|
|
|
private static BackupManager sBackupManager;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Notify the backup manager that out database is dirty.
|
|
|
|
|
*
|
|
|
|
|
* <P>This does not force an immediate backup.
|
|
|
|
|
*
|
|
|
|
|
* @param context application context
|
|
|
|
|
*/
|
|
|
|
|
public static void dataChanged(Context context) {
|
|
|
|
|
if (sBackupManager == null) {
|
|
|
|
|
sBackupManager = new BackupManager(context);
|
|
|
|
|
}
|
|
|
|
|
sBackupManager.dataChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-16 09:24:19 -07:00
|
|
|
private LauncherBackupHelper mHelper;
|
2013-10-04 11:29:36 -04:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onCreate() {
|
2014-10-16 09:24:19 -07:00
|
|
|
super.onCreate();
|
|
|
|
|
mHelper = new LauncherBackupHelper(this);
|
|
|
|
|
addHelper(LAUNCHER_DATA_PREFIX, mHelper);
|
2013-10-04 11:29:36 -04:00
|
|
|
}
|
2014-09-26 22:09:29 -07:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
|
|
|
|
|
throws IOException {
|
2014-10-23 13:57:41 -07:00
|
|
|
if (!Utilities.isLmpOrAbove()) {
|
|
|
|
|
// No restore for old devices.
|
|
|
|
|
Log.i(TAG, "You shall not pass!!!");
|
|
|
|
|
Log.d(TAG, "Restore is only supported on devices running Lollipop and above.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-09-26 22:09:29 -07:00
|
|
|
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();
|
|
|
|
|
|
2014-10-16 09:24:19 -07:00
|
|
|
if (hasData && mHelper.restoreSuccessful) {
|
|
|
|
|
LauncherAppState.getLauncherProvider().clearFlagEmptyDbCreated();
|
|
|
|
|
LauncherClings.synchonouslyMarkFirstRunClingDismissed(this);
|
|
|
|
|
} else {
|
2014-09-26 22:09:29 -07:00
|
|
|
if (VERBOSE) Log.v(TAG, "Nothing was restored, clearing DB");
|
|
|
|
|
LauncherAppState.getLauncherProvider().createEmptyDB();
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-04 11:29:36 -04:00
|
|
|
}
|