summaryrefslogtreecommitdiffstats
path: root/wifi
diff options
context:
space:
mode:
Diffstat (limited to 'wifi')
-rw-r--r--wifi/java/android/net/wifi/IWifiManager.aidl10
-rw-r--r--wifi/java/android/net/wifi/WifiManager.java66
-rw-r--r--wifi/java/android/net/wifi/WifiNative.java4
-rw-r--r--wifi/java/android/net/wifi/WifiStateTracker.java392
4 files changed, 363 insertions, 109 deletions
diff --git a/wifi/java/android/net/wifi/IWifiManager.aidl b/wifi/java/android/net/wifi/IWifiManager.aidl
index 5fd44b1..198b1e6 100644
--- a/wifi/java/android/net/wifi/IWifiManager.aidl
+++ b/wifi/java/android/net/wifi/IWifiManager.aidl
@@ -21,6 +21,8 @@ import android.net.wifi.WifiConfiguration;
import android.net.wifi.ScanResult;
import android.net.DhcpInfo;
+import android.os.WorkSource;
+
/**
* Interface that allows controlling and querying Wi-Fi connectivity.
*
@@ -40,7 +42,7 @@ interface IWifiManager
boolean pingSupplicant();
- boolean startScan(boolean forceActive);
+ void startScan(boolean forceActive);
List<ScanResult> getScanResults();
@@ -66,7 +68,9 @@ interface IWifiManager
DhcpInfo getDhcpInfo();
- boolean acquireWifiLock(IBinder lock, int lockType, String tag);
+ boolean acquireWifiLock(IBinder lock, int lockType, String tag, in WorkSource ws);
+
+ void updateWifiLockWorkSource(IBinder lock, in WorkSource ws);
boolean releaseWifiLock(IBinder lock);
@@ -83,5 +87,7 @@ interface IWifiManager
int getWifiApEnabledState();
WifiConfiguration getWifiApConfiguration();
+
+ void setWifiApConfiguration(in WifiConfiguration wifiConfig);
}
diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java
index 970d5fc..f883588 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -23,6 +23,7 @@ import android.os.Binder;
import android.os.IBinder;
import android.os.Handler;
import android.os.RemoteException;
+import android.os.WorkSource;
import java.util.List;
@@ -307,6 +308,16 @@ public class WifiManager {
public static final String ACTION_PICK_WIFI_NETWORK = "android.net.wifi.PICK_WIFI_NETWORK";
/**
+ * In this Wi-Fi lock mode, Wi-Fi will behave as in the mode
+ * {@link #WIFI_MODE_FULL} but it operates at high performance
+ * at the expense of power. This mode should be used
+ * only when the wifi connection needs to have minimum loss and low
+ * latency as it can impact the battery life.
+ * @hide
+ */
+ public static final int WIFI_MODE_FULL_HIGH_PERF = 3;
+
+ /**
* In this Wi-Fi lock mode, Wi-Fi will be kept active,
* and will behave normally, i.e., it will attempt to automatically
* establish a connection to a remembered access point that is
@@ -559,7 +570,8 @@ public class WifiManager {
*/
public boolean startScan() {
try {
- return mService.startScan(false);
+ mService.startScan(false);
+ return true;
} catch (RemoteException e) {
return false;
}
@@ -577,7 +589,8 @@ public class WifiManager {
*/
public boolean startScanActive() {
try {
- return mService.startScan(true);
+ mService.startScan(true);
+ return true;
} catch (RemoteException e) {
return false;
}
@@ -824,6 +837,21 @@ public class WifiManager {
}
/**
+ * Sets the Wi-Fi AP Configuration.
+ * @return {@code true} if the operation succeeded, {@code false} otherwise
+ *
+ * @hide Dont open yet
+ */
+ public boolean setWifiApConfiguration(WifiConfiguration wifiConfig) {
+ try {
+ mService.setWifiApConfiguration(wifiConfig);
+ return true;
+ } catch (RemoteException e) {
+ return false;
+ }
+ }
+
+ /**
* Allows an application to keep the Wi-Fi radio awake.
* Normally the Wi-Fi radio may turn off when the user has not used the device in a while.
* Acquiring a WifiLock will keep the radio on until the lock is released. Multiple
@@ -847,6 +875,7 @@ public class WifiManager {
int mLockType;
private boolean mRefCounted;
private boolean mHeld;
+ private WorkSource mWorkSource;
private WifiLock(int lockType, String tag) {
mTag = tag;
@@ -872,7 +901,7 @@ public class WifiManager {
synchronized (mBinder) {
if (mRefCounted ? (++mRefCount > 0) : (!mHeld)) {
try {
- mService.acquireWifiLock(mBinder, mLockType, mTag);
+ mService.acquireWifiLock(mBinder, mLockType, mTag, mWorkSource);
synchronized (WifiManager.this) {
if (mActiveLockCount >= MAX_ACTIVE_LOCKS) {
mService.releaseWifiLock(mBinder);
@@ -944,6 +973,32 @@ public class WifiManager {
}
}
+ public void setWorkSource(WorkSource ws) {
+ synchronized (mBinder) {
+ if (ws != null && ws.size() == 0) {
+ ws = null;
+ }
+ boolean changed = true;
+ if (ws == null) {
+ mWorkSource = null;
+ } else if (mWorkSource == null) {
+ changed = mWorkSource != null;
+ mWorkSource = new WorkSource(ws);
+ } else {
+ changed = mWorkSource.diff(ws);
+ if (changed) {
+ mWorkSource.set(ws);
+ }
+ }
+ if (changed && mHeld) {
+ try {
+ mService.updateWifiLockWorkSource(mBinder, mWorkSource);
+ } catch (RemoteException e) {
+ }
+ }
+ }
+ }
+
public String toString() {
String s1, s2, s3;
synchronized (mBinder) {
@@ -978,8 +1033,9 @@ public class WifiManager {
/**
* Creates a new WifiLock.
*
- * @param lockType the type of lock to create. See {@link #WIFI_MODE_FULL} and
- * {@link #WIFI_MODE_SCAN_ONLY} for descriptions of the types of Wi-Fi locks.
+ * @param lockType the type of lock to create. See {@link #WIFI_MODE_FULL},
+ * and {@link #WIFI_MODE_SCAN_ONLY} for descriptions of the types of Wi-Fi locks.
+ *
* @param tag a tag for the WifiLock to identify it in debugging messages. This string is
* never shown to the user under normal conditions, but should be descriptive
* enough to identify your application and the specific WifiLock within it, if it
diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java
index f98cd28..25f05c0 100644
--- a/wifi/java/android/net/wifi/WifiNative.java
+++ b/wifi/java/android/net/wifi/WifiNative.java
@@ -109,6 +109,8 @@ public class WifiNative {
public native static boolean setPowerModeCommand(int mode);
+ public native static int getPowerModeCommand();
+
public native static boolean setNumAllowedChannelsCommand(int numChannels);
public native static int getNumAllowedChannelsCommand();
@@ -147,6 +149,8 @@ public class WifiNative {
public native static String getDhcpError();
+ public native static boolean setSuspendOptimizationsCommand(boolean enabled);
+
/**
* Wait for the supplicant to send an event, returning the event string.
* @return the event string sent by the supplicant.
diff --git a/wifi/java/android/net/wifi/WifiStateTracker.java b/wifi/java/android/net/wifi/WifiStateTracker.java
index 3813015..5540174 100644
--- a/wifi/java/android/net/wifi/WifiStateTracker.java
+++ b/wifi/java/android/net/wifi/WifiStateTracker.java
@@ -38,6 +38,7 @@ import android.os.SystemProperties;
import android.os.Looper;
import android.os.RemoteException;
import android.os.ServiceManager;
+import android.os.WorkSource;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.EventLog;
@@ -59,6 +60,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicBoolean;
/**
* Track the state of Wifi connectivity. All event handling is done here,
@@ -216,6 +218,9 @@ public class WifiStateTracker extends NetworkStateTracker {
private boolean mUseStaticIp = false;
private int mReconnectCount;
+ /* Tracks if any network in the configuration is disabled */
+ private AtomicBoolean mIsAnyNetworkDisabled = new AtomicBoolean(false);
+
// used to store the (non-persisted) num determined during device boot
// (from mcc or other phone info) before the driver is started.
private int mNumAllowedChannels = 0;
@@ -276,6 +281,9 @@ public class WifiStateTracker extends NetworkStateTracker {
private boolean mIsScanModeActive;
private boolean mEnableRssiPolling;
+ private boolean mIsHighPerfEnabled;
+ private int mPowerModeRefCount = 0;
+ private int mOptimizationsDisabledRefCount = 0;
/**
* One of {@link WifiManager#WIFI_STATE_DISABLED},
@@ -316,6 +324,21 @@ public class WifiStateTracker extends NetworkStateTracker {
private static String[] sDnsPropNames;
/**
+ * Keep track of whether we last told the battery stats we had started.
+ */
+ private boolean mReportedRunning = false;
+
+ /**
+ * Most recently set source of starting WIFI.
+ */
+ private final WorkSource mRunningWifiUids = new WorkSource();
+
+ /**
+ * The last reported UIDs that were responsible for starting WIFI.
+ */
+ private final WorkSource mLastRunningWifiUids = new WorkSource();
+
+ /**
* A structure for supplying information about a supplicant state
* change in the STATE_CHANGE event message that comes from the
* WifiMonitor
@@ -578,8 +601,6 @@ public class WifiStateTracker extends NetworkStateTracker {
* Send the tracker a notification that the Wi-Fi driver has been stopped.
*/
void notifyDriverStopped() {
- mRunState = RUN_STATE_STOPPED;
-
// Send a driver stopped message to our handler
Message.obtain(this, EVENT_DRIVER_STATE_CHANGED, DRIVER_STOPPED, 0).sendToTarget();
}
@@ -625,12 +646,35 @@ public class WifiStateTracker extends NetworkStateTracker {
return mRunState == RUN_STATE_STOPPED || mRunState == RUN_STATE_STOPPING;
}
- private void noteRunState() {
+ public void updateBatteryWorkSourceLocked(WorkSource newSource) {
try {
+ if (newSource != null) {
+ mRunningWifiUids.set(newSource);
+ }
if (mRunState == RUN_STATE_RUNNING) {
- mBatteryStats.noteWifiRunning();
+ if (mReportedRunning) {
+ // If the work source has changed since last time, need
+ // to remove old work from battery stats.
+ if (mLastRunningWifiUids.diff(mRunningWifiUids)) {
+ mBatteryStats.noteWifiRunningChanged(mLastRunningWifiUids,
+ mRunningWifiUids);
+ mLastRunningWifiUids.set(mRunningWifiUids);
+ }
+ } else {
+ // Now being started, report it.
+ mBatteryStats.noteWifiRunning(mRunningWifiUids);
+ mLastRunningWifiUids.set(mRunningWifiUids);
+ mReportedRunning = true;
+ }
} else if (mRunState == RUN_STATE_STOPPED) {
- mBatteryStats.noteWifiStopped();
+ if (mReportedRunning) {
+ // Last reported we were running, time to stop.
+ mBatteryStats.noteWifiStopped(mLastRunningWifiUids);
+ mLastRunningWifiUids.clear();
+ mReportedRunning = false;
+ }
+ } else {
+ // State in transition -- nothing to update yet.
}
} catch (RemoteException ignore) {
}
@@ -659,6 +703,67 @@ public class WifiStateTracker extends NetworkStateTracker {
}
}
+ /**
+ * Set suspend mode optimizations. These include:
+ * - packet filtering
+ * - turn off roaming
+ * - DTIM settings
+ *
+ * Uses reference counting to keep the suspend optimizations disabled
+ * as long as one entity wants optimizations disabled.
+ *
+ * For example, WifiLock can keep suspend optimizations disabled
+ * or the user setting (wifi never sleeps) can keep suspend optimizations
+ * disabled. As long as one entity wants it disabled, it should stay
+ * that way
+ *
+ * @param enabled true if optimizations need enabled, false otherwise
+ */
+ public synchronized void setSuspendModeOptimizations(boolean enabled) {
+
+ /* It is good to plumb suspend optimization enable
+ * or disable even if ref count indicates already done
+ * since we could have a case of previous failure.
+ */
+ if (!enabled) {
+ mOptimizationsDisabledRefCount++;
+ } else {
+ mOptimizationsDisabledRefCount--;
+ if (mOptimizationsDisabledRefCount > 0) {
+ return;
+ } else {
+ /* Keep refcount from becoming negative */
+ mOptimizationsDisabledRefCount = 0;
+ }
+ }
+
+ if (mWifiState.get() != WIFI_STATE_ENABLED || isDriverStopped()) {
+ return;
+ }
+
+ WifiNative.setSuspendOptimizationsCommand(enabled);
+ }
+
+
+ /**
+ * Set high performance mode of operation. This would mean
+ * use active power mode and disable suspend optimizations
+ * @param enabled true if enabled, false otherwise
+ */
+ public synchronized void setHighPerfMode(boolean enabled) {
+ if (mIsHighPerfEnabled != enabled) {
+ if (enabled) {
+ setPowerMode(DRIVER_POWER_MODE_ACTIVE);
+ setSuspendModeOptimizations(false);
+ } else {
+ setPowerMode(DRIVER_POWER_MODE_AUTO);
+ setSuspendModeOptimizations(true);
+ }
+ mIsHighPerfEnabled = enabled;
+ Log.d(TAG,"high performance mode: " + enabled);
+ }
+ }
+
private void checkIsBluetoothPlaying() {
boolean isBluetoothPlaying = false;
@@ -733,7 +838,15 @@ public class WifiStateTracker extends NetworkStateTracker {
switch (msg.what) {
case EVENT_SUPPLICANT_CONNECTION:
mRunState = RUN_STATE_RUNNING;
- noteRunState();
+ String macaddr;
+ synchronized (this) {
+ updateBatteryWorkSourceLocked(null);
+ macaddr = WifiNative.getMacAddressCommand();
+ }
+ if (macaddr != null) {
+ mWifiInfo.setMacAddress(macaddr);
+ }
+
checkUseStaticIp();
/* Reset notification state on new connection */
resetNotificationTimer();
@@ -744,20 +857,16 @@ public class WifiStateTracker extends NetworkStateTracker {
dhcpThread.start();
mDhcpTarget = new DhcpHandler(dhcpThread.getLooper(), this);
mIsScanModeActive = true;
+ mIsHighPerfEnabled = false;
+ mOptimizationsDisabledRefCount = 0;
+ mPowerModeRefCount = 0;
mTornDownByConnMgr = false;
mLastBssid = null;
mLastSsid = null;
+ mIsAnyNetworkDisabled.set(false);
requestConnectionInfo();
SupplicantState supplState = mWifiInfo.getSupplicantState();
- /**
- * The MAC address isn't going to change, so just request it
- * once here.
- */
- String macaddr = getMacAddress();
- if (macaddr != null) {
- mWifiInfo.setMacAddress(macaddr);
- }
if (LOCAL_LOGD) Log.v(TAG, "Connection to supplicant established, state=" +
supplState);
// Wi-Fi supplicant connection state changed:
@@ -803,7 +912,9 @@ public class WifiStateTracker extends NetworkStateTracker {
case EVENT_SUPPLICANT_DISCONNECT:
mRunState = RUN_STATE_STOPPED;
- noteRunState();
+ synchronized (this) {
+ updateBatteryWorkSourceLocked(null);
+ }
boolean died = mWifiState.get() != WIFI_STATE_DISABLED &&
mWifiState.get() != WIFI_STATE_DISABLING;
if (died) {
@@ -927,13 +1038,18 @@ public class WifiStateTracker extends NetworkStateTracker {
}
handleDisconnectedState(newDetailedState, true);
/**
- * If we were associated with a network (networkId != -1),
- * assume we reached this state because of a failed attempt
- * to acquire an IP address, and attempt another connection
- * and IP address acquisition in RECONNECT_DELAY_MSECS
- * milliseconds.
+ * We should never let the supplicant stay in DORMANT state
+ * as long as we are in connect mode and driver is started
+ *
+ * We should normally hit a DORMANT state due to a disconnect
+ * issued after an IP configuration failure. We issue a reconnect
+ * after RECONNECT_DELAY_MSECS in such a case.
+ *
+ * After multiple failures, the network gets disabled and the
+ * supplicant should reach an INACTIVE state.
+ *
*/
- if (mRunState == RUN_STATE_RUNNING && !mIsScanOnly && networkId != -1) {
+ if (mRunState == RUN_STATE_RUNNING && !mIsScanOnly) {
sendMessageDelayed(reconnectMsg, RECONNECT_DELAY_MSECS);
} else if (mRunState == RUN_STATE_STOPPING) {
stopDriver();
@@ -1132,7 +1248,8 @@ public class WifiStateTracker extends NetworkStateTracker {
setDetailedState(DetailedState.CONNECTED);
sendNetworkStateChangeBroadcast(mWifiInfo.getBSSID());
} else {
- mTarget.sendEmptyMessage(EVENT_CONFIGURATION_CHANGED);
+ msg = mTarget.obtainMessage(EVENT_CONFIGURATION_CHANGED, mNetworkInfo);
+ msg.sendToTarget();
}
if (LOCAL_LOGD) Log.v(TAG, "IP configuration: " + mDhcpInfo);
// Wi-Fi interface configuration state changed:
@@ -1173,18 +1290,23 @@ public class WifiStateTracker extends NetworkStateTracker {
*/
setNumAllowedChannels();
synchronized (this) {
- if (mRunState == RUN_STATE_STARTING) {
- mRunState = RUN_STATE_RUNNING;
- if (!mIsScanOnly) {
- reconnectCommand();
- } else {
- // In some situations, supplicant needs to be kickstarted to
- // start the background scanning
- scan(true);
- }
+ macaddr = WifiNative.getMacAddressCommand();
+ if (macaddr != null) {
+ mWifiInfo.setMacAddress(macaddr);
+ }
+ mRunState = RUN_STATE_RUNNING;
+ if (!mIsScanOnly) {
+ reconnectCommand();
+ } else {
+ // In some situations, supplicant needs to be kickstarted to
+ // start the background scanning
+ scan(true);
}
}
break;
+ case DRIVER_STOPPED:
+ mRunState = RUN_STATE_STOPPED;
+ break;
case DRIVER_HUNG:
Log.e(TAG, "Wifi Driver reports HUNG - reloading.");
/**
@@ -1194,7 +1316,9 @@ public class WifiStateTracker extends NetworkStateTracker {
mWM.setWifiEnabled(true);
break;
}
- noteRunState();
+ synchronized (this) {
+ updateBatteryWorkSourceLocked(null);
+ }
break;
case EVENT_PASSWORD_KEY_MAY_BE_INCORRECT:
@@ -1342,34 +1466,34 @@ public class WifiStateTracker extends NetworkStateTracker {
}
private void requestConnectionStatus(WifiInfo info) {
- String reply = status();
- if (reply == null) {
- return;
- }
- /*
- * Parse the reply from the supplicant to the status command, and update
- * local state accordingly. The reply is a series of lines of the form
- * "name=value".
- */
String SSID = null;
String BSSID = null;
String suppState = null;
int netId = -1;
- String[] lines = reply.split("\n");
- for (String line : lines) {
- String[] prop = line.split(" *= *");
- if (prop.length < 2)
- continue;
- String name = prop[0];
- String value = prop[1];
- if (name.equalsIgnoreCase("id"))
- netId = Integer.parseInt(value);
- else if (name.equalsIgnoreCase("ssid"))
- SSID = value;
- else if (name.equalsIgnoreCase("bssid"))
- BSSID = value;
- else if (name.equalsIgnoreCase("wpa_state"))
- suppState = value;
+ String reply = status();
+ if (reply != null) {
+ /*
+ * Parse the reply from the supplicant to the status command, and update
+ * local state accordingly. The reply is a series of lines of the form
+ * "name=value".
+ */
+
+ String[] lines = reply.split("\n");
+ for (String line : lines) {
+ String[] prop = line.split(" *= *");
+ if (prop.length < 2)
+ continue;
+ String name = prop[0];
+ String value = prop[1];
+ if (name.equalsIgnoreCase("id"))
+ netId = Integer.parseInt(value);
+ else if (name.equalsIgnoreCase("ssid"))
+ SSID = value;
+ else if (name.equalsIgnoreCase("bssid"))
+ BSSID = value;
+ else if (name.equalsIgnoreCase("wpa_state"))
+ suppState = value;
+ }
}
info.setNetworkId(netId);
info.setSSID(SSID);
@@ -1483,27 +1607,26 @@ public class WifiStateTracker extends NetworkStateTracker {
* disconnect or stop command was initiated.
*/
public synchronized boolean disconnectAndStop() {
+ boolean ret = true;;
if (mRunState != RUN_STATE_STOPPING && mRunState != RUN_STATE_STOPPED) {
// Take down any open network notifications
setNotificationVisible(false, 0, false, 0);
- mRunState = RUN_STATE_STOPPING;
if (mWifiInfo.getSupplicantState() == SupplicantState.DORMANT) {
- return stopDriver();
+ ret = stopDriver();
} else {
- return disconnect();
+ ret = disconnect();
}
+ mRunState = RUN_STATE_STOPPING;
}
- return true;
+ return ret;
}
public synchronized boolean restart() {
- if (mRunState == RUN_STATE_STOPPED) {
+ if (isDriverStopped()) {
mRunState = RUN_STATE_STARTING;
resetConnections(true);
return startDriver();
- } else if (mRunState == RUN_STATE_STOPPING) {
- mRunState = RUN_STATE_STARTING;
}
return true;
}
@@ -1516,6 +1639,10 @@ public class WifiStateTracker extends NetworkStateTracker {
mWifiState.set(wifiState);
}
+ public boolean isAnyNetworkDisabled() {
+ return mIsAnyNetworkDisabled.get();
+ }
+
/**
* The WifiNative interface functions are listed below.
* The only native call that is not synchronized on
@@ -1605,7 +1732,7 @@ public class WifiStateTracker extends NetworkStateTracker {
* @return {@code true} if the operation succeeds, {@code false} otherwise
*/
public synchronized boolean scan(boolean forceActive) {
- if (mWifiState.get() != WIFI_STATE_ENABLED && !isDriverStopped()) {
+ if (mWifiState.get() != WIFI_STATE_ENABLED || isDriverStopped()) {
return false;
}
return WifiNative.scanCommand(forceActive);
@@ -1621,7 +1748,7 @@ public class WifiStateTracker extends NetworkStateTracker {
* @return {@code true} if the operation succeeds, {@code false} otherwise
*/
public synchronized boolean setScanResultHandling(int mode) {
- if (mWifiState.get() != WIFI_STATE_ENABLED && !isDriverStopped()) {
+ if (mWifiState.get() != WIFI_STATE_ENABLED) {
return false;
}
return WifiNative.setScanResultHandlingCommand(mode);
@@ -1635,7 +1762,7 @@ public class WifiStateTracker extends NetworkStateTracker {
* 00:bb:cc:dd:cc:ff 2412 165 [WPA-EAP-TKIP][WPA2-EAP-CCMP] Net2
*/
public synchronized String scanResults() {
- if (mWifiState.get() != WIFI_STATE_ENABLED && !isDriverStopped()) {
+ if (mWifiState.get() != WIFI_STATE_ENABLED || isDriverStopped()) {
return null;
}
return WifiNative.scanResultsCommand();
@@ -1647,7 +1774,7 @@ public class WifiStateTracker extends NetworkStateTracker {
* @return {@code true} if the operation succeeds, {@code false} otherwise
*/
public synchronized boolean setScanMode(boolean isScanModeActive) {
- if (mWifiState.get() != WIFI_STATE_ENABLED && !isDriverStopped()) {
+ if (mWifiState.get() != WIFI_STATE_ENABLED || isDriverStopped()) {
return false;
}
if (mIsScanModeActive != isScanModeActive) {
@@ -1662,7 +1789,7 @@ public class WifiStateTracker extends NetworkStateTracker {
* @return {@code true} if the operation succeeds, {@code false} otherwise
*/
public synchronized boolean disconnect() {
- if (mWifiState.get() != WIFI_STATE_ENABLED && !isDriverStopped()) {
+ if (mWifiState.get() != WIFI_STATE_ENABLED || isDriverStopped()) {
return false;
}
return WifiNative.disconnectCommand();
@@ -1674,7 +1801,7 @@ public class WifiStateTracker extends NetworkStateTracker {
* @return {@code true} if the operation succeeds, {@code false} otherwise
*/
public synchronized boolean reconnectCommand() {
- if (mWifiState.get() != WIFI_STATE_ENABLED && !isDriverStopped()) {
+ if (mWifiState.get() != WIFI_STATE_ENABLED || isDriverStopped()) {
return false;
}
return WifiNative.reconnectCommand();
@@ -1716,10 +1843,28 @@ public class WifiStateTracker extends NetworkStateTracker {
if (mWifiState.get() != WIFI_STATE_ENABLED) {
return false;
}
+ if (disableOthers) mIsAnyNetworkDisabled.set(true);
return WifiNative.enableNetworkCommand(netId, disableOthers);
}
/**
+ * Enable all networks
+ *
+ * @param networks list of configured networks
+ */
+ public synchronized void enableAllNetworks(List<WifiConfiguration> networks) {
+ if (mWifiState.get() != WIFI_STATE_ENABLED) {
+ return;
+ }
+ mIsAnyNetworkDisabled.set(false);
+ for (WifiConfiguration config : networks) {
+ if (config.status == WifiConfiguration.Status.DISABLED) {
+ WifiNative.enableNetworkCommand(config.networkId, false);
+ }
+ }
+ }
+
+ /**
* Disable a network
*
* @param netId network id of the network
@@ -1729,6 +1874,7 @@ public class WifiStateTracker extends NetworkStateTracker {
if (mWifiState.get() != WIFI_STATE_ENABLED) {
return false;
}
+ mIsAnyNetworkDisabled.set(true);
return WifiNative.disableNetworkCommand(netId);
}
@@ -1738,7 +1884,7 @@ public class WifiStateTracker extends NetworkStateTracker {
* @return {@code true} if the operation succeeds, {@code false} otherwise
*/
public synchronized boolean reassociate() {
- if (mWifiState.get() != WIFI_STATE_ENABLED && !isDriverStopped()) {
+ if (mWifiState.get() != WIFI_STATE_ENABLED || isDriverStopped()) {
return false;
}
return WifiNative.reassociateCommand();
@@ -1837,7 +1983,7 @@ public class WifiStateTracker extends NetworkStateTracker {
* @return RSSI value, -1 on failure
*/
public synchronized int getRssi() {
- if (mWifiState.get() != WIFI_STATE_ENABLED && !isDriverStopped()) {
+ if (mWifiState.get() != WIFI_STATE_ENABLED || isDriverStopped()) {
return -1;
}
return WifiNative.getRssiApproxCommand();
@@ -1849,7 +1995,7 @@ public class WifiStateTracker extends NetworkStateTracker {
* @return RSSI value, -1 on failure
*/
public synchronized int getRssiApprox() {
- if (mWifiState.get() != WIFI_STATE_ENABLED && !isDriverStopped()) {
+ if (mWifiState.get() != WIFI_STATE_ENABLED || isDriverStopped()) {
return -1;
}
return WifiNative.getRssiApproxCommand();
@@ -1861,25 +2007,13 @@ public class WifiStateTracker extends NetworkStateTracker {
* @return link speed, -1 on failure
*/
public synchronized int getLinkSpeed() {
- if (mWifiState.get() != WIFI_STATE_ENABLED && !isDriverStopped()) {
+ if (mWifiState.get() != WIFI_STATE_ENABLED || isDriverStopped()) {
return -1;
}
return WifiNative.getLinkSpeedCommand();
}
/**
- * Get MAC address of radio
- *
- * @return MAC address, null on failure
- */
- public synchronized String getMacAddress() {
- if (mWifiState.get() != WIFI_STATE_ENABLED && !isDriverStopped()) {
- return null;
- }
- return WifiNative.getMacAddressCommand();
- }
-
- /**
* Start driver
*
* @return {@code true} if the operation succeeds, {@code false} otherwise
@@ -1897,7 +2031,9 @@ public class WifiStateTracker extends NetworkStateTracker {
* @return {@code true} if the operation succeeds, {@code false} otherwise
*/
public synchronized boolean stopDriver() {
- if (mWifiState.get() != WIFI_STATE_ENABLED) {
+ /* Driver stop should not happen only when supplicant event
+ * DRIVER_STOPPED has already been handled */
+ if (mWifiState.get() != WIFI_STATE_ENABLED || mRunState == RUN_STATE_STOPPED) {
return false;
}
return WifiNative.stopDriverCommand();
@@ -1909,7 +2045,7 @@ public class WifiStateTracker extends NetworkStateTracker {
* @return {@code true} if the operation succeeds, {@code false} otherwise
*/
public synchronized boolean startPacketFiltering() {
- if (mWifiState.get() != WIFI_STATE_ENABLED && !isDriverStopped()) {
+ if (mWifiState.get() != WIFI_STATE_ENABLED || isDriverStopped()) {
return false;
}
return WifiNative.startPacketFiltering();
@@ -1921,24 +2057,63 @@ public class WifiStateTracker extends NetworkStateTracker {
* @return {@code true} if the operation succeeds, {@code false} otherwise
*/
public synchronized boolean stopPacketFiltering() {
- if (mWifiState.get() != WIFI_STATE_ENABLED && !isDriverStopped()) {
+ if (mWifiState.get() != WIFI_STATE_ENABLED || isDriverStopped()) {
return false;
}
return WifiNative.stopPacketFiltering();
}
/**
+ * Get power mode
+ * @return power mode
+ */
+ public synchronized int getPowerMode() {
+ if (mWifiState.get() != WIFI_STATE_ENABLED && !isDriverStopped()) {
+ return -1;
+ }
+ return WifiNative.getPowerModeCommand();
+ }
+
+ /**
* Set power mode
* @param mode
* DRIVER_POWER_MODE_AUTO
* DRIVER_POWER_MODE_ACTIVE
- * @return {@code true} if the operation succeeds, {@code false} otherwise
+ *
+ * Uses reference counting to keep power mode active
+ * as long as one entity wants power mode to be active.
+ *
+ * For example, WifiLock high perf mode can keep power mode active
+ * or a DHCP session can keep it active. As long as one entity wants
+ * it enabled, it should stay that way
+ *
*/
- public synchronized boolean setPowerMode(int mode) {
- if (mWifiState.get() != WIFI_STATE_ENABLED && !isDriverStopped()) {
- return false;
+ private synchronized void setPowerMode(int mode) {
+
+ /* It is good to plumb power mode change
+ * even if ref count indicates already done
+ * since we could have a case of previous failure.
+ */
+ switch(mode) {
+ case DRIVER_POWER_MODE_ACTIVE:
+ mPowerModeRefCount++;
+ break;
+ case DRIVER_POWER_MODE_AUTO:
+ mPowerModeRefCount--;
+ if (mPowerModeRefCount > 0) {
+ return;
+ } else {
+ /* Keep refcount from becoming negative */
+ mPowerModeRefCount = 0;
+ }
+ break;
}
- return WifiNative.setPowerModeCommand(mode);
+
+ if (mWifiState.get() != WIFI_STATE_ENABLED || isDriverStopped()) {
+ return;
+ }
+
+ WifiNative.setPowerModeCommand(mode);
}
/**
@@ -1948,7 +2123,7 @@ public class WifiStateTracker extends NetworkStateTracker {
* the number of channels is invalid.
*/
public synchronized boolean setNumAllowedChannels() {
- if (mWifiState.get() != WIFI_STATE_ENABLED && !isDriverStopped()) {
+ if (mWifiState.get() != WIFI_STATE_ENABLED || isDriverStopped()) {
return false;
}
try {
@@ -1973,7 +2148,7 @@ public class WifiStateTracker extends NetworkStateTracker {
* {@code numChannels} is outside the valid range.
*/
public synchronized boolean setNumAllowedChannels(int numChannels) {
- if (mWifiState.get() != WIFI_STATE_ENABLED && !isDriverStopped()) {
+ if (mWifiState.get() != WIFI_STATE_ENABLED || isDriverStopped()) {
return false;
}
mNumAllowedChannels = numChannels;
@@ -1986,7 +2161,7 @@ public class WifiStateTracker extends NetworkStateTracker {
* @return channel count, -1 on failure
*/
public synchronized int getNumAllowedChannels() {
- if (mWifiState.get() != WIFI_STATE_ENABLED && !isDriverStopped()) {
+ if (mWifiState.get() != WIFI_STATE_ENABLED || isDriverStopped()) {
return -1;
}
return WifiNative.getNumAllowedChannelsCommand();
@@ -2002,7 +2177,7 @@ public class WifiStateTracker extends NetworkStateTracker {
* @return {@code true} if the operation succeeds, {@code false} otherwise
*/
public synchronized boolean setBluetoothCoexistenceMode(int mode) {
- if (mWifiState.get() != WIFI_STATE_ENABLED && !isDriverStopped()) {
+ if (mWifiState.get() != WIFI_STATE_ENABLED || isDriverStopped()) {
return false;
}
return WifiNative.setBluetoothCoexistenceModeCommand(mode);
@@ -2016,7 +2191,7 @@ public class WifiStateTracker extends NetworkStateTracker {
* @param isBluetoothPlaying whether to enable or disable this mode
*/
public synchronized void setBluetoothScanMode(boolean isBluetoothPlaying) {
- if (mWifiState.get() != WIFI_STATE_ENABLED && !isDriverStopped()) {
+ if (mWifiState.get() != WIFI_STATE_ENABLED || isDriverStopped()) {
return;
}
WifiNative.setBluetoothCoexistenceScanModeCommand(isBluetoothPlaying);
@@ -2252,6 +2427,8 @@ public class WifiStateTracker extends NetworkStateTracker {
case EVENT_DHCP_START:
boolean modifiedBluetoothCoexistenceMode = false;
+ int powerMode = DRIVER_POWER_MODE_AUTO;
+
if (shouldDisableCoexistenceMode()) {
/*
* There are problems setting the Wi-Fi driver's power
@@ -2276,7 +2453,15 @@ public class WifiStateTracker extends NetworkStateTracker {
WifiNative.BLUETOOTH_COEXISTENCE_MODE_DISABLED);
}
- setPowerMode(DRIVER_POWER_MODE_ACTIVE);
+ powerMode = getPowerMode();
+ if (powerMode < 0) {
+ // Handle the case where supplicant driver does not support
+ // getPowerModeCommand.
+ powerMode = DRIVER_POWER_MODE_AUTO;
+ }
+ if (powerMode != DRIVER_POWER_MODE_ACTIVE) {
+ setPowerMode(DRIVER_POWER_MODE_ACTIVE);
+ }
synchronized (this) {
// A new request is being made, so assume we will callback
@@ -2292,7 +2477,9 @@ public class WifiStateTracker extends NetworkStateTracker {
NetworkUtils.getDhcpError());
}
- setPowerMode(DRIVER_POWER_MODE_AUTO);
+ if (powerMode != DRIVER_POWER_MODE_ACTIVE) {
+ setPowerMode(powerMode);
+ }
if (modifiedBluetoothCoexistenceMode) {
// Set the coexistence mode back to its default value
@@ -2323,7 +2510,7 @@ public class WifiStateTracker extends NetworkStateTracker {
* @return Whether to disable coexistence mode.
*/
private boolean shouldDisableCoexistenceMode() {
- int state = mBluetoothHeadset.getState();
+ int state = mBluetoothHeadset.getState(mBluetoothHeadset.getCurrentHeadset());
return state == BluetoothHeadset.STATE_DISCONNECTED;
}
}
@@ -2450,7 +2637,8 @@ public class WifiStateTracker extends NetworkStateTracker {
resetConnections(true);
configureInterface();
if (mUseStaticIp) {
- mTarget.sendEmptyMessage(EVENT_CONFIGURATION_CHANGED);
+ Message msg = mTarget.obtainMessage(EVENT_CONFIGURATION_CHANGED, mNetworkInfo);
+ msg.sendToTarget();
}
}
}