1 /* <lambda>null2 * Copyright (C) 2024 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.flicker 18 19 import android.tools.flicker.config.FlickerConfig 20 import android.tools.io.Reader 21 import android.tools.withTracing 22 23 /** Contains the logic for Flicker as a Service. */ 24 class FlickerServiceImpl(private val flickerConfig: FlickerConfig) : FlickerService { 25 override fun detectScenarios(reader: Reader): Collection<ScenarioInstance> { 26 validateTrace(reader) 27 28 return withTracing("FlickerService#detectScenarios") { 29 flickerConfig.getEntries().flatMap { configEntry -> 30 configEntry.extractor.extract(reader).map { traceSlice -> 31 ScenarioInstanceImpl.fromSlice(traceSlice, reader, configEntry) 32 } 33 } 34 } 35 } 36 37 private fun validateTrace(reader: Reader) { 38 val layersTrace = reader.readLayersTrace() 39 ?: error("Missing layers trace: Cannot run Flicker Service without this trace!") 40 assert(layersTrace.entries.isNotEmpty()) { 41 "Layers trace is empty! Cannot run Flicker Service on this trace! " + 42 "This is likely a bug! It shouldn't ever happen." 43 } 44 assert(layersTrace.entries.size > 1) { 45 "Layers trace must have at least only one entry. This is likely due to nothing " + 46 "happening on the device while the trace is being collected. Please double " + 47 "check that something is happening while the trace is being collected." 48 } 49 } 50 } 51