diff options
3 files changed, 75 insertions, 0 deletions
diff --git a/apct-tests/perftests/contentcapture/src/android/view/contentcapture/AbstractContentCapturePerfTestCase.java b/apct-tests/perftests/contentcapture/src/android/view/contentcapture/AbstractContentCapturePerfTestCase.java index 0ea2dafbb047..bc8470888a5a 100644 --- a/apct-tests/perftests/contentcapture/src/android/view/contentcapture/AbstractContentCapturePerfTestCase.java +++ b/apct-tests/perftests/contentcapture/src/android/view/contentcapture/AbstractContentCapturePerfTestCase.java @@ -248,6 +248,11 @@ public abstract class AbstractContentCapturePerfTestCase { return mServiceWatcher.waitOnCreate(); } + /** Wait for session paused. */ + public void waitForSessionPaused() throws InterruptedException { + mServiceWatcher.waitSessionPaused(); + } + @NonNull protected ActivityWatcher startWatcher() { return mActivitiesWatcher.watch(CustomTestActivity.class); diff --git a/apct-tests/perftests/contentcapture/src/android/view/contentcapture/LoginTest.java b/apct-tests/perftests/contentcapture/src/android/view/contentcapture/LoginTest.java index aa95dfdfdf16..44e8a67e72ef 100644 --- a/apct-tests/perftests/contentcapture/src/android/view/contentcapture/LoginTest.java +++ b/apct-tests/perftests/contentcapture/src/android/view/contentcapture/LoginTest.java @@ -80,6 +80,34 @@ public class LoginTest extends AbstractContentCapturePerfTestCase { testActivityLaunchTime(R.layout.test_container_activity, 500); } + @Test + public void testSendEventsLatency() throws Throwable { + enableService(); + + testSendEventLatency(R.layout.test_container_activity, 0); + } + + @Test + public void testSendEventsLatency_contains100Views() throws Throwable { + enableService(); + + testSendEventLatency(R.layout.test_container_activity, 100); + } + + @Test + public void testSendEventsLatency_contains300Views() throws Throwable { + enableService(); + + testSendEventLatency(R.layout.test_container_activity, 300); + } + + @Test + public void testSendEventsLatency_contains500Views() throws Throwable { + enableService(); + + testSendEventLatency(R.layout.test_container_activity, 500); + } + private void testActivityLaunchTime(int layoutId, int numViews) throws Throwable { final Object drawNotifier = new Object(); final Intent intent = getLaunchIntent(layoutId, numViews); @@ -111,6 +139,38 @@ public class LoginTest extends AbstractContentCapturePerfTestCase { } } + private void testSendEventLatency(int layoutId, int numViews) throws Throwable { + final Object drawNotifier = new Object(); + final Intent intent = getLaunchIntent(layoutId, numViews); + intent.putExtra(CustomTestActivity.INTENT_EXTRA_FINISH_ON_IDLE, true); + intent.putExtra(CustomTestActivity.INTENT_EXTRA_DRAW_CALLBACK, + new RemoteCallback(result -> { + synchronized (drawNotifier) { + drawNotifier.notifyAll(); + } + })); + final ActivityWatcher watcher = startWatcher(); + + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + while (state.keepRunning()) { + mEntryActivity.startActivity(intent); + synchronized (drawNotifier) { + try { + drawNotifier.wait(GENERIC_TIMEOUT_MS); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + waitForSessionPaused(); + + // Ignore the time to finish the activity + state.pauseTiming(); + watcher.waitFor(DESTROYED); + sInstrumentation.waitForIdleSync(); + state.resumeTiming(); + } + } + @Test public void testOnVisibilityAggregated_visibleChanged() throws Throwable { enableService(); diff --git a/apct-tests/perftests/contentcapture/src/android/view/contentcapture/MyContentCaptureService.java b/apct-tests/perftests/contentcapture/src/android/view/contentcapture/MyContentCaptureService.java index ecc5112ab6dd..0b5345f5e2e1 100644 --- a/apct-tests/perftests/contentcapture/src/android/view/contentcapture/MyContentCaptureService.java +++ b/apct-tests/perftests/contentcapture/src/android/view/contentcapture/MyContentCaptureService.java @@ -114,6 +114,10 @@ public class MyContentCaptureService extends ContentCaptureService { public void onContentCaptureEvent(ContentCaptureSessionId sessionId, ContentCaptureEvent event) { Log.i(TAG, "onContentCaptureEventsRequest(session=" + sessionId + "): " + event); + if (sServiceWatcher != null + && event.getType() == ContentCaptureEvent.TYPE_SESSION_PAUSED) { + sServiceWatcher.mSessionPaused.countDown(); + } } @Override @@ -126,6 +130,7 @@ public class MyContentCaptureService extends ContentCaptureService { private static final long GENERIC_TIMEOUT_MS = 10_000; private final CountDownLatch mCreated = new CountDownLatch(1); private final CountDownLatch mDestroyed = new CountDownLatch(1); + private final CountDownLatch mSessionPaused = new CountDownLatch(1); private boolean mReadyToClear = true; private Pair<Set<String>, Set<ComponentName>> mAllowList; @@ -151,6 +156,11 @@ public class MyContentCaptureService extends ContentCaptureService { await(mDestroyed, "not destroyed"); } + /** Wait for session paused. */ + public void waitSessionPaused() throws InterruptedException { + await(mSessionPaused, "no Paused"); + } + /** * Allow just this package. */ |