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

Commit 161b27d5 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Better diagnosing leaked activities." into sc-dev

parents 41a5c370 ab469ac5
Loading
Loading
Loading
Loading
+22 −15
Original line number Diff line number Diff line
@@ -151,9 +151,13 @@ public abstract class AbstractLauncherUiTest {
    }

    public static String dumpHprofData() {
        if (sDumpWasGenerated) return "dump has already been generated by another test";
        String result;
        if (sDumpWasGenerated) {
            result = "dump has already been generated by another test";
        } else {
            try {
            final String fileName = getInstrumentation().getTargetContext().getFilesDir().getPath()
                final String fileName =
                        getInstrumentation().getTargetContext().getFilesDir().getPath()
                                + "/ActivityLeakHeapDump.hprof";
                if (TestHelpers.isInLauncherProcess()) {
                    Debug.dumpHprofData(fileName);
@@ -163,11 +167,14 @@ public abstract class AbstractLauncherUiTest {
                            "am dumpheap " + device.getLauncherPackageName() + " " + fileName);
                }
                sDumpWasGenerated = true;
            return "memory dump filename: " + fileName;
                result = "memory dump filename: " + fileName;
            } catch (Throwable e) {
                Log.e(TAG, "dumpHprofData failed", e);
            return "failed to save memory dump";
                result = "failed to save memory dump";
            }
        }
        return result
                + ". Full list of activities: " + ACTIVITY_LEAK_TRACKER.getActivitiesList();
    }

    protected AbstractLauncherUiTest() {
+6 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import androidx.test.InstrumentationRegistry;
import com.android.launcher3.tapl.TestHelpers;

import java.util.WeakHashMap;
import java.util.stream.Collectors;

public class ActivityLeakTracker implements Application.ActivityLifecycleCallbacks {
    private final WeakHashMap<Activity, Boolean> mActivities = new WeakHashMap<>();
@@ -81,4 +82,9 @@ public class ActivityLeakTracker implements Application.ActivityLifecycleCallbac

        return mActivities.size() <= 2;
    }

    public String getActivitiesList() {
        return mActivities.keySet().stream().map(a -> a.getClass().getSimpleName())
                .collect(Collectors.joining(","));
    }
}