Home | History | Annotate | Download | only in cts
      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.RequiredFeatureRule;
     28 import com.android.compatibility.common.util.SettingsStateChangerRule;
     29 
     30 import org.junit.Before;
     31 import org.junit.Rule;
     32 import org.junit.runner.RunWith;
     33 
     34 import androidx.test.ext.junit.runners.AndroidJUnit4;
     35 
     36 /**
     37  * Base class for all test cases
     38  */
     39 @RunWith(AndroidJUnit4.class)
     40 abstract class AbstractVoiceInteractionTestCase {
     41 
     42     // TODO: use PackageManager's / make it @TestApi
     43     protected static final String FEATURE_VOICE_RECOGNIZERS = "android.software.voice_recognizers";
     44 
     45     protected final Context mContext = getInstrumentation().getTargetContext();
     46 
     47     @Rule
     48     public final RequiredFeatureRule mRequiredFeatureRule = new RequiredFeatureRule(
     49             FEATURE_VOICE_RECOGNIZERS);
     50 
     51     @Rule
     52     public final SettingsStateChangerRule mServiceSetterRule = new SettingsStateChangerRule(
     53             mContext, Settings.Secure.VOICE_INTERACTION_SERVICE, Utils.SERVICE_NAME);
     54 
     55     @Before
     56     public void prepareDevice() throws Exception {
     57         // Unlock screen.
     58         runShellCommand("input keyevent KEYCODE_WAKEUP");
     59 
     60         // Dismiss keyguard, in case it's set as "Swipe to unlock".
     61         runShellCommand("wm dismiss-keyguard");
     62     }
     63 }
     64