168 Commits

Author SHA1 Message Date
Stefanot
f4e237c685 Add instrumentation for BackupManager during restore.
This CL adds more instumentation to
backup/restore operation in the BackupManager. For more details please
point to:
https://docs.google.com/document/d/1sUboR28LjkT1wRXOwVOV3tLo0qisiCvzxIGmzCVEjbI/edit#
This first Cl introduces 3 events that we sent to the monitor.
The base cl is ag/1835775

Test: TODO

BUG: 34873525
Change-Id: I127fe739a7522078eecce2ae689a4607203a98da
2017-02-10 13:52:02 +00:00
Stefanot
b1f573dca3 Add monitoring to backup in BackupManager.
This is the first CL of many that will add instumentation to
backup/restore operation in the BackupManager. For more details please
point to:
https://docs.google.com/document/d/1sUboR28LjkT1wRXOwVOV3tLo0qisiCvzxIGmzCVEjbI/edit#
This first Cl introduces 3 events that we sent to the monitor.

Test: ag/1858962 (same topic)

BUG: 34873525

Change-Id: I6c338b6fd9f4d7c8670dac201897250b6b170677
2017-02-10 11:03:08 +00:00
Shubham Ajmera
a6e5041a83 Merge "Replace RandomAccessFile with BufferedInputStream" 2017-02-09 12:14:23 +00:00
Shreyas Basarge
865303fce5 API to select backup transport
This cl adds an API to select a backup
transport by its component name and
receive a callback when BackupManager
is bound to the transport. Calling this API
will make BackupManager bind to the transport
if it isn't already bound to it.

Also fixes the issue where BackupManager would
detect only one transport per package.

Ref: go/backup-transport-switching

Bug: 33616220
Test: Manually tested. GTS tests will be put up shortly.

Change-Id: I8c23bdbb84ceb05eb1fad9b3a8b9c4441cb06c74
2017-01-24 17:28:48 +00:00
Shreyas Basarge
38e7486d38 Non incremental backup flag for requestBackup
This cl adds a new requestBackup API to
BackupManager that takes in an int flag
to indicate whether the caller wants the
entire key value set to be passed to the
transport and not just a diff.

Change-Id: Ia225797a58c4431fe742f2f116b257d006b30cd1

Bug: 33749084
Ref: go/request-backup-api-changes
Test: GTS Test at ag/1774002
2017-01-19 22:13:01 +00:00
Chris Tate
11e9cec138 Merge "Fix the deadlock problem" am: fa228e06f6 am: e8c0e1098e am: 35b99da33a
am: 0455c30035

Change-Id: Ib08f8deadfe6085d6d4368527892c799c42f0757
2016-12-02 23:02:58 +00:00
Chris Tate
e8c0e1098e Merge "Fix the deadlock problem"
am: fa228e06f6

Change-Id: I862d3cedcf38c81f22559439aa8f00ac2ab3cca3
2016-12-02 22:45:47 +00:00
pengzhicai
acaed3d29e Fix the deadlock problem
https://code.google.com/p/android/issues/detail?id=229020

Change-Id: Ib08f62dd916d09e666e58fb583555170d1e51da6
Signed-off-by: pengzhicai <pengzhicai@xiaomi.com>
2016-12-01 02:01:49 +00:00
Shubham Ajmera
274498e536 Replace RandomAccessFile with BufferedInputStream
com.android.server.backup.BackupManagerService#parseLeftoverJournals
uses input stream to read UTF. The method used RandomAccessFile to
perform the operation. The change replace the RandomAccessFile with
a Buffered InputStream.

Bug: 32866032
Test: `make`
Change-Id: I6594cecc49cb6efcfdf73beb5e425688cf890722
2016-11-16 11:10:06 +00:00
Sudheer Shanka
2250d56a0b Rename MountService to StorageManagerService.
Bug: 30977067
Test: Existing tests pass
Change-Id: Ieac0f11c2b249dcd60441b14c1f391e6f8131d42
2016-11-15 12:43:37 -08:00
Sudheer Shanka
dc589ac82b Update usage of ActivityManagerNative.
- Remove references to ActivityManagerProxy.
- Add isSystemReady to ActivityManager.

Bug: 30977067
Test: cts/hostsidetests/services/activityandwindowmanager/util/run-test android.server.cts
      adb shell am instrument -e class com.android.server.am.ActivityManagerTest,com.android.server.am.TaskStackChangedListenerTest \
          -w com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
Change-Id: I07390b6124fb1515821f5c0b37baf6ae74adc8fa
2016-11-14 11:27:12 -08:00
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