1 /* 2 * Copyright 2019 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.hardware.cts.helpers; 18 19 import android.app.UiAutomation; 20 import android.content.Context; 21 import android.os.Bundle; 22 import android.util.Log; 23 24 import androidx.test.InstrumentationRegistry; 25 import android.app.Activity; 26 import androidx.test.rule.ActivityTestRule; 27 28 import org.junit.After; 29 import org.junit.Before; 30 import org.junit.Ignore; 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 import org.junit.runners.Parameterized; 34 import org.junit.runners.Parameterized.Parameter; 35 import org.junit.runners.Parameterized.Parameters; 36 37 import java.util.ArrayList; 38 import java.util.List; 39 40 public class CameraParameterizedTestCase { 41 protected UiAutomation mUiAutomation; 42 protected Context mContext; 43 @Parameter(0) 44 public boolean mAdoptShellPerm; 45 46 private static final String CAMERA_ID_INSTR_ARG_KEY = "camera-id"; 47 private static final String CAMERA_PERF_MEASURE = "perf-measure"; 48 private static final Bundle mBundle = InstrumentationRegistry.getArguments(); 49 protected static final String mOverrideCameraId = mBundle.getString(CAMERA_ID_INSTR_ARG_KEY); 50 protected static final String mPerfMeasure = mBundle.getString(CAMERA_PERF_MEASURE); 51 isPerfMeasure()52 public boolean isPerfMeasure() { 53 return mPerfMeasure != null && mPerfMeasure.equals("on"); 54 } 55 56 @Parameters data()57 public static Iterable<? extends Object> data() { 58 List<Boolean> adoptShellPerm = new ArrayList<Boolean>(); 59 // Only add adoptShellPerm(true) of camera id is not overridden. 60 if (mPerfMeasure == null || !mPerfMeasure.equals("on")) { 61 adoptShellPerm.add(true); 62 } 63 adoptShellPerm.add(false); 64 return adoptShellPerm; 65 } 66 67 @Before setUp()68 public void setUp() throws Exception { 69 mUiAutomation = InstrumentationRegistry.getInstrumentation().getUiAutomation(); 70 mContext = InstrumentationRegistry.getTargetContext(); 71 if (mAdoptShellPerm) { 72 mUiAutomation.adoptShellPermissionIdentity(); 73 } 74 } 75 76 @After tearDown()77 public void tearDown() throws Exception { 78 if (mAdoptShellPerm) { 79 mUiAutomation.dropShellPermissionIdentity(); 80 } 81 } 82 } 83