Loading services/java/com/android/server/DnsPinger.java +40 −17 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; if (mConnectivityManager == null) { mConnectivityManager = (ConnectivityManager) mContext.getSystemService( Context.CONNECTIVITY_SERVICE); } Collection<InetAddress> dnses = linkProperties.getDnses(); if (dnses == null || dnses.size() == 0) return null; LinkProperties curLinkProps = mConnectivityManager.getLinkProperties(mConnectionType); if (curLinkProps == null) { Slog.e(TAG, "getCurLinkProperties:: LP for type" + mConnectionType + " is null!"); return mDefaultDns; } Collection<InetAddress> dnses = curLinkProps.getDnses(); if (dnses == null || dnses.size() == 0) { Slog.v(TAG, "getDns::LinkProps has null dns - returning default"); return mDefaultDns; } return dnses.iterator().next(); } private LinkProperties getCurLinkProperties() { if (mConnectivityManager == null) { mConnectivityManager = (ConnectivityManager) mContext.getSystemService( Context.CONNECTIVITY_SERVICE); private InetAddress getDefaultDns() { String dns = Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.DEFAULT_DNS_SERVER); if (dns == null || dns.length() == 0) { dns = mContext.getResources().getString( com.android.internal.R.string.config_default_dns_server); } try { return NetworkUtils.numericToInetAddress(dns); } catch (IllegalArgumentException e) { Slog.w(TAG, "getDefaultDns::malformed default dns address"); return null; } return mConnectivityManager.getLinkProperties(mConnectionType); } /** Loading services/java/com/android/server/WifiWatchdogService.java +3 −3 Original line number Diff line number Diff line Loading @@ -95,14 +95,14 @@ public class WifiWatchdogService { private static final long MIN_SINGLE_DNS_CHECK_INTERVAL = 10 * 60 * 1000; private static final long MIN_WALLED_GARDEN_INTERVAL = 15 * 60 * 1000; private static final int MAX_CHECKS_PER_SSID = 7; private static final int NUM_DNS_PINGS = 5; private static final int MAX_CHECKS_PER_SSID = 9; private static final int NUM_DNS_PINGS = 7; private static double MIN_RESPONSE_RATE = 0.50; // TODO : Adjust multiple DNS downward to 250 on repeated failure // private static final int MULTI_DNS_PING_TIMEOUT_MS = 250; private static final int DNS_PING_TIMEOUT_MS = 1000; private static final int DNS_PING_TIMEOUT_MS = 800; private static final long DNS_PING_INTERVAL = 250; private static final long BLACKLIST_FOLLOWUP_INTERVAL = 15 * 1000; Loading Loading
services/java/com/android/server/DnsPinger.java +40 −17 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; if (mConnectivityManager == null) { mConnectivityManager = (ConnectivityManager) mContext.getSystemService( Context.CONNECTIVITY_SERVICE); } Collection<InetAddress> dnses = linkProperties.getDnses(); if (dnses == null || dnses.size() == 0) return null; LinkProperties curLinkProps = mConnectivityManager.getLinkProperties(mConnectionType); if (curLinkProps == null) { Slog.e(TAG, "getCurLinkProperties:: LP for type" + mConnectionType + " is null!"); return mDefaultDns; } Collection<InetAddress> dnses = curLinkProps.getDnses(); if (dnses == null || dnses.size() == 0) { Slog.v(TAG, "getDns::LinkProps has null dns - returning default"); return mDefaultDns; } return dnses.iterator().next(); } private LinkProperties getCurLinkProperties() { if (mConnectivityManager == null) { mConnectivityManager = (ConnectivityManager) mContext.getSystemService( Context.CONNECTIVITY_SERVICE); private InetAddress getDefaultDns() { String dns = Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.DEFAULT_DNS_SERVER); if (dns == null || dns.length() == 0) { dns = mContext.getResources().getString( com.android.internal.R.string.config_default_dns_server); } try { return NetworkUtils.numericToInetAddress(dns); } catch (IllegalArgumentException e) { Slog.w(TAG, "getDefaultDns::malformed default dns address"); return null; } return mConnectivityManager.getLinkProperties(mConnectionType); } /** Loading
services/java/com/android/server/WifiWatchdogService.java +3 −3 Original line number Diff line number Diff line Loading @@ -95,14 +95,14 @@ public class WifiWatchdogService { private static final long MIN_SINGLE_DNS_CHECK_INTERVAL = 10 * 60 * 1000; private static final long MIN_WALLED_GARDEN_INTERVAL = 15 * 60 * 1000; private static final int MAX_CHECKS_PER_SSID = 7; private static final int NUM_DNS_PINGS = 5; private static final int MAX_CHECKS_PER_SSID = 9; private static final int NUM_DNS_PINGS = 7; private static double MIN_RESPONSE_RATE = 0.50; // TODO : Adjust multiple DNS downward to 250 on repeated failure // private static final int MULTI_DNS_PING_TIMEOUT_MS = 250; private static final int DNS_PING_TIMEOUT_MS = 1000; private static final int DNS_PING_TIMEOUT_MS = 800; private static final long DNS_PING_INTERVAL = 250; private static final long BLACKLIST_FOLLOWUP_INTERVAL = 15 * 1000; Loading