blob: be3bcc774cd137981dc8faefdd3b1efadc7dc74d [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
2 * Copyright (C) 2009 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 */
16
Stefanote66c1c32018-08-28 16:51:08 +010017package com.android.localtransport;
Christopher Tate9bbc21a2009-06-10 20:23:25 -070018
Al Sutton6d299d22019-10-16 11:18:27 +010019import android.annotation.Nullable;
Bernardo Rufinoeaa78b92018-01-26 11:25:37 +000020import android.app.backup.BackupAgent;
Christopher Tate45281862010-03-05 15:46:30 -080021import android.app.backup.BackupDataInput;
22import android.app.backup.BackupDataOutput;
Christopher Tate74318c92014-05-15 19:03:44 -070023import android.app.backup.BackupTransport;
Christopher Tate6a49dd02014-06-16 18:49:25 -070024import android.app.backup.RestoreDescription;
Christopher Tate45281862010-03-05 15:46:30 -080025import android.app.backup.RestoreSet;
Christopher Tatecefba582013-11-14 18:10:35 -080026import android.content.ComponentName;
Christopher Tate9bbc21a2009-06-10 20:23:25 -070027import android.content.Context;
Chris Tatea8ddef32010-11-10 11:53:26 -080028import android.content.Intent;
Christopher Tate9bbc21a2009-06-10 20:23:25 -070029import android.content.pm.PackageInfo;
Christopher Tate9bbc21a2009-06-10 20:23:25 -070030import android.os.ParcelFileDescriptor;
Elliott Hughesf97c6332014-04-28 16:38:43 -070031import android.system.ErrnoException;
32import android.system.Os;
33import android.system.StructStat;
Christopher Tatec8a9d422017-06-23 12:48:26 -070034import android.util.ArrayMap;
Bernardo Rufino7a6e0322018-07-17 10:17:43 +010035import android.util.Base64;
Christopher Tate9bbc21a2009-06-10 20:23:25 -070036import android.util.Log;
37
Christopher Tate824392b2014-11-14 18:27:36 -080038import libcore.io.IoUtils;
39
Christopher Tate9ff53a72014-06-03 17:20:07 -070040import java.io.BufferedOutputStream;
Christopher Tate9bbc21a2009-06-10 20:23:25 -070041import java.io.File;
Christopher Tate9bbc21a2009-06-10 20:23:25 -070042import java.io.FileInputStream;
Christopher Tate9ff53a72014-06-03 17:20:07 -070043import java.io.FileNotFoundException;
Christopher Tate9bbc21a2009-06-10 20:23:25 -070044import java.io.FileOutputStream;
45import java.io.IOException;
Christopher Tateadfe8b82014-02-04 16:23:32 -080046import java.util.ArrayList;
47import java.util.Collections;
Christopher Tateb048c332014-02-21 12:50:21 -080048
Christopher Tate9bbc21a2009-06-10 20:23:25 -070049/**
50 * Backup transport for stashing stuff into a known location on disk, and
51 * later restoring from there. For testing only.
52 */
53
Christopher Tate74318c92014-05-15 19:03:44 -070054public class LocalTransport extends BackupTransport {
Christopher Tate9bbc21a2009-06-10 20:23:25 -070055 private static final String TAG = "LocalTransport";
Ed Heyla50cd8d2014-07-14 23:42:04 -070056 private static final boolean DEBUG = false;
Christopher Tate9bbc21a2009-06-10 20:23:25 -070057
Christopher Tate5cb400b2009-06-25 16:03:14 -070058 private static final String TRANSPORT_DIR_NAME
Stefanote66c1c32018-08-28 16:51:08 +010059 = "com.android.localtransport.LocalTransport";
Christopher Tate5cb400b2009-06-25 16:03:14 -070060
Chris Tatea8ddef32010-11-10 11:53:26 -080061 private static final String TRANSPORT_DESTINATION_STRING
62 = "Backing up to debug-only private cache";
63
Christopher Tate96794102014-07-27 20:21:55 -070064 private static final String TRANSPORT_DATA_MANAGEMENT_LABEL
65 = "";
66
Christopher Tate6a49dd02014-06-16 18:49:25 -070067 private static final String INCREMENTAL_DIR = "_delta";
68 private static final String FULL_DATA_DIR = "_full";
69
Christopher Tateadfe8b82014-02-04 16:23:32 -080070 // The currently-active restore set always has the same (nonzero!) token
71 private static final long CURRENT_SET_TOKEN = 1;
Christopher Tate50c6df02010-01-29 12:48:20 -080072
Christopher Tatec8a9d422017-06-23 12:48:26 -070073 // Size quotas at reasonable values, similar to the current cloud-storage limits
Sergey Poromov872d3b62016-01-12 15:48:08 +010074 private static final long FULL_BACKUP_SIZE_QUOTA = 25 * 1024 * 1024;
Shreyas Basargeb6e73c92017-01-31 20:13:43 +000075 private static final long KEY_VALUE_BACKUP_SIZE_QUOTA = 5 * 1024 * 1024;
76
Christopher Tate9bbc21a2009-06-10 20:23:25 -070077 private Context mContext;
Stefanote66c1c32018-08-28 16:51:08 +010078 private File mDataDir;
79 private File mCurrentSetDir;
80 private File mCurrentSetIncrementalDir;
81 private File mCurrentSetFullDir;
Christopher Tateadfe8b82014-02-04 16:23:32 -080082
Dan Egnorefe52642009-06-24 00:16:33 -070083 private PackageInfo[] mRestorePackages = null;
84 private int mRestorePackage = -1; // Index into mRestorePackages
Christopher Tate6a49dd02014-06-16 18:49:25 -070085 private int mRestoreType;
86 private File mRestoreSetDir;
87 private File mRestoreSetIncrementalDir;
88 private File mRestoreSetFullDir;
Christopher Tate9bbc21a2009-06-10 20:23:25 -070089
Christopher Tate9ff53a72014-06-03 17:20:07 -070090 // Additional bookkeeping for full backup
91 private String mFullTargetPackage;
92 private ParcelFileDescriptor mSocket;
93 private FileInputStream mSocketInputStream;
94 private BufferedOutputStream mFullBackupOutputStream;
95 private byte[] mFullBackupBuffer;
Sergey Poromov872d3b62016-01-12 15:48:08 +010096 private long mFullBackupSize;
Christopher Tate9ff53a72014-06-03 17:20:07 -070097
Christopher Tate5a009f92014-06-19 14:53:18 -070098 private FileInputStream mCurFullRestoreStream;
Christopher Tate5a009f92014-06-19 14:53:18 -070099 private byte[] mFullRestoreBuffer;
Bernardo Rufinoeaa78b92018-01-26 11:25:37 +0000100 private final LocalTransportParameters mParameters;
Christopher Tate9bbc21a2009-06-10 20:23:25 -0700101
Christopher Tatede2826b2015-03-12 18:53:31 -0700102 private void makeDataDirs() {
Stefanote66c1c32018-08-28 16:51:08 +0100103 mDataDir = mContext.getFilesDir();
104 mCurrentSetDir = new File(mDataDir, Long.toString(CURRENT_SET_TOKEN));
105 mCurrentSetIncrementalDir = new File(mCurrentSetDir, INCREMENTAL_DIR);
106 mCurrentSetFullDir = new File(mCurrentSetDir, FULL_DATA_DIR);
107
Christopher Tateadfe8b82014-02-04 16:23:32 -0800108 mCurrentSetDir.mkdirs();
Christopher Tatede2826b2015-03-12 18:53:31 -0700109 mCurrentSetFullDir.mkdir();
110 mCurrentSetIncrementalDir.mkdir();
111 }
112
Bernardo Rufinoeaa78b92018-01-26 11:25:37 +0000113 public LocalTransport(Context context, LocalTransportParameters parameters) {
Christopher Tatede2826b2015-03-12 18:53:31 -0700114 mContext = context;
Bernardo Rufinoeaa78b92018-01-26 11:25:37 +0000115 mParameters = parameters;
Christopher Tatede2826b2015-03-12 18:53:31 -0700116 makeDataDirs();
Christopher Tate9bbc21a2009-06-10 20:23:25 -0700117 }
118
Bernardo Rufinoeaa78b92018-01-26 11:25:37 +0000119 LocalTransportParameters getParameters() {
120 return mParameters;
121 }
122
Christopher Tate5a009f92014-06-19 14:53:18 -0700123 @Override
Christopher Tatecefba582013-11-14 18:10:35 -0800124 public String name() {
125 return new ComponentName(mContext, this.getClass()).flattenToShortString();
126 }
127
Christopher Tate5a009f92014-06-19 14:53:18 -0700128 @Override
Chris Tatea8ddef32010-11-10 11:53:26 -0800129 public Intent configurationIntent() {
130 // The local transport is not user-configurable
131 return null;
132 }
133
Christopher Tate5a009f92014-06-19 14:53:18 -0700134 @Override
Chris Tatea8ddef32010-11-10 11:53:26 -0800135 public String currentDestinationString() {
136 return TRANSPORT_DESTINATION_STRING;
137 }
Christopher Tate5cb400b2009-06-25 16:03:14 -0700138
Christopher Tate96794102014-07-27 20:21:55 -0700139 public Intent dataManagementIntent() {
140 // The local transport does not present a data-management UI
141 // TODO: consider adding simple UI to wipe the archives entirely,
142 // for cleaning up the cache partition.
143 return null;
144 }
145
Al Sutton6d299d22019-10-16 11:18:27 +0100146 /** @removed Replaced with dataManagementIntentLabel in the API */
Christopher Tate96794102014-07-27 20:21:55 -0700147 public String dataManagementLabel() {
148 return TRANSPORT_DATA_MANAGEMENT_LABEL;
149 }
150
Christopher Tate5a009f92014-06-19 14:53:18 -0700151 @Override
Al Sutton6d299d22019-10-16 11:18:27 +0100152 @Nullable
153 public CharSequence dataManagementIntentLabel() {
154 return TRANSPORT_DATA_MANAGEMENT_LABEL;
155 }
156
157 @Override
Dan Egnor01445162009-09-21 17:04:05 -0700158 public String transportDirName() {
Christopher Tate5cb400b2009-06-25 16:03:14 -0700159 return TRANSPORT_DIR_NAME;
160 }
161
Christopher Tate5a009f92014-06-19 14:53:18 -0700162 @Override
Bernardo Rufinoeaa78b92018-01-26 11:25:37 +0000163 public int getTransportFlags() {
164 int flags = super.getTransportFlags();
165 // Testing for a fake flag and having it set as a boolean in settings prevents anyone from
166 // using this it to pull data from the agent
167 if (mParameters.isFakeEncryptionFlag()) {
168 flags |= BackupAgent.FLAG_FAKE_CLIENT_SIDE_ENCRYPTION_ENABLED;
169 }
170 return flags;
171 }
172
173 @Override
Dan Egnor01445162009-09-21 17:04:05 -0700174 public long requestBackupTime() {
Christopher Tate9bbc21a2009-06-10 20:23:25 -0700175 // any time is a good time for local backup
176 return 0;
177 }
178
Christopher Tate5a009f92014-06-19 14:53:18 -0700179 @Override
Dan Egnor01445162009-09-21 17:04:05 -0700180 public int initializeDevice() {
181 if (DEBUG) Log.v(TAG, "wiping all data");
Christopher Tateadfe8b82014-02-04 16:23:32 -0800182 deleteContents(mCurrentSetDir);
Christopher Tatede2826b2015-03-12 18:53:31 -0700183 makeDataDirs();
Christopher Tate5a009f92014-06-19 14:53:18 -0700184 return TRANSPORT_OK;
Dan Egnor01445162009-09-21 17:04:05 -0700185 }
186
Christopher Tatec8a9d422017-06-23 12:48:26 -0700187 // Encapsulation of a single k/v element change
188 private class KVOperation {
189 final String key; // Element filename, not the raw key, for efficiency
190 final byte[] value; // null when this is a deletion operation
191
192 KVOperation(String k, byte[] v) {
193 key = k;
194 value = v;
195 }
196 }
197
Christopher Tate5a009f92014-06-19 14:53:18 -0700198 @Override
Dan Egnor01445162009-09-21 17:04:05 -0700199 public int performBackup(PackageInfo packageInfo, ParcelFileDescriptor data) {
Anton Philippovd9030742018-03-26 19:12:08 +0100200 return performBackup(packageInfo, data, /*flags=*/ 0);
201 }
202
203 @Override
204 public int performBackup(PackageInfo packageInfo, ParcelFileDescriptor data, int flags) {
Stefanot07564fa2018-10-04 16:16:30 +0100205 try {
206 return performBackupInternal(packageInfo, data, flags);
207 } finally {
208 IoUtils.closeQuietly(data);
209 }
210 }
211
212 private int performBackupInternal(
213 PackageInfo packageInfo, ParcelFileDescriptor data, int flags) {
Anton Philippovd9030742018-03-26 19:12:08 +0100214 boolean isIncremental = (flags & FLAG_INCREMENTAL) != 0;
215 boolean isNonIncremental = (flags & FLAG_NON_INCREMENTAL) != 0;
216
217 if (isIncremental) {
218 Log.i(TAG, "Performing incremental backup for " + packageInfo.packageName);
219 } else if (isNonIncremental) {
220 Log.i(TAG, "Performing non-incremental backup for " + packageInfo.packageName);
221 } else {
222 Log.i(TAG, "Performing backup for " + packageInfo.packageName);
223 }
224
Christopher Tateb048c332014-02-21 12:50:21 -0800225 if (DEBUG) {
226 try {
Anton Philippovd9030742018-03-26 19:12:08 +0100227 StructStat ss = Os.fstat(data.getFileDescriptor());
228 Log.v(TAG, "performBackup() pkg=" + packageInfo.packageName
229 + " size=" + ss.st_size + " flags=" + flags);
Christopher Tateb048c332014-02-21 12:50:21 -0800230 } catch (ErrnoException e) {
231 Log.w(TAG, "Unable to stat input file in performBackup() on "
232 + packageInfo.packageName);
233 }
234 }
Christopher Tate2fdd4282009-06-12 15:20:04 -0700235
Christopher Tate9ff53a72014-06-03 17:20:07 -0700236 File packageDir = new File(mCurrentSetIncrementalDir, packageInfo.packageName);
Anton Philippovd9030742018-03-26 19:12:08 +0100237 boolean hasDataForPackage = !packageDir.mkdirs();
238
239 if (isIncremental) {
240 if (mParameters.isNonIncrementalOnly() || !hasDataForPackage) {
241 if (mParameters.isNonIncrementalOnly()) {
242 Log.w(TAG, "Transport is in non-incremental only mode.");
243
244 } else {
245 Log.w(TAG,
246 "Requested incremental, but transport currently stores no data for the "
247 + "package, requesting non-incremental retry.");
248 }
249 return TRANSPORT_NON_INCREMENTAL_BACKUP_REQUIRED;
250 }
251 }
252 if (isNonIncremental && hasDataForPackage) {
253 Log.w(TAG, "Requested non-incremental, deleting existing data.");
254 clearBackupData(packageInfo);
255 packageDir.mkdirs();
256 }
Christopher Tate9bbc21a2009-06-10 20:23:25 -0700257
Christopher Tate2fdd4282009-06-12 15:20:04 -0700258 // Each 'record' in the restore set is kept in its own file, named by
259 // the record key. Wind through the data file, extracting individual
Christopher Tatec8a9d422017-06-23 12:48:26 -0700260 // record operations and building a list of all the updates to apply
Christopher Tate2fdd4282009-06-12 15:20:04 -0700261 // in this update.
Christopher Tatec8a9d422017-06-23 12:48:26 -0700262 final ArrayList<KVOperation> changeOps;
Christopher Tate2fdd4282009-06-12 15:20:04 -0700263 try {
Christopher Tatec8a9d422017-06-23 12:48:26 -0700264 changeOps = parseBackupStream(data);
Christopher Tate2fdd4282009-06-12 15:20:04 -0700265 } catch (IOException e) {
266 // oops, something went wrong. abort the operation and return error.
Christopher Tatec8a9d422017-06-23 12:48:26 -0700267 Log.v(TAG, "Exception reading backup input", e);
Christopher Tate5a009f92014-06-19 14:53:18 -0700268 return TRANSPORT_ERROR;
Christopher Tate2fdd4282009-06-12 15:20:04 -0700269 }
Christopher Tatec8a9d422017-06-23 12:48:26 -0700270
271 // Okay, now we've parsed out the delta's individual operations. We need to measure
272 // the effect against what we already have in the datastore to detect quota overrun.
273 // So, we first need to tally up the current in-datastore size per key.
274 final ArrayMap<String, Integer> datastore = new ArrayMap<>();
275 int totalSize = parseKeySizes(packageDir, datastore);
276
277 // ... and now figure out the datastore size that will result from applying the
278 // sequence of delta operations
279 if (DEBUG) {
280 if (changeOps.size() > 0) {
281 Log.v(TAG, "Calculating delta size impact");
282 } else {
283 Log.v(TAG, "No operations in backup stream, so no size change");
284 }
285 }
286 int updatedSize = totalSize;
287 for (KVOperation op : changeOps) {
288 // Deduct the size of the key we're about to replace, if any
289 final Integer curSize = datastore.get(op.key);
290 if (curSize != null) {
291 updatedSize -= curSize.intValue();
292 if (DEBUG && op.value == null) {
293 Log.v(TAG, " delete " + op.key + ", updated total " + updatedSize);
294 }
295 }
296
297 // And add back the size of the value we're about to store, if any
298 if (op.value != null) {
299 updatedSize += op.value.length;
300 if (DEBUG) {
301 Log.v(TAG, ((curSize == null) ? " new " : " replace ")
302 + op.key + ", updated total " + updatedSize);
303 }
304 }
305 }
306
307 // If our final size is over quota, report the failure
308 if (updatedSize > KEY_VALUE_BACKUP_SIZE_QUOTA) {
309 if (DEBUG) {
310 Log.i(TAG, "New datastore size " + updatedSize
311 + " exceeds quota " + KEY_VALUE_BACKUP_SIZE_QUOTA);
312 }
313 return TRANSPORT_QUOTA_EXCEEDED;
314 }
315
316 // No problem with storage size, so go ahead and apply the delta operations
317 // (in the order that the app provided them)
318 for (KVOperation op : changeOps) {
319 File element = new File(packageDir, op.key);
320
321 // this is either a deletion or a rewrite-from-zero, so we can just remove
322 // the existing file and proceed in either case.
323 element.delete();
324
325 // if this wasn't a deletion, put the new data in place
326 if (op.value != null) {
327 try (FileOutputStream out = new FileOutputStream(element)) {
328 out.write(op.value, 0, op.value.length);
329 } catch (IOException e) {
330 Log.e(TAG, "Unable to update key file " + element);
331 return TRANSPORT_ERROR;
332 }
333 }
334 }
335 return TRANSPORT_OK;
336 }
337
338 // Parses a backup stream into individual key/value operations
339 private ArrayList<KVOperation> parseBackupStream(ParcelFileDescriptor data)
340 throws IOException {
341 ArrayList<KVOperation> changeOps = new ArrayList<>();
342 BackupDataInput changeSet = new BackupDataInput(data.getFileDescriptor());
343 while (changeSet.readNextHeader()) {
344 String key = changeSet.getKey();
Bernardo Rufino7a6e0322018-07-17 10:17:43 +0100345 String base64Key = new String(Base64.encode(key.getBytes(), Base64.NO_WRAP));
Christopher Tatec8a9d422017-06-23 12:48:26 -0700346 int dataSize = changeSet.getDataSize();
347 if (DEBUG) {
348 Log.v(TAG, " Delta operation key " + key + " size " + dataSize
349 + " key64 " + base64Key);
350 }
351
352 byte[] buf = (dataSize >= 0) ? new byte[dataSize] : null;
353 if (dataSize >= 0) {
354 changeSet.readEntityData(buf, 0, dataSize);
355 }
356 changeOps.add(new KVOperation(base64Key, buf));
357 }
358 return changeOps;
359 }
360
361 // Reads the given datastore directory, building a table of the value size of each
362 // keyed element, and returning the summed total.
363 private int parseKeySizes(File packageDir, ArrayMap<String, Integer> datastore) {
364 int totalSize = 0;
365 final String[] elements = packageDir.list();
366 if (elements != null) {
367 if (DEBUG) {
368 Log.v(TAG, "Existing datastore contents:");
369 }
370 for (String file : elements) {
371 File element = new File(packageDir, file);
372 String key = file; // filename
373 int size = (int) element.length();
374 totalSize += size;
375 if (DEBUG) {
376 Log.v(TAG, " key " + key + " size " + size);
377 }
378 datastore.put(key, size);
379 }
380 if (DEBUG) {
381 Log.v(TAG, " TOTAL: " + totalSize);
382 }
383 } else {
384 if (DEBUG) {
385 Log.v(TAG, "No existing data for this package");
386 }
387 }
388 return totalSize;
Dan Egnorefe52642009-06-24 00:16:33 -0700389 }
Christopher Tate9bbc21a2009-06-10 20:23:25 -0700390
Christopher Tate25a747f2009-09-20 12:43:58 -0700391 // Deletes the contents but not the given directory
392 private void deleteContents(File dirname) {
393 File[] contents = dirname.listFiles();
394 if (contents != null) {
395 for (File f : contents) {
396 if (f.isDirectory()) {
397 // delete the directory's contents then fall through
398 // and delete the directory itself.
399 deleteContents(f);
400 }
401 f.delete();
402 }
403 }
404 }
405
Christopher Tate5a009f92014-06-19 14:53:18 -0700406 @Override
Dan Egnor01445162009-09-21 17:04:05 -0700407 public int clearBackupData(PackageInfo packageInfo) {
Christopher Tateee0e78a2009-07-02 11:17:03 -0700408 if (DEBUG) Log.v(TAG, "clearBackupData() pkg=" + packageInfo.packageName);
409
Christopher Tate9ff53a72014-06-03 17:20:07 -0700410 File packageDir = new File(mCurrentSetIncrementalDir, packageInfo.packageName);
Christopher Tate0abf6a02012-03-23 17:45:15 -0700411 final File[] fileset = packageDir.listFiles();
412 if (fileset != null) {
413 for (File f : fileset) {
414 f.delete();
415 }
416 packageDir.delete();
Christopher Tateee0e78a2009-07-02 11:17:03 -0700417 }
Christopher Tate9ff53a72014-06-03 17:20:07 -0700418
419 packageDir = new File(mCurrentSetFullDir, packageInfo.packageName);
420 final File[] tarballs = packageDir.listFiles();
421 if (tarballs != null) {
422 for (File f : tarballs) {
423 f.delete();
424 }
425 packageDir.delete();
426 }
427
Christopher Tate5a009f92014-06-19 14:53:18 -0700428 return TRANSPORT_OK;
Christopher Tateee0e78a2009-07-02 11:17:03 -0700429 }
430
Christopher Tate5a009f92014-06-19 14:53:18 -0700431 @Override
Dan Egnor01445162009-09-21 17:04:05 -0700432 public int finishBackup() {
Christopher Tatee0792642014-08-07 14:19:50 -0700433 if (DEBUG) Log.v(TAG, "finishBackup() of " + mFullTargetPackage);
434 return tearDownFullBackup();
435 }
436
437 // ------------------------------------------------------------------------------------
438 // Full backup handling
439
440 private int tearDownFullBackup() {
Christopher Tate9ff53a72014-06-03 17:20:07 -0700441 if (mSocket != null) {
Christopher Tate9ff53a72014-06-03 17:20:07 -0700442 try {
Christopher Tate9310e422015-04-10 11:17:14 -0700443 if (mFullBackupOutputStream != null) {
444 mFullBackupOutputStream.flush();
445 mFullBackupOutputStream.close();
446 }
Christopher Tate9ff53a72014-06-03 17:20:07 -0700447 mSocketInputStream = null;
448 mFullTargetPackage = null;
449 mSocket.close();
450 } catch (IOException e) {
Christopher Tate89101f72014-07-17 19:09:00 -0700451 if (DEBUG) {
Christopher Tatee0792642014-08-07 14:19:50 -0700452 Log.w(TAG, "Exception caught in tearDownFullBackup()", e);
Christopher Tate89101f72014-07-17 19:09:00 -0700453 }
Christopher Tate5a009f92014-06-19 14:53:18 -0700454 return TRANSPORT_ERROR;
Christopher Tate9ff53a72014-06-03 17:20:07 -0700455 } finally {
456 mSocket = null;
Christopher Tate9310e422015-04-10 11:17:14 -0700457 mFullBackupOutputStream = null;
Christopher Tate9ff53a72014-06-03 17:20:07 -0700458 }
459 }
Christopher Tate5a009f92014-06-19 14:53:18 -0700460 return TRANSPORT_OK;
Christopher Tate9bbc21a2009-06-10 20:23:25 -0700461 }
462
Christopher Tatee0792642014-08-07 14:19:50 -0700463 private File tarballFile(String pkgName) {
464 return new File(mCurrentSetFullDir, pkgName);
465 }
Christopher Tate5a009f92014-06-19 14:53:18 -0700466
467 @Override
Christopher Tate9ff53a72014-06-03 17:20:07 -0700468 public long requestFullBackupTime() {
469 return 0;
470 }
471
Christopher Tate5a009f92014-06-19 14:53:18 -0700472 @Override
Christopher Tate9310e422015-04-10 11:17:14 -0700473 public int checkFullBackupSize(long size) {
Sergey Poromov872d3b62016-01-12 15:48:08 +0100474 int result = TRANSPORT_OK;
Christopher Tate9310e422015-04-10 11:17:14 -0700475 // Decline zero-size "backups"
Sergey Poromov872d3b62016-01-12 15:48:08 +0100476 if (size <= 0) {
477 result = TRANSPORT_PACKAGE_REJECTED;
478 } else if (size > FULL_BACKUP_SIZE_QUOTA) {
479 result = TRANSPORT_QUOTA_EXCEEDED;
480 }
Christopher Tate9310e422015-04-10 11:17:14 -0700481 if (result != TRANSPORT_OK) {
482 if (DEBUG) {
483 Log.v(TAG, "Declining backup of size " + size);
484 }
485 }
486 return result;
487 }
488
489 @Override
Christopher Tate9ff53a72014-06-03 17:20:07 -0700490 public int performFullBackup(PackageInfo targetPackage, ParcelFileDescriptor socket) {
491 if (mSocket != null) {
492 Log.e(TAG, "Attempt to initiate full backup while one is in progress");
Christopher Tate5a009f92014-06-19 14:53:18 -0700493 return TRANSPORT_ERROR;
Christopher Tate9ff53a72014-06-03 17:20:07 -0700494 }
495
496 if (DEBUG) {
497 Log.i(TAG, "performFullBackup : " + targetPackage);
498 }
499
500 // We know a priori that we run in the system process, so we need to make
501 // sure to dup() our own copy of the socket fd. Transports which run in
502 // their own processes must not do this.
503 try {
Sergey Poromov872d3b62016-01-12 15:48:08 +0100504 mFullBackupSize = 0;
Christopher Tate9ff53a72014-06-03 17:20:07 -0700505 mSocket = ParcelFileDescriptor.dup(socket.getFileDescriptor());
506 mSocketInputStream = new FileInputStream(mSocket.getFileDescriptor());
507 } catch (IOException e) {
508 Log.e(TAG, "Unable to process socket for full backup");
Christopher Tate5a009f92014-06-19 14:53:18 -0700509 return TRANSPORT_ERROR;
Christopher Tate9ff53a72014-06-03 17:20:07 -0700510 }
511
512 mFullTargetPackage = targetPackage.packageName;
Christopher Tate9ff53a72014-06-03 17:20:07 -0700513 mFullBackupBuffer = new byte[4096];
514
Christopher Tate5a009f92014-06-19 14:53:18 -0700515 return TRANSPORT_OK;
Christopher Tate9ff53a72014-06-03 17:20:07 -0700516 }
517
Christopher Tate5a009f92014-06-19 14:53:18 -0700518 @Override
Christopher Tate9310e422015-04-10 11:17:14 -0700519 public int sendBackupData(final int numBytes) {
520 if (mSocket == null) {
Christopher Tate9ff53a72014-06-03 17:20:07 -0700521 Log.w(TAG, "Attempted sendBackupData before performFullBackup");
Christopher Tate5a009f92014-06-19 14:53:18 -0700522 return TRANSPORT_ERROR;
Christopher Tate9ff53a72014-06-03 17:20:07 -0700523 }
524
Sergey Poromov872d3b62016-01-12 15:48:08 +0100525 mFullBackupSize += numBytes;
526 if (mFullBackupSize > FULL_BACKUP_SIZE_QUOTA) {
527 return TRANSPORT_QUOTA_EXCEEDED;
528 }
529
Christopher Tate9ff53a72014-06-03 17:20:07 -0700530 if (numBytes > mFullBackupBuffer.length) {
531 mFullBackupBuffer = new byte[numBytes];
532 }
Christopher Tate9310e422015-04-10 11:17:14 -0700533
534 if (mFullBackupOutputStream == null) {
535 FileOutputStream tarstream;
Christopher Tate9ff53a72014-06-03 17:20:07 -0700536 try {
Christopher Tate9310e422015-04-10 11:17:14 -0700537 File tarball = tarballFile(mFullTargetPackage);
538 tarstream = new FileOutputStream(tarball);
539 } catch (FileNotFoundException e) {
540 return TRANSPORT_ERROR;
541 }
542 mFullBackupOutputStream = new BufferedOutputStream(tarstream);
543 }
544
545 int bytesLeft = numBytes;
546 while (bytesLeft > 0) {
547 try {
548 int nRead = mSocketInputStream.read(mFullBackupBuffer, 0, bytesLeft);
Christopher Tate9ff53a72014-06-03 17:20:07 -0700549 if (nRead < 0) {
550 // Something went wrong if we expect data but saw EOD
551 Log.w(TAG, "Unexpected EOD; failing backup");
Christopher Tate5a009f92014-06-19 14:53:18 -0700552 return TRANSPORT_ERROR;
Christopher Tate9ff53a72014-06-03 17:20:07 -0700553 }
554 mFullBackupOutputStream.write(mFullBackupBuffer, 0, nRead);
Christopher Tate9310e422015-04-10 11:17:14 -0700555 bytesLeft -= nRead;
Christopher Tate9ff53a72014-06-03 17:20:07 -0700556 } catch (IOException e) {
557 Log.e(TAG, "Error handling backup data for " + mFullTargetPackage);
Christopher Tate5a009f92014-06-19 14:53:18 -0700558 return TRANSPORT_ERROR;
Christopher Tate9ff53a72014-06-03 17:20:07 -0700559 }
560 }
Christopher Tate77a2d78d2015-03-03 16:19:44 -0800561 if (DEBUG) {
562 Log.v(TAG, " stored " + numBytes + " of data");
563 }
Christopher Tate5a009f92014-06-19 14:53:18 -0700564 return TRANSPORT_OK;
Christopher Tate9ff53a72014-06-03 17:20:07 -0700565 }
566
Christopher Tatee0792642014-08-07 14:19:50 -0700567 // For now we can't roll back, so just tear everything down.
568 @Override
569 public void cancelFullBackup() {
570 if (DEBUG) {
571 Log.i(TAG, "Canceling full backup of " + mFullTargetPackage);
572 }
573 File archive = tarballFile(mFullTargetPackage);
574 tearDownFullBackup();
575 if (archive.exists()) {
576 archive.delete();
577 }
578 }
579
Christopher Tate9ff53a72014-06-03 17:20:07 -0700580 // ------------------------------------------------------------------------------------
Christopher Tate9bbc21a2009-06-10 20:23:25 -0700581 // Restore handling
Christopher Tate51fea572014-06-23 17:01:06 -0700582 static final long[] POSSIBLE_SETS = { 2, 3, 4, 5, 6, 7, 8, 9 };
Christopher Tate5a009f92014-06-19 14:53:18 -0700583
584 @Override
Christopher Tate74318c92014-05-15 19:03:44 -0700585 public RestoreSet[] getAvailableRestoreSets() {
Christopher Tateadfe8b82014-02-04 16:23:32 -0800586 long[] existing = new long[POSSIBLE_SETS.length + 1];
587 int num = 0;
588
Christopher Tate9ff53a72014-06-03 17:20:07 -0700589 // see which possible non-current sets exist...
Christopher Tateadfe8b82014-02-04 16:23:32 -0800590 for (long token : POSSIBLE_SETS) {
591 if ((new File(mDataDir, Long.toString(token))).exists()) {
592 existing[num++] = token;
593 }
594 }
Christopher Tate9ff53a72014-06-03 17:20:07 -0700595 // ...and always the currently-active set last
Christopher Tateadfe8b82014-02-04 16:23:32 -0800596 existing[num++] = CURRENT_SET_TOKEN;
597
598 RestoreSet[] available = new RestoreSet[num];
599 for (int i = 0; i < available.length; i++) {
600 available[i] = new RestoreSet("Local disk image", "flash", existing[i]);
601 }
602 return available;
Christopher Tate9bbc21a2009-06-10 20:23:25 -0700603 }
604
Christopher Tate5a009f92014-06-19 14:53:18 -0700605 @Override
Christopher Tate50c6df02010-01-29 12:48:20 -0800606 public long getCurrentRestoreSet() {
Christopher Tateadfe8b82014-02-04 16:23:32 -0800607 // The current restore set always has the same token
608 return CURRENT_SET_TOKEN;
Christopher Tate50c6df02010-01-29 12:48:20 -0800609 }
610
Christopher Tate5a009f92014-06-19 14:53:18 -0700611 @Override
Dan Egnor01445162009-09-21 17:04:05 -0700612 public int startRestore(long token, PackageInfo[] packages) {
Christopher Tate51fea572014-06-23 17:01:06 -0700613 if (DEBUG) Log.v(TAG, "start restore " + token + " : " + packages.length
614 + " matching packages");
Dan Egnorefe52642009-06-24 00:16:33 -0700615 mRestorePackages = packages;
616 mRestorePackage = -1;
Christopher Tate6a49dd02014-06-16 18:49:25 -0700617 mRestoreSetDir = new File(mDataDir, Long.toString(token));
618 mRestoreSetIncrementalDir = new File(mRestoreSetDir, INCREMENTAL_DIR);
619 mRestoreSetFullDir = new File(mRestoreSetDir, FULL_DATA_DIR);
Christopher Tate5a009f92014-06-19 14:53:18 -0700620 return TRANSPORT_OK;
Christopher Tate9bbc21a2009-06-10 20:23:25 -0700621 }
622
Christopher Tate6a49dd02014-06-16 18:49:25 -0700623 @Override
624 public RestoreDescription nextRestorePackage() {
Christopher Tate77a2d78d2015-03-03 16:19:44 -0800625 if (DEBUG) {
626 Log.v(TAG, "nextRestorePackage() : mRestorePackage=" + mRestorePackage
627 + " length=" + mRestorePackages.length);
628 }
Dan Egnorefe52642009-06-24 00:16:33 -0700629 if (mRestorePackages == null) throw new IllegalStateException("startRestore not called");
Christopher Tate6a49dd02014-06-16 18:49:25 -0700630
631 boolean found = false;
Dan Egnorefe52642009-06-24 00:16:33 -0700632 while (++mRestorePackage < mRestorePackages.length) {
633 String name = mRestorePackages[mRestorePackage].packageName;
Christopher Tate6a49dd02014-06-16 18:49:25 -0700634
635 // If we have key/value data for this package, deliver that
Christopher Tatea9b91862014-02-25 17:42:21 -0800636 // skip packages where we have a data dir but no actual contents
Christopher Tate6a49dd02014-06-16 18:49:25 -0700637 String[] contents = (new File(mRestoreSetIncrementalDir, name)).list();
Christopher Tatea9b91862014-02-25 17:42:21 -0800638 if (contents != null && contents.length > 0) {
Christopher Tate77a2d78d2015-03-03 16:19:44 -0800639 if (DEBUG) {
640 Log.v(TAG, " nextRestorePackage(TYPE_KEY_VALUE) @ "
641 + mRestorePackage + " = " + name);
642 }
Christopher Tate6a49dd02014-06-16 18:49:25 -0700643 mRestoreType = RestoreDescription.TYPE_KEY_VALUE;
644 found = true;
645 }
646
647 if (!found) {
648 // No key/value data; check for [non-empty] full data
649 File maybeFullData = new File(mRestoreSetFullDir, name);
650 if (maybeFullData.length() > 0) {
Christopher Tate77a2d78d2015-03-03 16:19:44 -0800651 if (DEBUG) {
652 Log.v(TAG, " nextRestorePackage(TYPE_FULL_STREAM) @ "
653 + mRestorePackage + " = " + name);
654 }
Christopher Tate6a49dd02014-06-16 18:49:25 -0700655 mRestoreType = RestoreDescription.TYPE_FULL_STREAM;
Christopher Tate5a009f92014-06-19 14:53:18 -0700656 mCurFullRestoreStream = null; // ensure starting from the ground state
Christopher Tate6a49dd02014-06-16 18:49:25 -0700657 found = true;
658 }
659 }
660
661 if (found) {
662 return new RestoreDescription(name, mRestoreType);
Dan Egnorefe52642009-06-24 00:16:33 -0700663 }
Christopher Tate77a2d78d2015-03-03 16:19:44 -0800664
665 if (DEBUG) {
666 Log.v(TAG, " ... package @ " + mRestorePackage + " = " + name
667 + " has no data; skipping");
668 }
Dan Egnorefe52642009-06-24 00:16:33 -0700669 }
Christopher Tate9bbc21a2009-06-10 20:23:25 -0700670
Dan Egnorefe52642009-06-24 00:16:33 -0700671 if (DEBUG) Log.v(TAG, " no more packages to restore");
Christopher Tate6a49dd02014-06-16 18:49:25 -0700672 return RestoreDescription.NO_MORE_PACKAGES;
Dan Egnorefe52642009-06-24 00:16:33 -0700673 }
674
Christopher Tate5a009f92014-06-19 14:53:18 -0700675 @Override
Dan Egnor01445162009-09-21 17:04:05 -0700676 public int getRestoreData(ParcelFileDescriptor outFd) {
Dan Egnorefe52642009-06-24 00:16:33 -0700677 if (mRestorePackages == null) throw new IllegalStateException("startRestore not called");
678 if (mRestorePackage < 0) throw new IllegalStateException("nextRestorePackage not called");
Christopher Tate6a49dd02014-06-16 18:49:25 -0700679 if (mRestoreType != RestoreDescription.TYPE_KEY_VALUE) {
680 throw new IllegalStateException("getRestoreData(fd) for non-key/value dataset");
681 }
Christopher Tate51fea572014-06-23 17:01:06 -0700682 File packageDir = new File(mRestoreSetIncrementalDir,
683 mRestorePackages[mRestorePackage].packageName);
Christopher Tate9bbc21a2009-06-10 20:23:25 -0700684
Christopher Tate2fdd4282009-06-12 15:20:04 -0700685 // The restore set is the concatenation of the individual record blobs,
Christopher Tateadfe8b82014-02-04 16:23:32 -0800686 // each of which is a file in the package's directory. We return the
687 // data in lexical order sorted by key, so that apps which use synthetic
688 // keys like BLOB_1, BLOB_2, etc will see the date in the most obvious
689 // order.
690 ArrayList<DecodedFilename> blobs = contentsByKey(packageDir);
Dan Egnor01445162009-09-21 17:04:05 -0700691 if (blobs == null) { // nextRestorePackage() ensures the dir exists, so this is an error
Christopher Tateadfe8b82014-02-04 16:23:32 -0800692 Log.e(TAG, "No keys for package: " + packageDir);
Christopher Tate5a009f92014-06-19 14:53:18 -0700693 return TRANSPORT_ERROR;
Christopher Tate2fdd4282009-06-12 15:20:04 -0700694 }
Dan Egnorefe52642009-06-24 00:16:33 -0700695
696 // We expect at least some data if the directory exists in the first place
Christopher Tateadfe8b82014-02-04 16:23:32 -0800697 if (DEBUG) Log.v(TAG, " getRestoreData() found " + blobs.size() + " key files");
Dan Egnorefe52642009-06-24 00:16:33 -0700698 BackupDataOutput out = new BackupDataOutput(outFd.getFileDescriptor());
699 try {
Christopher Tateadfe8b82014-02-04 16:23:32 -0800700 for (DecodedFilename keyEntry : blobs) {
701 File f = keyEntry.file;
Dan Egnorefe52642009-06-24 00:16:33 -0700702 FileInputStream in = new FileInputStream(f);
703 try {
704 int size = (int) f.length();
705 byte[] buf = new byte[size];
706 in.read(buf);
Christopher Tateadfe8b82014-02-04 16:23:32 -0800707 if (DEBUG) Log.v(TAG, " ... key=" + keyEntry.key + " size=" + size);
708 out.writeEntityHeader(keyEntry.key, size);
Dan Egnorefe52642009-06-24 00:16:33 -0700709 out.writeEntityData(buf, size);
710 } finally {
711 in.close();
712 }
713 }
Christopher Tate5a009f92014-06-19 14:53:18 -0700714 return TRANSPORT_OK;
Dan Egnorefe52642009-06-24 00:16:33 -0700715 } catch (IOException e) {
716 Log.e(TAG, "Unable to read backup records", e);
Christopher Tate5a009f92014-06-19 14:53:18 -0700717 return TRANSPORT_ERROR;
Dan Egnorefe52642009-06-24 00:16:33 -0700718 }
Christopher Tate9bbc21a2009-06-10 20:23:25 -0700719 }
Christopher Tate3a31a932009-06-22 15:10:30 -0700720
Christopher Tateadfe8b82014-02-04 16:23:32 -0800721 static class DecodedFilename implements Comparable<DecodedFilename> {
722 public File file;
723 public String key;
724
725 public DecodedFilename(File f) {
726 file = f;
Bernardo Rufino7a6e0322018-07-17 10:17:43 +0100727 key = new String(Base64.decode(f.getName(), Base64.DEFAULT));
Christopher Tateadfe8b82014-02-04 16:23:32 -0800728 }
729
730 @Override
731 public int compareTo(DecodedFilename other) {
732 // sorts into ascending lexical order by decoded key
733 return key.compareTo(other.key);
734 }
735 }
736
737 // Return a list of the files in the given directory, sorted lexically by
738 // the Base64-decoded file name, not by the on-disk filename
739 private ArrayList<DecodedFilename> contentsByKey(File dir) {
740 File[] allFiles = dir.listFiles();
741 if (allFiles == null || allFiles.length == 0) {
742 return null;
743 }
744
745 // Decode the filenames into keys then sort lexically by key
746 ArrayList<DecodedFilename> contents = new ArrayList<DecodedFilename>();
747 for (File f : allFiles) {
748 contents.add(new DecodedFilename(f));
749 }
750 Collections.sort(contents);
751 return contents;
752 }
753
Christopher Tate5a009f92014-06-19 14:53:18 -0700754 @Override
Dan Egnorefe52642009-06-24 00:16:33 -0700755 public void finishRestore() {
756 if (DEBUG) Log.v(TAG, "finishRestore()");
Christopher Tate5a009f92014-06-19 14:53:18 -0700757 if (mRestoreType == RestoreDescription.TYPE_FULL_STREAM) {
758 resetFullRestoreState();
759 }
760 mRestoreType = 0;
Christopher Tate3a31a932009-06-22 15:10:30 -0700761 }
Christopher Tate9ff53a72014-06-03 17:20:07 -0700762
763 // ------------------------------------------------------------------------------------
764 // Full restore handling
765
Christopher Tate5a009f92014-06-19 14:53:18 -0700766 private void resetFullRestoreState() {
Christopher Tate824392b2014-11-14 18:27:36 -0800767 IoUtils.closeQuietly(mCurFullRestoreStream);
Christopher Tate5a009f92014-06-19 14:53:18 -0700768 mCurFullRestoreStream = null;
Christopher Tate5a009f92014-06-19 14:53:18 -0700769 mFullRestoreBuffer = null;
Christopher Tate9ff53a72014-06-03 17:20:07 -0700770 }
771
772 /**
773 * Ask the transport to provide data for the "current" package being restored. The
774 * transport then writes some data to the socket supplied to this call, and returns
775 * the number of bytes written. The system will then read that many bytes and
776 * stream them to the application's agent for restore, then will call this method again
777 * to receive the next chunk of the archive. This sequence will be repeated until the
778 * transport returns zero indicating that all of the package's data has been delivered
779 * (or returns a negative value indicating some sort of hard error condition at the
780 * transport level).
781 *
782 * <p>After this method returns zero, the system will then call
783 * {@link #getNextFullRestorePackage()} to begin the restore process for the next
784 * application, and the sequence begins again.
785 *
786 * @param socket The file descriptor that the transport will use for delivering the
787 * streamed archive.
788 * @return 0 when no more data for the current package is available. A positive value
789 * indicates the presence of that much data to be delivered to the app. A negative
790 * return value is treated as equivalent to {@link BackupTransport#TRANSPORT_ERROR},
791 * indicating a fatal error condition that precludes further restore operations
792 * on the current dataset.
793 */
Christopher Tate5a009f92014-06-19 14:53:18 -0700794 @Override
Christopher Tate9ff53a72014-06-03 17:20:07 -0700795 public int getNextFullRestoreDataChunk(ParcelFileDescriptor socket) {
Christopher Tate5a009f92014-06-19 14:53:18 -0700796 if (mRestoreType != RestoreDescription.TYPE_FULL_STREAM) {
797 throw new IllegalStateException("Asked for full restore data for non-stream package");
798 }
799
800 // first chunk?
801 if (mCurFullRestoreStream == null) {
802 final String name = mRestorePackages[mRestorePackage].packageName;
803 if (DEBUG) Log.i(TAG, "Starting full restore of " + name);
804 File dataset = new File(mRestoreSetFullDir, name);
805 try {
806 mCurFullRestoreStream = new FileInputStream(dataset);
807 } catch (IOException e) {
808 // If we can't open the target package's tarball, we return the single-package
809 // error code and let the caller go on to the next package.
810 Log.e(TAG, "Unable to read archive for " + name);
811 return TRANSPORT_PACKAGE_REJECTED;
812 }
Christopher Tate89101f72014-07-17 19:09:00 -0700813 mFullRestoreBuffer = new byte[2*1024];
Christopher Tate5a009f92014-06-19 14:53:18 -0700814 }
815
Stefanot07564fa2018-10-04 16:16:30 +0100816 FileOutputStream stream = new FileOutputStream(socket.getFileDescriptor());
817
Christopher Tate5a009f92014-06-19 14:53:18 -0700818 int nRead;
819 try {
820 nRead = mCurFullRestoreStream.read(mFullRestoreBuffer);
821 if (nRead < 0) {
822 // EOF: tell the caller we're done
823 nRead = NO_MORE_DATA;
824 } else if (nRead == 0) {
825 // This shouldn't happen when reading a FileInputStream; we should always
826 // get either a positive nonzero byte count or -1. Log the situation and
827 // treat it as EOF.
828 Log.w(TAG, "read() of archive file returned 0; treating as EOF");
829 nRead = NO_MORE_DATA;
830 } else {
831 if (DEBUG) {
832 Log.i(TAG, " delivering restore chunk: " + nRead);
833 }
Stefanot07564fa2018-10-04 16:16:30 +0100834 stream.write(mFullRestoreBuffer, 0, nRead);
Christopher Tate5a009f92014-06-19 14:53:18 -0700835 }
836 } catch (IOException e) {
837 return TRANSPORT_ERROR; // Hard error accessing the file; shouldn't happen
838 } finally {
Stefanot07564fa2018-10-04 16:16:30 +0100839 IoUtils.closeQuietly(socket);
Christopher Tate5a009f92014-06-19 14:53:18 -0700840 }
841
842 return nRead;
Christopher Tate9ff53a72014-06-03 17:20:07 -0700843 }
Christopher Tate5a009f92014-06-19 14:53:18 -0700844
845 /**
846 * If the OS encounters an error while processing {@link RestoreDescription#TYPE_FULL_STREAM}
847 * data for restore, it will invoke this method to tell the transport that it should
848 * abandon the data download for the current package. The OS will then either call
849 * {@link #nextRestorePackage()} again to move on to restoring the next package in the
850 * set being iterated over, or will call {@link #finishRestore()} to shut down the restore
851 * operation.
852 *
853 * @return {@link #TRANSPORT_OK} if the transport was successful in shutting down the
854 * current stream cleanly, or {@link #TRANSPORT_ERROR} to indicate a serious
855 * transport-level failure. If the transport reports an error here, the entire restore
856 * operation will immediately be finished with no further attempts to restore app data.
857 */
858 @Override
859 public int abortFullRestore() {
860 if (mRestoreType != RestoreDescription.TYPE_FULL_STREAM) {
861 throw new IllegalStateException("abortFullRestore() but not currently restoring");
862 }
863 resetFullRestoreState();
864 mRestoreType = 0;
865 return TRANSPORT_OK;
866 }
867
Sergey Poromov872d3b62016-01-12 15:48:08 +0100868 @Override
869 public long getBackupQuota(String packageName, boolean isFullBackup) {
Shreyas Basargeb6e73c92017-01-31 20:13:43 +0000870 return isFullBackup ? FULL_BACKUP_SIZE_QUOTA : KEY_VALUE_BACKUP_SIZE_QUOTA;
Sergey Poromov872d3b62016-01-12 15:48:08 +0100871 }
Christopher Tate9bbc21a2009-06-10 20:23:25 -0700872}