286 Commits

Author SHA1 Message Date
Colin Cross
eb652a47a1 Convert services to Android.bp
See build/soong/README.md for more information.

Test: m checkbuild
Change-Id: I417409281c928ea667d937090d2a0d9d72a449a2
Merged-In: I417409281c928ea667d937090d2a0d9d72a449a2
Exempt-From-Owner-Approval: trivial conversion
(cherry-picked from commit e0b2ee52d2f274a2d46b2e6695e42d2764c39fa7)
2017-12-12 23:22:25 +00:00
Christopher Tate
2f87cb2d4a 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
Merged-In: I361ad4a0729f319db7339bd341a6d33aa3b64fed
2017-10-02 20:15:18 +00:00
Bernardo Rufino
628fee52b1 Add logs to IOExceptions during adb backup
Test: Run adb backup
Bug: 65435587
Change-Id: I744cb2878654b716858d7c9bedeb12fb9978df6b
2017-09-13 13:58:38 +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
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
b152fb8d30 Merge "Do not remove uninstalled packages from journal" into oc-mr1-dev 2017-08-08 21:19:41 +00: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
Christopher Tate
924afe2b0f Add 'bmgr' command to synchronously init transports
bmgr init TRANSPORT [...]

will run an init operation on each named transport, blocking
until the operations have all completed.

Bug 62253989
Test: manual

Change-Id: I7dbd94293738d5ecf195764f5b28905253819791
2017-06-20 13:28:56 -07:00
Christopher Tate
1a30fcd995 Fix #62798589 : requestBackup() needs to check enable/provisioned state
Also tweaked the logging to make sure to capture "not provisioned"
whenever it's the case.

Test: manual
Change-Id: Iee909b8336af776bad0fa46f036d6cf32ef9c3e7
2017-06-20 11:18:06 -07:00
Bryan Mawhinney
4fee93109a Start agent in correct mode for adb k/v restore
Previously we always started the agent in "dolly" mode, which meant that
the application context might not be what the agent was expecting.

Bug: 62524964
Test: Manual
Change-Id: I6cd2fafcac97f7ca01a6e172325968d79cc01194
2017-06-16 14:45:41 +01:00
Christopher Tate
fe2368c38c Refresh in-memory SharedPreferences instances after restore
Existing instances don't know that the file has changed out from
under them, so they continue to return stale values from reads, and
risk overwriting restored data with stale content if writes are
performed.  We now tell the backing cache system to induce a
reload after restore (i.e. after we might have written a relevant
file out from under it).

Along the way we shook out an irregularity in the way we were
setting up the context topology of non-lifecycle instances of
the metadata-handling BackupAgent subclass, so that's fixed
now too.

Bug 12061817
Test: cts-tradefed run cts -m CtsBackupHostTestCases

Change-Id: I401fe9297235b55d8a8f041e430d122dc6e24129
2017-05-30 12:41:39 -07:00
Artem Iglikov
21942e0aba Add tests for routeSocketDataToOutput.
Also fixes the problem where it could through IndexOutOfBoundsException
instead of more natuarl EOFExcpetion in case there is not enough data in
the chunk.

Bug: 38081946
Bug: 37983441
Test: runtest -p com.android.server.backup frameworks-services
Change-Id: Icac575a76b752922b9c2d9cc0b3cad50f4273241
2017-05-17 15:11:49 +01:00
Christopher Tate
c876ebe70b Merge "Do not perform backup/restore of instant apps" into oc-dev am: 1835f076b3
am: 8686e2219b

Change-Id: Ic9116dd9134b0b03e4eaa60c21cf00454ac36ba5
2017-05-13 00:01:02 +00:00
Christopher Tate
6c5631ee7c Do not perform backup/restore of instant apps
This keeps the install flow fast, and also happens to mean that
there is feature parity in this regard between pre-O and O+
instant app handling.

Fix #38263351
Test: manual

Change-Id: I8eb08c12d800f5288583e792621920c9876efdfc
2017-05-12 13:58:20 -07:00
Fyodor Kupolov
cc8e7c3e67 Merge "Use buffered DataInputStream vs RandomAccessFile" into oc-dev am: b4a032fd02
am: 8a98e746ef

Change-Id: I93b9a3909dc385f29efc4b4447d3fa90b948fc1b
2017-05-11 09:05:24 +00:00
Fyodor Kupolov
98b8d31add Use buffered DataInputStream vs RandomAccessFile
Switching to buffered streams saved up to 50% of
BackupManagerService.onUnlockUser time:

Before:
SystemServiceManager: Service com.android.server.backup.BackupManagerService$Lifecycle took 389 ms in onUnlockUser
SystemServiceManager: Service com.android.server.backup.BackupManagerService$Lifecycle took 380 ms in onUnlockUser
After:
SystemServiceManager: Service com.android.server.backup.BackupManagerService$Lifecycle took 178 ms in onUnlockUser
SystemServiceManager: Service com.android.server.backup.BackupManagerService$Lifecycle took 155 ms in onUnlockUser

Test: manual
Bug: 37686433
Change-Id: I41185a88e8377b434fab6a3bf1fd7086758127cd
2017-05-10 16:46:22 -07:00
Artem Iglikov
dbe6832480 Use static imports for constants.
This is an automated change with some manual formatting.

Bug: 36850431
Test: mmma frameworks/base
Change-Id: I126747e57ae1b666e5281b25d063d22d774b0718
2017-05-09 14:21:37 +01:00
Artem Iglikov
13fffd267c Add some tests for TarBackupReader
... and PerformAdbRestoreTask.

Involves some refactoring, splitting readAppManifest() into two methods.

Also a bit of cleanup: make private field actually private and use
static imports for some constants.

Bug: 38090803
Bug: 37619463
Test: runtest -p com.android.server.backup frameworks-services
Change-Id: Ic30a6c5a515da1efb67caaae6eb75f4313797d5c
2017-05-08 19:15:59 +01:00
TreeHugger Robot
b3f506aa5d Merge "Add null checking and exception handling in selectBackupTransportAsync" 2017-05-05 11:24:57 +00:00
Chris Tate
af31dffcb3 Merge "Correct scope of "disabled?" check viz backup/restore decisions" into oc-dev am: d239223cb0
am: 136f841c5c

Change-Id: Ibaf2939a7873ea017be0c71785ee02be8bcdd5ff
2017-05-05 01:27:53 +00:00
Chris Tate
d239223cb0 Merge "Correct scope of "disabled?" check viz backup/restore decisions" into oc-dev 2017-05-05 01:10:43 +00:00
Tony Mak
2dd109d238 Add null checking and exception handling in selectBackupTransportAsync
Bug: 37304539

Test: bit FrameworksServicesTests:com.android.server.backup.TrampolineTest

Change-Id: I01ffa25bfca6ca743220ee7277c2a6473c055bf1
2017-05-04 18:29:15 +01:00
Artem Iglikov
23c6007ccf Add more tests for AppBackupUtils.
Also enable other utils tests on presubmit.

Test: runtest -p com.android.server.backup frameworks-services
Bug: 37939902
Change-Id: I7f54a6a3d4dfe14f4802af1788a4d3afe01372f2
2017-05-04 12:26:47 +01:00
TreeHugger Robot
9dee975361 Merge "selectBackupTransportAsync should report failure when backup is not available" into oc-dev 2017-05-04 08:44:05 +00:00
Christopher Tate
5092dea7f5 Correct scope of "disabled?" check viz backup/restore decisions
*Really* don't back up or restore data for disabled apps.

Bug 37851910
Test: manual

Change-Id: I4b9bdcabb386789b03633d9d26775e54bf3c3d03
2017-05-03 13:52:33 -07:00
Chris Tate
b6c708a1d3 Merge "Don't mix "current dataset" tokens for different backup transports" into oc-dev am: 70a2316ec7
am: 362a819a46

Change-Id: Ica34b713dcb76de186221caf3ea158a5125903b9
2017-05-03 20:31:02 +00:00
Chris Tate
70a2316ec7 Merge "Don't mix "current dataset" tokens for different backup transports" into oc-dev 2017-05-03 20:15:54 +00:00
Tony Mak
60ef1ce025 selectBackupTransportAsync should report failure when backup is not available
Merged-in: I393308857ea6082dca167e3e417b946615a83c20
Fix: 37304539
Test: runtest -x frameworks/base/services/tests/servicestests/src/com/android/server/backup/TrampolineTest.java
Test: setup device owner, then set up profile.
      Ensure tapping Settings->Google->Work->Security -> Verify app
      is working

Change-Id: I88c3e3163605d62123c88377ae0843084e354212
2017-05-03 20:02:57 +00:00
TreeHugger Robot
13e8294638 Merge "Add unit tests for com.android.server.backup.utils" 2017-05-03 18:40:09 +00:00
Artem Iglikov
66ff1d62c0 Add unit tests for com.android.server.backup.utils
Also add missing javadocs to some new classes.

Bug: 37939902
Test: runtest -p com.android.server.backup frameworks-services
Change-Id: I7c24cec754af9ea6caee7791a11085b8c174c427
2017-05-03 16:36:21 +01:00