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.device.flicker.legacy.runner 18 19 import android.app.Instrumentation 20 import android.os.Bundle 21 import android.tools.common.Logger 22 import android.tools.common.Scenario 23 import android.tools.common.traces.ConditionList 24 import android.tools.common.traces.ConditionsFactory 25 import android.tools.device.traces.parsers.WindowManagerStateHelper 26 import androidx.test.platform.app.InstrumentationRegistry 27 import org.junit.runner.Description 28 29 /** Helper class for flicker transition rules */ 30 object Utils { 31 /** 32 * Conditions that determine when the UI is in a stable and no windows or layers are animating 33 * or changing state. 34 */ 35 private val UI_STABLE_CONDITIONS = 36 ConditionList( 37 listOf( 38 ConditionsFactory.isWMStateComplete(), 39 ConditionsFactory.hasLayersAnimating().negate() 40 ) 41 ) 42 private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation() 43 doWaitForUiStabilizenull44 internal fun doWaitForUiStabilize(wmHelper: WindowManagerStateHelper) { 45 wmHelper.StateSyncBuilder().add(UI_STABLE_CONDITIONS).waitFor() 46 } 47 notifyRunnerProgressnull48 internal fun notifyRunnerProgress(scenario: Scenario, msg: String) { 49 Logger.d(FLICKER_RUNNER_TAG, "${scenario.key} - $msg") 50 val results = Bundle() 51 results.putString(Instrumentation.REPORT_KEY_STREAMRESULT, "$msg\n") 52 instrumentation.sendStatus(1, results) 53 } 54 expandDescriptionnull55 internal fun expandDescription(description: Description?, suffix: String): Description? = 56 Description.createTestDescription( 57 description?.className, 58 "${description?.displayName}-$suffix", 59 description?.annotations?.toTypedArray() 60 ) 61 } 62