diff options
-rw-r--r-- | api/current.txt | 1 | ||||
-rw-r--r-- | core/java/android/appwidget/AppWidgetManager.java | 10 | ||||
-rw-r--r-- | core/java/android/appwidget/AppWidgetProvider.java | 3 | ||||
-rw-r--r-- | core/proto/android/service/appwidget.proto | 1 | ||||
-rw-r--r-- | services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java | 108 |
5 files changed, 62 insertions, 61 deletions
diff --git a/api/current.txt b/api/current.txt index 1227006dbe04..23f32b610784 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 6dea1c69ce86..ccd8199b8373 100644 --- a/core/java/android/appwidget/AppWidgetManager.java +++ b/core/java/android/appwidget/AppWidgetManager.java @@ -182,6 +182,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. + * <p> 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. */ public static final String OPTION_APPWIDGET_MIN_WIDTH = "appWidgetMinWidth"; diff --git a/core/java/android/appwidget/AppWidgetProvider.java b/core/java/android/appwidget/AppWidgetProvider.java index ab91edfeca24..a5d2198a6e17 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. * + * <p>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 cd7173a94a70..97350ef90eec 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 a8a27916f56a..b78d024cd02e 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<String> getWidgetParticipants(int userId) { return mBackupRestoreController.getWidgetParticipants(userId); @@ -3064,7 +3107,7 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku if (widget.host.getUserId() != userId) { continue; } - serializeAppWidget(out, widget); + serializeAppWidget(out, widget, true); } Iterator<Pair<Integer, String>> it = mPackagesWithBindWidgetPermission.iterator(); @@ -3203,34 +3246,7 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku String restoredIdString = parser.getAttributeValue(null, "rid"); widget.restoredId = (restoredIdString == null) ? 0 : Integer.parseInt(restoredIdString, 16); - - Bundle options = new Bundle(); - 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)); - } - widget.options = options; + widget.options = parseWidgetIdOptions(parser); final int hostTag = Integer.parseInt(parser.getAttributeValue( null, "h"), 16); @@ -4382,7 +4398,7 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku if (widget.host.isInPackageForUser(backedupPackage, userId) || (provider != null && provider.isInPackageForUser(backedupPackage, userId))) { - serializeAppWidget(out, widget); + serializeAppWidget(out, widget, false); } } @@ -4815,36 +4831,6 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku || widget.provider.getUserId() == userId); } - private Bundle parseWidgetIdOptions(XmlPullParser parser) { - Bundle options = new Bundle(); - 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; - } - private int countPendingUpdates(ArrayList<RestoreUpdateRecord> updates) { int pending = 0; final int N = updates.size(); |