summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Wren <cwren@android.com>2014-02-27 15:49:39 -0500
committerDanesh M <daneshm90@gmail.com>2014-06-06 22:54:28 -0700
commit7b64088e052357b58e5a3a49f2f7b3674db3b807 (patch)
treeb43ebf4079a4caa2e0412d3657c3363dd1e6db7f
parenta47d38f83aa7a59f159df67aa4b37fcbb67ab973 (diff)
downloadandroid_packages_apps_Trebuchet-7b64088e052357b58e5a3a49f2f7b3674db3b807.tar.gz
android_packages_apps_Trebuchet-7b64088e052357b58e5a3a49f2f7b3674db3b807.tar.bz2
android_packages_apps_Trebuchet-7b64088e052357b58e5a3a49f2f7b3674db3b807.zip
skip backup if launcher is in a bad state
Bug: 13153542 Change-Id: I4312ebd200e8e652ef841f54301981c2a486b726
-rw-r--r--src/com/android/launcher3/LauncherBackupHelper.java58
1 files changed, 50 insertions, 8 deletions
diff --git a/src/com/android/launcher3/LauncherBackupHelper.java b/src/com/android/launcher3/LauncherBackupHelper.java
index 741bb9ced..6a7f5cbd9 100644
--- a/src/com/android/launcher3/LauncherBackupHelper.java
+++ b/src/com/android/launcher3/LauncherBackupHelper.java
@@ -137,6 +137,8 @@ public class LauncherBackupHelper implements BackupHelper {
private static final int SCREEN_RANK_INDEX = 2;
+ private static IconCache mIconCache;
+
private final Context mContext;
private final boolean mRestoreEnabled;
@@ -185,16 +187,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.");
}
@@ -1101,6 +1107,42 @@ public class LauncherBackupHelper implements BackupHelper {
return mWidgetMap.get(component);
}
+ private boolean initializeIconCache() {
+ if (mIconCache != null) {
+ return true;
+ }
+
+ final LauncherAppState appState = LauncherAppState.getInstanceNoCreate();
+ if (appState == null) {
+ Throwable stackTrace = new Throwable();
+ stackTrace.fillInStackTrace();
+ Log.w(TAG, "Failed to get app state during backup/restore", stackTrace);
+ return false;
+ }
+ mIconCache = appState.getIconCache();
+ 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);