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
This commit is contained in:
@@ -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. -->
|
||||
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user