diff --git a/api/current.txt b/api/current.txt index 93b3784c3d2b4..a2f2c060428d8 100644 --- a/api/current.txt +++ b/api/current.txt @@ -8189,6 +8189,7 @@ package android.appwidget { field public static final String OPTION_APPWIDGET_MAX_WIDTH = "appWidgetMaxWidth"; field public static final String OPTION_APPWIDGET_MIN_HEIGHT = "appWidgetMinHeight"; field public static final String OPTION_APPWIDGET_MIN_WIDTH = "appWidgetMinWidth"; + field public static final String OPTION_APPWIDGET_RESTORE_COMPLETED = "appWidgetRestoreCompleted"; } public class AppWidgetProvider extends android.content.BroadcastReceiver { diff --git a/core/java/android/appwidget/AppWidgetManager.java b/core/java/android/appwidget/AppWidgetManager.java index 6dea1c69ce86b..ccd8199b8373b 100644 --- a/core/java/android/appwidget/AppWidgetManager.java +++ b/core/java/android/appwidget/AppWidgetManager.java @@ -181,6 +181,16 @@ public class AppWidgetManager { */ public static final String EXTRA_APPWIDGET_ID = "appWidgetId"; + /** + * A bundle extra that contains whether or not an app has finished restoring a widget. + *
After restore, the app should set OPTION_APPWIDGET_RESTORE_COMPLETED to true on its + * widgets followed by calling {@link #updateAppWidget} to update the views. + * + * @see #updateAppWidgetOptions(int, Bundle) + */ + public static final String OPTION_APPWIDGET_RESTORE_COMPLETED = "appWidgetRestoreCompleted"; + + /** * A bundle extra that contains the lower bound on the current width, in dips, of a widget instance. */ diff --git a/core/java/android/appwidget/AppWidgetProvider.java b/core/java/android/appwidget/AppWidgetProvider.java index ab91edfeca244..a5d2198a6e171 100644 --- a/core/java/android/appwidget/AppWidgetProvider.java +++ b/core/java/android/appwidget/AppWidgetProvider.java @@ -200,6 +200,9 @@ public class AppWidgetProvider extends BroadcastReceiver { * provider can immediately generate new RemoteViews suitable for its newly-restored set * of instances. * + *
In addition, you should set {@link AppWidgetManager#OPTION_APPWIDGET_RESTORE_COMPLETED}
+ * to true indicate if a widget has been restored successfully from the provider's side.
+ *
* {@more}
*
* @param context
diff --git a/core/proto/android/service/appwidget.proto b/core/proto/android/service/appwidget.proto
index cd7173a94a70d..97350ef90eec0 100644
--- a/core/proto/android/service/appwidget.proto
+++ b/core/proto/android/service/appwidget.proto
@@ -36,4 +36,5 @@ message WidgetProto {
optional int32 minHeight = 7;
optional int32 maxWidth = 8;
optional int32 maxHeight = 9;
+ optional bool restoreCompleted = 10;
}
diff --git a/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java b/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java
index a8a27916f56a1..b78d024cd02e0 100644
--- a/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java
+++ b/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java
@@ -794,6 +794,8 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
proto.write(WidgetProto.PROVIDER_PACKAGE, widget.provider.id.componentName.getPackageName());
proto.write(WidgetProto.PROVIDER_CLASS, widget.provider.id.componentName.getClassName());
if (widget.options != null) {
+ proto.write(WidgetProto.RESTORE_COMPLETED,
+ widget.options.getBoolean(AppWidgetManager.OPTION_APPWIDGET_RESTORE_COMPLETED));
proto.write(WidgetProto.MIN_WIDTH,
widget.options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, 0));
proto.write(WidgetProto.MIN_HEIGHT,
@@ -2509,7 +2511,8 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
out.endTag(null, "h");
}
- private static void serializeAppWidget(XmlSerializer out, Widget widget) throws IOException {
+ private static void serializeAppWidget(XmlSerializer out, Widget widget,
+ boolean saveRestoreCompleted) throws IOException {
out.startTag(null, "g");
out.attribute(null, "id", Integer.toHexString(widget.appWidgetId));
out.attribute(null, "rid", Integer.toHexString(widget.restoredId));
@@ -2528,10 +2531,50 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
out.attribute(null, "max_height", Integer.toHexString((maxHeight > 0) ? maxHeight : 0));
out.attribute(null, "host_category", Integer.toHexString(widget.options.getInt(
AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY)));
+ if (saveRestoreCompleted) {
+ boolean restoreCompleted = widget.options.getBoolean(
+ AppWidgetManager.OPTION_APPWIDGET_RESTORE_COMPLETED);
+ out.attribute(null, "restore_completed", Boolean.toString(restoreCompleted));
+ }
}
out.endTag(null, "g");
}
+ private static Bundle parseWidgetIdOptions(XmlPullParser parser) {
+ Bundle options = new Bundle();
+ String restoreCompleted = parser.getAttributeValue(null, "restore_completed");
+ if (restoreCompleted != null) {
+ options.putBoolean(AppWidgetManager.OPTION_APPWIDGET_RESTORE_COMPLETED,
+ Boolean.valueOf(restoreCompleted));
+ }
+ String minWidthString = parser.getAttributeValue(null, "min_width");
+ if (minWidthString != null) {
+ options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH,
+ Integer.parseInt(minWidthString, 16));
+ }
+ String minHeightString = parser.getAttributeValue(null, "min_height");
+ if (minHeightString != null) {
+ options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT,
+ Integer.parseInt(minHeightString, 16));
+ }
+ String maxWidthString = parser.getAttributeValue(null, "max_width");
+ if (maxWidthString != null) {
+ options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH,
+ Integer.parseInt(maxWidthString, 16));
+ }
+ String maxHeightString = parser.getAttributeValue(null, "max_height");
+ if (maxHeightString != null) {
+ options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT,
+ Integer.parseInt(maxHeightString, 16));
+ }
+ String categoryString = parser.getAttributeValue(null, "host_category");
+ if (categoryString != null) {
+ options.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
+ Integer.parseInt(categoryString, 16));
+ }
+ return options;
+ }
+
@Override
public List