1 /* 2 * Copyright (C) 2022 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 com.android.wm.shell.flicker.pip.tv 18 19 import android.app.Instrumentation 20 import android.content.pm.PackageManager 21 import android.view.Surface 22 import androidx.test.platform.app.InstrumentationRegistry 23 import androidx.test.uiautomator.UiDevice 24 import org.junit.Before 25 import org.junit.runners.Parameterized 26 27 abstract class PipTestBase(protected val rotationName: String, protected val rotation: Int) { 28 val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation() 29 val uiDevice = UiDevice.getInstance(instrumentation) 30 val packageManager: PackageManager = instrumentation.context.packageManager 31 protected val isTelevision: Boolean by lazy { 32 packageManager.run { 33 hasSystemFeature(PackageManager.FEATURE_LEANBACK) || 34 hasSystemFeature(PackageManager.FEATURE_LEANBACK_ONLY) 35 } 36 } 37 protected val testApp = PipAppHelperTv(instrumentation) 38 39 @Before 40 open fun televisionSetUp() { 41 /** 42 * The super implementation assumes ([org.junit.Assume]) that not running on TV, thus 43 * disabling the test on TV. This test, however, *should run on TV*, so we overriding this 44 * method and simply leaving it blank. 45 */ 46 } 47 48 companion object { 49 @Parameterized.Parameters(name = "{0}") 50 @JvmStatic 51 fun getParams(): Collection<Array<Any>> { 52 val supportedRotations = intArrayOf(Surface.ROTATION_0, Surface.ROTATION_90) 53 return supportedRotations.map { arrayOf(Surface.rotationToString(it), it) } 54 } 55 } 56 } 57