• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.photopicker.cts;
18 
19 import android.app.Instrumentation;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.content.pm.PackageManager;
23 
24 import androidx.test.InstrumentationRegistry;
25 import androidx.test.uiautomator.UiDevice;
26 
27 
28 import org.junit.Assume;
29 import org.junit.Before;
30 
31 /**
32  * Photo Picker Base class for Photo Picker tests. This includes common setup methods
33  * required for all Photo Picker tests.
34  */
35 public class PhotoPickerBaseTest {
36     public static int REQUEST_CODE = 42;
37     private static final Instrumentation sInstrumentation =
38             InstrumentationRegistry.getInstrumentation();
39     protected static final String sTargetPackageName =
40             sInstrumentation.getTargetContext().getPackageName();
41     protected static final UiDevice sDevice = UiDevice.getInstance(sInstrumentation);
42 
43     protected GetResultActivity mActivity;
44     protected Context mContext;
45 
46     @Before
setUp()47     public void setUp() throws Exception {
48         Assume.assumeTrue(isHardwareSupported());
49 
50         final String setSyncDelayCommand =
51                 "device_config put storage pickerdb.default_sync_delay_ms 0";
52         sDevice.executeShellCommand(setSyncDelayCommand);
53 
54         mContext = sInstrumentation.getContext();
55         final Intent intent = new Intent(mContext, GetResultActivity.class);
56         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
57 
58         // Wake up the device and dismiss the keyguard before the test starts
59         sDevice.executeShellCommand("input keyevent KEYCODE_WAKEUP");
60         sDevice.executeShellCommand("wm dismiss-keyguard");
61 
62         mActivity = (GetResultActivity) sInstrumentation.startActivitySync(intent);
63         // Wait for the UI Thread to become idle.
64         sInstrumentation.waitForIdleSync();
65         mActivity.clearResult();
66         sDevice.waitForIdle();
67     }
68 
isHardwareSupported()69     static boolean isHardwareSupported() {
70         // These UI tests are not optimised for Watches, TVs, Auto;
71         // IoT devices do not have a UI to run these UI tests
72         PackageManager pm = sInstrumentation.getContext().getPackageManager();
73         return !pm.hasSystemFeature(pm.FEATURE_EMBEDDED)
74                 && !pm.hasSystemFeature(pm.FEATURE_WATCH)
75                 && !pm.hasSystemFeature(pm.FEATURE_LEANBACK)
76                 && !pm.hasSystemFeature(pm.FEATURE_AUTOMOTIVE);
77     }
78 }
79