summaryrefslogtreecommitdiffstats
path: root/core/jni
diff options
context:
space:
mode:
Diffstat (limited to 'core/jni')
-rw-r--r--core/jni/Android.mk3
-rw-r--r--core/jni/android_emoji_EmojiFactory.cpp87
-rw-r--r--core/jni/android_media_AudioRecord.cpp34
-rw-r--r--core/jni/android_net_wifi_Wifi.cpp7
4 files changed, 66 insertions, 65 deletions
diff --git a/core/jni/Android.mk b/core/jni/Android.mk
index d46dd80..ed8deb1 100644
--- a/core/jni/Android.mk
+++ b/core/jni/Android.mk
@@ -165,8 +165,7 @@ LOCAL_SHARED_LIBRARIES := \
libicui18n \
libicudata \
libmedia \
- libwpa_client \
- libemoji
+ libwpa_client
ifeq ($(BOARD_HAVE_BLUETOOTH),true)
LOCAL_C_INCLUDES += \
diff --git a/core/jni/android_emoji_EmojiFactory.cpp b/core/jni/android_emoji_EmojiFactory.cpp
index 59f63a8..7d6e24f 100644
--- a/core/jni/android_emoji_EmojiFactory.cpp
+++ b/core/jni/android_emoji_EmojiFactory.cpp
@@ -1,7 +1,7 @@
#include "SkTypes.h"
#include "SkImageDecoder.h"
-#define LOG_TAG "DoCoMoEmojiFactory_jni"
+#define LOG_TAG "EmojiFactory_jni"
#include <utils/Log.h>
#include <utils/String8.h>
@@ -13,15 +13,11 @@
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 {
public:
- EmojiFactoryCaller();
+ EmojiFactoryCaller() {}
virtual ~EmojiFactoryCaller();
+ bool Init();
EmojiFactory *TryCallGetImplementation(const char* name);
EmojiFactory *TryCallGetAvailableImplementation();
private:
@@ -30,35 +26,45 @@ class EmojiFactoryCaller {
EmojiFactory *(*m_get_available_implementation)();
};
-EmojiFactoryCaller::EmojiFactoryCaller() {
+bool EmojiFactoryCaller::Init() {
+ const char* error_msg;
m_handle = dlopen("libemoji.so", RTLD_LAZY | RTLD_LOCAL);
- const char* error_str = dlerror();
- if (error_str) {
- LOGI("Failed to load libemoji.so: %s", error_str);
- return;
+
+ if (m_handle == NULL) {
+ error_msg = "Failed to load libemoji.so";
+ goto FAIL;
}
m_get_implementation =
reinterpret_cast<EmojiFactory *(*)(const char*)>(
dlsym(m_handle, "GetImplementation"));
- error_str = dlerror();
- if (error_str) {
- LOGE("Failed to get symbol of GetImplementation: %s", error_str);
- dlclose(m_handle);
- m_handle = NULL;
- return;
+ if (m_get_implementation == NULL) {
+ error_msg = "Failed to get symbol of GetImplementation";
+ goto FAIL;
}
m_get_available_implementation =
reinterpret_cast<EmojiFactory *(*)()>(
dlsym(m_handle,"GetAvailableImplementation"));
- error_str = dlerror();
- if (error_str) {
- LOGE("Failed to get symbol of GetAvailableImplementation: %s", error_str);
+ if (m_get_available_implementation == NULL) {
+ error_msg = "Failed to get symbol of GetAvailableImplementation";
+ 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);
m_handle = NULL;
- return;
}
+ return false;
}
EmojiFactoryCaller::~EmojiFactoryCaller() {
@@ -82,10 +88,9 @@ EmojiFactory *EmojiFactoryCaller::TryCallGetAvailableImplementation() {
return m_get_available_implementation();
}
-// Note: bionic libc's dlopen() does not allow recursive dlopen(). So currently
-// we cannot use EmojiFactoryCaller here.
-// static EmojiFactoryCaller* gCaller;
-// static pthread_once_t g_once = PTHREAD_ONCE_INIT;
+static EmojiFactoryCaller* gCaller;
+static pthread_once_t g_once = PTHREAD_ONCE_INIT;
+static bool lib_emoji_factory_is_ready;
static jclass gString_class;
@@ -95,9 +100,10 @@ static jmethodID gBitmap_constructorMethodID;
static jclass gEmojiFactory_class;
static jmethodID gEmojiFactory_constructorMethodID;
-// static void InitializeCaller() {
-// gCaller = new EmojiFactoryCaller();
-// }
+static void InitializeCaller() {
+ gCaller = new EmojiFactoryCaller();
+ lib_emoji_factory_is_ready = gCaller->Init();
+}
static jobject create_java_EmojiFactory(
JNIEnv* env, EmojiFactory* factory, jstring name) {
@@ -116,19 +122,23 @@ static jobject create_java_EmojiFactory(
static jobject android_emoji_EmojiFactory_newInstance(
JNIEnv* env, jobject clazz, jstring name) {
- // pthread_once(&g_once, InitializeCaller);
-
if (NULL == name) {
return NULL;
}
+ pthread_once(&g_once, InitializeCaller);
+ if (!lib_emoji_factory_is_ready) {
+ return NULL;
+ }
const jchar* jchars = env->GetStringChars(name, NULL);
jsize len = env->GetStringLength(name);
String8 str(String16(jchars, len));
- // EmojiFactory *factory = gCaller->TryCallGetImplementation(str.string());
- EmojiFactory *factory = EmojiFactory::GetImplementation(str.string());
-
+ EmojiFactory *factory = gCaller->TryCallGetImplementation(str.string());
+ // EmojiFactory *factory = EmojiFactory::GetImplementation(str.string());
+ if (NULL == factory) {
+ return NULL;
+ }
env->ReleaseStringChars(name, jchars);
return create_java_EmojiFactory(env, factory, name);
@@ -136,10 +146,13 @@ static jobject android_emoji_EmojiFactory_newInstance(
static jobject android_emoji_EmojiFactory_newAvailableInstance(
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 = EmojiFactory::GetAvailableImplementation();
+ EmojiFactory *factory = gCaller->TryCallGetAvailableImplementation();
+ // EmojiFactory *factory = EmojiFactory::GetAvailableImplementation();
if (NULL == factory) {
return NULL;
}
diff --git a/core/jni/android_media_AudioRecord.cpp b/core/jni/android_media_AudioRecord.cpp
index 288433a..e71e348 100644
--- a/core/jni/android_media_AudioRecord.cpp
+++ b/core/jni/android_media_AudioRecord.cpp
@@ -45,8 +45,6 @@ struct fields_t {
jmethodID postNativeEventInJava; //... event post callback method
int PCM16; //... format constants
int PCM8; //... format constants
- int SOURCE_DEFAULT; //... record source constants
- int SOURCE_MIC; //... record source constants
jfieldID nativeRecorderInJavaObj; // provides access to the C++ AudioRecord object
jfieldID nativeCallbackCookie; // provides access to the AudioRecord callback data
};
@@ -66,7 +64,7 @@ struct audiorecord_callback_cookie {
#define AUDIORECORD_ERROR_SETUP_ZEROFRAMECOUNT -16
#define AUDIORECORD_ERROR_SETUP_INVALIDCHANNELCOUNT -17
#define AUDIORECORD_ERROR_SETUP_INVALIDFORMAT -18
-#define AUDIORECORD_ERROR_SETUP_INVALIDSTREAMTYPE -19
+#define AUDIORECORD_ERROR_SETUP_INVALIDSOURCE -19
#define AUDIORECORD_ERROR_SETUP_NATIVEINITFAILED -20
jint android_media_translateRecorderErrorCode(int code) {
@@ -154,17 +152,16 @@ android_media_AudioRecord_setup(JNIEnv *env, jobject thiz, jobject weak_this,
int frameSize = nbChannels * bytesPerSample;
size_t frameCount = buffSizeInBytes / frameSize;
- // compare the source against the Java constants
- AudioRecord::stream_type arSource;
- if (source == javaAudioRecordFields.SOURCE_DEFAULT) {
- arSource = AudioRecord::DEFAULT_INPUT;
- } else if (source == javaAudioRecordFields.SOURCE_MIC) {
- arSource = AudioRecord::MIC_INPUT;
- } else {
+ // convert and check input source value
+ // input_source values defined in AudioRecord.h are equal to
+ // JAVA MediaRecord.AudioSource values minus 1.
+ AudioRecord::input_source arSource = (AudioRecord::input_source)(source - 1);
+ if (arSource < AudioRecord::DEFAULT_INPUT ||
+ arSource >= AudioRecord::NUM_INPUT_SOURCES) {
LOGE("Error creating AudioRecord: unknown source.");
- return AUDIORECORD_ERROR_SETUP_INVALIDSTREAMTYPE;
+ return AUDIORECORD_ERROR_SETUP_INVALIDSOURCE;
}
-
+
audiorecord_callback_cookie *lpCallbackData = NULL;
AudioRecord* lpRecorder = NULL;
@@ -511,8 +508,6 @@ static JNINativeMethod gMethods[] = {
#define JAVA_POSTEVENT_CALLBACK_NAME "postEventFromNative"
#define JAVA_CONST_PCM16_NAME "ENCODING_PCM_16BIT"
#define JAVA_CONST_PCM8_NAME "ENCODING_PCM_8BIT"
-#define JAVA_CONST_SOURCEDEFAULT_NAME "SOURCE_DEFAULT"
-#define JAVA_CONST_SOURCEMIC_NAME "SOURCE_MIC"
#define JAVA_NATIVERECORDERINJAVAOBJ_FIELD_NAME "mNativeRecorderInJavaObj"
#define JAVA_NATIVECALLBACKINFO_FIELD_NAME "mNativeCallbackCookie"
@@ -583,17 +578,6 @@ int register_android_media_AudioRecord(JNIEnv *env)
return -1;
}
- // Get the recording source constants from the AudioRecord class
- if ( !android_media_getIntConstantFromClass(env, javaAudioRecordFields.audioRecordClass,
- kClassPathName,
- JAVA_CONST_SOURCEDEFAULT_NAME, &(javaAudioRecordFields.SOURCE_DEFAULT))
- || !android_media_getIntConstantFromClass(env, javaAudioRecordFields.audioRecordClass,
- kClassPathName,
- JAVA_CONST_SOURCEMIC_NAME, &(javaAudioRecordFields.SOURCE_MIC)) ) {
- // error log performed in getIntConstantFromClass()
- return -1;
- }
-
return AndroidRuntime::registerNativeMethods(env,
kClassPathName, gMethods, NELEM(gMethods));
}
diff --git a/core/jni/android_net_wifi_Wifi.cpp b/core/jni/android_net_wifi_Wifi.cpp
index 25670df..9f93e2f 100644
--- a/core/jni/android_net_wifi_Wifi.cpp
+++ b/core/jni/android_net_wifi_Wifi.cpp
@@ -317,8 +317,13 @@ static jint android_net_wifi_getRssiCommand(JNIEnv* env, jobject clazz)
}
// reply comes back in the form "<SSID> rssi XX" where XX is the
// number we're interested in. if we're associating, it returns "OK".
+ // beware - <SSID> can contain spaces.
if (strcmp(reply, "OK") != 0) {
- sscanf(reply, "%*s %*s %d", &rssi);
+ char* lastSpace = strrchr(reply, ' ');
+ // lastSpace should be preceded by "rssi" and followed by the value
+ if (lastSpace && !strncmp(lastSpace - 4, "rssi", 4)) {
+ sscanf(lastSpace + 1, "%d", &rssi);
+ }
}
return (jint)rssi;
}