summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Malova <amalova@google.com>2020-01-22 14:17:14 +0000
committerAnna Malova <amalova@google.com>2020-02-11 12:54:26 +0000
commit29ed0cc421bcd5dce43d8d8bf2885bc6c2a52ef5 (patch)
treeb2c7c03a209cd95e10656f94aac5ebfe01b47dd5
parent83235861a5e1ae30411acc8105291ded37412b21 (diff)
Implement PacService using WebView's version of libpac.
Add config flag to choose between PacService implementations. Added flag (config_useWebViewPacProcessor) is disabled by default for now. Bug: 148516710 Test: atest DeviceOwnerTest#testProxyPacProxyTest Change-Id: I5d376a2a37f1bfb7ba5268c0088bf4417434b8f5
-rw-r--r--core/res/res/values/config.xml7
-rw-r--r--core/res/res/values/symbols.xml1
-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.java58
6 files changed, 121 insertions, 14 deletions
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index f17cd45cd880..9214ab7e5039 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -244,7 +244,7 @@
correctly use them when installed on your device. Otherwise, keep this disabled
so that applications can still use their own mechanisms. -->
<bool name="config_enableAutoPowerModes">false</bool>
-
+
<!-- Whether (if true) this is a kind of device that can be moved around (eg. phone/laptop),
or (if false) something for which movement is either not measurable or should not count
toward power states (eg. tv/soundbar). -->
@@ -269,6 +269,11 @@
when there's no network connection. If the scan doesn't timeout, use zero -->
<integer name="config_radioScanningTimeout">0</integer>
+ <!-- When true, Android uses the PAC implementation included in WebView to handle
+ networks with PAC scripts.
+ When false, Android's own implementation of libpac is used.-->
+ <bool name ="config_useWebViewPacProcessor">false</bool>
+
<!-- XXXXX NOTE THE FOLLOWING RESOURCES USE THE WRONG NAMING CONVENTION.
Please don't copy them, copy anything else. -->
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 2dd62c176e98..dce22cd0bd39 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -286,6 +286,7 @@
<java-symbol type="bool" name="config_duplicate_port_omadm_wappush" />
<java-symbol type="bool" name="config_disableTransitionAnimation" />
<java-symbol type="bool" name="config_enableAutoPowerModes" />
+ <java-symbol type="bool" name="config_useWebViewPacProcessor" />
<java-symbol type="integer" name="config_autoPowerModeThresholdAngle" />
<java-symbol type="integer" name="config_autoPowerModeAnyMotionSensor" />
<java-symbol type="bool" name="config_autoPowerModePreferWristTilt" />
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 b006d6e1fa7b..7aea721617b9 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);
}
@Override
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..89c466500fef
--- /dev/null
+++ b/packages/services/PacProcessor/src/com/android/pacprocessor/PacWebView.java
@@ -0,0 +1,58 @@
+/*
+ * 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;
+
+import com.android.internal.annotations.GuardedBy;
+
+/**
+ * @hide
+ */
+public class PacWebView implements LibpacInterface {
+ private static final String TAG = "PacWebView";
+
+ private static final PacWebView sInstance = new PacWebView();
+
+ private Object mLock = new Object();
+
+ @GuardedBy("mLock")
+ private PacProcessor mProcessor = PacProcessor.getInstance();
+
+ public static PacWebView getInstance() {
+ return sInstance;
+ }
+
+ @Override
+ public boolean setCurrentProxyScript(String script) {
+ synchronized (mLock) {
+ if (!mProcessor.setProxyScript(script)) {
+ Log.e(TAG, "Unable to parse proxy script.");
+ return false;
+ }
+ return true;
+ }
+ }
+
+ @Override
+ public String makeProxyRequest(String url, String host) {
+ synchronized (mLock) {
+ return mProcessor.findProxyForUrl(url);
+ }
+ }
+}