2 * //******************************************************************
4 * // Copyright 2015 Samsung Electronics All Rights Reserved.
6 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
8 * // Licensed under the Apache License, Version 2.0 (the "License");
9 * // you may not use this file except in compliance with the License.
10 * // You may obtain a copy of the License at
12 * // http://www.apache.org/licenses/LICENSE-2.0
14 * // Unless required by applicable law or agreed to in writing, software
15 * // distributed under the License is distributed on an "AS IS" BASIS,
16 * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * // See the License for the specific language governing permissions and
18 * // limitations under the License.
20 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 #include "JniPinCheckListener.h"
23 #include "oic_string.h"
25 JniPinCheckListener::JniPinCheckListener(JNIEnv *env, jobject jListener)
27 m_jListener = env->NewGlobalRef(jListener);
30 JniPinCheckListener::~JniPinCheckListener()
32 LOGI("~JniPinCheckListener()");
36 JNIEnv *env = GetJNIEnv(ret);
37 if (NULL == env) return;
38 env->DeleteGlobalRef(m_jListener);
39 if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
43 void JniPinCheckListener::PinCallback(char *pinBuf, size_t bufSize)
47 JNIEnv *env = GetJNIEnv(ret);
48 if (NULL == env) return;
50 jclass clsL = env->GetObjectClass(m_jListener);
54 if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
58 jmethodID midL = env->GetMethodID(clsL, "pinCallbackListener", "()Ljava/lang/String;");
61 if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
64 jstring jpin = (jstring)env->CallObjectMethod(m_jListener, midL);
65 if (env->ExceptionCheck())
67 LOGE("Java exception is thrown");
68 if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
72 char *str = (char*)env->GetStringUTFChars(jpin, NULL);
73 OICStrcpy(pinBuf, bufSize, str);
74 env->ReleaseStringUTFChars(jpin, str);
76 if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();