Merge "Support for counting activity creations" into ub-launcher3-rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
d4066f5876
@@ -101,7 +101,7 @@ public abstract class AbstractLauncherUiTest {
|
||||
private static String sStrictmodeDetectedActivityLeak;
|
||||
private static boolean sActivityLeakReported;
|
||||
private static final String SYSTEMUI_PACKAGE = "com.android.systemui";
|
||||
private static final ActivityLeakTracker ACTIVITY_LEAK_TRACKER = new ActivityLeakTracker();
|
||||
protected static final ActivityLeakTracker ACTIVITY_LEAK_TRACKER = new ActivityLeakTracker();
|
||||
|
||||
protected LooperExecutor mMainThreadExecutor = MAIN_EXECUTOR;
|
||||
protected final UiDevice mDevice = UiDevice.getInstance(getInstrumentation());
|
||||
|
||||
@@ -26,9 +26,11 @@ import com.android.launcher3.tapl.TestHelpers;
|
||||
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
class ActivityLeakTracker implements Application.ActivityLifecycleCallbacks {
|
||||
public class ActivityLeakTracker implements Application.ActivityLifecycleCallbacks {
|
||||
private final WeakHashMap<Activity, Boolean> mActivities = new WeakHashMap<>();
|
||||
|
||||
private int mActivitiesCreated;
|
||||
|
||||
ActivityLeakTracker() {
|
||||
if (!TestHelpers.isInLauncherProcess()) return;
|
||||
final Application app =
|
||||
@@ -36,9 +38,14 @@ class ActivityLeakTracker implements Application.ActivityLifecycleCallbacks {
|
||||
app.registerActivityLifecycleCallbacks(this);
|
||||
}
|
||||
|
||||
public int getActivitiesCreated() {
|
||||
return mActivitiesCreated;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Activity activity, Bundle bundle) {
|
||||
mActivities.put(activity, true);
|
||||
++mActivitiesCreated;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,7 +84,7 @@ class ActivityLeakTracker implements Application.ActivityLifecycleCallbacks {
|
||||
}
|
||||
}
|
||||
|
||||
if (liveActivities > 2) return false;
|
||||
if (liveActivities > 2) return false;
|
||||
|
||||
// It's OK to have 1 leaked activity if no active activities exist.
|
||||
return liveActivities == 0 ? destroyedActivities <= 1 : destroyedActivities == 0;
|
||||
|
||||
Reference in New Issue
Block a user