summaryrefslogtreecommitdiff
path: root/packages/services
diff options
context:
space:
mode:
Diffstat (limited to 'packages/services')
-rw-r--r--packages/services/PacProcessor/jni/Android.bp3
-rw-r--r--packages/services/PacProcessor/src/com/android/pacprocessor/LibpacInterface.java34
-rw-r--r--packages/services/PacProcessor/src/com/android/pacprocessor/PacNative.java18
-rw-r--r--packages/services/PacProcessor/src/com/android/pacprocessor/PacService.java17
-rw-r--r--packages/services/PacProcessor/src/com/android/pacprocessor/PacWebView.java48
5 files changed, 107 insertions, 13 deletions
diff --git a/packages/services/PacProcessor/jni/Android.bp b/packages/services/PacProcessor/jni/Android.bp
index 2a94237f2aed..0e7e10152f81 100644
--- a/packages/services/PacProcessor/jni/Android.bp
+++ b/packages/services/PacProcessor/jni/Android.bp
@@ -37,4 +37,7 @@ cc_library_shared {
"-Wunused",
"-Wunreachable-code",
],
+ sanitize: {
+ cfi: true,
+ },
}
diff --git a/packages/services/PacProcessor/src/com/android/pacprocessor/LibpacInterface.java b/packages/services/PacProcessor/src/com/android/pacprocessor/LibpacInterface.java
new file mode 100644
index 000000000000..103ef7811ff0
--- /dev/null
+++ b/packages/services/PacProcessor/src/com/android/pacprocessor/LibpacInterface.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2020 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;
+
+/**
+ * Common interface for both Android's and WebView's implementation of PAC processor.
+ *
+ * @hide
+ */
+interface LibpacInterface {
+ default boolean startPacSupport() {
+ return true;
+ }
+
+ default boolean stopPacSupport() {
+ return true;
+ }
+
+ boolean setCurrentProxyScript(String script);
+ String makeProxyRequest(String url, String host);
+}
diff --git a/packages/services/PacProcessor/src/com/android/pacprocessor/PacNative.java b/packages/services/PacProcessor/src/com/android/pacprocessor/PacNative.java
index 1e8109cb393c..9c0cfc27bd14 100644
--- a/packages/services/PacProcessor/src/com/android/pacprocessor/PacNative.java
+++ b/packages/services/PacProcessor/src/com/android/pacprocessor/PacNative.java
@@ -20,7 +20,7 @@ import android.util.Log;
/**
* @hide
*/
-public class PacNative {
+public class PacNative implements LibpacInterface {
private static final String TAG = "PacProxy";
private static final PacNative sInstance = new PacNative();
@@ -49,34 +49,38 @@ public class PacNative {
return sInstance;
}
+ @Override
public synchronized boolean startPacSupport() {
if (createV8ParserNativeLocked()) {
Log.e(TAG, "Unable to Create v8 Proxy Parser.");
- return true;
+ return false;
}
mIsActive = true;
- return false;
+ return true;
}
+ @Override
public synchronized boolean stopPacSupport() {
if (mIsActive) {
if (destroyV8ParserNativeLocked()) {
Log.e(TAG, "Unable to Destroy v8 Proxy Parser.");
- return true;
+ return false;
}
mIsActive = false;
}
- return false;
+ return true;
}
+ @Override
public synchronized boolean setCurrentProxyScript(String script) {
if (setProxyScriptNativeLocked(script)) {
Log.e(TAG, "Unable to parse proxy script.");
- return true;
+ return false;
}
- return false;
+ return true;
}
+ @Override
public synchronized String makeProxyRequest(String url, String host) {
String ret = makeProxyRequestNativeLocked(url, host);
if ((ret == null) || (ret.length() == 0)) {
diff --git a/packages/services/PacProcessor/src/com/android/pacprocessor/PacService.java b/packages/services/PacProcessor/src/com/android/pacprocessor/PacService.java
index 3c25bfd380f2..5a7de9f70b49 100644
--- a/packages/services/PacProcessor/src/com/android/pacprocessor/PacService.java
+++ b/packages/services/PacProcessor/src/com/android/pacprocessor/PacService.java
@@ -17,6 +17,7 @@ package com.android.pacprocessor;
import android.app.Service;
import android.content.Intent;
+import android.content.res.Resources;
import android.os.Binder;
import android.os.IBinder;
import android.os.Process;
@@ -30,19 +31,24 @@ import java.net.URL;
public class PacService extends Service {
private static final String TAG = "PacService";
+ private static final boolean sUseWebViewPacProcessor = Resources.getSystem().getBoolean(
+ com.android.internal.R.bool.config_useWebViewPacProcessor);
+
+ private final LibpacInterface mLibpac = sUseWebViewPacProcessor
+ ? PacWebView.getInstance()
+ : PacNative.getInstance();
- private PacNative mPacNative = PacNative.getInstance();
private ProxyServiceStub mStub = new ProxyServiceStub();
@Override
public void onCreate() {
super.onCreate();
- mPacNative.startPacSupport();
+ mLibpac.startPacSupport();
}
@Override
public void onDestroy() {
- mPacNative.stopPacSupport();
+ mLibpac.stopPacSupport();
super.onDestroy();
}
@@ -52,7 +58,6 @@ public class PacService extends Service {
}
private class ProxyServiceStub extends IProxyService.Stub {
-
@Override
public String resolvePacFile(String host, String url) throws RemoteException {
try {
@@ -69,7 +74,7 @@ public class PacService extends Service {
throw new IllegalArgumentException("Invalid host was passed");
}
}
- return mPacNative.makeProxyRequest(url, host);
+ return mLibpac.makeProxyRequest(url, host);
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Invalid URL was passed");
}
@@ -81,7 +86,7 @@ public class PacService extends Service {
Log.e(TAG, "Only system user is allowed to call setPacFile");
throw new SecurityException();
}
- mPacNative.setCurrentProxyScript(script);
+ mLibpac.setCurrentProxyScript(script);
}
}
}
diff --git a/packages/services/PacProcessor/src/com/android/pacprocessor/PacWebView.java b/packages/services/PacProcessor/src/com/android/pacprocessor/PacWebView.java
new file mode 100644
index 000000000000..4dd00f1ff01b
--- /dev/null
+++ b/packages/services/PacProcessor/src/com/android/pacprocessor/PacWebView.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2020 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;
+import android.webkit.PacProcessor;
+
+/**
+ * @hide
+ */
+public class PacWebView implements LibpacInterface {
+ private static final String TAG = "PacWebView";
+
+ private static final PacWebView sInstance = new PacWebView();
+ private PacProcessor mProcessor = PacProcessor.getInstance();
+
+ public static PacWebView getInstance() {
+ return sInstance;
+ }
+
+ @Override
+ public synchronized boolean setCurrentProxyScript(String script) {
+ if (!mProcessor.setProxyScript(script)) {
+ Log.e(TAG, "Unable to parse proxy script.");
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public synchronized String makeProxyRequest(String url, String host) {
+ return mProcessor.findProxyForUrl(url);
+ }
+}