diff options
author | Samuel Fufa <sfufa@google.com> | 2020-02-12 17:56:21 -0800 |
---|---|---|
committer | Samuel Fufa <sfufa@google.com> | 2020-02-24 19:07:59 +0000 |
commit | 1acbf7763b9019efcc956c8d70df75db9f8fce41 (patch) | |
tree | bfa0cb2a4f9f6c7ffe96afc7850d0cf9f0426e73 /services/appwidget | |
parent | 27f83cdbcefd687632811996e25ece99f7e1ac69 (diff) |
Fix widget restore flow
After restore, the app should set OPTION_APPWIDGET_RESTORE_COMPLETED to
true on its widgets followed by calling updateAppWidget to update views.
Bug:63667276
Test: Manual
Change-Id: Idb6fc63b0f894fca9e0470aaf335240fc124e2e9
Diffstat (limited to 'services/appwidget')
-rw-r--r-- | services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java | 108 |
1 files changed, 47 insertions, 61 deletions
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(); |