Loading packages/services/PacProcessor/jni/com_android_pacprocessor_PacNative.cpp +11 −9 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ #define LOG_TAG "PacProcessor" #include <stdlib.h> #include <string> #include <utils/Log.h> Loading @@ -25,11 +26,11 @@ #include "jni.h" #include <nativehelper/JNIHelp.h> #include "proxy_resolver_v8.h" #include "proxy_resolver_v8_wrapper.h" namespace android { net::ProxyResolverV8* proxyResolver = NULL; ProxyResolverV8Handle* proxyResolver = NULL; bool pacSet = false; std::u16string jstringToString16(JNIEnv* env, jstring jstr) { Loading @@ -50,7 +51,7 @@ jstring string16ToJstring(JNIEnv* env, std::u16string string) { static jboolean com_android_pacprocessor_PacNative_createV8ParserNativeLocked(JNIEnv* /* env */, jobject) { if (proxyResolver == NULL) { proxyResolver = new net::ProxyResolverV8(net::ProxyResolverJSBindings::CreateDefault()); proxyResolver = ProxyResolverV8Handle_new(); pacSet = false; return JNI_FALSE; } Loading @@ -60,7 +61,7 @@ static jboolean com_android_pacprocessor_PacNative_createV8ParserNativeLocked(JN static jboolean com_android_pacprocessor_PacNative_destroyV8ParserNativeLocked(JNIEnv* /* env */, jobject) { if (proxyResolver != NULL) { delete proxyResolver; ProxyResolverV8Handle_delete(proxyResolver); proxyResolver = NULL; return JNI_FALSE; } Loading @@ -76,7 +77,7 @@ static jboolean com_android_pacprocessor_PacNative_setProxyScriptNativeLocked(JN return JNI_TRUE; } if (proxyResolver->SetPacScript(script16) != OK) { if (ProxyResolverV8Handle_SetPacScript(proxyResolver, script16.data()) != OK) { ALOGE("Unable to set PAC script"); return JNI_TRUE; } Loading @@ -89,7 +90,6 @@ static jstring com_android_pacprocessor_PacNative_makeProxyRequestNativeLocked(J jstring url, jstring host) { std::u16string url16 = jstringToString16(env, url); std::u16string host16 = jstringToString16(env, host); std::u16string ret; if (proxyResolver == NULL) { ALOGE("V8 Parser not initialized when running PAC script"); Loading @@ -101,12 +101,14 @@ static jstring com_android_pacprocessor_PacNative_makeProxyRequestNativeLocked(J return NULL; } if (proxyResolver->GetProxyForURL(url16, host16, &ret) != OK) { String8 ret8(ret.data()); ALOGE("Error Running PAC: %s", ret8.string()); std::unique_ptr<char16_t, decltype(&free)> result = std::unique_ptr<char16_t, decltype(&free)>( ProxyResolverV8Handle_GetProxyForURL(proxyResolver, url16.data(), host16.data()), &free); if (result.get() == NULL) { ALOGE("Error Running PAC"); return NULL; } std::u16string ret(result.get()); jstring jret = string16ToJstring(env, ret); return jret; Loading Loading
packages/services/PacProcessor/jni/com_android_pacprocessor_PacNative.cpp +11 −9 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ #define LOG_TAG "PacProcessor" #include <stdlib.h> #include <string> #include <utils/Log.h> Loading @@ -25,11 +26,11 @@ #include "jni.h" #include <nativehelper/JNIHelp.h> #include "proxy_resolver_v8.h" #include "proxy_resolver_v8_wrapper.h" namespace android { net::ProxyResolverV8* proxyResolver = NULL; ProxyResolverV8Handle* proxyResolver = NULL; bool pacSet = false; std::u16string jstringToString16(JNIEnv* env, jstring jstr) { Loading @@ -50,7 +51,7 @@ jstring string16ToJstring(JNIEnv* env, std::u16string string) { static jboolean com_android_pacprocessor_PacNative_createV8ParserNativeLocked(JNIEnv* /* env */, jobject) { if (proxyResolver == NULL) { proxyResolver = new net::ProxyResolverV8(net::ProxyResolverJSBindings::CreateDefault()); proxyResolver = ProxyResolverV8Handle_new(); pacSet = false; return JNI_FALSE; } Loading @@ -60,7 +61,7 @@ static jboolean com_android_pacprocessor_PacNative_createV8ParserNativeLocked(JN static jboolean com_android_pacprocessor_PacNative_destroyV8ParserNativeLocked(JNIEnv* /* env */, jobject) { if (proxyResolver != NULL) { delete proxyResolver; ProxyResolverV8Handle_delete(proxyResolver); proxyResolver = NULL; return JNI_FALSE; } Loading @@ -76,7 +77,7 @@ static jboolean com_android_pacprocessor_PacNative_setProxyScriptNativeLocked(JN return JNI_TRUE; } if (proxyResolver->SetPacScript(script16) != OK) { if (ProxyResolverV8Handle_SetPacScript(proxyResolver, script16.data()) != OK) { ALOGE("Unable to set PAC script"); return JNI_TRUE; } Loading @@ -89,7 +90,6 @@ static jstring com_android_pacprocessor_PacNative_makeProxyRequestNativeLocked(J jstring url, jstring host) { std::u16string url16 = jstringToString16(env, url); std::u16string host16 = jstringToString16(env, host); std::u16string ret; if (proxyResolver == NULL) { ALOGE("V8 Parser not initialized when running PAC script"); Loading @@ -101,12 +101,14 @@ static jstring com_android_pacprocessor_PacNative_makeProxyRequestNativeLocked(J return NULL; } if (proxyResolver->GetProxyForURL(url16, host16, &ret) != OK) { String8 ret8(ret.data()); ALOGE("Error Running PAC: %s", ret8.string()); std::unique_ptr<char16_t, decltype(&free)> result = std::unique_ptr<char16_t, decltype(&free)>( ProxyResolverV8Handle_GetProxyForURL(proxyResolver, url16.data(), host16.data()), &free); if (result.get() == NULL) { ALOGE("Error Running PAC"); return NULL; } std::u16string ret(result.get()); jstring jret = string16ToJstring(env, ret); return jret; Loading