WifiService: Wifi power management change

Put Wifi into an idle state immediately if the screen is turned off and the Wifi interface has no IP address.
We will continue to keep Wifi up for 15 minutes in the case where the screen is turned off when Wifi is fully connected.
This will allow us to go into a low power mode faster when Wifi is not actively being used.
It also avoids bringing up Wifi if the user just turns on the screen for a few seconds to check the clock, etc.

Fixes bug b/1736920

Signed-off-by: Mike Lockwood <lockwood@android.com>
This commit is contained in:
Mike Lockwood
2009-05-18 14:14:15 -04:00
parent 6342d3936a
commit d9c32bc838
2 changed files with 43 additions and 23 deletions

View File

@@ -1449,10 +1449,12 @@ public class WifiService extends IWifiManager.Stub {
Settings.System.getInt(mContext.getContentResolver(),
Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0);
if (action.equals(Intent.ACTION_SCREEN_ON)) {
Log.d(TAG, "ACTION_SCREEN_ON");
mAlarmManager.cancel(mIdleIntent);
mDeviceIdle = false;
mScreenOff = false;
} else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
Log.d(TAG, "ACTION_SCREEN_OFF");
mScreenOff = true;
/*
* Set a timer to put Wi-Fi to sleep, but only if the screen is off
@@ -1461,12 +1463,20 @@ public class WifiService extends IWifiManager.Stub {
* or plugged in to AC).
*/
if (!shouldWifiStayAwake(stayAwakeConditions, mPluggedType)) {
long triggerTime = System.currentTimeMillis() + idleMillis;
mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerTime, mIdleIntent);
if (!mWifiStateTracker.hasIpAddress()) {
// do not keep Wifi awake when screen is off if Wifi is not fully active
mDeviceIdle = true;
updateWifiState();
} else {
long triggerTime = System.currentTimeMillis() + idleMillis;
Log.d(TAG, "setting ACTION_DEVICE_IDLE timer for " + idleMillis + "ms");
mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerTime, mIdleIntent);
}
}
/* we can return now -- there's nothing to do until we get the idle intent back */
return;
} else if (action.equals(ACTION_DEVICE_IDLE)) {
Log.d(TAG, "got ACTION_DEVICE_IDLE");
mDeviceIdle = true;
} else if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
/*
@@ -1477,9 +1487,11 @@ public class WifiService extends IWifiManager.Stub {
* the already-set timer.
*/
int pluggedType = intent.getIntExtra("plugged", 0);
Log.d(TAG, "ACTION_BATTERY_CHANGED pluggedType: " + pluggedType);
if (mScreenOff && shouldWifiStayAwake(stayAwakeConditions, mPluggedType) &&
!shouldWifiStayAwake(stayAwakeConditions, pluggedType)) {
long triggerTime = System.currentTimeMillis() + idleMillis;
Log.d(TAG, "setting ACTION_DEVICE_IDLE timer for " + idleMillis + "ms");
mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerTime, mIdleIntent);
mPluggedType = pluggedType;
return;