Loading services/java/com/android/server/WifiService.java +14 −31 Original line number Diff line number Diff line Loading @@ -921,18 +921,14 @@ public class WifiService extends IWifiManager.Stub { Slog.d(TAG, "ACTION_SCREEN_ON"); } mAlarmManager.cancel(mIdleIntent); mDeviceIdle = false; mScreenOff = false; // Once the screen is on, we are not keeping WIFI running // because of any locks so clear that tracking immediately. reportStartWorkSource(); evaluateTrafficStatsPolling(); mWifiStateMachine.enableRssiPolling(true); if (mBackgroundScanSupported) { mWifiStateMachine.enableBackgroundScanCommand(false); } mWifiStateMachine.enableAllNetworks(); updateWifiState(); setDeviceIdleAndUpdateWifi(false); } else if (action.equals(Intent.ACTION_SCREEN_OFF)) { if (DBG) { Slog.d(TAG, "ACTION_SCREEN_OFF"); Loading @@ -950,36 +946,17 @@ public class WifiService extends IWifiManager.Stub { * or plugged in to AC). */ if (!shouldWifiStayAwake(stayAwakeConditions, mPluggedType)) { WifiInfo info = mWifiStateMachine.syncRequestConnectionInfo(); if (info.getSupplicantState() != SupplicantState.COMPLETED) { // we used to go to sleep immediately, but this caused some race conditions // we don't have time to track down for this release. Delay instead, // but not as long as we would if connected (below) // TODO - fix the race conditions and switch back to the immediate turn-off long triggerTime = System.currentTimeMillis() + (2*60*1000); // 2 min if (DBG) { Slog.d(TAG, "setting ACTION_DEVICE_IDLE timer for 120,000 ms"); } mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerTime, mIdleIntent); // // do not keep Wifi awake when screen is off if Wifi is not associated // mDeviceIdle = true; // updateWifiState(); //Delayed shutdown if wifi is connected if (mNetworkInfo.getDetailedState() == DetailedState.CONNECTED) { if (DBG) Slog.d(TAG, "setting ACTION_DEVICE_IDLE: " + idleMillis + " ms"); mAlarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + idleMillis, mIdleIntent); } else { long triggerTime = System.currentTimeMillis() + idleMillis; if (DBG) { Slog.d(TAG, "setting ACTION_DEVICE_IDLE timer for " + idleMillis + "ms"); } mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerTime, mIdleIntent); setDeviceIdleAndUpdateWifi(true); } } } else if (action.equals(ACTION_DEVICE_IDLE)) { if (DBG) { Slog.d(TAG, "got ACTION_DEVICE_IDLE"); } mDeviceIdle = true; reportStartWorkSource(); updateWifiState(); setDeviceIdleAndUpdateWifi(true); } else if (action.equals(Intent.ACTION_BATTERY_CHANGED)) { /* * Set a timer to put Wi-Fi to sleep, but only if the screen is off Loading Loading @@ -1056,6 +1033,12 @@ public class WifiService extends IWifiManager.Stub { } }; private void setDeviceIdleAndUpdateWifi(boolean deviceIdle) { mDeviceIdle = deviceIdle; reportStartWorkSource(); updateWifiState(); } private synchronized void reportStartWorkSource() { mTmpWorkSource.clear(); if (mDeviceIdle) { Loading wifi/java/android/net/wifi/WifiStateMachine.java +37 −12 Original line number Diff line number Diff line Loading @@ -211,7 +211,7 @@ public class WifiStateMachine extends StateMachine { static final int CMD_STOP_SUPPLICANT = BASE + 12; /* Start the driver */ static final int CMD_START_DRIVER = BASE + 13; /* Start the driver */ /* Stop the driver */ static final int CMD_STOP_DRIVER = BASE + 14; /* Indicates Static IP succeded */ static final int CMD_STATIC_IP_SUCCESS = BASE + 15; Loading @@ -219,6 +219,9 @@ public class WifiStateMachine extends StateMachine { static final int CMD_STATIC_IP_FAILURE = BASE + 16; /* Indicates supplicant stop failed */ static final int CMD_STOP_SUPPLICANT_FAILED = BASE + 17; /* Delayed stop to avoid shutting down driver too quick*/ static final int CMD_DELAYED_STOP_DRIVER = BASE + 18; /* Start the soft access point */ static final int CMD_START_AP = BASE + 21; Loading Loading @@ -389,6 +392,13 @@ public class WifiStateMachine extends StateMachine { private static final int MIN_INTERVAL_ENABLE_ALL_NETWORKS_MS = 10 * 60 * 1000; /* 10 minutes */ private long mLastEnableAllNetworksTime; /** * Starting and shutting down driver too quick causes problems leading to driver * being in a bad state. Delay driver stop. */ private static final int DELAYED_DRIVER_STOP_MS = 2 * 60 * 1000; /* 2 minutes */ private int mDelayedStopCounter; private boolean mInDelayedStop = false; private static final int MIN_RSSI = -200; private static final int MAX_RSSI = 256; Loading Loading @@ -1780,6 +1790,7 @@ public class WifiStateMachine extends StateMachine { case CMD_STOP_SUPPLICANT_FAILED: case CMD_START_DRIVER: case CMD_STOP_DRIVER: case CMD_DELAYED_STOP_DRIVER: case CMD_START_AP: case CMD_START_AP_SUCCESS: case CMD_START_AP_FAILURE: Loading Loading @@ -2442,6 +2453,7 @@ public class WifiStateMachine extends StateMachine { EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); mIsRunning = true; mInDelayedStop = false; updateBatteryWorkSource(null); /** Loading Loading @@ -2521,6 +2533,30 @@ public class WifiStateMachine extends StateMachine { WifiNative.setBluetoothCoexistenceScanModeCommand(mBluetoothConnectionActive); break; case CMD_STOP_DRIVER: /* Already doing a delayed stop */ if (mInDelayedStop) { if (DBG) log("Already in delayed stop"); break; } mInDelayedStop = true; mDelayedStopCounter++; if (DBG) log("Delayed stop message " + mDelayedStopCounter); sendMessageDelayed(obtainMessage(CMD_DELAYED_STOP_DRIVER, mDelayedStopCounter, 0), DELAYED_DRIVER_STOP_MS); break; case CMD_START_DRIVER: if (mInDelayedStop) { mInDelayedStop = false; mDelayedStopCounter++; if (DBG) log("Delayed stop ignored due to start"); } break; case CMD_DELAYED_STOP_DRIVER: if (message.arg1 != mDelayedStopCounter) break; if (getCurrentState() != mDisconnectedState) { WifiNative.disconnectCommand(); handleNetworkDisconnect(); } mWakeLock.acquire(); WifiNative.stopDriverCommand(); transitionTo(mDriverStoppingState); Loading Loading @@ -2879,10 +2915,6 @@ public class WifiStateMachine extends StateMachine { /* Ignore */ case WifiMonitor.NETWORK_CONNECTION_EVENT: break; case CMD_STOP_DRIVER: sendMessage(CMD_DISCONNECT); deferMessage(message); break; case CMD_SET_SCAN_MODE: if (message.arg1 == SCAN_ONLY_MODE) { sendMessage(CMD_DISCONNECT); Loading Loading @@ -2937,10 +2969,6 @@ public class WifiStateMachine extends StateMachine { WifiNative.disconnectCommand(); transitionTo(mDisconnectingState); break; case CMD_STOP_DRIVER: sendMessage(CMD_DISCONNECT); deferMessage(message); break; case CMD_REQUEST_CM_WAKELOCK: checkAndSetConnectivityInstance(); mCm.requestNetworkTransitionWakelock(TAG); Loading Loading @@ -3036,9 +3064,6 @@ public class WifiStateMachine extends StateMachine { public boolean processMessage(Message message) { if (DBG) log(getName() + message.toString() + "\n"); switch (message.what) { case CMD_STOP_DRIVER: /* Stop driver only after disconnect handled */ deferMessage(message); break; case CMD_SET_SCAN_MODE: if (message.arg1 == SCAN_ONLY_MODE) { deferMessage(message); Loading Loading
services/java/com/android/server/WifiService.java +14 −31 Original line number Diff line number Diff line Loading @@ -921,18 +921,14 @@ public class WifiService extends IWifiManager.Stub { Slog.d(TAG, "ACTION_SCREEN_ON"); } mAlarmManager.cancel(mIdleIntent); mDeviceIdle = false; mScreenOff = false; // Once the screen is on, we are not keeping WIFI running // because of any locks so clear that tracking immediately. reportStartWorkSource(); evaluateTrafficStatsPolling(); mWifiStateMachine.enableRssiPolling(true); if (mBackgroundScanSupported) { mWifiStateMachine.enableBackgroundScanCommand(false); } mWifiStateMachine.enableAllNetworks(); updateWifiState(); setDeviceIdleAndUpdateWifi(false); } else if (action.equals(Intent.ACTION_SCREEN_OFF)) { if (DBG) { Slog.d(TAG, "ACTION_SCREEN_OFF"); Loading @@ -950,36 +946,17 @@ public class WifiService extends IWifiManager.Stub { * or plugged in to AC). */ if (!shouldWifiStayAwake(stayAwakeConditions, mPluggedType)) { WifiInfo info = mWifiStateMachine.syncRequestConnectionInfo(); if (info.getSupplicantState() != SupplicantState.COMPLETED) { // we used to go to sleep immediately, but this caused some race conditions // we don't have time to track down for this release. Delay instead, // but not as long as we would if connected (below) // TODO - fix the race conditions and switch back to the immediate turn-off long triggerTime = System.currentTimeMillis() + (2*60*1000); // 2 min if (DBG) { Slog.d(TAG, "setting ACTION_DEVICE_IDLE timer for 120,000 ms"); } mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerTime, mIdleIntent); // // do not keep Wifi awake when screen is off if Wifi is not associated // mDeviceIdle = true; // updateWifiState(); //Delayed shutdown if wifi is connected if (mNetworkInfo.getDetailedState() == DetailedState.CONNECTED) { if (DBG) Slog.d(TAG, "setting ACTION_DEVICE_IDLE: " + idleMillis + " ms"); mAlarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + idleMillis, mIdleIntent); } else { long triggerTime = System.currentTimeMillis() + idleMillis; if (DBG) { Slog.d(TAG, "setting ACTION_DEVICE_IDLE timer for " + idleMillis + "ms"); } mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerTime, mIdleIntent); setDeviceIdleAndUpdateWifi(true); } } } else if (action.equals(ACTION_DEVICE_IDLE)) { if (DBG) { Slog.d(TAG, "got ACTION_DEVICE_IDLE"); } mDeviceIdle = true; reportStartWorkSource(); updateWifiState(); setDeviceIdleAndUpdateWifi(true); } else if (action.equals(Intent.ACTION_BATTERY_CHANGED)) { /* * Set a timer to put Wi-Fi to sleep, but only if the screen is off Loading Loading @@ -1056,6 +1033,12 @@ public class WifiService extends IWifiManager.Stub { } }; private void setDeviceIdleAndUpdateWifi(boolean deviceIdle) { mDeviceIdle = deviceIdle; reportStartWorkSource(); updateWifiState(); } private synchronized void reportStartWorkSource() { mTmpWorkSource.clear(); if (mDeviceIdle) { Loading
wifi/java/android/net/wifi/WifiStateMachine.java +37 −12 Original line number Diff line number Diff line Loading @@ -211,7 +211,7 @@ public class WifiStateMachine extends StateMachine { static final int CMD_STOP_SUPPLICANT = BASE + 12; /* Start the driver */ static final int CMD_START_DRIVER = BASE + 13; /* Start the driver */ /* Stop the driver */ static final int CMD_STOP_DRIVER = BASE + 14; /* Indicates Static IP succeded */ static final int CMD_STATIC_IP_SUCCESS = BASE + 15; Loading @@ -219,6 +219,9 @@ public class WifiStateMachine extends StateMachine { static final int CMD_STATIC_IP_FAILURE = BASE + 16; /* Indicates supplicant stop failed */ static final int CMD_STOP_SUPPLICANT_FAILED = BASE + 17; /* Delayed stop to avoid shutting down driver too quick*/ static final int CMD_DELAYED_STOP_DRIVER = BASE + 18; /* Start the soft access point */ static final int CMD_START_AP = BASE + 21; Loading Loading @@ -389,6 +392,13 @@ public class WifiStateMachine extends StateMachine { private static final int MIN_INTERVAL_ENABLE_ALL_NETWORKS_MS = 10 * 60 * 1000; /* 10 minutes */ private long mLastEnableAllNetworksTime; /** * Starting and shutting down driver too quick causes problems leading to driver * being in a bad state. Delay driver stop. */ private static final int DELAYED_DRIVER_STOP_MS = 2 * 60 * 1000; /* 2 minutes */ private int mDelayedStopCounter; private boolean mInDelayedStop = false; private static final int MIN_RSSI = -200; private static final int MAX_RSSI = 256; Loading Loading @@ -1780,6 +1790,7 @@ public class WifiStateMachine extends StateMachine { case CMD_STOP_SUPPLICANT_FAILED: case CMD_START_DRIVER: case CMD_STOP_DRIVER: case CMD_DELAYED_STOP_DRIVER: case CMD_START_AP: case CMD_START_AP_SUCCESS: case CMD_START_AP_FAILURE: Loading Loading @@ -2442,6 +2453,7 @@ public class WifiStateMachine extends StateMachine { EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); mIsRunning = true; mInDelayedStop = false; updateBatteryWorkSource(null); /** Loading Loading @@ -2521,6 +2533,30 @@ public class WifiStateMachine extends StateMachine { WifiNative.setBluetoothCoexistenceScanModeCommand(mBluetoothConnectionActive); break; case CMD_STOP_DRIVER: /* Already doing a delayed stop */ if (mInDelayedStop) { if (DBG) log("Already in delayed stop"); break; } mInDelayedStop = true; mDelayedStopCounter++; if (DBG) log("Delayed stop message " + mDelayedStopCounter); sendMessageDelayed(obtainMessage(CMD_DELAYED_STOP_DRIVER, mDelayedStopCounter, 0), DELAYED_DRIVER_STOP_MS); break; case CMD_START_DRIVER: if (mInDelayedStop) { mInDelayedStop = false; mDelayedStopCounter++; if (DBG) log("Delayed stop ignored due to start"); } break; case CMD_DELAYED_STOP_DRIVER: if (message.arg1 != mDelayedStopCounter) break; if (getCurrentState() != mDisconnectedState) { WifiNative.disconnectCommand(); handleNetworkDisconnect(); } mWakeLock.acquire(); WifiNative.stopDriverCommand(); transitionTo(mDriverStoppingState); Loading Loading @@ -2879,10 +2915,6 @@ public class WifiStateMachine extends StateMachine { /* Ignore */ case WifiMonitor.NETWORK_CONNECTION_EVENT: break; case CMD_STOP_DRIVER: sendMessage(CMD_DISCONNECT); deferMessage(message); break; case CMD_SET_SCAN_MODE: if (message.arg1 == SCAN_ONLY_MODE) { sendMessage(CMD_DISCONNECT); Loading Loading @@ -2937,10 +2969,6 @@ public class WifiStateMachine extends StateMachine { WifiNative.disconnectCommand(); transitionTo(mDisconnectingState); break; case CMD_STOP_DRIVER: sendMessage(CMD_DISCONNECT); deferMessage(message); break; case CMD_REQUEST_CM_WAKELOCK: checkAndSetConnectivityInstance(); mCm.requestNetworkTransitionWakelock(TAG); Loading Loading @@ -3036,9 +3064,6 @@ public class WifiStateMachine extends StateMachine { public boolean processMessage(Message message) { if (DBG) log(getName() + message.toString() + "\n"); switch (message.what) { case CMD_STOP_DRIVER: /* Stop driver only after disconnect handled */ deferMessage(message); break; case CMD_SET_SCAN_MODE: if (message.arg1 == SCAN_ONLY_MODE) { deferMessage(message); Loading