diff options
author | Jason Monk <jmonk@google.com> | 2013-09-13 20:31:53 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-09-13 20:31:54 +0000 |
commit | 312c495f4b8d002264772f61fe1fa3ef87bf3e52 (patch) | |
tree | 8508f800432e603ae76330fa3d0c358fe4a85c03 /packages | |
parent | cac2428da4a22d9526af09e1457a6b644b2c2057 (diff) | |
parent | 6f8a68f49a7e8cf86104e721a1e8be7568b5f730 (diff) | |
download | frameworks_base-312c495f4b8d002264772f61fe1fa3ef87bf3e52.zip frameworks_base-312c495f4b8d002264772f61fe1fa3ef87bf3e52.tar.gz frameworks_base-312c495f4b8d002264772f61fe1fa3ef87bf3e52.tar.bz2 |
Merge "Guarantee that PAC Local Proxy owns Port" into klp-dev
Diffstat (limited to 'packages')
4 files changed, 109 insertions, 12 deletions
diff --git a/packages/services/Proxy/com/android/net/IProxyCallback.aidl b/packages/services/Proxy/com/android/net/IProxyCallback.aidl new file mode 100644 index 0000000..26b2a3f --- /dev/null +++ b/packages/services/Proxy/com/android/net/IProxyCallback.aidl @@ -0,0 +1,22 @@ +/** + * 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); +} diff --git a/packages/services/Proxy/com/android/net/IProxyPortListener.aidl b/packages/services/Proxy/com/android/net/IProxyPortListener.aidl new file mode 100644 index 0000000..fa4caf3 --- /dev/null +++ b/packages/services/Proxy/com/android/net/IProxyPortListener.aidl @@ -0,0 +1,22 @@ +/** + * 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); +} diff --git a/packages/services/Proxy/src/com/android/proxyhandler/ProxyServer.java b/packages/services/Proxy/src/com/android/proxyhandler/ProxyServer.java index 77f3c8c..4bf1db8 100644 --- a/packages/services/Proxy/src/com/android/proxyhandler/ProxyServer.java +++ b/packages/services/Proxy/src/com/android/proxyhandler/ProxyServer.java @@ -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,33 +184,59 @@ 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 { - ProxyConnection parser = new ProxyConnection(serverSocket.accept()); + while (mIsRunning) { + try { + ProxyConnection parser = new ProxyConnection(serverSocket.accept()); - threadExecutor.execute(parser); - } catch (IOException e) { - e.printStackTrace(); + threadExecutor.execute(parser); + } catch (IOException e) { + 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; + } } diff --git a/packages/services/Proxy/src/com/android/proxyhandler/ProxyService.java b/packages/services/Proxy/src/com/android/proxyhandler/ProxyService.java index cef3659..109435c 100644 --- a/packages/services/Proxy/src/com/android/proxyhandler/ProxyService.java +++ b/packages/services/Proxy/src/com/android/proxyhandler/ProxyService.java @@ -21,8 +21,12 @@ import android.net.Proxy; import android.net.ProxyProperties; import android.os.Bundle; import android.os.IBinder; +import android.os.RemoteException; import android.text.TextUtils; +import com.android.net.IProxyCallback; +import com.android.net.IProxyPortListener; + /** * @hide */ @@ -56,6 +60,16 @@ public class ProxyService extends Service { @Override public IBinder onBind(Intent intent) { - return null; + return new IProxyCallback.Stub() { + @Override + public void getProxyPort(IBinder callback) throws RemoteException { + if (server != null) { + IProxyPortListener portListener = IProxyPortListener.Stub.asInterface(callback); + if (portListener != null) { + server.setCallback(portListener); + } + } + } + }; } }
\ No newline at end of file |