From b1ef292b3d0c2b4b4c77bb7b442df8e73d1fbb5e Mon Sep 17 00:00:00 2001 From: Isaac Levy Date: Mon, 27 Jun 2011 10:02:50 -0700 Subject: Fixing null pointer b/4962091 Fixing watchdog service bug, adding some extra dump logs. Change-Id: I03d94a46fade6974f21931803f87fdd065750612 --- services/java/com/android/server/DnsPinger.java | 29 ++++++++++++++-------- .../com/android/server/WifiWatchdogService.java | 10 +++++--- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/services/java/com/android/server/DnsPinger.java b/services/java/com/android/server/DnsPinger.java index 5cfda7ec9965..05de53a2810c 100644 --- a/services/java/com/android/server/DnsPinger.java +++ b/services/java/com/android/server/DnsPinger.java @@ -38,7 +38,7 @@ import java.util.Random; * API may not differentiate between a time out and a failure lookup (which we * really care about). *

- * 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 @@ public final class DnsPinger { 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 @@ public final class DnsPinger { 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 0b7947882ee8..3ba9c14cf4d7 100644 --- a/services/java/com/android/server/WifiWatchdogService.java +++ b/services/java/com/android/server/WifiWatchdogService.java @@ -22,6 +22,7 @@ import android.content.Context; 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 @@ public class WifiWatchdogService { 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 @@ public class WifiWatchdogService { 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 @@ public class WifiWatchdogService { 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); } /** -- cgit v1.2.3-59-g8ed1b