1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.tools.rules 18 19 import android.tools.device.traces.monitors.TraceMonitor 20 import android.tools.device.traces.monitors.surfaceflinger.LayersTraceMonitor 21 import android.tools.device.traces.monitors.surfaceflinger.TransactionsTraceMonitor 22 import android.tools.device.traces.monitors.wm.ShellTransitionTraceMonitor 23 import android.tools.device.traces.monitors.wm.WindowManagerTraceMonitor 24 import android.tools.device.traces.monitors.wm.WmTransitionTraceMonitor 25 import android.tools.newTestResultWriter 26 import org.junit.rules.TestRule 27 import org.junit.runner.Description 28 import org.junit.runners.model.Statement 29 30 class StopAllTracesRule : TestRule { applynull31 override fun apply(base: Statement?, description: Description?): Statement { 32 return object : Statement() { 33 override fun evaluate() { 34 LayersTraceMonitor().stopIfEnabled() 35 TransactionsTraceMonitor().stopIfEnabled() 36 ShellTransitionTraceMonitor().stopIfEnabled() 37 WindowManagerTraceMonitor().stopIfEnabled() 38 WmTransitionTraceMonitor().stopIfEnabled() 39 40 base?.evaluate() 41 } 42 } 43 } 44 45 companion object { TraceMonitornull46 private fun TraceMonitor.stopIfEnabled() { 47 if (isEnabled) stop(newTestResultWriter()) 48 } 49 } 50 } 51