309 Commits

Author SHA1 Message Date
Christopher Tate
924afe2b0f Add 'bmgr' command to synchronously init transports
bmgr init TRANSPORT [...]

will run an init operation on each named transport, blocking
until the operations have all completed.

Bug 62253989
Test: manual

Change-Id: I7dbd94293738d5ecf195764f5b28905253819791
2017-06-20 13:28:56 -07:00
Christopher Tate
1a30fcd995 Fix #62798589 : requestBackup() needs to check enable/provisioned state
Also tweaked the logging to make sure to capture "not provisioned"
whenever it's the case.

Test: manual
Change-Id: Iee909b8336af776bad0fa46f036d6cf32ef9c3e7
2017-06-20 11:18:06 -07:00
Bryan Mawhinney
4fee93109a Start agent in correct mode for adb k/v restore
Previously we always started the agent in "dolly" mode, which meant that
the application context might not be what the agent was expecting.

Bug: 62524964
Test: Manual
Change-Id: I6cd2fafcac97f7ca01a6e172325968d79cc01194
2017-06-16 14:45:41 +01:00
Christopher Tate
fe2368c38c Refresh in-memory SharedPreferences instances after restore
Existing instances don't know that the file has changed out from
under them, so they continue to return stale values from reads, and
risk overwriting restored data with stale content if writes are
performed.  We now tell the backing cache system to induce a
reload after restore (i.e. after we might have written a relevant
file out from under it).

Along the way we shook out an irregularity in the way we were
setting up the context topology of non-lifecycle instances of
the metadata-handling BackupAgent subclass, so that's fixed
now too.

Bug 12061817
Test: cts-tradefed run cts -m CtsBackupHostTestCases

Change-Id: I401fe9297235b55d8a8f041e430d122dc6e24129
2017-05-30 12:41:39 -07:00
Artem Iglikov
21942e0aba Add tests for routeSocketDataToOutput.
Also fixes the problem where it could through IndexOutOfBoundsException
instead of more natuarl EOFExcpetion in case there is not enough data in
the chunk.

Bug: 38081946
Bug: 37983441
Test: runtest -p com.android.server.backup frameworks-services
Change-Id: Icac575a76b752922b9c2d9cc0b3cad50f4273241
2017-05-17 15:11:49 +01:00
Christopher Tate
c876ebe70b Merge "Do not perform backup/restore of instant apps" into oc-dev am: 1835f076b3
am: 8686e2219b

Change-Id: Ic9116dd9134b0b03e4eaa60c21cf00454ac36ba5
2017-05-13 00:01:02 +00:00
Christopher Tate
6c5631ee7c Do not perform backup/restore of instant apps
This keeps the install flow fast, and also happens to mean that
there is feature parity in this regard between pre-O and O+
instant app handling.

Fix #38263351
Test: manual

Change-Id: I8eb08c12d800f5288583e792621920c9876efdfc
2017-05-12 13:58:20 -07:00
Fyodor Kupolov
cc8e7c3e67 Merge "Use buffered DataInputStream vs RandomAccessFile" into oc-dev am: b4a032fd02
am: 8a98e746ef

Change-Id: I93b9a3909dc385f29efc4b4447d3fa90b948fc1b
2017-05-11 09:05:24 +00:00
Fyodor Kupolov
98b8d31add Use buffered DataInputStream vs RandomAccessFile
Switching to buffered streams saved up to 50% of
BackupManagerService.onUnlockUser time:

Before:
SystemServiceManager: Service com.android.server.backup.BackupManagerService$Lifecycle took 389 ms in onUnlockUser
SystemServiceManager: Service com.android.server.backup.BackupManagerService$Lifecycle took 380 ms in onUnlockUser
After:
SystemServiceManager: Service com.android.server.backup.BackupManagerService$Lifecycle took 178 ms in onUnlockUser
SystemServiceManager: Service com.android.server.backup.BackupManagerService$Lifecycle took 155 ms in onUnlockUser

Test: manual
Bug: 37686433
Change-Id: I41185a88e8377b434fab6a3bf1fd7086758127cd
2017-05-10 16:46:22 -07:00
Artem Iglikov
dbe6832480 Use static imports for constants.
This is an automated change with some manual formatting.

Bug: 36850431
Test: mmma frameworks/base
Change-Id: I126747e57ae1b666e5281b25d063d22d774b0718
2017-05-09 14:21:37 +01:00
Artem Iglikov
13fffd267c Add some tests for TarBackupReader
... and PerformAdbRestoreTask.

Involves some refactoring, splitting readAppManifest() into two methods.

Also a bit of cleanup: make private field actually private and use
static imports for some constants.

Bug: 38090803
Bug: 37619463
Test: runtest -p com.android.server.backup frameworks-services
Change-Id: Ic30a6c5a515da1efb67caaae6eb75f4313797d5c
2017-05-08 19:15:59 +01:00
TreeHugger Robot
b3f506aa5d Merge "Add null checking and exception handling in selectBackupTransportAsync" 2017-05-05 11:24:57 +00:00
Chris Tate
af31dffcb3 Merge "Correct scope of "disabled?" check viz backup/restore decisions" into oc-dev am: d239223cb0
am: 136f841c5c

Change-Id: Ibaf2939a7873ea017be0c71785ee02be8bcdd5ff
2017-05-05 01:27:53 +00:00
Chris Tate
d239223cb0 Merge "Correct scope of "disabled?" check viz backup/restore decisions" into oc-dev 2017-05-05 01:10:43 +00:00
Tony Mak
2dd109d238 Add null checking and exception handling in selectBackupTransportAsync
Bug: 37304539

Test: bit FrameworksServicesTests:com.android.server.backup.TrampolineTest

Change-Id: I01ffa25bfca6ca743220ee7277c2a6473c055bf1
2017-05-04 18:29:15 +01:00
Artem Iglikov
23c6007ccf Add more tests for AppBackupUtils.
Also enable other utils tests on presubmit.

Test: runtest -p com.android.server.backup frameworks-services
Bug: 37939902
Change-Id: I7f54a6a3d4dfe14f4802af1788a4d3afe01372f2
2017-05-04 12:26:47 +01:00
TreeHugger Robot
9dee975361 Merge "selectBackupTransportAsync should report failure when backup is not available" into oc-dev 2017-05-04 08:44:05 +00:00
Christopher Tate
5092dea7f5 Correct scope of "disabled?" check viz backup/restore decisions
*Really* don't back up or restore data for disabled apps.

Bug 37851910
Test: manual

Change-Id: I4b9bdcabb386789b03633d9d26775e54bf3c3d03
2017-05-03 13:52:33 -07:00
Chris Tate
b6c708a1d3 Merge "Don't mix "current dataset" tokens for different backup transports" into oc-dev am: 70a2316ec7
am: 362a819a46

Change-Id: Ica34b713dcb76de186221caf3ea158a5125903b9
2017-05-03 20:31:02 +00:00
Chris Tate
70a2316ec7 Merge "Don't mix "current dataset" tokens for different backup transports" into oc-dev 2017-05-03 20:15:54 +00:00
Tony Mak
60ef1ce025 selectBackupTransportAsync should report failure when backup is not available
Merged-in: I393308857ea6082dca167e3e417b946615a83c20
Fix: 37304539
Test: runtest -x frameworks/base/services/tests/servicestests/src/com/android/server/backup/TrampolineTest.java
Test: setup device owner, then set up profile.
      Ensure tapping Settings->Google->Work->Security -> Verify app
      is working

Change-Id: I88c3e3163605d62123c88377ae0843084e354212
2017-05-03 20:02:57 +00:00
TreeHugger Robot
13e8294638 Merge "Add unit tests for com.android.server.backup.utils" 2017-05-03 18:40:09 +00:00
Artem Iglikov
66ff1d62c0 Add unit tests for com.android.server.backup.utils
Also add missing javadocs to some new classes.

Bug: 37939902
Test: runtest -p com.android.server.backup frameworks-services
Change-Id: I7c24cec754af9ea6caee7791a11085b8c174c427
2017-05-03 16:36:21 +01:00
Johan Torås Halseth
3b03673d23 Increase timeout for ADB backup/restore of SharedStorage.
It previously used a backup timeout of 5 min, and restore timeout of 1
min, that would always timeout if the files on shared storage were big.
Now increase both to 60 minutes.

Bug: 37201952

Test: adb backup -shared && adb restore backup.ab

Merged-In: Ice6648554933baf76e96fd151b506564487c91c6

Change-Id: I99095249e960fd47fc742154bc513347bf506548
2017-05-03 12:36:52 +01:00
TreeHugger Robot
a91fa8b295 Merge "Increase timeout for ADB backup/restore of SharedStorage." 2017-05-03 11:22:38 +00:00
Artem Iglikov
6c2f7870bc Merge "Move message ids to BackupHandler." 2017-05-03 10:13:25 +00:00
Johan Torås Halseth
25c50f98e3 Increase timeout for ADB backup/restore of SharedStorage.
This is a manual merge of ag/2161962 into master.

Test: it compiles.

Change-Id: Ice6648554933baf76e96fd151b506564487c91c6
2017-05-03 10:44:23 +01:00
Artem Iglikov
c2a3d0fb3a Move message ids to BackupHandler.
Bug: 36850431
Test: it compiles
Change-Id: Ic4e63b0b3dd817ed89cd411b8fb52673e11b8cc3
2017-05-02 15:16:30 +01:00
Tony Mak
8b20b2c2ec selectBackupTransportAsync should report failure when backup is disabled
Fix: 37304539
Test: runtest -x frameworks/base/services/tests/servicestests/src/com/android/server/backup/TrampolineTest.java
Test: setup device owner, then set up profile.
      Ensure tapping Settings->Google->Work->Security -> Verify app
      is working

Change-Id: I393308857ea6082dca167e3e417b946615a83c20
2017-05-02 14:28:04 +01:00
Christopher Tate
2a2a817024 Don't mix "current dataset" tokens for different backup transports
Previously, one could poison the current-dataset tracking by
inopportunely-timed use of the local (aka development) transport.
Now you can't:  we reset the 'current dataset token?' tracking
whenever the user changes the active transport.

Also don't double-allocate return values sometimes.

Bug 37694618
Test: manual

Change-Id: I2cf5d42774522af830aecb99e65f43c4d0b5ce76
2017-05-01 16:59:16 -07:00
Artem Iglikov
0b54d6d929 Another round of code deduplication.
Moved more common classes and methods to utilities (automated).
Prepared for deduplication of restoreOneFile() method.

Bug: 37519282
Test: gts
Change-Id: Ibc3de8f7c6675f64c636aafe51a885cfbd162e3a
2017-04-28 15:46:49 +01:00
Artem Iglikov
b9d55570cb Fix missing read of widget data in adb restore.
This was done for FullRestoreEngine but not for PerformAdbRestoreTask by
mistake.

Bug: 37519282
Test: it compiles
Change-Id: I17be3f07d3eed9113c36bbb47db6146fa7e76d64
2017-04-27 09:40:38 +01:00
Artem Iglikov
1418d05ab3 Merge "Move more common methods to TarBackupReader." 2017-04-26 22:41:24 +00:00
Artem Iglikov
b3177dc9e5 Move more common methods to TarBackupReader.
This moves rest of common methods in FullRestoreEngine and
PerformAdbRestoreTask to TarBackupReader and FileMetadata.

Bug: 37519282
Test: gts
Change-Id: Iff1f95e87721e74c9c5764ab98c64026604eee9b
2017-04-26 14:14:11 +01:00
Michal Karpinski
14f57541b4 resolve merge conflicts of 970525ef3225 to master
Test: I solemnly swear I tested this conflict resolution.
Change-Id: Ia4860b81fbd1f45e6594197b1de75ff3531c4826
2017-04-26 11:55:02 +01:00
Michal Karpinski
b81243f523 Offload the mRunningFullBackupTask.handleCancel() call from the main
thread to another thread

The system_server process was being killed by Watchdog, as the main
thread was waiting for the mCancelLock for over a minute.

Bug: 35968123
Test: make gts -j40 && gts-tradefed run gts -m GtsGmscoreHostTestCases -t com.google.android.gts.backup.BackupManagerHostTest
Change-Id: Ia146569d2c741b35a6f6c9bfc4c5ddf8539b6242
2017-04-25 19:33:18 +01:00
Artem Iglikov
9c15a29bfd Move common tar reading parts to separate class.
This moves part of the common code for reading tar files from
PerformAdbRestoreTask and FullRestoreEngine to it's own class.

Change is mostly automated, but with some manual intervention which
doesn't change behaviour.

Bug: 37519282
Test: cts,gts,pts
Change-Id: I669b848e16196ae76fb9e820b786bbe248985e47
2017-04-25 17:15:11 +01:00
Anton Philippov
d4556b3a57 Merge "Merge "Call removeMessages() only for certain operations in BackupManagerService#handleCancel()" into oc-dev am: 5281775760" into oc-dev-plus-aosp
am: 254d2512d3

Change-Id: I76640f881b58c03b73fda80ff2536eb2a966d5ab
2017-04-24 20:24:01 +00:00
Johan Torås Halseth
81f6c9d1bf Merge "Add log before doRestoreFinished is called on BackupAgent." into oc-dev am: 8c7e6faa60
am: 20d7fd66cb

Change-Id: I0e586e507f91b8bd7c8b10022c502c3b4f620ea3
2017-04-24 19:56:38 +00:00
Artem Iglikov
603bcb7b88 Move password-related methods to their own class.
Automated change.

Bug: 37519282
Test: it compiles
Change-Id: I09b1fe2854c32abbeed953b83804bc8c976d9fdb
2017-04-24 16:45:21 +01:00
Artem Iglikov
2c2c856b3a Move public static methods to utility classes.
This is an automated change which moves all public static methods
from RefactoredBackupManagerService to respective utility classes.

Bug: 37519282
Test: it compiles.
Change-Id: I2f5765e430da3bd9a05e255dbd2656d5e667bf4d
2017-04-24 16:36:49 +01:00
TreeHugger Robot
5281775760 Merge "Call removeMessages() only for certain operations in BackupManagerService#handleCancel()" into oc-dev 2017-04-24 13:37:44 +00:00
Artem Iglikov
d6c00c7110 Encapsulate RefactoredBackupManagerService fields.
This encapsulates back the fields which were decapsulated when splitting
out internal classes.

Bug: 37520921
Test: adb shell settings put global backup_refactored_service_disabled 0
&& adb reboot && adb shell bmgr backupnow --all
Change-Id: I9caa75b2f688de96bd5b245f43e0ae66cd9d023c
2017-04-24 12:52:46 +01:00
Anton Philippov
b09a630d63 Call removeMessages() only for certain operations in BackupManagerService#handleCancel()
Only remove messages of types OP_TYPE_BACKUP_WAIT and OP_TYPE_RESTORE_WAIT, since OP_TYPE_BACKUP cannot time out and doesn't require cancellation.

This will prevent some unncecessary (false) warnings in logcat.

Bug: 36570881
Test: manual
Change-Id: I72ecf98438fff18616354b04638b7db5c943aa61
2017-04-24 12:22:56 +01:00
Johan Torås Halseth
ddb5278dcb Add log before doRestoreFinished is called on BackupAgent.
This is added because only logging before doRestore was previously
shown, which meant that if the doRestoreFinished timed out, it would
in the logs look like it was the doRestore timing out.

Test: adb shell bmgr restore com.android.calllogbackup

Bug: 36507762
Change-Id: I2bd6e59ed0c5b0128eaca41b627356d459000065
2017-04-21 18:06:47 +01:00
Artem Iglikov
e5263c62ee Add remaining tests for Trampoline.
Also a bit of refactoring on TrampolineTestable and enable it for
presubmits.

Bug: 37520021
Test: manually ran the unit test.
Change-Id: I20214b70d3eb35017d50983bd8bebef93b66e839
2017-04-21 15:13:27 +01:00
Artem Iglikov
e42c8416b0 [DO NOT MERGE] Fix potential NPE in Trampoline.requestBackup().
Before it was returning null in case the service was not initialized,
but as the method signature has int as the return type, this was boxed
and unboxed which would cause NPE.

Now it will return BackupManager.ERROR_BACKUP_NOT_ALLOWED instead.

This doesn't include fix for the test, because it's going to be
cherry-picked into oc-dev, which doesn't have the tests.

Test: manually ran unit tests

Bug: 37535747

Change-Id: I186cf812a4ec67be943b5c4334c82e9af5320b7a
2017-04-21 10:45:21 +00:00
Artem Iglikov
65090c6b47 Fix potential NPE in Trampoline.requestBackup().
Before it was returning null in case the service was not initialized,
but as the method signature has int as the return type, this was boxed
and unboxed which would cause NPE.

Now it will return BackupManager.ERROR_BACKUP_NOT_ALLOWED instead.

This doesn't include fix for the test, because it's going to be
cherry-picked into oc-dev, which doesn't have the tests.

Test: manually ran unit tests

Bug: 37535747

Change-Id: I186cf812a4ec67be943b5c4334c82e9af5320b7a
2017-04-21 09:53:49 +01:00
TreeHugger Robot
d4072d2ba7 Merge "Add unit test for Trampoline." 2017-04-20 22:15:35 +00:00
Artem Iglikov
6052ef563c Add unit test for Trampoline.
This adds the test to FrameworksServicesTests test suite, which can be
run with the following command:

make FrameworksServicesTests -j &&
adb install -r ${OUT}/data/app/FrameworksServicesTests/FrameworksServicesTests.apk &&
adb shell am instrument -w -e package com.android.server.backup \
com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner

Bug: 37520021

Test: manually ran the test

Change-Id: I3f0dc50b0eb2ff2bc9360c68714c27e82b820897
2017-04-20 21:43:16 +01:00