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

Commit 353e64ee authored by Jeremy Meyer's avatar Jeremy Meyer
Browse files

Add dumping of Resource paths and resource history

Sample of results:

history
0
  class=class android.content.res.Resources
  resourcesImpl
    class=class android.content.res.ResourcesImpl
    assets
      class=class android.content.res.AssetManager
      apkAssets=
      0
        class=class android.content.res.ApkAssets
        debugName=<empty> and /system/framework/framework-res.apk
        assetPath=/system/framework/framework-res.apk
      1
        class=class android.content.res.ApkAssets
        debugName=/product/overlay/GoogleConfigOverlay.apk
        assetPath=/product/overlay/GoogleConfigOverlay.apk

Fixes: 206615535
Test: Called from custom app to confirm format and info
Change-Id: I19a9fc60b61fff86e5b41a2d789d6dde8acf51a3
parent 73d699f9
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
@@ -1004,6 +1004,11 @@ public final class ActivityThread extends ClientTransactionHandler
        RemoteCallback finishCallback;
    }

    static final class DumpResourcesData {
        public ParcelFileDescriptor fd;
        public RemoteCallback finishCallback;
    }

    static final class UpdateCompatibilityData {
        String pkg;
        CompatibilityInfo info;
@@ -1315,6 +1320,20 @@ public final class ActivityThread extends ClientTransactionHandler
            sendMessage(H.SCHEDULE_CRASH, args, typeId);
        }

        @Override
        public void dumpResources(ParcelFileDescriptor fd, RemoteCallback callback) {
            DumpResourcesData data = new DumpResourcesData();
            try {
                data.fd = fd.dup();
                data.finishCallback = callback;
                sendMessage(H.DUMP_RESOURCES, data, 0, 0, false /*async*/);
            } catch (IOException e) {
                Slog.w(TAG, "dumpResources failed", e);
            } finally {
                IoUtils.closeQuietly(fd);
            }
        }

        public void dumpActivity(ParcelFileDescriptor pfd, IBinder activitytoken,
                String prefix, String[] args) {
            DumpComponentInfo data = new DumpComponentInfo();
@@ -2038,6 +2057,7 @@ public final class ActivityThread extends ClientTransactionHandler
        public static final int UPDATE_UI_TRANSLATION_STATE = 163;
        public static final int SET_CONTENT_CAPTURE_OPTIONS_CALLBACK = 164;
        public static final int DUMP_GFXINFO = 165;
        public static final int DUMP_RESOURCES = 166;

        public static final int INSTRUMENT_WITHOUT_RESTART = 170;
        public static final int FINISH_INSTRUMENTATION_WITHOUT_RESTART = 171;
@@ -2091,6 +2111,7 @@ public final class ActivityThread extends ClientTransactionHandler
                    case INSTRUMENT_WITHOUT_RESTART: return "INSTRUMENT_WITHOUT_RESTART";
                    case FINISH_INSTRUMENTATION_WITHOUT_RESTART:
                        return "FINISH_INSTRUMENTATION_WITHOUT_RESTART";
                    case DUMP_RESOURCES: return "DUMP_RESOURCES";
                }
            }
            return Integer.toString(code);
@@ -2206,6 +2227,9 @@ public final class ActivityThread extends ClientTransactionHandler
                case DUMP_HEAP:
                    handleDumpHeap((DumpHeapData) msg.obj);
                    break;
                case DUMP_RESOURCES:
                    handleDumpResources((DumpResourcesData) msg.obj);
                    break;
                case DUMP_ACTIVITY:
                    handleDumpActivity((DumpComponentInfo)msg.obj);
                    break;
@@ -4584,6 +4608,23 @@ public final class ActivityThread extends ClientTransactionHandler
        }
    }

    private void handleDumpResources(DumpResourcesData info) {
        final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
        try {
            PrintWriter pw = new FastPrintWriter(new FileOutputStream(
                    info.fd.getFileDescriptor()));

            Resources.dumpHistory(pw, "");
            pw.flush();
            if (info.finishCallback != null) {
                info.finishCallback.sendResult(null);
            }
        } finally {
            IoUtils.closeQuietly(info.fd);
            StrictMode.setThreadPolicy(oldPolicy);
        }
    }

    private void handleDumpActivity(DumpComponentInfo info) {
        final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
        try {
+1 −0
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ oneway interface IApplicationThread {
            in ParcelFileDescriptor fd, in RemoteCallback finishCallback);
    void dumpActivity(in ParcelFileDescriptor fd, IBinder servicetoken, in String prefix,
            in String[] args);
    void dumpResources(in ParcelFileDescriptor fd, in RemoteCallback finishCallback);
    void clearDnsCache();
    void updateHttpProxy();
    void setCoreSettings(in Bundle coreSettings);
+9 −0
Original line number Diff line number Diff line
@@ -5637,6 +5637,15 @@ public abstract class Context {
     */
    public static final String OVERLAY_SERVICE = "overlay";

    /**
     * Use with {@link #getSystemService(String)} to manage resources.
     *
     * @see #getSystemService(String)
     * @see com.android.server.resources.ResourcesManagerService
     * @hide
     */
    public static final String RESOURCES_SERVICE = "resources";

    /**
     * Use with {@link #getSystemService(String)} to retrieve a
     * {android.os.IIdmap2} for managing idmap files (used by overlay
+7 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import com.android.internal.annotations.GuardedBy;

import java.io.FileDescriptor;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Objects;
@@ -438,6 +439,12 @@ public final class ApkAssets {
        }
    }

    void dump(PrintWriter pw, String prefix) {
        pw.println(prefix + "class=" + getClass());
        pw.println(prefix + "debugName=" + getDebugName());
        pw.println(prefix + "assetPath=" + getAssetPath());
    }

    private static native long nativeLoad(@FormatType int format, @NonNull String path,
            @PropertyFlags int flags, @Nullable AssetsProvider asset) throws IOException;
    private static native long nativeLoadEmpty(@PropertyFlags int flags,
+10 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.ref.Reference;
import java.util.ArrayList;
import java.util.Arrays;
@@ -1531,6 +1532,15 @@ public final class AssetManager implements AutoCloseable {
        }
    }

    synchronized void dump(PrintWriter pw, String prefix) {
        pw.println(prefix + "class=" + getClass());
        pw.println(prefix + "apkAssets=");
        for (int i = 0; i < mApkAssets.length; i++) {
            pw.println(prefix + i);
            mApkAssets[i].dump(pw, prefix + "  ");
        }
    }

    // AssetManager setup native methods.
    private static native long nativeCreate();
    private static native void nativeDestroy(long ptr);
Loading