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

Commit 88bae17c authored by Isaac Levy's avatar Isaac Levy
Browse files

Changed walled garden to better url

Now checking for walled gardens using 204 error code on
http://clients3.google.com/generate_204

Change-Id: I0a00dc8b956f35f6695d2085c9f03ce40dc7e231
parent 491345b8
Loading
Loading
Loading
Loading
+0 −7
Original line number Original line Diff line number Diff line
@@ -3041,13 +3041,6 @@ public final class Settings {
        public static final String WIFI_WATCHDOG_WALLED_GARDEN_URL =
        public static final String WIFI_WATCHDOG_WALLED_GARDEN_URL =
                "wifi_watchdog_walled_garden_url";
                "wifi_watchdog_walled_garden_url";


        /**
         * The pattern string in the fetched URL used to detect a walled garden
         * @hide
         */
        public static final String WIFI_WATCHDOG_WALLED_GARDEN_PATTERN =
                "wifi_watchdog_walled_garden_pattern";

        /**
        /**
         * Boolean to determine whether to notify on disabling a network.  Secure setting used
         * Boolean to determine whether to notify on disabling a network.  Secure setting used
         * to notify user only once.  This setting is not monitored continuously.
         * to notify user only once.  This setting is not monitored continuously.
+22 −35
Original line number Original line Diff line number Diff line
@@ -41,16 +41,12 @@ import com.android.internal.util.Protocol;
import com.android.internal.util.State;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
import com.android.internal.util.StateMachine;


import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URL;
import java.util.HashSet;
import java.util.HashSet;
import java.util.List;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Pattern;


/**
/**
 * {@link WifiWatchdogStateMachine} monitors the initial connection to a Wi-Fi
 * {@link WifiWatchdogStateMachine} monitors the initial connection to a Wi-Fi
@@ -88,13 +84,14 @@ public class WifiWatchdogStateMachine extends StateMachine {
    private static final int DEFAULT_MIN_DNS_RESPONSES = 3;
    private static final int DEFAULT_MIN_DNS_RESPONSES = 3;
    private static final long DNS_PING_INTERVAL_MS = 100;
    private static final long DNS_PING_INTERVAL_MS = 100;


    private static final int DEFAULT_DNS_PING_TIMEOUT_MS = 1500;
    private static final int DEFAULT_DNS_PING_TIMEOUT_MS = 2000;


    private static final long DEFAULT_BLACKLIST_FOLLOWUP_INTERVAL_MS = 15 * 1000;
    private static final long DEFAULT_BLACKLIST_FOLLOWUP_INTERVAL_MS = 15 * 1000;


    private static final String DEFAULT_WALLED_GARDEN_URL = "http://www.google.com/";
    // See http://go/clientsdns for usage approval
    private static final String DEFAULT_WALLED_GARDEN_PATTERN = "<title>.*Google.*</title>";
    private static final String DEFAULT_WALLED_GARDEN_URL =

            "http://clients3.google.com/generate_204";
    private static final int WALLED_GARDEN_SOCKET_TIMEOUT_MS = 10000;


    private static final int BASE = Protocol.BASE_WIFI_WATCHDOG;
    private static final int BASE = Protocol.BASE_WIFI_WATCHDOG;


@@ -154,7 +151,6 @@ public class WifiWatchdogStateMachine extends StateMachine {
    private long mBlacklistFollowupIntervalMs;
    private long mBlacklistFollowupIntervalMs;
    private boolean mWalledGardenTestEnabled;
    private boolean mWalledGardenTestEnabled;
    private String mWalledGardenUrl;
    private String mWalledGardenUrl;
    private Pattern mWalledGardenPattern;


    private boolean mShowDisabledNotification;
    private boolean mShowDisabledNotification;
    /**
    /**
@@ -320,9 +316,6 @@ public class WifiWatchdogStateMachine extends StateMachine {
        mContext.getContentResolver().registerContentObserver(
        mContext.getContentResolver().registerContentObserver(
                Settings.Secure.getUriFor(Settings.Secure.WIFI_WATCHDOG_WALLED_GARDEN_URL),
                Settings.Secure.getUriFor(Settings.Secure.WIFI_WATCHDOG_WALLED_GARDEN_URL),
                false, contentObserver);
                false, contentObserver);
        mContext.getContentResolver().registerContentObserver(
                Settings.Secure.getUriFor(Settings.Secure.WIFI_WATCHDOG_WALLED_GARDEN_PATTERN),
                false, contentObserver);
    }
    }


    /**
    /**
@@ -331,31 +324,28 @@ public class WifiWatchdogStateMachine extends StateMachine {
     * fetches the data we expect
     * fetches the data we expect
     */
     */
    private boolean isWalledGardenConnection() {
    private boolean isWalledGardenConnection() {
        InputStream in = null;
        HttpURLConnection urlConnection = null;
        HttpURLConnection urlConnection = null;
        try {
        try {
            URL url = new URL(mWalledGardenUrl);
            URL url = new URL(mWalledGardenUrl);
            urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection = (HttpURLConnection) url.openConnection();
            in = new BufferedInputStream(urlConnection.getInputStream());
            urlConnection.setInstanceFollowRedirects(false);
            Scanner scanner = new Scanner(in);
            urlConnection.setConnectTimeout(WALLED_GARDEN_SOCKET_TIMEOUT_MS);
            if (scanner.findInLine(mWalledGardenPattern) != null) {
            urlConnection.setReadTimeout(WALLED_GARDEN_SOCKET_TIMEOUT_MS);
                return false;
            urlConnection.setUseCaches(false);
            } else {
            urlConnection.getInputStream();
                return true;
            // We got a valid response, but not from the real google
            }
            return urlConnection.getResponseCode() != 204;
        } catch (IOException e) {
        } catch (IOException e) {
            if (DBG) {
                Slog.d(WWSM_TAG, "Walled garden check - probably not a portal: exception ", e);
            }
            return false;
            return false;
        } finally {
        } finally {
            if (in != null) {
            if (urlConnection != null) {
                try {
                    in.close();
                } catch (IOException e) {
                }
            }
            if (urlConnection != null)
                urlConnection.disconnect();
                urlConnection.disconnect();
            }
            }
        }
        }
    }


    private boolean rssiStrengthAboveCutoff(int rssi) {
    private boolean rssiStrengthAboveCutoff(int rssi) {
        return WifiManager.calculateSignalLevel(rssi, WIFI_SIGNAL_LEVELS) > LOW_SIGNAL_CUTOFF;
        return WifiManager.calculateSignalLevel(rssi, WIFI_SIGNAL_LEVELS) > LOW_SIGNAL_CUTOFF;
@@ -401,9 +391,6 @@ public class WifiWatchdogStateMachine extends StateMachine {
        mWalledGardenUrl = getSettingsStr(mContentResolver,
        mWalledGardenUrl = getSettingsStr(mContentResolver,
                Settings.Secure.WIFI_WATCHDOG_WALLED_GARDEN_URL,
                Settings.Secure.WIFI_WATCHDOG_WALLED_GARDEN_URL,
                DEFAULT_WALLED_GARDEN_URL);
                DEFAULT_WALLED_GARDEN_URL);
        mWalledGardenPattern = Pattern.compile(getSettingsStr(mContentResolver,
                Settings.Secure.WIFI_WATCHDOG_WALLED_GARDEN_PATTERN,
                DEFAULT_WALLED_GARDEN_PATTERN));
        mWalledGardenIntervalMs = Secure.getLong(mContentResolver,
        mWalledGardenIntervalMs = Secure.getLong(mContentResolver,
                Secure.WIFI_WATCHDOG_WALLED_GARDEN_INTERVAL_MS,
                Secure.WIFI_WATCHDOG_WALLED_GARDEN_INTERVAL_MS,
                DEFAULT_WALLED_GARDEN_INTERVAL_MS);
                DEFAULT_WALLED_GARDEN_INTERVAL_MS);
@@ -434,6 +421,9 @@ public class WifiWatchdogStateMachine extends StateMachine {
   *
   *
   */
   */
    private void resetWatchdogState() {
    private void resetWatchdogState() {
        if (VDBG) {
            Slog.v(WWSM_TAG, "Resetting watchdog state...");
        }
        mInitialConnInfo = null;
        mInitialConnInfo = null;
        mDisableAPNextFailure = false;
        mDisableAPNextFailure = false;
        mLastWalledGardenCheckTime = null;
        mLastWalledGardenCheckTime = null;
@@ -545,11 +535,8 @@ public class WifiWatchdogStateMachine extends StateMachine {


                    switch (networkInfo.getState()) {
                    switch (networkInfo.getState()) {
                        case CONNECTED:
                        case CONNECTED:
                            // WifiInfo wifiInfo = (WifiInfo)
                            WifiInfo wifiInfo = (WifiInfo)
                            //         stateChangeIntent
                                stateChangeIntent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
                            //                 .getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
                            // TODO : Replace with above code when API is changed
                            WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
                            if (wifiInfo == null) {
                            if (wifiInfo == null) {
                                Slog.e(WWSM_TAG, "Connected --> WifiInfo object null!");
                                Slog.e(WWSM_TAG, "Connected --> WifiInfo object null!");
                                return HANDLED;
                                return HANDLED;