1 /* 2 * Copyright (C) 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.voiceinteraction.cts; 18 19 import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; 20 21 import static com.android.compatibility.common.util.ShellUtils.runShellCommand; 22 23 import android.content.Context; 24 import android.provider.Settings; 25 import android.voiceinteraction.common.Utils; 26 27 import com.android.compatibility.common.util.SettingsStateChangerRule; 28 29 import org.junit.Before; 30 import org.junit.Rule; 31 import org.junit.runner.RunWith; 32 33 import androidx.test.ext.junit.runners.AndroidJUnit4; 34 35 /** 36 * Base class for all test cases 37 */ 38 @RunWith(AndroidJUnit4.class) 39 abstract class AbstractVoiceInteractionTestCase { 40 41 protected final Context mContext = getInstrumentation().getTargetContext(); 42 43 @Rule 44 public final SettingsStateChangerRule mServiceSetterRule = new SettingsStateChangerRule( 45 mContext, Settings.Secure.VOICE_INTERACTION_SERVICE, Utils.SERVICE_NAME); 46 47 @Before prepareDevice()48 public void prepareDevice() throws Exception { 49 // Unlock screen. 50 runShellCommand("input keyevent KEYCODE_WAKEUP"); 51 52 // Dismiss keyguard, in case it's set as "Swipe to unlock". 53 runShellCommand("wm dismiss-keyguard"); 54 } 55 } 56