diff options
5 files changed, 57 insertions, 81 deletions
diff --git a/packages/services/Proxy/AndroidManifest.xml b/packages/services/Proxy/AndroidManifest.xml index 09b8327dced0..bbcd6b93bbb0 100644 --- a/packages/services/Proxy/AndroidManifest.xml +++ b/packages/services/Proxy/AndroidManifest.xml @@ -13,12 +13,5 @@ android:exported="true"> </service> - <receiver android:name=".ProxyServiceReceiver"> - - <intent-filter> - <action android:name="android.intent.action.PROXY_CHANGE" /> - </intent-filter> - </receiver> - </application> </manifest> diff --git a/packages/services/Proxy/src/com/android/proxyhandler/ProxyServer.java b/packages/services/Proxy/src/com/android/proxyhandler/ProxyServer.java index 5d8689e8edc5..77f3c8c21cc6 100644 --- a/packages/services/Proxy/src/com/android/proxyhandler/ProxyServer.java +++ b/packages/services/Proxy/src/com/android/proxyhandler/ProxyServer.java @@ -1,7 +1,20 @@ - +/** + * 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.proxyhandler; -import android.net.ProxyProperties; import android.util.Log; import com.google.android.collect.Lists; @@ -36,7 +49,6 @@ public class ProxyServer extends Thread { public boolean mIsRunning = false; private ServerSocket serverSocket; - private ProxyProperties mProxy; private class ProxyConnection implements Runnable { private Socket connection; @@ -48,8 +60,6 @@ public class ProxyServer extends Thread { @Override public void run() { try { - android.net.Proxy.setHttpProxySystemProperty(mProxy); - String requestLine = getLine(connection.getInputStream()); if (requestLine == null) { connection.close(); @@ -212,8 +222,4 @@ public class ProxyServer extends Thread { } } } - - public void setProxy(ProxyProperties proxy) { - mProxy = proxy; - } } diff --git a/packages/services/Proxy/src/com/android/proxyhandler/ProxyService.java b/packages/services/Proxy/src/com/android/proxyhandler/ProxyService.java index 18ed645f2223..cef36593b306 100644 --- a/packages/services/Proxy/src/com/android/proxyhandler/ProxyService.java +++ b/packages/services/Proxy/src/com/android/proxyhandler/ProxyService.java @@ -1,3 +1,18 @@ +/** + * 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.proxyhandler; import android.app.Service; @@ -18,43 +33,17 @@ public class ProxyService extends Service { /** Keep these values up-to-date with PacManager.java */ public static final String KEY_PROXY = "keyProxy"; public static final String HOST = "localhost"; + // STOPSHIP This being a static port means it can be hijacked by other apps. public static final int PORT = 8182; public static final String EXCL_LIST = ""; @Override - public int onStartCommand(Intent intent, int flags, int startId) { - if (intent != null) { - if (handleCommand(intent)) { - return START_REDELIVER_INTENT; - } - } - return START_NOT_STICKY; - } - - private boolean handleCommand(Intent intent) { - Bundle bundle = intent.getExtras(); - ProxyProperties proxy = null; - if ((bundle != null) && bundle.containsKey(Proxy.EXTRA_PROXY_INFO)) { - proxy = bundle.getParcelable(Proxy.EXTRA_PROXY_INFO); - if ((proxy != null) && !TextUtils.isEmpty(proxy.getPacFileUrl())) { - startProxy(proxy); - return true; - } else { - stopSelf(); - } - } else { - stopSelf(); - } - return false; - } - - - private void startProxy(ProxyProperties proxy) { + public void onCreate() { + super.onCreate(); if (server == null) { server = new ProxyServer(); server.startServer(); } - server.setProxy(proxy); } @Override diff --git a/packages/services/Proxy/src/com/android/proxyhandler/ProxyServiceReceiver.java b/packages/services/Proxy/src/com/android/proxyhandler/ProxyServiceReceiver.java deleted file mode 100644 index 4638def97964..000000000000 --- a/packages/services/Proxy/src/com/android/proxyhandler/ProxyServiceReceiver.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.android.proxyhandler; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.net.Proxy; -import android.net.ProxyProperties; -import android.os.Bundle; -import android.text.TextUtils; - -public class ProxyServiceReceiver extends BroadcastReceiver { - - @Override - public void onReceive(Context context, Intent intent) { - Intent service = new Intent(context, ProxyService.class); - Bundle bundle = intent.getExtras(); - ProxyProperties proxy = null; - if (bundle != null) { - proxy = bundle.getParcelable(Proxy.EXTRA_PROXY_INFO); - service.putExtra(Proxy.EXTRA_PROXY_INFO, proxy); - } - if ((proxy != null) && (!TextUtils.isEmpty(proxy.getPacFileUrl()))) { - context.startService(service); - } else { - context.stopService(service); - } - } - -} diff --git a/services/java/com/android/server/connectivity/PacManager.java b/services/java/com/android/server/connectivity/PacManager.java index 0b68ff5595eb..c8cc85e8d1cd 100644 --- a/services/java/com/android/server/connectivity/PacManager.java +++ b/services/java/com/android/server/connectivity/PacManager.java @@ -48,10 +48,12 @@ import java.net.URLConnection; * @hide */ public class PacManager { - public static final String PROXY_PACKAGE = "com.android.pacprocessor"; - public static final String PROXY_SERVICE = "com.android.pacprocessor.PacService"; - public static final String PROXY_SERVICE_NAME = "com.android.net.IProxyService"; + public static final String PAC_PACKAGE = "com.android.pacprocessor"; + public static final String PAC_SERVICE = "com.android.pacprocessor.PacService"; + public static final String PAC_SERVICE_NAME = "com.android.net.IProxyService"; + public static final String PROXY_PACKAGE = "com.android.proxyhandler"; + public static final String PROXY_SERVICE = "com.android.proxyhandler.ProxyService"; private static final String TAG = "PacManager"; @@ -73,6 +75,7 @@ public class PacManager { private IProxyService mProxyService; private PendingIntent mPacRefreshIntent; private ServiceConnection mConnection; + private ServiceConnection mProxyConnection; private Context mContext; private int mCurrentDelay; @@ -229,7 +232,7 @@ public class PacManager { return; } Intent intent = new Intent(); - intent.setClassName(PROXY_PACKAGE, PROXY_SERVICE); + intent.setClassName(PAC_PACKAGE, PAC_SERVICE); mConnection = new ServiceConnection() { @Override public void onServiceDisconnected(ComponentName component) { @@ -242,12 +245,12 @@ public class PacManager { public void onServiceConnected(ComponentName component, IBinder binder) { synchronized (mProxyLock) { try { - Log.d(TAG, "Adding service " + PROXY_SERVICE_NAME + " " + Log.d(TAG, "Adding service " + PAC_SERVICE_NAME + " " + binder.getInterfaceDescriptor()); } catch (RemoteException e1) { Log.e(TAG, "Remote Exception", e1); } - ServiceManager.addService(PROXY_SERVICE_NAME, binder); + ServiceManager.addService(PAC_SERVICE_NAME, binder); mProxyService = IProxyService.Stub.asInterface(binder); if (mProxyService == null) { Log.e(TAG, "No proxy service"); @@ -262,13 +265,27 @@ public class PacManager { } } }; - Log.e(TAG, "Attempting to bind"); mContext.bindService(intent, mConnection, Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND | Context.BIND_NOT_VISIBLE); + + intent = new Intent(); + intent.setClassName(PROXY_PACKAGE, PROXY_SERVICE); + mProxyConnection = new ServiceConnection() { + @Override + public void onServiceDisconnected(ComponentName component) { + } + + @Override + public void onServiceConnected(ComponentName component, IBinder binder) { + } + }; + mContext.bindService(intent, mProxyConnection, + Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND | Context.BIND_NOT_VISIBLE); } private void unbind() { mContext.unbindService(mConnection); + mContext.unbindService(mProxyConnection); mConnection = null; } } |