Merge change 1881 into donut
* changes: WifiService: Wifi power management change
This commit is contained in:
@@ -1449,10 +1449,12 @@ public class WifiService extends IWifiManager.Stub {
|
|||||||
Settings.System.getInt(mContext.getContentResolver(),
|
Settings.System.getInt(mContext.getContentResolver(),
|
||||||
Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0);
|
Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0);
|
||||||
if (action.equals(Intent.ACTION_SCREEN_ON)) {
|
if (action.equals(Intent.ACTION_SCREEN_ON)) {
|
||||||
|
Log.d(TAG, "ACTION_SCREEN_ON");
|
||||||
mAlarmManager.cancel(mIdleIntent);
|
mAlarmManager.cancel(mIdleIntent);
|
||||||
mDeviceIdle = false;
|
mDeviceIdle = false;
|
||||||
mScreenOff = false;
|
mScreenOff = false;
|
||||||
} else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
|
} else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
|
||||||
|
Log.d(TAG, "ACTION_SCREEN_OFF");
|
||||||
mScreenOff = true;
|
mScreenOff = true;
|
||||||
/*
|
/*
|
||||||
* Set a timer to put Wi-Fi to sleep, but only if the screen is off
|
* 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).
|
* or plugged in to AC).
|
||||||
*/
|
*/
|
||||||
if (!shouldWifiStayAwake(stayAwakeConditions, mPluggedType)) {
|
if (!shouldWifiStayAwake(stayAwakeConditions, mPluggedType)) {
|
||||||
|
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;
|
long triggerTime = System.currentTimeMillis() + idleMillis;
|
||||||
|
Log.d(TAG, "setting ACTION_DEVICE_IDLE timer for " + idleMillis + "ms");
|
||||||
mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerTime, mIdleIntent);
|
mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerTime, mIdleIntent);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/* we can return now -- there's nothing to do until we get the idle intent back */
|
/* we can return now -- there's nothing to do until we get the idle intent back */
|
||||||
return;
|
return;
|
||||||
} else if (action.equals(ACTION_DEVICE_IDLE)) {
|
} else if (action.equals(ACTION_DEVICE_IDLE)) {
|
||||||
|
Log.d(TAG, "got ACTION_DEVICE_IDLE");
|
||||||
mDeviceIdle = true;
|
mDeviceIdle = true;
|
||||||
} else if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
|
} else if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
|
||||||
/*
|
/*
|
||||||
@@ -1477,9 +1487,11 @@ public class WifiService extends IWifiManager.Stub {
|
|||||||
* the already-set timer.
|
* the already-set timer.
|
||||||
*/
|
*/
|
||||||
int pluggedType = intent.getIntExtra("plugged", 0);
|
int pluggedType = intent.getIntExtra("plugged", 0);
|
||||||
|
Log.d(TAG, "ACTION_BATTERY_CHANGED pluggedType: " + pluggedType);
|
||||||
if (mScreenOff && shouldWifiStayAwake(stayAwakeConditions, mPluggedType) &&
|
if (mScreenOff && shouldWifiStayAwake(stayAwakeConditions, mPluggedType) &&
|
||||||
!shouldWifiStayAwake(stayAwakeConditions, pluggedType)) {
|
!shouldWifiStayAwake(stayAwakeConditions, pluggedType)) {
|
||||||
long triggerTime = System.currentTimeMillis() + idleMillis;
|
long triggerTime = System.currentTimeMillis() + idleMillis;
|
||||||
|
Log.d(TAG, "setting ACTION_DEVICE_IDLE timer for " + idleMillis + "ms");
|
||||||
mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerTime, mIdleIntent);
|
mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerTime, mIdleIntent);
|
||||||
mPluggedType = pluggedType;
|
mPluggedType = pluggedType;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -161,8 +161,8 @@ public class WifiStateTracker extends NetworkStateTracker {
|
|||||||
private WifiInfo mWifiInfo;
|
private WifiInfo mWifiInfo;
|
||||||
private List<ScanResult> mScanResults;
|
private List<ScanResult> mScanResults;
|
||||||
private WifiManager mWM;
|
private WifiManager mWM;
|
||||||
private boolean mHaveIPAddress;
|
private boolean mHaveIpAddress;
|
||||||
private boolean mObtainingIPAddress;
|
private boolean mObtainingIpAddress;
|
||||||
private boolean mTornDownByConnMgr;
|
private boolean mTornDownByConnMgr;
|
||||||
/**
|
/**
|
||||||
* A DISCONNECT event has been received, but processing it
|
* A DISCONNECT event has been received, but processing it
|
||||||
@@ -303,8 +303,8 @@ public class WifiStateTracker extends NetworkStateTracker {
|
|||||||
|
|
||||||
mWifiInfo = new WifiInfo();
|
mWifiInfo = new WifiInfo();
|
||||||
mWifiMonitor = new WifiMonitor(this);
|
mWifiMonitor = new WifiMonitor(this);
|
||||||
mHaveIPAddress = false;
|
mHaveIpAddress = false;
|
||||||
mObtainingIPAddress = false;
|
mObtainingIpAddress = false;
|
||||||
setTornDownByConnMgr(false);
|
setTornDownByConnMgr(false);
|
||||||
mDisconnectPending = false;
|
mDisconnectPending = false;
|
||||||
mScanResults = new ArrayList<ScanResult>();
|
mScanResults = new ArrayList<ScanResult>();
|
||||||
@@ -443,6 +443,14 @@ public class WifiStateTracker extends NetworkStateTracker {
|
|||||||
return mWifiInfo.getSupplicantState() == SupplicantState.COMPLETED;
|
return mWifiInfo.getSupplicantState() == SupplicantState.COMPLETED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Report whether the Wi-Fi connection has successfully acquired an IP address.
|
||||||
|
* @return {@code true} if the Wi-Fi connection has been assigned an IP address.
|
||||||
|
*/
|
||||||
|
public boolean hasIpAddress() {
|
||||||
|
return mHaveIpAddress;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send the tracker a notification that a user-entered password key
|
* Send the tracker a notification that a user-entered password key
|
||||||
* may be incorrect (i.e., caused authentication to fail).
|
* may be incorrect (i.e., caused authentication to fail).
|
||||||
@@ -724,7 +732,7 @@ public class WifiStateTracker extends NetworkStateTracker {
|
|||||||
intent.putExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED, true);
|
intent.putExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED, true);
|
||||||
mContext.sendBroadcast(intent);
|
mContext.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
if (supplState == SupplicantState.COMPLETED && mHaveIPAddress) {
|
if (supplState == SupplicantState.COMPLETED && mHaveIpAddress) {
|
||||||
setDetailedState(DetailedState.CONNECTED);
|
setDetailedState(DetailedState.CONNECTED);
|
||||||
} else {
|
} else {
|
||||||
setDetailedState(WifiInfo.getDetailedStateOf(supplState));
|
setDetailedState(WifiInfo.getDetailedStateOf(supplState));
|
||||||
@@ -783,8 +791,8 @@ public class WifiStateTracker extends NetworkStateTracker {
|
|||||||
}
|
}
|
||||||
setDetailedState(DetailedState.DISCONNECTED);
|
setDetailedState(DetailedState.DISCONNECTED);
|
||||||
setSupplicantState(SupplicantState.UNINITIALIZED);
|
setSupplicantState(SupplicantState.UNINITIALIZED);
|
||||||
mHaveIPAddress = false;
|
mHaveIpAddress = false;
|
||||||
mObtainingIPAddress = false;
|
mObtainingIpAddress = false;
|
||||||
if (died) {
|
if (died) {
|
||||||
mWM.setWifiEnabled(false);
|
mWM.setWifiEnabled(false);
|
||||||
}
|
}
|
||||||
@@ -954,7 +962,7 @@ public class WifiStateTracker extends NetworkStateTracker {
|
|||||||
}
|
}
|
||||||
requestConnectionStatus(mWifiInfo);
|
requestConnectionStatus(mWifiInfo);
|
||||||
if (!(result.state == DetailedState.CONNECTED &&
|
if (!(result.state == DetailedState.CONNECTED &&
|
||||||
(!mHaveIPAddress || mDisconnectPending))) {
|
(!mHaveIpAddress || mDisconnectPending))) {
|
||||||
setDetailedState(result.state);
|
setDetailedState(result.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -983,7 +991,7 @@ public class WifiStateTracker extends NetworkStateTracker {
|
|||||||
mLastBssid = result.BSSID;
|
mLastBssid = result.BSSID;
|
||||||
mLastSsid = mWifiInfo.getSSID();
|
mLastSsid = mWifiInfo.getSSID();
|
||||||
mLastNetworkId = result.networkId;
|
mLastNetworkId = result.networkId;
|
||||||
if (mHaveIPAddress) {
|
if (mHaveIpAddress) {
|
||||||
setDetailedState(DetailedState.CONNECTED);
|
setDetailedState(DetailedState.CONNECTED);
|
||||||
} else {
|
} else {
|
||||||
setDetailedState(DetailedState.OBTAINING_IPADDR);
|
setDetailedState(DetailedState.OBTAINING_IPADDR);
|
||||||
@@ -1051,8 +1059,8 @@ public class WifiStateTracker extends NetworkStateTracker {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mReconnectCount = 0;
|
mReconnectCount = 0;
|
||||||
mHaveIPAddress = true;
|
mHaveIpAddress = true;
|
||||||
mObtainingIPAddress = false;
|
mObtainingIpAddress = false;
|
||||||
mWifiInfo.setIpAddress(mDhcpInfo.ipAddress);
|
mWifiInfo.setIpAddress(mDhcpInfo.ipAddress);
|
||||||
mLastSignalLevel = -1; // force update of signal strength
|
mLastSignalLevel = -1; // force update of signal strength
|
||||||
if (mNetworkInfo.getDetailedState() != DetailedState.CONNECTED) {
|
if (mNetworkInfo.getDetailedState() != DetailedState.CONNECTED) {
|
||||||
@@ -1078,9 +1086,9 @@ public class WifiStateTracker extends NetworkStateTracker {
|
|||||||
// [ 0- 0] Interface configuration succeeded (1) or failed (0)
|
// [ 0- 0] Interface configuration succeeded (1) or failed (0)
|
||||||
EventLog.writeEvent(EVENTLOG_INTERFACE_CONFIGURATION_STATE_CHANGED, 0);
|
EventLog.writeEvent(EVENTLOG_INTERFACE_CONFIGURATION_STATE_CHANGED, 0);
|
||||||
|
|
||||||
mHaveIPAddress = false;
|
mHaveIpAddress = false;
|
||||||
mWifiInfo.setIpAddress(0);
|
mWifiInfo.setIpAddress(0);
|
||||||
mObtainingIPAddress = false;
|
mObtainingIpAddress = false;
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
WifiNative.disconnectCommand();
|
WifiNative.disconnectCommand();
|
||||||
}
|
}
|
||||||
@@ -1156,18 +1164,18 @@ public class WifiStateTracker extends NetworkStateTracker {
|
|||||||
setPollTimer();
|
setPollTimer();
|
||||||
mLastSignalLevel = -1;
|
mLastSignalLevel = -1;
|
||||||
if (!mUseStaticIp) {
|
if (!mUseStaticIp) {
|
||||||
if (!mHaveIPAddress && !mObtainingIPAddress) {
|
if (!mHaveIpAddress && !mObtainingIpAddress) {
|
||||||
mObtainingIPAddress = true;
|
mObtainingIpAddress = true;
|
||||||
mDhcpTarget.sendEmptyMessage(EVENT_DHCP_START);
|
mDhcpTarget.sendEmptyMessage(EVENT_DHCP_START);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int event;
|
int event;
|
||||||
if (NetworkUtils.configureInterface(mInterfaceName, mDhcpInfo)) {
|
if (NetworkUtils.configureInterface(mInterfaceName, mDhcpInfo)) {
|
||||||
mHaveIPAddress = true;
|
mHaveIpAddress = true;
|
||||||
event = EVENT_INTERFACE_CONFIGURATION_SUCCEEDED;
|
event = EVENT_INTERFACE_CONFIGURATION_SUCCEEDED;
|
||||||
if (LOCAL_LOGD) Log.v(TAG, "Static IP configuration succeeded");
|
if (LOCAL_LOGD) Log.v(TAG, "Static IP configuration succeeded");
|
||||||
} else {
|
} else {
|
||||||
mHaveIPAddress = false;
|
mHaveIpAddress = false;
|
||||||
event = EVENT_INTERFACE_CONFIGURATION_FAILED;
|
event = EVENT_INTERFACE_CONFIGURATION_FAILED;
|
||||||
if (LOCAL_LOGD) Log.v(TAG, "Static IP configuration failed");
|
if (LOCAL_LOGD) Log.v(TAG, "Static IP configuration failed");
|
||||||
}
|
}
|
||||||
@@ -1200,8 +1208,8 @@ public class WifiStateTracker extends NetworkStateTracker {
|
|||||||
* using the interface, stopping DHCP, and disabling the interface.
|
* using the interface, stopping DHCP, and disabling the interface.
|
||||||
*/
|
*/
|
||||||
public void resetInterface() {
|
public void resetInterface() {
|
||||||
mHaveIPAddress = false;
|
mHaveIpAddress = false;
|
||||||
mObtainingIPAddress = false;
|
mObtainingIpAddress = false;
|
||||||
mWifiInfo.setIpAddress(0);
|
mWifiInfo.setIpAddress(0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1612,8 +1620,8 @@ public class WifiStateTracker extends NetworkStateTracker {
|
|||||||
}
|
}
|
||||||
sb.append(LS).append(mWifiInfo).append(LS);
|
sb.append(LS).append(mWifiInfo).append(LS);
|
||||||
sb.append(mDhcpInfo).append(LS);
|
sb.append(mDhcpInfo).append(LS);
|
||||||
sb.append("haveIpAddress=").append(mHaveIPAddress).
|
sb.append("haveIpAddress=").append(mHaveIpAddress).
|
||||||
append(", obtainingIpAddress=").append(mObtainingIPAddress).
|
append(", obtainingIpAddress=").append(mObtainingIpAddress).
|
||||||
append(", scanModeActive=").append(mIsScanModeActive).append(LS).
|
append(", scanModeActive=").append(mIsScanModeActive).append(LS).
|
||||||
append("lastSignalLevel=").append(mLastSignalLevel).
|
append("lastSignalLevel=").append(mLastSignalLevel).
|
||||||
append(", explicitlyDisabled=").append(mTornDownByConnMgr);
|
append(", explicitlyDisabled=").append(mTornDownByConnMgr);
|
||||||
|
|||||||
Reference in New Issue
Block a user