Merge change 2432 into donut
* changes: Make android_runtime to not include libemoji but use dlopen() instead. This must be submitted with change 2432
This commit is contained in:
@@ -165,8 +165,7 @@ LOCAL_SHARED_LIBRARIES := \
|
|||||||
libicui18n \
|
libicui18n \
|
||||||
libicudata \
|
libicudata \
|
||||||
libmedia \
|
libmedia \
|
||||||
libwpa_client \
|
libwpa_client
|
||||||
libemoji
|
|
||||||
|
|
||||||
ifeq ($(BOARD_HAVE_BLUETOOTH),true)
|
ifeq ($(BOARD_HAVE_BLUETOOTH),true)
|
||||||
LOCAL_C_INCLUDES += \
|
LOCAL_C_INCLUDES += \
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "SkTypes.h"
|
#include "SkTypes.h"
|
||||||
#include "SkImageDecoder.h"
|
#include "SkImageDecoder.h"
|
||||||
|
|
||||||
#define LOG_TAG "DoCoMoEmojiFactory_jni"
|
#define LOG_TAG "EmojiFactory_jni"
|
||||||
#include <utils/Log.h>
|
#include <utils/Log.h>
|
||||||
#include <utils/String8.h>
|
#include <utils/String8.h>
|
||||||
|
|
||||||
@@ -13,15 +13,11 @@
|
|||||||
|
|
||||||
namespace android {
|
namespace android {
|
||||||
|
|
||||||
// Note: This class is originally developed so that libandroid_runtime does
|
|
||||||
// not have to depend on libemoji which is optional library. However, we
|
|
||||||
// cannot use this class, since current (2009-02-16) bionic libc does not allow
|
|
||||||
// dlopen()-ing inside dlopen(), while not only this class but also libemoji
|
|
||||||
// uses dlopen().
|
|
||||||
class EmojiFactoryCaller {
|
class EmojiFactoryCaller {
|
||||||
public:
|
public:
|
||||||
EmojiFactoryCaller();
|
EmojiFactoryCaller() {}
|
||||||
virtual ~EmojiFactoryCaller();
|
virtual ~EmojiFactoryCaller();
|
||||||
|
bool Init();
|
||||||
EmojiFactory *TryCallGetImplementation(const char* name);
|
EmojiFactory *TryCallGetImplementation(const char* name);
|
||||||
EmojiFactory *TryCallGetAvailableImplementation();
|
EmojiFactory *TryCallGetAvailableImplementation();
|
||||||
private:
|
private:
|
||||||
@@ -30,35 +26,45 @@ class EmojiFactoryCaller {
|
|||||||
EmojiFactory *(*m_get_available_implementation)();
|
EmojiFactory *(*m_get_available_implementation)();
|
||||||
};
|
};
|
||||||
|
|
||||||
EmojiFactoryCaller::EmojiFactoryCaller() {
|
bool EmojiFactoryCaller::Init() {
|
||||||
|
const char* error_msg;
|
||||||
m_handle = dlopen("libemoji.so", RTLD_LAZY | RTLD_LOCAL);
|
m_handle = dlopen("libemoji.so", RTLD_LAZY | RTLD_LOCAL);
|
||||||
const char* error_str = dlerror();
|
|
||||||
if (error_str) {
|
if (m_handle == NULL) {
|
||||||
LOGI("Failed to load libemoji.so: %s", error_str);
|
error_msg = "Failed to load libemoji.so";
|
||||||
return;
|
goto FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_get_implementation =
|
m_get_implementation =
|
||||||
reinterpret_cast<EmojiFactory *(*)(const char*)>(
|
reinterpret_cast<EmojiFactory *(*)(const char*)>(
|
||||||
dlsym(m_handle, "GetImplementation"));
|
dlsym(m_handle, "GetImplementation"));
|
||||||
error_str = dlerror();
|
if (m_get_implementation == NULL) {
|
||||||
if (error_str) {
|
error_msg = "Failed to get symbol of GetImplementation";
|
||||||
LOGE("Failed to get symbol of GetImplementation: %s", error_str);
|
goto FAIL;
|
||||||
dlclose(m_handle);
|
|
||||||
m_handle = NULL;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_get_available_implementation =
|
m_get_available_implementation =
|
||||||
reinterpret_cast<EmojiFactory *(*)()>(
|
reinterpret_cast<EmojiFactory *(*)()>(
|
||||||
dlsym(m_handle,"GetAvailableImplementation"));
|
dlsym(m_handle,"GetAvailableImplementation"));
|
||||||
error_str = dlerror();
|
if (m_get_available_implementation == NULL) {
|
||||||
if (error_str) {
|
error_msg = "Failed to get symbol of GetAvailableImplementation";
|
||||||
LOGE("Failed to get symbol of GetAvailableImplementation: %s", error_str);
|
goto FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
FAIL:
|
||||||
|
const char* error_str = dlerror();
|
||||||
|
if (error_str == NULL) {
|
||||||
|
error_str = "unknown reason";
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGE("%s: %s", error_msg, error_str);
|
||||||
|
if (m_handle != NULL) {
|
||||||
dlclose(m_handle);
|
dlclose(m_handle);
|
||||||
m_handle = NULL;
|
m_handle = NULL;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
EmojiFactoryCaller::~EmojiFactoryCaller() {
|
EmojiFactoryCaller::~EmojiFactoryCaller() {
|
||||||
@@ -82,10 +88,9 @@ EmojiFactory *EmojiFactoryCaller::TryCallGetAvailableImplementation() {
|
|||||||
return m_get_available_implementation();
|
return m_get_available_implementation();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: bionic libc's dlopen() does not allow recursive dlopen(). So currently
|
static EmojiFactoryCaller* gCaller;
|
||||||
// we cannot use EmojiFactoryCaller here.
|
static pthread_once_t g_once = PTHREAD_ONCE_INIT;
|
||||||
// static EmojiFactoryCaller* gCaller;
|
static bool lib_emoji_factory_is_ready;
|
||||||
// static pthread_once_t g_once = PTHREAD_ONCE_INIT;
|
|
||||||
|
|
||||||
static jclass gString_class;
|
static jclass gString_class;
|
||||||
|
|
||||||
@@ -95,9 +100,10 @@ static jmethodID gBitmap_constructorMethodID;
|
|||||||
static jclass gEmojiFactory_class;
|
static jclass gEmojiFactory_class;
|
||||||
static jmethodID gEmojiFactory_constructorMethodID;
|
static jmethodID gEmojiFactory_constructorMethodID;
|
||||||
|
|
||||||
// static void InitializeCaller() {
|
static void InitializeCaller() {
|
||||||
// gCaller = new EmojiFactoryCaller();
|
gCaller = new EmojiFactoryCaller();
|
||||||
// }
|
lib_emoji_factory_is_ready = gCaller->Init();
|
||||||
|
}
|
||||||
|
|
||||||
static jobject create_java_EmojiFactory(
|
static jobject create_java_EmojiFactory(
|
||||||
JNIEnv* env, EmojiFactory* factory, jstring name) {
|
JNIEnv* env, EmojiFactory* factory, jstring name) {
|
||||||
@@ -116,19 +122,23 @@ static jobject create_java_EmojiFactory(
|
|||||||
|
|
||||||
static jobject android_emoji_EmojiFactory_newInstance(
|
static jobject android_emoji_EmojiFactory_newInstance(
|
||||||
JNIEnv* env, jobject clazz, jstring name) {
|
JNIEnv* env, jobject clazz, jstring name) {
|
||||||
// pthread_once(&g_once, InitializeCaller);
|
|
||||||
|
|
||||||
if (NULL == name) {
|
if (NULL == name) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
pthread_once(&g_once, InitializeCaller);
|
||||||
|
if (!lib_emoji_factory_is_ready) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
const jchar* jchars = env->GetStringChars(name, NULL);
|
const jchar* jchars = env->GetStringChars(name, NULL);
|
||||||
jsize len = env->GetStringLength(name);
|
jsize len = env->GetStringLength(name);
|
||||||
String8 str(String16(jchars, len));
|
String8 str(String16(jchars, len));
|
||||||
|
|
||||||
// EmojiFactory *factory = gCaller->TryCallGetImplementation(str.string());
|
EmojiFactory *factory = gCaller->TryCallGetImplementation(str.string());
|
||||||
EmojiFactory *factory = EmojiFactory::GetImplementation(str.string());
|
// EmojiFactory *factory = EmojiFactory::GetImplementation(str.string());
|
||||||
|
if (NULL == factory) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
env->ReleaseStringChars(name, jchars);
|
env->ReleaseStringChars(name, jchars);
|
||||||
|
|
||||||
return create_java_EmojiFactory(env, factory, name);
|
return create_java_EmojiFactory(env, factory, name);
|
||||||
@@ -136,10 +146,13 @@ static jobject android_emoji_EmojiFactory_newInstance(
|
|||||||
|
|
||||||
static jobject android_emoji_EmojiFactory_newAvailableInstance(
|
static jobject android_emoji_EmojiFactory_newAvailableInstance(
|
||||||
JNIEnv* env, jobject clazz) {
|
JNIEnv* env, jobject clazz) {
|
||||||
// pthread_once(&g_once, InitializeCaller);
|
pthread_once(&g_once, InitializeCaller);
|
||||||
|
if (!lib_emoji_factory_is_ready) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// EmojiFactory *factory = gCaller->TryCallGetAvailableImplementation();
|
EmojiFactory *factory = gCaller->TryCallGetAvailableImplementation();
|
||||||
EmojiFactory *factory = EmojiFactory::GetAvailableImplementation();
|
// EmojiFactory *factory = EmojiFactory::GetAvailableImplementation();
|
||||||
if (NULL == factory) {
|
if (NULL == factory) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user