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

Commit e0ea094b authored by Yurii Zubrytskyi's avatar Yurii Zubrytskyi
Browse files

[res] Fix a crash in dumpHistory() when impl==null

setImpl() may sometimes put a null ResourcesImpl object into
Resources (e.g. when we couldn't load the APK), and in that case
the whole bugreport generation fails with a system server crash.

This fix makes it log a "null" string for that Resources object
instead

Bug: 321161602
Test: build + boot + bugreport
Change-Id: Ia955c9433c845e75d3813378220a166e67911182
parent 83029199
Loading
Loading
Loading
Loading
+20 −9
Original line number Diff line number Diff line
@@ -87,7 +87,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;

@@ -186,7 +185,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<>()));

@@ -2806,7 +2805,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 */
@@ -2814,15 +2818,22 @@ 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 + "  ");
        }
    }
}
}