am c21994bc: Merge "Fix watchdog to stop ping after wifi disconnects" into ics-factoryrom
* commit 'c21994bc26df959d1a7161e38b4402b7255ea321': Fix watchdog to stop ping after wifi disconnects
This commit is contained in:
@@ -53,7 +53,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
public final class DnsPinger extends Handler {
|
public final class DnsPinger extends Handler {
|
||||||
private static final boolean V = true;
|
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;
|
private static final int DNS_PORT = 53;
|
||||||
|
|
||||||
/** Short socket timeout so we don't block one any 'receive' call */
|
/** 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 final ArrayList<InetAddress> mDefaultDns;
|
||||||
private String TAG;
|
private String TAG;
|
||||||
|
|
||||||
|
//Invalidates old dns requests upon a cancel
|
||||||
|
private AtomicInteger mCurrentToken = new AtomicInteger();
|
||||||
|
|
||||||
private static final int BASE = Protocol.BASE_DNS_PINGER;
|
private static final int BASE = Protocol.BASE_DNS_PINGER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,6 +105,17 @@ public final class DnsPinger extends Handler {
|
|||||||
long start = SystemClock.elapsedRealtime();
|
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,
|
public DnsPinger(Context context, String TAG, Looper looper,
|
||||||
Handler target, int connectionType) {
|
Handler target, int connectionType) {
|
||||||
super(looper);
|
super(looper);
|
||||||
@@ -122,9 +136,13 @@ public final class DnsPinger extends Handler {
|
|||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
switch (msg.what) {
|
switch (msg.what) {
|
||||||
case ACTION_PING_DNS:
|
case ACTION_PING_DNS:
|
||||||
|
DnsArg dnsArg = (DnsArg) msg.obj;
|
||||||
|
if (dnsArg.seq != mCurrentToken.get()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
ActivePing newActivePing = new ActivePing();
|
ActivePing newActivePing = new ActivePing();
|
||||||
InetAddress dnsAddress = (InetAddress) msg.obj;
|
InetAddress dnsAddress = dnsArg.dns;
|
||||||
newActivePing.internalId = msg.arg1;
|
newActivePing.internalId = msg.arg1;
|
||||||
newActivePing.timeout = msg.arg2;
|
newActivePing.timeout = msg.arg2;
|
||||||
newActivePing.socket = new DatagramSocket();
|
newActivePing.socket = new DatagramSocket();
|
||||||
@@ -248,11 +266,13 @@ public final class DnsPinger extends Handler {
|
|||||||
*/
|
*/
|
||||||
public int pingDnsAsync(InetAddress dns, int timeout, int delay) {
|
public int pingDnsAsync(InetAddress dns, int timeout, int delay) {
|
||||||
int id = sCounter.incrementAndGet();
|
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;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelPings() {
|
public void cancelPings() {
|
||||||
|
mCurrentToken.incrementAndGet();
|
||||||
obtainMessage(ACTION_CANCEL_ALL_PINGS).sendToTarget();
|
obtainMessage(ACTION_CANCEL_ALL_PINGS).sendToTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -589,12 +589,11 @@ public class WifiWatchdogStateMachine extends StateMachine {
|
|||||||
updateBssids();
|
updateBssids();
|
||||||
transitionTo(mDnsCheckingState);
|
transitionTo(mDnsCheckingState);
|
||||||
mNetEventCounter++;
|
mNetEventCounter++;
|
||||||
return HANDLED;
|
break;
|
||||||
case DISCONNECTED:
|
default:
|
||||||
case DISCONNECTING:
|
|
||||||
mNetEventCounter++;
|
mNetEventCounter++;
|
||||||
transitionTo(mNotConnectedState);
|
transitionTo(mNotConnectedState);
|
||||||
return HANDLED;
|
break;
|
||||||
}
|
}
|
||||||
return HANDLED;
|
return HANDLED;
|
||||||
case EVENT_WIFI_RADIO_STATE_CHANGE:
|
case EVENT_WIFI_RADIO_STATE_CHANGE:
|
||||||
|
|||||||
Reference in New Issue
Block a user