PointerIcon: Load all animation frames using the same resources
It seems like it's possible for display metrics to change while an
animation drawable is being loaded. If that happens, some animation
frames can be a different size than others, which is unexpected.
To avoid this from happening, use a single Resources object to load all
frames from an animation drawable, and hopefully the metrics associated
with the Resources won't change while the frames are being loaded.
Bug: 321324470
Test: speculative fix
Change-Id: I5f9f3b36dd050006bebbaab06f2c17381d3228fa
diff --git a/core/java/android/view/PointerIcon.java b/core/java/android/view/PointerIcon.java
index 270bf8b..715f1be 100644
--- a/core/java/android/view/PointerIcon.java
+++ b/core/java/android/view/PointerIcon.java
@@ -257,7 +257,7 @@
}
final PointerIcon icon = new PointerIcon(type);
- icon.loadResource(context, context.getResources(), resourceId);
+ icon.loadResource(context.getResources(), resourceId);
return icon;
}
@@ -320,7 +320,7 @@
}
PointerIcon icon = new PointerIcon(TYPE_CUSTOM);
- icon.loadResource(null, resources, resourceId);
+ icon.loadResource(resources, resourceId);
return icon;
}
@@ -436,7 +436,7 @@
return new BitmapDrawable(resources, bitmap);
}
- private void loadResource(Context context, Resources resources, @XmlRes int resourceId) {
+ private void loadResource(@NonNull Resources resources, @XmlRes int resourceId) {
final XmlResourceParser parser = resources.getXml(resourceId);
final int bitmapRes;
final float hotSpotX;
@@ -460,12 +460,7 @@
throw new IllegalArgumentException("<pointer-icon> is missing bitmap attribute.");
}
- Drawable drawable;
- if (context == null) {
- drawable = resources.getDrawable(bitmapRes);
- } else {
- drawable = context.getDrawable(bitmapRes);
- }
+ Drawable drawable = resources.getDrawable(bitmapRes);
if (drawable instanceof AnimationDrawable) {
// Extract animation frame bitmaps.
final AnimationDrawable animationDrawable = (AnimationDrawable) drawable;