Don't try to get the JNIEnv on Android

It's currently not used. More stuff is needed anyway which may need a different
approach.
This commit is contained in:
Chris Robinson
2018-10-02 12:40:26 -07:00
parent 493c8bbc83
commit c39eeb9638
3 changed files with 7 additions and 82 deletions
-69
View File
@@ -1165,75 +1165,6 @@ static void alc_initconfig(void)
}
#define DO_INITCONFIG() alcall_once(&alc_config_once, alc_initconfig)
#ifdef __ANDROID__
#include <jni.h>
static JavaVM *gJavaVM;
static pthread_key_t gJVMThreadKey;
static void CleanupJNIEnv(void* UNUSED(ptr))
{
JCALL0(gJavaVM,DetachCurrentThread)();
}
void *Android_GetJNIEnv(void)
{
if(!gJavaVM)
{
WARN("gJavaVM is NULL!\n");
return NULL;
}
/* http://developer.android.com/guide/practices/jni.html
*
* All threads are Linux threads, scheduled by the kernel. They're usually
* started from managed code (using Thread.start), but they can also be
* created elsewhere and then attached to the JavaVM. For example, a thread
* started with pthread_create can be attached with the JNI
* AttachCurrentThread or AttachCurrentThreadAsDaemon functions. Until a
* thread is attached, it has no JNIEnv, and cannot make JNI calls.
* Attaching a natively-created thread causes a java.lang.Thread object to
* be constructed and added to the "main" ThreadGroup, making it visible to
* the debugger. Calling AttachCurrentThread on an already-attached thread
* is a no-op.
*/
JNIEnv *env = pthread_getspecific(gJVMThreadKey);
if(!env)
{
int status = JCALL(gJavaVM,AttachCurrentThread)(&env, NULL);
if(status < 0)
{
ERR("Failed to attach current thread\n");
return NULL;
}
pthread_setspecific(gJVMThreadKey, env);
}
return env;
}
/* Automatically called by JNI. */
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void* UNUSED(reserved))
{
void *env;
int err;
gJavaVM = jvm;
if(JCALL(gJavaVM,GetEnv)(&env, JNI_VERSION_1_4) != JNI_OK)
{
ERR("Failed to get JNIEnv with JNI_VERSION_1_4\n");
return JNI_ERR;
}
/* Create gJVMThreadKey so we can keep track of the JNIEnv assigned to each
* thread. The JNIEnv *must* be detached before the thread is destroyed.
*/
if((err=pthread_key_create(&gJVMThreadKey, CleanupJNIEnv)) != 0)
ERR("pthread_key_create failed: %d\n", err);
pthread_setspecific(gJVMThreadKey, env);
return JNI_VERSION_1_4;
}
#endif
/************************************************
* Library deinitialization
+7 -5
View File
@@ -391,7 +391,6 @@ static ALCboolean ALCopenslPlayback_reset(ALCopenslPlayback *self)
SLInterfaceID ids[2];
SLboolean reqs[2];
SLresult result;
JNIEnv *env;
if(self->mBufferQueueObj != NULL)
VCALL0(self->mBufferQueueObj,Destroy)();
@@ -401,12 +400,15 @@ static ALCboolean ALCopenslPlayback_reset(ALCopenslPlayback *self)
self->mRing = NULL;
sampleRate = device->Frequency;
if(!(device->Flags&DEVICE_FREQUENCY_REQUEST) && (env=Android_GetJNIEnv()) != NULL)
#if 0
if(!(device->Flags&DEVICE_FREQUENCY_REQUEST))
{
/* FIXME: Disabled until I figure out how to get the Context needed for
* the getSystemService call.
*/
#if 0
JNIEnv *env = Android_GetJNIEnv();
jobject jctx = Android_GetContext();
/* Get necessary stuff for using java.lang.Integer,
* android.content.Context, and android.media.AudioManager.
*/
@@ -442,7 +444,7 @@ static ALCboolean ALCopenslPlayback_reset(ALCopenslPlayback *self)
/* Now make the calls. */
//AudioManager audMgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
strobj = JCALL(env,GetStaticObjectField)(ctx_cls, ctx_audsvc);
jobject audMgr = JCALL(env,CallObjectMethod)(ctx_cls, ctx_getSysSvc, strobj);
jobject audMgr = JCALL(env,CallObjectMethod)(jctx, ctx_getSysSvc, strobj);
strchars = JCALL(env,GetStringUTFChars)(strobj, NULL);
TRACE("Context.getSystemService(%s) = %p\n", strchars, audMgr);
JCALL(env,ReleaseStringUTFChars)(strobj, strchars);
@@ -463,8 +465,8 @@ static ALCboolean ALCopenslPlayback_reset(ALCopenslPlayback *self)
if(!sampleRate) sampleRate = device->Frequency;
else sampleRate = maxu(sampleRate, MIN_OUTPUT_RATE);
#endif
}
#endif
if(sampleRate != device->Frequency)
{
-8
View File
@@ -50,14 +50,6 @@ void CloseLib(void *handle);
void *GetSymbol(void *handle, const char *name);
#endif
#ifdef __ANDROID__
#define JCALL(obj, func) ((*(obj))->func((obj), EXTRACT_VCALL_ARGS
#define JCALL0(obj, func) ((*(obj))->func((obj) EXTRACT_VCALL_ARGS
/** Returns a JNIEnv*. */
void *Android_GetJNIEnv(void);
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif