diff options
author | Christopher Tate <ctate@google.com> | 2014-02-04 16:23:32 -0800 |
---|---|---|
committer | Christopher Tate <ctate@google.com> | 2014-03-20 12:30:51 -0700 |
commit | adfe8b86e9178a553b6db9722340fa4ff5201cf1 (patch) | |
tree | 2054d99dc17b0ada61693b97d9f3e306b4fe4d4a /core/java/android/app/backup | |
parent | aef4f6ebc8f8eb1f9fbfbe4ae2556c9f1a26a63c (diff) | |
download | frameworks_base-adfe8b86e9178a553b6db9722340fa4ff5201cf1.zip frameworks_base-adfe8b86e9178a553b6db9722340fa4ff5201cf1.tar.gz frameworks_base-adfe8b86e9178a553b6db9722340fa4ff5201cf1.tar.bz2 |
App widget backup/restore infrastructure
Backup/restore now supports app widgets.
An application involved with app widgets, either hosting or publishing,
now has associated data in its backup dataset related to the state of
widget instantiation on the ancestral device. That data is processed
by the OS during restore so that the matching widget instances can be
"automatically" regenerated.
To take advantage of this facility, widget-using apps need to do two
things: first, implement a backup agent and store whatever widget
state they need to properly deal with them post-restore (e.g. the
widget instance size & location, for a host); and second, implement
handlers for new AppWidgetManager broadcasts that describe how to
translate ancestral-dataset widget id numbers to the post-restore
world. Note that a host or provider doesn't technically need to
store *any* data on its own via its agent; it just needs to opt in
to the backup/restore process by publishing an agent. The OS will
then store a small amount of data on behalf of each widget-savvy
app within the backup dataset, and act on that data at restore time.
The broadcasts are AppWidgetManager.ACTION_APPWIDGET_RESTORED and
ACTION_APPWIDGET_HOST_RESTORED, and have three associated extras:
EXTRA_APPWIDGET_OLD_IDS
EXTRA_APPWIDGET_IDS
EXTRA_HOST_ID [for the host-side broadcast]
The first two are same-sized arrays of integer widget IDs. The
_OLD_IDS values are the widget IDs as known to the ancestral device.
The _IDS array holds the corresponding widget IDs in the new post-
restore environment. The app should simply update the stored
widget IDs in its bookkeeping to the new values, and things are
off and running. The HOST_ID extra, as one might expect, is the
app-defined host ID value of the particular host instance which
has just been restored.
The broadcasts are sent following the conclusion of the overall
restore pass. This is because the restore might have occurred in a
tightly restricted lifecycle environment without content providers
or the package's custom Application class. The _RESTORED broadcast,
however, is always delivered into a normal application environment,
so that the app can use its content provider etc as expected.
*All* widget instances that were processed over the course of the
system restore are indicated in the _RESTORED broadcast, even if
the backing provider or host is not yet installed. The widget
participant is responsible for understanding that these are
promises that might be fulfilled later rather than necessarily
reflecting the immediate presentable widget state. (Remember
that following a cloud restore, apps may be installed piecemeal
over a lengthy period of time.) Telling the hosts up front
about all intended widget instances allows them to show placeholder
UI or similarly useful information rather than surprising the user
with piecemeal unexpected appearances.
The AppWidgetProvider helper class has been updated to add a new
callback, onRestored(...), invoked when the _RESTORED broadcast
is received. The call to onRestored() is immediately followed by
an invocation of onUpdate() for the affected widgets because
they will need to have their RemoteViews regenerated under the
new ID values.
Bug 10622506
Bug 10707117
Change-Id: Ie0007cdf809600b880d91989c00c3c3b8a4f988b
Diffstat (limited to 'core/java/android/app/backup')
-rw-r--r-- | core/java/android/app/backup/BackupDataOutput.java | 9 | ||||
-rw-r--r-- | core/java/android/app/backup/IBackupManager.aidl | 2 |
2 files changed, 9 insertions, 2 deletions
diff --git a/core/java/android/app/backup/BackupDataOutput.java b/core/java/android/app/backup/BackupDataOutput.java index 3a070b6..845784f 100644 --- a/core/java/android/app/backup/BackupDataOutput.java +++ b/core/java/android/app/backup/BackupDataOutput.java @@ -17,6 +17,7 @@ package android.app.backup; import android.os.ParcelFileDescriptor; +import android.os.Process; import java.io.FileDescriptor; import java.io.IOException; @@ -76,13 +77,19 @@ public class BackupDataOutput { /** * Mark the beginning of one record in the backup data stream. This must be called before * {@link #writeEntityData}. - * @param key A string key that uniquely identifies the data record within the application + * @param key A string key that uniquely identifies the data record within the application. + * Keys whose first character is \uFF00 or higher are not valid. * @param dataSize The size in bytes of this record's data. Passing a dataSize * of -1 indicates that the record under this key should be deleted. * @return The number of bytes written to the backup stream * @throws IOException if the write failed */ public int writeEntityHeader(String key, int dataSize) throws IOException { + if (key != null && key.charAt(0) >= 0xff00) { + if (Process.myUid() != Process.SYSTEM_UID) { + throw new IllegalArgumentException("Invalid key " + key); + } + } int result = writeEntityHeader_native(mBackupWriter, key, dataSize); if (result >= 0) { return result; diff --git a/core/java/android/app/backup/IBackupManager.aidl b/core/java/android/app/backup/IBackupManager.aidl index 12ee3b6..c629a2e 100644 --- a/core/java/android/app/backup/IBackupManager.aidl +++ b/core/java/android/app/backup/IBackupManager.aidl @@ -167,7 +167,7 @@ interface IBackupManager { * are to be backed up. The <code>allApps</code> parameter supersedes this. */ void fullBackup(in ParcelFileDescriptor fd, boolean includeApks, boolean includeObbs, - boolean includeShared, boolean allApps, boolean allIncludesSystem, + boolean includeShared, boolean doWidgets, boolean allApps, boolean allIncludesSystem, in String[] packageNames); /** |