Merge "Disable suspend optimizations during DHCP" into jb-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
85cf4a1519
@@ -138,10 +138,6 @@ public class WifiStateMachine extends StateMachine {
|
|||||||
private boolean mScanResultIsPending = false;
|
private boolean mScanResultIsPending = false;
|
||||||
/* Tracks if the current scan settings are active */
|
/* Tracks if the current scan settings are active */
|
||||||
private boolean mSetScanActive = false;
|
private boolean mSetScanActive = false;
|
||||||
/* High perf mode is true if an app has held a high perf Wifi Lock */
|
|
||||||
private boolean mHighPerfMode = false;
|
|
||||||
/* Tracks if user has disabled suspend optimizations through settings */
|
|
||||||
private AtomicBoolean mSuspendOptEnabled = new AtomicBoolean(true);
|
|
||||||
|
|
||||||
private boolean mBluetoothConnectionActive = false;
|
private boolean mBluetoothConnectionActive = false;
|
||||||
|
|
||||||
@@ -338,10 +334,8 @@ public class WifiStateMachine extends StateMachine {
|
|||||||
static final int CMD_START_PACKET_FILTERING = BASE + 84;
|
static final int CMD_START_PACKET_FILTERING = BASE + 84;
|
||||||
/* Clear packet filter */
|
/* Clear packet filter */
|
||||||
static final int CMD_STOP_PACKET_FILTERING = BASE + 85;
|
static final int CMD_STOP_PACKET_FILTERING = BASE + 85;
|
||||||
/* Set suspend mode optimizations in the driver */
|
/* Enable suspend mode optimizations in the driver */
|
||||||
static final int CMD_SET_SUSPEND_OPTIMIZATIONS = BASE + 86;
|
static final int CMD_SET_SUSPEND_OPT_ENABLED = BASE + 86;
|
||||||
/* Clear suspend mode optimizations in the driver */
|
|
||||||
static final int CMD_CLEAR_SUSPEND_OPTIMIZATIONS = BASE + 87;
|
|
||||||
/* When there are no saved networks, we do a periodic scan to notify user of
|
/* When there are no saved networks, we do a periodic scan to notify user of
|
||||||
* an open network */
|
* an open network */
|
||||||
static final int CMD_NO_NETWORKS_PERIODIC_SCAN = BASE + 88;
|
static final int CMD_NO_NETWORKS_PERIODIC_SCAN = BASE + 88;
|
||||||
@@ -386,8 +380,19 @@ public class WifiStateMachine extends StateMachine {
|
|||||||
*/
|
*/
|
||||||
private static final int DEFAULT_MAX_DHCP_RETRIES = 9;
|
private static final int DEFAULT_MAX_DHCP_RETRIES = 9;
|
||||||
|
|
||||||
/* Tracks if power save is enabled in driver */
|
/* Tracks if suspend optimizations need to be disabled by DHCP,
|
||||||
private boolean mPowerSaveEnabled = true;;
|
* screen or due to high perf mode.
|
||||||
|
* When any of them needs to disable it, we keep the suspend optimizations
|
||||||
|
* disabled
|
||||||
|
*/
|
||||||
|
private int mSuspendOptNeedsDisabled = 0;
|
||||||
|
|
||||||
|
private static final int SUSPEND_DUE_TO_DHCP = 1;
|
||||||
|
private static final int SUSPEND_DUE_TO_HIGH_PERF = 1<<1;
|
||||||
|
private static final int SUSPEND_DUE_TO_SCREEN = 1<<2;
|
||||||
|
|
||||||
|
/* Tracks if user has enabled suspend optimizations through settings */
|
||||||
|
private AtomicBoolean mUserWantsSuspendOpt = new AtomicBoolean(true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default framework scan interval in milliseconds. This is used in the scenario in which
|
* Default framework scan interval in milliseconds. This is used in the scenario in which
|
||||||
@@ -599,7 +604,7 @@ public class WifiStateMachine extends StateMachine {
|
|||||||
mPrimaryDeviceType = mContext.getResources().getString(
|
mPrimaryDeviceType = mContext.getResources().getString(
|
||||||
com.android.internal.R.string.config_wifi_p2p_device_type);
|
com.android.internal.R.string.config_wifi_p2p_device_type);
|
||||||
|
|
||||||
mSuspendOptEnabled.set(Settings.Secure.getInt(mContext.getContentResolver(),
|
mUserWantsSuspendOpt.set(Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
Settings.Secure.WIFI_SUSPEND_OPTIMIZATIONS_ENABLED, 1) == 1);
|
Settings.Secure.WIFI_SUSPEND_OPTIMIZATIONS_ENABLED, 1) == 1);
|
||||||
|
|
||||||
mContext.registerReceiver(
|
mContext.registerReceiver(
|
||||||
@@ -637,20 +642,20 @@ public class WifiStateMachine extends StateMachine {
|
|||||||
enableBackgroundScanCommand(false);
|
enableBackgroundScanCommand(false);
|
||||||
}
|
}
|
||||||
enableAllNetworks();
|
enableAllNetworks();
|
||||||
if (mSuspendOptEnabled.get()) {
|
if (mUserWantsSuspendOpt.get()) {
|
||||||
if (DBG) log("Clear suspend optimizations");
|
if (DBG) log("Clear suspend optimizations");
|
||||||
sendMessage(CMD_CLEAR_SUSPEND_OPTIMIZATIONS);
|
sendMessage(obtainMessage(CMD_SET_SUSPEND_OPT_ENABLED, 0, 0));
|
||||||
}
|
}
|
||||||
} else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
|
} else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
|
||||||
enableRssiPolling(false);
|
enableRssiPolling(false);
|
||||||
if (mBackgroundScanSupported) {
|
if (mBackgroundScanSupported) {
|
||||||
enableBackgroundScanCommand(true);
|
enableBackgroundScanCommand(true);
|
||||||
}
|
}
|
||||||
if (mSuspendOptEnabled.get()) {
|
if (mUserWantsSuspendOpt.get()) {
|
||||||
if (DBG) log("Enable suspend optimizations");
|
if (DBG) log("Enable suspend optimizations");
|
||||||
//Allow 2s for suspend optimizations to be set
|
//Allow 2s for suspend optimizations to be set
|
||||||
mSuspendWakeLock.acquire(2000);
|
mSuspendWakeLock.acquire(2000);
|
||||||
sendMessage(CMD_SET_SUSPEND_OPTIMIZATIONS);
|
sendMessage(obtainMessage(CMD_SET_SUSPEND_OPT_ENABLED, 1, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -671,7 +676,7 @@ public class WifiStateMachine extends StateMachine {
|
|||||||
new ContentObserver(getHandler()) {
|
new ContentObserver(getHandler()) {
|
||||||
@Override
|
@Override
|
||||||
public void onChange(boolean selfChange) {
|
public void onChange(boolean selfChange) {
|
||||||
mSuspendOptEnabled.set(Settings.Secure.getInt(mContext.getContentResolver(),
|
mUserWantsSuspendOpt.set(Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
Settings.Secure.WIFI_SUSPEND_OPTIMIZATIONS_ENABLED, 1) == 1);
|
Settings.Secure.WIFI_SUSPEND_OPTIMIZATIONS_ENABLED, 1) == 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1172,8 +1177,8 @@ public class WifiStateMachine extends StateMachine {
|
|||||||
sb.append("mLastNetworkId ").append(mLastNetworkId).append(LS);
|
sb.append("mLastNetworkId ").append(mLastNetworkId).append(LS);
|
||||||
sb.append("mReconnectCount ").append(mReconnectCount).append(LS);
|
sb.append("mReconnectCount ").append(mReconnectCount).append(LS);
|
||||||
sb.append("mIsScanMode ").append(mIsScanMode).append(LS);
|
sb.append("mIsScanMode ").append(mIsScanMode).append(LS);
|
||||||
sb.append("mHighPerfMode").append(mHighPerfMode).append(LS);
|
sb.append("mUserWantsSuspendOpt ").append(mUserWantsSuspendOpt).append(LS);
|
||||||
sb.append("mSuspendOptEnabled").append(mSuspendOptEnabled).append(LS);
|
sb.append("mSuspendOptNeedsDisabled ").append(mSuspendOptNeedsDisabled).append(LS);
|
||||||
sb.append("Supplicant status").append(LS)
|
sb.append("Supplicant status").append(LS)
|
||||||
.append(mWifiNative.status()).append(LS).append(LS);
|
.append(mWifiNative.status()).append(LS).append(LS);
|
||||||
|
|
||||||
@@ -1191,8 +1196,7 @@ public class WifiStateMachine extends StateMachine {
|
|||||||
case CMD_START_DRIVER:
|
case CMD_START_DRIVER:
|
||||||
case CMD_SET_SCAN_MODE:
|
case CMD_SET_SCAN_MODE:
|
||||||
case CMD_SET_HIGH_PERF_MODE:
|
case CMD_SET_HIGH_PERF_MODE:
|
||||||
case CMD_SET_SUSPEND_OPTIMIZATIONS:
|
case CMD_SET_SUSPEND_OPT_ENABLED:
|
||||||
case CMD_CLEAR_SUSPEND_OPTIMIZATIONS:
|
|
||||||
case CMD_ENABLE_BACKGROUND_SCAN:
|
case CMD_ENABLE_BACKGROUND_SCAN:
|
||||||
case CMD_ENABLE_ALL_NETWORKS:
|
case CMD_ENABLE_ALL_NETWORKS:
|
||||||
return false;
|
return false;
|
||||||
@@ -1324,6 +1328,32 @@ public class WifiStateMachine extends StateMachine {
|
|||||||
setFrequencyBand(band, false);
|
setFrequencyBand(band, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setSuspendOptimizationsNative(int reason, boolean enabled) {
|
||||||
|
if (DBG) log("setSuspendOptimizationsNative: " + reason + " " + enabled);
|
||||||
|
if (enabled) {
|
||||||
|
mSuspendOptNeedsDisabled &= ~reason;
|
||||||
|
/* None of dhcp, screen or highperf need it disabled and user wants it enabled */
|
||||||
|
if (mSuspendOptNeedsDisabled == 0 && mUserWantsSuspendOpt.get()) {
|
||||||
|
mWifiNative.setSuspendOptimizations(true);
|
||||||
|
if (DBG) log("Enabled, mSuspendOptNeedsDisabled " + mSuspendOptNeedsDisabled);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mSuspendOptNeedsDisabled |= reason;
|
||||||
|
mWifiNative.setSuspendOptimizations(false);
|
||||||
|
if (DBG) log("Disabled, mSuspendOptNeedsDisabled " + mSuspendOptNeedsDisabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setSuspendOptimizations(int reason, boolean enabled) {
|
||||||
|
if (DBG) log("setSuspendOptimizations: " + reason + " " + enabled);
|
||||||
|
if (enabled) {
|
||||||
|
mSuspendOptNeedsDisabled &= ~reason;
|
||||||
|
} else {
|
||||||
|
mSuspendOptNeedsDisabled |= reason;
|
||||||
|
}
|
||||||
|
if (DBG) log("mSuspendOptNeedsDisabled " + mSuspendOptNeedsDisabled);
|
||||||
|
}
|
||||||
|
|
||||||
private void setWifiState(int wifiState) {
|
private void setWifiState(int wifiState) {
|
||||||
final int previousWifiState = mWifiState.get();
|
final int previousWifiState = mWifiState.get();
|
||||||
|
|
||||||
@@ -1736,18 +1766,16 @@ public class WifiStateMachine extends StateMachine {
|
|||||||
mWifiNative.BLUETOOTH_COEXISTENCE_MODE_DISABLED);
|
mWifiNative.BLUETOOTH_COEXISTENCE_MODE_DISABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Disable power save during DHCP */
|
/* Disable power save and suspend optimizations during DHCP */
|
||||||
if (mPowerSaveEnabled) {
|
mWifiNative.setPowerSave(false);
|
||||||
mPowerSaveEnabled = false;
|
setSuspendOptimizationsNative(SUSPEND_DUE_TO_DHCP, false);
|
||||||
mWifiNative.setPowerSave(mPowerSaveEnabled);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void handlePostDhcpSetup() {
|
void handlePostDhcpSetup() {
|
||||||
/* Restore power save */
|
/* Restore power save and suspend optimizations */
|
||||||
mPowerSaveEnabled = true;
|
mWifiNative.setPowerSave(true);
|
||||||
mWifiNative.setPowerSave(mPowerSaveEnabled);
|
setSuspendOptimizationsNative(SUSPEND_DUE_TO_DHCP, true);
|
||||||
|
|
||||||
// Set the coexistence mode back to its default value
|
// Set the coexistence mode back to its default value
|
||||||
mWifiNative.setBluetoothCoexistenceMode(
|
mWifiNative.setBluetoothCoexistenceMode(
|
||||||
@@ -1880,7 +1908,11 @@ public class WifiStateMachine extends StateMachine {
|
|||||||
mEnableBackgroundScan = (message.arg1 == 1);
|
mEnableBackgroundScan = (message.arg1 == 1);
|
||||||
break;
|
break;
|
||||||
case CMD_SET_HIGH_PERF_MODE:
|
case CMD_SET_HIGH_PERF_MODE:
|
||||||
mHighPerfMode = (message.arg1 == 1);
|
if (message.arg1 == 1) {
|
||||||
|
setSuspendOptimizations(SUSPEND_DUE_TO_HIGH_PERF, false);
|
||||||
|
} else {
|
||||||
|
setSuspendOptimizations(SUSPEND_DUE_TO_HIGH_PERF, true);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
/* Discard */
|
/* Discard */
|
||||||
case CMD_LOAD_DRIVER:
|
case CMD_LOAD_DRIVER:
|
||||||
@@ -1927,14 +1959,18 @@ public class WifiStateMachine extends StateMachine {
|
|||||||
case CMD_RESPONSE_AP_CONFIG:
|
case CMD_RESPONSE_AP_CONFIG:
|
||||||
case WifiWatchdogStateMachine.POOR_LINK_DETECTED:
|
case WifiWatchdogStateMachine.POOR_LINK_DETECTED:
|
||||||
case WifiWatchdogStateMachine.GOOD_LINK_DETECTED:
|
case WifiWatchdogStateMachine.GOOD_LINK_DETECTED:
|
||||||
case CMD_CLEAR_SUSPEND_OPTIMIZATIONS:
|
|
||||||
case CMD_NO_NETWORKS_PERIODIC_SCAN:
|
case CMD_NO_NETWORKS_PERIODIC_SCAN:
|
||||||
break;
|
break;
|
||||||
case DhcpStateMachine.CMD_ON_QUIT:
|
case DhcpStateMachine.CMD_ON_QUIT:
|
||||||
mDhcpStateMachine = null;
|
mDhcpStateMachine = null;
|
||||||
break;
|
break;
|
||||||
case CMD_SET_SUSPEND_OPTIMIZATIONS:
|
case CMD_SET_SUSPEND_OPT_ENABLED:
|
||||||
mSuspendWakeLock.release();
|
if (message.arg1 == 1) {
|
||||||
|
mSuspendWakeLock.release();
|
||||||
|
setSuspendOptimizations(SUSPEND_DUE_TO_SCREEN, true);
|
||||||
|
} else {
|
||||||
|
setSuspendOptimizations(SUSPEND_DUE_TO_SCREEN, false);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case WifiMonitor.DRIVER_HUNG_EVENT:
|
case WifiMonitor.DRIVER_HUNG_EVENT:
|
||||||
setWifiEnabled(false);
|
setWifiEnabled(false);
|
||||||
@@ -2670,7 +2706,7 @@ public class WifiStateMachine extends StateMachine {
|
|||||||
mWifiNative.stopFilteringMulticastV4Packets();
|
mWifiNative.stopFilteringMulticastV4Packets();
|
||||||
}
|
}
|
||||||
|
|
||||||
mWifiNative.setPowerSave(mPowerSaveEnabled);
|
mWifiNative.setPowerSave(true);
|
||||||
|
|
||||||
if (mIsScanMode) {
|
if (mIsScanMode) {
|
||||||
mWifiNative.setScanResultHandling(SCAN_ONLY_MODE);
|
mWifiNative.setScanResultHandling(SCAN_ONLY_MODE);
|
||||||
@@ -2797,20 +2833,19 @@ public class WifiStateMachine extends StateMachine {
|
|||||||
loge("Illegal arugments to CMD_STOP_PACKET_FILTERING");
|
loge("Illegal arugments to CMD_STOP_PACKET_FILTERING");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CMD_SET_SUSPEND_OPTIMIZATIONS:
|
case CMD_SET_SUSPEND_OPT_ENABLED:
|
||||||
if (!mHighPerfMode) {
|
if (message.arg1 == 1) {
|
||||||
mWifiNative.setSuspendOptimizations(true);
|
setSuspendOptimizationsNative(SUSPEND_DUE_TO_SCREEN, true);
|
||||||
|
mSuspendWakeLock.release();
|
||||||
|
} else {
|
||||||
|
setSuspendOptimizationsNative(SUSPEND_DUE_TO_SCREEN, false);
|
||||||
}
|
}
|
||||||
mSuspendWakeLock.release();
|
|
||||||
break;
|
|
||||||
case CMD_CLEAR_SUSPEND_OPTIMIZATIONS:
|
|
||||||
mWifiNative.setSuspendOptimizations(false);
|
|
||||||
break;
|
break;
|
||||||
case CMD_SET_HIGH_PERF_MODE:
|
case CMD_SET_HIGH_PERF_MODE:
|
||||||
mHighPerfMode = (message.arg1 == 1);
|
if (message.arg1 == 1) {
|
||||||
if (mHighPerfMode) {
|
setSuspendOptimizationsNative(SUSPEND_DUE_TO_HIGH_PERF, false);
|
||||||
//Disable any suspend optimizations
|
} else {
|
||||||
mWifiNative.setSuspendOptimizations(false);
|
setSuspendOptimizationsNative(SUSPEND_DUE_TO_HIGH_PERF, true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user