summaryrefslogtreecommitdiffstats
path: root/wifi/java
diff options
context:
space:
mode:
Diffstat (limited to 'wifi/java')
-rw-r--r--wifi/java/android/net/wifi/IWifiManager.aidl2
-rw-r--r--wifi/java/android/net/wifi/WifiManager.java30
-rw-r--r--wifi/java/android/net/wifi/WifiNative.java4
-rw-r--r--wifi/java/android/net/wifi/WifiStateTracker.java189
4 files changed, 190 insertions, 35 deletions
diff --git a/wifi/java/android/net/wifi/IWifiManager.aidl b/wifi/java/android/net/wifi/IWifiManager.aidl
index 5fd44b1..6e0bc9d 100644
--- a/wifi/java/android/net/wifi/IWifiManager.aidl
+++ b/wifi/java/android/net/wifi/IWifiManager.aidl
@@ -83,5 +83,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..9d21521 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -307,6 +307,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
@@ -824,6 +834,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
@@ -978,8 +1003,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..0cc1f46 100644
--- a/wifi/java/android/net/wifi/WifiStateTracker.java
+++ b/wifi/java/android/net/wifi/WifiStateTracker.java
@@ -276,6 +276,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},
@@ -659,6 +662,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;
@@ -744,6 +808,9 @@ 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;
@@ -1132,7 +1199,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:
@@ -1483,18 +1551,19 @@ 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() {
@@ -1605,7 +1674,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 +1690,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 +1704,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 +1716,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 +1731,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 +1743,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();
@@ -1738,7 +1807,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 +1906,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 +1918,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,7 +1930,7 @@ 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();
@@ -1873,7 +1942,7 @@ public class WifiStateTracker extends NetworkStateTracker {
* @return MAC address, null on failure
*/
public synchronized String getMacAddress() {
- if (mWifiState.get() != WIFI_STATE_ENABLED && !isDriverStopped()) {
+ if (mWifiState.get() != WIFI_STATE_ENABLED || isDriverStopped()) {
return null;
}
return WifiNative.getMacAddressCommand();
@@ -1897,7 +1966,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 +1980,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 +1992,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 +2058,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 +2083,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 +2096,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 +2112,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 +2126,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 +2362,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 +2388,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 +2412,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 +2445,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 +2572,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();
}
}
}