summaryrefslogtreecommitdiffstats
path: root/packages/services/PacProcessor/src
diff options
context:
space:
mode:
authorJason Monk <jmonk@google.com>2013-08-12 16:42:38 -0400
committerJason Monk <jmonk@google.com>2013-08-20 17:36:39 -0400
commit9ced3cd9d6ea414523051ec872fffc68f5fdbf08 (patch)
tree22d49c8bde1a17da9c9ff1588a3af3e176d0173a /packages/services/PacProcessor/src
parent58514937628dfcf3b2949e4cbc45d5526ecb8019 (diff)
downloadframeworks_base-9ced3cd9d6ea414523051ec872fffc68f5fdbf08.zip
frameworks_base-9ced3cd9d6ea414523051ec872fffc68f5fdbf08.tar.gz
frameworks_base-9ced3cd9d6ea414523051ec872fffc68f5fdbf08.tar.bz2
Change PacProcessor to Android Service
This switches the PacProcessor over to an Android Service. The service is bound and unbound by the PacManager, which also adds it to the ServiceManager, allowing for Context-Free access by the PacProxySelector in all DVMs. bug:10182711 Change-Id: Id1ff7660be56e8976cdcccd76e041feb47a17a61
Diffstat (limited to 'packages/services/PacProcessor/src')
-rw-r--r--packages/services/PacProcessor/src/com/android/pacprocessor/PacNative.java86
-rw-r--r--packages/services/PacProcessor/src/com/android/pacprocessor/PacService.java101
2 files changed, 187 insertions, 0 deletions
diff --git a/packages/services/PacProcessor/src/com/android/pacprocessor/PacNative.java b/packages/services/PacProcessor/src/com/android/pacprocessor/PacNative.java
new file mode 100644
index 0000000..c67fe9f
--- /dev/null
+++ b/packages/services/PacProcessor/src/com/android/pacprocessor/PacNative.java
@@ -0,0 +1,86 @@
+/**
+ * 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.pacprocessor;
+
+import android.util.Log;
+
+/**
+ * @hide
+ */
+public class PacNative {
+ private static final String TAG = "PacProxy";
+
+ private String mCurrentPac;
+
+ private boolean mIsActive;
+
+ // Only make native calls from inside synchronized blocks.
+ private native boolean createV8ParserNativeLocked();
+ private native boolean destroyV8ParserNativeLocked();
+
+ private native boolean setProxyScriptNativeLocked(String script);
+
+ private native String makeProxyRequestNativeLocked(String url, String host);
+
+ static {
+ System.loadLibrary("jni_pacprocessor");
+ }
+
+ PacNative() {
+
+ }
+
+ public synchronized boolean startPacSupport() {
+ if (createV8ParserNativeLocked()) {
+ Log.e(TAG, "Unable to Create v8 Proxy Parser.");
+ return true;
+ }
+ mIsActive = true;
+ return false;
+ }
+
+ public synchronized boolean stopPacSupport() {
+ if (mIsActive) {
+ if (destroyV8ParserNativeLocked()) {
+ Log.e(TAG, "Unable to Destroy v8 Proxy Parser.");
+ return true;
+ }
+ mIsActive = false;
+ }
+ return false;
+ }
+
+ public synchronized boolean setCurrentProxyScript(String script) {
+ if (setProxyScriptNativeLocked(script)) {
+ Log.e(TAG, "Unable to parse proxy script.");
+ return true;
+ }
+ return false;
+ }
+
+ public synchronized String makeProxyRequest(String url, String host) {
+ String ret = makeProxyRequestNativeLocked(url, host);
+ if ((ret == null) || (ret.length() == 0)) {
+ Log.e(TAG, "v8 Proxy request failed.");
+ ret = null;
+ }
+ return ret;
+ }
+
+ public synchronized boolean isActive() {
+ return mIsActive;
+ }
+}
diff --git a/packages/services/PacProcessor/src/com/android/pacprocessor/PacService.java b/packages/services/PacProcessor/src/com/android/pacprocessor/PacService.java
new file mode 100644
index 0000000..7e76025
--- /dev/null
+++ b/packages/services/PacProcessor/src/com/android/pacprocessor/PacService.java
@@ -0,0 +1,101 @@
+/**
+ * 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.pacprocessor;
+
+import android.app.Service;
+import android.content.Intent;
+import android.os.Binder;
+import android.os.IBinder;
+import android.os.Process;
+import android.os.RemoteException;
+import android.util.Log;
+
+import com.android.net.IProxyService;
+
+public class PacService extends Service {
+ private static final String TAG = "PacService";
+
+ private PacNative mPacNative;
+ private ProxyServiceStub mStub;
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ if (mPacNative == null) {
+ mPacNative = new PacNative();
+ mStub = new ProxyServiceStub(mPacNative);
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ if (mPacNative != null) {
+ mPacNative.stopPacSupport();
+ mPacNative = null;
+ mStub = null;
+ }
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ if (mPacNative == null) {
+ mPacNative = new PacNative();
+ mStub = new ProxyServiceStub(mPacNative);
+ }
+ return mStub;
+ }
+
+ private static class ProxyServiceStub extends IProxyService.Stub {
+ private final PacNative mPacNative;
+
+ public ProxyServiceStub(PacNative pacNative) {
+ mPacNative = pacNative;
+ }
+
+ @Override
+ public String resolvePacFile(String host, String url) throws RemoteException {
+ return mPacNative.makeProxyRequest(url, host);
+ }
+
+ @Override
+ public void setPacFile(String script) throws RemoteException {
+ if (Binder.getCallingUid() != Process.SYSTEM_UID) {
+ Log.e(TAG, "Only system user is allowed to call setPacFile");
+ throw new SecurityException();
+ }
+ mPacNative.setCurrentProxyScript(script);
+ }
+
+ @Override
+ public void startPacSystem() throws RemoteException {
+ if (Binder.getCallingUid() != Process.SYSTEM_UID) {
+ Log.e(TAG, "Only system user is allowed to call startPacSystem");
+ throw new SecurityException();
+ }
+ mPacNative.startPacSupport();
+ }
+
+ @Override
+ public void stopPacSystem() throws RemoteException {
+ if (Binder.getCallingUid() != Process.SYSTEM_UID) {
+ Log.e(TAG, "Only system user is allowed to call stopPacSystem");
+ throw new SecurityException();
+ }
+ mPacNative.stopPacSupport();
+ }
+ }
+}