Commit Graph

239 Commits

Author SHA1 Message Date
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
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
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 970525ef32 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
Artem Iglikov
21510f0b75 Apply Android code style to RefactoredBackupManagerService.
Bug: 36850431

Test: it compiles.

Change-Id: I5f996e612c9117437c3ff14929afb529ee8e9a93
2017-04-18 15:27:09 +01:00
Artem Iglikov
ccbeef0378 Don't back up disabled apps.
This replicates ag/2116043 in RefactoredBackupManagerService.

Bug: 37150882

Test: manual

Change-Id: I83bec834b446f5855cd7ced0da24eb37e5880428
2017-04-18 14:49:08 +01:00
Chris Tate
b86d741f1f Merge "Don't back up disabled apps" into oc-dev am: 628690ea2b
am: 281def0704

Change-Id: Ibbb8403bdf68d6a55b67ee361b578e2aa767bb42
2017-04-17 17:52:21 +00:00
Christopher Tate
246a0e77fa Don't back up disabled apps
Bug 37150882
Test: manual

Change-Id: I9d8e34de880727325206f4d173a03f1fca4613a4
2017-04-14 18:08:23 -07:00
Artem Iglikov
f251e35098 Move inner classes of RefactoredBackupManagerService to their own files.
The move was done automatically separately for each class. For the
classes that are not static, instance of RBMS is passed in the
constructor.

To make this compilable all methods and fields of RBMS that are accessed
from the separated classes were made public. In later commits this will
be addressed.

Test: built, flashed, verified that bmgr backupnow works with RBMS
enabled.

Bug: 36850431

Change-Id: I2d9be8bb045d5c4d8106bc59630d3a278138b54f
2017-04-11 15:22:56 +01:00
TreeHugger Robot
9cd4c3671c Merge "Removed unused variables in PerformBackupTask#finalizeBackup()" 2017-04-07 15:07:15 +00:00
Michal Karpinski
3e6ecfeb68 Merge "Removed unused variables in PerformBackupTask#finalizeBackup()" into oc-dev am: ce7f931793
am: 5c71bdf14d

Change-Id: I6596a7438a967416753d96aa6807d87d78fb4a7b
2017-04-07 15:00:01 +00:00
Artem Iglikov
6358e5d1b5 Removed unused variables in PerformBackupTask#finalizeBackup()
The unused variables got left behind after changes in ag/1841867.

This replicates ag/2077691 in RefactoredBackupManagerService.

Bug: 35994670
Test: it builds
Change-Id: Ic28719dafb83542d7e4c73cb48508d6792d10174
2017-04-07 13:11:01 +01:00
Michal Karpinski
1ee80dd46c Removed unused variables in PerformBackupTask#finalizeBackup()
The unused variables got left behind after changes in ag/1841867.

Bug: 35994670
Test: it builds
Change-Id: Ic28719dafb83542d7e4c73cb48508d6792d10174
2017-04-07 11:08:27 +01:00
Artem Iglikov
f32ea1909a Lower visibility of members of RefactoredBackupManagerService.
This lowers visibility of all fields and some methods which are not used
outside of the class.

Also this cleans up explicit generic arguments.

Test: compiled it successfully.

Bug: 36850431

Change-Id: I491687dbb84c1d9773c73884b8884b2dd9016ae7
2017-04-06 16:55:22 +01:00
Artem Iglikov
5021918605 Clone BackupManagerService and make Trampoline aware of the clone.
RefactoredBackupManagerService is an exact clone of
BackupManagerService. Trampoline chooses between these two based on
backup_refactored_service_disabled global setting, defaulting to true.

Test: manual: flashed the device, ran `settings put global
backup_refactored_service_disabled 1|0`, verified that correct class was
instantiated, ran bmgr backupnow command to make sure that it works.

Bug: 36850431

Change-Id: I8ef91b928a40aae022f88f07a4126a00b1d5e220
2017-04-06 12:28:13 +01:00
Artem Iglikov
adf8288a3f Introduce BackupManagerServiceInteface in remaining parts of the code.
Use it in Trampoline, KeyValueAdbBackupEngine, KeyValueAdbRestoreEngine
where it wasn't used automatically, because of using package-private
methods and fields. To be able to do this, also make couple of methods
public and move them to the interface and add getBackupManagerBinder()
method to use instead of directly accessing the field.

Test: not required as behaviour is not modified.

Bug: 36850431

Change-Id: Ia7a26f93f8dba37ece87305979c922acb58a271f
2017-04-05 14:54:07 +01:00
Artem Iglikov
ada1f001e6 Rename IBackupManagerService to BackupManagerServiceInterface.
As per comment in ag/2047840

Test: not required

Bug: 36850431
Change-Id: I296830b7ac17ffacb219a3e8296659910e89585f
2017-04-04 20:02:08 +01:00
Artem Iglikov
1fb72bc2e1 Extract interface of BackupManagerService and make BackupManagerService implement this interface.
This is part of (mostly) automated refactoring of BackupManagerService, see go/br-bm-automated-refactor.

All done automatically with https://www.jetbrains.com/help/idea/2016.3/extract-interface.html

Test: not required, as this doesn't change any behaviour.

Bug: 36850431

Change-Id: I1efa15b0f600536a9fd555bed18f2e86c3bcfecb
2017-04-04 11:15:51 +01:00
Jeff Sharkey
6df866a851 Enforce PACKAGE_USAGE_STATS for usage data.
Some system services are offering package usage data through both
public/system APIs and through dump() calls.  In principle, usage
data hould always be protected with PACKAGE_USAGE_STATS, so start
enforcing that.  (Otherwise if a user blocked PACKAGE_USAGE_STATS
access to an app, that app could still obtain the data via dump()
if they held the DUMP permission.)

Bottom line, let's respect the user's wishes.

Protecting the entire output like this is pretty blunt, but future
CLs can add more nuance to the output if desired.

Test: cts-tradefed run commandAndExit cts-dev -m CtsSecurityTestCases -t android.security.cts.ServicePermissionsTest
Bug: 32806790
Change-Id: I46173562713bea7d89e12a4313c78eb52ea8d77d
2017-04-02 22:29:07 -06:00
Jeff Sharkey
fe9a53bc45 Consistent dump() permission checking.
This change introduces new methods on DumpUtils that can check if the
caller has DUMP and/or PACKAGE_USAGE_STATS access.  It then moves all
existing dump() methods to use these checks so that we emit
consistent error messages.

Test: cts-tradefed run commandAndExit cts-dev -m CtsSecurityTestCases -t android.security.cts.ServicePermissionsTest
Bug: 32806790
Change-Id: Iaff6b9506818ee082b1e169c89ebe1001b3bfeca
2017-04-02 22:29:07 -06:00
Anton Philippov
bc44678fb1 Add null check in BackupManagerService$PerformBackupTask.handleCancel()
handleCancel() can be called before we start backing up any particular
package, therefore we need to properly handle log messages in that case.

Bug: 36638539
Test: manual
Change-Id: Ic96e2fbad5c0a79640a3419d187e8b5e4d265de3
(cherry picked from commit 519a87db8f)
2017-03-28 11:25:44 +00:00
Johan Toras Halseth
b59a4b85ad Add support for key-value packages to adb backup/restore.
For adding CTS tests for packages having key-value backup agents, we add
support for key-value backups to the adb backup/restore command.
Previously, packages not supporting fullbackup would just be skipped on
this command. Now, by adding the -keyvalue flag to the adb backup command,
packages supporting key-value will also be added to the resulting
tarball. Similarly, if the tarball being supplied to adb restore
contains data from key-value packages, it will be restored.

This will later be utilized for writing CTS tests for such packages.

Test: adb backup -includekeyvalue -all && adb restore backup.ab

Change-Id: I7b4ccfb7072d01d29a888952145d7cce90a4f59e
2017-03-24 23:51:48 +00:00