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

Commit c2e62d24 authored by Steve Kondik's avatar Steve Kondik
Browse files

Finish the HTTP proxy support and add wifi-only pref.

parent a326b418
Loading
Loading
Loading
Loading
+21 −5
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.content.ContentResolver;
import android.content.Context;
import android.os.SystemProperties;
import android.provider.Settings;
import android.util.Log;

import java.net.InetAddress;
import java.net.URI;
@@ -59,7 +58,7 @@ final public class Proxy {
        String host = Settings.Secure.getString(
                contentResolver,
                Settings.Secure.HTTP_PROXY);
        if (host != null) {
        if (host != null && !host.equals("")) {
            int i = host.indexOf(':');
            if (i == -1) {
                if (DEBUG) {
@@ -132,8 +131,9 @@ final public class Proxy {

    /**
     * Returns the preferred proxy to be used by clients. This is a wrapper
     * around {@link android.net.Proxy#getHost()}. Currently no proxy will
     * be returned for localhost or if the active network is Wi-Fi.
     * around {@link android.net.Proxy#getHost()}. No proxy will be returned
     * for localhost, and Settings.Secure.HTTP_PROXY_WIFI_ONLY will be checked
     * if the user is on wifi.
     *
     * @param context the context which will be passed to
     * {@link android.net.Proxy#getHost()}
@@ -147,7 +147,11 @@ final public class Proxy {
     */
    static final public HttpHost getPreferredHttpHost(Context context,
            String url) {
        if (!isLocalHost(url) && !isNetworkWifi(context)) {
        if (!isLocalHost(url)) {
            if (isProxyForWifiOnly(context) && !isNetworkWifi(context)) {
                return null;
            }

            final String proxyHost = Proxy.getHost(context);
            if (proxyHost != null) {
                return new HttpHost(proxyHost, Proxy.getPort(context), "http");
@@ -200,4 +204,16 @@ final public class Proxy {

        return false;
    }

    /**
     * @param ctx
     * @return if we should only proxy while on wifi
     * @hide
     */
    static final public boolean isProxyForWifiOnly(Context ctx) {
        boolean ret = Settings.Secure.getInt(ctx.getContentResolver(),
                Settings.Secure.HTTP_PROXY_WIFI_ONLY, 1) != 0;
        return ret;
    }

};
+7 −41
Original line number Diff line number Diff line
@@ -21,23 +21,19 @@

package android.net.http;

import org.apache.http.HttpHost;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Proxy;
import android.net.WebAddress;
import android.os.Handler;
import android.os.Message;
import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.Log;

import java.io.InputStream;
import java.util.Comparator;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -45,8 +41,6 @@ import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map;

import org.apache.http.HttpHost;

/**
 * {@hide}
 */
@@ -59,7 +53,6 @@ public class RequestQueue implements RequestFeeder {
    private final LinkedHashMap<HttpHost, LinkedList<Request>> mPending;
    private final Context mContext;
    private final ActivePool mActivePool;
    private final ConnectivityManager mConnectivityManager;
    private final HashSet<HttpHost> mPriorities;

    private HttpHost mProxyHost = null;
@@ -222,8 +215,6 @@ public class RequestQueue implements RequestFeeder {
        mActivePool = new ActivePool(connectionCount);
        mActivePool.startup();

        mConnectivityManager = (ConnectivityManager)
                context.getSystemService(Context.CONNECTIVITY_SERVICE);
    }

    public synchronized boolean setRequestPriority(WebAddress uri, int priority) {
@@ -317,18 +308,10 @@ public class RequestQueue implements RequestFeeder {
     * synchronize setting the proxy
     */
    private synchronized void setProxyConfig() {
        NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
        if (info != null && info.getType() == ConnectivityManager.TYPE_WIFI) {
            mProxyHost = null;
        } else {
            String host = Proxy.getHost(mContext);
            if (HttpLog.LOGV) HttpLog.v("RequestQueue.setProxyConfig " + host);
            if (host == null) {
                mProxyHost = null;
            } else {
        mProxyHost = Proxy.getPreferredHttpHost(mContext, null);
        if (HttpLog.LOGV) HttpLog.v("RequestQueue.setProxyConfig ");
        if (mProxyHost != null) {
            mActivePool.disablePersistence();
                mProxyHost = new HttpHost(host, Proxy.getPort(mContext), "http");
            }
        }
    }

@@ -502,8 +485,6 @@ public class RequestQueue implements RequestFeeder {
                String hostName = entry.getKey().getHostName();
                StringBuilder line = new StringBuilder("p" + count++ + " " + hostName + " ");

                LinkedList<Request> reqList = entry.getValue();
                ListIterator reqIter = reqList.listIterator(0);
                while (iter.hasNext()) {
                    Request request = (Request)iter.next();
                    line.append(request + " ");
@@ -641,21 +622,6 @@ public class RequestQueue implements RequestFeeder {
        mActivePool.stopTiming();
    }

    /* helper */
    private Request removeFirst(LinkedHashMap<HttpHost, LinkedList<Request>> requestQueue) {
        Request ret = null;
        Iterator<Map.Entry<HttpHost, LinkedList<Request>>> iter = requestQueue.entrySet().iterator();
        if (iter.hasNext()) {
            Map.Entry<HttpHost, LinkedList<Request>> entry = iter.next();
            LinkedList<Request> reqList = entry.getValue();
            ret = reqList.removeFirst();
            if (reqList.isEmpty()) {
                requestQueue.remove(entry.getKey());
            }
        }
        return ret;
    }

    /**
     * This interface is exposed to each connection
     */
+6 −0
Original line number Diff line number Diff line
@@ -2851,6 +2851,12 @@ public final class Settings {
         */
        public static final String HTTP_PROXY = "http_proxy";

        /**
         * If proxy should be active on wifi only
         * @hide
         */
        public static final String HTTP_PROXY_WIFI_ONLY = "http_proxy_wifi_only";

        /**
         * Whether the package installer should allow installation of apps downloaded from
         * sources other than the Android Market (vending machine).