summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Monk <jmonk@google.com>2013-08-21 15:57:30 -0400
committerJason Monk <jmonk@google.com>2013-08-22 16:33:26 -0400
commitda205a749fadb3a87357d9bd607f094c7717764a (patch)
tree659b1785d4fb97c342b72cd54f1a602107c56b2a
parent6b223c6a5be788ca28d5d911ab10650be673684b (diff)
downloadframeworks_base-da205a749fadb3a87357d9bd607f094c7717764a.zip
frameworks_base-da205a749fadb3a87357d9bd607f094c7717764a.tar.gz
frameworks_base-da205a749fadb3a87357d9bd607f094c7717764a.tar.bz2
System binds PAC Local Proxy instead of self start
The PAC Local Proxy priviously caught proxy broadcasts and started itself when needed. Now it is bound by the system the same way the pac processing service is started. Bug: 10425091 Change-Id: I746daa21645a11aa18ef464f00c8cb5536d8c86f
-rw-r--r--packages/services/Proxy/AndroidManifest.xml7
-rw-r--r--packages/services/Proxy/src/com/android/proxyhandler/ProxyServer.java24
-rw-r--r--packages/services/Proxy/src/com/android/proxyhandler/ProxyService.java47
-rw-r--r--packages/services/Proxy/src/com/android/proxyhandler/ProxyServiceReceiver.java29
-rw-r--r--services/java/com/android/server/connectivity/PacManager.java31
5 files changed, 57 insertions, 81 deletions
diff --git a/packages/services/Proxy/AndroidManifest.xml b/packages/services/Proxy/AndroidManifest.xml
index 09b8327..bbcd6b9 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 5d8689e..77f3c8c 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 18ed645..cef3659 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 4638def..0000000
--- 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 0b68ff5..c8cc85e 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;
}
}