diff --git a/apct-tests/perftests/core/src/android/widget/LayoutPerfTest.java b/apct-tests/perftests/core/src/android/widget/LayoutPerfTest.java index ea412eb68e858..d570ef3b2de66 100644 --- a/apct-tests/perftests/core/src/android/widget/LayoutPerfTest.java +++ b/apct-tests/perftests/core/src/android/widget/LayoutPerfTest.java @@ -78,29 +78,31 @@ public class LayoutPerfTest { @Test @UiThreadTest - public void testLayoutPerf() { - assertTrue("We should be running on the main thread", - Looper.getMainLooper().getThread() == Thread.currentThread()); - assertTrue("We should be running on the main thread", - Looper.myLooper() == Looper.getMainLooper()); + public void testLayoutPerf() throws Throwable { + mActivityRule.runOnUiThread(() -> { + assertTrue("We should be running on the main thread", + Looper.getMainLooper().getThread() == Thread.currentThread()); + assertTrue("We should be running on the main thread", + Looper.myLooper() == Looper.getMainLooper()); - Activity activity = mActivityRule.getActivity(); - activity.setContentView(mLayoutId); + Activity activity = mActivityRule.getActivity(); + activity.setContentView(mLayoutId); - ViewGroup viewGroup = (ViewGroup) activity.findViewById(mViewId); + ViewGroup viewGroup = (ViewGroup) activity.findViewById(mViewId); - List allNodes = gatherViewTree(viewGroup); - BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + List allNodes = gatherViewTree(viewGroup); + BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); - int length = mMeasureSpecs.length; - while (state.keepRunning()) { - for (int i = 0; i < length; i++) { - // The overhead of this call is ignorable, like within 1% difference. - requestLayoutForAllNodes(allNodes); + int length = mMeasureSpecs.length; + while (state.keepRunning()) { + for (int i = 0; i < length; i++) { + // The overhead of this call is ignorable, like within 1% difference. + requestLayoutForAllNodes(allNodes); - viewGroup.measure(mMeasureSpecs[i % length], mMeasureSpecs[i % length]); - viewGroup.layout(0, 0, viewGroup.getMeasuredWidth(), viewGroup.getMeasuredHeight()); + viewGroup.measure(mMeasureSpecs[i % length], mMeasureSpecs[i % length]); + viewGroup.layout(0, 0, viewGroup.getMeasuredWidth(), viewGroup.getMeasuredHeight()); + } } - } + }); } }