diff options
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 | 111 |
5 files changed, 107 insertions, 37 deletions
diff --git a/wifi/java/android/net/wifi/IWifiManager.aidl b/wifi/java/android/net/wifi/IWifiManager.aidl index bfcc208..4a6b1ff 100644 --- a/wifi/java/android/net/wifi/IWifiManager.aidl +++ b/wifi/java/android/net/wifi/IWifiManager.aidl @@ -115,7 +115,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 1fa7e85..4c887cb 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 8c92e55..4f2af78 100644 --- a/wifi/java/android/net/wifi/WifiStateMachine.java +++ b/wifi/java/android/net/wifi/WifiStateMachine.java @@ -56,6 +56,8 @@ import android.net.wifi.WpsResult.Status; 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; @@ -410,7 +412,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; @@ -620,6 +623,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"); @@ -832,8 +844,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() { @@ -852,6 +870,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; @@ -863,10 +883,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); @@ -909,25 +929,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) { @@ -1155,6 +1181,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; @@ -1855,6 +1919,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"); @@ -2294,9 +2361,7 @@ public class WifiStateMachine extends StateMachine { mDhcpActive = false; - if (mBatchedScanSettings != null) { - startBatchedScan(); - } + startBatchedScan(); } private void handleSuccessfulIpConfiguration(DhcpResults dhcpResults) { @@ -2434,7 +2499,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(); @@ -2946,9 +3011,7 @@ public class WifiStateMachine extends StateMachine { mDhcpActive = false; - if (mBatchedScanSettings != null) { - startBatchedScan(); - } + startBatchedScan(); if (mOperationalMode != CONNECT_MODE) { mWifiNative.disconnect(); @@ -3007,8 +3070,10 @@ 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; @@ -3146,9 +3211,7 @@ 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); |