Merge "Fix delayed wifi shutdown" into jb-dev

This commit is contained in:
Irfan Sheriff
2012-05-25 10:31:46 -07:00
committed by Android (Google) Code Review

View File

@@ -209,6 +209,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);
@@ -521,6 +523,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.
*/
@@ -641,6 +648,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);
@@ -2701,18 +2717,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();