• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.pixel.tests;
18 
19 import static androidx.test.platform.app.InstrumentationRegistry.getArguments;
20 import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
21 
22 import android.app.KeyguardManager;
23 import android.support.test.uiautomator.UiDevice;
24 
25 import com.android.pixel.utils.DeviceUtils;
26 
27 import org.junit.After;
28 import org.junit.Before;
29 
30 /** Base class for Pixel app compatibility tests. */
31 public abstract class PixelAppCompatTestBase {
32     private static final String KEY_PACKAGE_NAME = "package";
33 
34     private DeviceUtils mDeviceUtils;
35     private UiDevice mDevice;
36     private KeyguardManager mKeyguardManager;
37     private String mPackage;
38 
39     @Before
setUp()40     public void setUp() throws Exception {
41         getDeviceUtils().createLogDataDir();
42         getDeviceUtils().wakeAndUnlockScreen();
43         // Start from the home screen
44         getDeviceUtils().backToHome(getUiDevice().getLauncherPackageName());
45         getDeviceUtils().startRecording(getPackage());
46     }
47 
48     @After
tearDown()49     public void tearDown() throws Exception {
50         getDeviceUtils().stopRecording();
51     }
52 
getUiDevice()53     protected UiDevice getUiDevice() {
54         if (mDevice == null) {
55             mDevice = UiDevice.getInstance(getInstrumentation());
56         }
57         return mDevice;
58     }
59 
getDeviceUtils()60     protected DeviceUtils getDeviceUtils() {
61         if (mDeviceUtils == null) {
62             mDeviceUtils = new DeviceUtils(getUiDevice());
63         }
64         return mDeviceUtils;
65     }
66 
getKeyguardManager()67     protected KeyguardManager getKeyguardManager() {
68         if (mKeyguardManager == null) {
69             mKeyguardManager =
70                     getInstrumentation().getContext().getSystemService(KeyguardManager.class);
71         }
72         return mKeyguardManager;
73     }
74 
getPackage()75     protected String getPackage() {
76         if (mPackage == null) {
77             mPackage = getArguments().getString(KEY_PACKAGE_NAME);
78         }
79         return mPackage;
80     }
81 }
82