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);
40 if (NULL == env) return;
41 env->DeleteWeakGlobalRef(m_jwListener);
42 if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
46 void JniProvisionResultListner::ProvisionResultCallback(PMResultList_t *result, int hasError,
50 JNIEnv *env = GetJNIEnv(ret);
51 if (NULL == env) return;
53 jobject jListener = env->NewLocalRef(m_jwListener);
56 checkExAndRemoveListener(env);
57 if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
61 jclass clsL = env->GetObjectClass(jListener);
65 checkExAndRemoveListener(env);
66 if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
71 jobject jResultList = JniSecureUtils::convertProvisionresultVectorToJavaList(env, result);
74 checkExAndRemoveListener(env);
75 if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
79 std::string calledFunc;
82 case ListenerFunc::OWNERSHIPTRANSFER:
84 calledFunc = "doOwnershipTransferListener";
87 case ListenerFunc::PROVISIONACL:
89 calledFunc = "provisionAclListener";
92 case ListenerFunc::PROVISIONCREDENTIALS:
94 calledFunc = "provisionCredentialsListener";
97 case ListenerFunc::UNLINKDEVICES:
99 calledFunc = "unlinkDevicesListener";
102 case ListenerFunc::REMOVEDEVICE:
104 calledFunc = "removeDeviceListener";
107 case ListenerFunc::PROVISIONPAIRWISEDEVICES:
109 calledFunc = "provisionPairwiseDevicesListener";
114 checkExAndRemoveListener(env);
115 if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
120 jmethodID midL = env->GetMethodID(clsL, calledFunc.c_str(), "(Ljava/util/List;I)V");
123 checkExAndRemoveListener(env);
124 if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
127 env->CallVoidMethod(jListener, midL, jResultList, (jint)hasError);
128 if (env->ExceptionCheck())
130 LOGE("Java exception is thrown");
133 checkExAndRemoveListener(env);
134 if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
137 void JniProvisionResultListner::checkExAndRemoveListener(JNIEnv* env)
139 if (env->ExceptionCheck())
141 jthrowable ex = env->ExceptionOccurred();
142 env->ExceptionClear();
143 m_removeProvisionResultListener(env, m_jwListener);
144 env->Throw((jthrowable)ex);
148 m_removeProvisionResultListener(env, m_jwListener);