Update JankUtil to always use the current window.
This allows a test to get content frame stats even if the window has
changed
Change-Id: Ifd97b111f871cffceb27dba023a0235981520e91
diff --git a/src/android/support/test/jank/JankUtil.java b/src/android/support/test/jank/JankUtil.java
index 9e4497b..7f63174 100644
--- a/src/android/support/test/jank/JankUtil.java
+++ b/src/android/support/test/jank/JankUtil.java
@@ -19,6 +19,7 @@
import android.accessibilityservice.AccessibilityServiceInfo;
import android.app.Instrumentation;
import android.app.UiAutomation;
+import android.util.Log;
import android.view.accessibility.AccessibilityWindowInfo;
import android.view.FrameStats;
@@ -28,6 +29,8 @@
/** The {@link JankUtil} class provides functionality for monitoring jank. */
public class JankUtil {
+ private static final String TAG = JankUtil.class.getSimpleName();
+
// Singleton instance
private static JankUtil sInstance;
@@ -57,8 +60,9 @@
if (mMonitor != null) {
throw new IllegalStateException("Monitor already started");
}
+
if (type == JankType.CONTENT_FRAMES) {
- mMonitor = new WindowContentJankMonitor(getCurrentWindow());
+ mMonitor = new WindowContentJankMonitor();
} else if (type == JankType.ANIMATION_FRAMES) {
mMonitor = new WindowAnimationJankMonitor();
} else {
@@ -93,20 +97,23 @@
/** Monitor for detecting window content frame jank. */
private class WindowContentJankMonitor implements JankMonitor {
- private int mWindowId;
-
- public WindowContentJankMonitor(int windowId) {
- mWindowId = windowId;
- }
+ private int mWindowId = -1;
@Override
public void clear() {
+ mWindowId = getCurrentWindow();
mUiAutomation.clearWindowContentFrameStats(mWindowId);
}
@Override
public FrameStats getStats() {
- return mUiAutomation.getWindowContentFrameStats(mWindowId);
+ int currentWindow = getCurrentWindow();
+ if (currentWindow != mWindowId) {
+ Log.w(TAG, "Current window changed during the test. Did you mean to measure " +
+ "ANIMATION_FRAMES?");
+ }
+ mWindowId = -1;
+ return mUiAutomation.getWindowContentFrameStats(currentWindow);
}
}