viewcapture tracing: flag cleanup
Flag: EXEMPT flag cleanup
Bug: 323166383
Test: presubmit
Change-Id: Id1b0b2563920d306a39f246d73a6d23220749999
diff --git a/libraries/flicker/src/android/tools/flicker/Utils.kt b/libraries/flicker/src/android/tools/flicker/Utils.kt
index d625739..1c55440 100644
--- a/libraries/flicker/src/android/tools/flicker/Utils.kt
+++ b/libraries/flicker/src/android/tools/flicker/Utils.kt
@@ -25,7 +25,6 @@
import android.tools.traces.monitors.ScreenRecorder
import android.tools.traces.monitors.TraceMonitor
import android.tools.traces.monitors.events.EventLogMonitor
-import android.tools.traces.monitors.view.ViewTraceMonitor
import android.tools.traces.monitors.wm.LegacyShellTransitionTraceMonitor
import android.tools.traces.monitors.wm.LegacyWmTransitionTraceMonitor
import android.tools.traces.monitors.wm.WindowManagerTraceMonitor
@@ -51,12 +50,7 @@
.enableLayersTrace()
.enableTransactionsTrace()
.enableProtoLog()
-
- if (android.tracing.Flags.perfettoViewCaptureTracing()) {
- perfettoMonitorBuilder.enableViewCaptureTrace()
- } else {
- this.add(ViewTraceMonitor())
- }
+ .enableViewCaptureTrace()
if (android.tracing.Flags.perfettoTransitionTracing()) {
perfettoMonitorBuilder.enableTransitionsTrace()
diff --git a/libraries/flicker/test/src/android/tools/integration/FlickerServiceTracesCollectorTest.kt b/libraries/flicker/test/src/android/tools/integration/FlickerServiceTracesCollectorTest.kt
index ebaeb53..3e88943 100644
--- a/libraries/flicker/test/src/android/tools/integration/FlickerServiceTracesCollectorTest.kt
+++ b/libraries/flicker/test/src/android/tools/integration/FlickerServiceTracesCollectorTest.kt
@@ -25,8 +25,6 @@
import android.tools.testutils.CleanFlickerEnvironmentRule
import android.tools.testutils.TEST_SCENARIO
import android.tools.testutils.assertArchiveContainsFiles
-import android.tools.testutils.getLauncherPackageName
-import android.tools.testutils.getSystemUiUidName
import android.tools.traces.parsers.WindowManagerStateHelper
import androidx.test.platform.app.InstrumentationRegistry
import com.android.systemui.Flags.enableViewCaptureTracing
@@ -122,10 +120,6 @@
it.add(TraceType.LEGACY_SHELL_TRANSITION.fileName)
}
- if (!android.tracing.Flags.perfettoViewCaptureTracing()) {
- it.add("${getLauncherPackageName()}_0.vc__view_capture_trace.winscope")
- }
-
if (!android.tracing.Flags.perfettoWmTracing()) {
it.add(TraceType.WM.fileName)
}
@@ -140,11 +134,6 @@
it.add(TraceType.LEGACY_SHELL_TRANSITION.fileName)
}
- if (!android.tracing.Flags.perfettoViewCaptureTracing()) {
- it.add("${getLauncherPackageName()}_0.vc__view_capture_trace.winscope")
- it.add("${getSystemUiUidName()}_1.vc__view_capture_trace.winscope")
- }
-
if (!android.tracing.Flags.perfettoWmTracing()) {
it.add(TraceType.WM.fileName)
}
@@ -162,11 +151,6 @@
it.add(TraceType.LEGACY_SHELL_TRANSITION.fileName)
}
- if (!android.tracing.Flags.perfettoViewCaptureTracing()) {
- it.add("${getSystemUiUidName()}_0.vc__view_capture_trace.winscope")
- it.add("${getLauncherPackageName()}_1.vc__view_capture_trace.winscope")
- }
-
if (!android.tracing.Flags.perfettoWmTracing()) {
it.add(TraceType.WM.fileName)
}
diff --git a/libraries/flicker/utils/src/android/tools/rules/StopAllTracesRule.kt b/libraries/flicker/utils/src/android/tools/rules/StopAllTracesRule.kt
index fb31d59..4a6e376 100644
--- a/libraries/flicker/utils/src/android/tools/rules/StopAllTracesRule.kt
+++ b/libraries/flicker/utils/src/android/tools/rules/StopAllTracesRule.kt
@@ -20,7 +20,6 @@
import android.tools.traces.io.ResultWriter
import android.tools.traces.monitors.PerfettoTraceMonitor
import android.tools.traces.monitors.TraceMonitor
-import android.tools.traces.monitors.view.ViewTraceMonitor
import android.tools.traces.monitors.wm.LegacyShellTransitionTraceMonitor
import android.tools.traces.monitors.wm.LegacyWmTransitionTraceMonitor
import android.tools.traces.monitors.wm.WindowManagerTraceMonitor
@@ -38,7 +37,6 @@
LegacyShellTransitionTraceMonitor().stopIfEnabled()
LegacyWmTransitionTraceMonitor().stopIfEnabled()
WindowManagerTraceMonitor().stopIfEnabled()
- ViewTraceMonitor().stopIfEnabled()
base?.evaluate()
}
diff --git a/libraries/flicker/utils/src/android/tools/traces/monitors/view/ViewTraceMonitor.kt b/libraries/flicker/utils/src/android/tools/traces/monitors/view/ViewTraceMonitor.kt
deleted file mode 100644
index 0322252..0000000
--- a/libraries/flicker/utils/src/android/tools/traces/monitors/view/ViewTraceMonitor.kt
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * 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.tools.traces.monitors.view
-
-import android.tools.io.TraceType
-import android.tools.traces.executeShellCommand
-import android.tools.traces.io.ResultWriter
-import android.tools.traces.monitors.LOG_TAG
-import android.tools.traces.monitors.TraceMonitor
-import android.util.Log
-import java.io.File
-import java.util.zip.ZipFile
-
-/** Captures View traces from Launcher. */
-open class ViewTraceMonitor : TraceMonitor() {
- override val traceType = TraceType.VIEW
- override val isEnabled
- get() =
- String(executeShellCommand("su root settings get global view_capture_enabled"))
- .trim() == "1"
-
- override fun doStart() {
- doEnableDisableTrace(enable = true)
- }
-
- override fun doStop(): File {
- val outputFileZip = dumpTraces()
- doEnableDisableTrace(enable = false)
- return outputFileZip
- }
-
- override fun stop(writer: ResultWriter) {
- val viewCaptureZip = doStop()
- writer.writeTraces(viewCaptureZip)
- }
-
- private fun dumpTraces(): File {
- val outputFileZip = File.createTempFile(traceType.fileName, "")
- val stdout = executeShellCommand("su root cmd launcherapps dump-view-hierarchies")
- outputFileZip.writeBytes(stdout)
- return outputFileZip
- }
-
- private fun ResultWriter.writeTraces(viewCaptureZip: File) {
- Log.d(LOG_TAG, "Uncompressing $viewCaptureZip from zip")
- ZipFile(viewCaptureZip).use { zipFile ->
- val entries = zipFile.entries()
- while (entries.hasMoreElements()) {
- val entry = entries.nextElement()
- if (!entry.isDirectory) {
- Log.d(LOG_TAG, "Found ${entry.name}")
- val fileName = entry.name.split("/").last()
- zipFile.getInputStream(entry).use { inputStream ->
- val unzippedFile = File.createTempFile(traceType.fileName, fileName)
- unzippedFile.writeBytes(inputStream.readAllBytes())
-
- addTraceResult(traceType, unzippedFile, tag = fileName)
- }
- }
- }
- }
- }
-
- private fun doEnableDisableTrace(enable: Boolean) {
- executeShellCommand(
- "su root settings put global view_capture_enabled ${if (enable) "1" else "0"}"
- )
- }
-}
diff --git a/libraries/flicker/utils/test/src/android/tools/monitors/PerfettoTraceMonitorTest.kt b/libraries/flicker/utils/test/src/android/tools/monitors/PerfettoTraceMonitorTest.kt
index 2928e00..260f174 100644
--- a/libraries/flicker/utils/test/src/android/tools/monitors/PerfettoTraceMonitorTest.kt
+++ b/libraries/flicker/utils/test/src/android/tools/monitors/PerfettoTraceMonitorTest.kt
@@ -177,11 +177,6 @@
@Test
fun viewCaptureTracingTest() {
- assumeTrue(
- "PerfettoViewCaptureTracing flag should be enabled",
- android.tracing.Flags.perfettoViewCaptureTracing(),
- )
-
val traceMonitor = PerfettoTraceMonitor.newBuilder().enableViewCaptureTrace().build()
val reader =
traceMonitor.withTracing(resultReaderProvider = { buildResultReader(it) }) {
diff --git a/libraries/flicker/utils/test/src/android/tools/monitors/view/ViewTraceMonitorTest.kt b/libraries/flicker/utils/test/src/android/tools/monitors/view/ViewTraceMonitorTest.kt
deleted file mode 100644
index 99c5fce..0000000
--- a/libraries/flicker/utils/test/src/android/tools/monitors/view/ViewTraceMonitorTest.kt
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * 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.tools.monitors.view
-
-import android.tools.io.TraceType
-import android.tools.monitors.TraceMonitorTest
-import android.tools.testutils.assertArchiveContainsFiles
-import android.tools.testutils.getActualTraceFilesFromArchive
-import android.tools.testutils.getLauncherPackageName
-import android.tools.testutils.getSystemUiUidName
-import android.tools.testutils.newTestResultWriter
-import android.tools.traces.TRACE_CONFIG_REQUIRE_CHANGES
-import android.tools.traces.io.ResultReader
-import android.tools.traces.monitors.view.ViewTraceMonitor
-import android.tracing.Flags
-import com.android.systemui.Flags.enableViewCaptureTracing
-import com.google.common.truth.Truth
-import java.io.File
-import org.junit.Assume
-import org.junit.Before
-import org.junit.FixMethodOrder
-import org.junit.Test
-import org.junit.runners.MethodSorters
-
-/** Tests for [ViewTraceMonitor] */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-class ViewTraceMonitorTest : TraceMonitorTest<ViewTraceMonitor>() {
- override val traceType = TraceType.VIEW
-
- override fun getMonitor() = ViewTraceMonitor()
-
- override fun assertTrace(traceData: ByteArray) {
- Truth.assertThat(traceData.size).isGreaterThan(0)
- }
-
- @Before
- override fun before() {
- Assume.assumeFalse(Flags.perfettoViewCaptureTracing())
- super.before()
- }
-
- @Test
- @Throws(Exception::class)
- override fun captureTrace() {
- var possibleExpectedTraces = listOf(EXPECTED_TRACES_LAUNCHER_ONLY)
- if (enableViewCaptureTracing()) {
- possibleExpectedTraces =
- listOf(EXPECTED_TRACES_LAUNCHER_FIRST, EXPECTED_TRACES_SYSUI_FIRST)
- }
-
- traceMonitor.start()
- device.pressHome()
- device.pressRecentApps()
- val writer = newTestResultWriter()
- traceMonitor.stop(writer)
- val result = writer.write()
- val reader = ResultReader(result, TRACE_CONFIG_REQUIRE_CHANGES)
-
- val traceArtifactPath = reader.artifactPath
- require(traceArtifactPath.isNotEmpty()) { "Artifact path missing in result" }
- val traceArchive = File(traceArtifactPath)
-
- assertArchiveContainsFiles(traceArchive, possibleExpectedTraces)
- val actualTraceFiles = getActualTraceFilesFromArchive(traceArchive)
- val tagList = getTagListFromTraces(actualTraceFiles)
- for (tag: String in tagList) {
- val trace =
- reader.readBytes(traceMonitor.traceType, tag)
- ?: error("Missing trace file ${traceMonitor.traceType}")
- Truth.assertWithMessage("Trace file size").that(trace.size).isGreaterThan(0)
- assertTrace(trace)
- }
- }
-
- // We override this test to create a placeholder since the [withTracing] method does not align
- // with the implementation of multiple instances of ViewCapture.
- @Test
- @Throws(Exception::class)
- override fun withTracing() {
- Truth.assertThat(true).isTrue()
- }
-
- private fun getTagListFromTraces(actualTraceFiles: List<String>): List<String> {
- var tagList: List<String> = emptyList()
- for (traceFile: String in actualTraceFiles) {
- tagList += traceFile.removeSuffix("__view_capture_trace.winscope")
- }
- return tagList
- }
-
- companion object {
- val EXPECTED_TRACES_LAUNCHER_ONLY =
- listOf("${getLauncherPackageName()}_0.vc__view_capture_trace.winscope")
- val EXPECTED_TRACES_LAUNCHER_FIRST =
- listOf(
- "${getLauncherPackageName()}_0.vc__view_capture_trace.winscope",
- "${getSystemUiUidName()}_1.vc__view_capture_trace.winscope",
- )
-
- val EXPECTED_TRACES_SYSUI_FIRST =
- listOf(
- "${getSystemUiUidName()}_0.vc__view_capture_trace.winscope",
- "${getLauncherPackageName()}_1.vc__view_capture_trace.winscope",
- )
- }
-}