diff options
author | Jason Monk <jmonk@google.com> | 2013-08-23 19:21:25 -0400 |
---|---|---|
committer | Jason Monk <jmonk@google.com> | 2013-09-13 09:53:26 -0400 |
commit | 6f8a68f49a7e8cf86104e721a1e8be7568b5f730 (patch) | |
tree | dbe5e5d7001b191c376d3ba3510cbf6f7f309279 /packages/services | |
parent | 86d9c457de3285f01552d4046a8a260c7a75147f (diff) | |
download | frameworks_base-6f8a68f49a7e8cf86104e721a1e8be7568b5f730.zip frameworks_base-6f8a68f49a7e8cf86104e721a1e8be7568b5f730.tar.gz frameworks_base-6f8a68f49a7e8cf86104e721a1e8be7568b5f730.tar.bz2 |
Guarantee that PAC Local Proxy owns Port
This changes the PAC support to not broadcast the Proxy information until
the Local Proxy has started up and successfully bound to a port so that
the local proxy information can be guaranteed to be owned by the proxy.
Bug: 10459877
Change-Id: I175cd3388c758c55e341115e4a8241884b90d633
Diffstat (limited to 'packages/services')
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 |