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

Commit a3513f05 authored by Kweku Adams's avatar Kweku Adams
Browse files

Add ability to take on demand system heap dumps.

With this, users with userdebug/eng builds will be able to initiate a
system heap dump from developer options.

Bug: 77490269
Test: manual
Change-Id: I0f4efec621e0d63b87c2d655a5f0434572cb92ac
parent c6479fd8
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -346,6 +346,9 @@ interface IActivityManager {
    void unregisterUserSwitchObserver(in IUserSwitchObserver observer);
    int[] getRunningUserIds();

    // Request a heap dump for the system server.
    void requestSystemServerHeapDump();

    // Deprecated - This method is only used by a few internal components and it will soon be
    // replaced by a proper bug report API (which will be restricted to a few, pre-defined apps).
    // No new code should be calling it.
+16 −0
Original line number Diff line number Diff line
@@ -12394,6 +12394,19 @@ public final class Settings {
         */
        public static final String EMERGENCY_AFFORDANCE_NEEDED = "emergency_affordance_needed";
        /**
         * Whether to enable automatic system server heap dumps. This only works on userdebug or
         * eng builds, not on user builds. This is set by the user and overrides the config value.
         * 1 means enable, 0 means disable.
         *
         * @hide
         */
        public static final String ENABLE_AUTOMATIC_SYSTEM_SERVER_HEAP_DUMPS =
                "enable_automatic_system_server_heap_dumps";
        private static final Validator ENABLE_AUTOMATIC_SYSTEM_SERVER_HEAP_DUMPS_VALIDATOR =
                new SettingsValidators.DiscreteValueValidator(new String[] {"0", "1"});
        /**
         * See RIL_PreferredNetworkType in ril.h
         * @hide
@@ -13565,6 +13578,7 @@ public final class Settings {
            EMERGENCY_TONE,
            CALL_AUTO_RETRY,
            DOCK_AUDIO_MEDIA_ENABLED,
            ENABLE_AUTOMATIC_SYSTEM_SERVER_HEAP_DUMPS,
            ENCODED_SURROUND_OUTPUT,
            ENCODED_SURROUND_OUTPUT_ENABLED_FORMATS,
            LOW_POWER_MODE_TRIGGER_LEVEL,
@@ -13607,6 +13621,8 @@ public final class Settings {
            VALIDATORS.put(EMERGENCY_TONE, EMERGENCY_TONE_VALIDATOR);
            VALIDATORS.put(CALL_AUTO_RETRY, CALL_AUTO_RETRY_VALIDATOR);
            VALIDATORS.put(DOCK_AUDIO_MEDIA_ENABLED, DOCK_AUDIO_MEDIA_ENABLED_VALIDATOR);
            VALIDATORS.put(ENABLE_AUTOMATIC_SYSTEM_SERVER_HEAP_DUMPS,
                    ENABLE_AUTOMATIC_SYSTEM_SERVER_HEAP_DUMPS_VALIDATOR);
            VALIDATORS.put(ENCODED_SURROUND_OUTPUT, ENCODED_SURROUND_OUTPUT_VALIDATOR);
            VALIDATORS.put(ENCODED_SURROUND_OUTPUT_ENABLED_FORMATS,
                    ENCODED_SURROUND_OUTPUT_ENABLED_FORMATS_VALIDATOR);
+16 −2
Original line number Diff line number Diff line
@@ -37,6 +37,10 @@ public class DumpHeapActivity extends Activity {
    public static final String KEY_PROCESS = "process";
    /** The size limit the process reached */
    public static final String KEY_SIZE = "size";
    /** Whether the user initiated the dump or not. */
    public static final String KEY_IS_USER_INITIATED = "is_user_initiated";
    /** Whether the process is a system process (eg: Android System) or not. */
    public static final String KEY_IS_SYSTEM_PROCESS = "is_system_process";
    /** Optional name of package to directly launch */
    public static final String KEY_DIRECT_LAUNCH = "direct_launch";

@@ -59,6 +63,8 @@ public class DumpHeapActivity extends Activity {

        mProcess = getIntent().getStringExtra(KEY_PROCESS);
        mSize = getIntent().getLongExtra(KEY_SIZE, 0);
        final boolean isUserInitiated = getIntent().getBooleanExtra(KEY_IS_USER_INITIATED, false);
        final boolean isSystemProcess = getIntent().getBooleanExtra(KEY_IS_SYSTEM_PROCESS, false);

        String directLaunch = getIntent().getStringExtra(KEY_DIRECT_LAUNCH);
        if (directLaunch != null) {
@@ -81,11 +87,19 @@ public class DumpHeapActivity extends Activity {
            }
        }

        final int messageId;
        if (isUserInitiated) {
            messageId = com.android.internal.R.string.dump_heap_ready_text;
        } else if (isSystemProcess) {
            messageId = com.android.internal.R.string.dump_heap_system_text;
        } else {
            messageId = com.android.internal.R.string.dump_heap_text;
        }
        AlertDialog.Builder b = new AlertDialog.Builder(this,
                android.R.style.Theme_Material_Light_Dialog_Alert);
        b.setTitle(com.android.internal.R.string.dump_heap_title);
        b.setMessage(getString(com.android.internal.R.string.dump_heap_text,
                mProcess, DebugUtils.sizeValueToString(mSize, null)));
        b.setMessage(getString(
                messageId, mProcess, DebugUtils.sizeValueToString(mSize, null)));
        b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
+1 −0
Original line number Diff line number Diff line
@@ -756,6 +756,7 @@ message ActivityManagerServiceDumpProcessesProto {
            optional string file = 2 [ (.android.privacy).dest = DEST_EXPLICIT ];
            optional int32 pid = 3;
            optional int32 uid = 4;
            optional bool is_user_initiated = 5;
        }
        optional Dump dump = 2;
    }
+3 −0
Original line number Diff line number Diff line
@@ -3975,4 +3975,7 @@
    <!-- The type of the light sensor to be used by the display framework for things like
         auto-brightness. If unset, then it just gets the default sensor of type TYPE_LIGHT. -->
    <string name="config_displayLightSensorType" translatable="false" />

    <!-- Whether or not to enable automatic heap dumps for the system server on debuggable builds. -->
    <bool name="config_debugEnableAutomaticSystemServerHeapDumps">false</bool>
</resources>
Loading