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 com.android.cts.verifier.features;
18 
19 import android.content.Context;
20 import android.content.pm.PackageManager;
21 import android.os.UserManager;
22 
23 /**
24  * Feature without feature flag for now will be skipped based on the devices temporarily.
25  * TODO(b/189282625): replace device feature with a more specific feature.
26  */
27 public final class FeatureUtil {
28 
FeatureUtil()29     private FeatureUtil() {
30         throw new AssertionError();
31     }
32 
33     /**
34      * Checks whether the device supports configing (e.g. disable, enable) location
35      */
isConfigLocationSupported(Context context)36     public static boolean isConfigLocationSupported(Context context) {
37         return !isWatch(context);
38     }
39 
40     /**
41      * Checks whether the device supports configing lock screen
42      */
isConfigLockScreenSupported(Context context)43     public static boolean isConfigLockScreenSupported(Context context) {
44         return !isWatchOrAutomotive(context);
45     }
46 
47     /**
48      * Checks whether the device supports customizing the lock screen message
49      */
isCustomizeLockScreenMessageSupported(Context context)50     public static boolean isCustomizeLockScreenMessageSupported(Context context) {
51         return !isWatch(context);
52     }
53 
54     /**
55      * Checks whether the device supports password
56      */
isPasswordSupported(Context context)57     public static boolean isPasswordSupported(Context context) {
58         return !isWatch(context);
59     }
60 
61     /**
62      * Checks whether the device supports high password complexity
63      */
isHighPasswordComplexitySupported(Context context)64     public static boolean isHighPasswordComplexitySupported(Context context) {
65         return !isWatch(context);
66     }
67 
68     /**
69      * Checks whether the device supports Easter egg / game
70      */
isFunSupported(Context context)71     public static boolean isFunSupported(Context context) {
72         return !isWatchOrAutomotive(context);
73     }
74 
75     /**
76      * Checks whether the device supports screen timeout
77      */
isScreenTimeoutSupported(Context context)78     public static boolean isScreenTimeoutSupported(Context context) {
79         return !isWatchOrAutomotive(context);
80     }
81 
82     /**
83      * Checks whether the device supports third party accessibility service
84      */
isThirdPartyAccessibilityServiceSupported(Context context)85     public static boolean isThirdPartyAccessibilityServiceSupported(Context context) {
86         return !isWatchOrAutomotive(context);
87     }
88 
89     /**
90      * Checks whether the device supports configuring VPN
91      */
isConfigVpnSupported(Context context)92     public static boolean isConfigVpnSupported(Context context) {
93         return !isWatchOrAutomotive(context);
94     }
95     /**
96      * Checks if Disabling Keyguard is supported.
97      */
isDisableKeyguardSupported(Context context)98     public static boolean isDisableKeyguardSupported(Context context) {
99         return !isWatch(context);
100     }
101 
102     /**
103      * Checks if Lock Task is supported.
104      */
isLockTaskSupported(Context context)105     public static boolean isLockTaskSupported(Context context) {
106         return !isWatch(context) && !isTelevision(context);
107     }
108 
109     /**
110      * Checks if Status Bar is supported.
111      */
isStatusBarSupported(Context context)112     public static boolean isStatusBarSupported(Context context) {
113         return !isWatch(context) && !isTelevision(context);
114     }
115 
116     /**
117      * Checks if Data Roaming is supported.
118      */
isDataRoamingSupported(Context context)119     public static boolean isDataRoamingSupported(Context context) {
120         PackageManager pm = context.getPackageManager();
121         return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY) && !isWatch(context);
122     }
123 
124     /**
125      * Checks if Swipe To Unlock is supported.
126      */
isSwipeToUnlockSupported(Context context)127     public static boolean isSwipeToUnlockSupported(Context context) {
128         return !isAutomotive(context);
129     }
130 
131     /**
132      * Checks whether the device supports installing from unknown sources
133      */
isInstallUnknownSourcesSupported(Context context)134     public static boolean isInstallUnknownSourcesSupported(Context context) {
135         return !isWatchOrAutomotive(context);
136     }
137 
138     /**
139      * Checks whether the device requires new user disclaimer acknowledgement for managed user.
140      */
isNewManagerUserDisclaimerRequired(Context context)141     public static boolean isNewManagerUserDisclaimerRequired(Context context) {
142         return isAutomotive(context);
143     }
144 
145     /**
146      * Checks whether the device supports file transfer.
147      */
isUsbFileTransferSupported(Context context)148     public static boolean isUsbFileTransferSupported(Context context) {
149         return !isWatchOrAutomotive(context) && !isTelevision(context);
150     }
151 
152     /**
153      * Checks whether back touch is supported on the window.
154      */
isBackTouchesSupported(Context context)155     public static boolean isBackTouchesSupported(Context context) {
156         return !isWatchOrAutomotiveOrTv(context);
157     }
158 
159     /**
160      * Checks whether the device is watch .
161      */
isWatch(Context context)162     public static boolean isWatch(Context context) {
163         PackageManager pm = context.getPackageManager();
164         return pm.hasSystemFeature(PackageManager.FEATURE_WATCH);
165     }
166 
167     /**
168      * Checks whether the device is a TV
169      */
isTelevision(Context context)170     public static boolean isTelevision(Context context) {
171         PackageManager pm = context.getPackageManager();
172         return pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK);
173     }
174 
175     /**
176      * Checks whether the device is watch or automotive
177      */
isWatchOrAutomotive(Context context)178     private static boolean isWatchOrAutomotive(Context context) {
179         PackageManager pm = context.getPackageManager();
180         return pm.hasSystemFeature(PackageManager.FEATURE_WATCH)
181                 || pm.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);
182     }
183 
184     /**
185      * Checks whether the device is watch, automotive or TV
186      */
isWatchOrAutomotiveOrTv(Context context)187     public static boolean isWatchOrAutomotiveOrTv(Context context) {
188         PackageManager pm = context.getPackageManager();
189         return pm.hasSystemFeature(PackageManager.FEATURE_WATCH)
190                 || pm.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)
191                 || pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK_ONLY);
192     }
193 
194 
195     /**
196      * Checks whether the device is automotive
197      */
isAutomotive(Context context)198     public static boolean isAutomotive(Context context) {
199         PackageManager pm = context.getPackageManager();
200         return pm.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);
201     }
202 
203     /**
204      * Checks whether the device supports managed secondary users.
205      */
supportManagedSecondaryUsers(Context context)206     public static boolean supportManagedSecondaryUsers(Context context) {
207         PackageManager pm = context.getPackageManager();
208 
209         // TODO(b/283140235): Remove this check once splitscreen_multitasking device supports
210         //  FEATURE_MANAGED_USERS
211         if (pm.hasSystemFeature(PackageManager.FEATURE_CAR_SPLITSCREEN_MULTITASKING)
212                 && isAutomotive(context)) {
213             return false;
214         }
215 
216         return (pm.hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS)
217                 || UserManager.isHeadlessSystemUserMode()) && UserManager.supportsMultipleUsers();
218     }
219 
220     /**
221      * Checks whether the device shows keyguard when the user doesn't have credentials.
222      */
isKeyguardShownWhenUserDoesntHaveCredentials(Context context)223     public static boolean isKeyguardShownWhenUserDoesntHaveCredentials(Context context) {
224         return !isAutomotive(context) && !isWatch(context);
225     }
226 
227     /**
228      * Checks whether the device supports camera.
229      */
supportCameraFeature(Context context)230     public static boolean supportCameraFeature(Context context) {
231         PackageManager pm = context.getPackageManager();
232         return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);
233     }
234 }
235