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

Commit 0ae6433a authored by Vadim Tryshev's avatar Vadim Tryshev Committed by Android (Google) Code Review
Browse files

Merge "Saving heap dump immediately as reported by StrictMode" into ub-launcher3-master

parents 9f30165b 3d9dad3b
Loading
Loading
Loading
Loading
+10 −12
Original line number Diff line number Diff line
@@ -35,9 +35,11 @@ import android.content.pm.ActivityInfo;
import android.content.pm.LauncherActivityInfo;
import android.content.pm.LauncherApps;
import android.content.pm.PackageManager;
import android.os.Debug;
import android.os.Process;
import android.os.RemoteException;
import android.os.StrictMode;
import android.util.Log;

import androidx.test.InstrumentationRegistry;
import androidx.test.uiautomator.By;
@@ -117,6 +119,14 @@ public abstract class AbstractLauncherUiTest {
                                // so let's just mark the fact that the leak has happened.
                                if (sDetectedActivityLeak == null) {
                                    sDetectedActivityLeak = violation.toString();
                                    try {
                                        Debug.dumpHprofData(
                                                getInstrumentation().getTargetContext()
                                                        .getFilesDir().getPath()
                                                        + "/ActivityLeakHeapDump.hprof");
                                    } catch (IOException e) {
                                        Log.e(TAG, "dumpHprofData failed", e);
                                    }
                                }
                            });
            StrictMode.setVmPolicy(builder.build());
@@ -126,18 +136,6 @@ public abstract class AbstractLauncherUiTest {
    public static void checkDetectedLeaks() {
        if (sDetectedActivityLeak != null && !sActivityLeakReported) {
            sActivityLeakReported = true;

            final UiDevice device = UiDevice.getInstance(getInstrumentation());
            try {
                device.executeShellCommand(
                        "am dumpheap "
                                + device.getLauncherPackageName()
                                + " "
                                + getInstrumentation().getTargetContext().getFilesDir().getPath()
                                + "/ActivityLeakHeapDump.hprof");
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }