summaryrefslogtreecommitdiffstats
path: root/service/java/com/android/server/wifi/CarrierNetworkNotifier.java
blob: 5af4001810e66083b5e8514f62924f8f57cceef0 (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
/*
 * Copyright (C) 2018 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.server.wifi;

import android.content.Context;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiConfiguration.KeyMgmt;
import android.net.wifi.WifiEnterpriseConfig;
import android.net.wifi.WifiEnterpriseConfig.Eap;
import android.os.Looper;
import android.provider.Settings;

import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
import com.android.server.wifi.nano.WifiMetricsProto;

/**
 * This class handles the "carrier wi-fi network available" notification
 *
 * NOTE: These API's are not thread safe and should only be used from ClientModeImpl thread.
 */
public class CarrierNetworkNotifier extends AvailableNetworkNotifier {
    public static final String TAG = "WifiCarrierNetworkNotifier";
    private static final String STORE_DATA_IDENTIFIER = "CarrierNetworkNotifierBlacklist";
    private static final String TOGGLE_SETTINGS_NAME =
            Settings.Global.WIFI_CARRIER_NETWORKS_AVAILABLE_NOTIFICATION_ON;

    public CarrierNetworkNotifier(
            Context context,
            Looper looper,
            FrameworkFacade framework,
            Clock clock,
            WifiMetrics wifiMetrics,
            WifiConfigManager wifiConfigManager,
            WifiConfigStore wifiConfigStore,
            ClientModeImpl clientModeImpl,
            ConnectToNetworkNotificationBuilder connectToNetworkNotificationBuilder) {
        super(TAG, STORE_DATA_IDENTIFIER, TOGGLE_SETTINGS_NAME,
                SystemMessage.NOTE_CARRIER_NETWORK_AVAILABLE,
                WifiMetricsProto.ConnectionEvent.NOMINATOR_CARRIER,
                context, looper, framework, clock,
                wifiMetrics, wifiConfigManager, wifiConfigStore, clientModeImpl,
                connectToNetworkNotificationBuilder);
    }

    @Override
    WifiConfiguration createRecommendedNetworkConfig(ScanResult recommendedNetwork) {
        WifiConfiguration network = super.createRecommendedNetworkConfig(recommendedNetwork);

        int eapMethod = recommendedNetwork.carrierApEapType;
        if (eapMethod == Eap.SIM || eapMethod == Eap.AKA || eapMethod == Eap.AKA_PRIME) {
            network.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
            network.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
            network.enterpriseConfig = new WifiEnterpriseConfig();
            network.enterpriseConfig.setEapMethod(recommendedNetwork.carrierApEapType);
            network.enterpriseConfig.setIdentity("");
            network.enterpriseConfig.setAnonymousIdentity("");
        }

        return network;
    }
}