1 /*
2  * Copyright (C) 2020 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.server.wifi;
18 
19 import android.annotation.Nullable;
20 import android.net.wifi.WifiConfiguration;
21 import android.net.wifi.WifiContext;
22 import android.net.wifi.WifiManager;
23 import android.net.wifi.util.WifiResourceCache;
24 import android.util.ArraySet;
25 import android.util.Log;
26 import android.util.SparseArray;
27 
28 import com.android.internal.annotations.VisibleForTesting;
29 import com.android.modules.utils.build.SdkLevel;
30 import com.android.server.wifi.WifiBlocklistMonitor.CarrierSpecificEapFailureConfig;
31 import com.android.wifi.resources.R;
32 
33 import java.io.FileDescriptor;
34 import java.io.PrintWriter;
35 import java.util.Arrays;
36 import java.util.HashMap;
37 import java.util.List;
38 import java.util.Map;
39 import java.util.Set;
40 import java.util.concurrent.atomic.AtomicBoolean;
41 import java.util.concurrent.atomic.AtomicInteger;
42 
43 import javax.annotation.concurrent.ThreadSafe;
44 
45 
46 /** Global wifi service in-memory state that is not persisted. */
47 @ThreadSafe
48 public class WifiGlobals {
49 
50     private static final String TAG = "WifiGlobals";
51     private final WifiContext mContext;
52     private final WifiResourceCache mWifiResourceCache;
53 
54     private final AtomicInteger mPollRssiIntervalMillis = new AtomicInteger(-1);
55     private final AtomicBoolean mIpReachabilityDisconnectEnabled = new AtomicBoolean(true);
56     private final AtomicBoolean mIsBluetoothConnected = new AtomicBoolean(false);
57     // Set default to false to check if the value will be overridden by WifiSettingConfigStore.
58     private final AtomicBoolean mIsWepAllowed = new AtomicBoolean(false);
59     private final AtomicBoolean mIsD2dStaConcurrencySupported = new AtomicBoolean(false);
60     private final AtomicInteger mSendDhcpHostnameRestriction = new AtomicInteger();
61 
62     // These are read from the overlay, cache them after boot up.
63     private final boolean mIsWpa3SaeUpgradeEnabled;
64     private boolean mIsWpa3SaeUpgradeOffloadEnabled;
65     private final boolean mIsOweUpgradeEnabled;
66     private final boolean mFlushAnqpCacheOnWifiToggleOffEvent;
67     private final boolean mIsWpa3SaeH2eSupported;
68     private final String mP2pDeviceNamePrefix;
69     private final int mP2pDeviceNamePostfixNumDigits;
70     private final int mClientModeImplNumLogRecs;
71     private final boolean mSaveFactoryMacToConfigStoreEnabled;
72     private final int mWifiLowConnectedScoreThresholdToTriggerScanForMbb;
73     private final int mWifiLowConnectedScoreScanPeriodSeconds;
74     private final boolean mWifiAllowInsecureEnterpriseConfiguration;
75     private final boolean mIsP2pMacRandomizationSupported;
76     private final int mPollRssiShortIntervalMillis;
77     private final int mPollRssiLongIntervalMillis;
78     private final int mClientRssiMonitorThresholdDbm;
79     private final int mClientRssiMonitorHysteresisDb;
80     private boolean mDisableFirmwareRoamingInIdleMode = false;
81     private final boolean mIsSupportMultiInternetDual5G;
82     private final int mRepeatedNudFailuresThreshold;
83     private final int mRepeatedNudFailuresWindowMs;
84     private final boolean mAdjustPollRssiIntervalEnabled;
85     private final boolean mWifiInterfaceAddedSelfRecoveryEnabled;
86     private final int mNetworkNotFoundEventThreshold;
87     private boolean mIsSwPnoEnabled;
88     private boolean mWepAllowedControlSupported;
89     private final boolean mIsWpaPersonalDeprecated;
90     private final Map<String, List<String>> mCountryCodeToAfcServers;
91     private final long mWifiConfigMaxDisableDurationMs;
92     // This is set by WifiManager#setVerboseLoggingEnabled(int).
93     private int mVerboseLoggingLevel = WifiManager.VERBOSE_LOGGING_LEVEL_DISABLED;
94     private boolean mIsUsingExternalScorer = false;
95     private boolean mDisableUnwantedNetworkOnLowRssi = false;
96     private final boolean mIsAfcSupportedOnDevice;
97     private boolean mDisableNudDisconnectsForWapiInSpecificCc = false;
98     private boolean mD2dAllowedControlSupportedWhenInfraStaDisabled = false;
99     private Set<String> mMacRandomizationUnsupportedSsidPrefixes = new ArraySet<>();
100 
101     private SparseArray<SparseArray<CarrierSpecificEapFailureConfig>>
102             mCarrierSpecificEapFailureConfigMapPerCarrierId = new SparseArray<>();
103 
104 
WifiGlobals(WifiContext context)105     public WifiGlobals(WifiContext context) {
106         mContext = context;
107         mWifiResourceCache = context.getResourceCache();
108         mIsWpa3SaeUpgradeEnabled = mContext.getResources()
109                 .getBoolean(R.bool.config_wifiSaeUpgradeEnabled);
110         mIsWpa3SaeUpgradeOffloadEnabled = mContext.getResources()
111                 .getBoolean(R.bool.config_wifiSaeUpgradeOffloadEnabled);
112         mIsOweUpgradeEnabled = mContext.getResources()
113                 .getBoolean(R.bool.config_wifiOweUpgradeEnabled);
114         mFlushAnqpCacheOnWifiToggleOffEvent = mContext.getResources()
115                 .getBoolean(R.bool.config_wifiFlushAnqpCacheOnWifiToggleOffEvent);
116         mIsWpa3SaeH2eSupported = mContext.getResources()
117                 .getBoolean(R.bool.config_wifiSaeH2eSupported);
118         mP2pDeviceNamePrefix = mContext.getResources()
119                 .getString(R.string.config_wifiP2pDeviceNamePrefix);
120         mP2pDeviceNamePostfixNumDigits = mContext.getResources()
121                 .getInteger(R.integer.config_wifiP2pDeviceNamePostfixNumDigits);
122         mClientModeImplNumLogRecs = mContext.getResources()
123                 .getInteger(R.integer.config_wifiClientModeImplNumLogRecs);
124         mSaveFactoryMacToConfigStoreEnabled = mContext.getResources()
125                 .getBoolean(R.bool.config_wifiSaveFactoryMacToWifiConfigStore);
126         mWifiLowConnectedScoreThresholdToTriggerScanForMbb = mContext.getResources().getInteger(
127                 R.integer.config_wifiLowConnectedScoreThresholdToTriggerScanForMbb);
128         mWifiLowConnectedScoreScanPeriodSeconds = mContext.getResources().getInteger(
129                 R.integer.config_wifiLowConnectedScoreScanPeriodSeconds);
130         mWifiAllowInsecureEnterpriseConfiguration = mContext.getResources().getBoolean(
131                 R.bool.config_wifiAllowInsecureEnterpriseConfigurationsForSettingsAndSUW);
132         mIsP2pMacRandomizationSupported = mContext.getResources().getBoolean(
133                 R.bool.config_wifi_p2p_mac_randomization_supported);
134         mPollRssiIntervalMillis.set(mContext.getResources().getInteger(
135                 R.integer.config_wifiPollRssiIntervalMilliseconds));
136         mPollRssiShortIntervalMillis = mContext.getResources().getInteger(
137                 R.integer.config_wifiPollRssiIntervalMilliseconds);
138         mPollRssiLongIntervalMillis = mContext.getResources().getInteger(
139                 R.integer.config_wifiPollRssiLongIntervalMilliseconds);
140         mClientRssiMonitorThresholdDbm = mContext.getResources().getInteger(
141                 R.integer.config_wifiClientRssiMonitorThresholdDbm);
142         mClientRssiMonitorHysteresisDb = mContext.getResources().getInteger(
143                 R.integer.config_wifiClientRssiMonitorHysteresisDb);
144         mAdjustPollRssiIntervalEnabled = mContext.getResources().getBoolean(
145                 R.bool.config_wifiAdjustPollRssiIntervalEnabled);
146         mDisableFirmwareRoamingInIdleMode = mContext.getResources()
147                 .getBoolean(R.bool.config_wifiDisableFirmwareRoamingInIdleMode);
148         mIsSupportMultiInternetDual5G = mContext.getResources().getBoolean(
149                 R.bool.config_wifiAllowMultiInternetConnectDual5GFrequency);
150         mRepeatedNudFailuresThreshold = mContext.getResources()
151                 .getInteger(R.integer.config_wifiDisableReasonRepeatedNudFailuresThreshold);
152         mRepeatedNudFailuresWindowMs = mContext.getResources()
153                 .getInteger(R.integer.config_wifiDisableReasonRepeatedNudFailuresWindowMs);
154         mWifiInterfaceAddedSelfRecoveryEnabled = mContext.getResources().getBoolean(
155                 R.bool.config_wifiInterfaceAddedSelfRecoveryEnabled);
156         mDisableUnwantedNetworkOnLowRssi = mContext.getResources().getBoolean(
157                 R.bool.config_wifiDisableUnwantedNetworkOnLowRssi);
158         mDisableNudDisconnectsForWapiInSpecificCc = mContext.getResources().getBoolean(
159                 R.bool.config_wifiDisableNudDisconnectsForWapiInSpecificCc);
160         mNetworkNotFoundEventThreshold = mContext.getResources().getInteger(
161                 R.integer.config_wifiNetworkNotFoundEventThreshold);
162         mIsSwPnoEnabled = mContext.getResources()
163                 .getBoolean(R.bool.config_wifiSwPnoEnabled);
164         mWepAllowedControlSupported = mContext.getResources()
165                 .getBoolean(R.bool.config_wifiWepAllowedControlSupported);
166         mIsWpaPersonalDeprecated = mContext.getResources()
167                 .getBoolean(R.bool.config_wifiWpaPersonalDeprecated);
168         mIsAfcSupportedOnDevice = mContext.getResources().getBoolean(R.bool.config_wifiAfcSupported)
169                 && mContext.getResources().getBoolean(R.bool.config_wifiSoftap6ghzSupported)
170                 && mContext.getResources().getBoolean(R.bool.config_wifi6ghzSupport);
171         mWifiConfigMaxDisableDurationMs = mContext.getResources()
172                 .getInteger(R.integer.config_wifiDisableTemporaryMaximumDurationMs);
173         mD2dAllowedControlSupportedWhenInfraStaDisabled = mContext.getResources()
174                 .getBoolean(R.bool.config_wifiD2dAllowedControlSupportedWhenInfraStaDisabled);
175         Set<String> unsupportedSsidPrefixes = new ArraySet<>(mContext.getResources().getStringArray(
176                 R.array.config_wifiForceDisableMacRandomizationSsidPrefixList));
177         mCountryCodeToAfcServers = getCountryCodeToAfcServersMap();
178         if (!unsupportedSsidPrefixes.isEmpty()) {
179             for (String ssid : unsupportedSsidPrefixes) {
180                 String cleanedSsid = ssid.length() > 1 && (ssid.charAt(0) == '"')
181                         && (ssid.charAt(ssid.length() - 1) == '"')
182                         ? ssid.substring(0, ssid.length() - 1) : ssid;
183                 mMacRandomizationUnsupportedSsidPrefixes.add(cleanedSsid);
184             }
185         }
186         loadCarrierSpecificEapFailureConfigMap();
187     }
188 
189     /**
190      * Gets the CarrierSpecificEapFailureConfig applicable for the carrierId and eapFailureReason.
191      * @param carrierId the carrier ID
192      * @param eapFailureReason EAP failure reason
193      * @return The applicable CarrierSpecificEapFailureConfig, or null if there's no data for this
194      * particular combination of carrierId and eapFailureReason.
195      */
getCarrierSpecificEapFailureConfig( int carrierId, int eapFailureReason)196     public @Nullable CarrierSpecificEapFailureConfig getCarrierSpecificEapFailureConfig(
197             int carrierId, int eapFailureReason) {
198         if (!mCarrierSpecificEapFailureConfigMapPerCarrierId.contains(carrierId)) {
199             return null;
200         }
201         return mCarrierSpecificEapFailureConfigMapPerCarrierId.get(carrierId).get(eapFailureReason);
202     }
203 
204     /**
205      * Utility method for unit testing.
206      */
getCarrierSpecificEapFailureConfigMapSize()207     public @VisibleForTesting int getCarrierSpecificEapFailureConfigMapSize() {
208         return mCarrierSpecificEapFailureConfigMapPerCarrierId.size();
209     }
210 
loadCarrierSpecificEapFailureConfigMap()211     private void loadCarrierSpecificEapFailureConfigMap() {
212         String[] eapFailureOverrides = mContext.getResources().getStringArray(
213                 R.array.config_wifiEapFailureConfig);
214         if (eapFailureOverrides == null) {
215             return;
216         }
217         for (String line : eapFailureOverrides) {
218             if (line == null) {
219                 continue;
220             }
221             String[] items = line.split(",");
222             if (items.length != 5) {
223                 // error case. Should have exactly 5 items.
224                 Log.e(TAG, "Failed to parse eapFailureOverrides line=" + line);
225                 continue;
226             }
227             try {
228                 int carrierId = Integer.parseInt(items[0].trim());
229                 int eapFailureCode = Integer.parseInt(items[1].trim());
230                 int displayDialogue = Integer.parseInt(items[2].trim());
231                 int disableThreshold = Integer.parseInt(items[3].trim());
232                 int disableDurationMinutes = Integer.parseInt(items[4].trim());
233                 if (!mCarrierSpecificEapFailureConfigMapPerCarrierId.contains(carrierId)) {
234                     mCarrierSpecificEapFailureConfigMapPerCarrierId.put(carrierId,
235                             new SparseArray<>());
236                 }
237                 SparseArray<CarrierSpecificEapFailureConfig> perEapFailureMap =
238                         mCarrierSpecificEapFailureConfigMapPerCarrierId.get(carrierId);
239                 perEapFailureMap.put(eapFailureCode, new CarrierSpecificEapFailureConfig(
240                         disableThreshold, disableDurationMinutes * 60 * 1000, displayDialogue > 0));
241             } catch (Exception e) {
242                 // failure to parse. Something is wrong with the config.
243                 Log.e(TAG, "Parsing eapFailureOverrides line=" + line
244                         + ". Exception occurred:" + e);
245             }
246         }
247     }
248 
getCountryCodeToAfcServersMap()249     private Map<String, List<String>> getCountryCodeToAfcServersMap() {
250         Map<String, List<String>> countryCodeToAfcServers = new HashMap<>();
251         String[] countryCodeToAfcServersFromConfig = mContext.getResources().getStringArray(
252                 R.array.config_wifiAfcServerUrlsForCountry);
253 
254         if (countryCodeToAfcServersFromConfig == null) {
255             return countryCodeToAfcServers;
256         }
257 
258         // each entry should be of the form: countryCode,url1,url2...
259         for (String entry : countryCodeToAfcServersFromConfig) {
260             String[] countryAndUrls = entry.split(",");
261 
262             // if no servers are specified for a country, then continue to the next entry
263             if (countryAndUrls.length < 2) {
264                 continue;
265             }
266             countryCodeToAfcServers.put(countryAndUrls[0], Arrays.asList(Arrays.copyOfRange(
267                     countryAndUrls, 1, countryAndUrls.length)));
268         }
269         return countryCodeToAfcServers;
270     }
271 
getMacRandomizationUnsupportedSsidPrefixes()272     public Set<String> getMacRandomizationUnsupportedSsidPrefixes() {
273         return mMacRandomizationUnsupportedSsidPrefixes;
274     }
275 
276     /** Get the interval between RSSI polls, in milliseconds. */
getPollRssiIntervalMillis()277     public int getPollRssiIntervalMillis() {
278         return mPollRssiIntervalMillis.get();
279     }
280 
281     /** Set the interval between RSSI polls, in milliseconds. */
setPollRssiIntervalMillis(int newPollIntervalMillis)282     public void setPollRssiIntervalMillis(int newPollIntervalMillis) {
283         mPollRssiIntervalMillis.set(newPollIntervalMillis);
284     }
285 
286     /** Returns whether CMD_IP_REACHABILITY_LOST events should trigger disconnects. */
getIpReachabilityDisconnectEnabled()287     public boolean getIpReachabilityDisconnectEnabled() {
288         return mIpReachabilityDisconnectEnabled.get();
289     }
290 
291     /**
292      * Returns a list of AFC server URLs for a country, or null if AFC is not available in that
293      * country.
294      */
getAfcServerUrlsForCountry(String countryCode)295     public @Nullable List<String> getAfcServerUrlsForCountry(String countryCode) {
296         return mCountryCodeToAfcServers.get(countryCode);
297     }
298 
299     /**
300      * Returns whether this device supports AFC.
301      */
isAfcSupportedOnDevice()302     public boolean isAfcSupportedOnDevice() {
303         return mIsAfcSupportedOnDevice;
304     }
305 
306     /** Sets whether CMD_IP_REACHABILITY_LOST events should trigger disconnects. */
setIpReachabilityDisconnectEnabled(boolean enabled)307     public void setIpReachabilityDisconnectEnabled(boolean enabled) {
308         mIpReachabilityDisconnectEnabled.set(enabled);
309     }
310 
311     /** Set whether bluetooth is enabled. */
setBluetoothEnabled(boolean isEnabled)312     public void setBluetoothEnabled(boolean isEnabled) {
313         // If BT was connected and then turned off, there is no CONNECTION_STATE_CHANGE message.
314         // So set mIsBluetoothConnected to false if we get a bluetooth disable while connected.
315         // But otherwise, Bluetooth being turned on doesn't mean that we're connected.
316         if (!isEnabled) {
317             mIsBluetoothConnected.set(false);
318         }
319     }
320 
321     /** Set whether bluetooth is connected. */
setBluetoothConnected(boolean isConnected)322     public void setBluetoothConnected(boolean isConnected) {
323         mIsBluetoothConnected.set(isConnected);
324     }
325 
326     /** Get whether bluetooth is connected */
isBluetoothConnected()327     public boolean isBluetoothConnected() {
328         return mIsBluetoothConnected.get();
329     }
330 
331     /**
332      * Helper method to check if Connected MAC Randomization is supported - onDown events are
333      * skipped if this feature is enabled (b/72459123).
334      *
335      * @return boolean true if Connected MAC randomization is supported, false otherwise
336      */
isConnectedMacRandomizationEnabled()337     public boolean isConnectedMacRandomizationEnabled() {
338         return mContext.getResources().getBoolean(
339                 R.bool.config_wifi_connected_mac_randomization_supported);
340     }
341 
342     /**
343      * Helper method to check if WEP networks are deprecated.
344      *
345      * @return boolean true if WEP networks are deprecated, false otherwise.
346      */
isWepDeprecated()347     public boolean isWepDeprecated() {
348         return mWifiResourceCache.getBoolean(R.bool.config_wifiWepDeprecated,
349                 "config_wifiWepDeprecated")
350                 || (mWepAllowedControlSupported && !mIsWepAllowed.get());
351     }
352 
353     /**
354      * Helper method to check if WEP networks are supported.
355      *
356      * @return boolean true if WEP networks are supported, false otherwise.
357      */
isWepSupported()358     public boolean isWepSupported() {
359         return !mWifiResourceCache.getBoolean(R.bool.config_wifiWepDeprecated,
360                 "config_wifiWepDeprecated");
361     }
362 
363     /**
364      * Helper method to check if WPA-Personal networks are deprecated.
365      *
366      * @return boolean true if WPA-Personal networks are deprecated, false otherwise.
367      */
isWpaPersonalDeprecated()368     public boolean isWpaPersonalDeprecated() {
369         return mIsWpaPersonalDeprecated;
370     }
371 
372     /**
373      * Helper method to check whether this device should disable firmware roaming in idle mode.
374      * @return if the device should disable firmware roaming in idle mode.
375      */
isDisableFirmwareRoamingInIdleMode()376     public boolean isDisableFirmwareRoamingInIdleMode() {
377         return mDisableFirmwareRoamingInIdleMode;
378     }
379 
380     /**
381      * Get the configuration for whether Multi-internet are allowed to
382      * connect simultaneously to both 5GHz high and 5GHz low.
383      */
isSupportMultiInternetDual5G()384     public boolean isSupportMultiInternetDual5G() {
385         return mIsSupportMultiInternetDual5G;
386     }
387 
388     /**
389      * Get number of repeated NUD failures needed to disable a network.
390      */
getRepeatedNudFailuresThreshold()391     public int getRepeatedNudFailuresThreshold() {
392         return mRepeatedNudFailuresThreshold;
393     }
394 
395     /**
396      * Get the time window in millis to count for repeated NUD failures.
397      */
getRepeatedNudFailuresWindowMs()398     public int getRepeatedNudFailuresWindowMs() {
399         return mRepeatedNudFailuresWindowMs;
400     }
401 
402     /**
403      * Helper method to check if the device may not connect to the configuration
404      * due to deprecated security type
405      */
isDeprecatedSecurityTypeNetwork(@ullable WifiConfiguration config)406     public boolean isDeprecatedSecurityTypeNetwork(@Nullable WifiConfiguration config) {
407         if (config == null) {
408             return false;
409         }
410         if (isWepDeprecated() && config.isSecurityType(WifiConfiguration.SECURITY_TYPE_WEP)) {
411             return true;
412         }
413         if (isWpaPersonalDeprecated() && config.isWpaPersonalOnlyConfiguration()) {
414             return true;
415         }
416         return false;
417     }
418 
419     /**
420      * Help method to check if WPA3 SAE auto-upgrade is enabled.
421      *
422      * @return boolean true if auto-upgrade is enabled, false otherwise.
423      */
isWpa3SaeUpgradeEnabled()424     public boolean isWpa3SaeUpgradeEnabled() {
425         return mIsWpa3SaeUpgradeEnabled;
426     }
427 
428     /**
429      * Help method to check if WPA3 SAE auto-upgrade offload is enabled.
430      *
431      * @return boolean true if auto-upgrade offload is enabled, false otherwise.
432      */
isWpa3SaeUpgradeOffloadEnabled()433     public boolean isWpa3SaeUpgradeOffloadEnabled() {
434         return mIsWpa3SaeUpgradeOffloadEnabled;
435     }
436 
437     /**
438      * Helper method to enable WPA3 SAE auto-upgrade offload based on the device capability for
439      * CROSS-AKM support.
440      */
setWpa3SaeUpgradeOffloadEnabled()441     public void setWpa3SaeUpgradeOffloadEnabled() {
442         Log.d(TAG, "Device supports CROSS-AKM feature - Enable WPA3 SAE auto-upgrade offload");
443         mIsWpa3SaeUpgradeOffloadEnabled = true;
444     }
445 
446 
447     /**
448      * Help method to check if OWE auto-upgrade is enabled.
449      *
450      * @return boolean true if auto-upgrade is enabled, false otherwise.
451      */
isOweUpgradeEnabled()452     public boolean isOweUpgradeEnabled() {
453         // OWE auto-upgrade is supported on S or newer releases.
454         return SdkLevel.isAtLeastS() && mIsOweUpgradeEnabled;
455     }
456 
457     /**
458      * Help method to check if the setting to flush ANQP cache when Wi-Fi is toggled off.
459      *
460      * @return boolean true to flush ANQP cache on Wi-Fi toggle off event, false otherwise.
461      */
flushAnqpCacheOnWifiToggleOffEvent()462     public boolean flushAnqpCacheOnWifiToggleOffEvent() {
463         return mFlushAnqpCacheOnWifiToggleOffEvent;
464     }
465 
466     /*
467      * Help method to check if WPA3 SAE Hash-to-Element is supported on this device.
468      *
469      * @return boolean true if supported;otherwise false.
470      */
isWpa3SaeH2eSupported()471     public boolean isWpa3SaeH2eSupported() {
472         return mIsWpa3SaeH2eSupported;
473     }
474 
475     /**
476      * Record the verbose logging level
477      */
setVerboseLoggingLevel(int level)478     public void setVerboseLoggingLevel(int level) {
479         mVerboseLoggingLevel = level;
480     }
481 
482     /** Return the currently set verbose logging level. */
getVerboseLoggingLevel()483     public int getVerboseLoggingLevel() {
484         return mVerboseLoggingLevel;
485     }
486 
487     /** Check if show key verbose logging mode is enabled. */
getShowKeyVerboseLoggingModeEnabled()488     public boolean getShowKeyVerboseLoggingModeEnabled() {
489         return mVerboseLoggingLevel == WifiManager.VERBOSE_LOGGING_LEVEL_ENABLED_SHOW_KEY;
490     }
491 
492     /** Set whether the external scorer is being used **/
setUsingExternalScorer(boolean isUsingExternalScorer)493     public void setUsingExternalScorer(boolean isUsingExternalScorer) {
494         mIsUsingExternalScorer = isUsingExternalScorer;
495     }
496 
497     /** Get whether the external scorer is being used **/
isUsingExternalScorer()498     public boolean isUsingExternalScorer() {
499         return mIsUsingExternalScorer;
500     }
501 
502     /** Get the prefix of the default wifi p2p device name. */
getWifiP2pDeviceNamePrefix()503     public String getWifiP2pDeviceNamePrefix() {
504         return mP2pDeviceNamePrefix;
505     }
506 
507     /** Get the number of the default wifi p2p device name postfix digit. */
getWifiP2pDeviceNamePostfixNumDigits()508     public int getWifiP2pDeviceNamePostfixNumDigits() {
509         return mP2pDeviceNamePostfixNumDigits;
510     }
511 
512     /** Get the number of log records to maintain. */
getClientModeImplNumLogRecs()513     public int getClientModeImplNumLogRecs() {
514         return mClientModeImplNumLogRecs;
515     }
516 
517     /** Get whether to use the saved factory MAC address when available **/
isSaveFactoryMacToConfigStoreEnabled()518     public boolean isSaveFactoryMacToConfigStoreEnabled() {
519         return mSaveFactoryMacToConfigStoreEnabled;
520     }
521 
522     /** Get the low score threshold to do scan for MBB when external scorer is not used. **/
getWifiLowConnectedScoreThresholdToTriggerScanForMbb()523     public int getWifiLowConnectedScoreThresholdToTriggerScanForMbb() {
524         return mWifiLowConnectedScoreThresholdToTriggerScanForMbb;
525     }
526 
527     /** Get the minimum period between the extra scans triggered for MBB when score is low **/
getWifiLowConnectedScoreScanPeriodSeconds()528     public int getWifiLowConnectedScoreScanPeriodSeconds() {
529         return mWifiLowConnectedScoreScanPeriodSeconds;
530     }
531 
532     /** Get whether or not insecure enterprise configuration is allowed. */
isInsecureEnterpriseConfigurationAllowed()533     public boolean isInsecureEnterpriseConfigurationAllowed() {
534         return mWifiAllowInsecureEnterpriseConfiguration;
535     }
536 
537     /** Get whether or not P2P MAC randomization is supported */
isP2pMacRandomizationSupported()538     public boolean isP2pMacRandomizationSupported() {
539         return mIsP2pMacRandomizationSupported;
540     }
541 
542     /** Get the regular (short) interval between RSSI polls, in milliseconds. */
getPollRssiShortIntervalMillis()543     public int getPollRssiShortIntervalMillis() {
544         return mPollRssiShortIntervalMillis;
545     }
546 
547     /**
548      * Get the long interval between RSSI polls, in milliseconds. The long interval is to
549      * reduce power consumption of the polls. This value should be greater than the regular
550      * interval.
551      */
getPollRssiLongIntervalMillis()552     public int getPollRssiLongIntervalMillis() {
553         return mPollRssiLongIntervalMillis;
554     }
555 
556     /**
557      * Get the RSSI threshold for client mode RSSI monitor, in dBm. If the device is stationary
558      * and current RSSI >= Threshold + Hysteresis value, set long interval and enable RSSI
559      * monitoring using the RSSI threshold. If device is non-stationary or current RSSI <=
560      * Threshold, set regular interval and disable RSSI monitoring.
561      */
getClientRssiMonitorThresholdDbm()562     public int getClientRssiMonitorThresholdDbm() {
563         return mClientRssiMonitorThresholdDbm;
564     }
565 
566     /**
567      * Get the hysteresis value in dB for the client mode RSSI monitor threshold. It can avoid
568      * frequent switch between regular and long polling intervals.
569      */
getClientRssiMonitorHysteresisDb()570     public int getClientRssiMonitorHysteresisDb() {
571         return mClientRssiMonitorHysteresisDb;
572     }
573 
574     /**
575      * Get whether adjusting the RSSI polling interval between regular and long intervals
576      * is enabled.
577      */
isAdjustPollRssiIntervalEnabled()578     public boolean isAdjustPollRssiIntervalEnabled() {
579         return mAdjustPollRssiIntervalEnabled;
580     }
581 
582     /**
583      * Get whether hot-plugging an interface will trigger a restart of the wifi stack.
584      */
isWifiInterfaceAddedSelfRecoveryEnabled()585     public boolean isWifiInterfaceAddedSelfRecoveryEnabled() {
586         return mWifiInterfaceAddedSelfRecoveryEnabled;
587     }
588 
589     /**
590      * Get whether background scan is supported.
591      */
isBackgroundScanSupported()592     public boolean isBackgroundScanSupported() {
593         return mWifiResourceCache
594                 .getBoolean(R.bool.config_wifi_background_scan_support,
595                         "config_wifi_background_scan_support");
596     };
597 
598     /**
599      * Get whether software pno is enabled.
600      */
isSwPnoEnabled()601     public boolean isSwPnoEnabled() {
602         return mIsSwPnoEnabled;
603     };
604 
605     /**
606      * Get whether to temporarily disable a unwanted network that has low RSSI.
607      */
disableUnwantedNetworkOnLowRssi()608     public boolean disableUnwantedNetworkOnLowRssi() {
609         return mDisableUnwantedNetworkOnLowRssi;
610     }
611 
612     /**
613      * Get whether to disable NUD disconnects for WAPI configurations in a specific CC.
614      */
disableNudDisconnectsForWapiInSpecificCc()615     public boolean disableNudDisconnectsForWapiInSpecificCc() {
616         return mDisableNudDisconnectsForWapiInSpecificCc;
617     }
618 
619     /**
620      * Get the threshold to use for blocking a network due to NETWORK_NOT_FOUND_EVENT failure.
621      */
getNetworkNotFoundEventThreshold()622     public int getNetworkNotFoundEventThreshold() {
623         return mNetworkNotFoundEventThreshold;
624     }
625 
626     /**
627      * Set whether wep network is allowed by user.
628      */
setWepAllowed(boolean isAllowed)629     public void setWepAllowed(boolean isAllowed) {
630         mIsWepAllowed.set(isAllowed);
631     }
632 
633     /**
634      * Get whether or not wep network is allowed by user.
635      */
isWepAllowed()636     public boolean isWepAllowed() {
637         return mIsWepAllowed.get();
638     }
639 
640     /**
641      * Set whether the device supports device-to-device + STA concurrency.
642      */
setD2dStaConcurrencySupported(boolean isSupported)643     public void setD2dStaConcurrencySupported(boolean isSupported) {
644         mIsD2dStaConcurrencySupported.set(isSupported);
645     }
646 
647     /**
648      * Returns whether the device supports device-to-device when infra STA is disabled.
649      */
isD2dSupportedWhenInfraStaDisabled()650     public boolean isD2dSupportedWhenInfraStaDisabled() {
651         return mD2dAllowedControlSupportedWhenInfraStaDisabled
652                 && !mIsD2dStaConcurrencySupported.get();
653     }
654 
655     /**
656      * Set the global dhcp hostname restriction.
657      */
setSendDhcpHostnameRestriction( @ifiManager.SendDhcpHostnameRestriction int restriction)658     public void setSendDhcpHostnameRestriction(
659             @WifiManager.SendDhcpHostnameRestriction int restriction) {
660         mSendDhcpHostnameRestriction.set(restriction);
661     }
662 
663     /**
664      * Get the global dhcp hostname restriction.
665      */
666     @WifiManager.SendDhcpHostnameRestriction
getSendDhcpHostnameRestriction()667     public int getSendDhcpHostnameRestriction() {
668         return mSendDhcpHostnameRestriction.get();
669     }
670 
671     /**
672      * Get the maximum Wifi temporary disable duration.
673      */
getWifiConfigMaxDisableDurationMs()674     public long getWifiConfigMaxDisableDurationMs() {
675         return mWifiConfigMaxDisableDurationMs;
676     }
677 
678     /** Dump method for debugging */
dump(FileDescriptor fd, PrintWriter pw, String[] args)679     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
680         pw.println("Dump of WifiGlobals");
681         pw.println("mPollRssiIntervalMillis=" + mPollRssiIntervalMillis.get());
682         pw.println("mIpReachabilityDisconnectEnabled=" + mIpReachabilityDisconnectEnabled.get());
683         pw.println("mIsBluetoothConnected=" + mIsBluetoothConnected.get());
684         pw.println("mIsWpa3SaeUpgradeEnabled=" + mIsWpa3SaeUpgradeEnabled);
685         pw.println("mIsWpa3SaeUpgradeOffloadEnabled=" + mIsWpa3SaeUpgradeOffloadEnabled);
686         pw.println("mIsOweUpgradeEnabled=" + mIsOweUpgradeEnabled);
687         pw.println("mFlushAnqpCacheOnWifiToggleOffEvent=" + mFlushAnqpCacheOnWifiToggleOffEvent);
688         pw.println("mIsWpa3SaeH2eSupported=" + mIsWpa3SaeH2eSupported);
689         pw.println("mP2pDeviceNamePrefix=" + mP2pDeviceNamePrefix);
690         pw.println("mP2pDeviceNamePostfixNumDigits=" + mP2pDeviceNamePostfixNumDigits);
691         pw.println("mClientModeImplNumLogRecs=" + mClientModeImplNumLogRecs);
692         pw.println("mSaveFactoryMacToConfigStoreEnabled=" + mSaveFactoryMacToConfigStoreEnabled);
693         pw.println("mWifiLowConnectedScoreThresholdToTriggerScanForMbb="
694                 + mWifiLowConnectedScoreThresholdToTriggerScanForMbb);
695         pw.println("mWifiLowConnectedScoreScanPeriodSeconds="
696                 + mWifiLowConnectedScoreScanPeriodSeconds);
697         pw.println("mIsUsingExternalScorer="
698                 + mIsUsingExternalScorer);
699         pw.println("mWifiAllowInsecureEnterpriseConfiguration="
700                 + mWifiAllowInsecureEnterpriseConfiguration);
701         pw.println("mIsP2pMacRandomizationSupported" + mIsP2pMacRandomizationSupported);
702         pw.println("mWifiInterfaceAddedSelfRecoveryEnabled="
703                 + mWifiInterfaceAddedSelfRecoveryEnabled);
704         pw.println("mDisableUnwantedNetworkOnLowRssi=" + mDisableUnwantedNetworkOnLowRssi);
705         pw.println("mNetworkNotFoundEventThreshold=" + mNetworkNotFoundEventThreshold);
706         pw.println("mIsSwPnoEnabled=" + mIsSwPnoEnabled);
707         pw.println("mIsWpaPersonalDeprecated=" + mIsWpaPersonalDeprecated);
708         pw.println("mIsWepAllowed=" + mIsWepAllowed.get());
709         pw.println("mWepAllowedControlSupported=" + mWepAllowedControlSupported);
710         pw.println("mDisableFirmwareRoamingInIdleMode=" + mDisableFirmwareRoamingInIdleMode);
711         pw.println("mRepeatedNudFailuresThreshold=" + mRepeatedNudFailuresThreshold);
712         pw.println("mRepeatedNudFailuresWindowMs=" + mRepeatedNudFailuresWindowMs);
713         pw.println("mCarrierSpecificEapFailureConfigMapPerCarrierId mapping below:");
714         pw.println("mWifiConfigMaxDisableDurationMs=" + mWifiConfigMaxDisableDurationMs);
715         pw.println("mD2dAllowedControlSupportedWhenInfraStaDisabled="
716                 + mD2dAllowedControlSupportedWhenInfraStaDisabled);
717         pw.println("IsD2dSupportedWhenInfraStaDisabled="
718                 + isD2dSupportedWhenInfraStaDisabled());
719         for (int i = 0; i < mCarrierSpecificEapFailureConfigMapPerCarrierId.size(); i++) {
720             int carrierId = mCarrierSpecificEapFailureConfigMapPerCarrierId.keyAt(i);
721             SparseArray<CarrierSpecificEapFailureConfig> perFailureMap =
722                     mCarrierSpecificEapFailureConfigMapPerCarrierId.valueAt(i);
723             for (int j = 0; j < perFailureMap.size(); j++) {
724                 int eapFailureCode = perFailureMap.keyAt(j);
725                 pw.println("carrierId=" + carrierId
726                         + ", eapFailureCode=" + eapFailureCode
727                         + ", displayNotification=" + perFailureMap.valueAt(j).displayNotification
728                         + ", threshold=" + perFailureMap.valueAt(j).threshold
729                         + ", durationMs=" + perFailureMap.valueAt(j).durationMs);
730             }
731         }
732         pw.println("mIsSupportMultiInternetDual5G=" + mIsSupportMultiInternetDual5G);
733         pw.println("mSendDhcpHostnameRestriction=" + mSendDhcpHostnameRestriction.get());
734     }
735 }
736