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

Commit 512e4239 authored by Eric Miao's avatar Eric Miao
Browse files

Add ability to dump bitmaps with `android.os.Debug.dumpHprofData()`

Bug: 382275220
Flag: NONE - hidden internal debugging APIs

Change-Id: I70a25a071821ab95d69d6fd9d52815ab7fe50200
parent 2a76c44a
Loading
Loading
Loading
Loading
+1 −7
Original line number Original line Diff line number Diff line
@@ -7039,12 +7039,9 @@ public final class ActivityThread extends ClientTransactionHandler
            System.runFinalization();
            System.runFinalization();
            System.gc();
            System.gc();
        }
        }
        if (dhd.dumpBitmaps != null) {
            Bitmap.dumpAll(dhd.dumpBitmaps);
        }
        try (ParcelFileDescriptor fd = dhd.fd) {
        try (ParcelFileDescriptor fd = dhd.fd) {
            if (dhd.managed) {
            if (dhd.managed) {
                Debug.dumpHprofData(dhd.path, fd.getFileDescriptor());
                Debug.dumpHprofData(dhd.path, fd.getFileDescriptor(), dhd.dumpBitmaps);
            } else if (dhd.mallocInfo) {
            } else if (dhd.mallocInfo) {
                Debug.dumpNativeMallocInfo(fd.getFileDescriptor());
                Debug.dumpNativeMallocInfo(fd.getFileDescriptor());
            } else {
            } else {
@@ -7069,9 +7066,6 @@ public final class ActivityThread extends ClientTransactionHandler
        if (dhd.finishCallback != null) {
        if (dhd.finishCallback != null) {
            dhd.finishCallback.sendResult(null);
            dhd.finishCallback.sendResult(null);
        }
        }
        if (dhd.dumpBitmaps != null) {
            Bitmap.dumpAll(null); // clear dump
        }
    }
    }


    final void handleDispatchPackageBroadcast(int cmd, String[] packages) {
    final void handleDispatchPackageBroadcast(int cmd, String[] packages) {
+42 −0
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.Nullable;
import android.app.AppGlobals;
import android.app.AppGlobals;
import android.compat.annotation.UnsupportedAppUsage;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.util.Log;


import com.android.internal.util.FastPrintWriter;
import com.android.internal.util.FastPrintWriter;
@@ -2138,6 +2139,47 @@ public final class Debug
        VMDebug.dumpHprofData(fileName, fd);
        VMDebug.dumpHprofData(fileName, fd);
    }
    }


    /**
     * Like dumpHprofData(String), but takes an argument of bitmapFormat,
     * which can be png, jpg, webp, or null (no bitmaps in heapdump).
     *
     * @hide
     */
    public static void dumpHprofData(String fileName, String bitmapFormat)
            throws IOException {
        try {
            if (bitmapFormat != null) {
                Bitmap.dumpAll(bitmapFormat);
            }
            VMDebug.dumpHprofData(fileName);
        } finally {
            if (bitmapFormat != null) {
                Bitmap.dumpAll(null); // clear dump data
            }
        }
    }

    /**
     * Like dumpHprofData(String, FileDescriptor), but takes an argument
     * of bitmapFormat, which can be png, jpg, webp, or null (no bitmaps
     * in heapdump).
     *
     * @hide
     */
    public static void dumpHprofData(String fileName, FileDescriptor fd,
            String bitmapFormat) throws IOException {
        try {
            if (bitmapFormat != null) {
                Bitmap.dumpAll(bitmapFormat);
            }
            VMDebug.dumpHprofData(fileName, fd);
        } finally {
            if (bitmapFormat != null) {
                Bitmap.dumpAll(null); // clear dump data
            }
        }
    }

    /**
    /**
     * Collect "hprof" and send it to DDMS.  This may cause a GC.
     * Collect "hprof" and send it to DDMS.  This may cause a GC.
     *
     *