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

Commit 8b72d447 authored by Chalard Jean's avatar Chalard Jean Committed by android-build-merger
Browse files

Merge "[PT17] Small cleanup of PacManager" am: f9bb1a99

am: 6fa5cc67

Change-Id: I7feead64e6fd1c4a02ccaaf4a76f1ad684887e72
parents 8e548252 6fa5cc67
Loading
Loading
Loading
Loading
+11 −8
Original line number Diff line number Diff line
@@ -43,8 +43,6 @@ import com.android.net.IProxyCallback;
import com.android.net.IProxyPortListener;
import com.android.net.IProxyService;

import libcore.io.Streams;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;
@@ -71,6 +69,11 @@ public class PacManager {
    private static final int DELAY_LONG = 4;
    private static final long MAX_PAC_SIZE = 20 * 1000 * 1000;

    // Return values for #setCurrentProxyScriptUrl
    enum ToSendOrNotToSendBroadcast {
        DONT_SEND_BROADCAST, DO_SEND_BROADCAST
    }

    private String mCurrentPac;
    @GuardedBy("mProxyLock")
    private volatile Uri mPacUrl = Uri.EMPTY;
@@ -171,13 +174,13 @@ public class PacManager {
     * PacManager will trigger a new broadcast when it is ready.
     *
     * @param proxy Proxy information that is about to be broadcast.
     * @return Returns true when the broadcast should not be sent
     * @return Returns whether the broadcast should be sent : either DO_ or DONT_SEND_BROADCAST
     */
    synchronized boolean setCurrentProxyScriptUrl(ProxyInfo proxy) {
    synchronized ToSendOrNotToSendBroadcast setCurrentProxyScriptUrl(ProxyInfo proxy) {
        if (!Uri.EMPTY.equals(proxy.getPacFileUrl())) {
            if (proxy.getPacFileUrl().equals(mPacUrl) && (proxy.getPort() > 0)) {
                // Allow to send broadcast, nothing to do.
                return false;
                return ToSendOrNotToSendBroadcast.DO_SEND_BROADCAST;
            }
            mPacUrl = proxy.getPacFileUrl();
            mCurrentDelay = DELAY_1;
@@ -185,7 +188,7 @@ public class PacManager {
            mHasDownloaded = false;
            getAlarmManager().cancel(mPacRefreshIntent);
            bind();
            return true;
            return ToSendOrNotToSendBroadcast.DONT_SEND_BROADCAST;
        } else {
            getAlarmManager().cancel(mPacRefreshIntent);
            synchronized (mProxyLock) {
@@ -201,7 +204,7 @@ public class PacManager {
                    }
                }
            }
            return false;
            return ToSendOrNotToSendBroadcast.DO_SEND_BROADCAST;
        }
    }

@@ -296,7 +299,7 @@ public class PacManager {
        Intent intent = new Intent();
        intent.setClassName(PAC_PACKAGE, PAC_SERVICE);
        if ((mProxyConnection != null) && (mConnection != null)) {
            // Already bound no need to bind again, just download the new file.
            // Already bound: no need to bind again, just download the new file.
            mNetThreadHandler.post(mPacDownloader);
            return;
        }
+4 −1
Original line number Diff line number Diff line
@@ -208,7 +208,10 @@ public class ProxyTracker {
    public void sendProxyBroadcast() {
        final ProxyInfo defaultProxy = getDefaultProxy();
        final ProxyInfo proxyInfo = null != defaultProxy ? defaultProxy : new ProxyInfo("", 0, "");
        if (mPacManager.setCurrentProxyScriptUrl(proxyInfo)) return;
        if (mPacManager.setCurrentProxyScriptUrl(proxyInfo)
                == PacManager.ToSendOrNotToSendBroadcast.DONT_SEND_BROADCAST) {
            return;
        }
        if (DBG) Slog.d(TAG, "sending Proxy Broadcast for " + proxyInfo);
        Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION);
        intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING |