PAC (Proxy auto-config) files contain a single javascript function, FindProxyForURL(url, host). It gets called to determine what proxy should be used for a specific request. This adds PAC support to the system. The ProxyProperties has been modified to hold the PAC file when one is present. The Proxy method setHttpProxySystemProperty has been modified to insert a PacProxySelector as the default ProxySelector when it is required. This new ProxySelector makes calls to the ConnectivityService to parse the PAC file. The ConnectivityService and the WifiConfigStore have been modified to support saving the extra PAC file data. The ConnectivityService now has a class attached (PacProxyNative) that interfaces to the native calls for PAC files. The parsing of the PAC file is handled by libpac (which is being added to external/) which utilizes libv8 to parse the javascript. As a fallback to applications that don't use the java ProxySelector, the proxy is setup to point to a local proxy server that will handle the pac parsing. bug:10182711 Change-Id: I5eb8df893c632fd3e1b732385cb7720ad646f401
97 lines
2.3 KiB
C++
97 lines
2.3 KiB
C++
#define LOG_TAG "ProxyService"
|
|
#include <utils/Log.h>
|
|
|
|
#include <errno.h>
|
|
#include <utils/threads.h>
|
|
#include <binder/IServiceManager.h>
|
|
#include <binder/IPCThreadState.h>
|
|
#include <sys/stat.h>
|
|
#include <proxy_resolver_v8.h>
|
|
#include <sstream>
|
|
|
|
#include "ProxyService.h"
|
|
|
|
using namespace net;
|
|
|
|
using namespace android;
|
|
|
|
class ProxyErrorLogger : public ProxyErrorListener {
|
|
protected:
|
|
~ProxyErrorLogger() {
|
|
|
|
}
|
|
public:
|
|
void AlertMessage(String16 message) {
|
|
String8 str(message);
|
|
ALOGD("Alert: %s", str.string());
|
|
}
|
|
void ErrorMessage(String16 message) {
|
|
String8 str(message);
|
|
ALOGE("Error: %s", str.string());
|
|
}
|
|
};
|
|
|
|
void ProxyService::instantiate() {
|
|
ALOGV("instantiate");
|
|
defaultServiceManager()->addService(String16("com.android.net.IProxyService"),
|
|
new ProxyService());
|
|
}
|
|
|
|
ProxyService::ProxyService() {
|
|
hasSetScript = false;
|
|
}
|
|
|
|
ProxyService::~ProxyService() {
|
|
stopPacSystem();
|
|
}
|
|
|
|
String16 ProxyService::resolveProxies(String16 host, String16 url) {
|
|
ALOGV("resolve");
|
|
String16 blankRet;
|
|
if (proxyResolver != NULL) {
|
|
if (hasSetScript) {
|
|
String16 ret;
|
|
if (proxyResolver->GetProxyForURL(url, host, &ret) != OK) {
|
|
return blankRet;
|
|
}
|
|
return ret;
|
|
} else {
|
|
ALOGD("Unable to resolve PAC when no script is set!");
|
|
}
|
|
} else {
|
|
ALOGE("Cannot parse while resolver not initialized!");
|
|
}
|
|
return blankRet;
|
|
}
|
|
|
|
void ProxyService::setPacFile(String16& scriptContents) {
|
|
ALOGV("set");
|
|
if (proxyResolver != NULL) {
|
|
if (proxyResolver->SetPacScript(scriptContents) != OK) {
|
|
ALOGD("Unable to initialize PAC - Resolving will not work");
|
|
} else {
|
|
hasSetScript = true;
|
|
}
|
|
} else {
|
|
ALOGE("PAC script set while resolver not initialized!");
|
|
}
|
|
}
|
|
|
|
void ProxyService::startPacSystem() {
|
|
ALOGV("start");
|
|
// Stop in case redundant start call
|
|
stopPacSystem();
|
|
|
|
proxyResolver = new ProxyResolverV8(ProxyResolverJSBindings::CreateDefault(),
|
|
new ProxyErrorLogger());
|
|
hasSetScript = false;
|
|
}
|
|
|
|
void ProxyService::stopPacSystem() {
|
|
ALOGV("stop");
|
|
if (proxyResolver != NULL) {
|
|
delete proxyResolver;
|
|
proxyResolver = NULL;
|
|
}
|
|
}
|