use of com.android.launcher3.backup.BackupProtos.Journal in project Launcher3 by chislon.
the class LauncherBackupHelper method performBackup.
/**
* Back up launcher data so we can restore the user's state on a new device.
*
* <P>The journal is a timestamp and a list of keys that were saved as of that time.
*
* <P>Keys may come back in any order, so each key/value is one complete row of the database.
*
* @param oldState notes from the last backup
* @param data incremental key/value pairs to persist off-device
* @param newState notes for the next backup
* @throws IOException
*/
@Override
public void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState) {
Log.v(TAG, "onBackup");
Journal in = readJournal(oldState);
Journal out = new Journal();
long lastBackupTime = in.t;
out.t = System.currentTimeMillis();
out.rows = 0;
out.bytes = 0;
Log.v(TAG, "lastBackupTime=" + lastBackupTime);
ArrayList<Key> keys = new ArrayList<Key>();
try {
backupFavorites(in, data, out, keys);
backupScreens(in, data, out, keys);
backupIcons(in, data, out, keys);
backupWidgets(in, data, out, keys);
} catch (IOException e) {
Log.e(TAG, "launcher backup has failed", e);
}
out.key = keys.toArray(BackupProtos.Key.emptyArray());
writeJournal(newState, out);
Log.v(TAG, "onBackup: wrote " + out.bytes + "b in " + out.rows + " rows.");
}
use of com.android.launcher3.backup.BackupProtos.Journal in project Launcher3 by chislon.
the class LauncherBackupHelper method backupFavorites.
/**
* Write all modified favorites to the data stream.
*
* @param in notes from last backup
* @param data output stream for key/value pairs
* @param out notes about this backup
* @param keys keys to mark as clean in the notes for next backup
* @throws IOException
*/
private void backupFavorites(Journal in, BackupDataOutput data, Journal out, ArrayList<Key> keys) throws IOException {
// read the old ID set
Set<String> savedIds = getSavedIdsByType(Key.FAVORITE, in);
if (DEBUG)
Log.d(TAG, "favorite savedIds.size()=" + savedIds.size());
// persist things that have changed since the last backup
ContentResolver cr = mContext.getContentResolver();
Cursor cursor = cr.query(Favorites.CONTENT_URI, FAVORITE_PROJECTION, null, null, null);
Set<String> currentIds = new HashSet<String>(cursor.getCount());
try {
cursor.moveToPosition(-1);
while (cursor.moveToNext()) {
final long id = cursor.getLong(ID_INDEX);
final long updateTime = cursor.getLong(ID_MODIFIED);
Key key = getKey(Key.FAVORITE, id);
keys.add(key);
currentIds.add(keyToBackupKey(key));
if (updateTime > in.t) {
byte[] blob = packFavorite(cursor);
writeRowToBackup(key, blob, out, data);
}
}
} finally {
cursor.close();
}
if (DEBUG)
Log.d(TAG, "favorite currentIds.size()=" + currentIds.size());
// these IDs must have been deleted
savedIds.removeAll(currentIds);
out.rows += removeDeletedKeysFromBackup(savedIds, data);
}
Aggregations