Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ed0afe71 authored by Irfan Sheriff's avatar Irfan Sheriff Committed by Android (Google) Code Review
Browse files

Merge "Fixing null pointer b/4962091"

parents a099fefe b1ef292b
Loading
Loading
Loading
Loading
+18 −11
Original line number Diff line number Diff line
@@ -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).
 * <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 @@ 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.
     */
+7 −3
Original line number Diff line number Diff line
@@ -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);
    }

    /**