Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 16 | package com.android.launcher3; |
| 17 | |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 18 | import android.app.backup.BackupDataInputStream; |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 19 | import android.app.backup.BackupDataOutput; |
Chris Wren | 4d89e2a | 2013-10-09 17:03:50 -0400 | [diff] [blame] | 20 | import android.app.backup.BackupHelper; |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 21 | import android.app.backup.BackupManager; |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 22 | import android.appwidget.AppWidgetProviderInfo; |
| 23 | import android.content.ComponentName; |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 24 | import android.content.ContentResolver; |
Chris Wren | 5dee7af | 2013-12-20 17:22:11 -0500 | [diff] [blame] | 25 | import android.content.ContentValues; |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 26 | import android.content.Context; |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 27 | import android.content.Intent; |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 28 | import android.content.pm.PackageManager.NameNotFoundException; |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 29 | import android.database.Cursor; |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 30 | import android.graphics.Bitmap; |
| 31 | import android.graphics.BitmapFactory; |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 32 | import android.graphics.drawable.Drawable; |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 33 | import android.os.ParcelFileDescriptor; |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 34 | import android.text.TextUtils; |
| 35 | import android.util.Base64; |
| 36 | import android.util.Log; |
| 37 | |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 38 | import com.android.launcher3.LauncherSettings.Favorites; |
| 39 | import com.android.launcher3.LauncherSettings.WorkspaceScreens; |
| 40 | import com.android.launcher3.backup.BackupProtos; |
| 41 | import com.android.launcher3.backup.BackupProtos.CheckedMessage; |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 42 | import com.android.launcher3.backup.BackupProtos.DeviceProfieData; |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 43 | import com.android.launcher3.backup.BackupProtos.Favorite; |
| 44 | import com.android.launcher3.backup.BackupProtos.Journal; |
| 45 | import com.android.launcher3.backup.BackupProtos.Key; |
| 46 | import com.android.launcher3.backup.BackupProtos.Resource; |
| 47 | import com.android.launcher3.backup.BackupProtos.Screen; |
| 48 | import com.android.launcher3.backup.BackupProtos.Widget; |
| 49 | import com.android.launcher3.compat.UserHandleCompat; |
| 50 | import com.android.launcher3.compat.UserManagerCompat; |
| 51 | import com.google.protobuf.nano.InvalidProtocolBufferNanoException; |
| 52 | import com.google.protobuf.nano.MessageNano; |
| 53 | |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 54 | import java.io.ByteArrayOutputStream; |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 55 | import java.io.FileInputStream; |
| 56 | import java.io.FileOutputStream; |
| 57 | import java.io.IOException; |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 58 | import java.net.URISyntaxException; |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 59 | import java.util.ArrayList; |
Sunny Goyal | c0ee675 | 2015-01-16 14:10:32 -0800 | [diff] [blame] | 60 | import java.util.Arrays; |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 61 | import java.util.HashMap; |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 62 | import java.util.HashSet; |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 63 | import java.util.zip.CRC32; |
| 64 | |
| 65 | /** |
| 66 | * Persist the launcher home state across calamities. |
| 67 | */ |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 68 | public class LauncherBackupHelper implements BackupHelper { |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 69 | private static final String TAG = "LauncherBackupHelper"; |
Chris Wren | 50c8f42 | 2014-01-15 16:10:39 -0500 | [diff] [blame] | 70 | private static final boolean VERBOSE = LauncherBackupAgentHelper.VERBOSE; |
| 71 | private static final boolean DEBUG = LauncherBackupAgentHelper.DEBUG; |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 72 | |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 73 | private static final int BACKUP_VERSION = 2; |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 74 | private static final int MAX_JOURNAL_SIZE = 1000000; |
| 75 | |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 76 | // Journal key is such that it is always smaller than any dynamically generated |
| 77 | // key (any Base64 encoded string). |
| 78 | private static final String JOURNAL_KEY = "#"; |
| 79 | |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 80 | /** icons are large, dribble them out */ |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 81 | private static final int MAX_ICONS_PER_PASS = 10; |
| 82 | |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 83 | /** widgets contain previews, which are very large, dribble them out */ |
| 84 | private static final int MAX_WIDGETS_PER_PASS = 5; |
| 85 | |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 86 | private static final int IMAGE_COMPRESSION_QUALITY = 75; |
Chris Wren | 45297f8 | 2013-10-17 15:16:48 -0400 | [diff] [blame] | 87 | |
Chris Wren | b86f076 | 2013-10-04 10:10:21 -0400 | [diff] [blame] | 88 | private static final Bitmap.CompressFormat IMAGE_FORMAT = |
| 89 | android.graphics.Bitmap.CompressFormat.PNG; |
| 90 | |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 91 | private static final String[] FAVORITE_PROJECTION = { |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 92 | Favorites._ID, // 0 |
| 93 | Favorites.MODIFIED, // 1 |
| 94 | Favorites.INTENT, // 2 |
| 95 | Favorites.APPWIDGET_PROVIDER, // 3 |
| 96 | Favorites.APPWIDGET_ID, // 4 |
| 97 | Favorites.CELLX, // 5 |
| 98 | Favorites.CELLY, // 6 |
| 99 | Favorites.CONTAINER, // 7 |
| 100 | Favorites.ICON, // 8 |
| 101 | Favorites.ICON_PACKAGE, // 9 |
| 102 | Favorites.ICON_RESOURCE, // 10 |
| 103 | Favorites.ICON_TYPE, // 11 |
| 104 | Favorites.ITEM_TYPE, // 12 |
| 105 | Favorites.SCREEN, // 13 |
| 106 | Favorites.SPANX, // 14 |
| 107 | Favorites.SPANY, // 15 |
| 108 | Favorites.TITLE, // 16 |
| 109 | Favorites.PROFILE_ID, // 17 |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | private static final int ID_INDEX = 0; |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 113 | private static final int ID_MODIFIED = 1; |
| 114 | private static final int INTENT_INDEX = 2; |
| 115 | private static final int APPWIDGET_PROVIDER_INDEX = 3; |
| 116 | private static final int APPWIDGET_ID_INDEX = 4; |
| 117 | private static final int CELLX_INDEX = 5; |
| 118 | private static final int CELLY_INDEX = 6; |
| 119 | private static final int CONTAINER_INDEX = 7; |
| 120 | private static final int ICON_INDEX = 8; |
| 121 | private static final int ICON_PACKAGE_INDEX = 9; |
| 122 | private static final int ICON_RESOURCE_INDEX = 10; |
| 123 | private static final int ICON_TYPE_INDEX = 11; |
| 124 | private static final int ITEM_TYPE_INDEX = 12; |
| 125 | private static final int SCREEN_INDEX = 13; |
| 126 | private static final int SPANX_INDEX = 14; |
| 127 | private static final int SPANY_INDEX = 15; |
| 128 | private static final int TITLE_INDEX = 16; |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 129 | |
| 130 | private static final String[] SCREEN_PROJECTION = { |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 131 | WorkspaceScreens._ID, // 0 |
| 132 | WorkspaceScreens.MODIFIED, // 1 |
| 133 | WorkspaceScreens.SCREEN_RANK // 2 |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 134 | }; |
| 135 | |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 136 | private static final int SCREEN_RANK_INDEX = 2; |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 137 | |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 138 | private final Context mContext; |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 139 | private final HashSet<String> mExistingKeys; |
Sunny Goyal | 42de82f | 2014-09-26 22:09:29 -0700 | [diff] [blame] | 140 | private final ArrayList<Key> mKeys; |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 141 | |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 142 | private IconCache mIconCache; |
| 143 | private BackupManager mBackupManager; |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 144 | private byte[] mBuffer = new byte[512]; |
| 145 | private long mLastBackupRestoreTime; |
Sunny Goyal | c0ee675 | 2015-01-16 14:10:32 -0800 | [diff] [blame] | 146 | private boolean mBackupDataWasUpdated; |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 147 | |
Sunny Goyal | 5fd733d | 2014-10-29 10:51:54 -0700 | [diff] [blame] | 148 | private DeviceProfieData mCurrentProfile; |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 149 | boolean restoreSuccessful; |
Sunny Goyal | 08f7261 | 2015-01-05 13:41:43 -0800 | [diff] [blame] | 150 | int restoredBackupVersion = 1; |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 151 | |
| 152 | public LauncherBackupHelper(Context context) { |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 153 | mContext = context; |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 154 | mExistingKeys = new HashSet<String>(); |
Sunny Goyal | 42de82f | 2014-09-26 22:09:29 -0700 | [diff] [blame] | 155 | mKeys = new ArrayList<Key>(); |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 156 | restoreSuccessful = true; |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | private void dataChanged() { |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 160 | if (mBackupManager == null) { |
| 161 | mBackupManager = new BackupManager(mContext); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 162 | } |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 163 | mBackupManager.dataChanged(); |
| 164 | } |
| 165 | |
| 166 | private void applyJournal(Journal journal) { |
| 167 | mLastBackupRestoreTime = journal.t; |
| 168 | mExistingKeys.clear(); |
| 169 | if (journal.key != null) { |
| 170 | for (Key key : journal.key) { |
| 171 | mExistingKeys.add(keyToBackupKey(key)); |
| 172 | } |
| 173 | } |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Back up launcher data so we can restore the user's state on a new device. |
| 178 | * |
| 179 | * <P>The journal is a timestamp and a list of keys that were saved as of that time. |
| 180 | * |
| 181 | * <P>Keys may come back in any order, so each key/value is one complete row of the database. |
| 182 | * |
| 183 | * @param oldState notes from the last backup |
| 184 | * @param data incremental key/value pairs to persist off-device |
| 185 | * @param newState notes for the next backup |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 186 | */ |
| 187 | @Override |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 188 | public void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data, |
| 189 | ParcelFileDescriptor newState) { |
Chris Wren | 50c8f42 | 2014-01-15 16:10:39 -0500 | [diff] [blame] | 190 | if (VERBOSE) Log.v(TAG, "onBackup"); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 191 | |
| 192 | Journal in = readJournal(oldState); |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 193 | if (!launcherIsReady()) { |
| 194 | // Perform backup later. |
| 195 | writeJournal(newState, in); |
| 196 | return; |
| 197 | } |
| 198 | Log.v(TAG, "lastBackupTime = " + in.t); |
| 199 | mKeys.clear(); |
| 200 | applyJournal(in); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 201 | |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 202 | // Record the time before performing backup so that entries edited while the backup |
| 203 | // was going on, do not get missed in next backup. |
| 204 | long newBackupTime = System.currentTimeMillis(); |
Sunny Goyal | c0ee675 | 2015-01-16 14:10:32 -0800 | [diff] [blame] | 205 | mBackupDataWasUpdated = false; |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 206 | try { |
| 207 | backupFavorites(data); |
| 208 | backupScreens(data); |
| 209 | backupIcons(data); |
| 210 | backupWidgets(data); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 211 | |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 212 | // Delete any key which still exist in the old backup, but is not valid anymore. |
| 213 | HashSet<String> validKeys = new HashSet<String>(); |
| 214 | for (Key key : mKeys) { |
| 215 | validKeys.add(keyToBackupKey(key)); |
Chris Wren | 7114426 | 2014-02-27 15:49:39 -0500 | [diff] [blame] | 216 | } |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 217 | mExistingKeys.removeAll(validKeys); |
| 218 | |
| 219 | // Delete anything left in the existing keys. |
| 220 | for (String deleted: mExistingKeys) { |
| 221 | if (VERBOSE) Log.v(TAG, "dropping deleted item " + deleted); |
| 222 | data.writeEntityHeader(deleted, -1); |
Sunny Goyal | c0ee675 | 2015-01-16 14:10:32 -0800 | [diff] [blame] | 223 | mBackupDataWasUpdated = true; |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | mExistingKeys.clear(); |
Sunny Goyal | c0ee675 | 2015-01-16 14:10:32 -0800 | [diff] [blame] | 227 | if (!mBackupDataWasUpdated) { |
| 228 | // Check if any metadata has changed |
| 229 | mBackupDataWasUpdated = (in.profile == null) |
| 230 | || !Arrays.equals(DeviceProfieData.toByteArray(in.profile), |
| 231 | DeviceProfieData.toByteArray(getDeviceProfieData())) |
| 232 | || (in.backupVersion != BACKUP_VERSION) |
| 233 | || (in.appVersion != getAppVersion()); |
| 234 | } |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 235 | |
Sunny Goyal | c0ee675 | 2015-01-16 14:10:32 -0800 | [diff] [blame] | 236 | if (mBackupDataWasUpdated) { |
| 237 | mLastBackupRestoreTime = newBackupTime; |
| 238 | |
| 239 | // We store the journal at two places. |
| 240 | // 1) Storing it in newState allows us to do partial backups by comparing old state |
| 241 | // 2) Storing it in backup data allows us to validate keys during restore |
| 242 | Journal state = getCurrentStateJournal(); |
| 243 | writeRowToBackup(JOURNAL_KEY, state, data); |
| 244 | } else { |
| 245 | if (DEBUG) Log.d(TAG, "Nothing was written during backup"); |
| 246 | } |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 247 | } catch (IOException e) { |
| 248 | Log.e(TAG, "launcher backup has failed", e); |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 249 | } |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 250 | |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 251 | writeNewStateDescription(newState); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | /** |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 255 | * @return true if the backup corresponding to oldstate can be successfully applied |
| 256 | * to this device. |
| 257 | */ |
| 258 | private boolean isBackupCompatible(Journal oldState) { |
Sunny Goyal | 5fd733d | 2014-10-29 10:51:54 -0700 | [diff] [blame] | 259 | DeviceProfieData currentProfile = getDeviceProfieData(); |
| 260 | |
| 261 | DeviceProfieData oldProfile = oldState.profile; |
| 262 | |
| 263 | if (oldProfile == null || oldProfile.desktopCols == 0) { |
| 264 | // Profile info is not valid, ignore the check. |
| 265 | return true; |
| 266 | } |
| 267 | |
| 268 | boolean isHotsetCompatible = false; |
| 269 | if (currentProfile.allappsRank >= oldProfile.hotseatCount) { |
| 270 | isHotsetCompatible = true; |
| 271 | } |
| 272 | if ((currentProfile.hotseatCount >= oldProfile.hotseatCount) && |
| 273 | (currentProfile.allappsRank == oldProfile.allappsRank)) { |
| 274 | isHotsetCompatible = true; |
| 275 | } |
| 276 | |
| 277 | return isHotsetCompatible && (currentProfile.desktopCols >= oldProfile.desktopCols) |
| 278 | && (currentProfile.desktopRows >= oldProfile.desktopRows); |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | /** |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 282 | * Restore launcher configuration from the restored data stream. |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 283 | * It assumes that the keys will arrive in lexical order. So if the journal was present in the |
| 284 | * backup, it should arrive first. |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 285 | * |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 286 | * @param data the key/value pair from the server |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 287 | */ |
| 288 | @Override |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 289 | public void restoreEntity(BackupDataInputStream data) { |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 290 | if (!restoreSuccessful) { |
| 291 | return; |
| 292 | } |
| 293 | |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 294 | int dataSize = data.size(); |
| 295 | if (mBuffer.length < dataSize) { |
| 296 | mBuffer = new byte[dataSize]; |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 297 | } |
| 298 | try { |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 299 | int bytesRead = data.read(mBuffer, 0, dataSize); |
| 300 | if (DEBUG) Log.d(TAG, "read " + bytesRead + " of " + dataSize + " available"); |
| 301 | String backupKey = data.getKey(); |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 302 | |
| 303 | if (JOURNAL_KEY.equals(backupKey)) { |
| 304 | if (VERBOSE) Log.v(TAG, "Journal entry restored"); |
| 305 | if (!mKeys.isEmpty()) { |
| 306 | // We received the journal key after a restore key. |
| 307 | Log.wtf(TAG, keyToBackupKey(mKeys.get(0)) + " received after " + JOURNAL_KEY); |
| 308 | restoreSuccessful = false; |
| 309 | return; |
| 310 | } |
| 311 | |
| 312 | Journal journal = new Journal(); |
| 313 | MessageNano.mergeFrom(journal, readCheckedBytes(mBuffer, dataSize)); |
| 314 | applyJournal(journal); |
| 315 | restoreSuccessful = isBackupCompatible(journal); |
Sunny Goyal | 08f7261 | 2015-01-05 13:41:43 -0800 | [diff] [blame] | 316 | restoredBackupVersion = journal.backupVersion; |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 317 | return; |
| 318 | } |
| 319 | |
| 320 | if (!mExistingKeys.isEmpty() && !mExistingKeys.contains(backupKey)) { |
| 321 | if (DEBUG) Log.e(TAG, "Ignoring key not present in the backup state " + backupKey); |
| 322 | return; |
| 323 | } |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 324 | Key key = backupKeyToKey(backupKey); |
Chris Wren | 50c8f42 | 2014-01-15 16:10:39 -0500 | [diff] [blame] | 325 | mKeys.add(key); |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 326 | switch (key.type) { |
| 327 | case Key.FAVORITE: |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 328 | restoreFavorite(key, mBuffer, dataSize); |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 329 | break; |
| 330 | |
| 331 | case Key.SCREEN: |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 332 | restoreScreen(key, mBuffer, dataSize); |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 333 | break; |
| 334 | |
| 335 | case Key.ICON: |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 336 | restoreIcon(key, mBuffer, dataSize); |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 337 | break; |
| 338 | |
| 339 | case Key.WIDGET: |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 340 | restoreWidget(key, mBuffer, dataSize); |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 341 | break; |
| 342 | |
| 343 | default: |
| 344 | Log.w(TAG, "unknown restore entity type: " + key.type); |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 345 | mKeys.remove(key); |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 346 | break; |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 347 | } |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 348 | } catch (IOException e) { |
| 349 | Log.w(TAG, "ignoring unparsable backup entry", e); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 350 | } |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | /** |
| 354 | * Record the restore state for the next backup. |
| 355 | * |
| 356 | * @param newState notes about the backup state after restore. |
| 357 | */ |
| 358 | @Override |
| 359 | public void writeNewStateDescription(ParcelFileDescriptor newState) { |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 360 | writeJournal(newState, getCurrentStateJournal()); |
| 361 | } |
| 362 | |
| 363 | private Journal getCurrentStateJournal() { |
| 364 | Journal journal = new Journal(); |
| 365 | journal.t = mLastBackupRestoreTime; |
| 366 | journal.key = mKeys.toArray(new BackupProtos.Key[mKeys.size()]); |
| 367 | journal.appVersion = getAppVersion(); |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 368 | journal.backupVersion = BACKUP_VERSION; |
| 369 | journal.profile = getDeviceProfieData(); |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 370 | return journal; |
| 371 | } |
| 372 | |
| 373 | private int getAppVersion() { |
| 374 | try { |
| 375 | return mContext.getPackageManager() |
| 376 | .getPackageInfo(mContext.getPackageName(), 0).versionCode; |
| 377 | } catch (NameNotFoundException e) { |
| 378 | return 0; |
| 379 | } |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | /** |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 383 | * @return the current device profile information. |
| 384 | */ |
| 385 | private DeviceProfieData getDeviceProfieData() { |
Sunny Goyal | 5fd733d | 2014-10-29 10:51:54 -0700 | [diff] [blame] | 386 | if (mCurrentProfile != null) { |
| 387 | return mCurrentProfile; |
| 388 | } |
Chris Wren | b02e611 | 2014-11-24 16:57:54 -0500 | [diff] [blame] | 389 | final Context applicationContext = mContext.getApplicationContext(); |
| 390 | DeviceProfile profile = LauncherAppState.createDynamicGrid(applicationContext, null) |
| 391 | .getDeviceProfile(); |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 392 | |
Sunny Goyal | 5fd733d | 2014-10-29 10:51:54 -0700 | [diff] [blame] | 393 | mCurrentProfile = new DeviceProfieData(); |
| 394 | mCurrentProfile.desktopRows = profile.numRows; |
| 395 | mCurrentProfile.desktopCols = profile.numColumns; |
| 396 | mCurrentProfile.hotseatCount = profile.numHotseatIcons; |
| 397 | mCurrentProfile.allappsRank = profile.hotseatAllAppsRank; |
| 398 | return mCurrentProfile; |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | /** |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 402 | * Write all modified favorites to the data stream. |
| 403 | * |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 404 | * @param data output stream for key/value pairs |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 405 | * @throws IOException |
| 406 | */ |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 407 | private void backupFavorites(BackupDataOutput data) throws IOException { |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 408 | // persist things that have changed since the last backup |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 409 | ContentResolver cr = mContext.getContentResolver(); |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 410 | // Don't backup apps in other profiles for now. |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 411 | Cursor cursor = cr.query(Favorites.CONTENT_URI, FAVORITE_PROJECTION, |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 412 | getUserSelectionArg(), null, null); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 413 | try { |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 414 | cursor.moveToPosition(-1); |
| 415 | while(cursor.moveToNext()) { |
| 416 | final long id = cursor.getLong(ID_INDEX); |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 417 | final long updateTime = cursor.getLong(ID_MODIFIED); |
| 418 | Key key = getKey(Key.FAVORITE, id); |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 419 | mKeys.add(key); |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 420 | final String backupKey = keyToBackupKey(key); |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 421 | if (!mExistingKeys.contains(backupKey) || updateTime >= mLastBackupRestoreTime) { |
| 422 | writeRowToBackup(key, packFavorite(cursor), data); |
Chris Wren | 50c8f42 | 2014-01-15 16:10:39 -0500 | [diff] [blame] | 423 | } else { |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 424 | if (DEBUG) Log.d(TAG, "favorite already backup up: " + id); |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 425 | } |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 426 | } |
| 427 | } finally { |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 428 | cursor.close(); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 429 | } |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | /** |
| 433 | * Read a favorite from the stream. |
| 434 | * |
| 435 | * <P>Keys arrive in any order, so screens and containers may not exist yet. |
| 436 | * |
| 437 | * @param key identifier for the row |
| 438 | * @param buffer the serialized proto from the stream, may be larger than dataSize |
| 439 | * @param dataSize the size of the proto from the stream |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 440 | */ |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 441 | private void restoreFavorite(Key key, byte[] buffer, int dataSize) throws IOException { |
Chris Wren | 50c8f42 | 2014-01-15 16:10:39 -0500 | [diff] [blame] | 442 | if (VERBOSE) Log.v(TAG, "unpacking favorite " + key.id); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 443 | if (DEBUG) Log.d(TAG, "read (" + buffer.length + "): " + |
| 444 | Base64.encodeToString(buffer, 0, dataSize, Base64.NO_WRAP)); |
| 445 | |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 446 | ContentResolver cr = mContext.getContentResolver(); |
| 447 | ContentValues values = unpackFavorite(buffer, dataSize); |
| 448 | cr.insert(Favorites.CONTENT_URI_NO_NOTIFICATION, values); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | /** |
| 452 | * Write all modified screens to the data stream. |
| 453 | * |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 454 | * @param data output stream for key/value pairs |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 455 | * @throws IOException |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 456 | */ |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 457 | private void backupScreens(BackupDataOutput data) throws IOException { |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 458 | // persist things that have changed since the last backup |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 459 | ContentResolver cr = mContext.getContentResolver(); |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 460 | Cursor cursor = cr.query(WorkspaceScreens.CONTENT_URI, SCREEN_PROJECTION, |
| 461 | null, null, null); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 462 | try { |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 463 | cursor.moveToPosition(-1); |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 464 | if (DEBUG) Log.d(TAG, "dumping screens after: " + mLastBackupRestoreTime); |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 465 | while(cursor.moveToNext()) { |
| 466 | final long id = cursor.getLong(ID_INDEX); |
| 467 | final long updateTime = cursor.getLong(ID_MODIFIED); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 468 | Key key = getKey(Key.SCREEN, id); |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 469 | mKeys.add(key); |
Chris Wren | 5743aa9 | 2014-01-10 18:02:06 -0500 | [diff] [blame] | 470 | final String backupKey = keyToBackupKey(key); |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 471 | if (!mExistingKeys.contains(backupKey) || updateTime >= mLastBackupRestoreTime) { |
| 472 | writeRowToBackup(key, packScreen(cursor), data); |
Chris Wren | 5dee7af | 2013-12-20 17:22:11 -0500 | [diff] [blame] | 473 | } else { |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 474 | if (VERBOSE) Log.v(TAG, "screen already backup up " + id); |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 475 | } |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 476 | } |
| 477 | } finally { |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 478 | cursor.close(); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 479 | } |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | /** |
| 483 | * Read a screen from the stream. |
| 484 | * |
| 485 | * <P>Keys arrive in any order, so children of this screen may already exist. |
| 486 | * |
| 487 | * @param key identifier for the row |
| 488 | * @param buffer the serialized proto from the stream, may be larger than dataSize |
| 489 | * @param dataSize the size of the proto from the stream |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 490 | */ |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 491 | private void restoreScreen(Key key, byte[] buffer, int dataSize) throws IOException { |
Chris Wren | 50c8f42 | 2014-01-15 16:10:39 -0500 | [diff] [blame] | 492 | if (VERBOSE) Log.v(TAG, "unpacking screen " + key.id); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 493 | if (DEBUG) Log.d(TAG, "read (" + buffer.length + "): " + |
| 494 | Base64.encodeToString(buffer, 0, dataSize, Base64.NO_WRAP)); |
Chris Wren | 5dee7af | 2013-12-20 17:22:11 -0500 | [diff] [blame] | 495 | |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 496 | ContentResolver cr = mContext.getContentResolver(); |
| 497 | ContentValues values = unpackScreen(buffer, dataSize); |
| 498 | cr.insert(WorkspaceScreens.CONTENT_URI, values); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 499 | } |
| 500 | |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 501 | /** |
| 502 | * Write all the static icon resources we need to render placeholders |
| 503 | * for a package that is not installed. |
| 504 | * |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 505 | * @param data output stream for key/value pairs |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 506 | */ |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 507 | private void backupIcons(BackupDataOutput data) throws IOException { |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 508 | // persist icons that haven't been persisted yet |
Chris Wren | 6d0dde0 | 2014-02-10 12:16:54 -0500 | [diff] [blame] | 509 | if (!initializeIconCache()) { |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 510 | dataChanged(); // try again later |
Chris Wren | d8fe6de | 2013-10-04 10:42:14 -0400 | [diff] [blame] | 511 | if (DEBUG) Log.d(TAG, "Launcher is not initialized, delaying icon backup"); |
| 512 | return; |
| 513 | } |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 514 | final ContentResolver cr = mContext.getContentResolver(); |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 515 | final int dpi = mContext.getResources().getDisplayMetrics().densityDpi; |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 516 | final UserHandleCompat myUserHandle = UserHandleCompat.myUserHandle(); |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 517 | int backupUpIconCount = 0; |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 518 | |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 519 | // Don't backup apps in other profiles for now. |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 520 | String where = "(" + Favorites.ITEM_TYPE + "=" + Favorites.ITEM_TYPE_APPLICATION + " OR " + |
Kenny Guy | 43ea7ac | 2014-05-09 16:44:18 +0100 | [diff] [blame] | 521 | Favorites.ITEM_TYPE + "=" + Favorites.ITEM_TYPE_SHORTCUT + ") AND " + |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 522 | getUserSelectionArg(); |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 523 | Cursor cursor = cr.query(Favorites.CONTENT_URI, FAVORITE_PROJECTION, |
| 524 | where, null, null); |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 525 | try { |
| 526 | cursor.moveToPosition(-1); |
| 527 | while(cursor.moveToNext()) { |
| 528 | final long id = cursor.getLong(ID_INDEX); |
| 529 | final String intentDescription = cursor.getString(INTENT_INDEX); |
| 530 | try { |
| 531 | Intent intent = Intent.parseUri(intentDescription, 0); |
| 532 | ComponentName cn = intent.getComponent(); |
| 533 | Key key = null; |
| 534 | String backupKey = null; |
| 535 | if (cn != null) { |
| 536 | key = getKey(Key.ICON, cn.flattenToShortString()); |
| 537 | backupKey = keyToBackupKey(key); |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 538 | } else { |
| 539 | Log.w(TAG, "empty intent on application favorite: " + id); |
| 540 | } |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 541 | if (mExistingKeys.contains(backupKey)) { |
| 542 | if (DEBUG) Log.d(TAG, "already saved icon " + backupKey); |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 543 | |
| 544 | // remember that we already backed this up previously |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 545 | mKeys.add(key); |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 546 | } else if (backupKey != null) { |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 547 | if (DEBUG) Log.d(TAG, "I can count this high: " + backupUpIconCount); |
| 548 | if (backupUpIconCount < MAX_ICONS_PER_PASS) { |
| 549 | if (DEBUG) Log.d(TAG, "saving icon " + backupKey); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 550 | Bitmap icon = mIconCache.getIcon(intent, myUserHandle); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 551 | if (icon != null && !mIconCache.isDefaultIcon(icon, myUserHandle)) { |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 552 | writeRowToBackup(key, packIcon(dpi, icon), data); |
| 553 | mKeys.add(key); |
| 554 | backupUpIconCount ++; |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 555 | } |
| 556 | } else { |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 557 | if (VERBOSE) Log.v(TAG, "deferring icon backup " + backupKey); |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 558 | // too many icons for this pass, request another. |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 559 | dataChanged(); |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 560 | } |
| 561 | } |
| 562 | } catch (URISyntaxException e) { |
Chris Wren | 50c8f42 | 2014-01-15 16:10:39 -0500 | [diff] [blame] | 563 | Log.e(TAG, "invalid URI on application favorite: " + id); |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 564 | } catch (IOException e) { |
Chris Wren | 50c8f42 | 2014-01-15 16:10:39 -0500 | [diff] [blame] | 565 | Log.e(TAG, "unable to save application icon for favorite: " + id); |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | } |
| 569 | } finally { |
| 570 | cursor.close(); |
| 571 | } |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | /** |
| 575 | * Read an icon from the stream. |
| 576 | * |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 577 | * <P>Keys arrive in any order, so shortcuts that use this icon may already exist. |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 578 | * |
| 579 | * @param key identifier for the row |
| 580 | * @param buffer the serialized proto from the stream, may be larger than dataSize |
| 581 | * @param dataSize the size of the proto from the stream |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 582 | */ |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 583 | private void restoreIcon(Key key, byte[] buffer, int dataSize) throws IOException { |
Chris Wren | 50c8f42 | 2014-01-15 16:10:39 -0500 | [diff] [blame] | 584 | if (VERBOSE) Log.v(TAG, "unpacking icon " + key.id); |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 585 | if (DEBUG) Log.d(TAG, "read (" + buffer.length + "): " + |
| 586 | Base64.encodeToString(buffer, 0, dataSize, Base64.NO_WRAP)); |
Chris Wren | 6d0dde0 | 2014-02-10 12:16:54 -0500 | [diff] [blame] | 587 | |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 588 | Resource res = unpackProto(new Resource(), buffer, dataSize); |
| 589 | if (DEBUG) { |
| 590 | Log.d(TAG, "unpacked " + res.dpi + " dpi icon"); |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 591 | } |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 592 | Bitmap icon = BitmapFactory.decodeByteArray(res.data, 0, res.data.length); |
| 593 | if (icon == null) { |
| 594 | Log.w(TAG, "failed to unpack icon for " + key.name); |
| 595 | } |
| 596 | if (VERBOSE) Log.v(TAG, "saving restored icon as: " + key.name); |
| 597 | IconCache.preloadIcon(mContext, ComponentName.unflattenFromString(key.name), icon, res.dpi); |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 598 | } |
| 599 | |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 600 | /** |
| 601 | * Write all the static widget resources we need to render placeholders |
| 602 | * for a package that is not installed. |
| 603 | * |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 604 | * @param data output stream for key/value pairs |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 605 | * @throws IOException |
| 606 | */ |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 607 | private void backupWidgets(BackupDataOutput data) throws IOException { |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 608 | // persist static widget info that hasn't been persisted yet |
Chris Wren | d8fe6de | 2013-10-04 10:42:14 -0400 | [diff] [blame] | 609 | final LauncherAppState appState = LauncherAppState.getInstanceNoCreate(); |
Chris Wren | 6d0dde0 | 2014-02-10 12:16:54 -0500 | [diff] [blame] | 610 | if (appState == null || !initializeIconCache()) { |
| 611 | Log.w(TAG, "Failed to get icon cache during restore"); |
Chris Wren | d8fe6de | 2013-10-04 10:42:14 -0400 | [diff] [blame] | 612 | return; |
| 613 | } |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 614 | final ContentResolver cr = mContext.getContentResolver(); |
| 615 | final WidgetPreviewLoader previewLoader = new WidgetPreviewLoader(mContext); |
| 616 | final PagedViewCellLayout widgetSpacingLayout = new PagedViewCellLayout(mContext); |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 617 | final int dpi = mContext.getResources().getDisplayMetrics().densityDpi; |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 618 | final DeviceProfile profile = appState.getDynamicGrid().getDeviceProfile(); |
| 619 | if (DEBUG) Log.d(TAG, "cellWidthPx: " + profile.cellWidthPx); |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 620 | int backupWidgetCount = 0; |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 621 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 622 | String where = Favorites.ITEM_TYPE + "=" + Favorites.ITEM_TYPE_APPWIDGET + " AND " |
| 623 | + getUserSelectionArg(); |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 624 | Cursor cursor = cr.query(Favorites.CONTENT_URI, FAVORITE_PROJECTION, |
| 625 | where, null, null); |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 626 | try { |
| 627 | cursor.moveToPosition(-1); |
| 628 | while(cursor.moveToNext()) { |
| 629 | final long id = cursor.getLong(ID_INDEX); |
| 630 | final String providerName = cursor.getString(APPWIDGET_PROVIDER_INDEX); |
| 631 | final int spanX = cursor.getInt(SPANX_INDEX); |
| 632 | final int spanY = cursor.getInt(SPANY_INDEX); |
| 633 | final ComponentName provider = ComponentName.unflattenFromString(providerName); |
| 634 | Key key = null; |
| 635 | String backupKey = null; |
| 636 | if (provider != null) { |
| 637 | key = getKey(Key.WIDGET, providerName); |
| 638 | backupKey = keyToBackupKey(key); |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 639 | } else { |
| 640 | Log.w(TAG, "empty intent on appwidget: " + id); |
| 641 | } |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 642 | if (mExistingKeys.contains(backupKey)) { |
| 643 | if (DEBUG) Log.d(TAG, "already saved widget " + backupKey); |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 644 | |
| 645 | // remember that we already backed this up previously |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 646 | mKeys.add(key); |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 647 | } else if (backupKey != null) { |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 648 | if (DEBUG) Log.d(TAG, "I can count this high: " + backupWidgetCount); |
| 649 | if (backupWidgetCount < MAX_WIDGETS_PER_PASS) { |
| 650 | if (DEBUG) Log.d(TAG, "saving widget " + backupKey); |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 651 | previewLoader.setPreviewSize(spanX * profile.cellWidthPx, |
| 652 | spanY * profile.cellHeightPx, widgetSpacingLayout); |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 653 | writeRowToBackup(key, packWidget(dpi, previewLoader, mIconCache, provider), data); |
| 654 | mKeys.add(key); |
| 655 | backupWidgetCount ++; |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 656 | } else { |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 657 | if (VERBOSE) Log.v(TAG, "deferring widget backup " + backupKey); |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 658 | // too many widgets for this pass, request another. |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 659 | dataChanged(); |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 660 | } |
| 661 | } |
| 662 | } |
| 663 | } finally { |
| 664 | cursor.close(); |
| 665 | } |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | /** |
| 669 | * Read a widget from the stream. |
| 670 | * |
| 671 | * <P>Keys arrive in any order, so widgets that use this data may already exist. |
| 672 | * |
| 673 | * @param key identifier for the row |
| 674 | * @param buffer the serialized proto from the stream, may be larger than dataSize |
| 675 | * @param dataSize the size of the proto from the stream |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 676 | */ |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 677 | private void restoreWidget(Key key, byte[] buffer, int dataSize) throws IOException { |
Chris Wren | 50c8f42 | 2014-01-15 16:10:39 -0500 | [diff] [blame] | 678 | if (VERBOSE) Log.v(TAG, "unpacking widget " + key.id); |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 679 | if (DEBUG) Log.d(TAG, "read (" + buffer.length + "): " + |
| 680 | Base64.encodeToString(buffer, 0, dataSize, Base64.NO_WRAP)); |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 681 | Widget widget = unpackProto(new Widget(), buffer, dataSize); |
| 682 | if (DEBUG) Log.d(TAG, "unpacked " + widget.provider); |
| 683 | if (widget.icon.data != null) { |
| 684 | Bitmap icon = BitmapFactory |
| 685 | .decodeByteArray(widget.icon.data, 0, widget.icon.data.length); |
| 686 | if (icon == null) { |
| 687 | Log.w(TAG, "failed to unpack widget icon for " + key.name); |
Chris Wren | 5dee7af | 2013-12-20 17:22:11 -0500 | [diff] [blame] | 688 | } else { |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 689 | IconCache.preloadIcon(mContext, ComponentName.unflattenFromString(widget.provider), |
| 690 | icon, widget.icon.dpi); |
Chris Wren | 5dee7af | 2013-12-20 17:22:11 -0500 | [diff] [blame] | 691 | } |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 692 | } |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 693 | |
| 694 | // future site of widget table mutation |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 695 | } |
| 696 | |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 697 | /** create a new key, with an integer ID. |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 698 | * |
| 699 | * <P> Keys contain their own checksum instead of using |
| 700 | * the heavy-weight CheckedMessage wrapper. |
| 701 | */ |
| 702 | private Key getKey(int type, long id) { |
| 703 | Key key = new Key(); |
| 704 | key.type = type; |
| 705 | key.id = id; |
| 706 | key.checksum = checkKey(key); |
| 707 | return key; |
| 708 | } |
| 709 | |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 710 | /** create a new key for a named object. |
| 711 | * |
| 712 | * <P> Keys contain their own checksum instead of using |
| 713 | * the heavy-weight CheckedMessage wrapper. |
| 714 | */ |
| 715 | private Key getKey(int type, String name) { |
| 716 | Key key = new Key(); |
| 717 | key.type = type; |
| 718 | key.name = name; |
| 719 | key.checksum = checkKey(key); |
| 720 | return key; |
| 721 | } |
| 722 | |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 723 | /** keys need to be strings, serialize and encode. */ |
| 724 | private String keyToBackupKey(Key key) { |
Chris Wren | 978194c | 2013-10-03 17:47:22 -0400 | [diff] [blame] | 725 | return Base64.encodeToString(Key.toByteArray(key), Base64.NO_WRAP); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | /** keys need to be strings, decode and parse. */ |
Sunny Goyal | 5fd733d | 2014-10-29 10:51:54 -0700 | [diff] [blame] | 729 | private Key backupKeyToKey(String backupKey) throws InvalidBackupException { |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 730 | try { |
| 731 | Key key = Key.parseFrom(Base64.decode(backupKey, Base64.DEFAULT)); |
| 732 | if (key.checksum != checkKey(key)) { |
| 733 | key = null; |
Sunny Goyal | 5fd733d | 2014-10-29 10:51:54 -0700 | [diff] [blame] | 734 | throw new InvalidBackupException("invalid key read from stream" + backupKey); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 735 | } |
| 736 | return key; |
| 737 | } catch (InvalidProtocolBufferNanoException e) { |
Sunny Goyal | 5fd733d | 2014-10-29 10:51:54 -0700 | [diff] [blame] | 738 | throw new InvalidBackupException(e); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 739 | } catch (IllegalArgumentException e) { |
Sunny Goyal | 5fd733d | 2014-10-29 10:51:54 -0700 | [diff] [blame] | 740 | throw new InvalidBackupException(e); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 741 | } |
| 742 | } |
| 743 | |
| 744 | /** Compute the checksum over the important bits of a key. */ |
| 745 | private long checkKey(Key key) { |
| 746 | CRC32 checksum = new CRC32(); |
| 747 | checksum.update(key.type); |
| 748 | checksum.update((int) (key.id & 0xffff)); |
| 749 | checksum.update((int) ((key.id >> 32) & 0xffff)); |
| 750 | if (!TextUtils.isEmpty(key.name)) { |
| 751 | checksum.update(key.name.getBytes()); |
| 752 | } |
| 753 | return checksum.getValue(); |
| 754 | } |
| 755 | |
| 756 | /** Serialize a Favorite for persistence, including a checksum wrapper. */ |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 757 | private Favorite packFavorite(Cursor c) { |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 758 | Favorite favorite = new Favorite(); |
| 759 | favorite.id = c.getLong(ID_INDEX); |
| 760 | favorite.screen = c.getInt(SCREEN_INDEX); |
| 761 | favorite.container = c.getInt(CONTAINER_INDEX); |
| 762 | favorite.cellX = c.getInt(CELLX_INDEX); |
| 763 | favorite.cellY = c.getInt(CELLY_INDEX); |
| 764 | favorite.spanX = c.getInt(SPANX_INDEX); |
| 765 | favorite.spanY = c.getInt(SPANY_INDEX); |
| 766 | favorite.iconType = c.getInt(ICON_TYPE_INDEX); |
| 767 | if (favorite.iconType == Favorites.ICON_TYPE_RESOURCE) { |
| 768 | String iconPackage = c.getString(ICON_PACKAGE_INDEX); |
| 769 | if (!TextUtils.isEmpty(iconPackage)) { |
| 770 | favorite.iconPackage = iconPackage; |
| 771 | } |
| 772 | String iconResource = c.getString(ICON_RESOURCE_INDEX); |
| 773 | if (!TextUtils.isEmpty(iconResource)) { |
| 774 | favorite.iconResource = iconResource; |
| 775 | } |
| 776 | } |
| 777 | if (favorite.iconType == Favorites.ICON_TYPE_BITMAP) { |
| 778 | byte[] blob = c.getBlob(ICON_INDEX); |
| 779 | if (blob != null && blob.length > 0) { |
| 780 | favorite.icon = blob; |
| 781 | } |
| 782 | } |
| 783 | String title = c.getString(TITLE_INDEX); |
| 784 | if (!TextUtils.isEmpty(title)) { |
| 785 | favorite.title = title; |
| 786 | } |
Kenny Guy | f8b1dfd | 2014-05-13 12:59:34 +0100 | [diff] [blame] | 787 | String intentDescription = c.getString(INTENT_INDEX); |
| 788 | if (!TextUtils.isEmpty(intentDescription)) { |
| 789 | try { |
| 790 | Intent intent = Intent.parseUri(intentDescription, 0); |
| 791 | intent.removeExtra(ItemInfo.EXTRA_PROFILE); |
| 792 | favorite.intent = intent.toUri(0); |
| 793 | } catch (URISyntaxException e) { |
| 794 | Log.e(TAG, "Invalid intent", e); |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 795 | } |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 796 | } |
| 797 | favorite.itemType = c.getInt(ITEM_TYPE_INDEX); |
| 798 | if (favorite.itemType == Favorites.ITEM_TYPE_APPWIDGET) { |
| 799 | favorite.appWidgetId = c.getInt(APPWIDGET_ID_INDEX); |
| 800 | String appWidgetProvider = c.getString(APPWIDGET_PROVIDER_INDEX); |
| 801 | if (!TextUtils.isEmpty(appWidgetProvider)) { |
| 802 | favorite.appWidgetProvider = appWidgetProvider; |
| 803 | } |
| 804 | } |
| 805 | |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 806 | return favorite; |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | /** Deserialize a Favorite from persistence, after verifying checksum wrapper. */ |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 810 | private ContentValues unpackFavorite(byte[] buffer, int dataSize) |
Sunny Goyal | 5fd733d | 2014-10-29 10:51:54 -0700 | [diff] [blame] | 811 | throws IOException { |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 812 | Favorite favorite = unpackProto(new Favorite(), buffer, dataSize); |
Chris Wren | 5dee7af | 2013-12-20 17:22:11 -0500 | [diff] [blame] | 813 | ContentValues values = new ContentValues(); |
| 814 | values.put(Favorites._ID, favorite.id); |
| 815 | values.put(Favorites.SCREEN, favorite.screen); |
| 816 | values.put(Favorites.CONTAINER, favorite.container); |
| 817 | values.put(Favorites.CELLX, favorite.cellX); |
| 818 | values.put(Favorites.CELLY, favorite.cellY); |
| 819 | values.put(Favorites.SPANX, favorite.spanX); |
| 820 | values.put(Favorites.SPANY, favorite.spanY); |
| 821 | values.put(Favorites.ICON_TYPE, favorite.iconType); |
| 822 | if (favorite.iconType == Favorites.ICON_TYPE_RESOURCE) { |
| 823 | values.put(Favorites.ICON_PACKAGE, favorite.iconPackage); |
| 824 | values.put(Favorites.ICON_RESOURCE, favorite.iconResource); |
| 825 | } |
| 826 | if (favorite.iconType == Favorites.ICON_TYPE_BITMAP) { |
| 827 | values.put(Favorites.ICON, favorite.icon); |
| 828 | } |
| 829 | if (!TextUtils.isEmpty(favorite.title)) { |
| 830 | values.put(Favorites.TITLE, favorite.title); |
| 831 | } else { |
| 832 | values.put(Favorites.TITLE, ""); |
| 833 | } |
| 834 | if (!TextUtils.isEmpty(favorite.intent)) { |
| 835 | values.put(Favorites.INTENT, favorite.intent); |
| 836 | } |
| 837 | values.put(Favorites.ITEM_TYPE, favorite.itemType); |
Chris Wren | f4d0811 | 2014-01-16 18:13:56 -0500 | [diff] [blame] | 838 | |
Kenny Guy | f8b1dfd | 2014-05-13 12:59:34 +0100 | [diff] [blame] | 839 | UserHandleCompat myUserHandle = UserHandleCompat.myUserHandle(); |
| 840 | long userSerialNumber = |
| 841 | UserManagerCompat.getInstance(mContext).getSerialNumberForUser(myUserHandle); |
| 842 | values.put(LauncherSettings.Favorites.PROFILE_ID, userSerialNumber); |
| 843 | |
Sunny Goyal | 5fd733d | 2014-10-29 10:51:54 -0700 | [diff] [blame] | 844 | DeviceProfieData currentProfile = getDeviceProfieData(); |
| 845 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 846 | if (favorite.itemType == Favorites.ITEM_TYPE_APPWIDGET) { |
| 847 | if (!TextUtils.isEmpty(favorite.appWidgetProvider)) { |
| 848 | values.put(Favorites.APPWIDGET_PROVIDER, favorite.appWidgetProvider); |
| 849 | } |
| 850 | values.put(Favorites.APPWIDGET_ID, favorite.appWidgetId); |
| 851 | values.put(LauncherSettings.Favorites.RESTORED, |
| 852 | LauncherAppWidgetInfo.FLAG_ID_NOT_VALID | |
| 853 | LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY | |
| 854 | LauncherAppWidgetInfo.FLAG_UI_NOT_READY); |
Sunny Goyal | 5fd733d | 2014-10-29 10:51:54 -0700 | [diff] [blame] | 855 | |
| 856 | // Verify placement |
| 857 | if (((favorite.cellX + favorite.spanX) > currentProfile.desktopCols) |
| 858 | || ((favorite.cellY + favorite.spanY) > currentProfile.desktopRows)) { |
| 859 | restoreSuccessful = false; |
| 860 | throw new InvalidBackupException("Widget not in screen bounds, aborting restore"); |
| 861 | } |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 862 | } else { |
| 863 | // Let LauncherModel know we've been here. |
| 864 | values.put(LauncherSettings.Favorites.RESTORED, 1); |
Sunny Goyal | 5fd733d | 2014-10-29 10:51:54 -0700 | [diff] [blame] | 865 | |
| 866 | // Verify placement |
| 867 | if (favorite.container == Favorites.CONTAINER_HOTSEAT) { |
| 868 | if ((favorite.screen >= currentProfile.hotseatCount) |
| 869 | || (favorite.screen == currentProfile.allappsRank)) { |
| 870 | restoreSuccessful = false; |
| 871 | throw new InvalidBackupException("Item not in hotseat bounds, aborting restore"); |
| 872 | } |
| 873 | } else { |
| 874 | if ((favorite.cellX >= currentProfile.desktopCols) |
| 875 | || (favorite.cellY >= currentProfile.desktopRows)) { |
| 876 | restoreSuccessful = false; |
| 877 | throw new InvalidBackupException("Item not in desktop bounds, aborting restore"); |
| 878 | } |
| 879 | } |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 880 | } |
Chris Wren | f4d0811 | 2014-01-16 18:13:56 -0500 | [diff] [blame] | 881 | |
Chris Wren | 5dee7af | 2013-12-20 17:22:11 -0500 | [diff] [blame] | 882 | return values; |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | /** Serialize a Screen for persistence, including a checksum wrapper. */ |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 886 | private Screen packScreen(Cursor c) { |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 887 | Screen screen = new Screen(); |
| 888 | screen.id = c.getLong(ID_INDEX); |
| 889 | screen.rank = c.getInt(SCREEN_RANK_INDEX); |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 890 | return screen; |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | /** Deserialize a Screen from persistence, after verifying checksum wrapper. */ |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 894 | private ContentValues unpackScreen(byte[] buffer, int dataSize) |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 895 | throws InvalidProtocolBufferNanoException { |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 896 | Screen screen = unpackProto(new Screen(), buffer, dataSize); |
Chris Wren | 5dee7af | 2013-12-20 17:22:11 -0500 | [diff] [blame] | 897 | ContentValues values = new ContentValues(); |
| 898 | values.put(WorkspaceScreens._ID, screen.id); |
| 899 | values.put(WorkspaceScreens.SCREEN_RANK, screen.rank); |
| 900 | return values; |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 901 | } |
| 902 | |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 903 | /** Serialize an icon Resource for persistence, including a checksum wrapper. */ |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 904 | private Resource packIcon(int dpi, Bitmap icon) { |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 905 | Resource res = new Resource(); |
| 906 | res.dpi = dpi; |
| 907 | ByteArrayOutputStream os = new ByteArrayOutputStream(); |
Chris Wren | b86f076 | 2013-10-04 10:10:21 -0400 | [diff] [blame] | 908 | if (icon.compress(IMAGE_FORMAT, IMAGE_COMPRESSION_QUALITY, os)) { |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 909 | res.data = os.toByteArray(); |
| 910 | } |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 911 | return res; |
| 912 | } |
| 913 | |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 914 | /** Serialize a widget for persistence, including a checksum wrapper. */ |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 915 | private Widget packWidget(int dpi, WidgetPreviewLoader previewLoader, IconCache iconCache, |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 916 | ComponentName provider) { |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 917 | final LauncherAppWidgetProviderInfo info = |
| 918 | LauncherModel.getProviderInfo(mContext, provider); |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 919 | Widget widget = new Widget(); |
| 920 | widget.provider = provider.flattenToShortString(); |
| 921 | widget.label = info.label; |
| 922 | widget.configure = info.configure != null; |
| 923 | if (info.icon != 0) { |
| 924 | widget.icon = new Resource(); |
| 925 | Drawable fullResIcon = iconCache.getFullResIcon(provider.getPackageName(), info.icon); |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 926 | Bitmap icon = Utilities.createIconBitmap(fullResIcon, mContext); |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 927 | ByteArrayOutputStream os = new ByteArrayOutputStream(); |
Chris Wren | b86f076 | 2013-10-04 10:10:21 -0400 | [diff] [blame] | 928 | if (icon.compress(IMAGE_FORMAT, IMAGE_COMPRESSION_QUALITY, os)) { |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 929 | widget.icon.data = os.toByteArray(); |
| 930 | widget.icon.dpi = dpi; |
| 931 | } |
| 932 | } |
| 933 | if (info.previewImage != 0) { |
| 934 | widget.preview = new Resource(); |
| 935 | Bitmap preview = previewLoader.generateWidgetPreview(info, null); |
| 936 | ByteArrayOutputStream os = new ByteArrayOutputStream(); |
Chris Wren | b86f076 | 2013-10-04 10:10:21 -0400 | [diff] [blame] | 937 | if (preview.compress(IMAGE_FORMAT, IMAGE_COMPRESSION_QUALITY, os)) { |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 938 | widget.preview.data = os.toByteArray(); |
| 939 | widget.preview.dpi = dpi; |
| 940 | } |
| 941 | } |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 942 | return widget; |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 943 | } |
| 944 | |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 945 | /** |
| 946 | * Deserialize a proto after verifying checksum wrapper. |
| 947 | */ |
| 948 | private <T extends MessageNano> T unpackProto(T proto, byte[] buffer, int dataSize) |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 949 | throws InvalidProtocolBufferNanoException { |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 950 | MessageNano.mergeFrom(proto, readCheckedBytes(buffer, dataSize)); |
| 951 | if (DEBUG) Log.d(TAG, "unpacked proto " + proto); |
| 952 | return proto; |
Chris Wren | fd13c71 | 2013-09-27 15:45:19 -0400 | [diff] [blame] | 953 | } |
| 954 | |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 955 | /** |
| 956 | * Read the old journal from the input file. |
| 957 | * |
| 958 | * In the event of any error, just pretend we didn't have a journal, |
| 959 | * in that case, do a full backup. |
| 960 | * |
| 961 | * @param oldState the read-0only file descriptor pointing to the old journal |
Chris Wren | 65b6a60 | 2014-01-10 14:11:25 -0500 | [diff] [blame] | 962 | * @return a Journal protocol buffer |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 963 | */ |
| 964 | private Journal readJournal(ParcelFileDescriptor oldState) { |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 965 | Journal journal = new Journal(); |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 966 | if (oldState == null) { |
| 967 | return journal; |
| 968 | } |
| 969 | FileInputStream inStream = new FileInputStream(oldState.getFileDescriptor()); |
| 970 | try { |
Chris Wren | 65b6a60 | 2014-01-10 14:11:25 -0500 | [diff] [blame] | 971 | int availableBytes = inStream.available(); |
| 972 | if (DEBUG) Log.d(TAG, "available " + availableBytes); |
| 973 | if (availableBytes < MAX_JOURNAL_SIZE) { |
| 974 | byte[] buffer = new byte[availableBytes]; |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 975 | int bytesRead = 0; |
Chris Wren | 65b6a60 | 2014-01-10 14:11:25 -0500 | [diff] [blame] | 976 | boolean valid = false; |
Chris Wren | 50c8f42 | 2014-01-15 16:10:39 -0500 | [diff] [blame] | 977 | InvalidProtocolBufferNanoException lastProtoException = null; |
Chris Wren | 65b6a60 | 2014-01-10 14:11:25 -0500 | [diff] [blame] | 978 | while (availableBytes > 0) { |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 979 | try { |
Chris Wren | 65b6a60 | 2014-01-10 14:11:25 -0500 | [diff] [blame] | 980 | // OMG what are you doing? This is crazy inefficient! |
| 981 | // If we read a byte that is not ours, we will cause trouble: b/12491813 |
| 982 | // However, we don't know how many bytes to expect (oops). |
| 983 | // So we have to step through *slowly*, watching for the end. |
| 984 | int result = inStream.read(buffer, bytesRead, 1); |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 985 | if (result > 0) { |
Chris Wren | 65b6a60 | 2014-01-10 14:11:25 -0500 | [diff] [blame] | 986 | availableBytes -= result; |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 987 | bytesRead += result; |
| 988 | } else { |
Chris Wren | 65b6a60 | 2014-01-10 14:11:25 -0500 | [diff] [blame] | 989 | Log.w(TAG, "unexpected end of file while reading journal."); |
| 990 | // stop reading and see what there is to parse |
| 991 | availableBytes = 0; |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 992 | } |
| 993 | } catch (IOException e) { |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 994 | buffer = null; |
Chris Wren | 65b6a60 | 2014-01-10 14:11:25 -0500 | [diff] [blame] | 995 | availableBytes = 0; |
| 996 | } |
| 997 | |
| 998 | // check the buffer to see if we have a valid journal |
| 999 | try { |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 1000 | MessageNano.mergeFrom(journal, readCheckedBytes(buffer, bytesRead)); |
Chris Wren | 65b6a60 | 2014-01-10 14:11:25 -0500 | [diff] [blame] | 1001 | // if we are here, then we have read a valid, checksum-verified journal |
| 1002 | valid = true; |
| 1003 | availableBytes = 0; |
Chris Wren | 50c8f42 | 2014-01-15 16:10:39 -0500 | [diff] [blame] | 1004 | if (VERBOSE) Log.v(TAG, "read " + bytesRead + " bytes of journal"); |
Chris Wren | 65b6a60 | 2014-01-10 14:11:25 -0500 | [diff] [blame] | 1005 | } catch (InvalidProtocolBufferNanoException e) { |
| 1006 | // if we don't have the whole journal yet, mergeFrom will throw. keep going. |
Chris Wren | 50c8f42 | 2014-01-15 16:10:39 -0500 | [diff] [blame] | 1007 | lastProtoException = e; |
Chris Wren | 65b6a60 | 2014-01-10 14:11:25 -0500 | [diff] [blame] | 1008 | journal.clear(); |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 1009 | } |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 1010 | } |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 1011 | if (DEBUG) Log.d(TAG, "journal bytes read: " + bytesRead); |
Chris Wren | 65b6a60 | 2014-01-10 14:11:25 -0500 | [diff] [blame] | 1012 | if (!valid) { |
Chris Wren | 50c8f42 | 2014-01-15 16:10:39 -0500 | [diff] [blame] | 1013 | Log.w(TAG, "could not find a valid journal", lastProtoException); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 1014 | } |
| 1015 | } |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 1016 | } catch (IOException e) { |
Chris Wren | 50c8f42 | 2014-01-15 16:10:39 -0500 | [diff] [blame] | 1017 | Log.w(TAG, "failed to close the journal", e); |
Chris Wren | 92aa423 | 2013-10-04 11:29:36 -0400 | [diff] [blame] | 1018 | } finally { |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 1019 | try { |
| 1020 | inStream.close(); |
| 1021 | } catch (IOException e) { |
Chris Wren | 50c8f42 | 2014-01-15 16:10:39 -0500 | [diff] [blame] | 1022 | Log.w(TAG, "failed to close the journal", e); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 1023 | } |
| 1024 | } |
| 1025 | return journal; |
| 1026 | } |
| 1027 | |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 1028 | private void writeRowToBackup(Key key, MessageNano proto, BackupDataOutput data) |
| 1029 | throws IOException { |
| 1030 | writeRowToBackup(keyToBackupKey(key), proto, data); |
| 1031 | } |
| 1032 | |
| 1033 | private void writeRowToBackup(String backupKey, MessageNano proto, |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 1034 | BackupDataOutput data) throws IOException { |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 1035 | byte[] blob = writeCheckedBytes(proto); |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 1036 | data.writeEntityHeader(backupKey, blob.length); |
| 1037 | data.writeEntityData(blob, blob.length); |
Sunny Goyal | c0ee675 | 2015-01-16 14:10:32 -0800 | [diff] [blame] | 1038 | mBackupDataWasUpdated = true; |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 1039 | if (VERBOSE) Log.v(TAG, "Writing New entry " + backupKey); |
Chris Wren | 22e130d | 2013-09-23 18:25:57 -0400 | [diff] [blame] | 1040 | } |
| 1041 | |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 1042 | /** |
| 1043 | * Write the new journal to the output file. |
| 1044 | * |
| 1045 | * In the event of any error, just pretend we didn't have a journal, |
| 1046 | * in that case, do a full backup. |
| 1047 | |
| 1048 | * @param newState the write-only file descriptor pointing to the new journal |
| 1049 | * @param journal a Journal protocol buffer |
| 1050 | */ |
| 1051 | private void writeJournal(ParcelFileDescriptor newState, Journal journal) { |
| 1052 | FileOutputStream outStream = null; |
| 1053 | try { |
| 1054 | outStream = new FileOutputStream(newState.getFileDescriptor()); |
Chris Wren | 65b6a60 | 2014-01-10 14:11:25 -0500 | [diff] [blame] | 1055 | final byte[] journalBytes = writeCheckedBytes(journal); |
Chris Wren | 65b6a60 | 2014-01-10 14:11:25 -0500 | [diff] [blame] | 1056 | outStream.write(journalBytes); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 1057 | outStream.close(); |
Chris Wren | 50c8f42 | 2014-01-15 16:10:39 -0500 | [diff] [blame] | 1058 | if (VERBOSE) Log.v(TAG, "wrote " + journalBytes.length + " bytes of journal"); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 1059 | } catch (IOException e) { |
Chris Wren | 50c8f42 | 2014-01-15 16:10:39 -0500 | [diff] [blame] | 1060 | Log.w(TAG, "failed to write backup journal", e); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | /** Wrap a proto in a CheckedMessage and compute the checksum. */ |
| 1065 | private byte[] writeCheckedBytes(MessageNano proto) { |
| 1066 | CheckedMessage wrapper = new CheckedMessage(); |
| 1067 | wrapper.payload = MessageNano.toByteArray(proto); |
| 1068 | CRC32 checksum = new CRC32(); |
| 1069 | checksum.update(wrapper.payload); |
| 1070 | wrapper.checksum = checksum.getValue(); |
| 1071 | return MessageNano.toByteArray(wrapper); |
| 1072 | } |
| 1073 | |
| 1074 | /** Unwrap a proto message from a CheckedMessage, verifying the checksum. */ |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 1075 | private static byte[] readCheckedBytes(byte[] buffer, int dataSize) |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 1076 | throws InvalidProtocolBufferNanoException { |
| 1077 | CheckedMessage wrapper = new CheckedMessage(); |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 1078 | MessageNano.mergeFrom(wrapper, buffer, 0, dataSize); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 1079 | CRC32 checksum = new CRC32(); |
| 1080 | checksum.update(wrapper.payload); |
| 1081 | if (wrapper.checksum != checksum.getValue()) { |
| 1082 | throw new InvalidProtocolBufferNanoException("checksum does not match"); |
| 1083 | } |
| 1084 | return wrapper.payload; |
| 1085 | } |
| 1086 | |
Chris Wren | 6d0dde0 | 2014-02-10 12:16:54 -0500 | [diff] [blame] | 1087 | private boolean initializeIconCache() { |
| 1088 | if (mIconCache != null) { |
| 1089 | return true; |
| 1090 | } |
| 1091 | |
| 1092 | final LauncherAppState appState = LauncherAppState.getInstanceNoCreate(); |
| 1093 | if (appState == null) { |
| 1094 | Throwable stackTrace = new Throwable(); |
| 1095 | stackTrace.fillInStackTrace(); |
| 1096 | Log.w(TAG, "Failed to get app state during backup/restore", stackTrace); |
| 1097 | return false; |
| 1098 | } |
| 1099 | mIconCache = appState.getIconCache(); |
| 1100 | return mIconCache != null; |
| 1101 | } |
| 1102 | |
Chris Wren | 7114426 | 2014-02-27 15:49:39 -0500 | [diff] [blame] | 1103 | |
Sunny Goyal | ef728d4 | 2014-10-22 11:28:28 -0700 | [diff] [blame] | 1104 | /** |
| 1105 | * @return true if the launcher is in a state to support backup |
| 1106 | */ |
Chris Wren | 7114426 | 2014-02-27 15:49:39 -0500 | [diff] [blame] | 1107 | private boolean launcherIsReady() { |
| 1108 | ContentResolver cr = mContext.getContentResolver(); |
| 1109 | Cursor cursor = cr.query(Favorites.CONTENT_URI, FAVORITE_PROJECTION, null, null, null); |
| 1110 | if (cursor == null) { |
| 1111 | // launcher data has been wiped, do nothing |
| 1112 | return false; |
| 1113 | } |
| 1114 | cursor.close(); |
| 1115 | |
| 1116 | if (!initializeIconCache()) { |
| 1117 | // launcher services are unavailable, try again later |
| 1118 | dataChanged(); |
| 1119 | return false; |
| 1120 | } |
| 1121 | |
| 1122 | return true; |
| 1123 | } |
| 1124 | |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 1125 | private String getUserSelectionArg() { |
| 1126 | return Favorites.PROFILE_ID + '=' + UserManagerCompat.getInstance(mContext) |
| 1127 | .getSerialNumberForUser(UserHandleCompat.myUserHandle()); |
| 1128 | } |
| 1129 | |
Sunny Goyal | 5fd733d | 2014-10-29 10:51:54 -0700 | [diff] [blame] | 1130 | private class InvalidBackupException extends IOException { |
| 1131 | private InvalidBackupException(Throwable cause) { |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 1132 | super(cause); |
| 1133 | } |
| 1134 | |
Sunny Goyal | 5fd733d | 2014-10-29 10:51:54 -0700 | [diff] [blame] | 1135 | public InvalidBackupException(String reason) { |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 1136 | super(reason); |
| 1137 | } |
| 1138 | } |
| 1139 | } |