Jason Monk 602b232a06 Add PAC File support for proxy configuration
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
2013-08-07 21:01:39 -04:00

98 lines
2.3 KiB
C++

#define LOG_TAG "ProxyTesting"
#include <stdint.h>
#include <sys/types.h>
#include <binder/Parcel.h>
#include <binder/IPCThreadState.h>
#include <utils/Errors.h>
#include "IProxyService.h"
#include <utils/Log.h>
#include <private/android_filesystem_config.h>
using namespace android;
String16 BpProxyService::resolveProxies(String16 host, String16 url) {
String16 ret;
return ret;
}
void BpProxyService::setPacFile(String16& scriptContents) {
}
void BpProxyService::startPacSystem() {
}
void BpProxyService::stopPacSystem() {
}
IMPLEMENT_META_INTERFACE(ProxyService, "com.android.net.IProxyService");
status_t BnProxyService::onTransact(
uint32_t code, const Parcel& data,
Parcel* reply, uint32_t flags) {
int returnInt = 0;
switch (code) {
case RESOLVE_PROXIES:
{
CHECK_INTERFACE(IProxyService, data, reply);
String16 host = data.readString16();
String16 url = data.readString16();
String16 response = resolveProxies(host, url);
reply->writeNoException();
reply->writeString16(response);
return NO_ERROR;
} break;
case SET_PAC:
{
CHECK_INTERFACE(IProxyService, data, reply);
if (notSystemUid()) {
returnInt = 1;
} else {
String16 pacFile = data.readString16();
setPacFile(pacFile);
}
reply->writeNoException();
reply->writeInt32(returnInt);
return NO_ERROR;
} break;
case START_PAC:
{
CHECK_INTERFACE(IProxyService, data, reply);
if (notSystemUid()) {
returnInt = 1;
} else {
startPacSystem();
}
reply->writeNoException();
reply->writeInt32(returnInt);
return NO_ERROR;
} break;
case STOP_PAC:
{
CHECK_INTERFACE(IProxyService, data, reply);
if (notSystemUid()) {
returnInt = 1;
} else {
stopPacSystem();
}
reply->writeNoException();
reply->writeInt32(returnInt);
return NO_ERROR;
} break;
default:
return BBinder::onTransact(code, data, reply, flags);
}
}
int BnProxyService::getCallingUid() {
return IPCThreadState::self()->getCallingUid();
}
bool BnProxyService::notSystemUid() {
return getCallingUid() != AID_SYSTEM;
}