Commit Graph

340 Commits

Author SHA1 Message Date
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
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
Philip P. Moltmann
7323eecba3 Disable installation via adb restore
Test: tried to install apk via adb restore -> was not installed
Bug: 16298482
Change-Id: I91e61cd229499f2ba8519554f4836f1e0b9f6404
2018-01-04 13:26:28 -08:00
Philip P. Moltmann
79c238ada6 Use modern install method in backup service
Test: adb backup -apk myApp -f backup ; adb restore backup
Change-Id: I2bbcb0487ecc525a6dc8a2693b15ce624db275b0
2018-01-04 13:26:28 -08:00
Michal Karpinski
a8a01bffdf Ancestral restore versioning for PackageManagerBackupAgent
Introduced usage of ANCESTRAL_RECORD_KEY, based on which value
the restore set can be parsed in multiple ways by different
RestoreDataConsumers.

Test: manual - D2D and cloud for different scenarios (O->P, P->P, Q->P)
Test: O->P and P->P will be covered by our automatic e2e tests
Test: a CTS test will be added to verify that backups of PMBA
      generated on Android P+ always contain the ANCESTRAL_RECORD_KEY,
      and it's always the first key
Bug: 64988620
Change-Id: I4634f403da4aefdeb09dc5ca621c4ac349583251
2018-01-04 13:52:03 +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
Bartosz Fabianowski
9fcc8ffd7b Send backup success notification to background apps as well
When the backup manager is configured to notify one or more apps of
successful backups, the notifications should be sent to apps that are
currently stopped as well.

Bug: 63885845
Test: cts-tradefed run cts-dev --module CtsBackupHostTestCase
Change-Id: I7086aee105229e0f8db4b1ec26639d53a4e0af37
2018-01-03 09:14:47 +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
7b3701a32c Log d when transport updates its attributes
Bug: 17140907
Test: Triggered an update and checked logs
Change-Id: I21926086ec0078872f3840737f77f79417178f6c
2017-12-20 15:35:52 +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
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
Christopher Tate
1d99c391ec Cancel alarms & jobs when an app's data is cleared
In the same bit of code, fix a system restore issue:  in the
course of setup + restore, we reestablish permission grants and
notification state up front for the to-be-restored app, and
then bring in its data.  However, a data wipe is part of the
prologue for that data delivery -- so we were inadvertently
unwinding the permission grants and notification state restore
that we'd just performed.  Now, we distinguish the restore flow
from other clear-data operations so we don't unwind that operation.

Finally take the opportunity to elide a lot of copypasta code into
a single predicate-driven implementation.

Bug: 67508896
Bug: 69538432
Test: atest android.app.cts.AlarmManagerTest

Change-Id: I15c912c3c99645599ae9bd6fb7337fa86b4e5757
2017-12-08 13:53:42 -08:00
Bernardo Rufino
f93a0918b6 Binding on-demand #4: PerformClearTask usage
Migeate the clear flow.

Change-Id: Id268f772ae0f7a88b3e060c9597d777e0b73121a
Ref: http://go/br-binding-on-demand
Bug: 17140907
Test: adb shell bmgr wipe <transport> <package> and observed 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
2017-12-06 11:55:56 +00:00
Dianne Hackborn
3accca05dd Add major version code to platform.
It turns the version code into almost a 64-bit integer, with the
new major part being the upper 32 bits.

The only tricky part about this is the backup manager, since it
stored 32-bit version codes in its backup data sets.  This is dealt
with by, when the major version code is not 0, writing MIN_INT as
the version code and following that by the full long version code,
which we can detect when reading.  Note that this makes backup sets
containing apps with major version codes incompatible with older
versions of the platform.

Bug: 64459786
Test: Added in Change-Id: Iab8a682b62103babd6c16a56b8dc1e97d7078658
Change-Id: Ibfffe235bbfcf358b3741abd3f7197fdb063d3f3
2017-12-04 13:02:10 -08:00
Bernardo Rufino
728dceac63 Remove old BackupManagerService
As discussed, only removed the class, local interface and trampoline
still exist. That will go into a next CL.

Bug: 65823538
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
Test: adb shell bmgr backupnow <kv and full-backup packages>
Test: adb backup & adb restore
Change-Id: Ifcb4c02e364b8c4899ff376ff20cd8c89fc1af28
2017-12-01 16:21:23 +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
4719ed513e Binding on-demand #2: PerformFullTransportBackupTask usage
Migrate the full-backup task to use binding on-demand

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: I15abe970db0b9858e0e2e4eb666358db3a9d50ad
2017-11-24 11:02:45 +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
Peter Visontay
d85c85f9d0 Merge "In backup/restore code wrap Binder.restoreCallingIdentity() in finally{}." 2017-11-03 11:53:20 +00:00
Makoto Onuki
2eccd02628 Make the battery saver knobs hidden public,
so other components (system UI, settings, etc) can use them.

Bug: 68769804
Test: Build & presubmit
Change-Id: I30fe78e49d2187bee7c7aeba735cd9c26fc332a5
2017-11-01 14:49:10 -07:00
Peter Visontay
a9565cb487 In backup/restore code wrap Binder.restoreCallingIdentity() in finally{}.
Test: none.
Bug: 68755611
Change-Id: Ic4326f3b50060be117ca7556cde15b0db10cc239
2017-11-01 18:44:01 +00:00
Michal Karpinski
387267eafe Don't overly call transport.transportDirName()
Test: runtest -p com.android.server.backup frameworks-services
Bug: 63401141
Change-Id: I485bd98f805fd6be689765e77a582820c53e9bc0
2017-10-20 11:00:38 +01:00
Christopher Tate
8808609896 Fix backup server
Mea culpa.  Properly do the trampoline indirection dance so
that we can asynchronously bring up the service components.
We'd previously accidentally introduced an ordering problem such
that the init process... didn't.

Bug: 67676879
Test: 'adb shell dumpsys backup' and 'adb shell bmgr list transports' after boot
Change-Id: I3e9a904a009f4745727e5eb13f7307c6deda1e4f
2017-10-12 13:37:02 +01:00
Christopher Tate
73093a477d Backup OS service now processes unlock off the main thread
We now perform the slow work of unlocking the primary user on the
background handler thread rather than on the main thread.  This
is expected to shave 150ms+ off of our total unlock latency on
some products.

Bug: 63389800
Test: manual
Change-Id: I70be032a64de3270476615fd9dde1b427e19aa91
2017-10-05 14:45:17 -07:00
Christopher Tate
66c94726c9 Fix system server crash when told to init backup transports
Refactor + merge gone awry; and pay attention to typed vs typeless
use of toArray().

Change-Id: I031ded949a6e3f2a296c9bf007129e4ebf796a4b
Fix: 67419822
Test: adb root && adb wait-for-device && \
      adb shell cmd activity broadcast -a android.app.backup.intent.INIT
2017-10-04 16:00:24 -07:00
Christopher Tate
43f2d3d337 Reduce lock interactions in backup transport management
1. process package update broadcasts on our background thread rather
   than on the main looper thread

2. don't synchronize unnecessarily around access to simple
   transport metadata

We mustn't block the main looper thread for anything that might wind
up interlocked with calls to the transport, because those might take
arbitrary amounts of time.  We were previously entering such an
implicitly interlocked code path during package-changed broadcast
handling, and in pathological cases were causing the watchdog to
restart the system.  This situation is addressed in a couple of ways:
first, by no longer performing package-update work on the main looper
thread at all; and second, by eliminating lock reliance entirely from
data-access paths that don't actually need it.

Bug: 65438129
Bug: 64133971
Test: manual + CTS
Change-Id: I361ad4a0729f319db7339bd341a6d33aa3b64fed
2017-09-29 12:20:34 -07:00
Michal Karpinski
bef5f4a64f Switch to use RefactoredBackupManagerService
Keeping the legacy BackupManagerService for now, but we'll remove
it in a few weeks if there's no issues noticed.
In case of any problems, this CL can be cleanly reverted as a fallback.

Test: pretty much all we got in store
1) runtest -p com.android.server.backup frameworks-services
2) make gts -j40 && gts-tradefed run gts -m GtsBackupHostTestCases
3) make cts -j40 && cts-tradefed run cts -m CtsBackupTestCases
4) make pts -j40 && pts-tradefed run pts -m PtsBackupHostSideTestCases
5) manual: "adb shell bmgr backupnow --all" and then cloud restore,
   D2D scenarios (both as source and target)
Bug: 65823538
Change-Id: I701764995c4fe2611a4941aecb45315aa457658e
2017-09-28 14:10:56 +01:00
Michal Karpinski
9464a3160d [RefactoredBMS] Use buffered DataInputStream vs RandomAccessFile
This CL replicates ag/2239004 in RefactoredBMS.

Test: runtest -p com.android.server.backup frameworks-services
Bug: 37973765
Change-Id: Id83445d433987730c5cdf9b9684b647baf3c3d1b
2017-09-19 11:44:41 +01:00
Michal Karpinski
c1741631d8 [RefactoredBMS] Refresh in-memory SharedPreferences instances after restore
This CL replicates ag/2284557 in RefactoredBMS (only the BMS part, the
rest is already live code).

Test: runtest -p com.android.server.backup frameworks-services
Bug: 37973765
Change-Id: I4f6cb85b879e0ee7b2b20ac998977f8c6d8fdfe0
2017-09-19 11:08:15 +01:00
Michal Karpinski
9d395bb3e2 [RefactoredBMS] Tear down agent after preflight rejection
This CL replicates ag/2520584 in RefactoredBMS.

Test: runtest -p com.android.server.backup frameworks-services
Bug: 37973765
Change-Id: I13ac110dbc197df473dd6a0cf24866133dfefab8
2017-09-19 10:46:43 +01:00
Michal Karpinski
fcd615fad2 [RefactoredBMS] Do not perform backup/restore of instant apps
This CL replicates ag/2256021 in RefactoredBMS.

Test: runtest -p com.android.server.backup frameworks-services
Bug: 37973765
Change-Id: Icf615b97025aa09681f9d25b1de3f94e60a45ee4
2017-09-19 10:34:12 +01:00
Michal Karpinski
5c90ff0f26 [RefactoredBMS] Correct scope of "disabled?" check viz backup/restore decisions
This CL replicates ag/2204901 in RefactoredBMS.
Also adjusts tests and adds new ones for appIsDisabled method.

Test: runtest -p com.android.server.backup frameworks-services
Bug: 37973765
Change-Id: Ibaa15ba935ca1ada657e912b18a5a0b3bcffd00f
2017-09-18 17:00:22 +01:00
Michal Karpinski
5246299c58 [RefactoredBMS] Don't mix "current dataset" tokens for different backup transports
This CL replicates ag/2191170 in RefactoredBMS.

Test: runtest -p com.android.server.backup frameworks-services
Bug: 37973765
Change-Id: Ic3fd528071cef8143e2c3f6b659722f951f0deb9
2017-09-18 14:32:47 +01:00
Michal Karpinski
f9b74cc7ef [RefactoredBMS] Ensure backup doesn't reuse ack tokens nearby in time
This CL replicates both ag/2551800 and ag/2613950 in RefactoredBMS.

Test: runtest -p com.android.server.backup frameworks-services
Bug: 37973765
Change-Id: I5e42dee67d587adabbfb81de03f3205d92a46add
2017-09-18 14:18:17 +01:00
Michal Karpinski
78ec67a264 [RefactoredBMS] Eliminate a race condition that could lead to
calling PBT#finalizeBackup() twice

This CL replicates ag/2510127 in RefactoredBMS.

Test: runtest -p com.android.server.backup frameworks-services
Bug: 37973765
Change-Id: Ic8571c08dd92386d0e4f79d7866aeb0f19f38106
2017-09-18 13:44:31 +01:00
Michal Karpinski
f95cf5d9c3 [RefactoredBMS] Offload the mRunningFullBackupTask.handleCancel()
call from the main thread to another thread

This CL replicates both ag/2135862 and ag/2465381 in RefactoredBMS.

Test: runtest -p com.android.server.backup frameworks-services
Bug: 37973765
Change-Id: I895cb27bc910d9970ab1c33cd54a773b8f9b6cf6
2017-09-18 13:34:44 +01:00
Michal Karpinski
3f09d6cf3b [RefactoredBMS] Add log before doRestoreFinished is called on BackupAgent.
This CL replicates ag/2140301 in RefactoredBMS.

Test: runtest -p com.android.server.backup frameworks-services
Bug: 37973765
Change-Id: I2c2795c89035dd6c38aee8aec4e4a95cfdba0846
2017-09-18 13:23:51 +01:00
Michal Karpinski
3d87a5bfaf [RefactoredBMS] Add tracing for UserState and a few services
This CL replicates ag/2500023 in RefactoredBMS.

Test: adb shell am instrument -w -e package com.android.server.backup com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
Bug: 37973765
Change-Id: I3d638a98ff61954797d9e5a70a28e0c2962112c6
2017-09-18 12:25:50 +01:00
Michal Karpinski
a7924a6795 [RefactoredBMS] Call removeMessages() only for certain operations in RefactoredBackupManagerService#handleCancel()
This CL replicates ag/2147459 in RefactoredBMS.

Test: adb shell am instrument -w -e package com.android.server.backup com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
Bug: 37973765
Change-Id: I55d1825477ce82c47fd5850bf00f34ee8c1b9fc0
2017-09-18 12:20:34 +01:00
Tim Zheng
bcc0c1d113 BackupManagerService uses BackupManagerConstants.
This change update the backup manager service to use newly created
BackupManagerConstants for some configuration parameters.

This is part 2 of the change.

Test: Used 'adb logcat -b system' to verify the settings worked.
Bug: 63351792
Change-Id: Ia6c9a2afbbaf3481a742a67c48ce9995c1ce6483
2017-09-15 11:50:09 -07:00
Tim Zheng
cc1e76a4b3 Add a backup manager constants secure settings.
This change add one secure settings which is a key value list consisting
of 7 individual settings; it also provides a class to get these settings
and use the default values specified in default.xml file when the settings
are missing.

This is the first part of a 2 part change. A subsequent change will use
these settings in backup service manger for setting up backup frequency.

Test: This change builds. Manual tests will be included in part 2 of the
change.
Bug: 63351792
Change-Id: I62baddbf3e0b96af6b7de3dfdeac3479e5b3ded8
2017-09-14 16:32:21 -07:00
Bernardo Rufino
5176c02501 Add logs to IOExceptions during adb backup
Test: Run adb backup
Bug: 65435587
Change-Id: I744cb2878654b716858d7c9bedeb12fb9978df6b
2017-09-13 14:10:20 +01:00