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

Commit f9464838 authored by Jason Monk's avatar Jason Monk Committed by Android Git Automerger
Browse files

am 312c495f: Merge "Guarantee that PAC Local Proxy owns Port" into klp-dev

* commit '312c495f':
  Guarantee that PAC Local Proxy owns Port
parents bd04940c 312c495f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -265,6 +265,8 @@ LOCAL_SRC_FILES += \
	wifi/java/android/net/wifi/IWifiManager.aidl \
	wifi/java/android/net/wifi/p2p/IWifiP2pManager.aidl \
	packages/services/PacProcessor/com/android/net/IProxyService.aidl \
	packages/services/Proxy/com/android/net/IProxyCallback.aidl \
	packages/services/Proxy/com/android/net/IProxyPortListener.aidl \

# FRAMEWORKS_BASE_JAVA_SRC_DIRS comes from build/core/pathmap.mk
LOCAL_AIDL_INCLUDES += $(FRAMEWORKS_BASE_JAVA_SRC_DIRS)
+9 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ public class ProxyProperties implements Parcelable {

    private String mPacFileUrl;
    public static final String LOCAL_EXCL_LIST = "";
    public static final int LOCAL_PORT = 8182;
    public static final int LOCAL_PORT = -1;
    public static final String LOCAL_HOST = "localhost";

    public ProxyProperties(String host, int port, String exclList) {
@@ -54,6 +54,14 @@ public class ProxyProperties implements Parcelable {
        mPacFileUrl = pacFileUrl;
    }

    // Only used in PacManager after Local Proxy is bound.
    public ProxyProperties(String pacFileUrl, int localProxyPort) {
        mHost = LOCAL_HOST;
        mPort = localProxyPort;
        setExclusionList(LOCAL_EXCL_LIST);
        mPacFileUrl = pacFileUrl;
    }

    private ProxyProperties(String host, int port, String exclList, String[] parsedExclList) {
        mHost = host;
        mPort = port;
+22 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2013, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.net;

/** @hide */
interface IProxyCallback
{
    oneway void getProxyPort(IBinder callback);
}
+22 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2013, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.net;

/** @hide */
interface IProxyPortListener
{
    oneway void setProxyPort(int port);
}
+50 −11
Original line number Diff line number Diff line
@@ -15,8 +15,11 @@
 */
package com.android.proxyhandler;

import android.net.ProxyProperties;
import android.os.RemoteException;
import android.util.Log;

import com.android.net.IProxyPortListener;
import com.google.android.collect.Lists;

import java.io.IOException;
@@ -49,6 +52,8 @@ public class ProxyServer extends Thread {
    public boolean mIsRunning = false;

    private ServerSocket serverSocket;
    private int mPort;
    private IProxyPortListener mCallback;

    private class ProxyConnection implements Runnable {
        private Socket connection;
@@ -179,14 +184,17 @@ public class ProxyServer extends Thread {

    public ProxyServer() {
        threadExecutor = Executors.newCachedThreadPool();
        mPort = -1;
        mCallback = null;
    }

    @Override
    public void run() {
        try {
            serverSocket = new ServerSocket(ProxyService.PORT);
            serverSocket = new ServerSocket(0);

            serverSocket.setReuseAddress(true);
            if (serverSocket != null) {
                setPort(serverSocket.getLocalPort());

                while (mIsRunning) {
                    try {
@@ -197,15 +205,38 @@ public class ProxyServer extends Thread {
                        e.printStackTrace();
                    }
                }
            }
        } catch (SocketException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
            Log.e(TAG, "Failed to start proxy server", e);
        } catch (IOException e1) {
            Log.e(TAG, "Failed to start proxy server", e1);
        }

        mIsRunning = false;
    }

    public synchronized void setPort(int port) {
        if (mCallback != null) {
            try {
                mCallback.setProxyPort(port);
            } catch (RemoteException e) {
                Log.w(TAG, "Proxy failed to report port to PacManager", e);
            }
        }
        mPort = port;
    }

    public synchronized void setCallback(IProxyPortListener callback) {
        if (mPort != -1) {
            try {
                callback.setProxyPort(mPort);
            } catch (RemoteException e) {
                Log.w(TAG, "Proxy failed to report port to PacManager", e);
            }
        }
        mCallback = callback;
    }

    public synchronized void startServer() {
        mIsRunning = true;
        start();
@@ -222,4 +253,12 @@ public class ProxyServer extends Thread {
            }
        }
    }

    public boolean isBound() {
        return (mPort != -1);
    }

    public int getPort() {
        return mPort;
    }
}
Loading