Merge "Fix watchdog to stop ping after wifi disconnects" into ics-factoryrom

This commit is contained in:
Irfan Sheriff
2011-09-23 15:18:37 -07:00
committed by Android (Google) Code Review
2 changed files with 26 additions and 7 deletions

View File

@@ -53,7 +53,7 @@ import java.util.concurrent.atomic.AtomicInteger;
public final class DnsPinger extends Handler {
private static final boolean V = true;
private static final int RECEIVE_POLL_INTERVAL_MS = 30;
private static final int RECEIVE_POLL_INTERVAL_MS = 200;
private static final int DNS_PORT = 53;
/** Short socket timeout so we don't block one any 'receive' call */
@@ -70,6 +70,9 @@ public final class DnsPinger extends Handler {
private final ArrayList<InetAddress> mDefaultDns;
private String TAG;
//Invalidates old dns requests upon a cancel
private AtomicInteger mCurrentToken = new AtomicInteger();
private static final int BASE = Protocol.BASE_DNS_PINGER;
/**
@@ -102,6 +105,17 @@ public final class DnsPinger extends Handler {
long start = SystemClock.elapsedRealtime();
}
/* Message argument for ACTION_PING_DNS */
private class DnsArg {
InetAddress dns;
int seq;
DnsArg(InetAddress d, int s) {
dns = d;
seq = s;
}
}
public DnsPinger(Context context, String TAG, Looper looper,
Handler target, int connectionType) {
super(looper);
@@ -122,9 +136,13 @@ public final class DnsPinger extends Handler {
public void handleMessage(Message msg) {
switch (msg.what) {
case ACTION_PING_DNS:
DnsArg dnsArg = (DnsArg) msg.obj;
if (dnsArg.seq != mCurrentToken.get()) {
break;
}
try {
ActivePing newActivePing = new ActivePing();
InetAddress dnsAddress = (InetAddress) msg.obj;
InetAddress dnsAddress = dnsArg.dns;
newActivePing.internalId = msg.arg1;
newActivePing.timeout = msg.arg2;
newActivePing.socket = new DatagramSocket();
@@ -248,11 +266,13 @@ public final class DnsPinger extends Handler {
*/
public int pingDnsAsync(InetAddress dns, int timeout, int delay) {
int id = sCounter.incrementAndGet();
sendMessageDelayed(obtainMessage(ACTION_PING_DNS, id, timeout, dns), delay);
sendMessageDelayed(obtainMessage(ACTION_PING_DNS, id, timeout,
new DnsArg(dns, mCurrentToken.get())), delay);
return id;
}
public void cancelPings() {
mCurrentToken.incrementAndGet();
obtainMessage(ACTION_CANCEL_ALL_PINGS).sendToTarget();
}

View File

@@ -589,12 +589,11 @@ public class WifiWatchdogStateMachine extends StateMachine {
updateBssids();
transitionTo(mDnsCheckingState);
mNetEventCounter++;
return HANDLED;
case DISCONNECTED:
case DISCONNECTING:
break;
default:
mNetEventCounter++;
transitionTo(mNotConnectedState);
return HANDLED;
break;
}
return HANDLED;
case EVENT_WIFI_RADIO_STATE_CHANGE: