diff options
author | vandwalle <vandwalle@google.com> | 2014-09-24 15:35:53 -0700 |
---|---|---|
committer | vandwalle <vandwalle@google.com> | 2014-09-24 16:32:14 -0700 |
commit | 70468b47454c8657e8963932f2e08a3f4d7e3881 (patch) | |
tree | 3ca61e806f178fdd52e23088de6867e67b831271 | |
parent | 9d082c381274f27dad1e344223189e00148e2124 (diff) | |
download | wifi-70468b47454c8657e8963932f2e08a3f4d7e3881.tar.gz |
- make rssi poll and wifi scan when associated configurable
- fix regression when forgeting network
- fix NPE in calculateWifiScore
Bug:17564108
Change-Id: I47329b1fb0f23c72886bdd3de99b4f9242d59eec
-rw-r--r-- | service/java/com/android/server/wifi/WifiConfigStore.java | 103 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/WifiStateMachine.java | 57 |
2 files changed, 104 insertions, 56 deletions
diff --git a/service/java/com/android/server/wifi/WifiConfigStore.java b/service/java/com/android/server/wifi/WifiConfigStore.java index 0887fc6df..b5495d87d 100644 --- a/service/java/com/android/server/wifi/WifiConfigStore.java +++ b/service/java/com/android/server/wifi/WifiConfigStore.java @@ -262,12 +262,28 @@ public class WifiConfigStore extends IpConfigStore { = "ALWAYS_ENABLE_SCAN_WHILE_ASSOCIATED: "; private static final String ONLY_LINK_SAME_CREDENTIAL_CONFIGURATIONS_KEY = "ONLY_LINK_SAME_CREDENTIAL_CONFIGURATIONS: "; + + // The three below configurations are mainly for power stats and CPU usage tracking + // allowing to incrementally disable framework features + private static final String ENABLE_AUTO_JOIN_SCAN_WHILE_ASSOCIATED_KEY + = "ENABLE_AUTO_JOIN_SCAN_WHILE_ASSOCIATED: "; + private static final String ENABLE_AUTO_JOIN_WHILE_ASSOCIATED_KEY + = "ENABLE_AUTO_JOIN_WHILE_ASSOCIATED: "; + private static final String ENABLE_CHIP_WAKE_UP_WHILE_ASSOCIATED_KEY + = "ENABLE_CHIP_WAKE_UP_WHILE_ASSOCIATED: "; + private static final String ENABLE_RSSI_POLL_WHILE_ASSOCIATED_KEY + = "ENABLE_RSSI_POLL_WHILE_ASSOCIATED_KEY: "; + // The Wifi verbose log is provided as a way to persist the verbose logging settings // for testing purpose. // It is not intended for normal use. private static final String WIFI_VERBOSE_LOGS_KEY = "WIFI_VERBOSE_LOGS: "; - public boolean enableAutoJoinWhileAssociated = true; + + public boolean enableAutoJoinScanWhenAssociated = true; + public boolean enableAutoJoinWhenAssociated = true; + public boolean enableChipWakeUpWhenAssociated = true; + public boolean enableRssiPollWhenAssociated = true; public int maxTxPacketForNetworkSwitching = 40; public int maxRxPacketForNetworkSwitching = 80; @@ -475,6 +491,13 @@ public class WifiConfigStore extends IpConfigStore { R.integer.config_wifi_framework_max_connection_errors_to_blacklist); wifiConfigBlacklistMinTimeMilli = mContext.getResources().getInteger( R.integer.config_wifi_framework_network_black_list_min_time_milli); + + + enableAutoJoinScanWhenAssociated = mContext.getResources().getBoolean( + R.bool.config_wifi_framework_enable_associated_autojoin_scan); + + enableAutoJoinWhenAssociated = mContext.getResources().getBoolean( + R.bool.config_wifi_framework_enable_associated_network_selection); } void enableVerboseLogging(int verbose) { @@ -947,7 +970,7 @@ public class WifiConfigStore extends IpConfigStore { removeKeys(config.enterpriseConfig); } - if (config.didSelfAdd || config.linkedConfigurations != null + if (config.selfAdded || config.linkedConfigurations != null || config.allowedKeyManagement.get(KeyMgmt.WPA_PSK)) { remove = false; loge("removeNetwork " + Integer.toString(netId) @@ -1377,7 +1400,6 @@ public class WifiConfigStore extends IpConfigStore { String value = null; for (String line = reader.readLine(); line != null; line = reader.readLine()) { - if (VDBG) loge(line); if (line.matches("[ \\t]*network=\\{")) { found = true; @@ -1625,6 +1647,9 @@ public class WifiConfigStore extends IpConfigStore { out.writeUTF(FAILURE_KEY + config.lastFailure + SEPARATOR_KEY); } out.writeUTF(SEPARATOR_KEY); + // Add extra blank lines for clarity + out.writeUTF(SEPARATOR_KEY); + out.writeUTF(SEPARATOR_KEY); } } @@ -1978,24 +2003,48 @@ public class WifiConfigStore extends IpConfigStore { if (key != null) { Log.d(TAG, "readAutoJoinConfig line: " + key); } - if (key.startsWith(ENABLE_AUTOJOIN_WHILE_ASSOCIATED_KEY)) { - String st = key.replace(ENABLE_AUTOJOIN_WHILE_ASSOCIATED_KEY, ""); + if (key.startsWith(ENABLE_AUTO_JOIN_WHILE_ASSOCIATED_KEY)) { + String st = key.replace(ENABLE_AUTO_JOIN_WHILE_ASSOCIATED_KEY, ""); st = st.replace(SEPARATOR_KEY, ""); try { - enableAutoJoinWhileAssociated = Integer.parseInt(st) != 0; - Log.d(TAG,"readAutoJoinConfig: enabled = " + enableAutoJoinWhileAssociated); + enableAutoJoinWhenAssociated = Integer.parseInt(st) != 0; + Log.d(TAG,"readAutoJoinConfig: enabled = " + enableAutoJoinWhenAssociated); } catch (NumberFormatException e) { Log.d(TAG,"readAutoJoinConfig: incorrect format :" + key); } } - if (key.startsWith(ONLY_LINK_SAME_CREDENTIAL_CONFIGURATIONS_KEY)) { - String st = key.replace(ONLY_LINK_SAME_CREDENTIAL_CONFIGURATIONS_KEY, ""); + if (key.startsWith(ENABLE_AUTO_JOIN_SCAN_WHILE_ASSOCIATED_KEY)) { + String st = key.replace(ENABLE_AUTO_JOIN_SCAN_WHILE_ASSOCIATED_KEY, ""); st = st.replace(SEPARATOR_KEY, ""); try { - onlyLinkSameCredentialConfigurations = Integer.parseInt(st) != 0; + enableAutoJoinScanWhenAssociated = Integer.parseInt(st) != 0; Log.d(TAG,"readAutoJoinConfig: enabled = " - + onlyLinkSameCredentialConfigurations); + + enableAutoJoinScanWhenAssociated); + } catch (NumberFormatException e) { + Log.d(TAG,"readAutoJoinConfig: incorrect format :" + key); + } + } + + if (key.startsWith(ENABLE_CHIP_WAKE_UP_WHILE_ASSOCIATED_KEY)) { + String st = key.replace(ENABLE_CHIP_WAKE_UP_WHILE_ASSOCIATED_KEY, ""); + st = st.replace(SEPARATOR_KEY, ""); + try { + enableChipWakeUpWhenAssociated = Integer.parseInt(st) != 0; + Log.d(TAG,"readAutoJoinConfig: enabled = " + + enableChipWakeUpWhenAssociated); + } catch (NumberFormatException e) { + Log.d(TAG,"readAutoJoinConfig: incorrect format :" + key); + } + } + + if (key.startsWith(ENABLE_RSSI_POLL_WHILE_ASSOCIATED_KEY)) { + String st = key.replace(ENABLE_RSSI_POLL_WHILE_ASSOCIATED_KEY, ""); + st = st.replace(SEPARATOR_KEY, ""); + try { + enableRssiPollWhenAssociated = Integer.parseInt(st) != 0; + Log.d(TAG,"readAutoJoinConfig: enabled = " + + enableRssiPollWhenAssociated); } catch (NumberFormatException e) { Log.d(TAG,"readAutoJoinConfig: incorrect format :" + key); } @@ -2870,7 +2919,7 @@ public class WifiConfigStore extends IpConfigStore { for (WifiConfiguration link : mConfiguredNetworks.values()) { boolean doLink = false; - if (link.autoJoinStatus == WifiConfiguration.AUTO_JOIN_DELETED || link.didSelfAdd) { + if (link.autoJoinStatus == WifiConfiguration.AUTO_JOIN_DELETED || link.selfAdded) { if (VVDBG) loge("associateWithConfiguration(): skip selfadd " + link.configKey() ); // Make sure we dont associate the scan result to a deleted config continue; @@ -3035,14 +3084,6 @@ public class WifiConfigStore extends IpConfigStore { for (WifiConfiguration config : mConfiguredNetworks.values()) { boolean found = false; - if (config.autoJoinStatus == WifiConfiguration.AUTO_JOIN_DELETED) { - if (VVDBG) { - loge("updateSavedNetworkHistory(): skip deleted " + config.configKey()); - } - // Make sure we dont add the scan result to a deleted config - continue; - } - if (config.SSID == null || !config.SSID.equals(SSID)) { // SSID mismatch if (VVDBG) { @@ -3054,7 +3095,8 @@ public class WifiConfigStore extends IpConfigStore { if (VDBG) { loge("updateSavedNetworkHistory(): try " + config.configKey() + " SSID=" + config.SSID + " " + scanResult.SSID - + " " + scanResult.capabilities); + + " " + scanResult.capabilities + + " ajst=" + config.autoJoinStatus); } if (scanResult.capabilities.contains("WEP") && config.configKey().contains("WEP")) { @@ -3075,6 +3117,20 @@ public class WifiConfigStore extends IpConfigStore { } if (found) { + numConfigFound ++; + + if (config.autoJoinStatus == WifiConfiguration.AUTO_JOIN_DELETED) { + if (VVDBG) { + loge("updateSavedNetworkHistory(): found a deleted, skip it... " + + config.configKey()); + } + // The scan result belongs to a deleted config: + // - increment numConfigFound to remember that we found a config + // matching for this scan result + // - dont do anything since the config was deleted, just skip... + continue; + } + if (config.scanResultCache == null) { config.scanResultCache = new HashMap<String, ScanResult>(); } @@ -3084,7 +3140,6 @@ public class WifiConfigStore extends IpConfigStore { config.dirty = true; } - numConfigFound ++; // Add the scan result to this WifiConfiguration config.scanResultCache.put(scanResult.BSSID, scanResult); // Since we added a scan result to this configuration, re-attempt linking @@ -3689,9 +3744,7 @@ public class WifiConfigStore extends IpConfigStore { // This is a network we self added, and we never succeeded, // the user did not create this network and never entered its credentials, // so we want to be very aggressive in disabling it completely. - disableNetwork(config.networkId, WifiConfiguration.DISABLED_AUTH_FAILURE); - config.setAutoJoinStatus(WifiConfiguration.AUTO_JOIN_DISABLED_ON_AUTH_FAILURE); - config.disableReason = WifiConfiguration.DISABLED_AUTH_FAILURE; + removeConfigAndSendBroadcastIfNeeded(config.networkId); } else { if (message != null) { if (message.contains("no identity")) { diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index c2b822242..8fe1b3c5d 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -183,11 +183,6 @@ public class WifiStateMachine extends StateMachine { /* Chipset supports background scan */ private final boolean mBackgroundScanSupported; - /* enable autojoin scans and selection when in associated mode */ - private final boolean mEnableAutoJoinScanWhenAssociated; - private final boolean mEnableAutoJoinWhenAssociated; - - private String mInterfaceName; /* Tethering interface could be separate from wlan interface */ private String mTetherInterfaceName; @@ -896,12 +891,6 @@ public class WifiStateMachine extends StateMachine { mBackgroundScanSupported = mContext.getResources().getBoolean( R.bool.config_wifi_background_scan_support); - mEnableAutoJoinScanWhenAssociated = mContext.getResources().getBoolean( - R.bool.config_wifi_framework_enable_associated_autojoin_scan); - - mEnableAutoJoinWhenAssociated = mContext.getResources().getBoolean( - R.bool.config_wifi_framework_enable_associated_network_selection); - mPrimaryDeviceType = mContext.getResources().getString( R.string.config_wifi_p2p_device_type); @@ -2825,7 +2814,7 @@ public class WifiStateMachine extends StateMachine { fullBandConnectedTimeIntervalMilli = mWifiConfigStore.associatedPartialScanPeriodMilli; // Start the scan alarm so as to enable autojoin if (getCurrentState() == mConnectedState - && mEnableAutoJoinScanWhenAssociated) { + && mWifiConfigStore.enableAutoJoinScanWhenAssociated) { mCurrentScanAlarmMs = mWifiConfigStore.associatedPartialScanPeriodMilli; // Scan after 200ms setScanAlarm(true, 200); @@ -3221,7 +3210,7 @@ public class WifiStateMachine extends StateMachine { || getCurrentState() == mScanModeState || getCurrentState() == mDisconnectingState || (getCurrentState() == mConnectedState - && !mEnableAutoJoinWhenAssociated) + && !mWifiConfigStore.enableAutoJoinWhenAssociated) || linkDebouncing || state == SupplicantState.ASSOCIATING || state == SupplicantState.AUTHENTICATING @@ -3345,7 +3334,7 @@ public class WifiStateMachine extends StateMachine { } delta = networkDelta; if (mWifiInfo != null) { - if (!mWifiConfigStore.enableAutoJoinWhileAssociated + if (!mWifiConfigStore.enableAutoJoinWhenAssociated && mWifiInfo.getNetworkId() != WifiConfiguration.INVALID_NETWORK_ID) { // If AutoJoin while associated is not enabled, // we should never switch network when already associated @@ -3522,10 +3511,10 @@ public class WifiStateMachine extends StateMachine { sb.append(" p3"); } } + sb.append(String.format(" ticks %d,%d,%d", currentConfiguration.numTicksAtBadRSSI, + currentConfiguration.numTicksAtLowRSSI, + currentConfiguration.numTicksAtNotHighRSSI)); } - sb.append(String.format(" ticks %d,%d,%d", currentConfiguration.numTicksAtBadRSSI, - currentConfiguration.numTicksAtLowRSSI, - currentConfiguration.numTicksAtNotHighRSSI)); if (PDBG) { String rssiStatus = ""; @@ -6734,19 +6723,21 @@ public class WifiStateMachine extends StateMachine { break; case CMD_RSSI_POLL: if (message.arg1 == mRssiPollToken) { - if (VVDBG) log(" get link layer stats " + mWifiLinkLayerStatsSupported); - WifiLinkLayerStats stats = getWifiLinkLayerStats(VDBG); - if (stats != null) { - // Sanity check the results provided by driver - if (mWifiInfo.getRssi() != WifiInfo.INVALID_RSSI - && (stats.rssi_mgmt == 0 - || stats.beacon_rx == 0)) { - stats = null; - } + if (mWifiConfigStore.enableChipWakeUpWhenAssociated) { + if (VVDBG) log(" get link layer stats " + mWifiLinkLayerStatsSupported); + WifiLinkLayerStats stats = getWifiLinkLayerStats(VDBG); + if (stats != null) { + // Sanity check the results provided by driver + if (mWifiInfo.getRssi() != WifiInfo.INVALID_RSSI + && (stats.rssi_mgmt == 0 + || stats.beacon_rx == 0)) { + stats = null; + } + } + // Get Info and continue polling + fetchRssiLinkSpeedAndFrequencyNative(); + calculateWifiScore(stats); } - // Get Info and continue polling - fetchRssiLinkSpeedAndFrequencyNative(); - calculateWifiScore(stats); sendMessageDelayed(obtainMessage(CMD_RSSI_POLL, mRssiPollToken, 0), POLL_RSSI_INTERVAL_MSECS); if (DBG) sendRssiChangeBroadcast(mWifiInfo.getRssi()); @@ -6755,7 +6746,11 @@ public class WifiStateMachine extends StateMachine { } break; case CMD_ENABLE_RSSI_POLL: - mEnableRssiPolling = (message.arg1 == 1); + if (mWifiConfigStore.enableRssiPollWhenAssociated) { + mEnableRssiPolling = (message.arg1 == 1); + } else { + mEnableRssiPolling = false; + } mRssiPollToken++; if (mEnableRssiPolling) { // First poll @@ -7119,7 +7114,7 @@ public class WifiStateMachine extends StateMachine { + Integer.toString(mWifiConfigStore.associatedPartialScanPeriodMilli) ); } if (mScreenOn - && mEnableAutoJoinScanWhenAssociated) { + && mWifiConfigStore.enableAutoJoinScanWhenAssociated) { mCurrentScanAlarmMs = mWifiConfigStore.associatedPartialScanPeriodMilli; // Scan after 200ms setScanAlarm(true, 200); |