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

Commit 2cd1dbe5 authored by Oscar Montemayor's avatar Oscar Montemayor Committed by Android (Google) Code Review
Browse files

Merge "Fix for bug 2890320 Browser crashes, after adding bookmark. Fixed Proxy...

Merge "Fix for bug 2890320 Browser crashes, after adding bookmark. Fixed Proxy class locking and dealing with empty exclusion lists."
parents 96183e16 b8f66019
Loading
Loading
Loading
Loading
+31 −18
Original line number Original line Diff line number Diff line
@@ -138,6 +138,7 @@ public final class Proxy {
     */
     */
    public static final java.net.Proxy getProxy(Context ctx, String url) {
    public static final java.net.Proxy getProxy(Context ctx, String url) {
        sProxyInfoLock.readLock().lock();
        sProxyInfoLock.readLock().lock();
        java.net.Proxy retval;
        try {
        try {
            if (sGlobalProxyChangedObserver == null) {
            if (sGlobalProxyChangedObserver == null) {
                registerContentObserversReadLocked(ctx);
                registerContentObserversReadLocked(ctx);
@@ -147,16 +148,19 @@ public final class Proxy {
                // Proxy defined - Apply exclusion rules
                // Proxy defined - Apply exclusion rules
                if (isURLInExclusionListReadLocked(url, sGlobalProxySpec.exclusionList)) {
                if (isURLInExclusionListReadLocked(url, sGlobalProxySpec.exclusionList)) {
                    // Return no proxy
                    // Return no proxy
                    return java.net.Proxy.NO_PROXY;
                    retval = java.net.Proxy.NO_PROXY;
                }
                } else {
                    java.net.Proxy retProxy =
                    java.net.Proxy retProxy =
                        new java.net.Proxy(java.net.Proxy.Type.HTTP, sGlobalProxySpec.proxyAddress);
                        new java.net.Proxy(java.net.Proxy.Type.HTTP, sGlobalProxySpec.proxyAddress);
                    sProxyInfoLock.readLock().unlock();
                    sProxyInfoLock.readLock().unlock();
                    if (isLocalHost(url)) {
                    if (isLocalHost(url)) {
                    return java.net.Proxy.NO_PROXY;
                }
                        sProxyInfoLock.readLock().lock();
                        sProxyInfoLock.readLock().lock();
                return retProxy;
                        retval = java.net.Proxy.NO_PROXY;
                    } else {
                        sProxyInfoLock.readLock().lock();
                        retval = retProxy;
                    }
                }
            } else {
            } else {
                // If network is WiFi, return no proxy.
                // If network is WiFi, return no proxy.
                // Otherwise, return the Mobile Operator proxy.
                // Otherwise, return the Mobile Operator proxy.
@@ -164,17 +168,20 @@ public final class Proxy {
                    java.net.Proxy retProxy = getDefaultProxy(url);
                    java.net.Proxy retProxy = getDefaultProxy(url);
                    sProxyInfoLock.readLock().unlock();
                    sProxyInfoLock.readLock().unlock();
                    if (isLocalHost(url)) {
                    if (isLocalHost(url)) {
                        return java.net.Proxy.NO_PROXY;
                    }
                        sProxyInfoLock.readLock().lock();
                        sProxyInfoLock.readLock().lock();
                    return retProxy;
                        retval = java.net.Proxy.NO_PROXY;
                    } else {
                    } else {
                    return java.net.Proxy.NO_PROXY;
                        sProxyInfoLock.readLock().lock();
                        retval = retProxy;
                    }
                } else {
                    retval = java.net.Proxy.NO_PROXY;
                }
                }
            }
            }
        } finally {
        } finally {
            sProxyInfoLock.readLock().unlock();
            sProxyInfoLock.readLock().unlock();
        }
        }
        return retval;
    }
    }


    // TODO: deprecate this function
    // TODO: deprecate this function
@@ -233,7 +240,7 @@ public final class Proxy {
     */
     */
    public static final String getDefaultHost() {
    public static final String getDefaultHost() {
        String host = SystemProperties.get("net.gprs.http-proxy");
        String host = SystemProperties.get("net.gprs.http-proxy");
        if (host != null) {
        if ((host != null) && (host.length() != 0)) {
            Uri u = Uri.parse(host);
            Uri u = Uri.parse(host);
            host = u.getHost();
            host = u.getHost();
            return host;
            return host;
@@ -250,7 +257,7 @@ public final class Proxy {
     */
     */
    public static final int getDefaultPort() {
    public static final int getDefaultPort() {
        String host = SystemProperties.get("net.gprs.http-proxy");
        String host = SystemProperties.get("net.gprs.http-proxy");
        if (host != null) {
        if ((host != null) && (host.length() != 0)) {
            Uri u = Uri.parse(host);
            Uri u = Uri.parse(host);
            return u.getPort();
            return u.getPort();
        } else {
        } else {
@@ -262,7 +269,7 @@ public final class Proxy {
        // TODO: This will go away when information is collected from ConnectivityManager...
        // TODO: This will go away when information is collected from ConnectivityManager...
        // There are broadcast of network proxies, so they are parse manually.
        // There are broadcast of network proxies, so they are parse manually.
        String host = SystemProperties.get("net.gprs.http-proxy");
        String host = SystemProperties.get("net.gprs.http-proxy");
        if (host != null) {
        if ((host != null) && (host.length() != 0)) {
            Uri u = Uri.parse(host);
            Uri u = Uri.parse(host);
            return new java.net.Proxy(java.net.Proxy.Type.HTTP,
            return new java.net.Proxy(java.net.Proxy.Type.HTTP,
                    new InetSocketAddress(u.getHost(), u.getPort()));
                    new InetSocketAddress(u.getHost(), u.getPort()));
@@ -376,7 +383,13 @@ public final class Proxy {
        String proxyHost =  Settings.Secure.getString(
        String proxyHost =  Settings.Secure.getString(
                contentResolver,
                contentResolver,
                Settings.Secure.HTTP_PROXY);
                Settings.Secure.HTTP_PROXY);
        if (proxyHost == null) {
        if ((proxyHost == null) || (proxyHost.length() == 0)) {
            // Clear signal
            sProxyInfoLock.readLock().unlock();
            sProxyInfoLock.writeLock().lock();
            sGlobalProxySpec = null;
            sProxyInfoLock.readLock().lock();
            sProxyInfoLock.writeLock().unlock();
            return;
            return;
        }
        }
        String exclusionListSpec = Settings.Secure.getString(
        String exclusionListSpec = Settings.Secure.getString(
@@ -387,7 +400,7 @@ public final class Proxy {
        if (proxyHost != null) {
        if (proxyHost != null) {
            sGlobalProxySpec = new ProxySpec();
            sGlobalProxySpec = new ProxySpec();
            sGlobalProxySpec.proxyAddress = new InetSocketAddress(host, port);
            sGlobalProxySpec.proxyAddress = new InetSocketAddress(host, port);
            if (exclusionListSpec != null) {
            if ((exclusionListSpec != null) && (exclusionListSpec.length() != 0)) {
                String[] exclusionListEntries = exclusionListSpec.toLowerCase().split(",");
                String[] exclusionListEntries = exclusionListSpec.toLowerCase().split(",");
                String[] processedEntries = new String[exclusionListEntries.length];
                String[] processedEntries = new String[exclusionListEntries.length];
                for (int i = 0; i < exclusionListEntries.length; i++) {
                for (int i = 0; i < exclusionListEntries.length; i++) {