summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/LauncherBackupHelper.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2015-06-05 11:14:01 -0700
committerSunny Goyal <sunnygoyal@google.com>2015-06-05 11:36:20 -0700
commit9637364c447cd8df12dd70d3c769d101b7565df7 (patch)
tree7d086084caeb48d5f5d570e281a0c6093d647ad6 /src/com/android/launcher3/LauncherBackupHelper.java
parent8d8c73b591bf58f93f8841938ad8ce92085f7105 (diff)
downloadandroid_packages_apps_Trebuchet-9637364c447cd8df12dd70d3c769d101b7565df7.tar.gz
android_packages_apps_Trebuchet-9637364c447cd8df12dd70d3c769d101b7565df7.tar.bz2
android_packages_apps_Trebuchet-9637364c447cd8df12dd70d3c769d101b7565df7.zip
Fixing crash in restore
> LauncherAppState cannot be initialized during restore, as it is not called from a looper thread. Bug: 21275736 Change-Id: Ifdb3f9913fa2ee63a7e1566d0c5cfc6f72b4f41e
Diffstat (limited to 'src/com/android/launcher3/LauncherBackupHelper.java')
-rw-r--r--src/com/android/launcher3/LauncherBackupHelper.java61
1 files changed, 20 insertions, 41 deletions
diff --git a/src/com/android/launcher3/LauncherBackupHelper.java b/src/com/android/launcher3/LauncherBackupHelper.java
index b40ace3fb..dc0bccc3c 100644
--- a/src/com/android/launcher3/LauncherBackupHelper.java
+++ b/src/com/android/launcher3/LauncherBackupHelper.java
@@ -146,7 +146,6 @@ public class LauncherBackupHelper implements BackupHelper {
private long mLastBackupRestoreTime;
private boolean mBackupDataWasUpdated;
- private LauncherAppState mLauncherAppState;
private IconCache mIconCache;
private DeviceProfieData mDeviceProfileData;
@@ -205,7 +204,11 @@ public class LauncherBackupHelper implements BackupHelper {
return;
}
- lazyInitAppState(true /* noCreate */);
+ if (mDeviceProfileData == null) {
+ LauncherAppState app = LauncherAppState.getInstance();
+ mDeviceProfileData = initDeviceProfileData(app.getInvariantDeviceProfile());
+ mIconCache = app.getIconCache();
+ }
Log.v(TAG, "lastBackupTime = " + in.t);
mKeys.clear();
@@ -240,7 +243,7 @@ public class LauncherBackupHelper implements BackupHelper {
// Check if any metadata has changed
mBackupDataWasUpdated = (in.profile == null)
|| !Arrays.equals(DeviceProfieData.toByteArray(in.profile),
- DeviceProfieData.toByteArray(getDeviceProfieData()))
+ DeviceProfieData.toByteArray(mDeviceProfileData))
|| (in.backupVersion != BACKUP_VERSION)
|| (in.appVersion != getAppVersion());
}
@@ -268,8 +271,7 @@ public class LauncherBackupHelper implements BackupHelper {
* to this device.
*/
private boolean isBackupCompatible(Journal oldState) {
- DeviceProfieData currentProfile = getDeviceProfieData();
-
+ DeviceProfieData currentProfile = mDeviceProfileData;
DeviceProfieData oldProfile = oldState.profile;
if (oldProfile == null || oldProfile.desktopCols == 0) {
@@ -302,7 +304,14 @@ public class LauncherBackupHelper implements BackupHelper {
if (!restoreSuccessful) {
return;
}
- lazyInitAppState(false /* noCreate */);
+
+ if (mDeviceProfileData == null) {
+ // This call does not happen on a looper thread. So LauncherAppState
+ // can't be created . Instead initialize required dependencies directly.
+ InvariantDeviceProfile profile = new InvariantDeviceProfile(mContext);
+ mDeviceProfileData = initDeviceProfileData(profile);
+ mIconCache = new IconCache(mContext, profile);
+ }
int dataSize = data.size();
if (mBuffer.length < dataSize) {
@@ -379,7 +388,7 @@ public class LauncherBackupHelper implements BackupHelper {
journal.key = mKeys.toArray(new BackupProtos.Key[mKeys.size()]);
journal.appVersion = getAppVersion();
journal.backupVersion = BACKUP_VERSION;
- journal.profile = getDeviceProfieData();
+ journal.profile = mDeviceProfileData;
return journal;
}
@@ -392,31 +401,6 @@ public class LauncherBackupHelper implements BackupHelper {
}
}
- /**
- * @return the current device profile information.
- */
- private DeviceProfieData getDeviceProfieData() {
- return mDeviceProfileData;
- }
-
- private void lazyInitAppState(boolean noCreate) {
- if (mLauncherAppState != null) {
- return;
- }
-
- if (noCreate) {
- mLauncherAppState = LauncherAppState.getInstanceNoCreate();
- } else {
- LauncherAppState.setApplicationContext(mContext);
- mLauncherAppState = LauncherAppState.getInstance();
- }
-
- mIconCache = mLauncherAppState.getIconCache();
- InvariantDeviceProfile profile = mLauncherAppState.getInvariantDeviceProfile();
-
- mDeviceProfileData = initDeviceProfileData(profile);
- }
-
private DeviceProfieData initDeviceProfileData(InvariantDeviceProfile profile) {
DeviceProfieData data = new DeviceProfieData();
data.desktopRows = profile.numRows;
@@ -631,7 +615,6 @@ public class LauncherBackupHelper implements BackupHelper {
private void backupWidgets(BackupDataOutput data) throws IOException {
// persist static widget info that hasn't been persisted yet
final ContentResolver cr = mContext.getContentResolver();
- final WidgetPreviewLoader previewLoader = mLauncherAppState.getWidgetCache();
final int dpi = mContext.getResources().getDisplayMetrics().densityDpi;
int backupWidgetCount = 0;
@@ -644,7 +627,6 @@ public class LauncherBackupHelper implements BackupHelper {
while(cursor.moveToNext()) {
final long id = cursor.getLong(ID_INDEX);
final String providerName = cursor.getString(APPWIDGET_PROVIDER_INDEX);
- final int spanX = cursor.getInt(SPANX_INDEX);
final ComponentName provider = ComponentName.unflattenFromString(providerName);
Key key = null;
String backupKey = null;
@@ -664,9 +646,7 @@ public class LauncherBackupHelper implements BackupHelper {
if (backupWidgetCount < MAX_WIDGETS_PER_PASS) {
if (DEBUG) Log.d(TAG, "saving widget " + backupKey);
UserHandleCompat user = UserHandleCompat.myUserHandle();
- writeRowToBackup(key,
- packWidget(dpi, previewLoader, mIconCache, provider, user),
- data);
+ writeRowToBackup(key, packWidget(dpi, provider, user), data);
mKeys.add(key);
backupWidgetCount ++;
} else {
@@ -895,7 +875,7 @@ public class LauncherBackupHelper implements BackupHelper {
UserManagerCompat.getInstance(mContext).getSerialNumberForUser(myUserHandle);
values.put(LauncherSettings.Favorites.PROFILE_ID, userSerialNumber);
- DeviceProfieData currentProfile = getDeviceProfieData();
+ DeviceProfieData currentProfile = mDeviceProfileData;
if (favorite.itemType == Favorites.ITEM_TYPE_APPWIDGET) {
if (!TextUtils.isEmpty(favorite.appWidgetProvider)) {
@@ -972,8 +952,7 @@ public class LauncherBackupHelper implements BackupHelper {
}
/** Serialize a widget for persistence, including a checksum wrapper. */
- private Widget packWidget(int dpi, WidgetPreviewLoader previewLoader, IconCache iconCache,
- ComponentName provider, UserHandleCompat user) {
+ private Widget packWidget(int dpi, ComponentName provider, UserHandleCompat user) {
final LauncherAppWidgetProviderInfo info =
LauncherModel.getProviderInfo(mContext, provider, user);
Widget widget = new Widget();
@@ -982,7 +961,7 @@ public class LauncherBackupHelper implements BackupHelper {
widget.configure = info.configure != null;
if (info.icon != 0) {
widget.icon = new Resource();
- Drawable fullResIcon = iconCache.getFullResIcon(provider.getPackageName(), info.icon);
+ Drawable fullResIcon = mIconCache.getFullResIcon(provider.getPackageName(), info.icon);
Bitmap icon = Utilities.createIconBitmap(fullResIcon, mContext);
widget.icon.data = Utilities.flattenBitmap(icon);
widget.icon.dpi = dpi;