Commit Graph

385 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Amith Yamasani
14c716c911 Revert "Allow restoring of apps that rotated key"
This reverts commit 313d225cd1.

Reason for revert: b/74159113

Change-Id: I483ecdd80d26fca8451cd270b4fcbe34379839cb
2018-03-05 20:40:23 +00:00
TreeHugger Robot
9371be3b88 Merge "Bmgr about running backups" 2018-02-28 14:26:34 +00:00
Bernardo Rufino
760c1f552c Bmgr about running backups
Says that backups can be canceled if one already running. Put message
for running backups in dumpsys for checking.

Bug: 72484277
Test: Triggered backup, checked dumpsys and bmgr backupnow
Change-Id: I028cf663858e374389f50175aaf5a3e8c9d45e42
2018-02-28 12:11:26 +00:00
Michal Karpinski
961f409d37 Merge "Allow restoring of apps that rotated key" 2018-02-28 10:08:14 +00:00
Annie Meng
0b0ebb616d Merge "Move transport constant to BackupTransport API" 2018-02-27 17:39:58 +00:00
Annie Meng
1b9877ab44 Move transport constant to BackupTransport API
Previously, the transport registration extra was a private
constant. Since GMSCore depends on this value being passed, moving
it to a public API prevents having to define it twice in
framework and GMSCore, and ensures compatibility between the two.

TODO: Update GMSCore with this constant once this drops
into GMSCore.

Bug: 72730566
Test: 1) m -j ROBOTEST_FILTER=TransportManagerTest RunFrameworksServicesRoboTests
2) m -j ROBOTEST_FILTER=TransportClientManagerTest RunFrameworksServicesRoboTests

Change-Id: I8f7a2ca0275047a5d3cc1a530cd86499d0170f2f
2018-02-27 15:17:56 +00:00
Bernardo Rufino
12b6bafcf4 More tests for ActiveRestoreSession
Around restoreAll() and restoreSome(). And some small refactorings in
restore code paths.

Test: m -j RunFrameworksServicesRoboTests
Change-Id: I0ff446ef4dcf15eade189c79e90a22c0f2eda0d6
2018-02-27 12:24:34 +00:00
Michal Karpinski
313d225cd1 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
Bug: 64686581
Bug: 34345052
Change-Id: I91b5ae0afb6f2714ceae02b4d4dc202d6cd4fe4e
2018-02-26 11:05:40 +00:00
Michal Karpinski
92c8756876 Support bmgr wipe also for full backup apps
Previously we'd only really clear data for K/V packages,
now we consult with the journal of ever backed apps.

Bug: 28405555
Test: manual (adb shell bmgr wipe com.google.android.gms/.backup.BackupTransportService com.android.wallpaperbackup
      after adb shell bmgr backupnow --all)
Test: m -j RunFrameworksServicesRoboTests
Test: runtest -p com.android.server.backup frameworks-services
Change-Id: If99cb2c8ab9ddc05386d634818f4585ec47efc00
2018-02-23 15:16:08 +00:00
TreeHugger Robot
0eb747e51e Merge "Update transport connection with registration info" 2018-02-15 13:57:50 +00:00
Annie Meng
36c5613a93 Update transport connection with registration info
When connecting to a transport, let the transport
know if this connection is for registration. This is to
prevent updating transport attributes during registration
in GMSCore.

Bug: 72730566
Test: 1) m -j ROBOTEST_FILTER=TransportManagerTest RunFrameworksServicesRoboTests
2) m -j ROBOTEST_FILTER=TransportClientManagerTest RunFrameworksServicesRoboTests
3) adb reboot; adb logcat | grep BackupTransportManager; check no errors with "...not registered tried to change description"
4) GMSCore Robo tests
Change-Id: I5adf6ea3e668a8e8ed8c568728d109814b6f8975
2018-02-15 10:40:01 +00:00
Andreas Gampe
bbab23ff97 Frameworks: Annotate trivial @GuardedBy in services/ misc
Add @GuardedBy for simple functions that require a single lock
and are named XYZLocked.

Derived by errorprone.

Bug: 73000847
Test: m
Test: m javac-check-framework RUN_ERROR_PRONE=true
Change-Id: Id1d9fbe5018250e3b9d1466fc5f670d5ad902fa3
2018-02-08 02:19:42 -08:00
Annie Meng
d38749b6ff Update adb backup/restore confirmation activity on new intent
Now, if adb backup/restore is currently active and the activity is
passed a new intent, the activity instance would be updated with the new intent.
Same for if the activity is relaunched.

Before, the activity would ignore intent changes and use old tokens and
views, leading to backing up/restoring wrong files.

Bug: 65723308
Test: adb backup -f old.ab -all; ctrl-c; adb backup -f new.ab -all;
gts-tradefed run commandAndExit gts-dev -m GtsBackupHostTestCases
Change-Id: Ifa11efecf82a682a578dab7e5795328ab7d0c054
2018-01-29 12:43:20 +00:00
Michal Karpinski
fe4ae0c5b1 Rename RefactoredBackupManagerService to BackupManagerService
The interface will be removed in a subsequent CL, it will be
easier to deal with merge conflicts.

Test: 1) m -j RunFrameworksServicesRoboTests
      2) runtest -p com.android.server.backup frameworks-services
Bug: 65823538
Change-Id: I37c4c6758c646e1b18889ed05aa1b1d7c6129cf0
2018-01-26 10:37:32 +00:00
TreeHugger Robot
1e7f8014a8 Merge "Binding on-demand #12: Log and unbind dangling TransportClients" 2018-01-25 16:08:15 +00:00
Bernardo Rufino
3184cc9948 Binding on-demand #12: Log and unbind dangling TransportClients
Extracted connection in TransportClient to static class with weak
reference to TransportClient so that TransportClient is garbage
collected when left undisposed. Created finalize method that logs,
unbinds TransportClient and warns using CloseGuard.
Also adjusted some logging.

Bug: 17140907
Test: m -j RunFrameworksServicesRoboTests
Test: Manually left a dangling TransportClient and observed logs and
connections

Change-Id: I30f89e7c27579089ba29936483abd1b60c9e8e37
2018-01-25 12:38:04 +00:00
Robert Berry
39194c0582 Add #getTransportFlags to BackupDataOutput
This allows a BackupAgent to check whether the transport has client-side
encryption enabled. It can then use this information to decide whether
to back up more sensitive data.

Bug: 72299360
Test: Manually verified full & kv backup agents receive transport flags
Test: m -j RunFrameworksServicesRoboTests
Change-Id: Ibd9b5f9479815e1721e9d6b7663d892b9ab3fcae
2018-01-25 09:28:55 +00:00
Oscar Key
f5b99ad2ea Let the transport ask for non-incremental backup.
Add a new performBackup() return code TRANSPORT_PACKAGE_DATA_LOST. If
the transport returns this then delete the state for the package and
immediately retry it. Thus the retry will be a non-incremental backup.

I have left the new constant as @hide to unblock this change. I will add
this to the current API review change: ag/3477872.

Bug: 71887023
Test: I tested manually by returning the new code for both @pm@ and
other key value packages. No automated test exists for this file, and it
will be tricky to add this before IC.

Change-Id: I4357a8b297c373eb81e25afb82d480b26f6642b6
2018-01-23 17:16:28 +00:00
Oscar Key
8056728f7c Move backup of @pm@ into its own state.
Previously it shared the INITIAL state with various set up work and
initializing the transport if needed. By moving it to its own state this
will mean we can retry a non-incremental backup of @pm@ if the transport
indicates that it has lost the state.

I removed the "mStatus == BackupTransport.TRANSPORT_NOT_INITIALIZED" as
the mStatus could never have this value at that point.
TRANSPORT_NOT_INITIALIZED is returned by the transport.performBackup(),
which is not executed until after beginBackup() has returned.

Bug: 71887023
Test: Manually tested init case, incremental case, @pm@ error case, init
error case. There are no unit tests for this file, and it's 1200 lines
long which makes writing them for IC difficult.

Change-Id: I23b7512391068316f4c1039faf88cc27905f4492
2018-01-23 15:16:34 +00:00
Oscar Key
38902fc09e Merge "Make various members private in PerformBackupTask." 2018-01-22 21:07:49 +00:00
Oscar Key
3d2f335c21 Make various members private in PerformBackupTask.
Test: None. No functional changes.
Change-Id: Ia35bdd7637887b4c02a71e96e9037842078fdba4
2018-01-22 16:10:36 +00:00
TreeHugger Robot
b56074b37b Merge "Clear calling uid in isAppEligibleForBackup() and variant" 2018-01-19 21:54:36 +00:00
Bernardo Rufino
5d94c398eb Merge "Binding on-demand #11: Dump TransportClients" 2018-01-19 20:57:49 +00:00
Bernardo Rufino
c3e509cacc Clear calling uid in isAppEligibleForBackup() and variant
This method is called by bmgr backupnow. Bmgr pid is not system uid.
When executing the method it fails with permission denied because it
can't bind to the transport. Before binding on-demand we haven't seen
this error because we didn't try to bind in the method, it was always
bound.

Bug: 72215413
Test: adb shell bmgr backupnow -all
Change-Id: I82ad712e893abfec4727d568ab48a49945645eb4
2018-01-19 19:02:09 +00:00
Bernardo Rufino
861b420bc3 Binding on-demand #11: Dump TransportClients
And adjust logs.

Change-Id: I04fcfb77bac14db36cc30288878bbb65332deb81
Ref: http://go/br-binding-on-demand
Bug: 17140907
Test: adb shell dumpsys backup
2018-01-19 14:56:21 +00:00
Bernardo Rufino
a4517cdb7d Remove use of streams in TransportManager
Test: m -j RunFrameworksServicesRoboTests
Change-Id: Ie5d81ca9e8c8fcda482fa520aa46841800b88210
2018-01-19 12:09:15 +00:00
Bernardo Rufino
070081bc4f Don't use transport binder with the lock held
There was a deadlock around the transport lock. We registered transports
with the transport lock held, this kicked-off transport onCreate()
synchronously, which called TransportManager
updateTransportAttributes(), which tried to acquire mentioned lock but
couldn't. This CL removes the lock for any call to the transport or
operation that triggers a call to the transport (it was
TransportClient.connect() or its variants).

Test: Load GMSCore before fix, boot, register transports, check no ANR
Test: m -j RunFrameworksServicesRoboTests
Test: adb shell bmgr transport -c <transport>, being registered & not
Bug: 72147303
Change-Id: I72ca145d7fb73c0ef29c4aa1b620fea4969481db
2018-01-18 19:20:49 +00:00
TreeHugger Robot
3fb6ea960f Merge "Add BackupManager#isBackupServiceActive() system API" 2018-01-17 19:07:21 +00:00
Bernardo Rufino
4e588baaa4 Merge "Move event logging to TransportClient and add connection event" 2018-01-17 15:39:45 +00:00
Michal Karpinski
96e0be0fd8 Add BackupManager#isBackupServiceActive() system API
So that GMSCore can find out and disable restore flow
and Backup UI.

Bug: 33339643
Test: gts-tradefed run gts -m GtsGmscoreHostTestCases -t com.google.android.gts.devicepolicy.DeviceOwnerTest#testBackupServiceActive (new GTS test in companion CL)
Test: cts-tradefed run cts -m CtsDevicePolicyManagerTestCases -t com.android.cts.devicepolicy.DeviceOwnerTest#testBackupServiceEnabling
Change-Id: I62c38dec2395d3aa926566d128b0067ce7d62c26
2018-01-17 15:00:45 +00:00
Bernardo Rufino
ec2965de46 Dispose of TransportClient in updateStateForTransport()
Forgot this one :)

Change-Id: I13126b94ad0272c912a3e1c3d2e8ee06692a1897
Ref: http://go/br-binding-on-demand
Bug: 17140907
Test: m -j RunFrameworksServicesRoboTests
Test: adb shell bmgr transport [-c] <transport>, check connections
2018-01-17 13:45:08 +00:00
Lenka Trochtova
c141d08b70 New management API for making backups mandatory.
Let the device owner make backups with a chosen backup
transport mandatory.

BUG: 64012357
Test: make RunFrameworksServicesRoboTests
Test: manually together with the corresponding GmsCore change.
Test: cts-tradefed run cts -m CtsDevicePolicyManagerTestCases --test
com.android.cts.devicepolicy.DeviceOwnerTest#testGetAndSetMandatoryBackupTransport
Test: cts-tradefed run cts -m CtsBackupHostTestCase --test
android.cts.backup.BackupDeviceOwnerHostSideTest#testMandatoryBackupTransport

Change-Id: I9bfae5799beae3459659e697813b75a9b508ae55
2018-01-16 22:24:11 +01:00
TreeHugger Robot
931abbc249 Merge "Binding on-demand #10: Remove permanent binding and add registration" 2018-01-16 18:39:27 +00:00
Bernardo Rufino
aa56a6cde3 Move event logging to TransportClient and add connection event
Move event logging from registration to TransportClient and add new
event for connection.

Change-Id: I32022590a36b6f28f960e91f8880a0430e862852
Ref: http://go/br-binding-on-demand
Bug: 17140907
Test: m -j RunFrameworksServicesRoboTest
Test: adb logcat -b events, check relevant events
2018-01-16 15:56:53 +00:00
Bernardo Rufino
41349c02a8 Binding on-demand #10: Remove permanent binding and add registration
This CL is the last of the P1 CLs for binding on-demand. During
transport-usage migration to binding on-demand the permanent-bound
code was still there and we piggybacked on it to register the
transports. Now that everything is migrated we removed the permanent
binding and used the registration code created in the CL #9
(selectTransport) for registering all the transports.

I put a 3s delay on registration after bring-up. Any operation that uses
the transport before that will gracefully fail.

The TransportBoundListener does not return a boolean anymore because it
can't fail anymore (we pass it the data it needs so that it doesn't need
to be exposed to TransportNotRegistered exceptions). It's now called
OnTransportRegisteredListener.

Eligible transports were a similar thing to valid transports from the
permanent binding code, whose only need came from rebinding from what I
could tell. I saw no need for it anymore and removed it. If I missed
something please shout :)

I shuffled methods a bit in TransportManager.

There were a lot of changes to robo test infra to bring together
TransportManager tests and the rest and re-use mocking infra.

Change-Id: If61268228dd0bb724b718abd3dcafdad50e8b3dc
Ref: http://go/br-binding-on-demand
Bug: 17140907
Test: m -j RunFrameworksServicesRoboTest
Test: runtest -p com.android.server.backup frameworks-services
Test: gts-tradefed run commandAndExit gts-dev -m GtsBackupTestCases
Test: gts-tradefed run commandAndExit gts-dev -m GtsBackupHostTestCases
Test: cts-tradefed run commandAndExit cts-dev -m CtsBackupTestCases
Test: adb shell bmgr enable true/false
Test: adb shell bmgr list transports [-c]
Test: adb shell bmgr transport <transport_name>/-c <transport_component>
Test: adb shell bmgr restore <token>/<token> <package>/<package>
Test: adb shell bmgr backup <pacakge>
Test: adb shell bmgr run
Test: adb shell bmgr wipe <transport> <package>
Test: adb shell bmgr fullbackup <package>
Test: adb shell bmgr backupnow --all/<packages>
Test: adb shell cmd jobscheduler run -f android <job_id>
Test: adb shell dumpsys backup
Test: D2D scenario
2018-01-16 14:22:23 +00:00
Oscar Key
0158d976c8 Merge "Add FLAG_INCREMENTAL and FLAG_NON_INCREMENTAL to performBackup()." 2018-01-16 11:17:00 +00:00
Oscar Key
7b1d974d71 Add FLAG_INCREMENTAL and FLAG_NON_INCREMENTAL to performBackup().
These indicate if backup manager passed any previous state to the backup
agent when building a backup. The transport will use these to decide
whether to clear any existing encryption related state for the app.

I left the new flags as @hide for now.

Bug: b/71792427
Test: Tested manually with a buid of GmsCore updated to process the new
flag. I am attempting to write a robolectric test.

Change-Id: Ica0f6f578cd7d1ad29af532a45a2ee6685c84747
2018-01-15 18:22:29 +00:00
Bernardo Rufino
5a484dc45b Binding on-demand #9: selectBackupTransport[Async]
Migrate selectBackupTransport()/selectBackupTransportAsync() to binding
on-demand. To mimic the bind-if-needed behavior that existed before for
selectBackupTransportAsync we now register-if-needed in the selection.
This means a new registerTransport() method was created in the
TransportManager. I intend to use this method with only few
modifications for the first-binding code.

Change-Id: I39661cff0f7b2f8a27da37905dcd93e0aa9b1178
Ref: http://go/br-binding-on-demand
Bug: 17140907
Test: m -j RunFrameworksServicesRoboTest
Test: adb shell bmgr transport <transport>, observe logs
Test: Robolectric tests for TransportManager will go in registration CL
2018-01-09 12:37:06 +00:00
Bartosz Fabianowski
d8a0cb7556 Start BackupManagerConstants content observer
BackupManagerConstants has a content observer that is meant to be
notified whenever backup settings change. However, that observer is
never registered.

Bug: 71622864
Test: cts-tradefed run cts-dev --module CtsBackupHostTestCase
Change-Id: Icbd90ef3af83dd2f29e26a5d787505bcf5681154
2018-01-08 10:55:32 +01:00
Michal Karpinski
0b25273da2 Merge "Ancestral restore versioning for PackageManagerBackupAgent" 2018-01-05 22:46:08 +00:00
TreeHugger Robot
172bb61656 Merge "Remove transport dir name from TransportClient" 2018-01-05 18:35:55 +00:00
TreeHugger Robot
a068cd68c0 Merge "Binding on-demand #8: Miscellaneous usages" 2018-01-05 18:21:53 +00:00