summaryrefslogtreecommitdiff
path: root/apps/CtsVerifier/src/com/android/cts/verifier/features/FeatureUtil.java
blob: 1fe4768e86754526bcc359ca112b0d63b6f7afa2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.cts.verifier.features;

import android.content.Context;
import android.content.pm.PackageManager;
import android.os.UserManager;

/**
 * Feature without feature flag for now will be skipped based on the devices temporarily.
 * TODO(b/189282625): replace device feature with a more specific feature.
 */
public final class FeatureUtil {

    private FeatureUtil() {
        throw new AssertionError();
    }

    /**
     * Checks whether the device supports configing (e.g. disable, enable) location
     */
    public static boolean isConfigLocationSupported(Context context) {
        return !isWatchOrAutomotive(context);
    }

    /**
     * Checks whether the device supports configing lock screen
     */
    public static boolean isConfigLockScreenSupported(Context context) {
        return !isWatchOrAutomotive(context);
    }

    /**
     * Checks whether the device supports Easter egg / game
     */
    public static boolean isFunSupported(Context context) {
        return !isWatchOrAutomotive(context);
    }

    /**
     * Checks whether the device supports screen timeout
     */
    public static boolean isScreenTimeoutSupported(Context context) {
        return !isWatchOrAutomotive(context);
    }

    /**
     * Checks whether the device supports third party accessibility service
     */
    public static boolean isThirdPartyAccessibilityServiceSupported(Context context) {
        return !isWatchOrAutomotive(context);
    }

    /**
     * Checks whether the device supports configuring VPN
     */
    public static boolean isConfigVpnSupported(Context context) {
        return !isWatchOrAutomotive(context);
    }

    /**
     * Checks whether the device is watch or automotive
     */
    private static boolean isWatchOrAutomotive(Context context) {
        PackageManager pm = context.getPackageManager();
        return pm.hasSystemFeature(PackageManager.FEATURE_WATCH)
                || pm.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);
    }

    /**
     * Checks whether the device supports managed secondary users.
     */
    public static boolean supportManagedSecondaryUsers(Context context) {
        return (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS)
                || UserManager.isHeadlessSystemUserMode()) && UserManager.supportsMultipleUsers();
    }
}