Skip to content

Commit f48fb85

Browse files
vishalmtiisheriff
authored andcommitted
Fix delayed wifi shutdown
Use a wake up alarm to ensure delayed shut down message is sent Bug: 5926285 Change-Id: I26a3353ddabb17d55299d8b5f9faf4c7ef5b2448 Signed-off-by: Vishal Mahaveer <vishalm@ti.com>
1 parent ae14715 commit f48fb85

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

wifi/java/android/net/wifi/WifiStateMachine.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ public class WifiStateMachine extends StateMachine {
208208

209209
private AlarmManager mAlarmManager;
210210
private PendingIntent mScanIntent;
211+
private PendingIntent mDriverStopIntent;
212+
211213
/* Tracks current frequency mode */
212214
private AtomicInteger mFrequencyBand = new AtomicInteger(WifiManager.WIFI_FREQUENCY_BAND_AUTO);
213215

@@ -520,6 +522,11 @@ private class TetherStateChange {
520522
private static final String ACTION_START_SCAN =
521523
"com.android.server.WifiManager.action.START_SCAN";
522524

525+
private static final String DELAYED_STOP_COUNTER = "DelayedStopCounter";
526+
private static final int DRIVER_STOP_REQUEST = 0;
527+
private static final String ACTION_DELAYED_DRIVER_STOP =
528+
"com.android.server.WifiManager.action.DELAYED_DRIVER_STOP";
529+
523530
/**
524531
* Keep track of whether WIFI is running.
525532
*/
@@ -637,6 +644,15 @@ public void onReceive(Context context, Intent intent) {
637644
}
638645
}
639646
};
647+
mContext.registerReceiver(
648+
new BroadcastReceiver() {
649+
@Override
650+
public void onReceive(Context context, Intent intent) {
651+
int counter = intent.getIntExtra(DELAYED_STOP_COUNTER, 0);
652+
sendMessage(obtainMessage(CMD_DELAYED_STOP_DRIVER, counter, 0));
653+
}
654+
},
655+
new IntentFilter(ACTION_DELAYED_DRIVER_STOP));
640656

641657
mScanResultCache = new LruCache<String, ScanResult>(SCAN_RESULT_CACHE_SIZE);
642658

@@ -2666,18 +2682,26 @@ public boolean processMessage(Message message) {
26662682
sendMessage(obtainMessage(CMD_DELAYED_STOP_DRIVER, mDelayedStopCounter, 0));
26672683
} else {
26682684
/* send regular delayed shut down */
2669-
sendMessageDelayed(obtainMessage(CMD_DELAYED_STOP_DRIVER,
2670-
mDelayedStopCounter, 0), mDriverStopDelayMs);
2685+
Intent driverStopIntent = new Intent(ACTION_DELAYED_DRIVER_STOP, null);
2686+
driverStopIntent.putExtra(DELAYED_STOP_COUNTER, mDelayedStopCounter);
2687+
mDriverStopIntent = PendingIntent.getBroadcast(mContext,
2688+
DRIVER_STOP_REQUEST, driverStopIntent,
2689+
PendingIntent.FLAG_UPDATE_CURRENT);
2690+
2691+
mAlarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
2692+
+ mDriverStopDelayMs, mDriverStopIntent);
26712693
}
26722694
break;
26732695
case CMD_START_DRIVER:
26742696
if (mInDelayedStop) {
26752697
mInDelayedStop = false;
26762698
mDelayedStopCounter++;
2699+
mAlarmManager.cancel(mDriverStopIntent);
26772700
if (DBG) log("Delayed stop ignored due to start");
26782701
}
26792702
break;
26802703
case CMD_DELAYED_STOP_DRIVER:
2704+
if (DBG) log("delayed stop " + message.arg1 + " " + mDelayedStopCounter);
26812705
if (message.arg1 != mDelayedStopCounter) break;
26822706
if (getCurrentState() != mDisconnectedState) {
26832707
mWifiNative.disconnect();

0 commit comments

Comments
 (0)