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

Commit c23b0165 authored by Ryan Mitchell's avatar Ryan Mitchell
Browse files

Synchronize before calling unstableRemoveIf

The call to unstableRemoveIf should be synchronized on the
ResourcesManager instance since the collection belongs to the instance.

Also remove dead code from the loader refactor to prevent apps from
creating AssetManagers that return InputStreams instead of
AssetInputStreams.

Bug: 145510133
Test: boots
Change-Id: I50bcfc8e882f3d8a7827688e32f68790dd226801
parent 393c9121
Loading
Loading
Loading
Loading
+16 −15
Original line number Diff line number Diff line
@@ -214,11 +214,10 @@ public class ResourcesManager {
            for (int i = mCachedApkAssets.size() - 1; i >= 0; i--) {
                final ApkKey key = mCachedApkAssets.keyAt(i);
                if (key.path.equals(path)) {
                    WeakReference<ApkAssets> apkAssetsRef = mCachedApkAssets.remove(key);
                    WeakReference<ApkAssets> apkAssetsRef = mCachedApkAssets.removeAt(i);
                    if (apkAssetsRef != null && apkAssetsRef.get() != null) {
                        apkAssetsRef.get().close();
                    }
                    mCachedApkAssets.remove(key);
                }
            }
        }
@@ -774,6 +773,7 @@ public class ResourcesManager {
     * Rebases a key's override config on top of the Activity's base override.
     */
    private void rebaseKeyForActivity(IBinder activityToken, ResourcesKey key) {
        synchronized (this) {
            final ActivityResources activityResources =
                    getOrCreateActivityResourcesStructLocked(activityToken);

@@ -789,6 +789,7 @@ public class ResourcesManager {
                key.mOverrideConfiguration.setTo(temp);
            }
        }
    }

    /**
     * Check WeakReferences and remove any dead references so they don't pile up.
+2 −29
Original line number Diff line number Diff line
@@ -57,8 +57,6 @@ import android.view.DisplayAdjustments;

import com.android.internal.util.GrowingArrayUtils;

import libcore.io.IoUtils;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

@@ -817,27 +815,6 @@ public class ResourcesImpl {
        }
    }

    /**
     * Loads a Drawable from an encoded image stream, or null.
     *
     * This call will handle closing the {@link InputStream}.
     */
    @Nullable
    private Drawable decodeImageDrawable(@NonNull InputStream inputStream,
            @NonNull Resources wrapper, @NonNull TypedValue value) {
        ImageDecoder.Source src = ImageDecoder.createSource(wrapper, inputStream, value.density);
        try {
            return ImageDecoder.decodeDrawable(src, (decoder, info, s) ->
                    decoder.setAllocator(ImageDecoder.ALLOCATOR_SOFTWARE));
        } catch (IOException ignored) {
            // This is okay. This may be something that ImageDecoder does not
            // support, like SVG.
            return null;
        } finally {
            IoUtils.closeQuietly(inputStream);
        }
    }

    /**
     * Loads a drawable from XML or resources stream.
     *
@@ -902,12 +879,8 @@ public class ResourcesImpl {
                } else {
                    final InputStream is = mAssets.openNonAsset(
                            value.assetCookie, file, AssetManager.ACCESS_STREAMING);
                    if (is instanceof AssetInputStream) {
                        AssetInputStream ais = (AssetInputStream) is;
                    final AssetInputStream ais = (AssetInputStream) is;
                    dr = decodeImageDrawable(ais, wrapper, value);
                    } else {
                        dr = decodeImageDrawable(is, wrapper, value);
                    }
                }
            } finally {
                stack.pop();