Skip to content

Commit c21994b

Browse files
isheriffAndroid (Google) Code Review
authored andcommitted
Merge "Fix watchdog to stop ping after wifi disconnects" into ics-factoryrom
2 parents b20d378 + 32f04e9 commit c21994b

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

core/java/android/net/DnsPinger.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
public final class DnsPinger extends Handler {
5454
private static final boolean V = true;
5555

56-
private static final int RECEIVE_POLL_INTERVAL_MS = 30;
56+
private static final int RECEIVE_POLL_INTERVAL_MS = 200;
5757
private static final int DNS_PORT = 53;
5858

5959
/** Short socket timeout so we don't block one any 'receive' call */
@@ -70,6 +70,9 @@ public final class DnsPinger extends Handler {
7070
private final ArrayList<InetAddress> mDefaultDns;
7171
private String TAG;
7272

73+
//Invalidates old dns requests upon a cancel
74+
private AtomicInteger mCurrentToken = new AtomicInteger();
75+
7376
private static final int BASE = Protocol.BASE_DNS_PINGER;
7477

7578
/**
@@ -102,6 +105,17 @@ private class ActivePing {
102105
long start = SystemClock.elapsedRealtime();
103106
}
104107

108+
/* Message argument for ACTION_PING_DNS */
109+
private class DnsArg {
110+
InetAddress dns;
111+
int seq;
112+
113+
DnsArg(InetAddress d, int s) {
114+
dns = d;
115+
seq = s;
116+
}
117+
}
118+
105119
public DnsPinger(Context context, String TAG, Looper looper,
106120
Handler target, int connectionType) {
107121
super(looper);
@@ -122,9 +136,13 @@ public DnsPinger(Context context, String TAG, Looper looper,
122136
public void handleMessage(Message msg) {
123137
switch (msg.what) {
124138
case ACTION_PING_DNS:
139+
DnsArg dnsArg = (DnsArg) msg.obj;
140+
if (dnsArg.seq != mCurrentToken.get()) {
141+
break;
142+
}
125143
try {
126144
ActivePing newActivePing = new ActivePing();
127-
InetAddress dnsAddress = (InetAddress) msg.obj;
145+
InetAddress dnsAddress = dnsArg.dns;
128146
newActivePing.internalId = msg.arg1;
129147
newActivePing.timeout = msg.arg2;
130148
newActivePing.socket = new DatagramSocket();
@@ -248,11 +266,13 @@ public List<InetAddress> getDnsList() {
248266
*/
249267
public int pingDnsAsync(InetAddress dns, int timeout, int delay) {
250268
int id = sCounter.incrementAndGet();
251-
sendMessageDelayed(obtainMessage(ACTION_PING_DNS, id, timeout, dns), delay);
269+
sendMessageDelayed(obtainMessage(ACTION_PING_DNS, id, timeout,
270+
new DnsArg(dns, mCurrentToken.get())), delay);
252271
return id;
253272
}
254273

255274
public void cancelPings() {
275+
mCurrentToken.incrementAndGet();
256276
obtainMessage(ACTION_CANCEL_ALL_PINGS).sendToTarget();
257277
}
258278

wifi/java/android/net/wifi/WifiWatchdogStateMachine.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,12 +589,11 @@ public boolean processMessage(Message msg) {
589589
updateBssids();
590590
transitionTo(mDnsCheckingState);
591591
mNetEventCounter++;
592-
return HANDLED;
593-
case DISCONNECTED:
594-
case DISCONNECTING:
592+
break;
593+
default:
595594
mNetEventCounter++;
596595
transitionTo(mNotConnectedState);
597-
return HANDLED;
596+
break;
598597
}
599598
return HANDLED;
600599
case EVENT_WIFI_RADIO_STATE_CHANGE:

0 commit comments

Comments
 (0)