Commit 71144266 authored by Chris Wren's avatar Chris Wren
Browse files

skip backup if launcher is in a bad state

Bug: 13153542
Change-Id: I4312ebd200e8e652ef841f54301981c2a486b726
parent 3de6ea86
......@@ -50,9 +50,7 @@ import android.util.Base64;
import android.util.Log;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URISyntaxException;
......@@ -188,16 +186,20 @@ public class LauncherBackupHelper implements BackupHelper {
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);
if (launcherIsReady()) {
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(new BackupProtos.Key[keys.size()]);
} else {
out = in;
}
out.key = keys.toArray(new BackupProtos.Key[keys.size()]);
writeJournal(newState, out);
Log.v(TAG, "onBackup: wrote " + out.bytes + "b in " + out.rows + " rows.");
}
......@@ -1129,6 +1131,26 @@ public class LauncherBackupHelper implements BackupHelper {
return mIconCache != null;
}
// check if the launcher is in a state to support backup
private boolean launcherIsReady() {
ContentResolver cr = mContext.getContentResolver();
Cursor cursor = cr.query(Favorites.CONTENT_URI, FAVORITE_PROJECTION, null, null, null);
if (cursor == null) {
// launcher data has been wiped, do nothing
return false;
}
cursor.close();
if (!initializeIconCache()) {
// launcher services are unavailable, try again later
dataChanged();
return false;
}
return true;
}
private class KeyParsingException extends Throwable {
private KeyParsingException(Throwable cause) {
super(cause);
......
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