diff options
author | Jean-Baptiste Queru <jbq@google.com> | 2010-08-18 13:20:08 -0700 |
---|---|---|
committer | Jean-Baptiste Queru <jbq@google.com> | 2010-08-18 13:20:28 -0700 |
commit | 3719f8568e809ffd30f90adc38993256a9d3d066 (patch) | |
tree | 3cb03ca65d5460fd035ed631dbc82bd86080ac04 /wifi | |
parent | f93951851052f14e3263adff22266b61f487b018 (diff) | |
parent | 8c11e952305327183db9f7be719e4c94fde15a7c (diff) | |
download | frameworks_base-3719f8568e809ffd30f90adc38993256a9d3d066.zip frameworks_base-3719f8568e809ffd30f90adc38993256a9d3d066.tar.gz frameworks_base-3719f8568e809ffd30f90adc38993256a9d3d066.tar.bz2 |
DO NOT MERGE resolved conflicts for merge of 8c11e952 to gingerbread-plus-aosp
Change-Id: I29703133654f0f80a4425914d290e9dc50cbc3cc
Diffstat (limited to 'wifi')
-rw-r--r-- | wifi/java/android/net/wifi/WifiManager.java | 15 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/WifiNative.java | 2 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/WifiStateTracker.java | 103 |
3 files changed, 114 insertions, 6 deletions
diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java index 4a22b68..3b41dc1 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 @@ -993,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}, + * {@link #WIFI_MODE_SCAN_ONLY} and {@link #WIFI_MODE_FULL_HIGH_PERF} 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 7a3282c..25f05c0 100644 --- a/wifi/java/android/net/wifi/WifiNative.java +++ b/wifi/java/android/net/wifi/WifiNative.java @@ -149,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 05d6e17..fe1b096 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}, @@ -662,6 +665,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; @@ -747,6 +811,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; @@ -1950,13 +2017,41 @@ public class WifiStateTracker extends NetworkStateTracker { * @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) { + 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; + } + if (mWifiState.get() != WIFI_STATE_ENABLED || isDriverStopped()) { - return false; + return; } - return WifiNative.setPowerModeCommand(mode); + + WifiNative.setPowerModeCommand(mode); } /** |