157 Commits

Author SHA1 Message Date
Sudheer Shanka
f734114280 Move IMountService to aidl.
Bug: 30977067
Test: Existing tests passing.
Change-Id: Icadfdcbc79708d3826b4e11afe35f5963aabcd4c
2016-10-27 12:36:37 -07:00
Sudheer Shanka
cc6418feb7 Move ApplicationThread to aidl.
Bug: 30977067
Test: Existing tests are passing, dump commands still working.
Change-Id: Iecb382e8720dfb1b6b707272497e3793e6995edb
2016-10-19 11:29:47 -07:00
Christopher Tate
d990e4d3df Respect restoreAnyVersion=true in full-data restore path
The scheduling mechanism was properly checking for it, but the raw
data-handling engine wasn't.  Now it is.

Bug 32054889

Change-Id: Id57ea12be8e2674c4f678f058278b8c14865b6fa
2016-10-11 15:29:39 -07:00
Chris Tate
a46b7f44c0 Merge "Turn down restore-time logspam" into nyc-mr1-dev 2016-07-15 18:05:07 +00:00
Christopher Tate
4c307258ac Turn down restore-time logspam
Bug 30160827

Change-Id: I14ccf0a31e5a6882bf189c28c79d1c139ec44bcc
2016-07-15 10:56:05 -07:00
Chris Tate
4595bc7f12 Merge "Thread-safe pipe teardown during restore operations" into nyc-mr1-dev 2016-07-15 01:38:03 +00:00
Chris Tate
69818781f3 Merge "Explicitly flush compress/encrypt stream before close" into nyc-mr1-dev 2016-07-12 22:47:00 +00:00
Chris Tate
1165790f70 Merge "Harden framework against backup transport crashes" into nyc-mr1-dev 2016-07-12 21:00:29 +00:00
Christopher Tate
ad869cc908 Thread-safe pipe teardown during restore operations
Bug 29135140

Change-Id: Id474f180815318618ec28ff953dc0cab892f781e
2016-07-12 13:56:35 -07:00
Christopher Tate
bf13ccf4b7 Back up / restore lock wallpapers
If writing both system + lock wallpapers winds up hitting the
transport-defined quota, the next backup operation steps back
to storing only the system wallpaper.

Also makes sure to unbind full-backup target agents following
the backup operation.  In practice this usually doesn't matter
because the target gets killed following the operation, but
the wallpaper agent runs in the system process where this does
not happen, so was mistakenly being left in place and reused
for the next operation, failing to re-run the full create +
backup lifecycle.

Bug 28968107

Change-Id: I219c2ddd7e899a430ef4cf693b1259464c15eed5
2016-07-12 18:34:05 +00:00
Fyodor Kupolov
4e8ce9ec4e Schedule backup of a package on a background thread
Scheduling involves writing to journal file. This part can be done on the
background thread in order to speed up the unlocking. Deferring writes to
journal file should be safe, because the system will reschedule backups in
case of a crash.

Bug: 29619732
Bug: 29645167
Change-Id: I0667ac2bf159e0f40b7a5066f41ea0841df98437
2016-07-06 18:20:29 -07:00
Christopher Tate
59397a8e05 Explicitly flush compress/encrypt stream before close
We're losing the stream footer for mysterious reasons; maybe this
will help even though supposedly close() is expected to flush pending
buffered writes anyway.  In particular, an explicit flush of the
compression stage will generate a SYNC_FLUSH point, which ordinary
deflate-at-close operation does not.

Bug 28056941

Change-Id: I96580411257932d7addb176c6672eae72a5ac6f7
2016-07-06 16:27:32 -07:00
Christopher Tate
a2a6533d65 Harden framework against backup transport crashes
Make sure we catch any exception thrown back from the transport,
rather than relying on it to maintain the interface surface.  Some
exceptions turn out to be beyond the call-target's control to
prevent.

Bug 29761883

Change-Id: Ifafbac300e7d7dab793237b2fd47d3122751435f
2016-07-06 16:27:32 -07:00
Christopher Tate
5cb5e89d77 Fix adb backup/restore
* Exclude key/value-only backup participants until we have a chance to
  augment the archive format with proper handling.

* Don't back up 'stopped' apps, which would un-stop them

* Fix unspecified-user bindService/startActivity invocations

* Teach adb restore about the onRestoreFinished() lifecycle method

* Implement proper app timeout handling in the adb data flows

* Backstop wallpaper backup against rare leftover-state issues

Bug 28056941

Change-Id: Ia59c71a2c74a632a2c2a527b9b7374229c440d46
2016-06-22 13:53:41 -07:00
Chris Tate
0f101342e1 Merge "Let bmgr inspect the set of whitelisted transports" into nyc-dev 2016-06-20 17:19:55 +00:00
Christopher Tate
1c3be1a5b1 resolve merge conflicts of cffb19c to mnc-dev am: 3f9ea2d386 am: d6c1126fab am: e2c9b1af3e
am: d2a4e1b39c

Change-Id: I8e59a88278ba50ab7e3768031611065131ed6834
2016-06-17 00:32:26 +00:00
Christopher Tate
3f9ea2d386 resolve merge conflicts of cffb19c to mnc-dev
Change-Id: I4dba574de2678d851e3d82961a07de27d61f5940
2016-06-16 16:31:39 -07:00
Christopher Tate
cffb19c812 Don\\\'t trust callers to supply app info to bindBackupAgent() am: c58054f25f am: cd777e95a7
am: ec6c3f7a32

Change-Id: Idc2b6c712078493b4186edad750d8d5beab58adf
2016-06-16 22:30:17 +00:00
Christopher Tate
cd777e95a7 Don\'t trust callers to supply app info to bindBackupAgent()
am: c58054f25f

Change-Id: I3b0bd91c38b5f13770f09f39c2eea78b63c29d7c
2016-06-16 22:21:37 +00:00
Christopher Tate
e227ec61c2 Let bmgr inspect the set of whitelisted transports
Needed for compliance testing.

Bug 29072466

Change-Id: I025058ab9197f9e2db062bf0074e79f1cd04b443
2016-06-15 17:40:31 -07:00
Christopher Tate
c58054f25f Don't trust callers to supply app info to bindBackupAgent()
Get the canonical identity and metadata about the package from the
Package Manager at time of usage rather than rely on the caller to
have gotten things right, even when the caller has the system uid.

Bug 28795098

Change-Id: I215786bc894dedf7ca28e9c80cefabd0e40ca877
2016-06-14 13:28:43 -07:00
Christopher Tate
09893e9a41 Don't allow restore sessions during backups
Gracefully no-op if apps attempt to restore themselves while there is
a backup pass in flight.

Bug 29135379

Change-Id: I8f0b5cd9d149b703e1de7a3a0b4b54c3aff766b6
2016-06-09 16:28:26 -07:00
Christopher Tate
c1c8325619 Use backstop timeouts on asynchronous countdown during preflight
Work around nebulous lost-timeout issues by adding a backstop timeout
to "wait for result" latch operations.  When we hit these, the initial
conditions will be reported as final result; so make those intial states
match the error condition that is appropriate to such a timeout.

Bug 28963707

Change-Id: I4d21a86c48e87633118b1e6eaa05c1d966efec81
2016-05-25 18:13:30 -07:00
Christopher Tate
2be3de1723 Backport of backup transport whitelist
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

Backport of 494df791728f4d42d67e935c327910975993ad29 from N

Change-Id: I9f90e324169a68720d608f74754d284a7e59cf87
2016-05-25 10:51:38 -07:00
Christopher Tate
647cb6a6d8 DO NOT MERGE : backport of backup transport whitelist
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

Backport of 494df791728f4d42d67e935c327910975993ad29 from N

Change-Id: I405b49daee8c576584575c3e46877cc97632d8c6
2016-05-23 15:37:57 -07:00
Christopher Tate
3bed1c0ef8 Explicitly close pipe end when we cease operations...
...because the other in-VM reference to that FD means that it won't
get GC'd after we release our local reference to the containing object,
and we wind up with the feeder end blocking on write to a still-fully-
open pipe rather than being made aware that the read end has needed
to shut down.

Bug 28756668

Change-Id: I90b6aaeaabe7d912d96d7ef57c24f68d87d9d0ab
2016-05-18 19:24:32 +00:00
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