summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/LauncherBackupHelper.java
diff options
context:
space:
mode:
authorChris Wren <cwren@android.com>2014-02-10 12:16:54 -0500
committerDanesh Mondegarian <daneshm90@gmail.com>2014-06-07 06:55:58 -0700
commit953e0828b29215bb96b029ec01e6e6a3ae841b1e (patch)
treeffad76b7438c25f7fbd931e22cf267f1a3f57cec /src/com/android/launcher3/LauncherBackupHelper.java
parentdb4940837d20e4b45c0722a91b7fd10fd9b6b9b0 (diff)
downloadandroid_packages_apps_Trebuchet-953e0828b29215bb96b029ec01e6e6a3ae841b1e.tar.gz
android_packages_apps_Trebuchet-953e0828b29215bb96b029ec01e6e6a3ae841b1e.tar.bz2
android_packages_apps_Trebuchet-953e0828b29215bb96b029ec01e6e6a3ae841b1e.zip
use restored icon for restored app shortcuts
Bug: 10778992 Change-Id: Ie430a6587d49dc0d78b87b81582c0cef7c281017
Diffstat (limited to 'src/com/android/launcher3/LauncherBackupHelper.java')
-rw-r--r--src/com/android/launcher3/LauncherBackupHelper.java48
1 files changed, 26 insertions, 22 deletions
diff --git a/src/com/android/launcher3/LauncherBackupHelper.java b/src/com/android/launcher3/LauncherBackupHelper.java
index b77bf9fa3..62e6f3102 100644
--- a/src/com/android/launcher3/LauncherBackupHelper.java
+++ b/src/com/android/launcher3/LauncherBackupHelper.java
@@ -30,9 +30,8 @@ import com.android.launcher3.backup.BackupProtos.Screen;
import com.android.launcher3.backup.BackupProtos.Widget;
import android.app.backup.BackupDataInputStream;
-import android.app.backup.BackupHelper;
-import android.app.backup.BackupDataInput;
import android.app.backup.BackupDataOutput;
+import android.app.backup.BackupHelper;
import android.app.backup.BackupManager;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
@@ -448,14 +447,12 @@ public class LauncherBackupHelper implements BackupHelper {
private void backupIcons(Journal in, BackupDataOutput data, Journal out,
ArrayList<Key> keys) throws IOException {
// persist icons that haven't been persisted yet
- final LauncherAppState appState = LauncherAppState.getInstanceNoCreate();
- if (appState == null) {
+ if (!initializeIconCache()) {
dataChanged(); // try again later
if (DEBUG) Log.d(TAG, "Launcher is not initialized, delaying icon backup");
return;
}
final ContentResolver cr = mContext.getContentResolver();
- final IconCache iconCache = appState.getIconCache();
final int dpi = mContext.getResources().getDisplayMetrics().densityDpi;
// read the old ID set
@@ -494,9 +491,9 @@ public class LauncherBackupHelper implements BackupHelper {
if (DEBUG) Log.d(TAG, "I can count this high: " + out.rows);
if ((out.rows - startRows) < MAX_ICONS_PER_PASS) {
if (VERBOSE) Log.v(TAG, "saving icon " + backupKey);
- Bitmap icon = iconCache.getIcon(intent);
+ Bitmap icon = mIconCache.getIcon(intent);
keys.add(key);
- if (icon != null && !iconCache.isDefaultIcon(icon)) {
+ if (icon != null && !mIconCache.isDefaultIcon(icon)) {
byte[] blob = packIcon(dpi, icon);
writeRowToBackup(key, blob, out, data);
}
@@ -537,25 +534,33 @@ public class LauncherBackupHelper implements BackupHelper {
if (VERBOSE) Log.v(TAG, "unpacking icon " + key.id);
if (DEBUG) Log.d(TAG, "read (" + buffer.length + "): " +
Base64.encodeToString(buffer, 0, dataSize, Base64.NO_WRAP));
+
try {
Resource res = unpackIcon(buffer, 0, dataSize);
- if (DEBUG) Log.d(TAG, "unpacked " + res.dpi + " dpi icon");
- if (DEBUG_PAYLOAD) Log.d(TAG, "read " +
- Base64.encodeToString(res.data, 0, res.data.length,
- Base64.NO_WRAP));
+ if (DEBUG) {
+ Log.d(TAG, "unpacked " + res.dpi + " dpi icon");
+ }
+ if (DEBUG_PAYLOAD) {
+ Log.d(TAG, "read " +
+ Base64.encodeToString(res.data, 0, res.data.length,
+ Base64.NO_WRAP));
+ }
Bitmap icon = BitmapFactory.decodeByteArray(res.data, 0, res.data.length);
if (icon == null) {
Log.w(TAG, "failed to unpack icon for " + key.name);
}
if (!mRestoreEnabled) {
- if (VERBOSE) Log.v(TAG, "restore not enabled: skipping database mutation");
+ if (VERBOSE) {
+ Log.v(TAG, "restore not enabled: skipping database mutation");
+ }
return;
} else {
- // future site of icon cache mutation
+ IconCache.preloadIcon(mContext, ComponentName.unflattenFromString(key.name),
+ icon, res.dpi);
}
- } catch (InvalidProtocolBufferNanoException e) {
- Log.e(TAG, "failed to decode icon", e);
+ } catch (IOException e) {
+ Log.d(TAG, "failed to save restored icon for: " + key.name, e);
}
}
@@ -573,15 +578,13 @@ public class LauncherBackupHelper implements BackupHelper {
ArrayList<Key> keys) throws IOException {
// persist static widget info that hasn't been persisted yet
final LauncherAppState appState = LauncherAppState.getInstanceNoCreate();
- if (appState == null) {
- dataChanged(); // try again later
- if (DEBUG) Log.d(TAG, "Launcher is not initialized, delaying widget backup");
+ if (appState == null || !initializeIconCache()) {
+ Log.w(TAG, "Failed to get icon cache during restore");
return;
}
final ContentResolver cr = mContext.getContentResolver();
final WidgetPreviewLoader previewLoader = new WidgetPreviewLoader(mContext);
final PagedViewCellLayout widgetSpacingLayout = new PagedViewCellLayout(mContext);
- final IconCache iconCache = appState.getIconCache();
final int dpi = mContext.getResources().getDisplayMetrics().densityDpi;
final DeviceProfile profile = appState.getDynamicGrid().getDeviceProfile();
if (DEBUG) Log.d(TAG, "cellWidthPx: " + profile.cellWidthPx);
@@ -624,7 +627,7 @@ public class LauncherBackupHelper implements BackupHelper {
if (VERBOSE) Log.v(TAG, "saving widget " + backupKey);
previewLoader.setPreviewSize(spanX * profile.cellWidthPx,
spanY * profile.cellHeightPx, widgetSpacingLayout);
- byte[] blob = packWidget(dpi, previewLoader, iconCache, provider);
+ byte[] blob = packWidget(dpi, previewLoader, mIconCache, provider);
keys.add(key);
writeRowToBackup(key, blob, out, data);
@@ -889,7 +892,7 @@ public class LauncherBackupHelper implements BackupHelper {
}
/** Deserialize an icon resource from persistence, after verifying checksum wrapper. */
- private Resource unpackIcon(byte[] buffer, int offset, int dataSize)
+ private static Resource unpackIcon(byte[] buffer, int offset, int dataSize)
throws InvalidProtocolBufferNanoException {
Resource res = new Resource();
MessageNano.mergeFrom(res, readCheckedBytes(buffer, offset, dataSize));
@@ -1087,7 +1090,7 @@ public class LauncherBackupHelper implements BackupHelper {
}
/** Unwrap a proto message from a CheckedMessage, verifying the checksum. */
- private byte[] readCheckedBytes(byte[] buffer, int offset, int dataSize)
+ private static byte[] readCheckedBytes(byte[] buffer, int offset, int dataSize)
throws InvalidProtocolBufferNanoException {
CheckedMessage wrapper = new CheckedMessage();
MessageNano.mergeFrom(wrapper, buffer, offset, dataSize);
@@ -1111,6 +1114,7 @@ public class LauncherBackupHelper implements BackupHelper {
return mWidgetMap.get(component);
}
+
private boolean initializeIconCache() {
if (mIconCache != null) {
return true;