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 "JniProvisionResultListner.h"
23 #include "JniOcSecureResource.h"
24 #include "JniSecureUtils.h"
26 JniProvisionResultListner::JniProvisionResultListner(JNIEnv *env, jobject jListener,
27 RemoveCallback removeProvisionResultListener)
29 m_jwListener = env->NewWeakGlobalRef(jListener);
30 m_removeProvisionResultListener = removeProvisionResultListener;
33 JniProvisionResultListner::~JniProvisionResultListner()
35 LOGI("~JniProvisionResultListner()");
39 JNIEnv *env = GetJNIEnv(ret);
44 env->DeleteWeakGlobalRef(m_jwListener);
45 if (JNI_EDETACHED == ret)
47 g_jvm->DetachCurrentThread();
52 void JniProvisionResultListner::ProvisionResultCallback(PMResultList_t *result, int hasError,
56 JNIEnv *env = GetJNIEnv(ret);
62 jobject jListener = env->NewLocalRef(m_jwListener);
65 checkExAndRemoveListener(env);
66 if (JNI_EDETACHED == ret)
68 g_jvm->DetachCurrentThread();
73 jclass clsL = env->GetObjectClass(jListener);
77 checkExAndRemoveListener(env);
78 if (JNI_EDETACHED == ret)
80 g_jvm->DetachCurrentThread();
86 jobject jResultList = JniSecureUtils::convertProvisionresultVectorToJavaList(env, result);
89 checkExAndRemoveListener(env);
90 if (JNI_EDETACHED == ret)
92 g_jvm->DetachCurrentThread();
97 std::string calledFunc;
100 case ListenerFunc::OWNERSHIPTRANSFER:
102 calledFunc = "doOwnershipTransferListener";
105 case ListenerFunc::PROVISIONACL:
107 calledFunc = "provisionAclListener";
110 case ListenerFunc::PROVISIONCREDENTIALS:
112 calledFunc = "provisionCredentialsListener";
115 case ListenerFunc::UNLINKDEVICES:
117 calledFunc = "unlinkDevicesListener";
120 case ListenerFunc::REMOVEDEVICE:
122 calledFunc = "removeDeviceListener";
125 case ListenerFunc::PROVISIONPAIRWISEDEVICES:
127 calledFunc = "provisionPairwiseDevicesListener";
130 case ListenerFunc::PROVISIONDIRECTPAIRING:
132 calledFunc = "provisionDirectPairingListener";
137 checkExAndRemoveListener(env);
138 if (JNI_EDETACHED == ret)
140 g_jvm->DetachCurrentThread();
147 jmethodID midL = env->GetMethodID(clsL, calledFunc.c_str(), "(Ljava/util/List;I)V");
150 checkExAndRemoveListener(env);
151 if (JNI_EDETACHED == ret)
153 g_jvm->DetachCurrentThread();
157 env->CallVoidMethod(jListener, midL, jResultList, (jint)hasError);
158 if (env->ExceptionCheck())
160 LOGE("Java exception is thrown");
163 checkExAndRemoveListener(env);
164 if (JNI_EDETACHED == ret)
166 g_jvm->DetachCurrentThread();
170 void JniProvisionResultListner::checkExAndRemoveListener(JNIEnv* env)
172 if (env->ExceptionCheck())
174 jthrowable ex = env->ExceptionOccurred();
175 env->ExceptionClear();
176 m_removeProvisionResultListener(env, m_jwListener);
177 env->Throw((jthrowable)ex);
181 m_removeProvisionResultListener(env, m_jwListener);