diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2013-12-05 13:10:46 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2013-12-05 13:10:46 -0800 |
commit | ebcb32f58a6220802ca129ea33f47b4b69931a10 (patch) | |
tree | 32b57c1d6ba9180ae63979e06d7421e107a9aa6c /wifi | |
parent | 6e2d0c1d91f644ab50e0c0b7cae4306262a4ca41 (diff) | |
parent | bac61807d3bcfff957b358cb9ad77850bd373689 (diff) | |
download | frameworks_base-ebcb32f58a6220802ca129ea33f47b4b69931a10.zip frameworks_base-ebcb32f58a6220802ca129ea33f47b4b69931a10.tar.gz frameworks_base-ebcb32f58a6220802ca129ea33f47b4b69931a10.tar.bz2 |
Merge commit 'bac61807d3bcfff957b358cb9ad77850bd373689' into HEAD
Change-Id: I29374270c8e0c2f2859efaf1d55af9f73da0f8d7
Diffstat (limited to 'wifi')
-rw-r--r-- | wifi/java/android/net/wifi/IWifiManager.aidl | 2 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/SupplicantStateTracker.java | 2 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/WifiManager.java | 8 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/WifiNative.java | 21 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/WifiStateMachine.java | 129 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/p2p/WifiP2pService.java | 16 |
6 files changed, 138 insertions, 40 deletions
diff --git a/wifi/java/android/net/wifi/IWifiManager.aidl b/wifi/java/android/net/wifi/IWifiManager.aidl index 5a1928c..149bda6 100644 --- a/wifi/java/android/net/wifi/IWifiManager.aidl +++ b/wifi/java/android/net/wifi/IWifiManager.aidl @@ -117,7 +117,7 @@ interface IWifiManager void enableTdlsWithMacAddress(String remoteMacAddress, boolean enable); - boolean requestBatchedScan(in BatchedScanSettings requested, IBinder binder); + boolean requestBatchedScan(in BatchedScanSettings requested, IBinder binder, in WorkSource ws); void stopBatchedScan(in BatchedScanSettings requested); diff --git a/wifi/java/android/net/wifi/SupplicantStateTracker.java b/wifi/java/android/net/wifi/SupplicantStateTracker.java index f6a621f..e76eb17 100644 --- a/wifi/java/android/net/wifi/SupplicantStateTracker.java +++ b/wifi/java/android/net/wifi/SupplicantStateTracker.java @@ -55,7 +55,7 @@ class SupplicantStateTracker extends StateMachine { private static final int MAX_RETRIES_ON_AUTHENTICATION_FAILURE = 2; /* Maximum retries on assoc rejection events */ - private static final int MAX_RETRIES_ON_ASSOCIATION_REJECT = 4; + private static final int MAX_RETRIES_ON_ASSOCIATION_REJECT = 16; /* Tracks if networks have been disabled during a connection */ private boolean mNetworksDisabledDuringConnect = false; diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java index 7fc8bef..3b47e63 100644 --- a/wifi/java/android/net/wifi/WifiManager.java +++ b/wifi/java/android/net/wifi/WifiManager.java @@ -799,7 +799,13 @@ public class WifiManager { */ public boolean requestBatchedScan(BatchedScanSettings requested) { try { - return mService.requestBatchedScan(requested, new Binder()); + return mService.requestBatchedScan(requested, new Binder(), null); + } catch (RemoteException e) { return false; } + } + /** @hide */ + public boolean requestBatchedScan(BatchedScanSettings requested, WorkSource workSource) { + try { + return mService.requestBatchedScan(requested, new Binder(), workSource); } catch (RemoteException e) { return false; } } diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java index 520668e..c2f278a 100644 --- a/wifi/java/android/net/wifi/WifiNative.java +++ b/wifi/java/android/net/wifi/WifiNative.java @@ -39,7 +39,6 @@ import java.util.Locale; public class WifiNative { private static final boolean DBG = false; - private static final boolean VDBG = false; private final String mTAG; private static final int DEFAULT_GROUP_OWNER_INTENT = 6; @@ -118,12 +117,12 @@ public class WifiNative { public boolean connectToSupplicant() { // No synchronization necessary .. it is implemented in WifiMonitor - if (VDBG) localLog(mInterfacePrefix + "connectToSupplicant"); + localLog(mInterfacePrefix + "connectToSupplicant"); return connectToSupplicantNative(); } public void closeSupplicantConnection() { - if (VDBG) localLog(mInterfacePrefix + "closeSupplicantConnection"); + localLog(mInterfacePrefix + "closeSupplicantConnection"); closeSupplicantConnectionNative(); } @@ -136,9 +135,9 @@ public class WifiNative { if (DBG) Log.d(mTAG, "doBoolean: " + command); synchronized (mLock) { int cmdId = getNewCmdIdLocked(); - if (VDBG) localLog(cmdId + "->" + mInterfacePrefix + command); + localLog(cmdId + "->" + mInterfacePrefix + command); boolean result = doBooleanCommandNative(mInterfacePrefix + command); - if (VDBG) localLog(cmdId + "<-" + result); + localLog(cmdId + "<-" + result); if (DBG) Log.d(mTAG, " returned " + result); return result; } @@ -148,9 +147,9 @@ public class WifiNative { if (DBG) Log.d(mTAG, "doInt: " + command); synchronized (mLock) { int cmdId = getNewCmdIdLocked(); - if (VDBG) localLog(cmdId + "->" + mInterfacePrefix + command); + localLog(cmdId + "->" + mInterfacePrefix + command); int result = doIntCommandNative(mInterfacePrefix + command); - if (VDBG) localLog(cmdId + "<-" + result); + localLog(cmdId + "<-" + result); if (DBG) Log.d(mTAG, " returned " + result); return result; } @@ -160,9 +159,9 @@ public class WifiNative { if (DBG) Log.d(mTAG, "doString: " + command); synchronized (mLock) { int cmdId = getNewCmdIdLocked(); - if (VDBG) localLog(cmdId + "->" + mInterfacePrefix + command); + localLog(cmdId + "->" + mInterfacePrefix + command); String result = doStringCommandNative(mInterfacePrefix + command); - if (VDBG) localLog(cmdId + "<-" + result); + localLog(cmdId + "<-" + result); if (DBG) Log.d(mTAG, " returned " + result); return result; } @@ -298,7 +297,9 @@ public class WifiNative { * the firmware can remember before it runs out of buffer space or -1 on error */ public String setBatchedScanSettings(BatchedScanSettings settings) { - if (settings == null) return doStringCommand("DRIVER WLS_BATCHING STOP"); + if (settings == null) { + return doStringCommand("DRIVER WLS_BATCHING STOP"); + } String cmd = "DRIVER WLS_BATCHING SET SCANFREQ=" + settings.scanIntervalSec; cmd += " MSCAN=" + settings.maxScansPerBatch; if (settings.maxApPerScan != BatchedScanSettings.UNSPECIFIED) { diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java index 60c7f03..d8ca6b0 100644 --- a/wifi/java/android/net/wifi/WifiStateMachine.java +++ b/wifi/java/android/net/wifi/WifiStateMachine.java @@ -57,6 +57,7 @@ import android.net.wifi.p2p.WifiP2pManager; import android.net.wifi.p2p.WifiP2pService; import android.os.BatteryStats; import android.os.Binder; +import android.os.Bundle; import android.os.IBinder; import android.os.INetworkManagementService; import android.os.Message; @@ -89,6 +90,7 @@ import java.net.InetAddress; import java.net.Inet6Address; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicBoolean; import java.util.Iterator; @@ -415,7 +417,8 @@ public class WifiStateMachine extends StateMachine { /* change the batch scan settings. * arg1 = responsible UID - * obj = the new settings + * arg2 = csph (channel scans per hour) + * obj = bundle with the new settings and the optional worksource */ public static final int CMD_SET_BATCHED_SCAN = BASE + 135; public static final int CMD_START_NEXT_BATCHED_SCAN = BASE + 136; @@ -500,6 +503,10 @@ public class WifiStateMachine extends StateMachine { // until after, so the write is deferred private volatile String mPersistedCountryCode; + // Supplicant doesn't like setting the same country code multiple times (it may drop + // currently connected network), so we save the country code here to avoid redundency + private String mLastSetCountryCode; + private static final int MIN_RSSI = -200; private static final int MAX_RSSI = 256; @@ -623,6 +630,15 @@ public class WifiStateMachine extends StateMachine { private BatchedScanSettings mBatchedScanSettings = null; + /** + * Track the worksource/cost of the current settings and track what's been noted + * to the battery stats, so we can mark the end of the previous when changing. + */ + private WorkSource mBatchedScanWorkSource = null; + private int mBatchedScanCsph = 0; + private WorkSource mNotedBatchedScanWorkSource = null; + private int mNotedBatchedScanCsph = 0; + public WifiStateMachine(Context context, String wlanInterface) { super("WifiStateMachine"); @@ -836,8 +852,14 @@ public class WifiStateMachine extends StateMachine { /** * start or stop batched scanning using the given settings */ - public void setBatchedScanSettings(BatchedScanSettings settings, int callingUid) { - sendMessage(CMD_SET_BATCHED_SCAN, callingUid, 0, settings); + private static final String BATCHED_SETTING = "batched_settings"; + private static final String BATCHED_WORKSOURCE = "batched_worksource"; + public void setBatchedScanSettings(BatchedScanSettings settings, int callingUid, int csph, + WorkSource workSource) { + Bundle bundle = new Bundle(); + bundle.putParcelable(BATCHED_SETTING, settings); + bundle.putParcelable(BATCHED_WORKSOURCE, workSource); + sendMessage(CMD_SET_BATCHED_SCAN, callingUid, csph, bundle); } public List<BatchedScanResult> syncGetBatchedScanResultsList() { @@ -856,6 +878,8 @@ public class WifiStateMachine extends StateMachine { } private void startBatchedScan() { + if (mBatchedScanSettings == null) return; + if (mDhcpActive) { if (DBG) log("not starting Batched Scans due to DHCP"); return; @@ -867,10 +891,10 @@ public class WifiStateMachine extends StateMachine { mAlarmManager.cancel(mBatchedScanIntervalIntent); String scansExpected = mWifiNative.setBatchedScanSettings(mBatchedScanSettings); - try { mExpectedBatchedScans = Integer.parseInt(scansExpected); setNextBatchedAlarm(mExpectedBatchedScans); + if (mExpectedBatchedScans > 0) noteBatchedScanStart(); } catch (NumberFormatException e) { stopBatchedScan(); loge("Exception parsing WifiNative.setBatchedScanSettings response " + e); @@ -913,25 +937,31 @@ public class WifiStateMachine extends StateMachine { } // return true if new/different - private boolean recordBatchedScanSettings(BatchedScanSettings settings) { - if (DBG) log("set batched scan to " + settings); + private boolean recordBatchedScanSettings(int responsibleUid, int csph, Bundle bundle) { + BatchedScanSettings settings = bundle.getParcelable(BATCHED_SETTING); + WorkSource responsibleWorkSource = bundle.getParcelable(BATCHED_WORKSOURCE); + + if (DBG) { + log("set batched scan to " + settings + " for uid=" + responsibleUid + + ", worksource=" + responsibleWorkSource); + } if (settings != null) { - // TODO - noteBatchedScanStart(message.arg1); if (settings.equals(mBatchedScanSettings)) return false; } else { if (mBatchedScanSettings == null) return false; - // TODO - noteBatchedScanStop(message.arg1); } mBatchedScanSettings = settings; + if (responsibleWorkSource == null) responsibleWorkSource = new WorkSource(responsibleUid); + mBatchedScanWorkSource = responsibleWorkSource; + mBatchedScanCsph = csph; return true; } private void stopBatchedScan() { mAlarmManager.cancel(mBatchedScanIntervalIntent); - if (mBatchedScanSettings != null) { - retrieveBatchedScanData(); - mWifiNative.setBatchedScanSettings(null); - } + retrieveBatchedScanData(); + mWifiNative.setBatchedScanSettings(null); + noteBatchedScanStop(); } private void setNextBatchedAlarm(int scansExpected) { @@ -1159,6 +1189,44 @@ public class WifiStateMachine extends StateMachine { } } + private void noteBatchedScanStart() { + // note the end of a previous scan set + if (mNotedBatchedScanWorkSource != null && + (mNotedBatchedScanWorkSource.equals(mBatchedScanWorkSource) == false || + mNotedBatchedScanCsph != mBatchedScanCsph)) { + try { + mBatteryStats.noteWifiBatchedScanStoppedFromSource(mNotedBatchedScanWorkSource); + } catch (RemoteException e) { + log(e.toString()); + } finally { + mNotedBatchedScanWorkSource = null; + mNotedBatchedScanCsph = 0; + } + } + // note the start of the new + try { + mBatteryStats.noteWifiBatchedScanStartedFromSource(mBatchedScanWorkSource, + mBatchedScanCsph); + mNotedBatchedScanWorkSource = mBatchedScanWorkSource; + mNotedBatchedScanCsph = mBatchedScanCsph; + } catch (RemoteException e) { + log(e.toString()); + } + } + + private void noteBatchedScanStop() { + if (mNotedBatchedScanWorkSource != null) { + try { + mBatteryStats.noteWifiBatchedScanStoppedFromSource(mNotedBatchedScanWorkSource); + } catch (RemoteException e) { + log(e.toString()); + } finally { + mNotedBatchedScanWorkSource = null; + mNotedBatchedScanCsph = 0; + } + } + } + private void startScanNative(int type) { mWifiNative.scan(type); mScanResultIsPending = true; @@ -1863,6 +1931,9 @@ public class WifiStateMachine extends StateMachine { return; } + // note that all these splits and substrings keep references to the original + // huge string buffer while the amount we really want is generally pretty small + // so make copies instead (one example b/11087956 wasted 400k of heap here). synchronized(mScanResultCache) { mScanResults = new ArrayList<ScanResult>(); String[] lines = scanResults.split("\n"); @@ -2302,9 +2373,7 @@ public class WifiStateMachine extends StateMachine { mDhcpActive = false; - if (mBatchedScanSettings != null) { - startBatchedScan(); - } + startBatchedScan(); } private void handleSuccessfulIpConfiguration(DhcpResults dhcpResults) { @@ -2442,7 +2511,7 @@ public class WifiStateMachine extends StateMachine { } break; case CMD_SET_BATCHED_SCAN: - recordBatchedScanSettings((BatchedScanSettings)message.obj); + recordBatchedScanSettings(message.arg1, message.arg2, (Bundle)message.obj); break; case CMD_POLL_BATCHED_SCAN: handleBatchedScanPollRequest(); @@ -2955,9 +3024,7 @@ public class WifiStateMachine extends StateMachine { mDhcpActive = false; - if (mBatchedScanSettings != null) { - startBatchedScan(); - } + startBatchedScan(); if (mOperationalMode != CONNECT_MODE) { mWifiNative.disconnect(); @@ -3016,14 +3083,24 @@ public class WifiStateMachine extends StateMachine { startScanNative(WifiNative.SCAN_WITH_CONNECTION_SETUP); break; case CMD_SET_BATCHED_SCAN: - recordBatchedScanSettings((BatchedScanSettings)message.obj); - startBatchedScan(); + if (recordBatchedScanSettings(message.arg1, message.arg2, + (Bundle)message.obj)) { + startBatchedScan(); + } break; case CMD_SET_COUNTRY_CODE: String country = (String) message.obj; if (DBG) log("set country code " + country); - if (!mWifiNative.setCountryCode(country)) { - loge("Failed to set country code " + country); + if (country != null) { + country = country.toUpperCase(Locale.ROOT); + if (mLastSetCountryCode == null + || country.equals(mLastSetCountryCode) == false) { + if (mWifiNative.setCountryCode(country)) { + mLastSetCountryCode = country; + } else { + loge("Failed to set country code " + country); + } + } } break; case CMD_SET_FREQUENCY_BAND: @@ -3147,15 +3224,15 @@ public class WifiStateMachine extends StateMachine { updateBatteryWorkSource(null); mScanResults = new ArrayList<ScanResult>(); - if (mBatchedScanSettings != null) { - stopBatchedScan(); - } + stopBatchedScan(); final Intent intent = new Intent(WifiManager.WIFI_SCAN_AVAILABLE); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); intent.putExtra(WifiManager.EXTRA_SCAN_AVAILABLE, WIFI_STATE_DISABLED); mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); noteScanEnd(); // wrap up any pending request. + + mLastSetCountryCode = null; } } diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pService.java b/wifi/java/android/net/wifi/p2p/WifiP2pService.java index 625ffb8..8b07208 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pService.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pService.java @@ -85,6 +85,8 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; +import java.util.Locale; + /** * WifiP2pService includes a state machine to perform Wi-Fi p2p operations. Applications @@ -201,6 +203,10 @@ public class WifiP2pService extends IWifiP2pManager.Stub { */ private boolean mDiscoveryBlocked; + // Supplicant doesn't like setting the same country code multiple times (it may drop + // current connected network), so we save the country code here to avoid redundency + private String mLastSetCountryCode; + /* * remember if we were in a scan when it had to be stopped */ @@ -1070,7 +1076,13 @@ public class WifiP2pService extends IWifiP2pManager.Stub { break; case SET_COUNTRY_CODE: String countryCode = (String) message.obj; - mWifiNative.setCountryCode(countryCode); + countryCode = countryCode.toUpperCase(Locale.ROOT); + if (mLastSetCountryCode == null || + countryCode.equals(mLastSetCountryCode) == false) { + if (mWifiNative.setCountryCode(countryCode)) { + mLastSetCountryCode = countryCode; + } + } break; default: return NOT_HANDLED; @@ -1082,6 +1094,8 @@ public class WifiP2pService extends IWifiP2pManager.Stub { public void exit() { sendP2pStateChangedBroadcast(false); mNetworkInfo.setIsAvailable(false); + + mLastSetCountryCode = null; } } |