OSDN Git Service

Valid resource IDs may be negative
authorAdam Lesinski <adamlesinski@google.com>
Fri, 28 Apr 2017 01:09:19 +0000 (18:09 -0700)
committerAdam Lesinski <adamlesinski@google.com>
Fri, 28 Apr 2017 19:48:36 +0000 (12:48 -0700)
Package IDs greater than 0x7f are interpreted as negative
numbers in Java's signed integer. The proper check for existence of
a resource ID is that it is not 0.

Bug: 37498913
Test: none
Change-Id: I446fb6abb514bf7cf2d0dcbfbd81dd5718cd2cb4

core/java/android/app/AlertDialog.java
core/java/android/appwidget/AppWidgetProviderInfo.java

index 7d81c4c..b7f1068 100644 (file)
@@ -215,7 +215,8 @@ public class AlertDialog extends Dialog implements DialogInterface {
             return R.style.Theme_DeviceDefault_Dialog_Alert;
         } else if (themeResId == THEME_DEVICE_DEFAULT_LIGHT) {
             return R.style.Theme_DeviceDefault_Light_Dialog_Alert;
-        } else if (themeResId >= 0x01000000) {   // start of real resource IDs.
+        } else if (Integer.compareUnsigned(themeResId, 0x01000000) >= 0) {
+            // start of real resource IDs.
             return themeResId;
         } else {
             final TypedValue outValue = new TypedValue();
index 06fdb32..52fa8a6 100644 (file)
@@ -368,11 +368,11 @@ public class AppWidgetProviderInfo implements Parcelable {
         try {
             Resources resources = context.getPackageManager().getResourcesForApplication(
                     providerInfo.applicationInfo);
-            if (resourceId > 0) {
-                if (density <= 0) {
-                    density = context.getResources().getDisplayMetrics().densityDpi;
+            if (resourceId != 0) {
+                if (density < 0) {
+                    density = 0;
                 }
-                return resources.getDrawableForDensity(resourceId, density);
+                return resources.getDrawableForDensity(resourceId, density, null);
             }
         } catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) {
             /* ignore */