226 Commits

Author SHA1 Message Date
Christopher Tate
b0183f0ae3 Harden against transiently unavailable backup transports
The init & clear operations are particularly important to ensure
delivery when at all possible, so we retry those periodically
if the transport is unavailable when we first attempt them.

Now with 100% less build break.

Bug 11716868

Change-Id: I2af4e93788068cfac97c0a48d3568c561eefa23d
2013-11-19 11:24:46 -08:00
Sascha Prueter
d5965cb506 Trying to unbreak build...
Revert "Harden against transiently unavailable backup transports"

This reverts commit 8f98252afea3fd0e68693635ec21b6004a52fa69.

Change-Id: I3aabb80f1a5932d530bce6b82d4b30c6cd1cdd5a
2013-11-19 06:51:21 +00:00
Christopher Tate
8f98252afe Harden against transiently unavailable backup transports
The init & clear operations are particularly important to ensure
delivery when at all possible, so we retry those periodically
if the transport is unavailable when we first attempt them.

Bug 11716868

Change-Id: I4860fe3d4e99618b2cd194c83162bd7cbd5a83a9
2013-11-18 16:12:38 -08:00
Christopher Tate
cefba58d14 Handle backup transport registration dynamically
Bug 11369873

Change-Id: I9bbdcc21ce25159c6645690123b5d03c553b0ddc
2013-11-14 18:13:25 -08:00
Christopher Tate
9ac23d0952 Don't back up apps in the 'stopped' state
E.g. right after install from the Play Store, or after a force stop.

Bug 10845317

Change-Id: I7764ce61caa77136ca2758657f111928f9740fc0
2013-09-19 17:12:27 -07:00
Christopher Tate
a8de43fd8c Don't assume that transport unbind == transport invalid
We now expect that the transport service's host process will be
OOM-killed sometimes, but will come back automatically because we
still hold the binding.  So, we no longer drop it as the
expected-to-be-current transport when that happens.

Bug 10728767

Change-Id: I5e756e8942e7c4c3567632f10460ee31b9618d75
2013-09-16 18:14:52 -07:00
Christopher Tate
ffe0a803f8 Fix permission checks around setBackupEnabled()
...by making sure to drop binder identity before writing our new
state to secure settings etc.

Bug 10506933

Change-Id: I00505cc5215c8fe5f30f2f35698b30645fe14c87
2013-09-08 15:41:32 -07:00
Jeff Sharkey
1abdb71230 APIs for multiple external storage devices.
Provide developer APIs to discover application-specific paths on
secondary external storage devices.  Covers files, cache, and OBB
directories.  Apps will not have write access outside their package-
specific directories on secondary devices, so only primary storage is
exposed through Environment.

Creation of .nomedia files will be handled by FUSE daemon in future
change.

Change-Id: Ifcce6201a686d80269d7285adb597c008cf8fa7c
2013-08-11 17:07:44 -07:00
Christopher Tate
2baf6dcfcf Ensure install-during-restore is like install-then-restore
When we've installed an apk from the archive, recheck whether
to apply the system-uid policy restrictions around file system
restores.

Bug 8833099

Change-Id: Ifa1b5877673a0d6ca6acf94e60f314fd0dda008c
2013-05-06 13:10:21 -07:00
Geremy Condra
df4144f4df am 9fa57b74: am 2aee33c1: Merge "BackupManagerService files need new security labeling."
* commit '9fa57b74d8acb99c86f761a98f6e76998de8aff2':
  BackupManagerService files need new security labeling.
2013-03-25 22:29:10 -07:00
Geremy Condra
2aee33c1cd Merge "BackupManagerService files need new security labeling." 2013-03-26 05:10:38 +00:00
Elliott Hughes
6d3b13384e am c9fe40ea: am 71558f1f: Merge "Fix times in debugging output to use H rather than k."
* commit 'c9fe40ead549ff18393c0cc5c6e3bd67548f9da6':
  Fix times in debugging output to use H rather than k.
2013-03-19 10:13:34 -07:00
Elliott Hughes
64a277d837 Fix times in debugging output to use H rather than k.
Bug: 8359981
Change-Id: I4fccf3ed7e469b77f6e755dacbcd025005390505
2013-03-18 17:47:22 -07:00
Christopher Tate
294b512eca DO NOT MERGE - Full backup/restore now handles OBBs sensibly
OBB backup/ restore is no longer handled within the target app
process.  This is done to avoid having to require that OBB-using
apps have full read/write permission for external storage.

The new OBB backup service is a new component running in the
same app as the already-existing shared storage backup agent.
The backup infrastructure delegates backup/restore of apps'
OBB contents to this component (because the system process
may not itself read/write external storage).

From the command line, OBB backup is enabled by using new
-obb / -noobb flags with adb backup.  The default is noobb.

Finally, a couple of nit fixes:

- buffer-size mismatch between the writer and reader of chunked
  file data has been corrected; now the reading side won't be
  issuing an extra pipe read per chunk.

- bu now explicitly closes the transport socket fd after
  adopting it. This was benign but triggered a logged
  warning about leaked fds.

(Cherrypicked)

Change-Id: I471f6348abcccb7bf1e1710b7beda9f23de53e14
2013-03-08 15:08:10 -08:00
Christopher Tate
5cb5c337d5 Be cool in backup/restore of apps that can't touch external storage
Bug: 8241337
Change-Id: I23f6eeba8448b234a7b18ce50d2ced2ba54b4ebd
2013-02-21 15:43:52 -08:00
Christopher Tate
559c654801 For now enable backup/restore DEBUG logs
Change-Id: I5733251f1e11c8eedb0601ae6751a35134d6419d
2013-02-12 14:57:04 -08:00
Amith Yamasani
27b89e6658 Rename bindService to bindServiceAsUser to follow convention.
This is for the multi-user version of bindService, not the original.

Change-Id: Ib2de35941196accf387b1a276a77e6f9af805ec0
2013-01-16 12:30:11 -08:00
rpcraig
ebab0ae105 BackupManagerService files need new security labeling.
Use restorecon to label files and directories
specific to BMS.

 * /data/backup : provide default type labeling
    for all files/dirs used by BMS.

 * /data/secure/backup : provide default type
    labeling used by BMS when encrypted
    file system is enabled.

 * /cache/<package name>.{data|restore} :
    specifically target files opened and
    passed by BMS to apps that have backup
    capabilities.

 * /cache/backup : default labeling for the
    directory used by the LocalTransport
    that stores backup files for local testing.

Change-Id: Id4d46e82cd13abc2e395e0c30c515f0a33df93e7
Signed-off-by: rpcraig <rpcraig@tycho.ncsc.mil>
2012-12-04 10:26:33 -05:00
Dianne Hackborn
7ff30113de Remove extraneous logs.
Change-Id: I4c47d36748de91bd6fddc419afbf59552bf63e9a
2012-11-08 13:13:48 -08:00
Christopher Tate
acf5943c44 Merge "Fix the Backup Manager's uninstall tracking" into jb-mr1-dev 2012-10-24 12:24:51 -07:00
Christopher Tate
e82f68d016 Fix the Backup Manager's uninstall tracking
The bug was that when an app was uninstalled, the Backup Manager was
discarding its bookkeeping about that app being represented in the
device's current live backup dataset.  This in turn meant that if the
app was subsequently reinstalled, its data would not be restored from
that most-recent dataset: it would be restored from the *ancestral*
dataset if possible, or not at all.

Now the "ever backed up" state is retained correctly, and the app
will get its most-recent-data restored as expected.

Bug 7394519

Change-Id: I733cf41737765676e0a3a05fb1bcd32b165cb4ba
2012-10-23 15:40:27 -07:00
Amith Yamasani
cd75706117 System server should always send broadcasts to a specific or all users
Bug: 7368245

Log a warning if the system process calls unqualified sendBroadcast()
and other calls.

As a result of the logging above, found a few more method calls such as
bindService() that would benefit from being more explicit to avoid
future confusion and reduce the log warnings.

Change-Id: I17f15c8be9adf7becd456d6abbab606f19befdbf
2012-10-22 12:38:53 -07:00
Christopher Tate
346acb123d Sanity-check erroneous backup agent instantiations
Two distinct changes:

Fix a bug seen in the wild where a newly-launched application will be
spuriously asked to instantiate a backup agent.  What was happening
there is that some Activity Manager state was being left stale in certain
circumstances, and then in combination with app uninstall / install, there
could be a case where uid reuse wound up looking like an app identity
match.

We now positively verify before instantiating the agent that the intended
backup target package is uid-compatible with the app process that the
instantiation was requested of.  The incomplete bookkeeping in the
Activity Manager has also been tightened up, and the Backup Manager is
more aggressive about cleaning up pending operations pertaining to
apps being uninstalled.

Bug 5874010

Change-Id: Ic389f4a96c9dcd0ba6b3962b579084033d8ae9f8
2012-10-17 13:36:15 -07:00
Christopher Tate
f6d6fa8cbc Full (local) restore security changes
(1) Prevent full restore from creating files/directories that are
    accessible by other applications

(2) Don't restore filesets from "system" packages; i.e. any that runs
    as a special uid, unless they define their own agent for handling
    the restore process.

Bug 7168284

Change-Id: Id6a0cb4c113c2e4a8c4605252cffa41bea22d8a3
2012-09-27 12:54:37 -07:00
Jeff Brown
bf6f6f9de7 Update references to migrated global settings.
Fixed one setting that was migrated but not marked deprecated.

Removed a hidden setting that is no longer used by the new
power manager service.

Bug: 7231172
Change-Id: I332f020f876a18d519a1a20598a172f1c98036f7
2012-09-25 15:27:51 -07:00
Jeff Sharkey
b049e212ab Include user identifier in external storage paths.
When building external storage paths, always include user in path
to enable cross-user paths and aid debugging.

Each Zygote process continues to only have access to the appropriate
user-specific emulated storage through bind mounts. A second set of
mounts continue supporting legacy /sdcard-style paths. For example,
a process running as owner has these mount points:

/storage/emulated_legacy
/storage/emulated_legacy/Android/obb
/storage/emulated/0
/storage/emulated/obb

Since Environment is created before Zygote forks, we need to update
its internal paths after each process launches.

Bug: 7131382
Change-Id: I6f8c6971f2a8edfb415c14cb4ed05ff97e587a21
2012-09-11 23:11:14 -07:00
Christopher Tate
e7287a0791 Sanity-check existence of restore agent
When a restore dataset includes data for an app that used to have
a backup agent, but does not in the currently-installed version, we
were merrily trying to bring up the agent for restore anyway, and
crashing.  Now we don't do that; we check whether there's actually
going to be an agent to handle the data before doing any of the
heavy work.

Bug 7130695

Change-Id: I0a38c2a8bb51d4a140a72d22896fa58d98ebaa02
2012-09-07 18:32:12 -07:00
Dianne Hackborn
4120375d46 Remove Binder.getOrigCallingUid().
Replaced all remaining places that used it with explicit user
specification.

While doing this, I ran into stuff that was creating PendingIntent
objects (that now need to specify the explicit user they are for),
which are also posting notifications...  but have no way to specify
the user for the notification.

So the notification manager in the system process now also gets a
formal concept of a user associated with the notification, which
is passed in to all the necessary aidl calls.  I also removed the
old deprecated aidl interface for posting/cancelling notifications,
since we now always need a user supplied.

There is more work that needs to be done here, though.  For example
I think we need to be able to specify USER_ALL for a notification that
should be shown to all users (such as low storage or low battery).
Along with that, the PendingIntent creation needs to be tweaked to
be able to handle USER_CURRENT by evaluating the user at the point the
pending intent is sent.

That's for another change, however.

Change-Id: I468e14dce8def0e13e0870571e7c31ed32b6310c
2012-08-31 15:11:13 -07:00
Dianne Hackborn
f02b60aa4f Rename UserId to UserHandle.
This is the start of turning this into a formal public API.

Change-Id: I5786d2c320f1de41a06ed5d0f65adb68967287a0
2012-08-16 12:46:38 -07:00
Christopher Tate
aac71ff465 Don't back up / restore non-primary users' data
For now only the device owner "user" gets cloud backups.  Also, only the
device owner account has access to local backup/restore.

Bug 6956438

Change-Id: I87d7ba5969e606c23f4214469f9bf2fd47a6c61b
2012-08-13 17:36:14 -07:00
Christopher Tate
97ea122c65 Eliminate "backup enabled but not provisioned" failure modes
Previously, the setup app was responsible for telling the backup
manager through a side band that the user had passed through the
backup/restore-related portion of the setup flow.  Now that the
flow has been streamlined and certain mandatory portions of it
are no longer relevant, we can ditch the whole idea of the backup
manager's internal "provisioned" state.  This makes setup and the
setup "wizard" applications less fragile as well as eliminating
the possibility of unrecoverable "backup was never provisioned"
failure modes.

Now, the only check the backup manager has to do is against the
full "device is provisioned" flag, just like all of the other
components on the phone that only become usable after the setup
process has exited [such as phone calls].

Bug 6493520

Change-Id: I13ec8dd8baa1e74ed8569b0326219a98a7f632a9
2012-05-17 16:02:15 -07:00
Jeff Sharkey
eb4cc492c9 Protect system services with DUMP permission.
Change-Id: I5e53859f8b8e5473e54eca43ebd7de841f1a05ff
2012-04-26 18:17:29 -07:00
Christopher Tate
a3d55342be Fix uninstallation tracking in the Backup Manager
This never worked properly; now it does.  We also no longer
do a redundant pair of remove/add operations when a package is
updated.

Bonus memory savings: we were keeping sets of ApplicationInfo
objects as part of the ongoing bookkeeping, but those were no longer
being used for anything other than the package names.  That's been
tossed out now and only the name strings are now used; hooray for
memory savings!

Change-Id: I4c6e592a1680e28550bcb4f76789260ded22280d
2012-03-27 16:29:35 -07:00
Christopher Tate
0abf6a0014 Don't crash when wiping backup data redundantly in the local transport
Previously, if using the "local" debugging transport:

    adb shell bmgr wipe com.android.browser
    adb shell bmgr wipe com.android.browser

... would bring down the runtime.  This no longer happens.  The fix
covers two aspects of the situation:  1. the local transport no longer
blows up in this use case, and 2. the backup manager itself now catches
blowups on the part of the transport, and tidies up after them.

Bug 6205185

Change-Id: Ieb9b8827a62523148ad5a0ec15b05a954d198b3d
2012-03-23 17:47:58 -07:00
Christopher Tate
5b6f07b461 Merge "Deal gracefully with fatal exceptions during full backup" 2012-03-23 14:01:40 -07:00
Christopher Tate
aa0c02d221 Deal gracefully with fatal exceptions during full backup
In particular, if the low-level zip or crypto layers of the output
pipeline throw, the output becomes invalid at that point, but we
were not properly detecting this; we were missing the exception and
the runtime was going down.  Now we catch any such fatal exception
and make sure to shut down the backup operation cleanly, leaving
the output at whatever point in its construction that it had
achieved.

Bug 6131870

Change-Id: If0fe0337857404b776f407a79d11dd88b8e60fd0
2012-03-23 13:56:34 -07:00
Christopher Tate
9c2efb35e2 Sanity-check backup agent name prior to instantiation
Fixes a crash that would occur if an app with a pending backup
pass in the pipeline was updated to remove its agent declaration
from the manifest (or other more esoteric ways that a backup
pass was expected to run for an app without their own agent).

Bug 5776591

Change-Id: I5a8bc8c12de6a2bfa82f5093fe3a15b754109ab1
2012-03-23 13:00:05 -07:00
Amith Yamasani
742a671273 Multi-user - 1st major checkin
Switching activity stacks
Cache ContentProvider per user
Long-press power to switch users (on phone)

Added ServiceMap for separating services by user
Launch PendingIntents on the correct user's uid
Fix task switching from Recents list
AppWidgetService is mostly working.

Commands added to pm and am to allow creating and switching profiles.

Change-Id: I15810e8cfbe50a04bd3323a7ef5a8ff4230870ed
2012-02-03 12:01:47 -08:00
Christopher Tate
73d7369e0f Fix shared-storage full backup
The special shared-storage step was mistakenly writing its data directly
to the USB output pipe rather than to the proper stacked data handling
chain that applies compression and encryption.  Fix this by getting rid
of the custom handling of the shared-storage data, instead folding it
into the normal data handling flow [with a small amount of additional
management because e.g. it doesn't need a "manifest" pseudofile in the
archive stream].

Fixes bug 5897791

Change-Id: I3995b07963334d2f8cce49b247c87d3d3ff93bed
2012-01-20 17:41:41 -08:00
Christopher Tate
6de74ff2a4 Fix edge cases leading to backup hanging forever
Plug a couple of apparent code paths (one not obviously reachable, but
fixed here on general principles) that could lead to a backup pass
getting confused partway through and simply never properly completing.
In this state it would leave its wakelock held forever until next
reboot.  Bug 5828859.

Those fixes are a total of two lines of code. The rest of the patch
adds a textual journal of the most recently completed (or ongoing!)
backup pass's progress, with an eye to being able to isolate any such
issues that may crop up in the future.

Change-Id: If8a5e8aba11db5a1e618d8b9c9ba3038dd5377a1
2012-01-18 15:44:47 -08:00
Christopher Tate
0bacfd2ba6 Streamline package-installed handling by the Backup Manager
In particular, don't do O(asec_apps * installed_apps) work during the
broadcast receiver's operation.  On devices with many installed apps
and a large number of them moved to ASECs, this was causing the system
process to become unresponsive and the watchdog to fire -- which in turn
would initiate a restart loop, as the same package-installed broadcast
would then be issued again once the package manager rescanned the ASEC
containers, ad infinitum.  With this change, the expensive call to the
package manager is only made once rather than asec_apps times.

Bug 5850283

Change-Id: I14e280ea1fa6af19cebc58869a20fbb599c92c8c
2012-01-12 16:15:09 -08:00
Christopher Tate
32418be49e Require device encryption password to perform adb backup/restore
This supersedes any backup-password that the user might supply.  Per
design, the device encryption password is also always used to encrypt
the backup archive.

The CL introduces two new strings, used for prompting the user for
their device encryption password rather than their settings-defined
"backup password" when confirming a full backup or restore operation.

Bug 5382487

Change-Id: I0b03881b45437c944eaf636b6209278e1bba7a9f
2011-10-13 12:29:32 -07:00
Christopher Tate
e659fb9275 Gracefully handle "needs init" transport errors at finish
Although it's typical for a backup transport to report that it
needs an explicit initialization opportunity when the backup is
initiated, it can sometimes come to pass that the "needs init"
error condition is reported at backup *finish*.  In this case the
framework side was failing to properly reset all of the relevant
state.  The end result was to spin hard forever, holding wakelocks
and continually failing to actually perform the necessary init
operation, possibly continuing even after a reboot.  Fixed.

Bug 5434579

Change-Id: If1d72c338526e4019ea524c48a11e71e44e77f71
2011-10-10 16:34:50 -07:00
Christopher Tate
336a649cd8 Prevent concurrent backup operations
We've seen cases (bug 5417779) where the transport kicked off an immediate
backup operation but then was perfectly content to allow the periodic
timer to start *another* pass concurrently while the first was still in
progress.  This wound up with the backup manager getting mightily
confused and leaking wakelock acquisitions, which is Very Bad(tm).

This patch adds a little bookkeeping so that the backup manager is aware
of backups in flight, and refuses to kick off a new one until the ongoing
one has finished.

Change-Id: If12b54f4db3effc8af36d31c58d8f9b415ddc01e
2011-10-05 16:05:43 -07:00
Christopher Tate
240c7d2d1f Add -nosystem flag to adb backup
This makes it easy to back up everything that belongs to 3rd party apps, but
nothing that comes with the system per se.  If any system packages are
explicitly named on the command line they will be included in the backup
even if -nosystem was passed.  So, for example, this will back up all 3rd
party apps as well as system settings, but nothing else belonging to
system-deployed apps:

   adb backup -all -nosystem com.android.provider.settings

Bug 5361503

Change-Id: Iebe04b7d7027ca58b9f55e8eb7f219d6cca69269
2011-10-04 15:35:00 -07:00
Christopher Tate
b8491bb75f Enforce DUMP permission on BackupManagerService's dump() method
The text of the dumped output can potentially include an email address;
we don't want random code to be able to read it.

Bug 5389201

Change-Id: If84886357a36b7015878e4d72017abba83b4c511
2011-09-29 15:13:11 -07:00
Christopher Tate
d7208b98e9 am 7462251b: Merge "Don\'t hang in restore if the transport reports failure" into ics-factoryrom
* commit '7462251b0a3f2601236b599bcabf54451143b704':
  Don't hang in restore if the transport reports failure
2011-09-26 20:40:56 -07:00
Christopher Tate
ab63aa87c1 Use the new INSTALL_FROM_ADB Package Manager flag...
...when installing an apk in the course of an 'adb restore' operation.

Fixes bug 5374597.

Change-Id: I8ddce0e015e3bab79432e82709d841887667c346
2011-09-26 16:30:30 -07:00
Christopher Tate
5f2f41350e Don't hang in restore if the transport reports failure
Casualty of the recent refactoring: in this particular error case,
the restore sequence wasn't being directed into the finalization
state.  Fixes bug 5336295.

Change-Id: Ibf5570cd1003e123da8b561685de8479663340ce
2011-09-26 13:10:38 -07:00
Christopher Tate
d2c0cd4313 Don't do full backup/restore before setup
On the restore side, there's a bunch of one-time setup, device
provisioning, etc that we're very much not prepared to do in
lieu of running setup wizard, at least at this time.

On the backup side, it simply doesn't make sense to back up
stuff before the device has been set up.

Part of bug 5290261

Change-Id: If1c65e88e2da589d6204232d2b59c3e994f4ed3f
2011-09-15 15:51:29 -07:00