131 Commits

Author SHA1 Message Date
Christopher Tate
494df79172 Sysconfig define a whitelist of permitted backup transports
Previously any apk bundled in priv-app could insert a backup transport.
Reduce risk surface by giving the OEM explicit control over who is
allowed to handle backup data.

Bug 28406080

Change-Id: I84ed954c31b41b671825122e537971b110e00a4d
2016-05-10 17:11:03 -07:00
Chris Tate
e2cdb20cf8 Merge "Ensure that the stream feeder doesn't hang in write..." into nyc-dev 2016-05-05 19:35:39 +00:00
Christopher Tate
35c2827c60 Ensure that the stream feeder doesn't hang in write...
...if the restoring data engine thread winds up operations.  By closing
the engine side of the pipe unconditionally when exiting the thread,
the unanticipated-failure path is now guaranteed (instead of blocking
forever in write() to a pipe that isn't being read!).

In addition, wire agent-timeout handling into the various stream
data-handling operations (preflight, backup, restore).  This were
not sufficiently robust and were in some situations leaving the
backup/restore mechanisms in a livelock state.

Finally, plug a longstanding problem in which we'd have orphaned
timeout messages coming in and producing a certain amount of "wtf?"
logging and wasted CPU.  No longer!

Bug 28457158

Change-Id: I597c76c3eada378ffeb20870253847594f73e089
2016-05-04 17:52:19 -07:00
Christopher Tate
722d27f99c Full-data restore path needs to pass along the widget metadata
The engine itself knows about it, but that's at one remove from the
code that needs to consume it.  Make sure it gets passed up the chain.

Bug 28346706

Change-Id: Ib94c9fbc512d92039bb7db5cd6b0b088a4a66027
2016-05-02 17:16:05 -07:00
Christopher Tate
98f1ff0558 Don't wedge full data backups by blocking the data consumer thread
In particular, don't ask the producer about error overrides when
it is still relying on the consumer to do its job first.  This
needs to be policy for *any* transport-side error condition, not
just the one that was previously handled safely.  Any transport-
initiated error "on the fly" means that the app-facing side of
the engine doesn't know to stop feeding data, and mustn't be
consulted with any blocking request.

We also now detect unexpected PACKAGE_REJECTED by the transport
after data streaming has begun, and translate that to the general
TRANSPORT_ERROR for correct handling down the line.

Bug 28399225
Bug 28375634

Change-Id: I613dc21bc9f2d23e6520eed6c3ac2e9dbc1d88dc
2016-04-28 15:07:31 -07:00
Christopher Tate
5cf5578a45 Make sure FIRST_LAUNCH is after PACKAGE_ADDED
If an app undergoes restore during install, it is considered 'started'
and the FIRST_LAUNCH broadcast needs to go out.  However, this must not
take place until after the restore operation has fully completed, in
order to avoid publishing the app's existence while it may still be in
an incoherent state.  We now make this broadcast part of POST_INSTALL
in the restore case.

Bundled apps are in the 'started' state regardless, so no FIRST_LAUNCH
broadcast is ever sent for them -- this CL does not change that
existing behavior even in the case of setup-time data restore of
factory-installed packages.

Bug 28173625

Change-Id: Ibcc3758576662dc447b75476173a0d008a9fe4da
2016-04-27 15:07:26 -07:00
Makoto Onuki
021a48d50e Merge "Extract signature related utilities" into nyc-dev 2016-03-29 19:25:49 +00:00
Makoto Onuki
590096a0e3 Extract signature related utilities
So that they can be used from services/core.

Bug 27548047

Change-Id: I610e267cba320418e766c0e609fa26c485dc6e1f
2016-03-29 10:09:43 -07:00
Christopher Tate
d5f70b7483 Clean up a couple of bugs about transport init staging
Using the right names for things typically works better.

Bug 27794697

Change-Id: Ic8c3c2c978536545bd669c1c12aad9ee6783f38a
2016-03-28 17:57:51 -07:00
Christopher Tate
1f4c450342 Fix deadlock when full data backup times out
The code was attempting to let a reported error in the app <-> engine
surface take precedence over apparent success at the engine <-> transport
handoff surface.  However, in the case of timeout, this is inappropriate.
It was leading to deadlock because the engine runs free, with socket-closed
as its shutdown signals for determinism.  In this case that means that
having accidentally asked it to finish and report the final result, we
locked up forever since the data it was writing dutifully to the engine
was no longer being consumed, and the actual teardown signals were never
sent.

The fix is to properly express the error-state hierarchy: only when the
engine <-> transport layer is not issuing its own abort is the app-data-
moving layer consulted about errors detected at that surface.

Bug 22348852

Change-Id: I8987be0c4f708116dfeb08098d7222241ed317f3
2016-03-21 10:51:34 -07:00
Christopher Tate
4ebf6dd961 Don't use restricted backup launch mode for system-ish processes
We now impose restricted launch behavior and lifetime only on "ordinary"
apps' backup/restore operations.  System-ish targets such as the telephony
provider continue to get their full Application instance and providers,
and won't get killed following conclusion of the data-moving operations.
Such customers of backup/restore are expected to be able to deal
gracefully with this sort of thing.

Bug 27362301
Bug 27076602

Change-Id: Ib62483b8469cc750a20f80b7c596ad486a397564
2016-02-29 17:34:43 -08:00
Christopher Tate
50f56607d5 Don't use Settings for storing the backup enable state
Bug 19678828

Change-Id: Ieb572bcb2e8fe4d03f654dd52596c8dc4fdd72a9
2016-02-25 17:49:41 -08:00
Christopher Tate
43fbc5f898 Add android:backupInForeground
An app can now declare that it really needs to be backed up
whenever possible even if it is currently engaged in foreground-
equivalent work.  Only applies to full-data backup clients: key/value
backups are not intrusive on normal lifecycle so they can already
happen in such circumstances.

Bug 26790411

Change-Id: Ia0ebcc7a53da888ae9ae4d63cd4bcab6e3a2e866
2016-02-18 20:47:36 +00:00
Jeff Sharkey
2c1ba9a961 Make BackupManager encryption aware.
Backup requires both CE and DE storage to be available, so delay
spinning up the backup system until the user is unlocked, since
that's when CE storage becomes available.  Note that devices without
FBE immediately transition USER_SYSTEM into the unlocked state,
since their CE is always available.

Offer to backup and restore files under both CE and DE.  Since DE
is effectively the same as CE, most logic is simply duplicated for
now, but it could be simplified in the future.  Since system apps
can force their default storage location to DE, we always build
explicit CE and DE paths.

Add getDataDir() to give clean access to the top-level private data
directory, but disclaim that apps shouldn't create files there.

Bug: 26279618
Change-Id: Ic34a4b330223725db93b1d0f5c9dffc88002c61f
2016-02-18 10:54:11 -07:00
Sergey Poromov
cd8c13fc4e Synchronize results from runner thread to main full backup thread.
Previously, all results from runner thread - both for preflight
or full backup pass were ignored.
This change adds two synchronized method to get preflight result
and result of full backup pass.
This leads to better coverage of AGENT_ERROR to return in callback
as a result of backup operation.
On the other side we won't start backup pass in main thread
if preflight check hasn't been succeeded.

Change-Id: Id5f9e4c956a1bd5c396d59b7ad2098139a15e69d
2016-02-17 14:24:39 +01:00
Sergey Poromov
65775b9c68 Use long for preflight check size in BackupManagerService.
Bug: 26557141
Change-Id: I3794a91b62578044745a61bf774f5028f3e3b373
2016-02-11 20:44:09 +00:00
Sergey Poromov
266190839f Don't call BackupTransport#checkFullBackupSize when preflight timeouted.
mResult in SinglePackageBackupPreflight could be set
to a negative value if preflight timeouted.
Together with ag/863259 this change will better handle this case.

Bug: 26818914
Change-Id: I171bf95f146552b3b50f044964c2b041f6303d90
(cherry picked from commit a235f7e4e046b1a69af988240ff5f0dd46f3b5f9)
2016-02-11 13:12:53 +00:00
Jeff Sharkey
8212ae0aee Consistent naming for internal storage APIs.
Also completely remove a few confusingly named deprecated APIs.

Change-Id: Ia7e4ea3190a97f0a7dfa9bebf2118da0866ec38f
2016-02-10 15:03:33 -07:00
Sergey Poromov
eee352f7a2 Fix that backupFinished() callback is not called sometimes.
Before this in case of TRANSPORT_ERROR backup pass was aborted before backupFinished() call.
Now this happens in 'finally' block so that there is no way to avoid it.
Also, now backup pass doesn't break in case of QUOTA_EXCEEDED result for single package.
And some refactoring around 'currentPackage' variable.

Bug: 27094847
Change-Id: I18df3f500b427381f32bd11ed1aa87ab9577bc91
(cherry picked from commit 2ea71ad6254c4094d0d34a39d9988c9d75b038ed)
2016-02-10 00:07:55 +00:00
Christopher Tate
0b9ea17889 fullBackupOnly=true means don't even think about key/value backup
Bug 26790411

Change-Id: Ifa5b97053969de958b08cbf2975c503b10f93571
2016-02-02 14:11:54 -08:00
Christopher Tate
e5f51c212c Stage backup/restore data in a cache subdir rather than root
Also make sure not to do the restorecon() before the file is
created.

(Also fix binder identity bug in the 'bmgr fullbackup' flow.)

Bug 26834865

Change-Id: Ia8a59eeb55762264163c8b310caae5e303413571
2016-01-29 12:47:45 -08:00
Sergey Poromov
7200364e8d Merge "Quota exceeded API in BackupAgent" 2016-01-27 12:15:50 +00:00
Christopher Tate
339b53a8e6 Prevent (and repair) poisoned full-data backup queue
An app that transitioned from full-data to key/value backup regimes
was being left in the full-data backup queue until next reboot.  In
edge cases this would result in the app being inappropriately shut
down for backup; furthermore, it would potentially cause there to
exist a full-data payload for the app that was considered "newest"
and therefore be the one delivered at restore time on a new device
or app (re)installation.

Defense in depth: full-backup candidates are just-in-time reevaluated
for validity when they come up again in the queue; app update
notifications cause a reevaluation and removal from the queue if
full-data is no longer the right modality; and the common engine for
all cloud-facing full-data backups does an additional last-ditch
validation that each stated target is actually supposed to get
full-data backups rather than key/value, to backstop the checks on
queue-presence validity.

Bug 26744511

Change-Id: I55bea3e19a2cab0150dbe5a08dd9fc550f0068c4
2016-01-26 10:58:37 -08:00
Sergey Poromov
872d3b6e19 Quota exceeded API in BackupAgent
Should be also implemented in GMS BackupTransport.

Bug: 25693504
Change-Id: I6e4b2edb6d62addca0aced3e801d7629fb9394ca
2016-01-22 14:38:52 +01:00
Sergey Poromov
9448196076 Add BackupManager#isAppEligibleForBackup() method to Backup API.
Check is done only in framework.
Transport still can deny backup for the package.

Bug: 26443192
Change-Id: Ifcde67a4d11725aa4b15ab4f57d740f55ab2b265
2016-01-21 22:41:39 +01:00
Sergey Poromov
d3665f1f0f Merge "Introduce BackupManager#requestBackup & BackupObserver API" 2016-01-21 18:55:28 +00:00
Sergey Poromov
fe06bf64d2 Introduce BackupManager#requestBackup & BackupObserver API
Introduces a way to request immediate backup for list of packages
and receive callbacks on backup progress.

Bug: 25688526
Change-Id: Ib826933d44f4ebf2b981f8be366215b2d37847e2
2016-01-21 19:15:33 +01:00
Christopher Tate
63fec3ef1a Don't full-data back up apps in foreground-equivalent state
We have to kill the app and bring it up in a controlled lifecycle mode
in order to do full-data backup, and if it's e.g. playing media, this
is hugely disruptive.  Instead, we now check whether an app being
considered for full-data backup is in a user-observable state, and
defer its backup if so.  We don't kick it all the way down the
daily-backup cycle in this situation -- we set it up to retry the
backup in just a few hours.

Bug 25960428

Change-Id: I576f25c6fb07545565f59bd685624c612b9c5ffd
2016-01-14 11:03:36 -08:00
Xiaohui Chen
4cfe29bdf2 Cleanup USER_OWNER in backup service
This is just a straight constant replace.  The feature is tracked in a
separate bug b/22388012.

Bug: 19913735
Change-Id: I7ae0953558bfdb77441e9efd749f1bb1cc77050c
2015-09-04 13:57:20 -07:00
Chris Tate
05a24e5b59 am a6888d6d: am b5bcd607: am 27c5cfd7: am 9b2f9bcb: am 82d14d60: Merge "Crashing the system process is inadvisable" into mnc-dev
* commit 'a6888d6d8b912a69fad189e1d53da79746aa74ae':
  Crashing the system process is inadvisable
2015-08-28 20:37:24 +00:00
Christopher Tate
0d446c18dc Crashing the system process is inadvisable
When asking for the set of services published by a package, it's
quite possible that there are none, in which case the returned List<>
is null rather than valid-but-empty.  Don't bother looking at it
when it's null.

Bug 23614440

Change-Id: Ibebb26b9c3f75ec810a95f1b9d2663e884cb98bc
2015-08-28 10:59:25 -07:00
Christopher Tate
6578ad5bb4 am 905cb17f: am adde39d8: am b893c1ba: am 99b252ad: am ddc2536d: Make sure to kill restore-at-install full-data targets after restore
* commit '905cb17f921a804fde3679a2f8887055ec7db028':
  Make sure to kill restore-at-install full-data targets after restore
2015-08-21 01:35:49 +00:00
Christopher Tate
ddc2536d2b Make sure to kill restore-at-install full-data targets after restore
Specifically: correctly distinguish the "I want to restore my own data"
case, in which the app is intentionally not killed, from the single-package
restore at install operation.

Bug 23357388

Change-Id: Ic50ac39fe942af1f6ec9e04a32d81a39b70a0b2b
2015-08-20 15:08:55 -07:00
Chris Tate
1c1dd4bc8d am 45f88e1b: am 591b371f: am ccbb02f9: am b16cd62c: am c0a2254e: Merge "Clean up properly if outcall for doRestoreFinished() fails" into mnc-dev
* commit '45f88e1b2c0a8433b073f69c58660db843d46d04':
  Clean up properly if outcall for doRestoreFinished() fails
2015-08-18 01:44:08 +00:00
Christopher Tate
d71d7c350c Clean up properly if outcall for doRestoreFinished() fails
The target app crashed at an inopportune time but this shouldn't
invalidate the whole ongoing restore operation; it's a problem local to
the specific app undergoing restore.  Recognize this, clean up the app's
possibly-incomplete data, and continue running the restore queue as
planned.

Bug 23228982

Change-Id: If9a19d2fe6a0ce5339c893630d7a61a5a5ccd9b1
2015-08-17 12:16:19 -07:00
Chris Tate
1ad82779be am 5f70b3b1: am e5b25915: am e625b631: am 4de7b0ff: am 74a0744e: Merge "Fix issues around process teardown after full-data restore" into mnc-dev
* commit '5f70b3b1d3360dcfa2716d610c04efa3e309521e':
  Fix issues around process teardown after full-data restore
2015-07-30 18:12:43 +00:00
Christopher Tate
2ad7e27362 Fix issues around process teardown after full-data restore
The unified code path for cleanup was mistakenly looking at the
android:killAfterRestore manifest attribute even for full-data restore
operations.  That attribute is only relevant for key/value payload
handling.  We need to *always* kill after restore in the full-data
case because the app will otherwise be allowed to enter normal
component lifecycles without its correct Application / ContentProvider
state in force.

Bug 22704852

Change-Id: Ia63f985a35c28084c734389cfc49d3792173e5c7
2015-07-29 19:27:47 -07:00
Chris Tate
7e744dfcfd am 803b73a2: am f9f837fa: am 6613ec44: am 403e22b9: am 751a96a0: Merge "Don\'t redundantly call transport.finishRestore()" into mnc-dev
* commit '803b73a29004d2f8bf0234c0619480f5e639b5d6':
  Don't redundantly call transport.finishRestore()
2015-07-29 00:49:12 +00:00
Christopher Tate
6ab2fb61f0 Don't redundantly call transport.finishRestore()
The RestoreSession is no longer responsible for calling finishRestore();
that happens as part of tidying up after running the restore itself,
even in failure cases.

Bug 22640096

Change-Id: I0be52af2ae8c2c1ac685e9904ccb8120f7fcf522
2015-07-28 14:04:04 -07:00
Kenny Guy
a848379cab Update backup todo to mentioned admin control.
Update backup manager todo about backups for profiles
to mention the need for DevicePolicyManager control.

Change-Id: I7f17fc01a53d9608b104b70e57da7f619cb82c5f
2015-07-15 16:44:12 +01:00
Christopher Tate
2fe00adc02 Clean up obsolete pending timeout after restoring package metadata
Bug 22040047

Change-Id: I460dbcc50a45d794392beb9ff4a4358c05c87e07
2015-07-07 10:46:10 -07:00
Christopher Tate
758de809b9 Fix dispatch of onRestoreFinished()
The agent instance wasn't properly being conveyed from the generic
restore engine implementation to the state machine handling the
lifecycles.  On top of that, the lifecycle wasn't advancing to the
restore-finished callback phase properly in the full-data restore
case.

Bug 22194736

Change-Id: Ic649d6a196adbd21a4a0f3083c7eed2fff383e52
2015-06-30 17:58:27 -07:00
Christopher Tate
ad8a962316 Don't run backups in battery-saver mode
Defer both full-data and key/value backups while in battery-saver mode.

Bug 21563473

Change-Id: I081b7bcd19af21a4c88ebb434d2d3ef4bc93951f
2015-06-05 14:22:11 -07:00
Christopher Tate
3d7e0d8e21 Adjust key/value backup scheduling
We now try to perform key/value backups only while charging, proceeding
off-charger only after we've waited a full day for the device to be
plugged in.

Bug 21076663

Change-Id: Ib32c9f8bfaf8a310f5f388907e38a28d3c54bd8e
2015-05-30 00:49:26 +00:00
Christopher Tate
03d64a5210 Don't erase backup metadata when an app is uninstalled
We still retain the data in the backup, in order to support the flow
in which a user has the app and its data is stored; then the app
is uninstalled; then later the app is reinstalled.  We depend on
having correct metadata for the data in the datastore in order to
evaluate its validity for restore-at-install, so we mustn't
forget that metadata just because the app is not currently
installed.

We also now permit the sentinel pseudopackage name "@pm@" as an
argument to dataChanged(), indicating specifically that the metadata
should be scheduled for backup without having to be piggybacked on
another app's requested backup pass.  That lets us now make sure to
schedule a backup pass for metadata-update in response to app
install activity.

Finally, fix a "min instead of max" bug in full backup scheduling
that was causing the OS to ignore the transport's inter-package
quiet time requirement when multiple packages were overdue for
backup.

Bug 21471973

Change-Id: I1dbc260edb91b8deadd2744e273dfa9578b9ef2a
2015-05-27 15:06:24 -07:00
Christopher Tate
62d1e1ef7e Scan at boot time to detect newly-present full backup candidates
OTA or similar might have caused an app to appear without the usual
notifications being sent.  Make sure we pick up those apps as
appropriate for full-data backup.

Bug 19462310

Change-Id: Ic17bc72b14cc7599ae8ea540548fda932606b8f2
2015-05-21 01:32:39 +00:00
Christopher Tate
1a78d8c2b8 Rebind backup transports only when clearly needed
Significantly narrow the circumstances under which transports
will be re-bound.  In particular, we now do not unbind + rebind
whenever any component in a bound transport's host package changes;
rather, we do so only when the transport component itself has
changed state, or when there is a state change that might cause
a new transport to become available.

Bug 19775237

Change-Id: Ib386875df19ffe9f2d3eb9f9788187338360644a
2015-05-19 17:05:22 -07:00
Christopher Tate
5aba226d8a Fix requestRestore() of an app's own package
The BACKUP permission check was being applied over-zealously.

Bug 19336200

Change-Id: Ia52b5c5cc0fd8d19b74ee624be85113d1b8dca7e
2015-05-06 12:31:46 -07:00
Matthew Williams
303650c9cd Add full backup criteria to android manifest
BUG: 20010079
Api change: ApplicationInfo now has a fullBackupContent int
where -1 is (off) 0 is (on) and >0 indicates an xml
resource that should be parsed in order for a developer
to indicate exactly which files they want to include/exclude
from the backup set.
dd: https://docs.google.com/document/d/1dnNctwhWOI-_qtZ7I3iNRtrbShmERj2GFTzwV4xXtOk/edit#heading=h.wcfw1q2pbmae

Change-Id: I90273dc0aef5e9a3230c6b074a45e8f5409ed5ce
2015-05-03 16:19:27 -07:00
Christopher Tate
511d02fcc3 Add system API for querying the available restore dataset for a package
Bug 20123585

Change-Id: Ife6e77a224b5d4175178aacdb7c285e9944b9eab
2015-04-09 13:13:42 -07:00