309 Commits

Author SHA1 Message Date
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
Christopher Tate
39be7faab2 Merge "Set flags on the correct Intent, please" into oc-mr1-dev am: 33894b2998
am: a80316daa3

Change-Id: I486096da329ccfed44ba6e5e9f6e14af47db8932
2017-09-04 11:15:39 +00:00
Christopher Tate
ed961d90ea Set flags on the correct Intent, please
Bug: 65115426
Test: passes CTS backup suite
Change-Id: I497d077f563fef7b0800df626d15651c721d4ca7
2017-09-01 13:39:10 -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
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
Bernardo Rufino
0d0d180305 Merge "Merge "Solve AppBackupUtils.signaturesMatch() policies" into oc-mr1-dev am: a743c01d00" into oc-mr1-dev-plus-aosp
am: 13889d75c7

Change-Id: Ifd1afbf731cfb10d2e37d86d0c5b1d64011eb9d6
2017-08-22 20:02:06 +00:00
Bernardo Rufino
cbcc34e4da Solve AppBackupUtils.signaturesMatch() policies
Now we reject unsigned apps, either source or target. Also
added javadoc.

Bug: 37977154
Test: runtest -p com.android.server.backup frameworks-services
Change-Id: I44df43d5322ae64d97f8b19c20db508033301f91
2017-08-22 15:54:04 +01:00
TreeHugger Robot
5f1d35ee21 Merge "Locking changes in ProcessedPackagesJournal" 2017-08-09 14:09:17 +00:00
Robert Berry
a1109ef8da Locking changes in ProcessedPackagesJournal
A follow-up CL to apply the code feedback from the first one.

Bug: 36850431
Test: adb shell am instrument -w -e package com.android.server.backup com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
Change-Id: I8785eb358658757b329ac871194243c47e6d87a9
2017-08-09 13:12:05 +01:00
Robert Berry
bfcff7be30 Merge "Do not remove uninstalled packages from journal" into oc-mr1-dev am: b152fb8d30
am: dae011cc5a

Change-Id: I2940aafdf07b572ee69d988599a2f8084c290dab
2017-08-08 21:43:36 +00:00
TreeHugger Robot
b152fb8d30 Merge "Do not remove uninstalled packages from journal" into oc-mr1-dev 2017-08-08 21:19:41 +00:00
Robert Berry
6d2fbdf10d Extract class AppsBackedUpOnThisDeviceJournal from BackupManagerService
Puts all the logic for remembering what apps have been backed up on
the current device into own class. Also fixes bug where if an app was
uninstalled, it was removed from the journal. As the journal is used
to decide what restore set to use after a fresh install of an app (as
at this point we do try to restore previous state if it's available)
it doesn't make sense to forget apps that were uninstalled.

Bug: 36850431
Test: adb shell am instrument -w -e package com.android.server.backup com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
Change-Id: I9300883e139ee0773acbf4a09b08c7f5955c66e5
2017-08-07 11:45:04 +01:00
Michal Karpinski
c2e30cd5c9 Merge "Reintroduce the contract for random token to be non-negative" into oc-dr1-dev
am: 810c312a29

Change-Id: Ida86b2e9f68683c88db24bcbb16eaf14ce8f2d94
2017-07-31 19:03:13 +00:00
Robert Berry
e8564b752d Do not remove uninstalled packages from journal
The point of this journal is to remember whether a package was ever
backed up on the device, so as to know, when re-installing a package,
which restore set to restore from (i.e., the restore set of the
current device - if the package has been backed up on the current
device - or the restore set of the ancestral device).

Bug: 63794452
Test: Manual
Change-Id: I6519ed625124487ffb09b7c3899550e4d791e0df
2017-07-31 16:40:33 +01:00
Michal Karpinski
fc637c168e Reintroduce the contract for random token to be non-negative
Clients like adb backup/restore confimation activity
depended on it.

Test: gts-tradefed run gts -m GtsBackupHostTestCases
Bug: 64042228
Bug: 63691912
Bug: 63695367
Change-Id: I09e348f7570bcdbad2d91e79f90a248b17c82940
2017-07-27 16:02:15 +00:00
Christopher Tate
3a419bee91 Merge "Ensure backup doesn't reuse ack tokens nearby in time" into oc-dr1-dev
am: 672f578fd1

Change-Id: I110ab6b96ac3fd866ace40fbe47614e2ad73a787
2017-07-21 18:27:43 +00:00
Christopher Tate
6935755f43 Ensure backup doesn't reuse ack tokens nearby in time
We've seen at least one incident in the field that suggests we
used the same identifying token in back to back operations, which
breaks certain invariants in the asynchronous-completion bookkeeping.
Harden against this by making sure that we don't reuse tokens in
nearby proximity.  This is done by making the low 8 bits a sequence
count, i.e. guaranteed unique within the last 256 operations, while
keeping the upper bits random so that apps can't guess at correct
tokens.

Fix 63691912
Fix 63553575
Test: CTS backup pass to completion plus manual inspection

Change-Id: I321c3a2b3f4203836800bb72db7332bd82e54aaf
2017-07-20 11:03:41 -07:00
Robert Berry
a780907d9f Use try with resources in BackupManagerService
Resources are not handled in a consistent manner, or even consistently
closed.

Bug: 36850431
Test: adb shell am instrument -w -e package com.android.server.backup com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
Change-Id: I9ca2bd8d532af385174a107ee7fbe113575c5bbb
2017-07-17 10:01:53 +01:00
TreeHugger Robot
88783f22fe Merge "Move duplicated union of HashSets logic into helper class" 2017-07-14 16:56:05 +00:00
TreeHugger Robot
cb2bb89878 Merge "Move logic for backup journal into its own class" 2017-07-14 16:02:26 +00:00
Robert Berry
c89535567b Move duplicated union of HashSets logic into helper class
Bug: 36850431
Test: adb shell am instrument -w -e package com.android.server.backup com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
Change-Id: I83a95919d7b85131cc7ad73575d7a89c7f2d78f9
2017-07-14 14:10:51 +00:00
Robert Berry
9699fe319e Pull backup password logic out of BackupManagerService
This makes it easier to follow what's going on. Also makes it easy for us to
add unit tests for this component.

Bug: 36850431
Test: adb shell am instrument -w -e package com.android.server.backup com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
Change-Id: Ifb85f1573bcfb7da26febed35d49454614b5d975
2017-07-14 14:51:16 +01:00
Robert Berry
c31a839fd3 Move logic for backup journal into its own class
Refactor to further simplify BackupManagerService, which currently has too
many responsibilities. Also adds unit tests.

Bug: 36850431
Test: adb shell am instrument -w -e package com.android.server.backup com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
Change-Id: Id433d7604c22c8b6f0d524a9bf9e83053facc0ca
2017-07-14 14:45:22 +01:00
Christopher Tate
1ff9475ea0 Merge "Tear down agent after preflight rejection" into oc-dr1-dev am: 47303ec66b
am: 19bb6c35ca

Change-Id: I17cbc0a91b65d755965ac4479d7656a7dbeef109
2017-07-13 20:05:40 +00:00
Christopher Tate
e989348ca3 Tear down agent after preflight rejection
We were failing to tear down a full-backup target process in several
error situations (preflight, quota exceeded, unforeseen), leaving the
app in an incoherent execution state for general operation.  Now we
properly tear down the target in all full-backup early exits.

Fix #63540605
Test: run cts -m CtsBackupTestCases -t android.backup.cts.BackupQuotaTest

Change-Id: Id8f6fe0381e85a8d8e4015fc6fd34bb840859e7a
2017-07-10 17:25:19 -07:00
Michal Karpinski
1a7d868804 Merge "Eliminate a race condition that could lead to calling PBT#finalizeBackup() twice" into oc-dr1-dev am: 150fec445a
am: 9ccbc85470

Change-Id: I9624a73cf044bf8dce07870045b253063595c0b5
2017-07-10 21:41:24 +00:00
Michal Karpinski
015df962d5 Eliminate a race condition that could lead to calling PBT#finalizeBackup() twice
Calling finalizeBackup() the second time will most probably lead to underholding
the wakelock and system crash.

Bug: 63156509
Test: manual
Change-Id: Ic995ba4a65d749b80bf1f1d226d35a279a0d1b25
2017-07-10 12:00:14 +01:00
Jeff Sharkey
1c7736d2a7 Add tracing for UserState and a few services.
Both BackupManager and AppWidgetManager internals are taking a long
time to process user unlock events, so add tracing details.  Also add
general tracing to show all UserState changes.

Bug: 32859180
Test: builds, boots
Change-Id: I82f4f7220ccb695941acd6bc45cd67a5fae8a4d2
2017-07-06 11:55:44 -06:00
Michal Karpinski
a96694b49b Merge "Fix an NPE when cancelling full backup in BMS#endFullBackup()" into oc-dev
am: 0d1b1a253a

Change-Id: Idd633c178416ababe623f02327a830939ee769ba
2017-06-27 21:47:36 +00:00
Michal Karpinski
21d156c310 Merge "Fix an NPE when cancelling full backup in BMS#endFullBackup()" into oc-dev am: 0d1b1a253a am: 4b48d48a19
am: 2ceefbf767

Change-Id: I1cef46b35a89fd91dce268089757fc2edcccbff4
2017-06-27 21:02:57 +00:00
Michal Karpinski
2ceefbf767 Merge "Fix an NPE when cancelling full backup in BMS#endFullBackup()" into oc-dev am: 0d1b1a253a
am: 4b48d48a19

Change-Id: I6e35567cd376666fefb1e9356ce7325595507f77
2017-06-27 20:56:08 +00:00
Michal Karpinski
077d637193 Fix an NPE when cancelling full backup in BMS#endFullBackup()
Bug: 63000171
Test: it's just a nullcheck that compiles
Change-Id: I90faa5577f2fd656bb4f7b6af39494590a77e3bf
2017-06-27 15:09:01 +01:00
TreeHugger Robot
fd4b85ad1c Merge "Fix #62798589 : requestBackup() needs to check enable/provisioned state" 2017-06-21 00:01:15 +00:00