• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.content.Context;
20 
21 import com.android.wifi.resources.R;
22 
23 import java.io.FileDescriptor;
24 import java.io.PrintWriter;
25 import java.util.concurrent.atomic.AtomicBoolean;
26 import java.util.concurrent.atomic.AtomicInteger;
27 
28 import javax.annotation.concurrent.ThreadSafe;
29 
30 
31 /** Global wifi service in-memory state that is not persisted. */
32 @ThreadSafe
33 public class WifiGlobals {
34 
35     /**
36      * Maximum allowable interval in milliseconds between polling for RSSI and linkspeed
37      * information. This is also used as the polling interval for WifiTrafficPoller, which updates
38      * its data activity on every CMD_RSSI_POLL.
39      */
40     private static final int MAXIMUM_POLL_RSSI_INTERVAL_MSECS = 6000;
41 
42     private final Context mContext;
43 
44     private final AtomicInteger mPollRssiIntervalMillis = new AtomicInteger(-1);
45     private final AtomicBoolean mIpReachabilityDisconnectEnabled = new AtomicBoolean(true);
46     private final AtomicBoolean mIsBluetoothConnected = new AtomicBoolean(false);
47 
48     // This is read from the overlay, cache it after boot up.
49     private final boolean mIsWpa3SaeUpgradeEnabled;
50     // This is read from the overlay, cache it after boot up.
51     private final boolean mIsWpa3SaeUpgradeOffloadEnabled;
52     // This is read from the overlay, cache it after boot up.
53     private final boolean mIsOweUpgradeEnabled;
54     // This is read from the overlay, cache it after boot up.
55     private final boolean mFlushAnqpCacheOnWifiToggleOffEvent;
56     // This is read from the overlay, cache it after boot up.
57     private final boolean mIsWpa3SaeH2eSupported;
58     // This is read from the overlay, cache it after boot up.
59     private final String mP2pDeviceNamePrefix;
60     // This is read from the overlay, cache it after boot up.
61     private final int mP2pDeviceNamePostfixNumDigits;
62     // This is read from the overlay, cache it after boot up.
63     private final int mClientModeImplNumLogRecs;
64 
65     // This is set by WifiManager#setVerboseLoggingEnabled(int).
66     private boolean mIsShowKeyVerboseLoggingModeEnabled = false;
67 
WifiGlobals(Context context)68     public WifiGlobals(Context context) {
69         mContext = context;
70 
71         mIsWpa3SaeUpgradeEnabled = mContext.getResources()
72                 .getBoolean(R.bool.config_wifiSaeUpgradeEnabled);
73         mIsWpa3SaeUpgradeOffloadEnabled = mContext.getResources()
74                 .getBoolean(R.bool.config_wifiSaeUpgradeOffloadEnabled);
75         mIsOweUpgradeEnabled = mContext.getResources()
76                 .getBoolean(R.bool.config_wifiOweUpgradeEnabled);
77         mFlushAnqpCacheOnWifiToggleOffEvent = mContext.getResources()
78                 .getBoolean(R.bool.config_wifiFlushAnqpCacheOnWifiToggleOffEvent);
79         mIsWpa3SaeH2eSupported = mContext.getResources()
80                 .getBoolean(R.bool.config_wifiSaeH2eSupported);
81         mP2pDeviceNamePrefix = mContext.getResources()
82                 .getString(R.string.config_wifiP2pDeviceNamePrefix);
83         mP2pDeviceNamePostfixNumDigits = mContext.getResources()
84                 .getInteger(R.integer.config_wifiP2pDeviceNamePostfixNumDigits);
85         mClientModeImplNumLogRecs = mContext.getResources()
86                 .getInteger(R.integer.config_wifiClientModeImplNumLogRecs);
87     }
88 
89     /** Get the interval between RSSI polls, in milliseconds. */
getPollRssiIntervalMillis()90     public int getPollRssiIntervalMillis() {
91         int interval = mPollRssiIntervalMillis.get();
92         if (interval > 0) {
93             return interval;
94         } else {
95             return Math.min(
96                     mContext.getResources()
97                             .getInteger(R.integer.config_wifiPollRssiIntervalMilliseconds),
98                     MAXIMUM_POLL_RSSI_INTERVAL_MSECS);
99         }
100     }
101 
102     /** Set the interval between RSSI polls, in milliseconds. */
setPollRssiIntervalMillis(int newPollIntervalMillis)103     public void setPollRssiIntervalMillis(int newPollIntervalMillis) {
104         mPollRssiIntervalMillis.set(newPollIntervalMillis);
105     }
106 
107     /** Returns whether CMD_IP_REACHABILITY_LOST events should trigger disconnects. */
getIpReachabilityDisconnectEnabled()108     public boolean getIpReachabilityDisconnectEnabled() {
109         return mIpReachabilityDisconnectEnabled.get();
110     }
111 
112     /** Sets whether CMD_IP_REACHABILITY_LOST events should trigger disconnects. */
setIpReachabilityDisconnectEnabled(boolean enabled)113     public void setIpReachabilityDisconnectEnabled(boolean enabled) {
114         mIpReachabilityDisconnectEnabled.set(enabled);
115     }
116 
117     /** Set whether bluetooth is enabled. */
setBluetoothEnabled(boolean isEnabled)118     public void setBluetoothEnabled(boolean isEnabled) {
119         // If BT was connected and then turned off, there is no CONNECTION_STATE_CHANGE message.
120         // So set mIsBluetoothConnected to false if we get a bluetooth disable while connected.
121         // But otherwise, Bluetooth being turned on doesn't mean that we're connected.
122         if (!isEnabled) {
123             mIsBluetoothConnected.set(false);
124         }
125     }
126 
127     /** Set whether bluetooth is connected. */
setBluetoothConnected(boolean isConnected)128     public void setBluetoothConnected(boolean isConnected) {
129         mIsBluetoothConnected.set(isConnected);
130     }
131 
132     /** Get whether bluetooth is connected */
isBluetoothConnected()133     public boolean isBluetoothConnected() {
134         return mIsBluetoothConnected.get();
135     }
136 
137     /**
138      * Helper method to check if Connected MAC Randomization is supported - onDown events are
139      * skipped if this feature is enabled (b/72459123).
140      *
141      * @return boolean true if Connected MAC randomization is supported, false otherwise
142      */
isConnectedMacRandomizationEnabled()143     public boolean isConnectedMacRandomizationEnabled() {
144         return mContext.getResources().getBoolean(
145                 R.bool.config_wifi_connected_mac_randomization_supported);
146     }
147 
148     /**
149      * Help method to check if WPA3 SAE auto-upgrade is enabled.
150      *
151      * @return boolean true if auto-upgrade is enabled, false otherwise.
152      */
isWpa3SaeUpgradeEnabled()153     public boolean isWpa3SaeUpgradeEnabled() {
154         return mIsWpa3SaeUpgradeEnabled;
155     }
156 
157     /**
158      * Help method to check if WPA3 SAE auto-upgrade offload is enabled.
159      *
160      * @return boolean true if auto-upgrade offload is enabled, false otherwise.
161      */
isWpa3SaeUpgradeOffloadEnabled()162     public boolean isWpa3SaeUpgradeOffloadEnabled() {
163         return mIsWpa3SaeUpgradeOffloadEnabled;
164     }
165 
166     /**
167      * Help method to check if OWE auto-upgrade is enabled.
168      *
169      * @return boolean true if auto-upgrade is enabled, false otherwise.
170      */
isOweUpgradeEnabled()171     public boolean isOweUpgradeEnabled() {
172         return mIsOweUpgradeEnabled;
173     }
174 
175     /**
176      * Help method to check if the setting to flush ANQP cache when Wi-Fi is toggled off.
177      *
178      * @return boolean true to flush ANQP cache on Wi-Fi toggle off event, false otherwise.
179      */
flushAnqpCacheOnWifiToggleOffEvent()180     public boolean flushAnqpCacheOnWifiToggleOffEvent() {
181         return mFlushAnqpCacheOnWifiToggleOffEvent;
182     }
183 
184     /*
185      * Help method to check if WPA3 SAE Hash-to-Element is supported on this device.
186      *
187      * @return boolean true if supported;otherwise false.
188      */
isWpa3SaeH2eSupported()189     public boolean isWpa3SaeH2eSupported() {
190         return mIsWpa3SaeH2eSupported;
191     }
192 
193     /** Set if show key verbose logging mode is enabled. */
setShowKeyVerboseLoggingModeEnabled(boolean enable)194     public void setShowKeyVerboseLoggingModeEnabled(boolean enable) {
195         mIsShowKeyVerboseLoggingModeEnabled = enable;
196     }
197 
198     /** Check if show key verbose logging mode is enabled. */
getShowKeyVerboseLoggingModeEnabled()199     public boolean getShowKeyVerboseLoggingModeEnabled() {
200         return mIsShowKeyVerboseLoggingModeEnabled;
201     }
202 
203     /** Get the prefix of the default wifi p2p device name. */
getWifiP2pDeviceNamePrefix()204     public String getWifiP2pDeviceNamePrefix() {
205         return mP2pDeviceNamePrefix;
206     }
207 
208     /** Get the number of the default wifi p2p device name postfix digit. */
getWifiP2pDeviceNamePostfixNumDigits()209     public int getWifiP2pDeviceNamePostfixNumDigits() {
210         return mP2pDeviceNamePostfixNumDigits;
211     }
212 
213     /** Get the number of log records to maintain. */
getClientModeImplNumLogRecs()214     public int getClientModeImplNumLogRecs() {
215         return mClientModeImplNumLogRecs;
216     }
217 
218     /** Dump method for debugging */
dump(FileDescriptor fd, PrintWriter pw, String[] args)219     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
220         pw.println("Dump of WifiGlobals");
221         pw.println("mPollRssiIntervalMillis=" + mPollRssiIntervalMillis.get());
222         pw.println("mIpReachabilityDisconnectEnabled=" + mIpReachabilityDisconnectEnabled.get());
223         pw.println("mIsBluetoothConnected=" + mIsBluetoothConnected.get());
224         pw.println("mIsWpa3SaeUpgradeEnabled=" + mIsWpa3SaeUpgradeEnabled);
225         pw.println("mIsWpa3SaeUpgradeOffloadEnabled=" + mIsWpa3SaeUpgradeOffloadEnabled);
226         pw.println("mIsOweUpgradeEnabled=" + mIsOweUpgradeEnabled);
227         pw.println("mFlushAnqpCacheOnWifiToggleOffEvent=" + mFlushAnqpCacheOnWifiToggleOffEvent);
228         pw.println("mIsWpa3SaeH2eSupported=" + mIsWpa3SaeH2eSupported);
229         pw.println("mP2pDeviceNamePrefix=" + mP2pDeviceNamePrefix);
230         pw.println("mP2pDeviceNamePostfixNumDigits=" + mP2pDeviceNamePostfixNumDigits);
231         pw.println("mClientModeImplNumLogRecs=" + mClientModeImplNumLogRecs);
232     }
233 }
234