Commit Graph

428 Commits

Author SHA1 Message Date
Bernardo Rufino
c1b6ca05ef Increase PerformBackupTask unit coverage
With KV Refactor in mind.
* Added tests around empty queue and single package backups.
* Refactored a bit some of the existing tests.
* Moved from mocking BMS to using a real instance and had to adjust a
  few things for this.

Test: atest PerformBackupTaskTest
Change-Id: I0ee3be32c7cbac5ed2cdc2717408749907c15ade
2018-07-17 12:23:11 +01:00
Anton Philippov
5148582ef2 Use FullRestoreEngine in adb restore.
PerformAdbRestoreTask and FullRestoreEngine has shared a lot of code,
remove the copy that was in PerformAdbRestoreTask.

Test: adb restore
Change-Id: Ib4ce8b50eff8aed4a2c0660808c05b80f378ea98
2018-06-15 11:38:29 +00:00
TreeHugger Robot
c87e4b8ea0 Merge "Update PerformInitializeTask error message" 2018-06-11 11:34:26 +00:00
Bernardo Rufino
1f315591ba Update PerformInitializeTask error message
Bug: 109652198
Test: m -j RunFrameworksServicesRoboTests
Change-Id: Iaef534bba74b05f73e150d9fc3ff212c788e8205
2018-06-08 17:54:19 +01:00
Bernardo Rufino
7307e645b8 Check manifest if runtime state of app is DEFAULT
Before we were considering that the app was enabled in this case, which
might not be always true.

Bug: 80227098
Test: atest AppBackupUtilsTest
Test: Check app w/ manifest enabled="true" is backed-up, but
      enabled="false" is not.

Change-Id: I4625aa39ba0de45ce6689f2375245081a5d4d722
2018-06-06 08:19:09 +00:00
Annie Meng
8cdae01244 Clear calling identity in BMS.backupNow
BMS.backupNow is called from GMSCore, which has a different calling
identity than the framework. This causes an IllegalArgumentException due
to uid mismatch when backupNow tries to schedule a job.

This occurs when the following conditions are combined:
1) Battery saver mode enabled
2) Network change detected
3) Backup pass is scheduled for now

Bug: 79441902
Test: 1) m -j RunFrameworksServicesRoboTests
2) Manual: Enabled battery saver, modified code to run backupNow with
each network change and overwrite previously scheduled KeyValueJob.
Then, change wifi to trigger scheduling the KeyValueJob.
Verified:
- IllegalStateException b/c of uid mismatch without change
- No exception and correct calling uid with change

Change-Id: Iac90cd435e3fc32ff5428236aa15507b36aa833d
2018-05-25 09:45:18 +00:00
TreeHugger Robot
a41a7094ac Merge "Add getCurrentTransportComponent() API" 2018-05-24 13:13:18 +00:00
Bernardo Rufino
98b17a6146 Add getCurrentTransportComponent() API
Bug: 73640944
Test: atest RunFrameworksServicesRoboTests
Change-Id: I62193d63367c3b7564ccd41f5b103a7076764e3f
2018-05-14 11:36:11 +01:00
ericchhsu
e6e63cd6c6 Instantly excute next state when the agent provides a prohibited key.
When the agent provides a prohibited key, the code flow will directly be returned
without excuting next backup state. The next state should be execute instantly to
make sure the backup mechanism can be executed properly.

Bug: 77272601
Test: 1.m -j RunFrameworksServicesRoboTests
      2.Manual testing by test package with prohibited key.
      - adb backup -all
      - adb backup -shared
      - adb backup -obb -all
      - adb shell bmgr backupnow --all
      - adb shell bmgr backupnow [test key value package]
      - adb backup -keyvalue [test key value package]
Change-Id: I46e1aa8dd0f75cf54087b43cee50ee952d85abc1
2018-05-03 11:55:17 +08:00
Shaowei Shen
44b8e043cf Merge "Fix [kv-3]PerformBackupTask using last package status to decide status sent to IBackupObserver." into pi-dev am: 49a987c277
am: 661afbe5fa

Change-Id: Ia242afee49f7c715ba0b6fa65a4325b89e26f79d
2018-05-02 19:24:29 -07:00
Shaowei Shen
49a987c277 Merge "Fix [kv-3]PerformBackupTask using last package status to decide status sent to IBackupObserver." into pi-dev 2018-05-03 02:05:17 +00:00
android-build-team Robot
492e53ee17 Merge "Don't run obb backup for shared storage backup package." into pi-dev am: 494113e74a
am: e673650aff

Change-Id: I97389ba178bf6a225c375d27d91655e9957bbbf5
2018-05-01 08:53:05 -07:00
Anton Philippov
09589d0073 Don't run obb backup for shared storage backup package.
This fixes an issue when adb backup would hang (and hold wakelock)
forever when run with '-obb' and '-shared'.

Bug: 75997810
Test: 'adb backup -obb -shared' finishes successfully
Change-Id: I015add6dc525984592e733266b3e046f41d2cb93
2018-05-01 14:27:00 +01:00
shaoweishen
59ab5f4934 Fix [kv-3]PerformBackupTask using last package status to decide status sent to IBackupObserver.
We only report failure to IBackupObserver.backupFinished() when we meet
transport failure, but now it will report failure when the last package
meet TRANSPORT_PACKAGE_REJECTED or TRANSPORT_QUOTA_EXCEEDED, add above
two states in FINAL to prevent the situation, and update related
test, also javadoc of IBackupObserver.

Bug: 77271953

Test: make -j RunFrameworksServicesRoboTests ROBOTEST_FILTER=PerformBackupTaskTest
Change-Id: Ic2bfdf9f50d700f8ccb509e081ae8e0afb186020
2018-04-24 09:54:37 +08:00
Allen Su
8eb97f61a4 PerformBackupTask getting 2 IBackupObserver.backupFinished()
Remove IBackupObserver.backupFinished() before
executeNextState(BackupState.FINAL), add test cases to verify it and
format PerformBackupTaskTest.java
Bug: 77272662
Test: make RunFrameworksServicesRoboTests

Change-Id: Ia464d0326437fb8680ab88619829c483e2c1164d
2018-04-24 00:01:05 +08:00
Henry Liu
cfa5a82f82 Fix [kv-4] PerformBackupTask possible NPE/Wrong package report.
mCurrentPackage is null when package doesn't exist, which lead test
failed with NPE
Use request.packageName for case BackupTransport.AGENT_UNKNOWN instead

Bug: 77272500

Test: m -j RunFrameworksServicesRoboTests ROBOTEST_FILTER=PerformBackupTaskTest
Change-Id: I27be85f0c3f95e36edd92d0d552189fbcf6952dd
(cherry picked from commit 87f1209ac6)
2018-04-12 02:44:50 +00:00
Henry Liu
af3598cf13 Merge "Fix [kv-4] PerformBackupTask possible NPE/Wrong package report." 2018-04-12 02:43:18 +00:00
Henry Liu
87f1209ac6 Fix [kv-4] PerformBackupTask possible NPE/Wrong package report.
mCurrentPackage is null when package doesn't exist, which lead test
failed with NPE
Use request.packageName for case BackupTransport.AGENT_UNKNOWN instead

Bug: 77272500

Test: m -j RunFrameworksServicesRoboTests ROBOTEST_FILTER=PerformBackupTaskTest
Change-Id: I27be85f0c3f95e36edd92d0d552189fbcf6952dd
2018-04-12 02:17:20 +00:00
Daniel Cashman
934b61ddcb Merge "Add SigningInfo class to expose package signing details." into pi-dev am: 960a0c6c57
am: 63b447531e

Change-Id: Ie311660c339d1293c2b332dc4da0e865a1d21685
2018-04-11 13:07:50 -07:00
Daniel Cashman
960a0c6c57 Merge "Add SigningInfo class to expose package signing details." into pi-dev 2018-04-11 19:21:07 +00:00
Anton Philippov
0e6647ad59 Merge "Pass app version to agent in adb restore for kv." into pi-dev am: 133f93bbbb
am: 0d383d2ee4

Change-Id: Icc2051dd9f08d8c0c48e0bb96621a203b6d979c7
2018-04-11 11:07:52 -07:00
Anton Philippov
133f93bbbb Merge "Pass app version to agent in adb restore for kv." into pi-dev 2018-04-11 16:53:30 +00:00
Anton Philippov
f8cefdec4b Pass app version to agent in adb restore for kv.
This is a temporary solution for P to unblock GTS tests.

Bug: 77852250
Test: manual:
1. adb backup -f saved-wifi-api100.ab -keyvalue com.android.providers.settings
2. adb restore saved-wifi-api100.ab
3. See that SettingsBackupAgent receives appVersionCode in onRestore()

Change-Id: I6092bea570e7e27cb5b72165e9284ad2befc21b6
2018-04-11 14:58:14 +01:00
Dan Cashman
5c9f527e33 Add SigningInfo class to expose package signing details.
Attempt to simplify the exposure of package signing information via
PackageInfo by creating a new class and corresponding methods for
querying a package's signing information.

Bug: 74831530
Test: PkgInstallSignatureVerificationTest
Change-Id: Idbc008b41a921f89cefb224b26f910da4d238dea
2018-04-10 22:19:20 +00:00
Bernardo Rufino
6858acd442 Merge "Catch IAE from unbind onServiceDisconnected()" into pi-dev am: c83cf90166
am: 0f95a94940

Change-Id: I2097f145026be9d72c4d920e2567ea7cc6fe5589
2018-04-05 04:51:43 -07:00
Bernardo Rufino
51c4f038b2 Catch IAE from unbind onServiceDisconnected()
We still don't know the underlying cause of this, but we shouldn't crash
the system_server. Catching for now.

Bug: 74940472
Bug: 77574274
Test: m -j RunFrameworksServicesRoboTests
Change-Id: I36fc2e65f8766f6b8fd68104d8830b72668d84eb
2018-04-05 10:14:01 +00:00
Artem Iglikov
1e1c28b8d4 Merge "Clear app data before full restore for specified packages" into pi-dev am: bb0bcc4460
am: d723b5ea24

Change-Id: I551d4dc0cbc04e48daa2c636aa341e7775246ffa
2018-03-29 13:47:34 +00:00
TreeHugger Robot
bb0bcc4460 Merge "Clear app data before full restore for specified packages" into pi-dev 2018-03-29 13:23:24 +00:00
Artem Iglikov
5b53875fdc Clear app data before full restore for specified packages
In some cases (deferred restore) the app data needs to be cleared even
if the app has implemented backup agent. As a quick fix introduce
PACKAGES_TO_CLEAR_DATA_BEFORE_FULL_RESTORE secure setting, which
transport can fill prior to restore.

Bug: 69069240
Test: adb shell settings put secure packages_to_clear_data_before_full_restore com.google.android.apps.nexuslauncher && adb shell bmgr restore com.google.android.apps.nexuslauncher
Change-Id: I2a4651365d9cf4747f32d2ba69312f54cd03d118
2018-03-29 11:01:50 +01:00
Annie Meng
92892163d5 DO NOT MERGE Unrevert update references to backup agent timeouts
Cherry-picked from master (ag/3800434).

Reintroduce change (ag/3742803) that was reverted due to SUW crash
(ag/3780292).

Updates references to backup/restore agent timeouts from hardcoded
constants to the Global setting backup_agent_timeout_parameters.

Bug: 70276070
Test: 1) m -j RunFrameworksServicesRoboTests
2) Manual testing of affected backup/restore paths:
- Wipe device; restore cloud backup via SUW
- adb shell bmgr list sets
- adb shell bmgr restore [package]
- adb shell bmgr restore [token]
- adb backup -all
- adb backup -shared
- adb backup -obb -all
- adb shell bmgr backupnow --all
- adb shell bmgr backupnow [key value package]
- adb shell bmgr backupnow [full data package]
- adb backup -keyvalue [key value package]
- adb restore backup.ab

Change-Id: If9aad572d688451d37178cd7c2d7844be054953c
2018-03-28 18:07:19 +01:00
Annie Meng
a1e8fd61a6 Unrevert update references to backup agent timeouts
Reintroduce change (ag/3742803) that was reverted due to SUW crash
(ag/3780292).

Updates references to backup/restore agent timeouts from hardcoded
constants to the Global setting backup_agent_timeout_parameters.

Bug: 70276070
Test: 1) m -j RunFrameworksServicesRoboTests
2) Manual testing of affected backup/restore paths:
- Wipe device; restore cloud backup via SUW
- adb shell bmgr list sets
- adb shell bmgr restore [package]
- adb shell bmgr restore [token]
- adb backup -all
- adb backup -shared
- adb backup -obb -all
- adb shell bmgr backupnow --all
- adb shell bmgr backupnow [key value package]
- adb shell bmgr backupnow [full data package]
- adb backup -keyvalue [key value package]
- adb restore backup.ab

Change-Id: I871fd32c7601bbe6b06a0c8516bb85bc0ead4198
2018-03-28 15:37:33 +01:00
Artem Iglikov
b873780a3d DO NOT MERGE Revert "DO NOT MERGE Update references to backup/restore agent timeouts"
This reverts commit f77cae6125.

Reason for revert: crashes SUW

Bug: 76128378
Change-Id: Ia77af64892aa5a03109cc4ef4c2c04b256000ba9
2018-03-22 13:07:34 +00:00
Annie Meng
c3b004f828 Revert "Update references to backup/restore agent timeouts"
This reverts commit ea409907e3.

Reason for revert: Crashes SUW

Bug: b/76128378
Change-Id: I4ec134cb979f17bdbaf30d958e8278479312a3d3
2018-03-22 13:02:29 +00:00
Annie Meng
f77cae6125 DO NOT MERGE Update references to backup/restore agent timeouts
With the newly created Global setting for backup/restore agent timeouts
(backup_agent_timeout_parameters introduced in ag/3731401), update
references in backup and restore code to get the timeout values from
the setting instead of referencing constants in BMS.
This makes these timeouts configurable outside of the framework.

The default value of the setting is the same as the constants in BMS so
this should have no change on the timeout values used in the backup and
restore flow.

Bug: 70276070
Test: 1) m -j RunFrameworksServicesRoboTests
Change-Id: I0259bba76d0fed48158b8316f430b315ea98086e
2018-03-20 23:48:27 +00:00
Annie Meng
ea409907e3 Update references to backup/restore agent timeouts
With the newly created Global setting for backup/restore agent timeouts
(backup_agent_timeout_parameters introduced in ag/3731401), update
references in backup and restore code to get the timeout values from
the setting instead of referencing constants in BMS.
This makes these timeouts configurable outside of the framework.

The default value of the setting is the same as the constants in BMS so
this should have no change on the timeout values used in the backup and
restore flow.

Bug: 70276070
Test: 1) m -j RunFrameworksServicesRoboTests
Change-Id: I0259bba76d0fed48158b8316f430b315ea98086e
2018-03-16 12:15:32 +00:00
Annie Meng
d069a888cf DO NOT MERGE Create a setting for backup/restore agent timeouts
Part of push to make backup and restore agent timeouts configurable. Creates
a Global setting for the current static BackupManagerService timeouts so
that they can be overriden with P/H. We keep the current default values,
which will be updated once we investigate what more appropriate values are.

Remame the constants to better reflect what they're used
for. Next, we will update the framework to use these constants.

This depends on the refactor of how we observe changes to key value
backup settings (ag/3709997).

Bug: 70276070
Test: m -j RunFrameworksServicesRoboTests ROBOTEST_FILTER=BackupAgentTimeoutParametersTest
Change-Id: Id506314ce0c8bd5e4d1d8b4001b26cbad0056c99
2018-03-15 17:43:56 +00:00
Annie Meng
1e13e37401 Create a setting for backup/restore agent timeouts
Part of push to make backup and restore agent timeouts configurable. Creates
a Global setting for the current static BackupManagerService timeouts so
that they can be overriden with P/H. We keep the current default values,
which will be updated once we investigate what more appropriate values are.

Remame the constants to better reflect what they're used
for. Next, we will update the framework to use these constants.

This depends on the refactor of how we observe changes to key value
backup settings (ag/3709997).

Bug: 70276070
Test: m -j RunFrameworksServicesRoboTests ROBOTEST_FILTER=BackupAgentTimeoutParametersTest
Change-Id: Id506314ce0c8bd5e4d1d8b4001b26cbad0056c99
2018-03-15 12:59:13 +00:00
Michal Karpinski
808d8a0163 Merge "Allow restoring of apps that rotated key" into pi-dev am: d766e212c9
am: f89a90bcca

Change-Id: I0895c47a93d7bd3b90a89bd0b0dce2cc24fcb963
2018-03-15 10:41:22 +00:00
Michal Karpinski
528c3e572a Allow restoring of apps that rotated key
Restoring of apps that rotated key wouldn't be possible due to
explicit signature matching.
Amend signature matching strategies to take into account
apps that have rotated key.

Test: atest frameworks/base/services/tests/servicestests/src/
      com/android/server/backup/utils/AppBackupUtilsTest.java
Test: atest frameworks/base/services/tests/servicestests/src/
      com/android/server/pm/backup/BackupUtilsTest.java
Test: m -j RunFrameworksServicesRoboTests
Test: runtest -p com.android.server.backup frameworks-services
Test: atest frameworks/base/services/tests/servicestests/src/
      com/android/server/pm/ShortcutManagerTest1.java
Test: atest frameworks/base/services/tests/servicestests/src/
      com/android/server/pm/ShortcutManagerTest2.java
Test: atest frameworks/base/services/tests/servicestests/src/
      com/android/server/pm/ShortcutManagerTest3.java
Test: atest frameworks/base/services/tests/servicestests/src/
      com/android/server/pm/ShortcutManagerTest4.java
Test: atest frameworks/base/services/tests/servicestests/src/
      com/android/server/pm/ShortcutManagerTest5.java
Test: atest frameworks/base/services/tests/servicestests/src/
      com/android/server/pm/ShortcutManagerTest6.java
Test: atest frameworks/base/services/tests/servicestests/src/
      com/android/server/pm/ShortcutManagerTest7.java
Test: atest frameworks/base/services/tests/servicestests/src/
      com/android/server/pm/ShortcutManagerTest8.java
Test: atest frameworks/base/services/tests/servicestests/src/
      com/android/server/pm/ShortcutManagerTest9.java
Test: atest frameworks/base/services/tests/servicestests/src/
      com/android/server/pm/ShortcutManagerTest10.java
Test: atest CtsShortcutManagerTestCases
Bug: 64686581
Bug: 34345052
Bug: 74208476
Bug: 74159113

Change-Id: Ica23bbfec89648d9348c65db4597188e8c18e1d8
2018-03-14 16:11:18 +00:00
Annie Meng
d3b6e9fe22 Merge "DO NOT MERGE Create a key value settings observer for backup parameters" into pi-dev 2018-03-14 13:40:46 +00:00
TreeHugger Robot
cd8f972f61 Merge "Tests for BMS.requestBackup()" 2018-03-14 13:23:21 +00:00
Bernardo Rufino
34607a0f7e Tests for BMS.requestBackup()
Test: m -j RunFrameworksServicesRoboTests
Change-Id: I71f377a2ce16ece08e7d2ebbf2af31c0d1594703
2018-03-14 10:42:04 +00:00
Annie Meng
7d3033b11f DO NOT MERGE Create a key value settings observer for backup parameters
Extracts an abstract class to observe changes in backup parameter settings that
are stored as a comma-separated key value list. This class is
responsible for registering and unregistering a content observer on the
setting and updating local references to the parameters.

Refactor BackupManagerConstants and LocalTransportParameters to use this
implementation. This will also be used for the new backup timeout
setting.

Bug: 74346317
Test: 1) m -j RunFrameworksServicesRoboTests ROBOTEST_FILTER=BackupManagerConstantsTest
2) gts-tradefed run commandAndExit gts-dev -m GtsBackupHostTestCases -t com.google.android.gts.backup.TransportFlagsHostSideTest

Change-Id: Id4c50fbcf7479c925515887e3fa70e166dd9955c
2018-03-13 18:47:46 +00:00
Annie Meng
48b2ecae52 Create a key value settings observer for backup parameters
Extracts an abstract class to observe changes in backup parameter settings that
are stored as a comma-separated key value list. This class is
responsible for registering and unregistering a content observer on the
setting and updating local references to the parameters.

Refactor BackupManagerConstants and LocalTransportParameters to use this
implementation. This will also be used for the new backup timeout
setting.

Bug: 74346317
Test: 1) m -j RunFrameworksServicesRoboTests ROBOTEST_FILTER=BackupManagerConstantsTest
2) gts-tradefed run commandAndExit gts-dev -m GtsBackupHostTestCases -t com.google.android.gts.backup.TransportFlagsHostSideTest

Change-Id: Id4c50fbcf7479c925515887e3fa70e166dd9955c
(cherry picked from commit 16ef6ffb3cbea77637ad99c2b0c79cbfd8f03c9a)
2018-03-13 18:24:12 +00:00
Bernardo Rufino
602bf1a8a8 Add tests for TransportStats and some refactor
Added units for http://ag/3709565. Some refactoring.

Test: m -j RunFrameworksServicesRoboTests
Bug: 72485465
Change-Id: Id75a4e0b96936580fd677041e091340b0fff8c1e
(cherry picked from commit cac3a74059)
2018-03-12 15:33:43 +00:00
TreeHugger Robot
cb0fe76877 Merge "Add tests for TransportStats and some refactor" 2018-03-12 14:02:42 +00:00
Bernardo Rufino
60719a4e74 Add measurements for TransportClient connections
Retrievable via 'adb shell dumpsys backup transportstats'.
Sample output:

Average connection time: 36.00 ms
Max connection time: 181 ms
Min connection time: 7 ms
Number of connections: 16
Per transport:
    com.google.android.gms/.backup.BackupTransportService
        Average connection time: 27.71 ms
        Max connection time: 139 ms
        Min connection time: 13 ms
        Number of connections: 14
    com.google.android.gms/.backup.component.D2dTransportService
        Average connection time: 181.00 ms
        Max connection time: 181 ms
        Min connection time: 181 ms
        Number of connections: 1
    android/com.android.internal.backup.LocalTransportService
        Average connection time: 7.00 ms
        Max connection time: 7 ms
        Min connection time: 7 ms
        Number of connections: 1

Bug: 72485465
Test: Will follow in another CL if reviewers OK w/ approach.
Change-Id: I133ed423d0b8471d69e3c3631aadee7d42d0ec0e
(cherry picked from commit e5a976404c)
2018-03-12 12:19:56 +00:00
Bernardo Rufino
cac3a74059 Add tests for TransportStats and some refactor
Added units for http://ag/3709565. Some refactoring.

Test: m -j RunFrameworksServicesRoboTests
Bug: 72485465
Change-Id: Id75a4e0b96936580fd677041e091340b0fff8c1e
2018-03-12 12:19:10 +00:00
TreeHugger Robot
22b821f8e8 Merge "Add measurements for TransportClient connections" 2018-03-09 17:49:34 +00:00
Bernardo Rufino
e5a976404c Add measurements for TransportClient connections
Retrievable via 'adb shell dumpsys backup transportstats'.
Sample output:

Average connection time: 36.00 ms
Max connection time: 181 ms
Min connection time: 7 ms
Number of connections: 16
Per transport:
    com.google.android.gms/.backup.BackupTransportService
        Average connection time: 27.71 ms
        Max connection time: 139 ms
        Min connection time: 13 ms
        Number of connections: 14
    com.google.android.gms/.backup.component.D2dTransportService
        Average connection time: 181.00 ms
        Max connection time: 181 ms
        Min connection time: 181 ms
        Number of connections: 1
    android/com.android.internal.backup.LocalTransportService
        Average connection time: 7.00 ms
        Max connection time: 7 ms
        Min connection time: 7 ms
        Number of connections: 1

Bug: 72485465
Test: Will follow in another CL if reviewers OK w/ approach.
Change-Id: I133ed423d0b8471d69e3c3631aadee7d42d0ec0e
2018-03-09 13:52:40 +00:00