summaryrefslogtreecommitdiff
path: root/apct-tests
diff options
context:
space:
mode:
authorXin Li <delphij@google.com>2024-01-30 10:36:03 -0800
committerXin Li <delphij@google.com>2024-01-30 10:36:03 -0800
commit7b647e4ea0e92f33c19b315eaed364ee067ba0aa (patch)
tree47c285aa18cf79476d615f8e169ebd823bee6d38 /apct-tests
parent46deec9f696f850efdd4427e10db145d68cbb5bd (diff)
parentefd99108901ae47b085f96c841214f6f416dd86f (diff)
downloadbase-7b647e4ea0e92f33c19b315eaed364ee067ba0aa.tar.gz
Merge Android 24Q1 Release (ab/11220357)
Bug: 319669529 Merged-In: I46c7859ff042ee7aa9193757e5df8269f4892362 Change-Id: I0c7b5036c0b0f5f2caad551edb063350f6eb87e7
Diffstat (limited to 'apct-tests')
-rw-r--r--apct-tests/perftests/core/src/android/accessibility/AccessibilityPerfTest.java164
-rw-r--r--apct-tests/perftests/core/src/android/graphics/perftests/RenderNodePerfTest.java16
-rw-r--r--apct-tests/perftests/core/src/android/graphics/perftests/TypefaceSerializationPerfTest.java24
-rw-r--r--apct-tests/perftests/core/src/android/input/VelocityTrackerBenchmarkTest.kt258
-rw-r--r--apct-tests/perftests/core/src/android/text/TextViewCursorAnchorInfoPerfTest.java2
-rw-r--r--apct-tests/perftests/core/src/android/view/ViewConfigurationPerfTest.java61
-rw-r--r--apct-tests/perftests/core/src/android/view/ViewShowHidePerfTest.java7
-rw-r--r--apct-tests/perftests/inputmethod/OWNERS1
-rw-r--r--apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java1
-rw-r--r--apct-tests/perftests/packagemanager/src/android/os/PackageParsingPerfTest.kt8
-rw-r--r--apct-tests/perftests/rubidium/src/android/rubidium/js/JSScriptEnginePerfTests.java4
-rw-r--r--apct-tests/perftests/surfaceflinger/Android.bp1
-rw-r--r--apct-tests/perftests/surfaceflinger/AndroidManifest.xml4
-rw-r--r--apct-tests/perftests/surfaceflinger/AndroidTest.xml11
-rw-r--r--apct-tests/perftests/surfaceflinger/src/android/surfaceflinger/BufferFlinger.java22
-rw-r--r--apct-tests/perftests/surfaceflinger/src/android/surfaceflinger/SurfaceFlingerPerfTest.java96
-rw-r--r--apct-tests/perftests/surfaceflinger/src/android/surfaceflinger/SurfaceFlingerTestActivity.java15
-rw-r--r--apct-tests/perftests/windowmanager/src/android/wm/InternalWindowOperationPerfTest.java5
-rw-r--r--apct-tests/perftests/windowmanager/src/android/wm/RecentsAnimationPerfTest.java253
-rw-r--r--apct-tests/perftests/windowmanager/src/android/wm/RelayoutPerfTest.java8
-rw-r--r--apct-tests/perftests/windowmanager/src/android/wm/WindowAddRemovePerfTest.java2
21 files changed, 637 insertions, 326 deletions
diff --git a/apct-tests/perftests/core/src/android/accessibility/AccessibilityPerfTest.java b/apct-tests/perftests/core/src/android/accessibility/AccessibilityPerfTest.java
new file mode 100644
index 000000000000..885000fdcf3e
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/accessibility/AccessibilityPerfTest.java
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.accessibility;
+
+import static junit.framework.Assert.assertTrue;
+
+import android.app.Activity;
+import android.app.Instrumentation;
+import android.app.UiAutomation;
+import android.perftests.utils.PerfTestActivity;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityNodeInfo;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import androidx.benchmark.BenchmarkState;
+import androidx.benchmark.junit4.BenchmarkRule;
+import androidx.test.filters.LargeTest;
+import androidx.test.platform.app.InstrumentationRegistry;
+import androidx.test.rule.ActivityTestRule;
+
+import com.android.compatibility.common.util.TestUtils;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.RuleChain;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+@LargeTest
+public class AccessibilityPerfTest {
+
+ private static final String TEXT_KEY = "Child";
+
+ BenchmarkRule mBenchmarkRule = new BenchmarkRule();
+ ActivityTestRule<PerfTestActivity> mActivityTestRule =
+ new ActivityTestRule(PerfTestActivity.class);
+
+ @Rule
+ public RuleChain rules =
+ RuleChain.outerRule(mBenchmarkRule).around(mActivityTestRule);
+
+ private static Instrumentation sInstrumentation;
+
+ private Activity mActivity;
+
+ private ViewGroup createTestViewGroup(int children) {
+ ViewGroup group = new LinearLayout(mActivity.getBaseContext());
+ sInstrumentation.runOnMainSync(() -> {
+ mActivity.setContentView(group);
+ for (int i = 0; i < children; i++) {
+ TextView text = new TextView(mActivity.getBaseContext());
+ text.setText(TEXT_KEY);
+ group.addView(text);
+ }
+ });
+
+ return group;
+ }
+
+ @BeforeClass
+ public static void setUpClass() {
+ sInstrumentation = InstrumentationRegistry.getInstrumentation();
+ }
+
+ @Before
+ public void setUp() {
+ mActivity = mActivityTestRule.getActivity();
+ }
+
+ @Test
+ public void testCreateAccessibilityNodeInfo() {
+ final BenchmarkState state = mBenchmarkRule.getState();
+ View view = new View(mActivity.getBaseContext());
+
+ while (state.keepRunning()) {
+ view.createAccessibilityNodeInfo();
+ }
+ }
+
+ @Test
+ public void testCreateViewGroupAccessibilityNodeInfo() {
+ final BenchmarkState state = mBenchmarkRule.getState();
+ ViewGroup group = createTestViewGroup(10);
+
+ while (state.keepRunning()) {
+ group.createAccessibilityNodeInfo();
+ }
+ }
+
+ @Test
+ public void testCreateAccessibilityEvent() {
+ final BenchmarkState state = mBenchmarkRule.getState();
+ View view = new View(mActivity.getBaseContext());
+
+ while (state.keepRunning()) {
+ view.onInitializeAccessibilityEvent(
+ new AccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED));
+ }
+ }
+
+ @Test
+ public void testPrefetching() throws Exception {
+ final BenchmarkState state = mBenchmarkRule.getState();
+ createTestViewGroup(AccessibilityNodeInfo.MAX_NUMBER_OF_PREFETCHED_NODES);
+ UiAutomation uiAutomation = sInstrumentation.getUiAutomation();
+
+ while (state.keepRunning()) {
+ state.pauseTiming();
+ uiAutomation.clearCache();
+ CountDownLatch latch = new CountDownLatch(
+ AccessibilityNodeInfo.MAX_NUMBER_OF_PREFETCHED_NODES);
+ uiAutomation.getCache().registerOnNodeAddedListener(
+ (node) -> {
+ latch.countDown();
+ });
+ state.resumeTiming();
+ // Get the root node, and await for the latch to have seen the expected max number
+ // of prefetched nodes.
+ uiAutomation.getRootInActiveWindow(
+ AccessibilityNodeInfo.FLAG_PREFETCH_DESCENDANTS_HYBRID
+ | AccessibilityNodeInfo.FLAG_PREFETCH_UNINTERRUPTIBLE);
+ assertTrue(latch.await(100, TimeUnit.MILLISECONDS));
+ }
+ }
+
+ @Test
+ public void testConnectUiAutomation() throws Exception {
+ final BenchmarkState state = mBenchmarkRule.getState();
+ while (state.keepRunning()) {
+ UiAutomation uiAutomation = sInstrumentation.getUiAutomation();
+ state.pauseTiming();
+ uiAutomation.destroy();
+ TestUtils.waitUntil(
+ "UiAutomation did not disconnect.", 10,
+ () -> uiAutomation.isDestroyed()
+ );
+ state.resumeTiming();
+ }
+ // We currently run into an exception
+ // if a test ends with UiAutomation explicitly disconnected,
+ // which seems to be the result of some commands being run by benchmarking.
+ sInstrumentation.getUiAutomation();
+ }
+}
diff --git a/apct-tests/perftests/core/src/android/graphics/perftests/RenderNodePerfTest.java b/apct-tests/perftests/core/src/android/graphics/perftests/RenderNodePerfTest.java
index e805ab912fc1..abb0fa759fc3 100644
--- a/apct-tests/perftests/core/src/android/graphics/perftests/RenderNodePerfTest.java
+++ b/apct-tests/perftests/core/src/android/graphics/perftests/RenderNodePerfTest.java
@@ -42,22 +42,6 @@ public class RenderNodePerfTest {
}
@Test
- public void testCreateRenderNodeNoName() {
- final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
- while (state.keepRunning()) {
- RenderNode.create(null, null);
- }
- }
-
- @Test
- public void testCreateRenderNode() {
- final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
- while (state.keepRunning()) {
- RenderNode.create("LinearLayout", null);
- }
- }
-
- @Test
public void testIsValid() {
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
RenderNode node = RenderNode.create("LinearLayout", null);
diff --git a/apct-tests/perftests/core/src/android/graphics/perftests/TypefaceSerializationPerfTest.java b/apct-tests/perftests/core/src/android/graphics/perftests/TypefaceSerializationPerfTest.java
index bc8fc53cc448..2de6f369796d 100644
--- a/apct-tests/perftests/core/src/android/graphics/perftests/TypefaceSerializationPerfTest.java
+++ b/apct-tests/perftests/core/src/android/graphics/perftests/TypefaceSerializationPerfTest.java
@@ -147,28 +147,4 @@ public class TypefaceSerializationPerfTest {
out.clear();
}
}
-
- @ManualBenchmarkState.ManualBenchmarkTest(
- warmupDurationNs = WARMUP_DURATION_NS,
- targetTestDurationNs = TARGET_TEST_DURATION_NS)
- @Test
- public void testSetSystemFontMap() throws Exception {
- SharedMemory memory = null;
- ManualBenchmarkState state = mPerfManualStatusReporter.getBenchmarkState();
-
- long elapsedTime = 0;
- while (state.keepRunning(elapsedTime)) {
- // Explicitly destroy lazy-loaded typefaces, so that we don't hit the mmap limit
- // (max_map_count).
- Typeface.destroySystemFontMap();
- Typeface.loadPreinstalledSystemFontMap();
- if (memory != null) {
- memory.close();
- }
- memory = Typeface.serializeFontMap(Typeface.getSystemFontMap());
- long startTime = System.nanoTime();
- Typeface.setSystemFontMap(memory);
- elapsedTime = System.nanoTime() - startTime;
- }
- }
}
diff --git a/apct-tests/perftests/core/src/android/input/VelocityTrackerBenchmarkTest.kt b/apct-tests/perftests/core/src/android/input/VelocityTrackerBenchmarkTest.kt
new file mode 100644
index 000000000000..530ca7b7e5a0
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/input/VelocityTrackerBenchmarkTest.kt
@@ -0,0 +1,258 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.input
+
+import android.perftests.utils.PerfStatusReporter
+import android.view.InputDevice
+import android.view.MotionEvent
+import android.view.VelocityTracker
+
+import androidx.test.filters.LargeTest
+import androidx.test.runner.AndroidJUnit4
+
+import java.time.Duration
+
+import org.junit.Assert
+import org.junit.Before
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+
+/**
+ * Helper class to maintain [MotionEvent]s for tests.
+ *
+ * This is primarily used to create [MotionEvent]s for tests, in a way where a sequence of
+ * [MotionEvent]s created in multiple test runs are exactly the same, as long as [reset] is called
+ * between consecutive sequences of [MotionEvent]s.
+ *
+ * Furthermore, it also contains convenience methods to run any queries/verifications of the
+ * generated [MotionEvent]s.
+ */
+abstract class MotionState {
+ /** Current time, in ms. */
+ protected var currentTime = START_TIME
+
+ /** Resets the state of this instance. */
+ open fun reset() {
+ currentTime = START_TIME
+ }
+
+ /** Creates a [MotionEvent]. */
+ abstract fun createMotionEvent(): MotionEvent
+
+ /** Asserts that the current velocity is not zero, just for verifying there's motion. */
+ abstract fun assertNonZeroVelocity(velocityTracker: VelocityTracker)
+
+ companion object {
+ /** Arbitrarily chosen start time. */
+ val START_TIME = Duration.ofMillis(100)
+ /**
+ * A small enough time jump, which won't be considered by the tracker as big enough to
+ * deduce that a pointer has stopped.
+ */
+ val DEFAULT_TIME_JUMP = Duration.ofMillis(2)
+ }
+}
+
+/** An implementation of [MotionState] for [MotionEvent.AXIS_SCROLL]. */
+private class ScrollMotionState : MotionState() {
+ override fun createMotionEvent(): MotionEvent {
+ val props = MotionEvent.PointerProperties()
+ props.id = 0
+ val coords = MotionEvent.PointerCoords()
+ coords.setAxisValue(MotionEvent.AXIS_SCROLL, DEFAULT_SCROLL_AMOUNT)
+ val motionEvent = MotionEvent.obtain(
+ /*downTime=*/0,
+ currentTime.toMillis(),
+ MotionEvent.ACTION_SCROLL,
+ /*pointerCount=*/1,
+ arrayOf(props),
+ arrayOf(coords),
+ /*metaState=*/0,
+ /*buttonState=*/0,
+ /*xPrecision=*/0f,
+ /*yPrecision=*/0f,
+ /*deviceId=*/1,
+ /*edgeFlags=*/0,
+ InputDevice.SOURCE_ROTARY_ENCODER,
+ /*flags=*/0
+ )
+
+ currentTime = currentTime.plus(DEFAULT_TIME_JUMP)
+
+ return motionEvent
+ }
+
+ override fun assertNonZeroVelocity(velocityTracker: VelocityTracker) {
+ Assert.assertTrue(velocityTracker.getAxisVelocity(MotionEvent.AXIS_SCROLL) != 0f)
+ }
+
+ companion object {
+ private val DEFAULT_SCROLL_AMOUNT: Float = 30f
+ }
+}
+
+/** An implementation of [MotionState] for [MotionEvent.AXIS_X] and [MotionEvent.AXIS_Y]. */
+private class PlanarMotionState : MotionState() {
+ private var x: Float = DEFAULT_X
+ private var y: Float = DEFAULT_Y
+ private var downEventCreated = false
+
+ override fun createMotionEvent(): MotionEvent {
+ val action: Int = if (downEventCreated) MotionEvent.ACTION_MOVE else MotionEvent.ACTION_DOWN
+ val motionEvent = MotionEvent.obtain(
+ /*downTime=*/START_TIME.toMillis(),
+ currentTime.toMillis(),
+ action,
+ x,
+ y,
+ /*metaState=*/0)
+
+ if (downEventCreated) {
+ x += INCREMENT
+ y += INCREMENT
+ } else {
+ downEventCreated = true
+ }
+ currentTime = currentTime.plus(DEFAULT_TIME_JUMP)
+
+ return motionEvent
+ }
+
+ override fun assertNonZeroVelocity(velocityTracker: VelocityTracker) {
+ Assert.assertTrue(velocityTracker.getAxisVelocity(MotionEvent.AXIS_X) != 0f)
+ Assert.assertTrue(velocityTracker.getAxisVelocity(MotionEvent.AXIS_Y) != 0f)
+ }
+
+ override fun reset() {
+ super.reset()
+ x = DEFAULT_X
+ y = DEFAULT_Y
+ downEventCreated = false
+ }
+
+ companion object {
+ /** Arbitrarily chosen constants. No need to have varying velocity for now. */
+ private val DEFAULT_X: Float = 2f
+ private val DEFAULT_Y: Float = 4f
+ private val INCREMENT: Float = 0.7f
+ }
+}
+
+/**
+ * Benchmark tests for [VelocityTracker]
+ *
+ * Build/Install/Run:
+ * atest VelocityTrackerBenchmarkTest
+ */
+@LargeTest
+@RunWith(AndroidJUnit4::class)
+class VelocityTrackerBenchmarkTest {
+ @get:Rule
+ val perfStatusReporter: PerfStatusReporter = PerfStatusReporter()
+
+ private val velocityTracker = VelocityTracker.obtain()
+ @Before
+ fun setup() {
+ velocityTracker.clear()
+ }
+
+ @Test
+ fun addMovement_axisScroll() {
+ testAddMovement(ScrollMotionState())
+ }
+
+ @Test
+ fun computeCurrentVelocity_computeAfterAllAdditions_axisScroll() {
+ testComputeCurrentVelocity_computeAfterAllAdditions(ScrollMotionState())
+ }
+
+ @Test
+ fun computeCurrentVelocity_computeAfterEachAdd_axisScroll() {
+ testComputeCurrentVelocity_computeAfterEachAdd(ScrollMotionState())
+ }
+
+ @Test
+ fun addMovement_planarAxes() {
+ testAddMovement(PlanarMotionState())
+ }
+
+ @Test
+ fun computeCurrentVelocity_computeAfterAllAdditions_planarAxes() {
+ testComputeCurrentVelocity_computeAfterAllAdditions(PlanarMotionState())
+ }
+
+ private fun testAddMovement(motionState: MotionState) {
+ val state = perfStatusReporter.getBenchmarkState()
+ while (state.keepRunning()) {
+ state.pauseTiming()
+ for (i in 0 until TEST_NUM_DATAPOINTS) {
+ val motionEvent = motionState.createMotionEvent()
+ state.resumeTiming()
+ velocityTracker.addMovement(motionEvent)
+ state.pauseTiming()
+ }
+ velocityTracker.computeCurrentVelocity(1000)
+ motionState.assertNonZeroVelocity(velocityTracker)
+ // Clear the tracker for the next run
+ velocityTracker.clear()
+ motionState.reset()
+ state.resumeTiming()
+ }
+ }
+
+ private fun testComputeCurrentVelocity_computeAfterAllAdditions(motionState: MotionState) {
+ val state = perfStatusReporter.getBenchmarkState()
+ while (state.keepRunning()) {
+ // Add the data points
+ state.pauseTiming()
+ for (i in 0 until TEST_NUM_DATAPOINTS) {
+ velocityTracker.addMovement(motionState.createMotionEvent())
+ }
+
+ // Do the velocity computation
+ state.resumeTiming()
+ velocityTracker.computeCurrentVelocity(1000)
+
+ state.pauseTiming()
+ motionState.assertNonZeroVelocity(velocityTracker)
+ // Clear the tracker for the next run
+ velocityTracker.clear()
+ state.resumeTiming()
+ }
+ }
+
+ private fun testComputeCurrentVelocity_computeAfterEachAdd(motionState: MotionState) {
+ val state = perfStatusReporter.getBenchmarkState()
+ while (state.keepRunning()) {
+ state.pauseTiming()
+ for (i in 0 until TEST_NUM_DATAPOINTS) {
+ velocityTracker.addMovement(motionState.createMotionEvent())
+ state.resumeTiming()
+ velocityTracker.computeCurrentVelocity(1000)
+ state.pauseTiming()
+ }
+ motionState.assertNonZeroVelocity(velocityTracker)
+ // Clear the tracker for the next run
+ velocityTracker.clear()
+ state.resumeTiming()
+ }
+ }
+
+ companion object {
+ private const val TEST_NUM_DATAPOINTS = 100
+ }
+} \ No newline at end of file
diff --git a/apct-tests/perftests/core/src/android/text/TextViewCursorAnchorInfoPerfTest.java b/apct-tests/perftests/core/src/android/text/TextViewCursorAnchorInfoPerfTest.java
index 898111f2fd8a..436ee16504bb 100644
--- a/apct-tests/perftests/core/src/android/text/TextViewCursorAnchorInfoPerfTest.java
+++ b/apct-tests/perftests/core/src/android/text/TextViewCursorAnchorInfoPerfTest.java
@@ -22,13 +22,13 @@ import android.content.Context;
import android.perftests.utils.BenchmarkState;
import android.perftests.utils.PerfStatusReporter;
import android.perftests.utils.PerfTestActivity;
-import android.platform.test.annotations.LargeTest;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.CursorAnchorInfo;
import android.widget.TextView;
+import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;
import org.junit.Before;
diff --git a/apct-tests/perftests/core/src/android/view/ViewConfigurationPerfTest.java b/apct-tests/perftests/core/src/android/view/ViewConfigurationPerfTest.java
new file mode 100644
index 000000000000..7a7250b9e910
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/view/ViewConfigurationPerfTest.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.view;
+
+import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
+
+import android.content.Context;
+
+import androidx.benchmark.BenchmarkState;
+import androidx.benchmark.junit4.BenchmarkRule;
+import androidx.test.filters.SmallTest;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+@SmallTest
+public class ViewConfigurationPerfTest {
+ @Rule
+ public final BenchmarkRule mBenchmarkRule = new BenchmarkRule();
+
+ private final Context mContext = getInstrumentation().getTargetContext();
+
+ @Test
+ public void testGet_newViewConfiguration() {
+ final BenchmarkState state = mBenchmarkRule.getState();
+
+ while (state.keepRunning()) {
+ state.pauseTiming();
+ // Reset cache so that `ViewConfiguration#get` creates a new instance.
+ ViewConfiguration.resetCacheForTesting();
+ state.resumeTiming();
+
+ ViewConfiguration.get(mContext);
+ }
+ }
+
+ @Test
+ public void testGet_cachedViewConfiguration() {
+ final BenchmarkState state = mBenchmarkRule.getState();
+ // Do `get` once to make sure there's something cached.
+ ViewConfiguration.get(mContext);
+
+ while (state.keepRunning()) {
+ ViewConfiguration.get(mContext);
+ }
+ }
+}
diff --git a/apct-tests/perftests/core/src/android/view/ViewShowHidePerfTest.java b/apct-tests/perftests/core/src/android/view/ViewShowHidePerfTest.java
index a69d3ffa46fa..818e11b407d5 100644
--- a/apct-tests/perftests/core/src/android/view/ViewShowHidePerfTest.java
+++ b/apct-tests/perftests/core/src/android/view/ViewShowHidePerfTest.java
@@ -18,6 +18,7 @@ package android.view;
import static org.junit.Assert.assertTrue;
+import android.app.UiAutomation;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
@@ -29,8 +30,8 @@ import android.widget.LinearLayout;
import androidx.benchmark.BenchmarkState;
import androidx.benchmark.junit4.BenchmarkRule;
-import androidx.test.InstrumentationRegistry;
import androidx.test.filters.LargeTest;
+import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;
import org.junit.Rule;
@@ -142,6 +143,10 @@ public class ViewShowHidePerfTest {
}
private void testParentWithChild(TestCallback callback) throws Throwable {
+ // Make sure that a11y is disabled to prevent the test affected by accessibility events.
+ InstrumentationRegistry.getInstrumentation()
+ .getUiAutomation(UiAutomation.FLAG_DONT_USE_ACCESSIBILITY);
+
mActivityRule.runOnUiThread(() -> {
final BenchmarkState state = mBenchmarkRule.getState();
diff --git a/apct-tests/perftests/inputmethod/OWNERS b/apct-tests/perftests/inputmethod/OWNERS
index 5deb2ce8f24b..cbd94ba6b467 100644
--- a/apct-tests/perftests/inputmethod/OWNERS
+++ b/apct-tests/perftests/inputmethod/OWNERS
@@ -1 +1,2 @@
+# Bug component: 34867
include /core/java/android/view/inputmethod/OWNERS
diff --git a/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java b/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java
index a2c67bc3c2e5..68717623d05d 100644
--- a/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java
+++ b/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java
@@ -1557,6 +1557,7 @@ public class UserLifecycleTests {
}
private void waitCoolDownPeriod() {
+ // Heuristic value based on local tests. Stability increased compared to no waiting.
final int tenSeconds = 1000 * 10;
waitForBroadcastIdle();
sleep(tenSeconds);
diff --git a/apct-tests/perftests/packagemanager/src/android/os/PackageParsingPerfTest.kt b/apct-tests/perftests/packagemanager/src/android/os/PackageParsingPerfTest.kt
index 6d1e6d0cbd73..4352c8ae982e 100644
--- a/apct-tests/perftests/packagemanager/src/android/os/PackageParsingPerfTest.kt
+++ b/apct-tests/perftests/packagemanager/src/android/os/PackageParsingPerfTest.kt
@@ -24,10 +24,11 @@ import android.content.pm.parsing.result.ParseTypeImpl
import android.content.res.TypedArray
import android.perftests.utils.BenchmarkState
import android.perftests.utils.PerfStatusReporter
+import android.util.ArraySet
import androidx.test.filters.LargeTest
+import com.android.internal.pm.parsing.pkg.PackageImpl
+import com.android.internal.pm.pkg.parsing.ParsingPackageUtils
import com.android.internal.util.ConcurrentUtils
-import com.android.server.pm.parsing.pkg.PackageImpl
-import com.android.server.pm.pkg.parsing.ParsingPackageUtils
import java.io.File
import java.io.FileOutputStream
import java.util.concurrent.ArrayBlockingQueue
@@ -214,7 +215,10 @@ public class PackageParsingPerfTest {
path,
manifestArray,
isCoreApp,
+ this,
)
+ override fun getHiddenApiWhitelistedApps() = ArraySet<String>()
+ override fun getInstallConstraintsAllowlist() = ArraySet<String>()
})
override fun parseImpl(file: File) =
diff --git a/apct-tests/perftests/rubidium/src/android/rubidium/js/JSScriptEnginePerfTests.java b/apct-tests/perftests/rubidium/src/android/rubidium/js/JSScriptEnginePerfTests.java
index cbd602f0de76..ba15796f47fe 100644
--- a/apct-tests/perftests/rubidium/src/android/rubidium/js/JSScriptEnginePerfTests.java
+++ b/apct-tests/perftests/rubidium/src/android/rubidium/js/JSScriptEnginePerfTests.java
@@ -44,6 +44,7 @@ import androidx.test.core.app.ApplicationProvider;
import androidx.test.filters.MediumTest;
import androidx.test.runner.AndroidJUnit4;
+import com.android.adservices.LoggerFactory;
import com.android.adservices.data.adselection.CustomAudienceSignals;
import com.android.adservices.service.adselection.AdCounterKeyCopier;
import com.android.adservices.service.adselection.AdCounterKeyCopierNoOpImpl;
@@ -101,9 +102,10 @@ public class JSScriptEnginePerfTests {
private static final Context sContext = ApplicationProvider.getApplicationContext();
private static final ExecutorService sExecutorService = Executors.newFixedThreadPool(10);
+ private static final LoggerFactory.Logger sLogger = LoggerFactory.getFledgeLogger();
private static final JSScriptEngine sJSScriptEngine =
JSScriptEngine.getInstanceForTesting(
- sContext, Profiler.createInstance(JSScriptEngine.TAG));
+ sContext, Profiler.createInstance(JSScriptEngine.TAG), sLogger);
private static final Clock CLOCK = Clock.fixed(Instant.now(), ZoneOffset.UTC);
private static final Instant ACTIVATION_TIME = CLOCK.instant();
private static final Instant EXPIRATION_TIME = CLOCK.instant().plus(Duration.ofDays(1));
diff --git a/apct-tests/perftests/surfaceflinger/Android.bp b/apct-tests/perftests/surfaceflinger/Android.bp
index 0c28bcef469c..21d0d44fdd2f 100644
--- a/apct-tests/perftests/surfaceflinger/Android.bp
+++ b/apct-tests/perftests/surfaceflinger/Android.bp
@@ -32,6 +32,7 @@ android_test {
"apct-perftests-utils",
"collector-device-lib",
"platform-test-annotations",
+ "cts-wm-util",
],
test_suites: ["device-tests"],
data: [":perfetto_artifacts"],
diff --git a/apct-tests/perftests/surfaceflinger/AndroidManifest.xml b/apct-tests/perftests/surfaceflinger/AndroidManifest.xml
index 26f25863f055..aa55b01cc787 100644
--- a/apct-tests/perftests/surfaceflinger/AndroidManifest.xml
+++ b/apct-tests/perftests/surfaceflinger/AndroidManifest.xml
@@ -16,9 +16,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android.perftests.surfaceflinger">
- <!-- permission needed to write perfetto trace and read/write simpleperf report -->
+ <!-- permission needed to read/write simpleperf report -->
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <!-- permission needed to disable tracing -->
+ <uses-permission android:name="android.permission.HARDWARE_TEST" />
<application android:label="SurfaceFlingerPerfTests">
<uses-library android:name="android.test.runner" />
diff --git a/apct-tests/perftests/surfaceflinger/AndroidTest.xml b/apct-tests/perftests/surfaceflinger/AndroidTest.xml
index 58cf58b89782..6dcd86e156d9 100644
--- a/apct-tests/perftests/surfaceflinger/AndroidTest.xml
+++ b/apct-tests/perftests/surfaceflinger/AndroidTest.xml
@@ -44,17 +44,12 @@
<option name="hidden-api-checks" value="false"/>
<!-- Listener related args for collecting the traces and waiting for the device to stabilize. -->
- <option name="device-listeners" value="android.device.collectors.ProcLoadListener,android.device.collectors.PerfettoListener,android.device.collectors.SimpleperfListener" />
-
- <!-- Guarantee that user defined RunListeners will be running before any of the default listeners defined in this runner. -->
- <option name="instrumentation-arg" key="newRunListenerMode" value="true" />
+ <option name="device-listeners" value="android.device.collectors.ProcLoadListener,android.device.collectors.SimpleperfListener" />
<option name="instrumentation-arg" key="profiling-iterations" value="525" />
- <!-- PerfettoListener related arguments -->
- <option name="instrumentation-arg" key="perfetto_config_text_proto" value="true" />
- <option name="instrumentation-arg" key="perfetto_config_file" value="trace_config.textproto" />
<!-- SimpleperfListener related arguments -->
+ <option name="instrumentation-arg" key="record" value="false"/>
<option name="instrumentation-arg" key="report" value="true" />
<option name="instrumentation-arg" key="arguments" value="-g" />
<option name="instrumentation-arg" key="events_to_record" value="instructions,cpu-cycles,raw-l3d-cache-refill,sched:sched_waking" />
@@ -70,13 +65,11 @@
<option name="instrumentation-arg" key="proc-loadavg-threshold" value="3" />
<option name="instrumentation-arg" key="proc-loadavg-timeout" value="120000" />
<option name="instrumentation-arg" key="proc-loadavg-interval" value="10000" />
-
</test>
<metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector">
<option name="directory-keys" value="/data/local/tmp/SurfaceFlingerPerfTests" />
<!-- Needed for pulling the collected trace config on to the host -->
- <option name="pull-pattern-keys" value="perfetto_file_path" />
<option name="pull-pattern-keys" value="simpleperf_file_path" />
</metrics_collector>
diff --git a/apct-tests/perftests/surfaceflinger/src/android/surfaceflinger/BufferFlinger.java b/apct-tests/perftests/surfaceflinger/src/android/surfaceflinger/BufferFlinger.java
index 8a447bb801f2..8d6dd127645f 100644
--- a/apct-tests/perftests/surfaceflinger/src/android/surfaceflinger/BufferFlinger.java
+++ b/apct-tests/perftests/surfaceflinger/src/android/surfaceflinger/BufferFlinger.java
@@ -16,6 +16,10 @@
package android.surfaceflinger;
+import static android.view.SurfaceControl.BUFFER_TRANSFORM_IDENTITY;
+import static android.view.SurfaceControl.BUFFER_TRANSFORM_ROTATE_270;
+import static android.view.SurfaceControl.BUFFER_TRANSFORM_ROTATE_90;
+
import android.annotation.ColorInt;
import android.graphics.Canvas;
import android.graphics.GraphicBuffer;
@@ -33,9 +37,11 @@ import java.util.concurrent.ArrayBlockingQueue;
* @hide
*/
public class BufferFlinger {
+ private final int mTransformHint;
ArrayBlockingQueue<GraphicBuffer> mBufferQ;
- public BufferFlinger(int numOfBuffers, @ColorInt int color) {
+ public BufferFlinger(int numOfBuffers, @ColorInt int color, int bufferTransformHint) {
+ mTransformHint = bufferTransformHint;
mBufferQ = new ArrayBlockingQueue<>(numOfBuffers);
while (numOfBuffers > 0) {
@@ -56,12 +62,18 @@ public class BufferFlinger {
public void addBuffer(SurfaceControl.Transaction t, SurfaceControl surfaceControl) {
try {
final GraphicBuffer buffer = mBufferQ.take();
- t.setBuffer(surfaceControl,
+ int transform = BUFFER_TRANSFORM_IDENTITY;
+ if (mTransformHint == BUFFER_TRANSFORM_ROTATE_90) {
+ transform = BUFFER_TRANSFORM_ROTATE_270;
+ } else if (mTransformHint == BUFFER_TRANSFORM_ROTATE_270) {
+ transform = BUFFER_TRANSFORM_ROTATE_90;
+ }
+ t.setBufferTransform(surfaceControl, transform);
+ t.setBuffer(
+ surfaceControl,
HardwareBuffer.createFromGraphicBuffer(buffer),
null,
- (SyncFence fence) -> {
- releaseCallback(fence, buffer);
- });
+ (SyncFence fence) -> releaseCallback(fence, buffer));
} catch (InterruptedException ignore) {
}
}
diff --git a/apct-tests/perftests/surfaceflinger/src/android/surfaceflinger/SurfaceFlingerPerfTest.java b/apct-tests/perftests/surfaceflinger/src/android/surfaceflinger/SurfaceFlingerPerfTest.java
index dca818ec9708..c53cc1820b6f 100644
--- a/apct-tests/perftests/surfaceflinger/src/android/surfaceflinger/SurfaceFlingerPerfTest.java
+++ b/apct-tests/perftests/surfaceflinger/src/android/surfaceflinger/SurfaceFlingerPerfTest.java
@@ -16,22 +16,31 @@
package android.surfaceflinger;
+import static android.server.wm.CtsWindowInfoUtils.waitForWindowOnTop;
+import static android.provider.Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS;
+
+import android.app.Instrumentation;
+import android.content.ContentResolver;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.os.Bundle;
+import android.provider.Settings;
import android.util.Log;
import android.view.SurfaceControl;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
-
import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.filters.LargeTest;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
+import com.android.compatibility.common.util.SystemUtil;
+import com.android.helpers.SimpleperfHelper;
+
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
@@ -39,6 +48,8 @@ import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.runner.RunWith;
+import java.io.IOException;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Random;
@@ -63,31 +74,103 @@ public class SurfaceFlingerPerfTest {
public final RuleChain mAllRules = RuleChain
.outerRule(mActivityRule);
+ private int mTransformHint;
+ private SimpleperfHelper mSimpleperfHelper = new SimpleperfHelper();
+ private static String sImmersiveModeConfirmationValue;
+ /** Start simpleperf sampling. */
+ public void startSimpleperf(String subcommand, String arguments) {
+ if (!mSimpleperfHelper.startCollecting(subcommand, arguments)) {
+ Log.e(TAG, "Simpleperf did not start successfully.");
+ }
+ }
+
+ /** Stop simpleperf sampling and dump the collected file into the given path. */
+ private void stopSimpleperf(Path path) {
+ if (!mSimpleperfHelper.stopCollecting(path.toString())) {
+ Log.e(TAG, "Failed to collect the simpleperf output.");
+ }
+ }
+
@BeforeClass
public static void suiteSetup() {
+ SystemUtil.runWithShellPermissionIdentity(() -> {
+ // hide immersive mode confirmation dialog
+ final ContentResolver resolver =
+ InstrumentationRegistry.getInstrumentation().getContext().getContentResolver();
+ sImmersiveModeConfirmationValue =
+ Settings.Secure.getString(resolver, IMMERSIVE_MODE_CONFIRMATIONS);
+ Settings.Secure.putString(
+ resolver,
+ IMMERSIVE_MODE_CONFIRMATIONS,
+ "confirmed");
+ });
final Bundle arguments = InstrumentationRegistry.getArguments();
sProfilingIterations = Integer.parseInt(
arguments.getString(ARGUMENT_PROFILING_ITERATIONS, DEFAULT_PROFILING_ITERATIONS));
Log.d(TAG, "suiteSetup: mProfilingIterations = " + sProfilingIterations);
+ // disable transaction tracing
+ InstrumentationRegistry.getInstrumentation()
+ .getUiAutomation()
+ .executeShellCommand("service call SurfaceFlinger 1041 i32 -1");
+ }
+
+ @AfterClass
+ public static void suiteTeardown() {
+ SystemUtil.runWithShellPermissionIdentity(() -> {
+ // Restore the immersive mode confirmation state.
+ Settings.Secure.putString(
+ InstrumentationRegistry.getInstrumentation().getContext().getContentResolver(),
+ IMMERSIVE_MODE_CONFIRMATIONS,
+ sImmersiveModeConfirmationValue);
+ });
}
+
@Before
public void setup() {
mActivityRule.getScenario().onActivity(activity -> mActivity = activity);
SurfaceControl.Transaction t = new SurfaceControl.Transaction();
for (int i = 0; i < MAX_BUFFERS; i++) {
SurfaceControl sc = createSurfaceControl();
- BufferFlinger bufferTracker = createBufferTracker(Color.argb(getRandomColorComponent(),
- getRandomColorComponent(), getRandomColorComponent(),
- getRandomColorComponent()));
+ BufferFlinger bufferTracker =
+ createBufferTracker(
+ Color.argb(
+ getRandomColorComponent(),
+ getRandomColorComponent(),
+ getRandomColorComponent(),
+ getRandomColorComponent()),
+ mActivity.getBufferTransformHint());
bufferTracker.addBuffer(t, sc);
t.setPosition(sc, i * 10, i * 10);
}
t.apply(true);
+ mBufferTrackers.get(0).addBuffer(mTransaction, mSurfaceControls.get(0));
+ mTransaction.show(mSurfaceControls.get(0)).apply(true);
+ Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
+
+ instrumentation.waitForIdleSync();
+ // Wait for device animation that shows above the activity to leave.
+ try {
+ waitForWindowOnTop(mActivity.getWindow());
+ } catch (InterruptedException e) {
+ Log.e(TAG, "Failed to wait for window", e);
+ }
+ String args =
+ "-o /data/local/tmp/perf.data -g -e"
+ + " instructions,cpu-cycles,raw-l3d-cache-refill,sched:sched_waking -p "
+ + mSimpleperfHelper.getPID("surfaceflinger")
+ + ","
+ + mSimpleperfHelper.getPID("android.perftests.surfaceflinger");
+ startSimpleperf("record", args);
}
@After
public void teardown() {
+ try {
+ mSimpleperfHelper.stopSimpleperf();
+ } catch (IOException e) {
+ Log.e(TAG, "Failed to stop simpleperf", e);
+ }
mSurfaceControls.forEach(SurfaceControl::release);
mBufferTrackers.forEach(BufferFlinger::freeBuffers);
}
@@ -97,8 +180,9 @@ public class SurfaceFlingerPerfTest {
}
private final ArrayList<BufferFlinger> mBufferTrackers = new ArrayList<>();
- private BufferFlinger createBufferTracker(int color) {
- BufferFlinger bufferTracker = new BufferFlinger(BUFFER_COUNT, color);
+
+ private BufferFlinger createBufferTracker(int color, int bufferTransformHint) {
+ BufferFlinger bufferTracker = new BufferFlinger(BUFFER_COUNT, color, bufferTransformHint);
mBufferTrackers.add(bufferTracker);
return bufferTracker;
}
diff --git a/apct-tests/perftests/surfaceflinger/src/android/surfaceflinger/SurfaceFlingerTestActivity.java b/apct-tests/perftests/surfaceflinger/src/android/surfaceflinger/SurfaceFlingerTestActivity.java
index bb956596c7eb..5f1f44d826e5 100644
--- a/apct-tests/perftests/surfaceflinger/src/android/surfaceflinger/SurfaceFlingerTestActivity.java
+++ b/apct-tests/perftests/surfaceflinger/src/android/surfaceflinger/SurfaceFlingerTestActivity.java
@@ -16,12 +16,15 @@
package android.surfaceflinger;
+import static android.view.Surface.FRAME_RATE_COMPATIBILITY_DEFAULT;
+
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.SurfaceControl;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
+import android.view.View;
import android.view.Window;
import android.view.WindowManager;
@@ -42,6 +45,11 @@ public class SurfaceFlingerTestActivity extends Activity {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ View decorView = getWindow().getDecorView();
+ // Hide both the navigation bar and the status bar.
+ int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
+ decorView.setSystemUiVisibility(uiOptions);
+
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
mTestSurfaceView = new TestSurfaceView(this);
setContentView(mTestSurfaceView);
@@ -51,6 +59,10 @@ public class SurfaceFlingerTestActivity extends Activity {
return mTestSurfaceView.getChildSurfaceControlHelper();
}
+ public int getBufferTransformHint() {
+ return mTestSurfaceView.getRootSurfaceControl().getBufferTransformHint();
+ }
+
public class TestSurfaceView extends SurfaceView {
public TestSurfaceView(Context context) {
super(context);
@@ -79,6 +91,9 @@ public class SurfaceFlingerTestActivity extends Activity {
// check to see if surface is valid
if (holder.getSurface().isValid()) {
mSurfaceControl = getSurfaceControl();
+ new SurfaceControl.Transaction()
+ .setFrameRate(mSurfaceControl, 1000, FRAME_RATE_COMPATIBILITY_DEFAULT)
+ .apply(true);
}
return new SurfaceControl.Builder()
.setName("ChildSurfaceControl")
diff --git a/apct-tests/perftests/windowmanager/src/android/wm/InternalWindowOperationPerfTest.java b/apct-tests/perftests/windowmanager/src/android/wm/InternalWindowOperationPerfTest.java
index 3a114173869a..d3b4f23477da 100644
--- a/apct-tests/perftests/windowmanager/src/android/wm/InternalWindowOperationPerfTest.java
+++ b/apct-tests/perftests/windowmanager/src/android/wm/InternalWindowOperationPerfTest.java
@@ -52,9 +52,8 @@ public class InternalWindowOperationPerfTest extends WindowManagerPerfTestBase
private final TraceMarkParser mTraceMarkParser = new TraceMarkParser(
"applyPostLayoutPolicy",
"applySurfaceChanges",
- "AppTransitionReady",
- "closeSurfaceTransaction",
- "openSurfaceTransaction",
+ "onTransactionReady",
+ "applyTransaction",
"performLayout",
"performSurfacePlacement",
"prepareSurfaces",
diff --git a/apct-tests/perftests/windowmanager/src/android/wm/RecentsAnimationPerfTest.java b/apct-tests/perftests/windowmanager/src/android/wm/RecentsAnimationPerfTest.java
deleted file mode 100644
index 42fb24f570d2..000000000000
--- a/apct-tests/perftests/windowmanager/src/android/wm/RecentsAnimationPerfTest.java
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.wm;
-
-import static android.perftests.utils.ManualBenchmarkState.StatsReport;
-
-import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
-
-import static org.hamcrest.core.AnyOf.anyOf;
-import static org.hamcrest.core.Is.is;
-
-import android.app.ActivityManager;
-import android.app.ActivityTaskManager;
-import android.app.IActivityTaskManager;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.graphics.Rect;
-import android.os.RemoteException;
-import android.os.SystemClock;
-import android.perftests.utils.ManualBenchmarkState;
-import android.perftests.utils.ManualBenchmarkState.ManualBenchmarkTest;
-import android.perftests.utils.PerfManualStatusReporter;
-import android.util.Pair;
-import android.view.IRecentsAnimationController;
-import android.view.IRecentsAnimationRunner;
-import android.view.RemoteAnimationTarget;
-import android.window.TaskSnapshot;
-
-import androidx.test.filters.LargeTest;
-import androidx.test.runner.lifecycle.Stage;
-
-import org.junit.AfterClass;
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.concurrent.Semaphore;
-import java.util.concurrent.TimeUnit;
-
-@RunWith(Parameterized.class)
-@LargeTest
-public class RecentsAnimationPerfTest extends WindowManagerPerfTestBase
- implements ManualBenchmarkState.CustomizedIterationListener {
- private static Intent sRecentsIntent;
-
- @Rule
- public final PerfManualStatusReporter mPerfStatusReporter = new PerfManualStatusReporter();
-
- @Rule
- public final PerfTestActivityRule mActivityRule =
- new PerfTestActivityRule(true /* launchActivity */);
-
- private long mMeasuredTimeNs;
-
- /**
- * Used to skip each test method if there is error. It cannot be raised in static setup because
- * that will break the amount of target method count.
- */
- private static Exception sSetUpClassException;
-
- @Parameterized.Parameter(0)
- public int intervalBetweenOperations;
-
- @Parameterized.Parameters(name = "interval{0}ms")
- public static Collection<Object[]> getParameters() {
- return Arrays.asList(new Object[][] {
- { 0 },
- { 100 },
- { 300 },
- });
- }
-
- @BeforeClass
- public static void setUpClass() {
- // Get the permission to invoke startRecentsActivity.
- getUiAutomation().adoptShellPermissionIdentity();
-
- final Context context = getInstrumentation().getContext();
- final PackageManager pm = context.getPackageManager();
- final ComponentName defaultHome = pm.getHomeActivities(new ArrayList<>());
-
- try {
- final ComponentName recentsComponent =
- ComponentName.unflattenFromString(context.getResources().getString(
- com.android.internal.R.string.config_recentsComponentName));
- final int enabledState = pm.getComponentEnabledSetting(recentsComponent);
- Assume.assumeThat(enabledState, anyOf(
- is(PackageManager.COMPONENT_ENABLED_STATE_DEFAULT),
- is(PackageManager.COMPONENT_ENABLED_STATE_ENABLED)));
-
- final boolean homeIsRecents =
- recentsComponent.getPackageName().equals(defaultHome.getPackageName());
- sRecentsIntent =
- new Intent().setComponent(homeIsRecents ? defaultHome : recentsComponent);
- } catch (Exception e) {
- sSetUpClassException = e;
- }
- }
-
- @AfterClass
- public static void tearDownClass() {
- sSetUpClassException = null;
- try {
- // Recents activity may stop app switches. Restore the state to avoid affecting
- // the next test.
- ActivityManager.resumeAppSwitches();
- } catch (RemoteException ignored) {
- }
- getUiAutomation().dropShellPermissionIdentity();
- }
-
- @Before
- public void setUp() {
- Assume.assumeNoException(sSetUpClassException);
- }
-
- /** Simulate the timing of touch. */
- private void makeInterval() {
- SystemClock.sleep(intervalBetweenOperations);
- }
-
- /**
- * <pre>
- * Steps:
- * (1) Start recents activity (only make it visible).
- * (2) Finish animation, take turns to execute (a), (b).
- * (a) Move recents activity to top.
- * ({@link com.android.server.wm.RecentsAnimationController#REORDER_MOVE_TO_TOP})
- * Move test app to top by startActivityFromRecents.
- * (b) Cancel (it is similar to swipe a little distance and give up to enter recents).
- * ({@link com.android.server.wm.RecentsAnimationController#REORDER_MOVE_TO_ORIGINAL_POSITION})
- * (3) Loop (1).
- * </pre>
- */
- @Test
- @ManualBenchmarkTest(
- warmupDurationNs = TIME_1_S_IN_NS,
- targetTestDurationNs = TIME_5_S_IN_NS,
- statsReport = @StatsReport(flags = StatsReport.FLAG_ITERATION | StatsReport.FLAG_MEAN
- | StatsReport.FLAG_COEFFICIENT_VAR))
- public void testRecentsAnimation() throws Throwable {
- final ManualBenchmarkState state = mPerfStatusReporter.getBenchmarkState();
- state.setCustomizedIterations(getProfilingIterations(), this);
- final IActivityTaskManager atm = ActivityTaskManager.getService();
-
- final ArrayList<Pair<String, Boolean>> finishCases = new ArrayList<>();
- // Real launch the recents activity.
- finishCases.add(new Pair<>("finishMoveToTop", true));
- // Return to the original top.
- finishCases.add(new Pair<>("finishCancel", false));
-
- // Ensure startRecentsActivity won't be called before finishing the animation.
- final Semaphore recentsSemaphore = new Semaphore(1);
-
- final int testActivityTaskId = mActivityRule.getActivity().getTaskId();
- final IRecentsAnimationRunner.Stub anim = new IRecentsAnimationRunner.Stub() {
- int mIteration;
-
- @Override
- public void onAnimationStart(IRecentsAnimationController controller,
- RemoteAnimationTarget[] apps, RemoteAnimationTarget[] wallpapers,
- Rect homeContentInsets, Rect minimizedHomeBounds) throws RemoteException {
- final Pair<String, Boolean> finishCase = finishCases.get(mIteration++ % 2);
- final boolean moveRecentsToTop = finishCase.second;
- makeInterval();
-
- long startTime = SystemClock.elapsedRealtimeNanos();
- controller.finish(moveRecentsToTop, false /* sendUserLeaveHint */);
- final long elapsedTimeNsOfFinish = SystemClock.elapsedRealtimeNanos() - startTime;
- mMeasuredTimeNs += elapsedTimeNsOfFinish;
- state.addExtraResult(finishCase.first, elapsedTimeNsOfFinish);
-
- if (moveRecentsToTop) {
- mActivityRule.waitForIdleSync(Stage.STOPPED);
-
- startTime = SystemClock.elapsedRealtimeNanos();
- atm.startActivityFromRecents(testActivityTaskId, null /* options */);
- final long elapsedTimeNs = SystemClock.elapsedRealtimeNanos() - startTime;
- mMeasuredTimeNs += elapsedTimeNs;
- state.addExtraResult("startFromRecents", elapsedTimeNs);
-
- mActivityRule.waitForIdleSync(Stage.RESUMED);
- }
-
- makeInterval();
- recentsSemaphore.release();
- }
-
- @Override
- public void onAnimationCanceled(int[] taskIds, TaskSnapshot[] taskSnapshots)
- throws RemoteException {
- Assume.assumeNoException(
- new AssertionError("onAnimationCanceled should not be called"));
- }
-
- @Override
- public void onTasksAppeared(RemoteAnimationTarget[] app) throws RemoteException {
- /* no-op */
- }
- };
-
- recentsSemaphore.tryAcquire();
- while (state.keepRunning(mMeasuredTimeNs)) {
- mMeasuredTimeNs = 0;
-
- final long startTime = SystemClock.elapsedRealtimeNanos();
- atm.startRecentsActivity(sRecentsIntent, 0 /* eventTime */, anim);
- final long elapsedTimeNsOfStart = SystemClock.elapsedRealtimeNanos() - startTime;
- mMeasuredTimeNs += elapsedTimeNsOfStart;
- state.addExtraResult("start", elapsedTimeNsOfStart);
-
- // Ensure the animation callback is done.
- Assume.assumeTrue(recentsSemaphore.tryAcquire(
- sIsProfilingMethod() ? 10 * TIME_5_S_IN_NS : TIME_5_S_IN_NS,
- TimeUnit.NANOSECONDS));
- }
- }
-
- @Override
- public void onStart(int iteration) {
- startProfiling(RecentsAnimationPerfTest.class.getSimpleName()
- + "_interval_" + intervalBetweenOperations
- + "_MethodTracing_" + iteration + ".trace");
- }
-
- @Override
- public void onFinished(int iteration) {
- stopProfiling();
- }
-}
diff --git a/apct-tests/perftests/windowmanager/src/android/wm/RelayoutPerfTest.java b/apct-tests/perftests/windowmanager/src/android/wm/RelayoutPerfTest.java
index c42c7ca25133..2ace6028456e 100644
--- a/apct-tests/perftests/windowmanager/src/android/wm/RelayoutPerfTest.java
+++ b/apct-tests/perftests/windowmanager/src/android/wm/RelayoutPerfTest.java
@@ -128,6 +128,7 @@ public class RelayoutPerfTest extends WindowManagerPerfTestBase
final MergedConfiguration mOutMergedConfiguration = new MergedConfiguration();
final InsetsState mOutInsetsState = new InsetsState();
final InsetsSourceControl.Array mOutControls = new InsetsSourceControl.Array();
+ final Bundle mOutBundle = new Bundle();
final IWindow mWindow;
final View mView;
final WindowManager.LayoutParams mParams;
@@ -136,7 +137,7 @@ public class RelayoutPerfTest extends WindowManagerPerfTestBase
final SurfaceControl mOutSurfaceControl;
final IntSupplier mViewVisibility;
-
+ int mRelayoutSeq;
int mFlags;
RelayoutRunner(Activity activity, IWindow window, IntSupplier visibilitySupplier) {
@@ -152,10 +153,11 @@ public class RelayoutPerfTest extends WindowManagerPerfTestBase
void runBenchmark(BenchmarkState state) throws RemoteException {
final IWindowSession session = WindowManagerGlobal.getWindowSession();
while (state.keepRunning()) {
+ mRelayoutSeq++;
session.relayout(mWindow, mParams, mWidth, mHeight,
- mViewVisibility.getAsInt(), mFlags, 0 /* seq */, 0 /* lastSyncSeqId */,
+ mViewVisibility.getAsInt(), mFlags, mRelayoutSeq, 0 /* lastSyncSeqId */,
mOutFrames, mOutMergedConfiguration, mOutSurfaceControl, mOutInsetsState,
- mOutControls, new Bundle());
+ mOutControls, mOutBundle);
}
}
}
diff --git a/apct-tests/perftests/windowmanager/src/android/wm/WindowAddRemovePerfTest.java b/apct-tests/perftests/windowmanager/src/android/wm/WindowAddRemovePerfTest.java
index b87e42e31da3..72816e4ce900 100644
--- a/apct-tests/perftests/windowmanager/src/android/wm/WindowAddRemovePerfTest.java
+++ b/apct-tests/perftests/windowmanager/src/android/wm/WindowAddRemovePerfTest.java
@@ -112,7 +112,7 @@ public class WindowAddRemovePerfTest extends WindowManagerPerfTestBase
state.addExtraResult("add", elapsedTimeNsOfAdd);
startTime = SystemClock.elapsedRealtimeNanos();
- session.remove(this);
+ session.remove(asBinder());
final long elapsedTimeNsOfRemove = SystemClock.elapsedRealtimeNanos() - startTime;
state.addExtraResult("remove", elapsedTimeNsOfRemove);