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 Easter egg / game 49 */ isFunSupported(Context context)50 public static boolean isFunSupported(Context context) { 51 return !isWatchOrAutomotive(context); 52 } 53 54 /** 55 * Checks whether the device supports screen timeout 56 */ isScreenTimeoutSupported(Context context)57 public static boolean isScreenTimeoutSupported(Context context) { 58 return !isWatchOrAutomotive(context); 59 } 60 61 /** 62 * Checks whether the device supports third party accessibility service 63 */ isThirdPartyAccessibilityServiceSupported(Context context)64 public static boolean isThirdPartyAccessibilityServiceSupported(Context context) { 65 return !isWatchOrAutomotive(context); 66 } 67 68 /** 69 * Checks whether the device supports configuring VPN 70 */ isConfigVpnSupported(Context context)71 public static boolean isConfigVpnSupported(Context context) { 72 return !isWatchOrAutomotive(context); 73 } 74 75 /** 76 * Checks whether the device supports installing from unknown sources 77 */ isInstallUnknownSourcesSupported(Context context)78 public static boolean isInstallUnknownSourcesSupported(Context context) { 79 return !isWatchOrAutomotive(context); 80 } 81 82 /** 83 * Checks whether the device requires new user disclaimer acknowledgement for managed user. 84 */ isNewManagerUserDisclaimerRequired(Context context)85 public static boolean isNewManagerUserDisclaimerRequired(Context context) { 86 return isAutomotive(context); 87 } 88 89 /** 90 * Checks whether the device supports file transfer. 91 */ isUsbFileTransferSupported(Context context)92 public static boolean isUsbFileTransferSupported(Context context) { 93 return !isWatchOrAutomotive(context); 94 } 95 96 /** 97 * Checks whether the device is watch . 98 */ isWatch(Context context)99 public static boolean isWatch(Context context) { 100 PackageManager pm = context.getPackageManager(); 101 return pm.hasSystemFeature(PackageManager.FEATURE_WATCH); 102 } 103 104 /** 105 * Checks whether the device is watch or automotive 106 */ isWatchOrAutomotive(Context context)107 public static boolean isWatchOrAutomotive(Context context) { 108 PackageManager pm = context.getPackageManager(); 109 return pm.hasSystemFeature(PackageManager.FEATURE_WATCH) 110 || pm.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE); 111 } 112 113 /** 114 * Checks whether the device is automotive 115 */ isAutomotive(Context context)116 public static boolean isAutomotive(Context context) { 117 PackageManager pm = context.getPackageManager(); 118 return pm.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE); 119 } 120 121 /** 122 * Checks whether the device supports managed secondary users. 123 */ supportManagedSecondaryUsers(Context context)124 public static boolean supportManagedSecondaryUsers(Context context) { 125 return (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS) 126 || UserManager.isHeadlessSystemUserMode()) && UserManager.supportsMultipleUsers(); 127 } 128 129 /** 130 * Checks whether the device shows keyguard when the user doesn't have credentials. 131 */ isKeyguardShownWhenUserDoesntHaveCredentials(Context context)132 public static boolean isKeyguardShownWhenUserDoesntHaveCredentials(Context context) { 133 return !isAutomotive(context) && !isWatch(context); 134 } 135 } 136