diff options
-rw-r--r-- | wifi/java/android/net/wifi/WifiStateMachine.java | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java index 2903faa..c4519be 100644 --- a/wifi/java/android/net/wifi/WifiStateMachine.java +++ b/wifi/java/android/net/wifi/WifiStateMachine.java @@ -208,6 +208,8 @@ public class WifiStateMachine extends StateMachine { private AlarmManager mAlarmManager; private PendingIntent mScanIntent; + private PendingIntent mDriverStopIntent; + /* Tracks current frequency mode */ private AtomicInteger mFrequencyBand = new AtomicInteger(WifiManager.WIFI_FREQUENCY_BAND_AUTO); @@ -520,6 +522,11 @@ public class WifiStateMachine extends StateMachine { private static final String ACTION_START_SCAN = "com.android.server.WifiManager.action.START_SCAN"; + private static final String DELAYED_STOP_COUNTER = "DelayedStopCounter"; + private static final int DRIVER_STOP_REQUEST = 0; + private static final String ACTION_DELAYED_DRIVER_STOP = + "com.android.server.WifiManager.action.DELAYED_DRIVER_STOP"; + /** * Keep track of whether WIFI is running. */ @@ -637,6 +644,15 @@ public class WifiStateMachine extends StateMachine { } } }; + mContext.registerReceiver( + new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + int counter = intent.getIntExtra(DELAYED_STOP_COUNTER, 0); + sendMessage(obtainMessage(CMD_DELAYED_STOP_DRIVER, counter, 0)); + } + }, + new IntentFilter(ACTION_DELAYED_DRIVER_STOP)); mScanResultCache = new LruCache<String, ScanResult>(SCAN_RESULT_CACHE_SIZE); @@ -2666,18 +2682,26 @@ public class WifiStateMachine extends StateMachine { sendMessage(obtainMessage(CMD_DELAYED_STOP_DRIVER, mDelayedStopCounter, 0)); } else { /* send regular delayed shut down */ - sendMessageDelayed(obtainMessage(CMD_DELAYED_STOP_DRIVER, - mDelayedStopCounter, 0), mDriverStopDelayMs); + Intent driverStopIntent = new Intent(ACTION_DELAYED_DRIVER_STOP, null); + driverStopIntent.putExtra(DELAYED_STOP_COUNTER, mDelayedStopCounter); + mDriverStopIntent = PendingIntent.getBroadcast(mContext, + DRIVER_STOP_REQUEST, driverStopIntent, + PendingIntent.FLAG_UPDATE_CURRENT); + + mAlarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + + mDriverStopDelayMs, mDriverStopIntent); } break; case CMD_START_DRIVER: if (mInDelayedStop) { mInDelayedStop = false; mDelayedStopCounter++; + mAlarmManager.cancel(mDriverStopIntent); if (DBG) log("Delayed stop ignored due to start"); } break; case CMD_DELAYED_STOP_DRIVER: + if (DBG) log("delayed stop " + message.arg1 + " " + mDelayedStopCounter); if (message.arg1 != mDelayedStopCounter) break; if (getCurrentState() != mDisconnectedState) { mWifiNative.disconnect(); |