Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d390e326 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

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
parent a3c870d1
Loading
Loading
Loading
Loading
+4 −9
Original line number Diff line number Diff line
@@ -257,7 +257,7 @@ public final class PointerIcon implements Parcelable {
        }

        final PointerIcon icon = new PointerIcon(type);
        icon.loadResource(context, context.getResources(), resourceId);
        icon.loadResource(context.getResources(), resourceId);
        return icon;
    }

@@ -320,7 +320,7 @@ public final class PointerIcon implements Parcelable {
        }

        PointerIcon icon = new PointerIcon(TYPE_CUSTOM);
        icon.loadResource(null, resources, resourceId);
        icon.loadResource(resources, resourceId);
        return icon;
    }

@@ -436,7 +436,7 @@ public final class PointerIcon implements Parcelable {
        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 @@ public final class PointerIcon implements Parcelable {
            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;