[IOT-3012] Update JniOcProvisioning API usage 43/25343/3
authorLarry Sachs <larry.j.sachs@intel.com>
Mon, 21 May 2018 21:24:26 +0000 (14:24 -0700)
committerRick Bell <richard.s.bell@intel.com>
Thu, 31 May 2018 17:11:32 +0000 (17:11 +0000)
Use of deprecated functions in JniOcProvisioning.cpp has been updated
to use their replacements.

Java example ProvisioningClient.java has also been updated.

Change-Id: Ie46dccffc714b47109100dbd8c70aa3598d94190
Signed-off-by: Larry Sachs <larry.j.sachs@intel.com>
java/common/src/main/java/org/iotivity/base/OcProvisioning.java
java/examples-android/provisioningclient/src/main/java/org/iotivity/base/examples/provisioningclient/ProvisioningClient.java
java/jni/JniOcProvisioning.cpp
java/jni/JniPinCheckListener.cpp
java/jni/JniPinCheckListener.h

index 60538e8..c53da4f 100644 (file)
@@ -117,7 +117,7 @@ public class OcProvisioning {
     private  static native void ownershipTransferCBdata(int oxmType,  PinCallbackListener pinCallbackListener);
 
     public static interface PinCallbackListener {
-        public String pinCallbackListener();
+        public String pinCallbackListener(String deviceUuid);
     }
 
 
index 9c3af76..4e8fa85 100644 (file)
@@ -72,8 +72,8 @@ OcSecureResource.DoOwnershipTransferListener, OcSecureResource.ProvisionPairwise
     OcProvisioning.PinCallbackListener pinCallbackListener =
         new OcProvisioning.PinCallbackListener() {
             @Override
-                public String pinCallbackListener() {
-                    Log.d(TAG, "Inside Pin Callback ");
+                public String pinCallbackListener(String deviceUuid) {
+                    Log.d(TAG, "Inside Pin Callback -- deviceUuid = " + deviceUuid);
                     return "";
                 }
         };
@@ -582,7 +582,7 @@ OcSecureResource.DoOwnershipTransferListener, OcSecureResource.ProvisionPairwise
                                     deviceList.get(i).getDeviceID());
                         }
                         try {
-                            OcProvisioning.SetownershipTransferCBdata(OxmType.OIC_JUST_WORKS,
+                            OcProvisioning.setOwnershipTransferCBdata(OxmType.OIC_JUST_WORKS,
                                     pinCallbackListener);
                             for (int i = 0; i < deviceList.size(); i++) {
                                 publishProgress(TAG + "Doing Ownership Transfer for " +
index 53ea34f..b4f0a40 100644 (file)
@@ -28,6 +28,7 @@
 #include "oxmverifycommon.h"
 #include "JniDisplayVerifyNumListener.h"
 #include "JniConfirmNumListener.h"
+#include "OCProvisioningManager.hpp"
 #include <climits>
 
 using namespace OC;
@@ -38,11 +39,14 @@ static JniDisplayPinListener *jniDisplayPinListener = nullptr;
 static JniDisplayVerifyNumListener *jniDisplayMutualVerifyNumListener = nullptr;
 static JniConfirmNumListener *jniConfirmMutualVerifyNumListener = nullptr;
 
-void JNICALL Callback(char *buf, size_t size)
+static InputPinCallbackHandle inputPinCallbackHandle = NULL;
+static DisplayPinCallbackHandle displayPinCallbackHandle = NULL;
+
+void JNICALL Callback(OicUuid_t deviceId, char *buf, size_t size)
 {
     if (jniPinListener)
     {
-        jniPinListener->PinCallback(buf, size);
+        jniPinListener->PinCallback(deviceId, buf, size);
     }
     else
     {
@@ -119,14 +123,11 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_ownershipTransferCB
             {
                 delete jniPinListener;
                 jniPinListener = new JniPinCheckListener(env, jListener);
-#if defined(__GNUC__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-#endif
-                result = OCSecure::setInputPinCallback(Callback);
-#if defined(__GNUC__)
-#pragma GCC diagnostic pop
-#endif
+                if (inputPinCallbackHandle)
+                {
+                    OCSecure::deregisterInputPinCallback(inputPinCallbackHandle);
+                }
+                result = OCSecure::registerInputPinCallback(Callback, &inputPinCallbackHandle);
             }
             else
             {
@@ -507,19 +508,16 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_setDisplayPinListen
 
     try
     {
-#if defined(__GNUC__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-#endif
-        OCStackResult result = OCSecure::setDisplayPinCB(displayPinCB);
+        if (displayPinCallbackHandle)
+        {
+            OCSecure::deregisterDisplayPinCallback(displayPinCallbackHandle);
+        }
+        OCStackResult result = OCSecure::registerDisplayPinCallback(displayPinCB, &displayPinCallbackHandle);
         if (OC_STACK_OK != result)
         {
             ThrowOcException(result, "Failed to set displayPinListener");
             return;
         }
-#if defined(__GNUC__)
-#pragma GCC diagnostic pop
-#endif
     }
     catch (OCException& e)
     {
index 91264a9..44410fd 100644 (file)
@@ -20,7 +20,9 @@
 * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 */
 #include "JniPinCheckListener.h"
+#include "oic_malloc.h"
 #include "oic_string.h"
+#include "srmutility.h"
 
 JniPinCheckListener::JniPinCheckListener(JNIEnv *env, jobject jListener)
 {
@@ -46,7 +48,7 @@ JniPinCheckListener::~JniPinCheckListener()
     }
 }
 
-void JniPinCheckListener::PinCallback(char *pinBuf, size_t bufSize)
+void JniPinCheckListener::PinCallback(OicUuid_t deviceId, char *pinBuf, size_t bufSize)
 {
     jint ret = JNI_ERR;
     JNIEnv *env = GetJNIEnv(ret);
@@ -66,7 +68,22 @@ void JniPinCheckListener::PinCallback(char *pinBuf, size_t bufSize)
         return;
     }
 
-    jmethodID midL = env->GetMethodID(clsL, "pinCallbackListener", "()Ljava/lang/String;");
+    char *deviceUuidStr = NULL;
+    if (OC_STACK_OK != ConvertUuidToStr(&deviceId, &deviceUuidStr))
+    {
+        deviceUuidStr = (char *)OICMalloc(1);
+        deviceUuidStr[0] = 0;
+    }
+    jstring jUuidStr = env->NewStringUTF(deviceUuidStr);
+    OICFree(deviceUuidStr);
+
+    if (!jUuidStr)
+    {
+        LOGE("JniPinCheckListener()::PinCallback() failed to create device uuid string");
+        return;
+    }
+
+    jmethodID midL = env->GetMethodID(clsL, "pinCallbackListener", "(Ljava/lang/String;)Ljava/lang/String;");
     if (!midL)
     {
         if (JNI_EDETACHED == ret)
@@ -75,7 +92,8 @@ void JniPinCheckListener::PinCallback(char *pinBuf, size_t bufSize)
         }
         return;
     }
-    jstring jpin = (jstring)env->CallObjectMethod(m_jListener, midL);
+    jstring jpin = (jstring)env->CallObjectMethod(m_jListener, midL, jUuidStr);
+    env->DeleteLocalRef(jUuidStr);
     if (env->ExceptionCheck())
     {
         LOGE("Java exception is thrown");
index b15b5b5..8cb74be 100644 (file)
@@ -33,7 +33,7 @@ class JniPinCheckListener
         JniPinCheckListener(JNIEnv *, jobject);
         ~JniPinCheckListener();
 
-        void PinCallback(char*, size_t);
+        void PinCallback(OicUuid_t, char*, size_t);
     private:
         jobject m_jListener;
 };