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

Commit 9a9bb380 authored by Yurii Zubrytskyi's avatar Yurii Zubrytskyi Committed by Android (Google) Code Review
Browse files

Merge "[res] Fix a crash in dumpHistory() when impl==null" into main

parents 96fd7410 e0ea094b
Loading
Loading
Loading
Loading
+20 −9
Original line number Diff line number Diff line
@@ -89,7 +89,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;

@@ -188,7 +187,7 @@ public class Resources {
    private int mBaseApkAssetsSize;

    /** @hide */
    private static Set<Resources> sResourcesHistory = Collections.synchronizedSet(
    private static final Set<Resources> sResourcesHistory = Collections.synchronizedSet(
            Collections.newSetFromMap(
                    new WeakHashMap<>()));

@@ -2808,7 +2807,12 @@ public class Resources {
    public void dump(PrintWriter pw, String prefix) {
        pw.println(prefix + "class=" + getClass());
        pw.println(prefix + "resourcesImpl");
        mResourcesImpl.dump(pw, prefix + "  ");
        final var impl = mResourcesImpl;
        if (impl != null) {
            impl.dump(pw, prefix + "  ");
        } else {
            pw.println(prefix + "  " + "null");
        }
    }

    /** @hide */
@@ -2816,17 +2820,24 @@ public class Resources {
        pw.println(prefix + "history");
        // Putting into a map keyed on the apk assets to deduplicate resources that are different
        // objects but ultimately represent the same assets
        Map<List<ApkAssets>, Resources> history = new ArrayMap<>();
        ArrayMap<List<ApkAssets>, Resources> history = new ArrayMap<>();
        sResourcesHistory.forEach(
                r -> history.put(Arrays.asList(r.mResourcesImpl.mAssets.getApkAssets()), r));
                r -> {
                    if (r != null) {
                        final var impl = r.mResourcesImpl;
                        if (impl != null) {
                            history.put(Arrays.asList(impl.mAssets.getApkAssets()), r);
                        } else {
                            history.put(null, r);
                        }
                    }
                });
        int i = 0;
        for (Resources r : history.values()) {
            if (r != null) {
            pw.println(prefix + i++);
            r.dump(pw, prefix + "  ");
        }
    }
    }

    /**
     * Register the resources paths of a package (e.g. a shared library). This will collect the