// Display the android virtual keyboard. static void displayKeyboard(android_app* state, bool show) { // The following functions is supposed to show / hide functins from a native activity.. but currently do not work. // ANativeActivity_showSoftInput(state->activity, ANATIVEACTIVITY_SHOW_SOFT_INPUT_IMPLICIT); // ANativeActivity_hideSoftInput(state->activity, ANATIVEACTIVITY_HIDE_SOFT_INPUT_IMPLICIT_ONLY); // Show or hide the keyboard by calling the appropriate Java method through JNI instead. jint result; jint flags = 0; JavaVM* jvm = state->activity->vm; JNIEnv* env; jvm->GetEnv((void **)&env, JNI_VERSION_1_6); jvm->AttachCurrentThread(&env, NULL); if (result == JNI_ERR) { return; } // Retrieves NativeActivity. jobject lNativeActivity = state->activity->clazz; jclass ClassNativeActivity = env->GetObjectClass(lNativeActivity); // Retrieves Context.INPUT_METHOD_SERVICE. jclass ClassContext = env->FindClass("android/content/Context"); jfieldID FieldINPUT_METHOD_SERVICE = env->GetStaticFieldID(ClassContext, "INPUT_METHOD_SERVICE", "Ljava/lang/String;"); jobject INPUT_METHOD_SERVICE = env->GetStaticObjectField(ClassContext, FieldINPUT_METHOD_SERVICE); // Runs getSystemService(Context.INPUT_METHOD_SERVICE). jclass ClassInputMethodManager = env->FindClass("android/view/inputmethod/InputMethodManager"); jmethodID MethodGetSystemService = env->GetMethodID(ClassNativeActivity, "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;"); jobject lInputMethodManager = env->CallObjectMethod(lNativeActivity, MethodGetSystemService, INPUT_METHOD_SERVICE); // Runs getWindow().getDecorView(). jmethodID MethodGetWindow = env->GetMethodID(ClassNativeActivity, "getWindow", "()Landroid/view/Window;"); jobject lWindow = env->CallObjectMethod(lNativeActivity, MethodGetWindow); jclass ClassWindow = env->FindClass("android/view/Window"); jmethodID MethodGetDecorView = env->GetMethodID(ClassWindow, "getDecorView", "()Landroid/view/View;"); jobject lDecorView = env->CallObjectMethod(lWindow, MethodGetDecorView); if (show) { // Runs lInputMethodManager.showSoftInput(...). jmethodID MethodShowSoftInput = env->GetMethodID( ClassInputMethodManager, "showSoftInput", "(Landroid/view/View;I)Z"); jboolean result = env->CallBooleanMethod(lInputMethodManager, MethodShowSoftInput, lDecorView, flags); } else { // Runs lWindow.getViewToken() jclass ClassView = env->FindClass("android/view/View"); jmethodID MethodGetWindowToken = env->GetMethodID(ClassView, "getWindowToken", "()Landroid/os/IBinder;"); jobject lBinder = env->CallObjectMethod(lDecorView, MethodGetWindowToken); // lInputMethodManager.hideSoftInput(...). jmethodID MethodHideSoftInput = env->GetMethodID(ClassInputMethodManager, "hideSoftInputFromWindow", "(Landroid/os/IBinder;I)Z"); jboolean lRes = env->CallBooleanMethod( lInputMethodManager, MethodHideSoftInput, lBinder, flags); } // Finished with the JVM. jvm->DetachCurrentThread(); }
void JniManager::toProcessRequest(jobject obj, MonoObject* processRequest) { JNIEnv* env = getEnv(); MonoDomain* monoDomain = getMonoDomain(); string c_assemblyName = typeConverter->convertToC<string>(env, env->CallObjectMethod(obj, getAssemblyName, "()Ljava/lang/String;")); string c_assemblyPath = typeConverter->convertToC<string>(env, env->CallObjectMethod(obj, getAssemblyPath, "()Ljava/lang/String;")); string c_methodName = typeConverter->convertToC<string>(env, env->CallObjectMethod(obj, getMethodName, "()Ljava/lang/String;")); MonoString* assemblyName = mono_string_new(monoDomain, c_assemblyName.c_str()); MonoString* assemblyPath = mono_string_new(monoDomain, c_assemblyPath.c_str()); MonoString* methodName = mono_string_new(monoDomain, c_methodName.c_str()); bool fullTrust = env->CallBooleanMethod(obj, getFullTrust); bool isSingleton = env->CallBooleanMethod(obj, getIsSingleton); bool log = env->CallBooleanMethod(obj, getLog); bool notifyEvents = env->CallBooleanMethod(obj, getNotifyEvents); MonoObject* exception = NULL; void* args[1]; args[0] = assemblyName; mono_runtime_invoke(setAssemblyNameField, processRequest, args, &exception); args[0] = assemblyPath; mono_runtime_invoke(setAssemblyPathField, processRequest, args, &exception); args[0] = methodName; mono_runtime_invoke(setMethodNameField, processRequest, args, &exception); args[0] = &fullTrust; mono_runtime_invoke(setFullTrustField, processRequest, args, &exception); args[0] = &log; mono_runtime_invoke(setLogField, processRequest, args, &exception); args[0] = &isSingleton; mono_runtime_invoke(setIsSingletonField, processRequest, args, &exception); args[0] = ¬ifyEvents; mono_runtime_invoke(setNotifyEventsField, processRequest, args, &exception); if (exception) { const char* message = mono_string_to_utf8(mono_object_to_string(exception, NULL)); throwException(message); } jobject javaMethodArguments = env->CallObjectMethod(obj, getMethodArguments); setProperties(env, javaMethodArguments, addMethodArgumentsProperty, processRequest); //request->MethodArguments = typeConverter->convertToC<Dictionary<String^, Object^>^>(env, env->CallObjectMethod(obj, getMethodArguments)); //request->InboundProperties = typeConverter->convertToC<Dictionary<String^, Object^>^>(env, env->CallObjectMethod(obj, getInboundProperties)); //request->InvocationProperties = typeConverter->convertToC<Dictionary<String^, Object^>^>(env, env->CallObjectMethod(obj, getInvocationProperties)); //request->OutboundProperties = typeConverter->convertToC<Dictionary<String^, Object^>^>(env, env->CallObjectMethod(obj, getOutboundProperties)); //request->SessionProperties = typeConverter->convertToC<Dictionary<String^, Object^>^>(env, env->CallObjectMethod(obj, getSessionProperties)); }
bool Jipopt::get_list_of_nonlinear_variables(Index num_nonlin_vars,Index* pos_nonlin_vars) { if( using_LBFGS ) { jintArray pos_nonlin_vars_j = env->NewIntArray(num_nonlin_vars); if( !env->CallBooleanMethod(solver, get_list_of_nonlinear_variables_, num_nonlin_vars, pos_nonlin_vars_j) ) return false; if( pos_nonlin_vars != NULL ) { if( sizeof(jint) == sizeof(Index) ) { env->GetIntArrayRegion(pos_nonlin_vars_j, 0, num_nonlin_vars, reinterpret_cast<jint*>(pos_nonlin_vars)); } else { jint* tmp = new int[num_nonlin_vars]; env->GetIntArrayRegion(pos_nonlin_vars_j, 0, num_nonlin_vars, tmp); for( int i = 0; i < num_nonlin_vars; ++i ) pos_nonlin_vars[i] = (Index)tmp[i]; delete[] tmp; } } return true; } return false; }
bool Jipopt::get_starting_point(Index n, bool init_x, Number* x, bool init_z, Number* z_L, Number* z_U, Index m, bool init_lambda, Number* lambda) { jdoubleArray xj = this->xj; jdoubleArray z_lj = this->mult_x_Lj; jdoubleArray z_uj = this->mult_x_Uj; jdoubleArray lambdaj = this->mult_gj; if( !env->CallBooleanMethod(solver, get_starting_point_, n, init_x, xj, init_z, z_lj, z_uj, m, init_lambda, lambdaj) ) return false; /* Copy from Java to native value */ if( init_x ) env->GetDoubleArrayRegion(xj, 0, n, x); if( init_z ) { env->GetDoubleArrayRegion(z_lj, 0, n, z_L); env->GetDoubleArrayRegion(z_uj, 0, n, z_U); } if( init_lambda ) env->GetDoubleArrayRegion(lambdaj, 0, m, lambda); return true; }
bool Jipopt::get_bounds_info(Index n, Number *x_l, Number *x_u, Index m, Number *g_l, Number *g_u) { jdoubleArray x_lj = NULL; jdoubleArray x_uj = NULL; jdoubleArray g_lj = NULL; jdoubleArray g_uj = NULL; assert(x_l != NULL); assert(x_u != NULL); assert(g_l != NULL); assert(g_u != NULL); x_lj = env->NewDoubleArray(n); x_uj = env->NewDoubleArray(n); g_lj = env->NewDoubleArray(m); g_uj = env->NewDoubleArray(m); if( !env->CallBooleanMethod(solver, get_bounds_info_, n, x_lj, x_uj, m, g_lj, g_uj) ) return false; // Copy from Java to native value env->GetDoubleArrayRegion(x_lj, 0, n, x_l); env->GetDoubleArrayRegion(x_uj, 0, n, x_u); env->GetDoubleArrayRegion(g_lj, 0, m, g_l); env->GetDoubleArrayRegion(g_uj, 0, m, g_u); return true; }
//------------------------------------------------------------ ofLoopType ofxAndroidVideoPlayer::getLoopState() const { if(!javaVideoPlayer){ ofLogError("ofxAndroidVideoPlayer") << "getLoopState(): java VideoPlayer not loaded"; return OF_LOOP_NONE; } JNIEnv *env = ofGetJNIEnv(); if (!env) { ofLogError("ofxAndroidVideoPlayer") << "getLoopState(): couldn't get environment using GetEnv()"; return OF_LOOP_NONE; } jmethodID javaGetLoopStateMethod = env->GetMethodID(javaClass,"getLoopState","()Z"); if(!javaGetLoopStateMethod){ ofLogError("ofxAndroidVideoPlayer") << "getLoopState(): couldn't get java GetLoopState for VideoPlayer"; return OF_LOOP_NONE; } bool loopState = env->CallBooleanMethod(javaVideoPlayer,javaGetLoopStateMethod); if (loopState) { return OF_LOOP_NORMAL; } else { return OF_LOOP_NONE; } };
bool JSFunction::HasInstanceCallback(JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception) { JNIEnv *env; int getEnvStat = jvm->GetEnv((void**)&env, JNI_VERSION_1_6); if (getEnvStat == JNI_EDETACHED) { jvm->AttachCurrentThread(&env, NULL); } jclass cls = env->GetObjectClass(thiz); jmethodID mid; do { mid = env->GetMethodID(cls,"hasInstanceCallback","(JJJJ)Z"); if (!env->ExceptionCheck()) break; env->ExceptionClear(); jclass super = env->GetSuperclass(cls); env->DeleteLocalRef(cls); if (super == NULL || env->ExceptionCheck()) { if (super != NULL) env->DeleteLocalRef(super); jvm->DetachCurrentThread(); return NULL; } cls = super; } while (true); env->DeleteLocalRef(cls); bool ret = env->CallBooleanMethod(thiz, mid, (jlong)ctx, (jlong)constructor, (jlong)possibleInstance, (jlong)exception); if (getEnvStat == JNI_EDETACHED) { jvm->DetachCurrentThread(); } return ret; }
bool HDFSAccessor::copy(char* srcPath, char* destPath) { bool isNewEnv = false; JNIEnv* env = JVMState::instance()->getEnv(&isNewEnv); if (m_wfxPairObj != NULL) { jstring srcPathStr = env->NewStringUTF(srcPath); jstring destPathStr = env->NewStringUTF(destPath); jboolean retVal = env->CallBooleanMethod(m_wfxPairObj, s_WfxPairMetIdCopyPath, srcPathStr, destPathStr); if (!JVMState::instance()->exceptionExists(env)) { env->DeleteLocalRef(srcPathStr); env->DeleteLocalRef(destPathStr); if (isNewEnv) { JVMState::instance()->releaseEnv(); } return retVal == JNI_TRUE; } else { env->DeleteLocalRef(srcPathStr); env->DeleteLocalRef(destPathStr); } } if (isNewEnv) { JVMState::instance()->releaseEnv(); } return false; }
bool HDFSAccessor::mkdir(char* path) { bool isNewEnv = false; JNIEnv* env = JVMState::instance()->getEnv(&isNewEnv); if (m_wfxPairObj != NULL) { jstring pathStr = env->NewStringUTF(path); jboolean retVal = env->CallBooleanMethod(m_wfxPairObj, s_WfxPairMetIdMkDir, pathStr); if (!JVMState::instance()->exceptionExists(env)) { env->DeleteLocalRef(pathStr); if (isNewEnv) { JVMState::instance()->releaseEnv(); } return retVal == JNI_TRUE; } else { env->DeleteLocalRef(pathStr); } } if (isNewEnv) { JVMState::instance()->releaseEnv(); } return false; }
bool IsDirectory(const tstring& sPath) { // Check first to see if it's in the assets folder. JNIEnv* env = (JNIEnv*)SDL_AndroidGetJNIEnv(); jobject activity = (jobject)SDL_AndroidGetActivity(); jclass activity_class = env->GetObjectClass(activity); jmethodID activity_class_assetIsDirectory = env->GetMethodID(activity_class, "assetIsDirectory", "(Ljava/lang/String;)Z"); jstring assetIsDirectory_sFile = env->NewStringUTF(sPath.c_str()); jboolean assetIsDirectory_result = env->CallBooleanMethod(activity, activity_class_assetIsDirectory, assetIsDirectory_sFile); // activity.assetIsDirectory(file); bool bIsDirectory = assetIsDirectory_result; env->DeleteLocalRef(assetIsDirectory_sFile); if (bIsDirectory) return true; struct stat stFileInfo; bool blnReturn; int intStat; // Attempt to get the file attributes intStat = stat(sPath.c_str(), &stFileInfo); if(intStat == 0 && S_ISDIR(stFileInfo.st_mode)) return true; else return false; }
bool Billing_IsProductPurchased(const char* sku) { JNIEnv* env = getEnv(); jclass k = env->GetObjectClass(jBilling); jmethodID m = env->GetMethodID(k, "isProductPurchased", "(Ljava/lang/String;)Z"); jstring jSku = env->NewStringUTF(sku); return env->CallBooleanMethod(jBilling, m, jSku); }
int32_t JNIHelper :: isInterrupted() { JNIEnv * env = this->getEnv(); if (!env) return 0; if (env->ExceptionCheck()) return 1; // a pending exception interrupts us if (!mThread_class || !mThread_isInterrupted_mid || !mThread_currentThread_mid) // this is an error if these are not set up, but we're // going to assume no interrupt then. return 0; jclass cls = static_cast<jclass>(env->NewLocalRef(mThread_class)); if (!cls) return 0; jobject thread = env->CallStaticObjectMethod( cls, mThread_currentThread_mid); env->DeleteLocalRef(cls); if (!thread || env->ExceptionCheck()) return 1; jboolean result = env->CallBooleanMethod(thread, mThread_isInterrupted_mid); env->DeleteLocalRef(thread); if (env->ExceptionCheck()) result = true; if (result != JNI_FALSE) return 1; return 0; }
ushort s3eNOFhasUserApprovedFeint_platform() { JNIEnv* env = s3eEdkJNIGetEnv(); // env->CallVoidMethod(g_Obj, g_s3eNOFhasUserApprovedFeint); return env->CallBooleanMethod(g_Obj, g_s3eNOFhasUserApprovedFeint); //return S3E_RESULT_SUCCESS; }
svn_boolean_t OperationContext::checkTunnel(void *tunnel_baton, const char *tunnel_name) { JNIEnv *env = JNIUtil::getEnv(); jstring jtunnel_name = JNIUtil::makeJString(tunnel_name); if (JNIUtil::isJavaExceptionThrown()) return false; static jmethodID mid = 0; if (0 == mid) { jclass cls = env->FindClass(JAVAHL_CLASS("/callback/TunnelAgent")); if (JNIUtil::isJavaExceptionThrown()) return false; mid = env->GetMethodID(cls, "checkTunnel", "(Ljava/lang/String;)Z"); if (JNIUtil::isJavaExceptionThrown()) return false; } jobject jtunnelcb = jobject(tunnel_baton); jboolean check = env->CallBooleanMethod(jtunnelcb, mid, jtunnel_name); if (JNIUtil::isJavaExceptionThrown()) return false; return svn_boolean_t(check); }
static bool invoke_javaCallback(int msgType, const char* msgName) { jstring msg_name = NULL; UnionJNIEnvToVoid uenv; uenv.venv = NULL; JNIEnv* env = NULL; bool detach = false; if (mJvm->GetEnv(&uenv.venv, JNI_VERSION_1_4) != JNI_OK) { if (mJvm->AttachCurrentThread(&env, NULL) != JNI_OK) { LOGE("callback_handler: failed to attach current thread\n"); return false; } detach = true; } else { env = uenv.env; } msg_name = env->NewStringUTF(msgName); bool result = env->CallBooleanMethod(mjavaApp, method_javaCallback, msgType, msg_name); env->DeleteLocalRef(msg_name); if (detach) { if (mJvm->DetachCurrentThread() != JNI_OK) { LOGE("callback_handler: failed to detach current thread\n"); } } return result; }
bool OuyaInputView::javaDispatchKeyEvent(long long downTime, long long eventTime, int action, int code, int repeat, int metaState, int deviceId, int scancode, int flags, int source) { JNIEnv* env; if (_jvm->GetEnv((void**) &env, JNI_VERSION_1_6) != JNI_OK) { __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to get JNI environment!"); return false; } if (!env) { __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "JNI must be initialized with a valid environment!"); return false; } if (!_instance) { __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "_instance is not valid!"); return false; } if (!_jmJavaDispatchKeyEvent) { __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "_jmJavaDispatchKeyEvent is not valid!"); return false; } return env->CallBooleanMethod(_instance, _jmJavaDispatchKeyEvent, downTime, eventTime, action, code, repeat, metaState, deviceId, scancode, flags, source); }
/* * call back to java to * protect fd so that the socket can access internet */ int protectFd(int sockfd) { JNIEnv *jnienv; jnijvm->GetEnv((void **)&jnienv, JNI_VERSION_1_6); jclass cls = jnienv->GetObjectClass(jniobj); jmethodID protecdMid = jnienv->GetMethodID(cls, "protect", "(I)Z"); return jnienv->CallBooleanMethod(jniobj, protecdMid, sockfd); }
bool HDFSAccessor::rename(char* oldPath, char* newPath) { bool isNewEnv = false; JNIEnv* env = JVMState::instance()->getEnv(&isNewEnv); if (m_wfxPairObj != NULL) { jstring oldPathStr = env->NewStringUTF(oldPath); jstring newPathStr = env->NewStringUTF(newPath); jboolean retVal = env->CallBooleanMethod(m_wfxPairObj, s_WfxPairMetIdRenPath, oldPathStr, newPathStr); if (!JVMState::instance()->exceptionExists(env)) { env->DeleteLocalRef(oldPathStr); env->DeleteLocalRef(newPathStr); if (isNewEnv) { JVMState::instance()->releaseEnv(); } return retVal == JNI_TRUE; } else { env->DeleteLocalRef(oldPathStr); env->DeleteLocalRef(newPathStr); } } if (isNewEnv) { JVMState::instance()->releaseEnv(); } return false; }
//--------------------------------------------------------------------------- void ofxAndroidVideoPlayer::update(){ JNIEnv *env = ofGetJNIEnv(); jmethodID javaUpdate = env->GetMethodID(javaClass,"update","()Z"); if(!javaUpdate){ ofLogError("ofxAndroidVideoPlayer") << "update(): couldn't get java update for VideoPlayer"; return; } bIsFrameNew = env->CallBooleanMethod(javaVideoPlayer,javaUpdate); jmethodID javaGetTextureMatrix = env->GetMethodID(javaClass,"getTextureMatrix","([F)V"); if(!javaGetTextureMatrix){ ofLogError("ofxAndroidVideoPlayer") << "update(): couldn't get java javaGetTextureMatrix for VideoPlayer"; return; } env->CallVoidMethod(javaVideoPlayer,javaGetTextureMatrix,matrixJava); jfloat * m = env->GetFloatArrayElements(matrixJava,0); ofMatrix4x4 textureMatrix(m); ofMatrix4x4 vFlipTextureMatrix; vFlipTextureMatrix.scale(1,-1,1); vFlipTextureMatrix.translate(0,1,0); texture.setTextureMatrix(vFlipTextureMatrix * textureMatrix); //texture.getTextureData().tex_t = 1.+1-matrix.getPtr()[0]; // Hack! //texture.getTextureData().tex_u = 1.; env->ReleaseFloatArrayElements(matrixJava,m,0); }
bool HDFSAccessor::hdfsPathExist(char* remotePath) { bool retVal = false; bool isNewEnv = false; JNIEnv* env = JVMState::instance()->getEnv(&isNewEnv); if (m_wfxPairObj != NULL) { jstring remotePathStr = env->NewStringUTF(remotePath); jboolean fileExists = env->CallBooleanMethod(m_wfxPairObj, s_WfxPairMetIdfileExists, remotePathStr); if (!JVMState::instance()->exceptionExists(env)) { retVal = fileExists; env->DeleteLocalRef(remotePathStr); if (isNewEnv) { JVMState::instance()->releaseEnv(); } } else { env->DeleteLocalRef(remotePathStr); } } return retVal; }
static int release_wake_lock_callout(const char *lock_name) { JNIEnv *env; JavaVM *vm = AndroidRuntime::getJavaVM(); jint status = vm->GetEnv((void **)&env, JNI_VERSION_1_6); if (status != JNI_OK && status != JNI_EDETACHED) { ALOGE("%s unable to get environment for JNI call", __func__); return BT_STATUS_FAIL; } if (status == JNI_EDETACHED && vm->AttachCurrentThread(&env, &sAttachArgs) != 0) { ALOGE("%s unable to attach thread to VM", __func__); return BT_STATUS_FAIL; } jboolean ret = JNI_FALSE; jstring lock_name_jni = env->NewStringUTF(lock_name); if (lock_name_jni) { ret = env->CallBooleanMethod(sJniAdapterServiceObj, method_releaseWakeLock, lock_name_jni); env->DeleteLocalRef(lock_name_jni); } else { ALOGE("%s unable to allocate string: %s", __func__, lock_name); } if (status == JNI_EDETACHED) { vm->DetachCurrentThread(); } return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; }
void get_row(std::vector<std::string>& row) { jint i; row.clear(); char str_value[32]; jboolean flag = env->CallBooleanMethod(instances, jMID_Enumeration_hasMoreElements); if( flag ) { jobject instance = env->CallObjectMethod(instances, jMID_Enumeration_nextElement); jint d = env->CallIntMethod(instance, jMID_WekaInstance_numAttributes); jdouble value; jboolean iscopy; for(i = 0; i < d; i++) { value = env->CallDoubleMethod(instance, jMID_WekaInstance_value, i); sprintf(str_value, "%g", (double) value); row.push_back(std::string(str_value)); // row push_back classIndex } } return; }
void JNIScheduler::resourceOffers(SchedulerDriver* driver, const vector<Offer>& offers) { jvm->AttachCurrentThread(JNIENV_CAST(&env), NULL); jclass clazz = env->GetObjectClass(jdriver); jfieldID scheduler = env->GetFieldID(clazz, "scheduler", "Lorg/apache/mesos/Scheduler;"); jobject jscheduler = env->GetObjectField(jdriver, scheduler); clazz = env->GetObjectClass(jscheduler); // scheduler.resourceOffers(driver, offers); jmethodID resourceOffers = env->GetMethodID(clazz, "resourceOffers", "(Lorg/apache/mesos/SchedulerDriver;" "Ljava/util/List;)V"); // List offers = new ArrayList(); clazz = env->FindClass("java/util/ArrayList"); jmethodID _init_ = env->GetMethodID(clazz, "<init>", "()V"); jobject joffers = env->NewObject(clazz, _init_); jmethodID add = env->GetMethodID(clazz, "add", "(Ljava/lang/Object;)Z"); // Loop through C++ vector and add each offer to the Java list. foreach (const Offer& offer, offers) { jobject joffer = convert<Offer>(env, offer); env->CallBooleanMethod(joffers, add, joffer); }
static bool set_wake_alarm_callout(uint64_t delay_millis, bool should_wake, alarm_cb cb, void *data) { JNIEnv *env; JavaVM *vm = AndroidRuntime::getJavaVM(); jint status = vm->GetEnv((void **)&env, JNI_VERSION_1_6); if (status != JNI_OK && status != JNI_EDETACHED) { ALOGE("%s unable to get environment for JNI call", __func__); return false; } if (status == JNI_EDETACHED && vm->AttachCurrentThread(&env, &sAttachArgs) != 0) { ALOGE("%s unable to attach thread to VM", __func__); return false; } sAlarmCallback = cb; sAlarmCallbackData = data; jboolean jshould_wake = should_wake ? JNI_TRUE : JNI_FALSE; jboolean ret = env->CallBooleanMethod(sJniAdapterServiceObj, method_setWakeAlarm, (jlong)delay_millis, jshould_wake); if (!ret) { sAlarmCallback = NULL; sAlarmCallbackData = NULL; } if (status == JNI_EDETACHED) { vm->DetachCurrentThread(); } return !!ret; }
bool textbox_get_visible(int id) { native_shim* shim = get_native_shim(); JNIEnv *env = shim->env; jmethodID method = env->GetMethodID(shim->type, "getTextBoxVisible", "(I)Z"); return env->CallBooleanMethod(shim->instance, method, id) == JNI_TRUE; }
std::shared_ptr<std::map<std::string, std::string> > PluginJniHelper::JSONObject2Map(jobject json) { auto stdmap = std::make_shared<std::map<std::string, std::string> >(); JNIEnv* env = getEnv(); jclass c_json = env->FindClass("org/json/JSONObject"); jclass c_iterator = env->FindClass("java/util/Iterator"); jmethodID m_keys = env->GetMethodID(c_json, "keys", "()Ljava/util/Iterator;"); jmethodID m_hasNext = env->GetMethodID(c_iterator, "hasNext", "()Z"); jmethodID m_next = env->GetMethodID(c_iterator, "next", "()Ljava/lang/Object;"); jmethodID m_getString = env->GetMethodID(c_json, "getString", "(Ljava/lang/String;)Ljava/lang/String;"); jstring jKeyString = NULL; jstring jValueString = NULL; jobject jKeys = env->CallObjectMethod(json, m_keys); while(env->CallBooleanMethod(jKeys, m_hasNext)) { jKeyString = (jstring)(env->CallObjectMethod(jKeys, m_next)); jValueString = (jstring)(env-> CallObjectMethod(json, m_getString, jKeyString)); stdmap->insert(std::make_pair(jstring2string(jKeyString), jstring2string(jValueString))); } env->DeleteLocalRef(jKeys); if(jKeyString) env->DeleteLocalRef(jKeyString); if(jValueString) env->DeleteLocalRef(jValueString); env->DeleteLocalRef(c_json); env->DeleteLocalRef(c_iterator); return stdmap; }
virtual bool ShouldCollide(b2Fixture* fixtureA, b2Fixture* fixtureB) { if( shouldCollideID != 0 ) return env->CallBooleanMethod( obj, shouldCollideID, (jlong)fixtureA, (jlong)fixtureB ); else return true; }
virtual status_t onTransact( uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags = 0) { JNIEnv* env = javavm_to_jnienv(mVM); if (NULL == env) { ALOGE("onTransact() on %p calling object %p fail because env=NULL vm=%p \n", this, mObject, mVM); return -EPIPE; } ALOGV("onTransact() on %p calling object %p in env %p vm %p\n", this, mObject, env, mVM); IPCThreadState* thread_state = IPCThreadState::self(); const int32_t strict_policy_before = thread_state->getStrictModePolicy(); //printf("Transact from %p to Java code sending: ", this); //data.print(); //printf("\n"); jboolean res = env->CallBooleanMethod(mObject, gBinderOffsets.mExecTransact, code, reinterpret_cast<jlong>(&data), reinterpret_cast<jlong>(reply), flags); jthrowable excep = env->ExceptionOccurred(); if (excep) { report_exception(env, excep, "*** Uncaught remote exception! " "(Exceptions are not yet supported across processes.)"); res = JNI_FALSE; /* clean up JNI local ref -- we don't return to Java code */ env->DeleteLocalRef(excep); } // Check if the strict mode state changed while processing the // call. The Binder state will be restored by the underlying // Binder system in IPCThreadState, however we need to take care // of the parallel Java state as well. if (thread_state->getStrictModePolicy() != strict_policy_before) { set_dalvik_blockguard_policy(env, strict_policy_before); } jthrowable excep2 = env->ExceptionOccurred(); if (excep2) { report_exception(env, excep2, "*** Uncaught exception in onBinderStrictModePolicyChange"); /* clean up JNI local ref -- we don't return to Java code */ env->DeleteLocalRef(excep2); } // Need to always call through the native implementation of // SYSPROPS_TRANSACTION. if (code == SYSPROPS_TRANSACTION) { BBinder::onTransact(code, data, reply, flags); } //aout << "onTransact to Java code; result=" << res << endl // << "Transact from " << this << " to Java code returning " // << reply << ": " << *reply << endl; return res != JNI_FALSE ? NO_ERROR : UNKNOWN_TRANSACTION; }
virtual status_t onTransact( uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags = 0) { JNIEnv* env = javavm_to_jnienv(mVM); ALOGV("onTransact() on %p calling object %p in env %p vm %p\n", this, mObject, env, mVM); IPCThreadState* thread_state = IPCThreadState::self(); const int strict_policy_before = thread_state->getStrictModePolicy(); thread_state->setLastTransactionBinderFlags(flags); //printf("Transact from %p to Java code sending: ", this); //data.print(); //printf("\n"); jboolean res = env->CallBooleanMethod(mObject, gBinderOffsets.mExecTransact, code, (int32_t)&data, (int32_t)reply, flags); jthrowable excep = env->ExceptionOccurred(); if (excep) { report_exception(env, excep, "*** Uncaught remote exception! " "(Exceptions are not yet supported across processes.)"); res = JNI_FALSE; /* clean up JNI local ref -- we don't return to Java code */ env->DeleteLocalRef(excep); } // Restore the Java binder thread's state if it changed while // processing a call (as it would if the Parcel's header had a // new policy mask and Parcel.enforceInterface() changed // it...) const int strict_policy_after = thread_state->getStrictModePolicy(); if (strict_policy_after != strict_policy_before) { // Our thread-local... thread_state->setStrictModePolicy(strict_policy_before); // And the Java-level thread-local... set_dalvik_blockguard_policy(env, strict_policy_before); } jthrowable excep2 = env->ExceptionOccurred(); if (excep2) { report_exception(env, excep2, "*** Uncaught exception in onBinderStrictModePolicyChange"); /* clean up JNI local ref -- we don't return to Java code */ env->DeleteLocalRef(excep2); } // Need to always call through the native implementation of // SYSPROPS_TRANSACTION. if (code == SYSPROPS_TRANSACTION) { BBinder::onTransact(code, data, reply, flags); } //aout << "onTransact to Java code; result=" << res << endl // << "Transact from " << this << " to Java code returning " // << reply << ": " << *reply << endl; return res != JNI_FALSE ? NO_ERROR : UNKNOWN_TRANSACTION; }
tvector<tstring> ListAndroidAssetsDirectory(const tstring& sDirectory, bool bDirectories) { JNIEnv* env = (JNIEnv*)SDL_AndroidGetJNIEnv(); jobject activity = (jobject)SDL_AndroidGetActivity(); jclass activity_class = env->GetObjectClass(activity); jmethodID activity_class_assetOpenDir = env->GetMethodID(activity_class, "assetOpenDir", "(Ljava/lang/String;)Z"); jstring assetOpenDir_sDirectory = env->NewStringUTF(sDirectory.c_str()); jboolean assetOpenDir_success = env->CallBooleanMethod(activity, activity_class_assetOpenDir, assetOpenDir_sDirectory); // activity.assetOpenDir(sDirectory); env->DeleteLocalRef(assetOpenDir_sDirectory); if (!assetOpenDir_success) return tvector<tstring>(); tvector<tstring> asResult; const char* pszDir; jmethodID activity_class_assetGetNext = env->GetMethodID(activity_class, "assetGetNext", "()Ljava/lang/String;"); jmethodID activity_class_assetIsDirectory = env->GetMethodID(activity_class, "assetIsDirectory", "(Ljava/lang/String;)Z"); jstring dir; while ((dir = (jstring)env->CallObjectMethod(activity, activity_class_assetGetNext)) != NULL) { const char* pszDir = env->GetStringUTFChars(dir, nullptr); tstring sDir = pszDir; env->ReleaseStringUTFChars(dir, pszDir); tstring sFullDir = sDirectory + "/" + sDir; if (!bDirectories) { jstring assetIsDirectory_sFile = env->NewStringUTF(sFullDir.c_str()); jboolean assetIsDirectory_result = env->CallBooleanMethod(activity, activity_class_assetIsDirectory, assetIsDirectory_sFile); // activity.assetIsDirectory(file); bool bIsDirectory = assetIsDirectory_result; env->DeleteLocalRef(assetIsDirectory_sFile); if (bIsDirectory) continue; } asResult.push_back(sDir); } return asResult; }