summaryrefslogtreecommitdiff
path: root/libs/WifiTrackerLib/sdk_src/src/com/android/wifitrackerlib/NonSdkApiWrapper.java
blob: 8233fb032e5cbfb0aa8cbdc50dcfb20264d03e5d (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
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * 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.wifitrackerlib;

import android.app.admin.DevicePolicyManager;
import android.app.admin.WifiSsidPolicy;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.wifi.WifiInfo;
import android.os.Handler;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
 * Wrapper class to decouple WifiTrackerLibDefaults from non-SDK API usage at build time, for use
 * by apps that build against the SDK (e.g. SetupWizard).
 *
 * Clients may wish to provide their own implementation of these methods when copying this
 * library over to their own codebase.
 */
class NonSdkApiWrapper {
    /**
     * Starts the System captive portal app.
     */
    static void startCaptivePortalApp(
            @NonNull ConnectivityManager connectivityManager, @NonNull Network network) {
        return;
    }

    /**
     * Find the annotation of specified id in rawText and linkify it with helpUriString.
     */
    static CharSequence linkifyAnnotation(Context context, CharSequence rawText, String id,
            String helpUriString) {
        // TODO(b/162368129): Should SUW be concerned with annotation linking?
        return rawText;
    }

    /**
     * Returns whether or not the network capabilities is determined to be VCN over Wi-Fi or not.
     */
    static boolean isVcnOverWifi(@NonNull NetworkCapabilities networkCapabilities) {
        // This is only useful for treating CELLULAR over WIFI as a carrier merged network in
        // provider model Settings. Since SUW doesn't use the provider model, this is not used.
        return false;
    }

    /**
     * Returns whether or not the device is in retail demo mode.
     */
    static boolean isDemoMode(@NonNull Context context) {
        // This should be false since SUW is not used in demo mode.
        return false;
    }

    /**
     * Registers the system default network callback.
     */
    static void registerSystemDefaultNetworkCallback(
            @NonNull ConnectivityManager connectivityManager,
            @NonNull ConnectivityManager.NetworkCallback callback,
            @NonNull Handler handler) {
        // registerSystemDefaultNetworkCallback does not have visibility to non-updatable modules,
        // so we have to use the regular registerDefaultNetworkCallback here.
        // TODO(b/230643853): See if we can add registerSystemDefaultNetworkCallback to the SDK.
        connectivityManager.registerDefaultNetworkCallback(callback, handler);
    }

    /**
     * Returns true if the WifiInfo is for the primary network, false otherwise.
     */
    static boolean isPrimary(@NonNull WifiInfo wifiInfo) {
        // TODO(b/230643853): WifiInfo.isPrimary() currently requires NETWORK_SETTINGS permission to
        //                    access, which SUW does not hold. Always return true (WifiTracker1
        //                    behavior) until SUW can access this field.
        return true;
    }

    /**
     * Returns the {@link WifiSsidPolicy} of the device.
     */
    @Nullable
    static WifiSsidPolicy getWifiSsidPolicy(@NonNull DevicePolicyManager devicePolicyManager) {
        // Return null since SUW does not have QUERY_ADMIN_POLICY permission.
        return null;
    }
}