diff --git a/services/java/com/android/server/DnsPinger.java b/services/java/com/android/server/DnsPinger.java index 05de53a2810cd..a7324d9a958d5 100644 --- a/services/java/com/android/server/DnsPinger.java +++ b/services/java/com/android/server/DnsPinger.java @@ -20,7 +20,9 @@ import android.content.ContentResolver; import android.content.Context; import android.net.ConnectivityManager; import android.net.LinkProperties; +import android.net.NetworkUtils; import android.os.SystemClock; +import android.provider.Settings; import android.util.Slog; import java.net.DatagramPacket; @@ -38,7 +40,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. Socket does not bind to specified connection type
+ * 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
@@ -56,44 +58,65 @@ public final class DnsPinger {
private static Random sRandom = new Random();
private ConnectivityManager mConnectivityManager = null;
- private ContentResolver mContentResolver;
private Context mContext;
private int mConnectionType;
+ private InetAddress mDefaultDns;
private String TAG;
-
/**
- * @param connectionType The connection type from @link {@link ConnectivityManager}
+ * @param connectionType The connection type from {@link ConnectivityManager}
*/
public DnsPinger(String TAG, Context context, int connectionType) {
mContext = context;
- mContentResolver = context.getContentResolver();
mConnectionType = connectionType;
+ if (!ConnectivityManager.isNetworkTypeValid(connectionType)) {
+ Slog.e(TAG, "Invalid connectionType in constructor: " + connectionType);
+ }
this.TAG = TAG;
+
+ mDefaultDns = getDefaultDns();
}
/**
- * @return The first DNS in the link properties of the specified connection type
+ * @return The first DNS in the link properties of the specified connection
+ * type or the default system DNS if the link properties has null
+ * dns set. Should not be null.
*/
public InetAddress getDns() {
- LinkProperties linkProperties = getCurLinkProperties();
- if (linkProperties == null)
- return null;
-
- Collection