From d6da1e3ee20ca24781a0fa49a67f8500896fab9f Mon Sep 17 00:00:00 2001 From: Takamasa Kuramitsu Date: Mon, 18 Sep 2017 10:49:41 +0900 Subject: [PATCH] Add checking values not to save illegal value to appwidgets.xml Symptom: All AppWidgets on Home screen disppear after appwidgets.xml updated with invalid value. Root cause: The issue occurs when size information of an AppWidget is set to 0 via AppWidgetHostView#updateAppWidgetSize() API. Since width and height are taken positive padding, so they become negative number and are sent to AppWidgetServiceImpl#updateAppWidgetOptions(). In updateAppWidgetOptions(), convert values by Integer.toHexString() to save widget parameters to appwidgets.xml, but negative numbers become illegal values for Integer.parseInt(). After device is rebooted, widgets cannot be reloaded because parsing appwidgets.xml fail by NumberFormatException at Integer.parseInt(). Solution: When writing the widget's info to appwidgets.xml, check the size parameters and replace with 0 if they're negative value. Bug: 65705916 Change-Id: I48f69fbf081201a176ea1093094ba6cdb120e5f5 --- .../android/server/appwidget/AppWidgetServiceImpl.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java b/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java index aad44314e6cb..16a927c3c09a 100644 --- a/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java +++ b/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java @@ -2426,14 +2426,14 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku out.attribute(null, "p", Integer.toHexString(widget.provider.tag)); } if (widget.options != null) { - out.attribute(null, "min_width", Integer.toHexString(widget.options.getInt( - AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH))); - out.attribute(null, "min_height", Integer.toHexString(widget.options.getInt( - AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT))); - out.attribute(null, "max_width", Integer.toHexString(widget.options.getInt( - AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH))); - out.attribute(null, "max_height", Integer.toHexString(widget.options.getInt( - AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT))); + int minWidth = widget.options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH); + int minHeight = widget.options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT); + int maxWidth = widget.options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH); + int maxHeight = widget.options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT); + out.attribute(null, "min_width", Integer.toHexString((minWidth > 0) ? minWidth : 0)); + out.attribute(null, "min_height", Integer.toHexString((minHeight > 0) ? minHeight : 0)); + out.attribute(null, "max_width", Integer.toHexString((maxWidth > 0) ? maxWidth : 0)); + 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))); } -- 2.11.0