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

Commit f3121190 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 10341497 from 0ab1d0d8 to udc-qpr1-release

Change-Id: I4869ebc6652b19ecde404afadba8037bfef93091
parents 1c915ca4 0ab1d0d8
Loading
Loading
Loading
Loading
+12 −12
Original line number Original line Diff line number Diff line
@@ -111,20 +111,20 @@ public class AnimatorInflater {
            float pathErrorScale) throws NotFoundException {
            float pathErrorScale) throws NotFoundException {
        final ConfigurationBoundResourceCache<Animator> animatorCache = resources
        final ConfigurationBoundResourceCache<Animator> animatorCache = resources
                .getAnimatorCache();
                .getAnimatorCache();
        ConfigurationBoundResourceCache.Entry<Animator> animatorEntry =
        Animator animator = animatorCache.getInstance(id, resources, theme);
                animatorCache.getInstance(id, resources, theme);
        if (animator != null) {
        if (animatorEntry.hasValue()) {
            if (DBG_ANIMATOR_INFLATER) {
            if (DBG_ANIMATOR_INFLATER) {
                Log.d(TAG, "loaded animator from cache, " + resources.getResourceName(id));
                Log.d(TAG, "loaded animator from cache, " + resources.getResourceName(id));
            }
            }
            return animatorEntry.getValue();
            return animator;
        } else if (DBG_ANIMATOR_INFLATER) {
        } else if (DBG_ANIMATOR_INFLATER) {
            Log.d(TAG, "cache miss for animator " + resources.getResourceName(id));
            Log.d(TAG, "cache miss for animator " + resources.getResourceName(id));
        }
        }
        int cacheGeneration = animatorCache.getGeneration();
        XmlResourceParser parser = null;
        XmlResourceParser parser = null;
        try {
        try {
            parser = resources.getAnimation(id);
            parser = resources.getAnimation(id);
            Animator animator = createAnimatorFromXml(resources, theme, parser, pathErrorScale);
            animator = createAnimatorFromXml(resources, theme, parser, pathErrorScale);
            if (animator != null) {
            if (animator != null) {
                animator.appendChangingConfigurations(getChangingConfigs(resources, id));
                animator.appendChangingConfigurations(getChangingConfigs(resources, id));
                final ConstantState<Animator> constantState = animator.createConstantState();
                final ConstantState<Animator> constantState = animator.createConstantState();
@@ -132,7 +132,7 @@ public class AnimatorInflater {
                    if (DBG_ANIMATOR_INFLATER) {
                    if (DBG_ANIMATOR_INFLATER) {
                        Log.d(TAG, "caching animator for res " + resources.getResourceName(id));
                        Log.d(TAG, "caching animator for res " + resources.getResourceName(id));
                    }
                    }
                    animatorCache.put(id, theme, constantState, animatorEntry.getGeneration());
                    animatorCache.put(id, theme, constantState, cacheGeneration);
                    // create a new animator so that cached version is never used by the user
                    // create a new animator so that cached version is never used by the user
                    animator = constantState.newInstance(resources, theme);
                    animator = constantState.newInstance(resources, theme);
                }
                }
@@ -161,22 +161,22 @@ public class AnimatorInflater {
        final ConfigurationBoundResourceCache<StateListAnimator> cache = resources
        final ConfigurationBoundResourceCache<StateListAnimator> cache = resources
                .getStateListAnimatorCache();
                .getStateListAnimatorCache();
        final Theme theme = context.getTheme();
        final Theme theme = context.getTheme();
        ConfigurationBoundResourceCache.Entry<StateListAnimator> animatorEntry =
        StateListAnimator animator = cache.getInstance(id, resources, theme);
                cache.getInstance(id, resources, theme);
        if (animator != null) {
        if (animatorEntry.hasValue()) {
            return animator;
            return animatorEntry.getValue();
        }
        }
        int cacheGeneration = cache.getGeneration();
        XmlResourceParser parser = null;
        XmlResourceParser parser = null;
        try {
        try {
            parser = resources.getAnimation(id);
            parser = resources.getAnimation(id);
            StateListAnimator animator =
            animator =
                    createStateListAnimatorFromXml(context, parser, Xml.asAttributeSet(parser));
                    createStateListAnimatorFromXml(context, parser, Xml.asAttributeSet(parser));
            if (animator != null) {
            if (animator != null) {
                animator.appendChangingConfigurations(getChangingConfigs(resources, id));
                animator.appendChangingConfigurations(getChangingConfigs(resources, id));
                final ConstantState<StateListAnimator> constantState = animator
                final ConstantState<StateListAnimator> constantState = animator
                        .createConstantState();
                        .createConstantState();
                if (constantState != null) {
                if (constantState != null) {
                    cache.put(id, theme, constantState, animatorEntry.getGeneration());
                    cache.put(id, theme, constantState, cacheGeneration);
                    // return a clone so that the animator in constant state is never used.
                    // return a clone so that the animator in constant state is never used.
                    animator = constantState.newInstance(resources, theme);
                    animator = constantState.newInstance(resources, theme);
                }
                }
+6 −6
Original line number Original line Diff line number Diff line
@@ -37,16 +37,16 @@ public class ConfigurationBoundResourceCache<T> extends ThemedResourceCache<Cons
     * @param key a key that uniquely identifies the drawable resource
     * @param key a key that uniquely identifies the drawable resource
     * @param resources a Resources object from which to create new instances.
     * @param resources a Resources object from which to create new instances.
     * @param theme the theme where the resource will be used
     * @param theme the theme where the resource will be used
     * @return an Entry wrapping a new instance of the resource, or {@code null} if not in
     * @return a new instance of the resource, or {@code null} if not in
     *         the cache
     *         the cache
     */
     */
    public Entry<T> getInstance(long key, Resources resources, Resources.Theme theme) {
    public T getInstance(long key, Resources resources, Resources.Theme theme) {
        final Entry<ConstantState<T>> e = get(key, theme);
        final ConstantState<T> entry = get(key, theme);
        if (e.hasValue()) {
        if (entry != null) {
            return new Entry<>(e.getValue().newInstance(resources, theme), e.getGeneration());
            return entry.newInstance(resources, theme);
        }
        }


        return new Entry<>(null, e.getGeneration());
        return null;
    }
    }


    @Override
    @Override
+3 −21
Original line number Original line Diff line number Diff line
@@ -40,32 +40,14 @@ class DrawableCache extends ThemedResourceCache<Drawable.ConstantState> {
     */
     */
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    public Drawable getInstance(long key, Resources resources, Resources.Theme theme) {
    public Drawable getInstance(long key, Resources resources, Resources.Theme theme) {
        final Entry<Drawable.ConstantState> entry = get(key, theme);
        final Drawable.ConstantState entry = get(key, theme);
        if (entry.getValue() != null) {
        if (entry != null) {
            return entry.getValue().newDrawable(resources, theme);
            return entry.newDrawable(resources, theme);
        }
        }


        return null;
        return null;
    }
    }


    /**
     * If the resource is cached, creates and returns a new instance of it.
     *
     * @param key a key that uniquely identifies the drawable resource
     * @param resources a Resources object from which to create new instances.
     * @param theme the theme where the resource will be used
     * @return an Entry wrapping a a new instance of the resource, or {@code null} if not in
     *         the cache
     */
    public Entry<Drawable> getDrawable(long key, Resources resources, Resources.Theme theme) {
        final Entry<Drawable.ConstantState> e = get(key, theme);
        if (e.hasValue()) {
            return new Entry<>(e.getValue().newDrawable(resources, theme), e.getGeneration());
        }

        return new Entry<>(null, e.getGeneration());
    }

    @Override
    @Override
    public boolean shouldInvalidateEntry(Drawable.ConstantState entry, int configChanges) {
    public boolean shouldInvalidateEntry(Drawable.ConstantState entry, int configChanges) {
        return Configuration.needNewResources(configChanges, entry.getChangingConfigurations());
        return Configuration.needNewResources(configChanges, entry.getChangingConfigurations());
+10 −17
Original line number Original line Diff line number Diff line
@@ -650,21 +650,16 @@ public class ResourcesImpl {
                key = (((long) value.assetCookie) << 32) | value.data;
                key = (((long) value.assetCookie) << 32) | value.data;
            }
            }


            int cacheGeneration;
            int cacheGeneration = caches.getGeneration();
            // First, check whether we have a cached version of this drawable
            // First, check whether we have a cached version of this drawable
            // that was inflated against the specified theme. Skip the cache if
            // that was inflated against the specified theme. Skip the cache if
            // we're currently preloading or we're not using the cache.
            // we're currently preloading or we're not using the cache.
            if (!mPreloading && useCache) {
            if (!mPreloading && useCache) {
                final ThemedResourceCache.Entry<Drawable> cachedDrawable =
                Drawable cachedDrawable = caches.getInstance(key, wrapper, theme);
                        caches.getDrawable(key, wrapper, theme);
                if (cachedDrawable != null) {
                if (cachedDrawable.hasValue()) {
                    cachedDrawable.setChangingConfigurations(value.changingConfigurations);
                    cachedDrawable.getValue().setChangingConfigurations(
                    return cachedDrawable;
                            value.changingConfigurations);
                }
                    return cachedDrawable.getValue();
                }
                cacheGeneration = cachedDrawable.getGeneration();
            } else {
                cacheGeneration = ThemedResourceCache.UNDEFINED_GENERATION;
            }
            }


            // Next, check preloaded drawables. Preloaded drawables may contain
            // Next, check preloaded drawables. Preloaded drawables may contain
@@ -1009,16 +1004,15 @@ public class ResourcesImpl {
            TypedValue value, int id) {
            TypedValue value, int id) {
        final long key = (((long) value.assetCookie) << 32) | value.data;
        final long key = (((long) value.assetCookie) << 32) | value.data;
        final ConfigurationBoundResourceCache<ComplexColor> cache = mComplexColorCache;
        final ConfigurationBoundResourceCache<ComplexColor> cache = mComplexColorCache;
        ThemedResourceCache.Entry<ComplexColor> complexColorEntry =
        ComplexColor complexColor = cache.getInstance(key, wrapper, theme);
                cache.getInstance(key, wrapper, theme);
        if (complexColor != null) {
        if (complexColorEntry.hasValue()) {
            return complexColor;
            return complexColorEntry.getValue();
        }
        }
        int cacheGeneration = cache.getGeneration();


        final android.content.res.ConstantState<ComplexColor> factory =
        final android.content.res.ConstantState<ComplexColor> factory =
                sPreloadedComplexColors.get(key);
                sPreloadedComplexColors.get(key);


        ComplexColor complexColor = null;
        if (factory != null) {
        if (factory != null) {
            complexColor = factory.newInstance(wrapper, theme);
            complexColor = factory.newInstance(wrapper, theme);
        }
        }
@@ -1035,8 +1029,7 @@ public class ResourcesImpl {
                    sPreloadedComplexColors.put(key, complexColor.getConstantState());
                    sPreloadedComplexColors.put(key, complexColor.getConstantState());
                }
                }
            } else {
            } else {
                cache.put(key, theme, complexColor.getConstantState(),
                cache.put(key, theme, complexColor.getConstantState(), cacheGeneration);
                        complexColorEntry.getGeneration());
            }
            }
        }
        }
        return complexColor;
        return complexColor;
+14 −27
Original line number Original line Diff line number Diff line
@@ -41,29 +41,6 @@ abstract class ThemedResourceCache<T> {


    private int mGeneration;
    private int mGeneration;


    public static class Entry<S> {
        private S mValue;
        private int mGeneration;


        public S getValue() {
            return mValue;
        }

        public boolean hasValue() {
            return mValue != null;
        }

        public int getGeneration() {
            return mGeneration;
        }

        Entry(S value, int generation) {
            this.mValue = value;
            this.mGeneration = generation;
        }
    }

    /**
    /**
     * Adds a new theme-dependent entry to the cache.
     * Adds a new theme-dependent entry to the cache.
     *
     *
@@ -108,6 +85,15 @@ abstract class ThemedResourceCache<T> {
        }
        }
    }
    }


    /**
     * Returns the current generation of the cache
     *
     * @return The current generation
     */
    public int getGeneration() {
        return mGeneration;
    }

    /**
    /**
     * Returns an entry from the cache.
     * Returns an entry from the cache.
     *
     *
@@ -116,7 +102,7 @@ abstract class ThemedResourceCache<T> {
     * @return a cached entry, or {@code null} if not in the cache
     * @return a cached entry, or {@code null} if not in the cache
     */
     */
    @Nullable
    @Nullable
    public Entry get(long key, @Nullable Theme theme) {
    public T get(long key, @Nullable Theme theme) {
        // The themed (includes null-themed) and unthemed caches are mutually
        // The themed (includes null-themed) and unthemed caches are mutually
        // exclusive, so we'll give priority to whichever one we think we'll
        // exclusive, so we'll give priority to whichever one we think we'll
        // hit first. Since most of the framework drawables are themed, that's
        // hit first. Since most of the framework drawables are themed, that's
@@ -126,7 +112,7 @@ abstract class ThemedResourceCache<T> {
            if (themedEntries != null) {
            if (themedEntries != null) {
                final WeakReference<T> themedEntry = themedEntries.get(key);
                final WeakReference<T> themedEntry = themedEntries.get(key);
                if (themedEntry != null) {
                if (themedEntry != null) {
                    return new Entry(themedEntry.get(), mGeneration);
                    return themedEntry.get();
                }
                }
            }
            }


@@ -134,14 +120,15 @@ abstract class ThemedResourceCache<T> {
            if (unthemedEntries != null) {
            if (unthemedEntries != null) {
                final WeakReference<T> unthemedEntry = unthemedEntries.get(key);
                final WeakReference<T> unthemedEntry = unthemedEntries.get(key);
                if (unthemedEntry != null) {
                if (unthemedEntry != null) {
                    return new Entry(unthemedEntry.get(), mGeneration);
                    return unthemedEntry.get();
                }
                }
            }
            }
        }
        }


        return new Entry(null, mGeneration);
        return null;
    }
    }



    /**
    /**
     * Prunes cache entries that have been invalidated by a configuration
     * Prunes cache entries that have been invalidated by a configuration
     * change.
     * change.
Loading