142 Commits

Author SHA1 Message Date
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
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
Annie Meng
2ab9c4c953 Rename Robo tests to BackupManagerServiceTest
Bug: 71988336
Test: m -j RunFrameworksServicesRoboTests
Change-Id: I79acd816e2e1fc320fd2bea39692ed52cf56a67e
2018-01-17 16:52:46 +00:00
Annie Meng
9ec0407715 Move BackupManagerServiceTest to Robolectric framework
Bug: 71988336
Test: m -j ROBOTEST_FILTER=BackupManagerServiceRoboTest RunFrameworksServicesRoboTests
Change-Id: I81c45267ef98b66c05383bfdca9a1b5ab4ccbfbd
2018-01-17 16:50:45 +00:00
Bernardo Rufino
4e588baaa4 Merge "Move event logging to TransportClient and add connection event" 2018-01-17 15:39: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
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
Annie Meng
789bf28126 Update transport tests for binding on-demand to support SDK 26 API
After Robo 3.5.1 upgrade, these tests should support the new SDK.

Bug: 69153972
Test: m -j RunFrameworkServicesRoboTests
Change-Id: I12be8668b0c8bb7933cc1a30717356d86f1f3737
2018-01-15 12:31:58 +00:00
TreeHugger Robot
0c154bf670 Merge "Adopt robolectric 3.6.1" 2018-01-10 21:28:41 +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
James Lemieux
0f5bba003b Adopt robolectric 3.6.1
Bug: 71596155
Test: make RunSettingsLibRoboTests
Change-Id: I0f8e538238c42fed89bc4778a6a717f2eddac9b7
2018-01-06 00:28:25 -08: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
Bernardo Rufino
516ac95746 Remove transport dir name from TransportClient
To be able to re-use the TransportClient infra for transport
registration, I need to remove transport dir name property from
TransportClient because it's not available before registration
itself. As a result callsites that used getTransportDirName()
from TransportClient will have to go through the
TransportManager for that. Bryan suggested that the
TransportClient wasn't the best place for the property before.

Ref: http://go/br-binding-on-demand
Bug: 17140907
Test: m -j RunFrameworksServicesTests
Change-Id: I3fa335faf97d63adfad1a929336073a70fc8bc02
2018-01-05 16:57:51 +00:00
Bernardo Rufino
fa51853ae5 Binding on-demand #8: Miscellaneous usages
Migrate usages of the transport binder to binding on-demand:
* getDestinationString()
* isAppEligibleForBackup()
* dump()

For getDestinationString() we'll be introducing an invisible bug for
people that haven't updated GMSCore to include the usage of
updateTransportAttributes() API introduced in earlier CL. The bug is
that that text won't change, it'll remain constant. It's invisible
because currently only place that uses that method is Settings in some
circumstances that depend on the transport, and those circunstances
don't happen with our transports. Check http://ag/1831025.

For isAppEligibleForBackup(), a new filterAppsEligibleForBackup() is
created and there we bind on-demand.

Change-Id: Idc9e31f0e8eda8531e204c05a84fafdaf0247d08
Ref: http://go/br-binding-on-demand
Bug: 17140907
Test: adb shell dumpsys backup, observe destination of transports
Test: adb shell bmgr backupnow --all, observe only eligible apps got backed-up
Test: Force-loaded settings screen and observed destination string
Test: m -j RunFrameworksServicesRoboTests
2018-01-05 16:33:33 +00:00
Bartosz Fabianowski
7f97228e29 Address review comments from 02a1c08
This CL addresses a few remaining review comments from 02a1c08,
"Add notification on succesful backups"

Bug: 63885845
Test: make RunFrameworksServicesRoboTests
Change-Id: Id42777a213c37400f24f6ecb11ecacbd55a2e123
2018-01-03 12:43:09 +01:00
Bernardo Rufino
a67d10763a Merge "Binding on-demand #7: PerformInitializeTask usage" 2018-01-02 11:34:33 +00:00
Denis Kuznetsov
02a1c08096 Add notification on succesful backups
Bug: 63885845
Test: make RunFrameworksServicesRoboTests

Change-Id: I6c8d04de7f5d7e82d695b1bf36de0aa27452db19
2017-12-28 20:12:03 +01:00
Bernardo Rufino
79155590e6 Binding on-demand #7: PerformInitializeTask usage
Migrate transport initialization task to binding on-demand. Added
Robolectric tests for the task as well.

Bug: 17140907
Test: m -j RunFrameworksServicesRoboTest
Test: adb shell bmgr init <transport>, observed logs & transport dir
Change-Id: I2d6c1acd31741169080edef2f938fabf43b0649a
2017-12-22 17:06:20 +00:00
Bernardo Rufino
2447687352 Use testng for utilities in tests
Frameworks services tests and cts already use it.

Test: m -j RunFrameworksServicesRoboTests
Change-Id: Ib613997e9a7278f6b424cd4ce4aa16c112756564
2017-12-21 11:46:00 +00:00
Bernardo Rufino
7f14edea1d Binding on-demand #6: Transport attributes usage
Migrate the attribute queries from the Transport to the
TransportManager. Migrate all calls except currentDestinationString
because that's the one that changes and we should only migrate
after we have GMSCore that implements the push-from-transport
model.

Looking at method recordInitPendingLocked(), we only sent
MSG_RETRY_INIT if the transport threw while calling transportDirName
or the binder was null. With binding on-demand both of these cases
can't happen - i.e. we can't fail anymore. So, I removed the
message entirely.

Change-Id: I45a305704274c8b0c88637e3ccafc658639b2dfa
Ref: http://go/br-binding-on-demand
Bug: 17140907
Test: m -j RunFrameworksServicesRoboTests
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: runtest -p com.android.server.backup frameworks-services
Test: adb shell bmgr backupnow <packages>
Test: adb shell bmgr fullbackup <packages>
Test: adb shell cmd jobscheduler run -f android <job_id>
Test: adb shell bmgr enable false (being enabled before)
Test: adb shell dumpsys backup
Test: adb shell bmgr init <transport>
Test: Observed logs and used debugger to check proper code was being
Test: called in above commands
2017-12-15 16:32:30 +00:00
Bernardo Rufino
c4cded9c80 Merge "Binding on-demand #5: PerformUnifiedRestoreTask usage" 2017-12-14 13:19:46 +00:00
Bernardo Rufino
90a8802328 Update Roboletric to 3.5.1
To be able to migrate Robolectric and bump SDK we have to load our classes from
the system class loader instead of the android jars. This wasn't a
problem before because the classes weren't in the jars correspondent to the old
SDK that the tests were using. To be able to do this I created a custom test
runner and a custom annotation to be used in tests to load the specified
classes from the system class loader. Check comments on file. Also, made changes
to be compatible with new Robolectric version and bumped SDK.

Bug: 69254249
Test: m -j RunFrameworksServicesRoboTests
Change-Id: I538ef70cfae8ebeea047f275b9920cb2e814f4da
2017-12-13 20:23:31 +00:00
Bernardo Rufino
998fdaa636 Binding on-demand #5: PerformUnifiedRestoreTask usage
Migrate restore flow and related.

Change-Id: Ib61863e401067d7d4a9669982be8b3d87af0caa2
Ref: http://go/br-binding-on-demand
Bug: 17140907
Test: adb shell bmgr restore <set> <package> and observed logs
Test: adb shell bmgr restore <set> and observed logs
Test: Backed-up and re-installed app, observing logs
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: Looking into adding GTS/CTS for restore scenarios
2017-12-11 14:09:41 +00:00
Bernardo Rufino
ab953332bc Binding on-demand #3: updateTransportAttributes() API
This CL introduces the updateTransportAttributes() API to be used by the
transport hosts. It doesn't actually use the description attributes yet,
this will go in another CL. This is because I want to test that CL
together with transport usage. Tests are lacking for TransportManager
and BMS, I'll still add them, but I'm trying to migrate Robolectric
first.

Ref: http://go/br-binding-on-demand
Bug: 17140907
Test: make RunFrameworksServicesRoboTests
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
Change-Id: I56f7b5a5026d21d8f11afb371d5560d4913c5f2a
2017-11-30 14:26:13 +00:00
Bernardo Rufino
86d0573340 Merge "Binding on-demand #1: TransportClient infra + PerformBackupTask usage" 2017-11-22 14:23:04 +00:00
Bernardo Rufino
af547f4a15 Binding on-demand #1: TransportClient infra + PerformBackupTask usage
This CL introduces TransportClient infra-structure and integration in
TransportManager, plus a few unit tests. Also start using binding
on-demand for PerformBackupTask.

Ref: http://go/br-binding-on-demand
Bug: 17140907
Test: make RunFrameworksServicesRoboTests
Test: runtest -p com.android.server.backup frameworks-services
Test: adb shell bmgr backupnow <packages>
      With transports manually unbound and also canceled the operation a
      few times. Then inspected TransportClient logcat
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: Manually unbound before GTS/CTS above.
Change-Id: I63cbde27131205787d90663603a4f8f61d187607
2017-11-21 15:01:47 +00:00
Maurice Lam
d42f99c520 Specify the version for Robolectric version
The previous default version was 3.1.1, so specifying all existing
projects to that. Please migrate to new version (3.4.2 as of today)
at your convenience.

See robolectric.org/migrating for instructions on migrating.

Test: m RunFrameworksServicesRoboTests RunCarMessengerRoboTests \
    RunStorageManagerRoboTests RunCarSettingsRoboTests \
    RunEmergencyInfoRoboTests RunManagedProvisioningRoboTests \
    RunTurboRoboTests RunStorageManagerGoogleRoboTests \
    RunBluetoothRoboTests

Change-Id: Ife5a39b81206ec475bba5c4042258a37ad24707d
2017-11-14 13:10:36 -08:00
Bernardo Rufino
b7e9ac8f2c Explicit Roboletric version for runner
* Our test target uses default roboletric target
(platform-robolectric-prebuilt), which is 3.1.1.
* Runner was updated to 3.4.2 recently (ag/3181301).
* `make RunFrameworksServicesRoboTests` broke because
org.robolectric.res.builder.DefaultPackageManager doesn't exist in new
verion (http://robolectric.org/migrating/#packagemanager-1).

Hardcoded version in our target until we migrate to new version (I tried
but there were some other errors)

Test: make RunFrameworksServicesRoboTests
Change-Id: Ie934dedec3340620611f3d72b75e5eefba430f35
2017-11-13 18:21:07 +00:00
Bernardo Rufino
58dd6c376e Adjust services robotest makefile
In preparation for transport-related tests needed to make those fixes so
that Mockito annotations would work.

1. Switched from mockito-target-minus-junit4 to
mockito-robolectric-prebuilt. Otherwise we would get dexcache == null
error (similar to
https://groups.google.com/a/google.com/forum/#!topic/robolectric-users/gV0_59Kj2ME/discussion)

2. Removed unused frameworks-base-testutils because it included the
ill-suited mockito dependency (as per 1).

3. Tidied up by moving test dependencies to actual test target.

Test: make RunFrameworksServicesRoboTests
Change-Id: Idd4f13a9aa0327d74b58361ad02aa3313d30ac99
2017-11-10 11:21:52 +00:00
Maurice Lam
458d6a87d3 Remove dependency on platform-system-robolectric
Dependency on platform-system-robolectric is not needed when mockito
is not necessary.
If mockito is needed, add a static dependency on
mockito-robolectric-prebuilt.

Test: m RunFrameworksServicesRoboTests
Bug: 38456058
Change-Id: I60ac070125cf157225247561336288dfe97789c6
2017-09-06 14:38:07 -07:00
Artem Iglikov
026e93323e Add tests for TransportManager#ensureTransportReady().
This involves some refactoring, so that TransportManager doesn't use API
not available in pre-O.

Bug: 37616038
Test: make RunFrameworksServicesRoboTests
Change-Id: I6a79bdbbee2a37a9fecff7865bdec37be2c7e59a
2017-09-01 15:28:31 +01:00
Artem Iglikov
19e122754f Add more tests for TransportManager.
Bug: 37616038
Test: make RunFrameworksServicesRoboTests
Change-Id: I1120c181ffc898202e558f0dc73a6f1d2c10330f
2017-09-01 13:31:52 +01:00
Artem Iglikov
bd476eae4b Update TransportManager tests.
This applies changes that disappeared for some reason from ag/2314382

Bug: 37616038
Test: make RunFrameworksServicesRoboTests
Change-Id: Iabfafd8c6afaac7304194f7645d08ef9e6f3b3aa
2017-09-01 11:03:03 +01:00
Artem Iglikov
5ed1dab192 Add a test for TransportManager#onPackageAdded().
Also set up robolectric tests for framework services.

Bug: 37616038
Test: make RunFrameworksServicesRoboTests
Change-Id: Ia27a58365a0826ec5bc9f8a7544024b52cfbb3ec
2017-08-31 16:59:28 +01:00