Fixing null pointer b/4962091
Fixing watchdog service bug, adding some extra dump logs.
Change-Id: I03d94a46fade6974f21931803f87fdd065750612
diff --git a/services/java/com/android/server/DnsPinger.java b/services/java/com/android/server/DnsPinger.java
index 5cfda7e..05de53a 100644
--- a/services/java/com/android/server/DnsPinger.java
+++ b/services/java/com/android/server/DnsPinger.java
@@ -38,7 +38,7 @@
* API may not differentiate between a time out and a failure lookup (which we
* really care about).
* <p>
- * TODO : More general API. Wifi is currently hard coded
+ * TODO : More general API. Socket does not bind to specified connection type
* TODO : Choice of DNS query location - current looks up www.android.com
*
* @hide
@@ -58,27 +58,26 @@
private ConnectivityManager mConnectivityManager = null;
private ContentResolver mContentResolver;
private Context mContext;
+ private int mConnectionType;
private String TAG;
- public DnsPinger(String TAG, Context context) {
+
+ /**
+ * @param connectionType The connection type from @link {@link ConnectivityManager}
+ */
+ public DnsPinger(String TAG, Context context, int connectionType) {
mContext = context;
mContentResolver = context.getContentResolver();
+ mConnectionType = connectionType;
this.TAG = TAG;
}
/**
- * Gets the first DNS of the current Wifi AP.
- * @return The first DNS of the current AP.
+ * @return The first DNS in the link properties of the specified connection type
*/
public InetAddress getDns() {
- if (mConnectivityManager == null) {
- mConnectivityManager = (ConnectivityManager) mContext.getSystemService(
- Context.CONNECTIVITY_SERVICE);
- }
-
- LinkProperties linkProperties = mConnectivityManager.getLinkProperties(
- ConnectivityManager.TYPE_WIFI);
+ LinkProperties linkProperties = getCurLinkProperties();
if (linkProperties == null)
return null;
@@ -89,6 +88,14 @@
return dnses.iterator().next();
}
+ private LinkProperties getCurLinkProperties() {
+ if (mConnectivityManager == null) {
+ mConnectivityManager = (ConnectivityManager) mContext.getSystemService(
+ Context.CONNECTIVITY_SERVICE);
+ }
+ return mConnectivityManager.getLinkProperties(mConnectionType);
+ }
+
/**
* @return time to response. Negative value on error.
*/
diff --git a/services/java/com/android/server/WifiWatchdogService.java b/services/java/com/android/server/WifiWatchdogService.java
index 0b79478..3ba9c14 100644
--- a/services/java/com/android/server/WifiWatchdogService.java
+++ b/services/java/com/android/server/WifiWatchdogService.java
@@ -22,6 +22,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.database.ContentObserver;
+import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.net.wifi.ScanResult;
@@ -162,7 +163,8 @@
mContext = context;
mContentResolver = context.getContentResolver();
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
- mDnsPinger = new DnsPinger("WifiWatchdogServer.DnsPinger", context);
+ mDnsPinger = new DnsPinger("WifiWatchdogServer.DnsPinger", context,
+ ConnectivityManager.TYPE_WIFI);
HandlerThread handlerThread = new HandlerThread("WifiWatchdogServiceThread");
handlerThread.start();
@@ -523,7 +525,7 @@
if (DBG) {
mDNSCheckLogStr = String.format("Dns Check %d. Pinging %s on ssid [%s]: ",
- mStatus.numFullDNSchecks, mDnsPinger.getDns().getHostAddress(),
+ mStatus.numFullDNSchecks, mDnsPinger.getDns(),
mStatus.ssid);
}
}
@@ -717,11 +719,13 @@
pw.print("State " + mStatus.state);
pw.println(", network [" + mStatus.ssid + ", " + mStatus.bssid + "]");
pw.print("checkCount " + mStatus.numFullDNSchecks);
- pw.print(", bssids: " + mStatus.allBssids.size());
+ pw.println(", bssids: " + mStatus.allBssids);
pw.print(", hasCheckMessages? " +
mHandler.hasMessages(WifiWatchdogHandler.CHECK_SEQUENCE_STEP));
pw.println(" hasSingleCheckMessages? " +
mHandler.hasMessages(WifiWatchdogHandler.SINGLE_DNS_CHECK));
+ pw.println("DNS check log str: " + mDNSCheckLogStr);
+ pw.println("lastSingleCheck: " + mStatus.lastSingleCheckTime);
}
/**