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

Commit dbcbe9ae authored by MingWei's avatar MingWei
Browse files

Add event latency test in content capture performance test

Other than the startup latency, the latency of sending the events is
critical to content capture performance.

Test: ContentCapturePerfTests
Bug: 322344738
Change-Id: I1ecc90213d1aa9a48f1fc128b3b38ebf68343034
parent e6b3a7f1
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -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);
+60 −0
Original line number Diff line number Diff line
@@ -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();
+10 −0
Original line number Diff line number Diff line
@@ -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.
         */