@@ -209,6 +209,8 @@ public class WifiStateMachine extends StateMachine {
209209
210210 private AlarmManager mAlarmManager ;
211211 private PendingIntent mScanIntent ;
212+ private PendingIntent mDriverStopIntent ;
213+
212214 /* Tracks current frequency mode */
213215 private AtomicInteger mFrequencyBand = new AtomicInteger (WifiManager .WIFI_FREQUENCY_BAND_AUTO );
214216
@@ -521,6 +523,11 @@ private class TetherStateChange {
521523 private static final String ACTION_START_SCAN =
522524 "com.android.server.WifiManager.action.START_SCAN" ;
523525
526+ private static final String DELAYED_STOP_COUNTER = "DelayedStopCounter" ;
527+ private static final int DRIVER_STOP_REQUEST = 0 ;
528+ private static final String ACTION_DELAYED_DRIVER_STOP =
529+ "com.android.server.WifiManager.action.DELAYED_DRIVER_STOP" ;
530+
524531 /**
525532 * Keep track of whether WIFI is running.
526533 */
@@ -641,6 +648,15 @@ public void onReceive(Context context, Intent intent) {
641648 }
642649 }
643650 };
651+ mContext .registerReceiver (
652+ new BroadcastReceiver () {
653+ @ Override
654+ public void onReceive (Context context , Intent intent ) {
655+ int counter = intent .getIntExtra (DELAYED_STOP_COUNTER , 0 );
656+ sendMessage (obtainMessage (CMD_DELAYED_STOP_DRIVER , counter , 0 ));
657+ }
658+ },
659+ new IntentFilter (ACTION_DELAYED_DRIVER_STOP ));
644660
645661 mScanResultCache = new LruCache <String , ScanResult >(SCAN_RESULT_CACHE_SIZE );
646662
@@ -2701,18 +2717,26 @@ public boolean processMessage(Message message) {
27012717 sendMessage (obtainMessage (CMD_DELAYED_STOP_DRIVER , mDelayedStopCounter , 0 ));
27022718 } else {
27032719 /* send regular delayed shut down */
2704- sendMessageDelayed (obtainMessage (CMD_DELAYED_STOP_DRIVER ,
2705- mDelayedStopCounter , 0 ), mDriverStopDelayMs );
2720+ Intent driverStopIntent = new Intent (ACTION_DELAYED_DRIVER_STOP , null );
2721+ driverStopIntent .putExtra (DELAYED_STOP_COUNTER , mDelayedStopCounter );
2722+ mDriverStopIntent = PendingIntent .getBroadcast (mContext ,
2723+ DRIVER_STOP_REQUEST , driverStopIntent ,
2724+ PendingIntent .FLAG_UPDATE_CURRENT );
2725+
2726+ mAlarmManager .set (AlarmManager .RTC_WAKEUP , System .currentTimeMillis ()
2727+ + mDriverStopDelayMs , mDriverStopIntent );
27062728 }
27072729 break ;
27082730 case CMD_START_DRIVER :
27092731 if (mInDelayedStop ) {
27102732 mInDelayedStop = false ;
27112733 mDelayedStopCounter ++;
2734+ mAlarmManager .cancel (mDriverStopIntent );
27122735 if (DBG ) log ("Delayed stop ignored due to start" );
27132736 }
27142737 break ;
27152738 case CMD_DELAYED_STOP_DRIVER :
2739+ if (DBG ) log ("delayed stop " + message .arg1 + " " + mDelayedStopCounter );
27162740 if (message .arg1 != mDelayedStopCounter ) break ;
27172741 if (getCurrentState () != mDisconnectedState ) {
27182742 mWifiNative .disconnect ();
0 commit comments