Added Android support for Provisioning APIs
authorSandeep Sharma <sandeep.s9@samsung.com>
Tue, 1 Sep 2015 11:34:51 +0000 (17:04 +0530)
committerSachin Agrawal <sachin.agrawal@intel.com>
Thu, 17 Sep 2015 21:30:26 +0000 (21:30 +0000)
- Unowned/Owned device discovery, ACL, Credential provisioning
- Ownership transfer

[Patch #2] fixed wrong code comment.
[Patch #3] Added JNI and Java Interface for Unlink, revocation and Dashboard.
           Added Android Provisioning sample app.
[Patch #4] Revert Sconscript Changes with causes failure for automatic rebase.
[Patch #5] Addressed Ashwini's review commnets.
[Patch #6] Few fixes and addressed Randeep's review comments.
[Patch #7] Renamed sample app and more memory fixes.
[Patch #8] Addressed Tim's review comments.
[Patch #13] Addresses review comments.

NOTE: This change set won't build. It depends upon change set #2320

Change-Id: I41a29c0467976ea2b8439d8f85926b0a0ae6d79f
Signed-off-by: Sandeep Sharma <sandeep.s9@samsung.com>
Signed-off-by: Sunil Kumar K R <sunil.k14@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2334
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sachin Agrawal <sachin.agrawal@intel.com>
44 files changed:
android/android_api/SConscript
android/android_api/base/build.gradle
android/android_api/base/jni/Android.mk
android/android_api/base/jni/JniOcProvisioning.cpp [new file with mode: 0644]
android/android_api/base/jni/JniOcProvisioning.h [new file with mode: 0644]
android/android_api/base/jni/JniOcSecureResource.cpp [new file with mode: 0644]
android/android_api/base/jni/JniOcSecureResource.h [new file with mode: 0644]
android/android_api/base/jni/JniOcStack.cpp
android/android_api/base/jni/JniOcStack.h
android/android_api/base/jni/JniPinCheckListener.cpp [new file with mode: 0644]
android/android_api/base/jni/JniPinCheckListener.h [new file with mode: 0644]
android/android_api/base/jni/JniProvisionResultListner.cpp [new file with mode: 0644]
android/android_api/base/jni/JniProvisionResultListner.h [new file with mode: 0644]
android/android_api/base/jni/JniSecureUtils.cpp [new file with mode: 0644]
android/android_api/base/jni/JniSecureUtils.h [new file with mode: 0644]
android/android_api/base/src/main/java/org/iotivity/base/CredType.java [new file with mode: 0644]
android/android_api/base/src/main/java/org/iotivity/base/DeviceStatus.java [new file with mode: 0644]
android/android_api/base/src/main/java/org/iotivity/base/KeySize.java [new file with mode: 0644]
android/android_api/base/src/main/java/org/iotivity/base/OcProvisioning.java [new file with mode: 0644]
android/android_api/base/src/main/java/org/iotivity/base/OcSecureResource.java [new file with mode: 0644]
android/android_api/base/src/main/java/org/iotivity/base/OicSecAcl.java [new file with mode: 0644]
android/android_api/base/src/main/java/org/iotivity/base/OwnedStatus.java [new file with mode: 0644]
android/android_api/base/src/main/java/org/iotivity/base/OxmType.java [new file with mode: 0644]
android/android_api/base/src/main/java/org/iotivity/base/ProvisionResult.java [new file with mode: 0644]
android/examples/provisioningclient/build.gradle [new file with mode: 0644]
android/examples/provisioningclient/proguard-rules.pro [new file with mode: 0644]
android/examples/provisioningclient/provisioningclient.iml [new file with mode: 0644]
android/examples/provisioningclient/src/main/AndroidManifest.xml [new file with mode: 0644]
android/examples/provisioningclient/src/main/assets/oic_svr_db_client.json [new file with mode: 0644]
android/examples/provisioningclient/src/main/java/org/iotivity/base/examples/provisioningclient/ProvisioningClient.java [new file with mode: 0644]
android/examples/provisioningclient/src/main/java/org/iotivity/base/examples/provisioningclient/StringConstants.java [new file with mode: 0644]
android/examples/provisioningclient/src/main/res/layout/activity_secure_provision_client.xml [new file with mode: 0644]
android/examples/provisioningclient/src/main/res/menu/menu_secure_provision_client.xml [new file with mode: 0644]
android/examples/provisioningclient/src/main/res/mipmap-hdpi/ic_launcher.png [new file with mode: 0644]
android/examples/provisioningclient/src/main/res/mipmap-mdpi/ic_launcher.png [new file with mode: 0644]
android/examples/provisioningclient/src/main/res/mipmap-xhdpi/ic_launcher.png [new file with mode: 0644]
android/examples/provisioningclient/src/main/res/mipmap-xxhdpi/ic_launcher.png [new file with mode: 0644]
android/examples/provisioningclient/src/main/res/values-v21/styles.xml [new file with mode: 0644]
android/examples/provisioningclient/src/main/res/values-w820dp/dimens.xml [new file with mode: 0644]
android/examples/provisioningclient/src/main/res/values/dimens.xml [new file with mode: 0644]
android/examples/provisioningclient/src/main/res/values/strings.xml [new file with mode: 0644]
android/examples/provisioningclient/src/main/res/values/styles.xml [new file with mode: 0644]
android/examples/settings.gradle
resource/csdk/security/SConscript

index f2bc851..0f27318 100644 (file)
@@ -9,6 +9,7 @@ if env.get('RELEASE'):
        ANDROID_RELEASE="release"
 else:
        ANDROID_RELEASE="debug"
+ANDROID_SECURED = env.get('SECURED')
 
 os.environ['ANDROID_HOME'] = env.get('ANDROID_HOME')
 os.environ['ANDROID_NDK_HOME'] = env.get('ANDROID_NDK')
@@ -46,6 +47,6 @@ def ensure_libs(target, source, env):
     return target, [source, env.get('BUILD_DIR') + 'liboc.so', env.get('BUILD_DIR') + 'liboc_logger.so']
 
 jdk_env = Environment(ENV=os.environ)
-jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + os.getcwd()+'/build.gradle -PTARGET_ARCH=%s -PRELEASE=%s --stacktrace' %(ANDROID_TARGET_ARCH, ANDROID_RELEASE), emitter = ensure_libs)
+jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + os.getcwd()+'/build.gradle -PSECURED=%s -PTARGET_ARCH=%s -PRELEASE=%s --stacktrace' %(ANDROID_SECURED, ANDROID_TARGET_ARCH, ANDROID_RELEASE), emitter = ensure_libs)
 jdk_env['BUILD_DIR'] = env.get('BUILD_DIR')
 jdk_env.Gradle(target="base/objs", source="base/src/main/java/org/iotivity/base/OcResource.java")
index 9cbdaf8..afeb10d 100755 (executable)
@@ -94,7 +94,7 @@ task buildNative(type: Exec) {
         //for windows use 'ndk-build.cmd'\r
         //def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build.cmd')\r
         def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build')\r
-        commandLine ndkBuild, "APP_ABI=$TARGET_ARCH", "APP_OPTIM=$RELEASE"\r
+        commandLine ndkBuild, "APP_ABI=$TARGET_ARCH", "APP_OPTIM=$RELEASE", "SECURE=$SECURED"
     } else {\r
         println '##################'\r
         println 'Skipping NDK build'\r
index f29d75a..05172ee 100644 (file)
@@ -1,5 +1,6 @@
 LOCAL_PATH := $(call my-dir)\r
 TARGET_ARCH_ABI := $(APP_ABI)\r
+SECURED := $(SECURE)
 \r
 include $(CLEAR_VARS)\r
 OIC_LIB_PATH := ../../../../out/android/$(APP_ABI)/$(APP_OPTIM)\r
@@ -25,6 +26,20 @@ LOCAL_MODULE := libandroid-ca
 LOCAL_SRC_FILES := $(OIC_LIB_PATH)/libconnectivity_abstraction.so\r
 include $(PREBUILT_SHARED_LIBRARY)\r
 \r
+ifeq ($(SECURED), 1)
+include $(CLEAR_VARS)
+OIC_LIB_PATH := ../../../../out/android/$(APP_ABI)/$(APP_OPTIM)
+LOCAL_MODULE := libandroid-ocprovision
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/libocprovision.a
+include $(PREBUILT_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+OIC_LIB_PATH := ../../../../out/android/$(APP_ABI)/$(APP_OPTIM)
+LOCAL_MODULE := libandroid-ocpmapi
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/libocpmapi.a
+include $(PREBUILT_STATIC_LIBRARY)
+endif
+
 include $(CLEAR_VARS)\r
 OIC_SRC_PATH := ../../../resource\r
 LOCAL_MODULE := libca-interface\r
@@ -60,6 +75,13 @@ LOCAL_SRC_FILES :=  JniOcStack.cpp \
                     JniOcResource.cpp \\r
                     JniOcResourceIdentifier.cpp \
                     JniOcSecurity.cpp
+ifeq ($(SECURED), 1)
+LOCAL_SRC_FILES +=  JniOcSecureResource.cpp \
+                    JniOcProvisioning.cpp \
+                    JniSecureUtils.cpp \
+                    JniProvisionResultListner.cpp \
+                    JniPinCheckListener.cpp
+endif
 \r
 LOCAL_LDLIBS := -llog\r
 LOCAL_STATIC_LIBRARIES := android-oc\r
@@ -68,14 +90,23 @@ LOCAL_STATIC_LIBRARIES += android-coap
 LOCAL_STATIC_LIBRARIES += android-oc_logger\r
 LOCAL_STATIC_LIBRARIES += android-ca\r
 LOCAL_STATIC_LIBRARIES += android_cpp11_compat\r
+ifeq ($(SECURED), 1)
+LOCAL_STATIC_LIBRARIES += android-ocprovision
+LOCAL_STATIC_LIBRARIES += android-ocpmapi
+endif
 \r
 LOCAL_CPPFLAGS += -std=c++0x\r
 LOCAL_CPP_FEATURES := rtti exceptions\r
 LOCAL_C_INCLUDES := $(OIC_SRC_PATH)/include\r
 LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/c_common\r
+LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/c_common/oic_string/include
 LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/stack/include\r
 LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/ocsocket/include\r
 LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/oc_logger/include\r
 LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/../extlibs/boost/boost_1_58_0\r
 LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/../build_common/android/compatibility\r
+LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include
+LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include/oxm/
+LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include/internal
+LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/include
 include $(BUILD_SHARED_LIBRARY)\r
diff --git a/android/android_api/base/jni/JniOcProvisioning.cpp b/android/android_api/base/jni/JniOcProvisioning.cpp
new file mode 100644 (file)
index 0000000..7813169
--- /dev/null
@@ -0,0 +1,223 @@
+/*
+* //******************************************************************
+* //
+* // Copyright 2015 Samsung Electronics All Rights Reserved.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+* //
+* // Licensed under the Apache License, Version 2.0 (the "License");
+* // you may not use this file except in compliance with the License.
+* // You may obtain a copy of the License at
+* //
+* //      http://www.apache.org/licenses/LICENSE-2.0
+* //
+* // Unless required by applicable law or agreed to in writing, software
+* // distributed under the License is distributed on an "AS IS" BASIS,
+* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* // See the License for the specific language governing permissions and
+* // limitations under the License.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+*/
+
+#include "JniOcProvisioning.h"
+#include "JniPinCheckListener.h"
+
+using namespace OC;
+namespace PH = std::placeholders;
+
+static JniPinCheckListener *PinListener = nullptr;
+
+void Callback(char *buf, size_t size)
+{
+    if (PinListener)
+    {
+        PinListener->PinCallback(buf, size);
+    }
+    else
+    {
+        LOGE("PinListener is null");
+    }
+}
+
+/*
+ * Class:     org_iotivity_base_OcProvisioning
+ * Method:    ownershipTransferCDdata
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_ownershipTransferCBdata
+  (JNIEnv *env, jobject thiz, jint OxmType, jobject jListener)
+{
+    LOGD("OcProvisioning_ownershipTransferCBdata");
+    OCStackResult result = OC_STACK_ERROR;
+
+    try
+    {
+        OTMCallbackData_t CBData = {0};
+        if (OIC_JUST_WORKS == (OicSecOxm_t)OxmType)
+        {
+            CBData.loadSecretCB = LoadSecretJustWorksCallback;
+            CBData.createSecureSessionCB = CreateSecureSessionJustWorksCallback;
+            CBData.createSelectOxmPayloadCB = CreateJustWorksSelectOxmPayload;
+            CBData.createOwnerTransferPayloadCB = CreateJustWorksOwnerTransferPayload;
+
+            result = OCSecure::setOwnerTransferCallbackData((OicSecOxm_t)OxmType,
+                    &CBData, NULL);
+        }
+        if (OIC_RANDOM_DEVICE_PIN == (OicSecOxm_t)OxmType)
+        {
+            if (jListener)
+            {
+                delete PinListener;
+                PinListener = new JniPinCheckListener(env, jListener);
+                CBData.loadSecretCB = InputPinCodeCallback;
+                CBData.createSecureSessionCB = CreateSecureSessionRandomPinCallbak;
+                CBData.createSelectOxmPayloadCB = CreatePinBasedSelectOxmPayload;
+                CBData.createOwnerTransferPayloadCB = CreatePinBasedOwnerTransferPayload;
+                result = OCSecure::setOwnerTransferCallbackData((OicSecOxm_t)OxmType,
+                        &CBData, Callback);
+            }
+            else
+            {
+                result = OC_STACK_ERROR;
+            }
+        }
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcProvisioning_ownershipTransferCDdata");
+            return;
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcProvisioning
+* Method:    discoverUnownedDevices
+* Signature: (I)[Lorg/iotivity/base/OcSecureResource;
+*/
+JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcProvisioning_discoverUnownedDevices1
+  (JNIEnv *env, jclass clazz, jint timeout)
+{
+    LOGI("OcProvisioning_discoverUnownedDevices");
+    DeviceList_t list;
+
+    try
+    {
+        OCStackResult result = OCSecure::discoverUnownedDevices((unsigned short)timeout, list);
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "Failed to discover Unowned devices");
+            return nullptr;
+        }
+
+        return JniSecureUtils::convertDeviceVectorToJavaArray(env, list);
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+ * Class:     org_iotivity_base_OcProvisioning
+ * Method:    provisionInit
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_provisionInit
+  (JNIEnv *env, jclass calzz, jstring jdbPath)
+{
+    LOGI("OcProvisioning_provisionInit");
+    char *dbpath;
+
+    if (!jdbPath)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "SVR db path cannot be null");
+        return;
+    }
+
+    try
+    {
+        dbpath = (char*)env->GetStringUTFChars(jdbPath, NULL);
+        OCStackResult result = OCSecure::provisionInit(env->GetStringUTFChars(jdbPath, NULL));
+
+        if (OC_STACK_OK != result)
+        {
+            env->ReleaseStringUTFChars(jdbPath, (const char*)dbpath);
+            ThrowOcException(result, "Failed to Init Provisioning Manager");
+            return;
+        }
+        env->ReleaseStringUTFChars(jdbPath, (const char*)dbpath);
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+ * Class:     org_iotivity_base_OcProvisioning
+ * Method:    discoverOwnedDevices
+ * Signature: (I)[Lorg/iotivity/base/OcSecureResource;
+ */
+JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcProvisioning_discoverOwnedDevices1
+  (JNIEnv *env, jclass clazz , jint timeout)
+{
+    LOGI("OcProvisioning_discoverOwnedDevices");
+    DeviceList_t list;
+
+    try
+    {
+        OCStackResult result = OCSecure::discoverOwnedDevices((unsigned short)timeout, list);
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "Failed to discover Owned devices");
+            return nullptr;
+        }
+
+        return JniSecureUtils::convertDeviceVectorToJavaArray(env, list);
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
+
+/*
+ * Class:     org_iotivity_base_OcProvisioning
+ * Method:    getDevicestatusLists
+ * Signature: (I)[Lorg/iotivity/base/OcSecureResource;
+ */
+JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcProvisioning_getDeviceStatusList1
+  (JNIEnv *env, jclass clazz, jint timeout)
+{
+    LOGI("OcProvisioning_getDeviceStatusList");
+    DeviceList_t  ownedDevList, unownedDevList;
+
+    try
+    {
+        OCStackResult result = OCSecure::getDevInfoFromNetwork((unsigned short)timeout,
+                ownedDevList, unownedDevList);
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "Failed to get Device Status List");
+            return nullptr;
+        }
+        ownedDevList.insert(ownedDevList.end(), unownedDevList.begin(), unownedDevList.end());
+        return JniSecureUtils::convertDeviceVectorToJavaArray(env, ownedDevList);
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+    }
+}
diff --git a/android/android_api/base/jni/JniOcProvisioning.h b/android/android_api/base/jni/JniOcProvisioning.h
new file mode 100644 (file)
index 0000000..fe5bd9a
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+* //******************************************************************
+* //
+* // Copyright 2015 Samsung Electronics All Rights Reserved.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+* //
+* // Licensed under the Apache License, Version 2.0 (the "License");
+* // you may not use this file except in compliance with the License.
+* // You may obtain a copy of the License at
+* //
+* //      http://www.apache.org/licenses/LICENSE-2.0
+* //
+* // Unless required by applicable law or agreed to in writing, software
+* // distributed under the License is distributed on an "AS IS" BASIS,
+* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* // See the License for the specific language governing permissions and
+* // limitations under the License.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+*/
+#include "JniOcStack.h"
+#include "OCProvisioningManager.h"
+#include "JniSecureUtils.h"
+#include "oxmjustworks.h"
+#include "oxmrandompin.h"
+#include <jni.h>
+#include <mutex>
+
+#ifndef _Included_org_iotivity_base_OcProvisioning
+#define _Included_org_iotivity_base_OcProvisioning
+
+using namespace OC;
+
+/* DO NOT EDIT THIS FILE - it is machine generated */
+/* Header for class org_iotivity_base_OcProvisioning */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class:     org_iotivity_base_OcProvisioning
+ * Method:    ownershipTransferCDdata
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_ownershipTransferCBdata
+  (JNIEnv *, jobject, jint, jobject);
+
+/*
+ * Class:     org_iotivity_base_OcProvisioning
+ * Method:    discoverUnownedDevices
+ * Signature: (I)[Lorg/iotivity/base/OcSecureResource;
+ */
+JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcProvisioning_discoverUnownedDevices1
+  (JNIEnv *, jclass, jint);
+
+/*
+ * Class:     org_iotivity_base_OcProvisioning
+ * Method:    provisionInit
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_provisionInit
+  (JNIEnv *, jclass, jstring);
+
+/*
+ * Class:     org_iotivity_base_OcProvisioning
+ * Method:    discoverOwnedDevices
+ * Signature: (I)[Lorg/iotivity/base/OcSecureResource;
+ */
+JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcProvisioning_discoverOwnedDevices1
+  (JNIEnv *, jclass, jint);
+
+/*
+ * Class:     org_iotivity_base_OcProvisioning
+ * Method:    getDevicestatusLists
+ * Signature: (I)[Lorg/iotivity/base/OcSecureResource;
+ */
+JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcProvisioning_getDeviceStatusList1
+  (JNIEnv *, jclass, jint);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/android/android_api/base/jni/JniOcSecureResource.cpp b/android/android_api/base/jni/JniOcSecureResource.cpp
new file mode 100644 (file)
index 0000000..d2929de
--- /dev/null
@@ -0,0 +1,653 @@
+/*
+* //******************************************************************
+* //
+* // Copyright 2015 Samsung Electronics All Rights Reserved.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+* //
+* // Licensed under the Apache License, Version 2.0 (the "License");
+* // you may not use this file except in compliance with the License.
+* // You may obtain a copy of the License at
+* //
+* //      http://www.apache.org/licenses/LICENSE-2.0
+* //
+* // Unless required by applicable law or agreed to in writing, software
+* // distributed under the License is distributed on an "AS IS" BASIS,
+* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* // See the License for the specific language governing permissions and
+* // limitations under the License.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+*/
+
+#include "JniOcSecureResource.h"
+#include "JniSecureUtils.h"
+namespace PH = std::placeholders;
+
+JniOcSecureResource::JniOcSecureResource(std::shared_ptr<OCSecureResource> device)
+    : m_sharedSecureResource(device)
+{}
+
+JniOcSecureResource::~JniOcSecureResource()
+{
+    LOGD("~JniOcSecureResource()");
+    m_sharedSecureResource = nullptr;
+}
+
+std::string JniOcSecureResource::getIpAddr()
+{
+    return m_sharedSecureResource->getDevAddr();
+}
+
+std::string JniOcSecureResource::getDeviceID()
+{
+    return m_sharedSecureResource->getDeviceID();
+}
+
+int JniOcSecureResource::getDeviceStatus()
+{
+    return m_sharedSecureResource->getDeviceStatus();
+}
+
+bool JniOcSecureResource::getOwnedStatus()
+{
+    return m_sharedSecureResource->getOwnedStatus();
+}
+
+OCSecureResource* JniOcSecureResource::getDevicePtr()
+{
+    return m_sharedSecureResource.get();
+}
+
+JniOcSecureResource* JniOcSecureResource::getJniOcSecureResourcePtr(JNIEnv *env, jobject thiz)
+{
+    JniOcSecureResource *secureResource = GetHandle<JniOcSecureResource>(env, thiz);
+    if (env->ExceptionCheck())
+    {
+        LOGE("Failed to get native handle from OcSecureResource");
+    }
+    if (!secureResource)
+    {
+        ThrowOcException(JNI_NO_NATIVE_POINTER, "");
+    }
+    return secureResource;
+}
+
+JniProvisionResultListner* JniOcSecureResource::AddProvisionResultListener(JNIEnv* env,
+        jobject jListener)
+{
+    JniProvisionResultListner *resultListener = NULL;
+    resultMapLock.lock();
+
+    for (auto it = resultMap.begin(); it != resultMap.end(); ++it)
+    {
+        if (env->IsSameObject(jListener, it->first))
+        {
+            auto refPair = it->second;
+            resultListener = refPair.first;
+            refPair.second++;
+            it->second = refPair;
+            resultMap.insert(*it);
+            LOGD("Provision resultListener: ref. count incremented");
+            break;
+        }
+    }
+    if (!resultListener)
+    {
+        resultListener = new JniProvisionResultListner(env, jListener,
+            RemoveCallback(std::bind(&JniOcSecureResource::RemoveProvisionResultListener,
+                    this, PH::_1, PH::_2)));
+        jobject jgListener = env->NewGlobalRef(jListener);
+
+        resultMap.insert(std::pair < jobject, std::pair < JniProvisionResultListner*,
+                int >> (jgListener, std::pair<JniProvisionResultListner*, int>(resultListener, 1)));
+        LOGD("Provision resultListener: new listener");
+    }
+    resultMapLock.unlock();
+    return resultListener;
+}
+
+void JniOcSecureResource::RemoveProvisionResultListener(JNIEnv* env, jobject jListener)
+{
+    resultMapLock.lock();
+
+    for (auto it = resultMap.begin(); it != resultMap.end(); ++it)
+    {
+        if (env->IsSameObject(jListener, it->first))
+        {
+            auto refPair = it->second;
+            if (refPair.second > 1)
+            {
+                refPair.second--;
+                it->second = refPair;
+                resultMap.insert(*it);
+                LOGI("Provision resultListener: ref. count decremented");
+            }
+            else
+            {
+                env->DeleteGlobalRef(it->first);
+                JniProvisionResultListner* listener = refPair.first;
+                delete listener;
+                resultMap.erase(it);
+                LOGI("Provision resultListener removed");
+            }
+            break;
+        }
+    }
+    resultMapLock.unlock();
+}
+
+OCStackResult JniOcSecureResource::doOwnershipTransfer(JNIEnv* env, jobject jListener)
+{
+    JniProvisionResultListner *resultListener = AddProvisionResultListener(env, jListener);
+
+    ResultCallBack resultCallback = [resultListener](PMResultList_t *result, int hasError)
+    {
+        resultListener->ProvisionResultCallback(result, hasError, ListenerFunc::OWNERSHIPTRANSFER);
+    };
+
+    return m_sharedSecureResource->doOwnershipTransfer(resultCallback);
+}
+
+OCStackResult JniOcSecureResource::getLinkedDevices(JNIEnv *env, UuidList_t &uuidList)
+{
+    return m_sharedSecureResource->getLinkedDevices(uuidList);
+}
+
+OCStackResult JniOcSecureResource::removeDevice(JNIEnv* env, jint timeout, jobject jListener)
+{
+    JniProvisionResultListner *resultListener = AddProvisionResultListener(env, jListener);
+
+    ResultCallBack resultCallback = [resultListener](PMResultList_t *result, int hasError)
+    {
+        resultListener->ProvisionResultCallback(result, hasError, ListenerFunc::REMOVEDEVICE);
+    };
+
+    return m_sharedSecureResource->removeDevice((int)timeout, resultCallback);
+}
+
+OCStackResult JniOcSecureResource::unlinkDevices(JNIEnv* env, jobject _device2, jobject jListener)
+{
+    JniProvisionResultListner *resultListener = AddProvisionResultListener(env, jListener);
+
+    ResultCallBack resultCallback = [resultListener](PMResultList_t *result, int hasError)
+    {
+        resultListener->ProvisionResultCallback(result, hasError, ListenerFunc::UNLINKDEVICES);
+    };
+
+    JniOcSecureResource *device2 = JniOcSecureResource::getJniOcSecureResourcePtr(env, _device2);
+    if (!device2)
+    {
+        return OC_STACK_ERROR;
+    }
+
+    return m_sharedSecureResource->unlinkDevices(*device2->getDevicePtr(), resultCallback);
+}
+
+OCStackResult JniOcSecureResource::provisionCredentials(JNIEnv* env, jint type, jint keySize,
+        jobject _device2, jobject jListener)
+{
+    JniProvisionResultListner *resultListener = AddProvisionResultListener(env, jListener);
+
+    ResultCallBack resultCallback = [resultListener](PMResultList_t *result, int hasError)
+    {
+        resultListener->ProvisionResultCallback(result, hasError, ListenerFunc::PROVISIONCREDENTIALS);
+    };
+
+    JniOcSecureResource *device2 = JniOcSecureResource::getJniOcSecureResourcePtr(env, _device2);
+    if (!device2)
+    {
+        return OC_STACK_ERROR;
+    }
+
+    Credential cred((OicSecCredType_t)type, keySize);
+
+    return m_sharedSecureResource->provisionCredentials(cred, *device2->getDevicePtr(),
+            resultCallback);
+}
+
+OCStackResult JniOcSecureResource::provisionACL(JNIEnv* env, jobject _acl, jobject jListener)
+{
+    OCStackResult ret;
+    JniProvisionResultListner *resultListener = AddProvisionResultListener(env, jListener);
+    OicSecAcl_t *acl = new OicSecAcl_t;
+    acl->next = nullptr;
+    if (!acl)
+    {
+        return OC_STACK_NO_MEMORY;
+    }
+
+    if (OC_STACK_OK != JniSecureUtils::convertJavaACLToOCAcl(env, _acl, acl))
+    {
+        delete acl;
+        return OC_STACK_ERROR;
+    }
+
+    ResultCallBack resultCallback = [acl, resultListener](PMResultList_t *result, int hasError)
+    {
+        delete acl;
+        resultListener->ProvisionResultCallback(result, hasError, ListenerFunc::PROVISIONACL);
+    };
+    ret = m_sharedSecureResource->provisionACL(acl, resultCallback);
+
+    if (ret != OC_STACK_OK)
+    {
+        delete acl;
+
+    }
+    return ret;
+}
+
+OCStackResult JniOcSecureResource::provisionPairwiseDevices(JNIEnv* env, jint type, jint keySize,
+        jobject _acl1, jobject _device2, jobject _acl2, jobject jListener)
+{
+    OCStackResult ret;
+
+    JniProvisionResultListner *resultListener = AddProvisionResultListener(env, jListener);
+    JniOcSecureResource *device2 = JniOcSecureResource::getJniOcSecureResourcePtr(env, _device2);
+    if (!device2)
+    {
+        return OC_STACK_ERROR;
+    }
+
+    Credential cred((OicSecCredType_t)type, keySize);
+
+    OicSecAcl_t *acl1 = nullptr;
+    OicSecAcl_t *acl2 = nullptr;
+
+    if (_acl1)
+    {
+        acl1 = new OicSecAcl_t;
+        if (!acl1)
+        {
+            return OC_STACK_NO_MEMORY;
+        }
+
+        if (OC_STACK_OK != JniSecureUtils::convertJavaACLToOCAcl(env, _acl1, acl1))
+        {
+            delete acl1;
+            return OC_STACK_ERROR;
+        }
+        acl1->next = nullptr;
+    }
+
+    if (_acl2)
+    {
+        acl2 = new OicSecAcl_t;
+        if (!acl2)
+        {
+            delete acl1;
+            return OC_STACK_NO_MEMORY;
+        }
+
+        if (OC_STACK_OK != JniSecureUtils::convertJavaACLToOCAcl(env, _acl2, acl2))
+        {
+            delete acl2;
+            return OC_STACK_ERROR;
+        }
+        acl2->next = nullptr;
+    }
+
+    ResultCallBack resultCallback = [acl1, acl2, resultListener](PMResultList_t *result,
+            int hasError)
+    {
+        delete acl1;
+        delete acl2;
+        resultListener->ProvisionResultCallback(result, hasError,
+                ListenerFunc::PROVISIONPAIRWISEDEVICES);
+    };
+
+
+    ret = m_sharedSecureResource->provisionPairwiseDevices(cred, acl1,
+            *device2->getDevicePtr(), acl2, resultCallback);
+    if (ret != OC_STACK_OK)
+    {
+        delete acl1;
+        delete acl2;
+    }
+    return ret;
+}
+
+/*
+ * Class:     org_iotivity_base_OcSecureResource
+ * Method:    doOwnershipTransfer
+ * Signature: (Lorg/iotivity/base/OcSecureResource/doOwnershipTransferListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_doOwnershipTransfer
+(JNIEnv *env, jobject thiz, jobject jListener)
+{
+    LOGD("OcSecureResource_doOwnershipTransfer");
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "provisionResultListener cannot be null");
+        return;
+    }
+
+    JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz);
+    if (!secureResource)
+    {
+        return;
+    }
+
+    try
+    {
+        OCStackResult result = secureResource->doOwnershipTransfer(env, jListener);
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcSecureResource_doOwnershipTransfer");
+            return;
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+}
+
+/*
+ * Class:     org_iotivity_base_OcSecureResource
+ * Method:    removeDevice
+ * Signature: (ILorg/iotivity/base/OcSecureResource/removeDevice;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_removeDevice
+(JNIEnv *env, jobject thiz, jint timeout, jobject jListener)
+{
+    LOGD("OcSecureResource_removeDevice");
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "provisionResultListener cannot be null");
+        return;
+    }
+
+    JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz);
+    if (!secureResource)
+    {
+        return;
+    }
+
+    try
+    {
+        OCStackResult result = secureResource->removeDevice(env, timeout, jListener);
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcSecureResource_removeDevice");
+            return;
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+}
+
+/*
+ * Class:     org_iotivity_base_OcSecureResource
+ * Method:    unlinkDevices
+ * Signature: (Lorg/iotivity/base/OcSecureResource/unlinkDevices;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_unlinkDevices
+(JNIEnv *env, jobject thiz, jobject device2, jobject jListener)
+{
+    LOGD("OcSecureResource_unlinkDevices");
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "provisionResultListener cannot be null");
+        return;
+    }
+
+    JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz);
+    if (!secureResource)
+    {
+        return;
+    }
+
+    try
+    {
+        OCStackResult result = secureResource->unlinkDevices(env, device2, jListener);
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcSecureResource_unlinkDevices");
+            return;
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+}
+
+/*
+ * Class:     org_iotivity_base_OcSecureResource
+ * Method:    provisionCredentials1
+ * Signature: (Lorg/iotivity/base/OcSecureResource/provisionCredentials;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionCredentials1
+(JNIEnv *env, jobject thiz, jint type, jint keySize, jobject device2, jobject jListener)
+{
+    LOGD("OcSecureResource_provisionCredentials");
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "provisionResultListener cannot be null");
+        return;
+    }
+
+    JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz);
+    if (!secureResource)
+    {
+        return;
+    }
+
+    try
+    {
+        OCStackResult result = secureResource->provisionCredentials(env, type, keySize, device2,
+                jListener);
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcSecureResource_provisionCredentials");
+            return;
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+}
+
+/*
+ * Class:     org_iotivity_base_OcSecureResource
+ * Method:    provisionACL
+ * Signature: (Lorg/iotivity/base/OcSecureResource/provisionACL;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionACL
+(JNIEnv *env, jobject thiz, jobject acl, jobject jListener)
+{
+    LOGD("OcSecureResource_provisionACL");
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "provisionResultListener cannot be null");
+        return;
+    }
+
+    JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz);
+    if (!secureResource)
+    {
+        return;
+    }
+
+    try
+    {
+        OCStackResult result = secureResource->provisionACL(env, acl, jListener);
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcSecureResource_provisionACL");
+            return;
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+}
+
+/*
+ * Class:     org_iotivity_base_OcSecureResource
+ * Method:    provisionPairwiseDevices1
+ * Signature: (Lorg/iotivity/base/OcSecureResource/provisionPairwiseDevices;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionPairwiseDevices1
+(JNIEnv *env, jobject thiz, jint type, jint keySize, jobject acl1, jobject device2,
+        jobject acl2, jobject jListener)
+{
+    LOGD("OcSecureResource_provisionPairwiseDevices");
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "provisionResultListener cannot be null");
+        return;
+    }
+
+    JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz);
+    if (!secureResource)
+    {
+        return;
+    }
+
+    try
+    {
+        OCStackResult result = secureResource->provisionPairwiseDevices(env, type, keySize,
+                acl1, device2, acl2, jListener);
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcSecureResource_provisionPairwiseDevices");
+            return;
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+}
+
+/*
+ * Class:     org_iotivity_base_OcSecureResource
+ * Method:    getLinkedDevices
+ * Signature: ()Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcSecureResource_getLinkedDevices
+(JNIEnv *env, jobject thiz)
+{
+    LOGD("OcSecureResource_getLinkedDevices");
+    UuidList_t uuidList;
+
+    JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz);
+    if (!secureResource)
+    {
+        return nullptr;
+    }
+
+    try
+    {
+        OCStackResult result = secureResource->getLinkedDevices(env, uuidList);
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcSecureResource_getLinkedDevices");
+            return nullptr;
+        }
+        return JniSecureUtils::convertUUIDVectorToJavaStrList(env, uuidList);
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+}
+
+/*
+ * Class:     org_iotivity_base_OcSecureResource
+ * Method:    getIpAddr
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcSecureResource_getIpAddr
+  (JNIEnv *env, jobject thiz)
+{
+    LOGD("OcSecureResource_getIpAddr");
+    JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz);
+    if (!secureResource)
+    {
+        return nullptr;
+    }
+
+    return env->NewStringUTF(secureResource->getIpAddr().c_str());
+}
+
+/*
+ * Class:     org_iotivity_base_OcSecureResource
+ * Method:    getDeviceID
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcSecureResource_getDeviceID
+  (JNIEnv *env , jobject thiz)
+{
+    LOGD("OcSecureResource_getDeviceID");
+    JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz);
+    if (!secureResource)
+    {
+        return nullptr;
+    }
+
+    return env->NewStringUTF(secureResource->getDeviceID().c_str());
+}
+
+/*
+ * Class:     org_iotivity_base_OcSecureResource
+ * Method:    deviceStatus
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_iotivity_base_OcSecureResource_deviceStatus
+  (JNIEnv *env, jobject thiz)
+{
+    LOGD("OcSecureResource_deviceStatus");
+    JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz);
+    if (!secureResource)
+    {
+        return -1;
+    }
+
+    return secureResource->getDeviceStatus();
+}
+
+/*
+ * Class:     org_iotivity_base_OcSecureResource
+ * Method:    ownedStatus
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_iotivity_base_OcSecureResource_ownedStatus
+  (JNIEnv *env, jobject thiz)
+{
+    LOGD("OcSecureResource_ownedStatus");
+    JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz);
+    if (!secureResource)
+    {
+        return -1;
+    }
+
+    return secureResource->getOwnedStatus();
+}
+
+/*
+ * Class:     org_iotivity_base_OcSecureResource
+ * Method:    dispose
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_dispose
+  (JNIEnv *env, jobject thiz)
+{
+    LOGD("OcSecureResource_dispose");
+    JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz);
+    delete secureResource;
+}
diff --git a/android/android_api/base/jni/JniOcSecureResource.h b/android/android_api/base/jni/JniOcSecureResource.h
new file mode 100644 (file)
index 0000000..0b98f75
--- /dev/null
@@ -0,0 +1,171 @@
+/*
+* //******************************************************************
+* //
+* // Copyright 2015 Samsung Electronics All Rights Reserved.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+* //
+* // Licensed under the Apache License, Version 2.0 (the "License");
+* // you may not use this file except in compliance with the License.
+* // You may obtain a copy of the License at
+* //
+* //      http://www.apache.org/licenses/LICENSE-2.0
+* //
+* // Unless required by applicable law or agreed to in writing, software
+* // distributed under the License is distributed on an "AS IS" BASIS,
+* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* // See the License for the specific language governing permissions and
+* // limitations under the License.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+*/
+
+#include "JniOcStack.h"
+#include "JniProvisionResultListner.h"
+#include "OCProvisioningManager.h"
+#include <mutex>
+
+#ifndef _Included_org_iotivity_base_OcSecureResource
+#define _Included_org_iotivity_base_OcSecureResource
+
+using namespace OC;
+
+class JniOcSecureResource
+{
+    public:
+        JniOcSecureResource(std::shared_ptr<OCSecureResource> secureresource);
+        ~JniOcSecureResource();
+
+        static JniOcSecureResource* getJniOcSecureResourcePtr(JNIEnv *env, jobject thiz);
+        std::string getDeviceID(void);
+        std::string getIpAddr(void);
+        int getDeviceStatus(void);
+        bool getOwnedStatus(void);
+        OCSecureResource* getDevicePtr();
+
+        JniProvisionResultListner* AddProvisionResultListener(JNIEnv* env, jobject jListener);
+        void  RemoveProvisionResultListener(JNIEnv* env, jobject jListener);
+
+        OCStackResult doOwnershipTransfer(JNIEnv* env, jobject jListener);
+        OCStackResult getLinkedDevices(JNIEnv *env, UuidList_t &uuidList);
+        OCStackResult provisionACL(JNIEnv* env, jobject acl, jobject jListener);
+        OCStackResult provisionPairwiseDevices(JNIEnv* env, jint type, jint keySize,
+                jobject acl1, jobject device2, jobject acl2, jobject jListener);
+        OCStackResult provisionCredentials(JNIEnv* env, jint type, jint keySize,
+                jobject device2, jobject jListener);
+        OCStackResult unlinkDevices(JNIEnv* env, jobject device2, jobject jListener);
+        OCStackResult removeDevice(JNIEnv* env, jint timeout, jobject jListener);
+
+    private:
+
+        std::map<jobject, std::pair<JniProvisionResultListner*, int>> resultMap;
+        std::mutex resultMapLock;
+        std::shared_ptr<OCSecureResource> m_sharedSecureResource;
+};
+
+/* DO NOT EDIT THIS FILE BEYOND THIS LINE - it is machine generated */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class:     org_iotivity_base_OcSecureResource
+ * Method:    doOwnershipTransfer
+ * Signature: (Lorg/iotivity/base/OcSecureResource/DoOwnershipTransferListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_doOwnershipTransfer
+  (JNIEnv *, jobject, jobject);
+
+/*
+ * Class:     org_iotivity_base_OcSecureResource
+ * Method:    removeDevice
+ * Signature: (ILorg/iotivity/base/OcSecureResource/RemoveDeviceListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_removeDevice
+  (JNIEnv *, jobject, jint, jobject);
+
+/*
+ * Class:     org_iotivity_base_OcSecureResource
+ * Method:    unlinkDevices
+ * Signature: (Ljava/lang/Object;Lorg/iotivity/base/OcSecureResource/UnlinkDevicesListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_unlinkDevices
+  (JNIEnv *, jobject, jobject, jobject);
+
+/*
+ * Class:     org_iotivity_base_OcSecureResource
+ * Method:    provisionCredentials1
+ * Signature: (IILjava/lang/Object;Lorg/iotivity/base/OcSecureResource/ProvisionCredentialsListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionCredentials1
+  (JNIEnv *, jobject, jint, jint, jobject, jobject);
+
+/*
+ * Class:     org_iotivity_base_OcSecureResource
+ * Method:    provisionACL
+ * Signature: (Ljava/lang/Object;Lorg/iotivity/base/OcSecureResource/ProvisionAclListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionACL
+  (JNIEnv *, jobject, jobject, jobject);
+
+/*
+ * Class:     org_iotivity_base_OcSecureResource
+ * Method:    provisionPairwiseDevices1
+ * Signature: (IILjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lorg/iotivity/base/OcSecureResource/ProvisionPairwiseDevicesListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionPairwiseDevices1
+  (JNIEnv *, jobject, jint, jint, jobject, jobject, jobject, jobject);
+
+/*
+ * Class:     org_iotivity_base_OcSecureResource
+ * Method:    getLinkedDevices
+ * Signature: ()Ljava/util/List;
+ */
+JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcSecureResource_getLinkedDevices
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     org_iotivity_base_OcSecureResource
+ * Method:    getIpAddr
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcSecureResource_getIpAddr
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     org_iotivity_base_OcSecureResource
+ * Method:    getDeviceID
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcSecureResource_getDeviceID
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     org_iotivity_base_OcSecureResource
+ * Method:    deviceStatus
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_iotivity_base_OcSecureResource_deviceStatus
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     org_iotivity_base_OcSecureResource
+ * Method:    ownedStatus
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_iotivity_base_OcSecureResource_ownedStatus
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     org_iotivity_base_OcSecureResource
+ * Method:    dispose
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_dispose
+  (JNIEnv *, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
+
index bb9868c..9884732 100644 (file)
@@ -60,6 +60,10 @@ jclass g_cls_OcHeaderOption = NULL;
 jclass g_cls_ObservationInfo = NULL;
 jclass g_cls_OcResourceIdentifier = NULL;
 
+jclass g_cls_OcProvisionResult = NULL;
+jclass g_cls_OcSecureResource = NULL;
+jclass g_cls_OcOicSecAcl = NULL;
+
 jmethodID g_mid_Integer_ctor = NULL;
 jmethodID g_mid_Double_ctor = NULL;
 jmethodID g_mid_Boolean_ctor = NULL;
@@ -90,6 +94,19 @@ jmethodID g_mid_ObservationInfo_N_ctor = NULL;
 jmethodID g_mid_OcPresenceStatus_get = NULL;
 jmethodID g_mid_OcResourceIdentifier_N_ctor = NULL;
 
+jmethodID g_mid_OcProvisionResult_ctor = NULL;
+jmethodID g_mid_OcSecureResource_ctor = NULL;
+
+jmethodID g_mid_OcOicSecAcl_get_subject = NULL;
+jmethodID g_mid_OcOicSecAcl_get_resources_cnt = NULL;
+jmethodID g_mid_OcOicSecAcl_get_resources = NULL;
+jmethodID g_mid_OcOicSecAcl_get_permission = NULL;
+jmethodID g_mid_OcOicSecAcl_get_periods_cnt = NULL;
+jmethodID g_mid_OcOicSecAcl_get_periods = NULL;
+jmethodID g_mid_OcOicSecAcl_get_recurrences = NULL;
+jmethodID g_mid_OcOicSecAcl_get_owners_cnt = NULL;
+jmethodID g_mid_OcOicSecAcl_get_owners = NULL;
+
 jobject getOcException(JNIEnv* env, const char* file, const char* functionName,
     const int line, const int code, const char* message)
 {
@@ -400,6 +417,55 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
     g_mid_OcResourceIdentifier_N_ctor = env->GetMethodID(g_cls_OcResourceIdentifier, "<init>", "(J)V");
     if (!g_mid_OcResourceIdentifier_N_ctor) return JNI_ERR;
 
+    //OcSecureResource
+    clazz = env->FindClass("org/iotivity/base/OcSecureResource");
+    if (!clazz) return JNI_ERR;
+    g_cls_OcSecureResource =  (jclass)env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+    g_mid_OcSecureResource_ctor = env->GetMethodID(g_cls_OcSecureResource, "<init>", "(J)V");
+    if (!g_mid_OcSecureResource_ctor) return JNI_ERR;
+
+    //ProvisionResult
+    clazz = env->FindClass("org/iotivity/base/ProvisionResult");
+    if (!clazz) return JNI_ERR;
+    g_cls_OcProvisionResult =  (jclass)env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+    g_mid_OcProvisionResult_ctor = env->GetMethodID(g_cls_OcProvisionResult, "<init>", "(Ljava/lang/String;I)V");
+    if (!g_mid_OcProvisionResult_ctor) return JNI_ERR;
+
+    //OicSecAcl
+    clazz = env->FindClass("org/iotivity/base/OicSecAcl");
+    if (!clazz) return JNI_ERR;
+    g_cls_OcOicSecAcl =  (jclass)env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+
+    g_mid_OcOicSecAcl_get_subject = env->GetMethodID(g_cls_OcOicSecAcl, "getSubject", "()Ljava/lang/String;");
+    if (!g_mid_OcOicSecAcl_get_subject) return JNI_ERR;
+
+    g_mid_OcOicSecAcl_get_resources_cnt = env->GetMethodID(g_cls_OcOicSecAcl, "getResourcesCount", "()I");
+    if (!g_mid_OcOicSecAcl_get_resources_cnt) return JNI_ERR;
+
+    g_mid_OcOicSecAcl_get_resources = env->GetMethodID(g_cls_OcOicSecAcl, "getResources", "(I)Ljava/lang/String;");
+    if (!g_mid_OcOicSecAcl_get_resources) return JNI_ERR;
+
+    g_mid_OcOicSecAcl_get_permission = env->GetMethodID(g_cls_OcOicSecAcl, "getPermission", "()I");
+    if (!g_mid_OcOicSecAcl_get_permission) return JNI_ERR;
+
+    g_mid_OcOicSecAcl_get_periods_cnt = env->GetMethodID(g_cls_OcOicSecAcl, "getPeriodsCount", "()I");
+    if (!g_mid_OcOicSecAcl_get_periods_cnt) return JNI_ERR;
+
+    g_mid_OcOicSecAcl_get_periods = env->GetMethodID(g_cls_OcOicSecAcl, "getPeriods", "(I)Ljava/lang/String;");
+    if (!g_mid_OcOicSecAcl_get_periods) return JNI_ERR;
+
+    g_mid_OcOicSecAcl_get_recurrences = env->GetMethodID(g_cls_OcOicSecAcl, "getRecurrences", "(I)Ljava/lang/String;");
+    if (!g_mid_OcOicSecAcl_get_recurrences) return JNI_ERR;
+
+    g_mid_OcOicSecAcl_get_owners_cnt = env->GetMethodID(g_cls_OcOicSecAcl, "getOwnersCount", "()I");
+    if (!g_mid_OcOicSecAcl_get_owners_cnt) return JNI_ERR;
+
+    g_mid_OcOicSecAcl_get_owners = env->GetMethodID(g_cls_OcOicSecAcl, "getOwners", "(I)Ljava/lang/String;");
+    if (!g_mid_OcOicSecAcl_get_owners) return JNI_ERR;
+
     return JNI_CURRENT_VERSION;
 }
 
@@ -446,4 +512,7 @@ JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
     env->DeleteGlobalRef(g_cls_OcHeaderOption);
     env->DeleteGlobalRef(g_cls_ObservationInfo);
     env->DeleteGlobalRef(g_cls_OcResourceIdentifier);
+    env->DeleteGlobalRef(g_cls_OcSecureResource);
+    env->DeleteGlobalRef(g_cls_OcProvisionResult);
+    env->DeleteGlobalRef(g_cls_OcOicSecAcl);
 }
\ No newline at end of file
index f6b1ee0..1bb7fae 100644 (file)
@@ -79,6 +79,9 @@ extern jclass g_cls_OcPresenceStatus;
 extern jclass g_cls_OcHeaderOption;
 extern jclass g_cls_ObservationInfo;
 extern jclass g_cls_OcResourceIdentifier;
+extern jclass g_cls_OcProvisionResult;
+extern jclass g_cls_OcSecureResource;
+extern jclass g_cls_OcOicSecAcl;
 
 extern jmethodID g_mid_Integer_ctor;
 extern jmethodID g_mid_Double_ctor;
@@ -109,6 +112,17 @@ extern jmethodID g_mid_OcHeaderOption_get_data;
 extern jmethodID g_mid_ObservationInfo_N_ctor;
 extern jmethodID g_mid_OcPresenceStatus_get;
 extern jmethodID g_mid_OcResourceIdentifier_N_ctor;
+extern jmethodID g_mid_OcProvisionResult_ctor;
+extern jmethodID g_mid_OcSecureResource_ctor;
+extern jmethodID g_mid_OcOicSecAcl_get_subject;
+extern jmethodID g_mid_OcOicSecAcl_get_resources_cnt;
+extern jmethodID g_mid_OcOicSecAcl_get_resources;
+extern jmethodID g_mid_OcOicSecAcl_get_permission;
+extern jmethodID g_mid_OcOicSecAcl_get_periods_cnt;
+extern jmethodID g_mid_OcOicSecAcl_get_periods;
+extern jmethodID g_mid_OcOicSecAcl_get_recurrences;
+extern jmethodID g_mid_OcOicSecAcl_get_owners_cnt;
+extern jmethodID g_mid_OcOicSecAcl_get_owners;
 
 typedef void(*RemoveListenerCallback)(JNIEnv* env, jobject jListener);
 
diff --git a/android/android_api/base/jni/JniPinCheckListener.cpp b/android/android_api/base/jni/JniPinCheckListener.cpp
new file mode 100644 (file)
index 0000000..9a5e35a
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+* //******************************************************************
+* //
+* // Copyright 2015 Samsung Electronics All Rights Reserved.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+* //
+* // Licensed under the Apache License, Version 2.0 (the "License");
+* // you may not use this file except in compliance with the License.
+* // You may obtain a copy of the License at
+* //
+* //      http://www.apache.org/licenses/LICENSE-2.0
+* //
+* // Unless required by applicable law or agreed to in writing, software
+* // distributed under the License is distributed on an "AS IS" BASIS,
+* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* // See the License for the specific language governing permissions and
+* // limitations under the License.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+*/
+#include "JniPinCheckListener.h"
+#include "oic_string.h"
+
+JniPinCheckListener::JniPinCheckListener(JNIEnv *env, jobject jListener)
+{
+    m_jListener = env->NewGlobalRef(jListener);
+}
+
+JniPinCheckListener::~JniPinCheckListener()
+{
+    LOGI("~JniPinCheckListener()");
+    if (m_jListener)
+    {
+        jint ret;
+        JNIEnv *env = GetJNIEnv(ret);
+        if (NULL == env) return;
+        env->DeleteWeakGlobalRef(m_jListener);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+    }
+}
+
+void JniPinCheckListener::PinCallback(char *pinBuf, size_t bufSize)
+{
+    jint ret;
+
+    JNIEnv *env = GetJNIEnv(ret);
+    if (NULL == env) return;
+
+    jclass clsL = env->GetObjectClass(m_jListener);
+
+    if (!clsL)
+    {
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        return;
+    }
+
+    jmethodID midL = env->GetMethodID(clsL, "pinCallbackListener", "()Ljava/lang/String;");
+    if (!midL)
+    {
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        return;
+    }
+    jstring jpin = (jstring)env->CallObjectMethod(m_jListener, midL);
+    if (env->ExceptionCheck())
+    {
+        LOGE("Java exception is thrown");
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        return;
+    }
+
+    char *str = (char*)env->GetStringUTFChars(jpin, NULL);
+    OICStrcpy(pinBuf, bufSize, str);
+    env->ReleaseStringUTFChars(jpin, str);
+
+    if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+}
diff --git a/android/android_api/base/jni/JniPinCheckListener.h b/android/android_api/base/jni/JniPinCheckListener.h
new file mode 100644 (file)
index 0000000..74d150d
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+* //******************************************************************
+* //
+* // Copyright 2015 Samsung Electronics All Rights Reserved.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+* //
+* // Licensed under the Apache License, Version 2.0 (the "License");
+* // you may not use this file except in compliance with the License.
+* // You may obtain a copy of the License at
+* //
+* //      http://www.apache.org/licenses/LICENSE-2.0
+* //
+* // Unless required by applicable law or agreed to in writing, software
+* // distributed under the License is distributed on an "AS IS" BASIS,
+* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* // See the License for the specific language governing permissions and
+* // limitations under the License.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+*/
+
+#include "JniOcStack.h"
+#include "OCProvisioningManager.h"
+
+#ifndef _Included_org_iotivity_base_PinCheckListener
+#define _Included_org_iotivity_base_PinCheckListener
+
+typedef std::function<void(JNIEnv* env, jobject jListener)> RemoveCallback;
+class JniPinCheckListener
+{
+    public:
+        JniPinCheckListener(JNIEnv *, jobject);
+        ~JniPinCheckListener();
+
+        void PinCallback(char*, size_t);
+    private:
+        jobject m_jListener;
+};
+#endif
diff --git a/android/android_api/base/jni/JniProvisionResultListner.cpp b/android/android_api/base/jni/JniProvisionResultListner.cpp
new file mode 100644 (file)
index 0000000..6b9fd04
--- /dev/null
@@ -0,0 +1,150 @@
+/*
+* //******************************************************************
+* //
+* // Copyright 2015 Samsung Electronics All Rights Reserved.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+* //
+* // Licensed under the Apache License, Version 2.0 (the "License");
+* // you may not use this file except in compliance with the License.
+* // You may obtain a copy of the License at
+* //
+* //      http://www.apache.org/licenses/LICENSE-2.0
+* //
+* // Unless required by applicable law or agreed to in writing, software
+* // distributed under the License is distributed on an "AS IS" BASIS,
+* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* // See the License for the specific language governing permissions and
+* // limitations under the License.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+*/
+#include "JniProvisionResultListner.h"
+#include "JniOcSecureResource.h"
+#include "JniSecureUtils.h"
+
+JniProvisionResultListner::JniProvisionResultListner(JNIEnv *env, jobject jListener,
+    RemoveCallback removeProvisionResultListener)
+{
+    m_jwListener = env->NewWeakGlobalRef(jListener);
+    m_removeProvisionResultListener = removeProvisionResultListener;
+}
+
+JniProvisionResultListner::~JniProvisionResultListner()
+{
+    LOGI("~JniProvisionResultListner()");
+    if (m_jwListener)
+    {
+        jint ret;
+        JNIEnv *env = GetJNIEnv(ret);
+        if (NULL == env) return;
+        env->DeleteWeakGlobalRef(m_jwListener);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+    }
+}
+
+void JniProvisionResultListner::ProvisionResultCallback(PMResultList_t *result, int hasError,
+      ListenerFunc func)
+{
+    jint ret;
+    JNIEnv *env = GetJNIEnv(ret);
+    if (NULL == env) return;
+
+    jobject jListener = env->NewLocalRef(m_jwListener);
+    if (!jListener)
+    {
+        checkExAndRemoveListener(env);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        return;
+    }
+
+    jclass clsL = env->GetObjectClass(jListener);
+
+    if (!clsL)
+    {
+        checkExAndRemoveListener(env);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        return;
+    }
+
+
+    jobject jResultList = JniSecureUtils::convertProvisionresultVectorToJavaList(env, result);
+    if (!jResultList)
+    {
+        checkExAndRemoveListener(env);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        return;
+    }
+
+    std::string calledFunc;
+    switch (func)
+    {
+        case ListenerFunc::OWNERSHIPTRANSFER:
+        {
+            calledFunc = "doOwnershipTransferListener";
+        }
+        break;
+        case ListenerFunc::PROVISIONACL:
+        {
+            calledFunc = "provisionAclListener";
+        }
+        break;
+        case ListenerFunc::PROVISIONCREDENTIALS:
+        {
+            calledFunc = "provisionCredentialsListener";
+        }
+        break;
+        case ListenerFunc::UNLINKDEVICES:
+        {
+            calledFunc = "unlinkDevicesListener";
+        }
+        break;
+        case ListenerFunc::REMOVEDEVICE:
+        {
+            calledFunc = "removeDeviceListener";
+        }
+        break;
+        case ListenerFunc::PROVISIONPAIRWISEDEVICES:
+        {
+            calledFunc = "provisionPairwiseDevicesListener";
+        }
+        break;
+        default:
+        {
+            checkExAndRemoveListener(env);
+            if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        }
+        return;
+    }
+
+    jmethodID midL = env->GetMethodID(clsL, calledFunc.c_str(), "(Ljava/util/List;I)V");
+    if (!midL)
+    {
+        checkExAndRemoveListener(env);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        return;
+    }
+    env->CallVoidMethod(jListener, midL, jResultList, (jint)hasError);
+    if (env->ExceptionCheck())
+    {
+        LOGE("Java exception is thrown");
+    }
+
+    checkExAndRemoveListener(env);
+    if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+}
+
+void JniProvisionResultListner::checkExAndRemoveListener(JNIEnv* env)
+{
+    if (env->ExceptionCheck())
+    {
+        jthrowable ex = env->ExceptionOccurred();
+        env->ExceptionClear();
+        m_removeProvisionResultListener(env, m_jwListener);
+        env->Throw((jthrowable)ex);
+    }
+    else
+    {
+        m_removeProvisionResultListener(env, m_jwListener);
+    }
+}
diff --git a/android/android_api/base/jni/JniProvisionResultListner.h b/android/android_api/base/jni/JniProvisionResultListner.h
new file mode 100644 (file)
index 0000000..6df56d7
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+* //******************************************************************
+* //
+* // Copyright 2015 Samsung Electronics All Rights Reserved.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+* //
+* // Licensed under the Apache License, Version 2.0 (the "License");
+* // you may not use this file except in compliance with the License.
+* // You may obtain a copy of the License at
+* //
+* //      http://www.apache.org/licenses/LICENSE-2.0
+* //
+* // Unless required by applicable law or agreed to in writing, software
+* // distributed under the License is distributed on an "AS IS" BASIS,
+* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* // See the License for the specific language governing permissions and
+* // limitations under the License.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+*/
+#include <jni.h>
+#include "JniOcStack.h"
+#include "OCProvisioningManager.h"
+
+#ifndef _Included_org_iotivity_base_OcProvisioning_JniProvisionResultListner
+#define _Included_org_iotivity_base_OcProvisioning_JniProvisionResultListner
+
+typedef std::function<void(JNIEnv* env, jobject jListener)> RemoveCallback;
+
+enum class ListenerFunc
+{
+    OWNERSHIPTRANSFER = 1,
+    PROVISIONACL,
+    PROVISIONCREDENTIALS,
+    UNLINKDEVICES,
+    REMOVEDEVICE,
+    PROVISIONPAIRWISEDEVICES
+};
+
+class JniProvisionResultListner
+{
+    public:
+        JniProvisionResultListner(JNIEnv *env, jobject jListener,
+                RemoveCallback removeProvisionResultListener);
+        ~JniProvisionResultListner();
+
+        void ProvisionResultCallback(OC::PMResultList_t *result, int hasError, ListenerFunc func);
+
+    private:
+        RemoveCallback m_removeProvisionResultListener;
+        jweak m_jwListener;
+        void checkExAndRemoveListener(JNIEnv* env);
+};
+#endif
diff --git a/android/android_api/base/jni/JniSecureUtils.cpp b/android/android_api/base/jni/JniSecureUtils.cpp
new file mode 100644 (file)
index 0000000..2fb507f
--- /dev/null
@@ -0,0 +1,240 @@
+/*
+* //******************************************************************
+* //
+* // Copyright 2015 Samsung Electronics All Rights Reserved.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+* //
+* // Licensed under the Apache License, Version 2.0 (the "License");
+* // you may not use this file except in compliance with the License.
+* // You may obtain a copy of the License at
+* //
+* //      http://www.apache.org/licenses/LICENSE-2.0
+* //
+* // Unless required by applicable law or agreed to in writing, software
+* // distributed under the License is distributed on an "AS IS" BASIS,
+* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* // See the License for the specific language governing permissions and
+* // limitations under the License.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+*/
+
+#include "JniSecureUtils.h"
+#include "JniOcSecureResource.h"
+#include "base64.h"
+
+jobject JniSecureUtils::convertProvisionresultVectorToJavaList(JNIEnv *env, const OC::PMResultList_t *result)
+{
+    jobject jResultList = env->NewObject(g_cls_LinkedList, g_mid_LinkedList_ctor);
+    if (!jResultList)
+    {
+        return nullptr;
+    }
+
+    for (size_t i = 0; i < result->size(); ++i)
+    {
+        jobject jresult = env->NewObject(
+                g_cls_OcProvisionResult,
+                g_mid_OcProvisionResult_ctor,
+                env->NewStringUTF((char*)result->at(i).deviceId.id),
+                static_cast<jint>(result->at(i).res)
+                );
+        if (!jresult)
+        {
+            return nullptr;
+        }
+
+        env->CallBooleanMethod(jResultList, g_mid_LinkedList_add_object, jresult);
+        if (env->ExceptionCheck())
+        {
+            return nullptr;
+        }
+        env->DeleteLocalRef(jresult);
+    }
+    return jResultList;
+}
+
+jobjectArray JniSecureUtils::convertDeviceVectorToJavaArray(JNIEnv *env,
+    std::vector<std::shared_ptr<OC::OCSecureResource>> &deviceListVector)
+{
+    jsize len = static_cast<jsize>(deviceListVector.size());
+    jobjectArray devArr = env->NewObjectArray(len, g_cls_OcSecureResource, NULL);
+
+    if (!devArr)
+    {
+        return nullptr;
+    }
+
+    for (jsize i = 0; i < len; ++i)
+    {
+        JniOcSecureResource *device = new JniOcSecureResource(deviceListVector[i]);
+        jobject jDevice = env->NewObject(g_cls_OcSecureResource, g_mid_OcSecureResource_ctor);
+
+        SetHandle<JniOcSecureResource>(env, jDevice, device);
+        if (!jDevice)
+        {
+            return nullptr;
+        }
+
+        env->SetObjectArrayElement(devArr, i, jDevice);
+        if (env->ExceptionCheck())
+        {
+            return nullptr;
+        }
+        env->DeleteLocalRef(jDevice);
+    }
+    return devArr;
+}
+
+std::string JniSecureUtils::convertUUIDtoStr(OicUuid_t uuid)
+{
+    std::ostringstream deviceId("");
+    char base64Buff[B64ENCODE_OUT_SAFESIZE(sizeof(((OicUuid_t*)0)->id)) + 1] = {0,};
+    uint32_t outLen = 0;
+    B64Result b64Ret = B64_OK;
+
+    b64Ret = b64Encode(uuid.id, sizeof(uuid.id), base64Buff,
+            sizeof(base64Buff), &outLen);
+
+    deviceId << base64Buff;
+    return deviceId.str();
+}
+
+void JniSecureUtils::convertStrToUUID(char *str, OicUuid_t &uuid)
+{
+    unsigned char base64Buff[sizeof(((OicUuid_t*)0)->id)] = {};
+    uint32_t outLen = 0;
+    B64Result b64Ret = B64_OK;
+
+    b64Ret = b64Decode(str, strlen(str), base64Buff, sizeof(base64Buff), &outLen);
+    memcpy(uuid.id, base64Buff, outLen);
+}
+
+jobject JniSecureUtils::convertUUIDVectorToJavaStrList(JNIEnv *env, UuidList_t &vector)
+{
+    jobject jList = env->NewObject(g_cls_LinkedList, g_mid_LinkedList_ctor);
+    if (!jList)
+    {
+        return nullptr;
+    }
+    for (size_t i = 0; i < vector.size(); ++i)
+    {
+        jstring jStr = env->NewStringUTF((convertUUIDtoStr(vector[i])).c_str());
+        if (!jStr)
+        {
+            return nullptr;
+        }
+        env->CallBooleanMethod(jList, g_mid_LinkedList_add_object, jStr);
+        if (env->ExceptionCheck())
+        {
+            return nullptr;
+        }
+        env->DeleteLocalRef(jStr);
+    }
+    return jList;
+}
+
+OCStackResult JniSecureUtils::convertJavaACLToOCAcl(JNIEnv *env, jobject in, OicSecAcl_t *acl)
+{
+    jstring jData;
+    jvalue args[1];
+
+    jData = (jstring) env->CallObjectMethod(in, g_mid_OcOicSecAcl_get_subject);
+    if (!jData || env->ExceptionCheck())
+    {
+        return OC_STACK_ERROR;
+    }
+
+    char *str = (char*) env->GetStringUTFChars(jData, 0);
+    convertStrToUUID(str, acl->subject);
+    env->ReleaseStringUTFChars(jData, str);
+
+    jint jCount = (jint) env->CallIntMethod(in, g_mid_OcOicSecAcl_get_resources_cnt);
+    if (!jCount || env->ExceptionCheck())
+    {
+        return OC_STACK_ERROR;
+    }
+
+    acl->resourcesLen = jCount;
+    acl->resources = new char*[jCount];
+    for (jint i = 0; i < jCount; ++i)
+    {
+        args[0].i = i;
+        jData = (jstring) env->CallObjectMethodA(in, g_mid_OcOicSecAcl_get_resources, args);
+        if (!jData || env->ExceptionCheck())
+        {
+            return OC_STACK_ERROR;
+        }
+
+        acl->resources[i] = (char*) env->GetStringUTFChars(jData, 0);
+    }
+
+    jCount = (jint) env->CallIntMethod(in, g_mid_OcOicSecAcl_get_permission);
+    if (env->ExceptionCheck())
+    {
+        return OC_STACK_ERROR;
+    }
+
+    acl->permission = jCount;
+    jCount = (jint) env->CallIntMethod(in, g_mid_OcOicSecAcl_get_periods_cnt);
+    if (env->ExceptionCheck())
+    {
+        return OC_STACK_ERROR;
+    }
+
+    acl->prdRecrLen = jCount;
+    acl->periods = new char*[jCount];
+    for (jint i = 0; i < jCount; ++i)
+    {
+        args[0].i = i;
+        jData = (jstring) env->CallObjectMethodA(in, g_mid_OcOicSecAcl_get_periods, args);
+        if (!jData || env->ExceptionCheck())
+        {
+            return OC_STACK_ERROR;
+        }
+
+        acl->periods[i] = (char*) env->GetStringUTFChars(jData, 0);
+    }
+
+    acl->recurrences = new char*[jCount]; //TODO:Period Len and Reccurence len is same
+    for (jint i = 0; i < jCount; ++i)
+    {
+        args[0].i = i;
+        jData = (jstring) env->CallObjectMethodA(in, g_mid_OcOicSecAcl_get_recurrences, args);
+        if (!jData ||  env->ExceptionCheck())
+        {
+            return OC_STACK_ERROR;
+        }
+
+        acl->recurrences[i] = (char*) env->GetStringUTFChars(jData, 0);
+    }
+
+    jCount = (jint) env->CallIntMethod(in, g_mid_OcOicSecAcl_get_owners_cnt);
+    if (!jCount ||  env->ExceptionCheck())
+    {
+        return OC_STACK_ERROR;
+    }
+
+    acl->ownersLen = jCount;
+    acl->owners = new OicUuid_t[acl->ownersLen];
+    if (!acl->owners)
+    {
+        return OC_STACK_ERROR;
+    }
+
+    for (jint i = 0; i < jCount; ++i)
+    {
+        args[0].i = i;
+        jData = (jstring) env->CallObjectMethodA(in, g_mid_OcOicSecAcl_get_owners, args);
+        if (!jData ||  env->ExceptionCheck())
+        {
+            return OC_STACK_ERROR;
+        }
+
+        str = (char*) env->GetStringUTFChars(jData, 0);
+        convertStrToUUID(str, acl->owners[i]);
+        env->ReleaseStringUTFChars(jData, str);
+    }
+    return OC_STACK_OK;
+}
diff --git a/android/android_api/base/jni/JniSecureUtils.h b/android/android_api/base/jni/JniSecureUtils.h
new file mode 100644 (file)
index 0000000..c239c44
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+* //******************************************************************
+* //
+* // Copyright 2015 Samsung Electronics All Rights Reserved.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+* //
+* // Licensed under the Apache License, Version 2.0 (the "License");
+* // you may not use this file except in compliance with the License.
+* // You may obtain a copy of the License at
+* //
+* //      http://www.apache.org/licenses/LICENSE-2.0
+* //
+* // Unless required by applicable law or agreed to in writing, software
+* // distributed under the License is distributed on an "AS IS" BASIS,
+* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* // See the License for the specific language governing permissions and
+* // limitations under the License.
+* //
+* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+*/
+
+#include "JniOcStack.h"
+#include "OCProvisioningManager.h"
+
+class JniSecureUtils
+{
+    private:
+        static std::string convertUUIDtoStr(OicUuid_t uuid);
+        static void convertStrToUUID(char *str, OicUuid_t &uuid);
+    public:
+        static jobject convertProvisionresultVectorToJavaList(JNIEnv *,
+                const OC::PMResultList_t *);
+        static jobjectArray convertDeviceVectorToJavaArray(JNIEnv *env,
+                std::vector<std::shared_ptr<OC::OCSecureResource>>& deviceListVector);
+        static jobject convertUUIDVectorToJavaStrList(JNIEnv *env, OC::UuidList_t &vector);
+        static OCStackResult convertJavaACLToOCAcl(JNIEnv *env, jobject in, OicSecAcl_t *out);
+};
diff --git a/android/android_api/base/src/main/java/org/iotivity/base/CredType.java b/android/android_api/base/src/main/java/org/iotivity/base/CredType.java
new file mode 100644 (file)
index 0000000..bbaeda7
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * //******************************************************************
+ * //
+ * // Copyright 2015  Samsung Electronics All Rights Reserved.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // Licensed under the Apache License, Version 2.0 (the "License");
+ * // you may not use this file except in compliance with the License.
+ * // You may obtain a copy of the License at
+ * //
+ * //      http://www.apache.org/licenses/LICENSE-2.0
+ * //
+ * // Unless required by applicable law or agreed to in writing, software
+ * // distributed under the License is distributed on an "AS IS" BASIS,
+ * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * // See the License for the specific language governing permissions and
+ * // limitations under the License.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+package org.iotivity.base;
+
+import java.security.InvalidParameterException;
+import java.util.EnumSet;
+
+public enum CredType {
+
+    NO_SECURITY_MODE                (0),
+
+    SYMMETRIC_PAIR_WISE_KEY         (1 << 0),
+
+    SYMMETRIC_GROUP_KEY             (1 << 1),
+
+    ASYMMETRIC_KEY                  (1 << 2),
+
+    SIGNED_ASYMMETRIC_KEY           (1 << 3),
+
+    PIN_PASSWORD                    (1 << 4),
+
+    ASYMMETRIC_ENCRYPTION_KEY       (1 << 5),
+
+    ;
+    private int value;
+
+    private CredType(int value) {
+        this.value = value;
+    }
+
+    public int getValue() {
+        return this.value;
+    }
+
+    public static EnumSet<CredType> convertToEnumSet(int value) {
+        EnumSet<CredType> typeSet = null;
+
+        for (CredType v : values()) {
+            if (0 != (value & v.getValue())) {
+                if (null == typeSet) {
+                    typeSet = EnumSet.of(v);
+                } else {
+                    typeSet.add(v);
+                }
+            }
+        }
+
+        if (null == typeSet || typeSet.isEmpty()) {
+            throw new InvalidParameterException("Unexpected CredType value:" + value);
+        }
+
+        return typeSet;
+    }
+}
diff --git a/android/android_api/base/src/main/java/org/iotivity/base/DeviceStatus.java b/android/android_api/base/src/main/java/org/iotivity/base/DeviceStatus.java
new file mode 100644 (file)
index 0000000..4bc2e6f
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * //******************************************************************
+ * //
+ * // Copyright 2015 Samsung Electronics All Rights Reserved.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // Licensed under the Apache License, Version 2.0 (the "License");
+ * // you may not use this file except in compliance with the License.
+ * // You may obtain a copy of the License at
+ * //
+ * //      http://www.apache.org/licenses/LICENSE-2.0
+ * //
+ * // Unless required by applicable law or agreed to in writing, software
+ * // distributed under the License is distributed on an "AS IS" BASIS,
+ * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * // See the License for the specific language governing permissions and
+ * // limitations under the License.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+package org.iotivity.base;
+
+public enum DeviceStatus {
+    ON(0),
+    OFF(1),
+    INVALID(-1);
+
+    private int value;
+
+    private DeviceStatus(int value) {
+        this.value = value;
+    }
+
+    public int getValue() {
+        return this.value;
+    }
+
+    public static DeviceStatus convertDeviceStatus(int value) {
+
+        if (0 == value)
+        {
+            return DeviceStatus.ON;
+        }
+        else if (1 == value)
+        {
+            return DeviceStatus.OFF;
+        }
+        else
+        {
+            return DeviceStatus.INVALID;
+        }
+    }
+}
diff --git a/android/android_api/base/src/main/java/org/iotivity/base/KeySize.java b/android/android_api/base/src/main/java/org/iotivity/base/KeySize.java
new file mode 100644 (file)
index 0000000..6243db6
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * //******************************************************************
+ * //
+ * // Copyright 2015 Samsung Electronics All Rights Reserved.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // Licensed under the Apache License, Version 2.0 (the "License");
+ * // you may not use this file except in compliance with the License.
+ * // You may obtain a copy of the License at
+ * //
+ * //      http://www.apache.org/licenses/LICENSE-2.0
+ * //
+ * // Unless required by applicable law or agreed to in writing, software
+ * // distributed under the License is distributed on an "AS IS" BASIS,
+ * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * // See the License for the specific language governing permissions and
+ * // limitations under the License.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+package org.iotivity.base;
+
+public enum KeySize {
+    OWNER_PSK_LENGTH_128 (128/8),
+    OWNER_PSK_LENGTH_256 (256/8),;
+
+    private int value;
+
+    private KeySize(int value) {
+        this.value = value;
+    }
+
+    public int getValue() {
+        return this.value;
+    }
+}
diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcProvisioning.java b/android/android_api/base/src/main/java/org/iotivity/base/OcProvisioning.java
new file mode 100644 (file)
index 0000000..636e590
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * //******************************************************************
+ * //
+ * // Copyright 2015 Samsung Electronics All Rights Reserved.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // Licensed under the Apache License, Version 2.0 (the "License");
+ * // you may not use this file except in compliance with the License.
+ * // You may obtain a copy of the License at
+ * //
+ * //      http://www.apache.org/licenses/LICENSE-2.0
+ * //
+ * // Unless required by applicable law or agreed to in writing, software
+ * // distributed under the License is distributed on an "AS IS" BASIS,
+ * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * // See the License for the specific language governing permissions and
+ * // limitations under the License.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+package org.iotivity.base;
+
+import java.util.List;
+import java.util.Arrays;
+import java.util.Map;
+
+/**
+ * OcProvisionig represents functions corresponding to the provisioing of
+ * resources.
+ */
+public class OcProvisioning {
+
+    /**
+     * Method to Intialize Provisioning Manager.This will load the provisioning
+     * Manager's persistent database.
+     *
+     * @param dbPath     dbPath file path of the sqlite3 db.
+     * @throws OcException
+     */
+    public static native void provisionInit(String dbPath) throws OcException;
+
+    /**
+     * Method to Discover un-owned devices in its subnet.Un-owned devices need
+     * to be owned by calling ownershipTransferCBdata.
+     *
+     * @param timeout     Timeout in sec.Time to listen for responses before
+     *                    returining the Array.
+     * @return            Array of OcSecureResource class objects.
+     * @throws OcException
+     */
+    public  static List<OcSecureResource> discoverUnownedDevices(int timeout) throws OcException {
+        return Arrays.asList(OcProvisioning.discoverUnownedDevices1(timeout));
+    }
+    private static native OcSecureResource[] discoverUnownedDevices1(int timeout) throws OcException;
+
+    /**
+     * Method to Discover owned devices in its subnet.
+     *
+     * @param timeout     Timeout in sec.Time to listen for responses before
+     *                    returining the Array.
+     * @return            Array of OcSecureResource class objects.
+     * @throws OcException
+     */
+    public static List<OcSecureResource> discoverOwnedDevices(int timeout) throws OcException {
+        return Arrays.asList(OcProvisioning.discoverOwnedDevices1(timeout));
+    }
+    private static native OcSecureResource[] discoverOwnedDevices1(int timeout) throws OcException;
+
+    /**
+     *  API for registering Ownership transfer methods for a particular
+     *  transfer Type
+     *
+     * @param type     OxmType ownership transfer type.
+     * @throws OcException
+     */
+    public static void SetownershipTransferCBdata(OxmType type,
+            PinCallbackListener pinCallbackListener) throws OcException
+    {
+        OcProvisioning.ownershipTransferCBdata(type.getValue(), pinCallbackListener);
+    }
+
+    private  static native void ownershipTransferCBdata(int oxmType,  PinCallbackListener pinCallbackListener);
+
+    public static interface PinCallbackListener {
+        public String pinCallbackListener();
+    }
+
+    /**
+     * Method to get Array of owned and un-owned devices in the current subnet.
+     *
+     * @param timeout    timeout in sec for the API to return.
+     * @retrun           Array of OcSecureResource class objects.
+     *                   be provisioned.
+     * @throws OcException
+     */
+    public static List<OcSecureResource> getDeviceStatusList(int timeout) throws OcException {
+        return Arrays.asList(OcProvisioning.getDeviceStatusList1(timeout));
+    }
+    private static native OcSecureResource[] getDeviceStatusList1(int timeout) throws OcException;
+}
diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcSecureResource.java b/android/android_api/base/src/main/java/org/iotivity/base/OcSecureResource.java
new file mode 100644 (file)
index 0000000..218b9e2
--- /dev/null
@@ -0,0 +1,240 @@
+/*
+ * //******************************************************************
+ * //
+ * // Copyright 2015 Samsung Electronics All Rights Reserved.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // Licensed under the Apache License, Version 2.0 (the "License");
+ * // you may not use this file except in compliance with the License.
+ * // You may obtain a copy of the License at
+ * //
+ * //      http://www.apache.org/licenses/LICENSE-2.0
+ * //
+ * // Unless required by applicable law or agreed to in writing, software
+ * // distributed under the License is distributed on an "AS IS" BASIS,
+ * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * // See the License for the specific language governing permissions and
+ * // limitations under the License.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+package org.iotivity.base;
+
+import java.util.List;
+import java.util.EnumSet;
+import java.util.Map;
+
+public class OcSecureResource {
+
+    private OcSecureResource(long nativeHandle) {
+        this.mNativeHandle = nativeHandle;
+    }
+
+    /**
+     *  Method to Start Ownership Transfer of an un-owned device.
+     *
+     *  @param DoOwnershipTransferListener  Callback function, which will be called after
+     *                                      completion of ownership Transfer.
+     *  @throws OcException
+     */
+    public native void doOwnershipTransfer(DoOwnershipTransferListener doOwnershipTransferListener)
+        throws OcException;
+
+    /**
+     *  Method removes device credential from all devices in subnet
+     *
+     *  @param timeout
+     *  @param RemoveDeviceListener         Callback function, which will be called after
+     *                                      completion of removing device.
+     *  @throws OcException
+     */
+    public native void removeDevice(int timeout,  RemoveDeviceListener removeDeviceListener)
+        throws OcException;
+
+    /**
+     *  Method removes the credential & relationship between the two devices.
+     *
+     *  @param jobject                      Second device
+     *  @param UnlinkDevicesListener        Callback function, which will be called after
+     *                                      completion of removing device.
+     *  @throws OcException
+     */
+    public native void unlinkDevices(Object device2, UnlinkDevicesListener unlinkDevicesListener)
+        throws OcException;
+
+    /**
+     *  Method removes the credential & relationship between the two devices.
+     *
+     *  @param EnumSet<CredType>            OR'ed Cred Types
+     *  @param KeySize                          keySize
+     *  @param Object                       Second device
+     *  @param ProvisionCredentialsListener Callback function, which will be called after
+     *                                      completion of removing device.
+     *  @throws OcException
+     */
+    public void provisionCredentials(EnumSet<CredType> credTypeSet, KeySize keysize, Object device2,
+            ProvisionCredentialsListener provisionCredentialsListener) throws OcException {
+        int credTypeInt = 0;
+
+        for (CredType credType : CredType.values()) {
+            if (credTypeSet.contains(credType))
+                credTypeInt |= credType.getValue();
+        }
+        this.provisionCredentials1(credTypeInt, keysize.getValue(),
+                device2, provisionCredentialsListener);
+    }
+    private native void provisionCredentials1(int type, int keySize, Object device2,
+            ProvisionCredentialsListener provisionCredentialsListener)
+        throws OcException;
+
+    /**
+     *  Method send ACL information to resource.
+     *
+     *  @param jobject                      Acl
+     *  @param ProvisionAclListener         Callback function, which will be called after
+     *                                      completion of removing device.
+     *  @throws OcException
+     */
+    public native void provisionACL(Object acl, ProvisionAclListener provisionACLListener)
+        throws OcException;
+
+
+    /**
+     *  Method provisions credentials between two devices and ACLs for the devices who
+     *  act as a server.
+     *
+     *  @param EnumSet<CredType>            OR'ed Cred Types
+     *  @param KeySize                      keySize
+     *  @param Object                       First acl
+     *  @param Object                       Second device
+     *  @param Object                       Second acl
+     *  @param ProvisionPairwiseDevicesListener Callback function, which will be called after
+     *                                      completion of removing device.
+     *  @throws OcException
+     */
+    public void provisionPairwiseDevices(EnumSet<CredType> credTypeSet, KeySize keysize, Object acl1,
+            Object device2, Object acl2,
+            ProvisionPairwiseDevicesListener provisionPairwiseDevicesListener) throws OcException {
+        int credTypeInt = 0;
+
+        for (CredType credType : CredType.values()) {
+            if (credTypeSet.contains(credType))
+                credTypeInt |= credType.getValue();
+        }
+        this.provisionPairwiseDevices1(credTypeInt, keysize.getValue(), acl1, device2,
+                acl2, provisionPairwiseDevicesListener);
+    }
+    private native void provisionPairwiseDevices1(int type, int keySize, Object acl1,
+            Object device2, Object acl2,
+            ProvisionPairwiseDevicesListener provisionPairwiseDevicesListener) throws OcException;
+
+    /**
+     * doOwnershipTransferListener can be registered with doOwnershipTransfer
+     * call.
+     * Listener notified asynchronously.
+     */
+    public interface DoOwnershipTransferListener {
+        public void doOwnershipTransferListener(List<ProvisionResult> provisionResultList,
+                int hasError);
+    }
+
+    /**
+     * removeDeviceListener can be registered with removeDeviceListener
+     * call.
+     * Listener notified asynchronously.
+     */
+    public interface RemoveDeviceListener {
+        public void removeDeviceListener(List<ProvisionResult> provisionResultList,
+                int hasError);
+    }
+
+    /**
+     * unlinkDevicesListener can be registered with unlinkDevicesListener
+     * call.
+     * Listener notified asynchronously.
+     */
+    public interface UnlinkDevicesListener {
+        public void unlinkDevicesListener(List<ProvisionResult> provisionResultList,
+                int hasError);
+    }
+
+    /**
+     * provisionCredentialsListener can be registered with provisionCredentialsListener
+     * call.
+     * Listener notified asynchronously.
+     */
+    public interface ProvisionCredentialsListener {
+        public void provisionCredentialsListener(List<ProvisionResult> provisionResultList,
+                int hasError);
+    }
+
+    /**
+     * provisionAclListener can be registered with provisionAclListener
+     * call.
+     * Listener notified asynchronously.
+     */
+    public interface ProvisionAclListener {
+        public void provisionAclListener(List<ProvisionResult> provisionResultList,
+                int hasError);
+    }
+
+    /**
+     * provisionPairwiseDevicesListener can be registered with provisionPairwiseDevicesListener
+     * call.
+     * Listener notified asynchronously.
+     */
+    public interface ProvisionPairwiseDevicesListener {
+        public void provisionPairwiseDevicesListener(List<ProvisionResult> provisionResultList,
+                int hasError);
+    }
+
+    /** Method to get List of device ID of devices linked with invoking device.
+     *
+     *  @return Sring List  List of device id's of linked devices.
+     */
+     public native List<String> getLinkedDevices();
+
+     /**
+      * Method to get IP address of sercure discovered device.
+      * @return Stringified IP address.
+      */
+    public native String getIpAddr();
+
+    /**
+     * Method to get device id of a device.
+     * @return  Device ID of the selected device.
+     */
+    public native String getDeviceID();
+
+    /**
+     * Method to get device status (ON/OFF) of a device.
+     * @return      ON/OFF
+     */
+
+    public DeviceStatus getDeviceStatus() throws OcException {
+        return DeviceStatus.convertDeviceStatus(this.deviceStatus());
+    }
+    public native int deviceStatus() throws OcException;
+
+    /**
+     * Method to get device  ownership (OWNED/UNOWNED) status.
+     * @return      OWNED/UNOWNED
+     */
+
+    public OwnedStatus getOwnedStatus() throws OcException {
+        return  OwnedStatus.convertOwnedStatus(this.ownedStatus());
+    }
+    public native int ownedStatus() throws OcException;
+
+    @Override
+    protected void finalize() throws Throwable {
+        super.finalize();
+        dispose();
+    }
+
+    private native void dispose();
+
+    private long mNativeHandle;
+}
diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OicSecAcl.java b/android/android_api/base/src/main/java/org/iotivity/base/OicSecAcl.java
new file mode 100644 (file)
index 0000000..5ca6d96
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * //******************************************************************
+ * //
+ * // Copyright 2015 Samsung Electronics All Rights Reserved.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // Licensed under the Apache License, Version 2.0 (the "License");
+ * // you may not use this file except in compliance with the License.
+ * // You may obtain a copy of the License at
+ * //
+ * //      http://www.apache.org/licenses/LICENSE-2.0
+ * //
+ * // Unless required by applicable law or agreed to in writing, software
+ * // distributed under the License is distributed on an "AS IS" BASIS,
+ * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * // See the License for the specific language governing permissions and
+ * // limitations under the License.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+package org.iotivity.base;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Arrays;
+
+public class OicSecAcl implements Serializable {
+
+    private String       subject;
+    private int          permission;
+    private List<String> resources;
+    private List<String> periods;
+    private List<String> recurrences;
+    private List<String> owners;
+
+    public OicSecAcl(String subject, List<String> recurrences, List<String> periods, int permission,
+            List<String> resources, List<String> owners) {
+        this.subject = subject;
+        this.recurrences = recurrences;
+        this.periods = periods;
+        this.permission = permission;
+        this.resources = resources;
+        this.owners = owners;
+    }
+
+    public String getSubject() {
+        return this.subject;
+    }
+
+    public void setSubject(String subject) {
+        this.subject = subject;
+    }
+
+    public List<String> getOwners() {
+        return owners;
+    }
+
+    public void setOwners(List<String> owners) {
+        this.owners = owners;
+    }
+
+    public List<String> getRecurrences() {
+        return recurrences;
+    }
+
+    public void setRecurrences(List<String> recurrences) {
+        this.recurrences = recurrences;
+    }
+
+    public List<String> getPeriods() {
+        return periods;
+    }
+
+    public void setPeriods(List<String> periods) {
+        this.periods = periods;
+    }
+
+    public int getPermission() {
+        return this.permission;
+    }
+
+    public void setPermission(int permission) {
+        this.permission = permission;
+    }
+
+    public List<String> getResources() {
+        return resources;
+    }
+
+    public void setResources(List<String> resources) {
+        this.resources = resources;
+    }
+
+    public int getResourcesCount() {
+        return this.resources.size();
+    }
+
+    public String getResources(int i) {
+        return this.resources.get(i);
+    }
+
+    public int getPeriodsCount() {
+        return this.periods.size();
+    }
+
+    public String getPeriods(int i) {
+        return this.periods.get(i);
+    }
+
+    public String getRecurrences(int i) {
+        return this.recurrences.get(i);
+    }
+
+    public int getOwnersCount() {
+        return this.owners.size();
+    }
+
+    public String getOwners(int i) {
+        return this.owners.get(i);
+    }
+}
diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OwnedStatus.java b/android/android_api/base/src/main/java/org/iotivity/base/OwnedStatus.java
new file mode 100644 (file)
index 0000000..1c90578
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * //******************************************************************
+ * //
+ * // Copyright Samsung Electronics All Rights Reserved.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // Licensed under the Apache License, Version 2.0 (the "License");
+ * // you may not use this file except in compliance with the License.
+ * // You may obtain a copy of the License at
+ * //
+ * //      http://www.apache.org/licenses/LICENSE-2.0
+ * //
+ * // Unless required by applicable law or agreed to in writing, software
+ * // distributed under the License is distributed on an "AS IS" BASIS,
+ * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * // See the License for the specific language governing permissions and
+ * // limitations under the License.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+package org.iotivity.base;
+
+public enum OwnedStatus {
+    OWNED(0),
+    UNOWNED(1),
+    INVALID(-1);
+
+    private int value;
+
+    private OwnedStatus(int value) {
+        this.value = value;
+    }
+
+    public int getValue() {
+        return this.value;
+    }
+
+    public static OwnedStatus convertOwnedStatus(int value) {
+
+        if (0 == value)
+        {
+            return OwnedStatus.UNOWNED;
+        }
+        else if (1 == value)
+        {
+            return OwnedStatus.OWNED;
+        }
+        else
+        {
+            return OwnedStatus.INVALID;
+        }
+    }
+}
diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OxmType.java b/android/android_api/base/src/main/java/org/iotivity/base/OxmType.java
new file mode 100644 (file)
index 0000000..f336076
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * //******************************************************************
+ * //
+ * // Copyright 2015 Samsung Electronics All Rights Reserved.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // Licensed under the Apache License, Version 2.0 (the "License");
+ * // you may not use this file except in compliance with the License.
+ * // You may obtain a copy of the License at
+ * //
+ * //      http://www.apache.org/licenses/LICENSE-2.0
+ * //
+ * // Unless required by applicable law or agreed to in writing, software
+ * // distributed under the License is distributed on an "AS IS" BASIS,
+ * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * // See the License for the specific language governing permissions and
+ * // limitations under the License.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+package org.iotivity.base;
+
+public enum OxmType {
+    OIC_JUST_WORKS(0),
+    OIC_MODE_SWITCH(1),
+    OIC_RANDOM_DEVICE_PIN(2),
+    OIC_PRE_PROVISIONED_DEVICE_PIN(3),
+    OIC_PRE_PROVISION_STRONG_CREDENTIAL(4),
+    OIC_OXM_COUNT(5);
+
+    private int value;
+
+    private OxmType(int value) {
+        this.value = value;
+    }
+
+    public int getValue() {
+        return this.value;
+    }
+}
diff --git a/android/android_api/base/src/main/java/org/iotivity/base/ProvisionResult.java b/android/android_api/base/src/main/java/org/iotivity/base/ProvisionResult.java
new file mode 100644 (file)
index 0000000..5d46b8f
--- /dev/null
@@ -0,0 +1,41 @@
+/* *****************************************************************
+ *
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * *****************************************************************/
+package org.iotivity.base;
+
+public class ProvisionResult {
+
+    private String mDeviceId;
+    private int mResult;
+
+    public ProvisionResult(String deviceId, int result)
+    {
+        this.mDeviceId = deviceId;
+        this.mResult = result;
+    }
+
+    public String getDevId()
+    {
+        return this.mDeviceId;
+    }
+    public int getResult()
+    {
+        return this.mResult;
+    }
+}
diff --git a/android/examples/provisioningclient/build.gradle b/android/examples/provisioningclient/build.gradle
new file mode 100644 (file)
index 0000000..252b151
--- /dev/null
@@ -0,0 +1,24 @@
+apply plugin: 'com.android.application'\r
+\r
+android {\r
+    compileSdkVersion 21\r
+    buildToolsVersion "21.1.2"\r
+\r
+    defaultConfig {\r
+        applicationId "org.iotivity.base.examples.provisioningclient"\r
+        minSdkVersion 19\r
+        targetSdkVersion 21\r
+        versionCode 1\r
+        versionName "1.0"\r
+    }\r
+    buildTypes {\r
+        release {\r
+            minifyEnabled false\r
+            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'\r
+        }\r
+    }\r
+}\r
+\r
+dependencies {\r
+    compile 'com.android.support:appcompat-v7:21.0.3'\r
+}\r
diff --git a/android/examples/provisioningclient/proguard-rules.pro b/android/examples/provisioningclient/proguard-rules.pro
new file mode 100644 (file)
index 0000000..8a79c59
--- /dev/null
@@ -0,0 +1,17 @@
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in /home/sri/Android/Sdk/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the proguardFiles
+# directive in build.gradle.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
diff --git a/android/examples/provisioningclient/provisioningclient.iml b/android/examples/provisioningclient/provisioningclient.iml
new file mode 100644 (file)
index 0000000..c44426e
--- /dev/null
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="examples" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
+  <component name="FacetManager">
+    <facet type="android-gradle" name="Android-Gradle">
+      <configuration>
+        <option name="GRADLE_PROJECT_PATH" value=":secureprovisionclient" />
+      </configuration>
+    </facet>
+    <facet type="android" name="Android">
+      <configuration>
+        <option name="SELECTED_BUILD_VARIANT" value="debug" />
+        <option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
+        <option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
+        <option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
+        <option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
+        <option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
+        <option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugTestSources" />
+        <option name="ALLOW_USER_CONFIGURATION" value="false" />
+        <option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
+        <option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
+        <option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
+        <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
+      </configuration>
+    </facet>
+  </component>
+  <component name="NewModuleRootManager" inherit-compiler-output="false">
+    <output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
+    <output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/test/debug" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
+      <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
+    </content>
+    <orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="library" exported="" name="appcompat-v7-21.0.3" level="project" />
+    <orderEntry type="library" exported="" name="iotivity-armeabi-base-debug-" level="project" />
+    <orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
+    <orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
+    <orderEntry type="module" module-name="message" exported="" />
+  </component>
+</module>
+
diff --git a/android/examples/provisioningclient/src/main/AndroidManifest.xml b/android/examples/provisioningclient/src/main/AndroidManifest.xml
new file mode 100644 (file)
index 0000000..93a375b
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="org.iotivity.base.examples.provisioningclient" >
+
+    <application
+        android:allowBackup="true"
+        android:icon="@mipmap/ic_launcher"
+        android:label="@string/app_name"
+        android:theme="@style/AppTheme" >
+        <activity
+            android:name=".ProvisioningClient"
+            android:label="@string/app_name" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+    </application>
+
+</manifest>
diff --git a/android/examples/provisioningclient/src/main/assets/oic_svr_db_client.json b/android/examples/provisioningclient/src/main/assets/oic_svr_db_client.json
new file mode 100644 (file)
index 0000000..17dc43f
--- /dev/null
@@ -0,0 +1,49 @@
+{
+    "acl": [
+        {
+            "sub": "Kg==",
+            "rsrc": [
+                "/oic/res",
+                "/oic/d",
+                "/oic/p",
+                "/oic/res/types/d",
+                "/oic/ad",
+                "/oic/sec/acl"
+                       ],
+                       "perms": 2,
+                       "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+               },
+        {
+            "sub": "Kg==",
+            "rsrc": [
+                "/oic/sec/doxm",
+                "/oic/sec/pstat"
+             ],
+             "perms": 2,
+             "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+        }
+       ],
+       "pstat":        {
+               "isop": true,
+               "deviceid":     "ZGV2aWNlaWQAAAAAABhanw==",
+               "ch": 0,
+               "cm":   0,
+               "tm":   0,
+               "om":   3,
+               "sm":   [3]
+       },
+       "doxm": {
+               "oxm":  [0],
+               "oxmsel": 0,
+               "owned": true,
+               "deviceid":     "MjIyMjIyMjIyMjIyMjIyMg==",
+               "ownr": "MjIyMjIyMjIyMjIyMjIyMg=="
+       },
+    "cred":    [{
+               "credid": 1,
+               "sub": "MTExMTExMTExMTExMTExMQ==",
+               "credtyp": 1,
+               "pvdata": "QUFBQUFBQUFBQUFBQUFBQQ==",
+        "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+       }]
+}
diff --git a/android/examples/provisioningclient/src/main/java/org/iotivity/base/examples/provisioningclient/ProvisioningClient.java b/android/examples/provisioningclient/src/main/java/org/iotivity/base/examples/provisioningclient/ProvisioningClient.java
new file mode 100644 (file)
index 0000000..b9758af
--- /dev/null
@@ -0,0 +1,711 @@
+
+package org.iotivity.base.examples.provisioningclient;
+
+import android.app.Activity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.os.Message;
+import android.preference.PreferenceManager;
+import android.text.method.ScrollingMovementMethod;
+import android.util.Log;
+import android.view.Gravity;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+
+import org.iotivity.base.ModeType;
+
+import org.iotivity.base.OcException;
+
+import org.iotivity.base.OcPlatform;
+
+
+import org.iotivity.base.PlatformConfig;
+import org.iotivity.base.QualityOfService;
+import org.iotivity.base.ServiceType;
+import org.iotivity.base.OcProvisioning;
+import org.iotivity.base.OcSecureResource;
+import org.iotivity.base.ProvisionResult;
+import org.iotivity.base.OxmType;
+import org.iotivity.base.OicSecAcl;
+import org.iotivity.base.CredType;
+import org.iotivity.base.KeySize;
+import org.iotivity.base.DeviceStatus;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.EnumSet;
+
+
+import java.util.List;
+
+
+public class ProvisioningClient extends Activity implements
+        OcSecureResource.DoOwnershipTransferListener,
+        OcSecureResource.ProvisionPairwiseDevicesListener {
+    private static final String TAG = "Provisioning Client: ";
+    OcProvisioning.PinCallbackListener pinCallbackListener =
+            new OcProvisioning.PinCallbackListener() {
+                @Override
+                public String pinCallbackListener() {
+
+                    Log.d(TAG, "Inside Pin Callback ");
+                    return "";
+
+                }
+            };
+    OcSecureResource.ProvisionAclListener provisionAclListener =
+            new OcSecureResource.ProvisionAclListener() {
+                @Override
+                public void provisionAclListener(List<ProvisionResult> provisionResults,
+                                                 int hasError) {
+
+                    Log.d(TAG, "Inside ProvisionAclListener ");
+
+                    if (hasError == StringConstants.ERROR_CODE) {
+                        logMessage("Error: ACL Provision failed !!");
+                    } else {
+                        logMessage("ACL Provision Done !!");
+                        new DeviceRevocationAsyncTask().execute();
+                    }
+
+                }
+            };
+    OcSecureResource.ProvisionCredentialsListener provisionCredentialsListener =
+            new OcSecureResource.ProvisionCredentialsListener() {
+                @Override
+                public void provisionCredentialsListener(List<ProvisionResult> provisionResults,
+                                                         int hasError) {
+
+                    Log.d(TAG, "Inside ProvisionCredentialsListener ");
+                    if (hasError == StringConstants.ERROR_CODE) {
+                        logMessage("Error: Provision Credentials failed !!");
+                    } else {
+                        logMessage("Provision Credentials Done !!");
+                        new ProvisionACLAsyncTask().execute();
+                    }
+
+
+                }
+            };
+    OcSecureResource.UnlinkDevicesListener unlinkDevicesListener =
+            new OcSecureResource.UnlinkDevicesListener() {
+                @Override
+                public void unlinkDevicesListener(List<ProvisionResult> provisionResults,
+                                                  int hasError) {
+                    Log.d(TAG, "Inside unlinkDevicesListener ");
+
+                    if (hasError == StringConstants.ERROR_CODE) {
+                        logMessage("Error: UnLinking device !!");
+                    } else {
+                        logMessage("Unlink Done !!");
+                        new ProvisionCredentialAsyncTask().execute();
+                    }
+
+                }
+            };
+
+    OcSecureResource.RemoveDeviceListener removeDeviceListener =
+            new OcSecureResource.RemoveDeviceListener() {
+                @Override
+                public void removeDeviceListener(List<ProvisionResult> provisionResults,
+                                                 int hasError) {
+                    if (hasError == StringConstants.ERROR_CODE) {
+                        logMessage("Error: Remove Fail !!");
+                    } else {
+                        logMessage("Remove Device done !!");
+                    }
+                }
+            };
+    private static final int BUFFER_SIZE = 1024;
+    int unownedDevCount = StringConstants.NUMBER_ZERO;
+    private String filePath = "";
+    private OcSecureResource newSecureResource;
+    private List<OcSecureResource> deviceList;
+    private List<OcSecureResource> ownedDeviceList;
+    //for display
+    private TextView mEventsTextView;
+
+    /**
+     * configure OIC platform and call findResource
+     */
+    private void initOICStack() {
+
+        //create platform config
+        PlatformConfig cfg = new PlatformConfig(
+                this,
+                ServiceType.IN_PROC,
+                ModeType.CLIENT_SERVER,
+                "0.0.0.0", // bind to all available interfaces
+                0,
+                QualityOfService.LOW, filePath + StringConstants.OIC_CLIENT_JSON_DB_FILE);
+        OcPlatform.Configure(cfg);
+
+        try {
+            /*
+             * Initialize DataBase
+             */
+
+            String sqlDbPath = getFilesDir().getAbsolutePath().replace("files", "databases") +
+                    File.separator;
+
+            File file = new File(sqlDbPath);
+            //check files directory exists
+            if (!(file.isDirectory())) {
+                file.mkdirs();
+                Log.d(TAG, "Sql db directory created at " + sqlDbPath);
+            }
+            Log.d(TAG, "Sql db directory exists at " + sqlDbPath);
+
+            OcProvisioning.provisionInit(sqlDbPath + StringConstants.OIC_SQL_DB_FILE);
+        } catch (OcException e) {
+            logMessage(TAG + "provisionInit error: " + e.getMessage());
+            Log.e(TAG, e.getMessage());
+        }
+
+        new DiscoveryOTTransferAsyncTask().execute();
+    }
+
+    @Override
+    synchronized public void doOwnershipTransferListener(List<ProvisionResult> ProvisionResultList,
+                                                         int hasError) {
+
+        ProvisionResult pResult = ProvisionResultList.get(0);
+        if (hasError == StringConstants.ERROR_CODE) {
+            logMessage(TAG + "Ownership Transfer Failed for " + pResult.getDevId());
+        } else {
+            logMessage(TAG + "Ownership Transfer Successful for "
+                    + pResult.getDevId());
+            unownedDevCount--;
+        }
+
+        if (unownedDevCount == 0) { //When done with Ownership Transfer
+            new OwnedDiscoveryAsyncTask().execute();
+        }
+    }
+
+    private void doPairwiseProvisioning() {
+        try {
+            logMessage(TAG + "Pairwise Provisioning b/w " + ownedDeviceList.get(0).getDeviceID()
+                    + " and " + ownedDeviceList.get(1).getDeviceID());
+            newSecureResource = ownedDeviceList.get(0);
+            OcSecureResource newSecureResource2 = ownedDeviceList.get(1);
+            List<String> resources = new ArrayList<String>();
+            List<String> owners = new ArrayList<String>();
+            List<String> periods = new ArrayList<String>();
+            List<String> recurrences = new ArrayList<String>();
+            recurrences.add("Daily");
+            resources.add("*");
+            owners.add("adminDeviceUUID0");
+            periods.add("01-01-15");
+            OicSecAcl acl1 = new OicSecAcl(newSecureResource.getDeviceID(), recurrences, periods,
+                    31, resources, owners);
+            OicSecAcl acl2 = new OicSecAcl(newSecureResource2.getDeviceID(), recurrences, periods,
+                    31, resources, owners);
+            newSecureResource.provisionPairwiseDevices(EnumSet.of(CredType.SYMMETRIC_PAIR_WISE_KEY),
+                    KeySize.OWNER_PSK_LENGTH_128, acl1, newSecureResource2, acl2, this);
+
+        } catch (Exception e) {
+            logMessage(TAG + "Pairwise Provisioning  error: " + e.getMessage());
+            Log.e(TAG, e.getMessage());
+        }
+    }
+
+    @Override
+    public void provisionPairwiseDevicesListener(List<ProvisionResult> ProvisionResultList,
+                                                 int hasError) {
+        if (hasError == StringConstants.ERROR_CODE) {
+            logMessage(TAG + "provisionPairwiseDevices Failed");
+        } else {
+            for (int i = 0; i < ProvisionResultList.size(); i++) {
+                ProvisionResult pResult = ProvisionResultList.get(i);
+                logMessage(TAG + "provisionPairwiseDevices Result for "
+                        + pResult.getDevId() + "is " + pResult.getResult());
+            }
+            new GetLinkedDevicesAsyncTask().execute();
+        }
+    }
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_secure_provision_client);
+        mEventsTextView = new TextView(this);
+        mEventsTextView.setGravity(Gravity.BOTTOM);
+        mEventsTextView.setMovementMethod(new ScrollingMovementMethod());
+        LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
+        layout.addView(mEventsTextView, new LinearLayout.LayoutParams(
+                        LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f)
+        );
+
+        filePath = getFilesDir().getPath() + "/"; //  data/data/<package>/files/
+        //copy json when application runs first time
+        SharedPreferences wmbPreference = PreferenceManager.getDefaultSharedPreferences(this);
+        boolean isFirstRun = wmbPreference.getBoolean("FIRSTRUN", true);
+        if (isFirstRun) {
+            copyJsonFromAsset();
+            SharedPreferences.Editor editor = wmbPreference.edit();
+            editor.putBoolean("FIRSTRUN", false);
+            editor.commit();
+        }
+        initOICStack();
+    }
+
+    /**
+     * Copy svr db json file from assets folder to app data files dir
+     */
+    private void copyJsonFromAsset() {
+        InputStream inputStream = null;
+        OutputStream outputStream = null;
+        int length;
+        byte[] buffer = new byte[BUFFER_SIZE];
+
+        try {
+            inputStream = getAssets().open(StringConstants.OIC_CLIENT_JSON_DB_FILE);
+            File file = new File(filePath);
+            //check files directory exists
+            if (!(file.exists() && file.isDirectory())) {
+                file.mkdirs();
+            }
+            outputStream = new FileOutputStream(filePath + StringConstants.OIC_CLIENT_JSON_DB_FILE);
+
+            while ((length = inputStream.read(buffer)) != -1) {
+                outputStream.write(buffer, 0, length);
+            }
+
+
+        } catch (NullPointerException e) {
+            logMessage(TAG + "Null pointer exception " + e.getMessage());
+            Log.e(TAG, e.getMessage());
+        } catch (FileNotFoundException e) {
+            logMessage(TAG + "Json svr db file not found " + e.getMessage());
+            Log.e(TAG, e.getMessage());
+        } catch (IOException e) {
+            logMessage(TAG + StringConstants.OIC_CLIENT_JSON_DB_FILE + " file copy failed");
+            Log.e(TAG, e.getMessage());
+        } finally {
+            if (inputStream != null) {
+                try {
+                    inputStream.close();
+                } catch (IOException e) {
+                    Log.e(TAG, e.getMessage());
+                }
+            }
+            if (outputStream != null) {
+                try {
+                    outputStream.close();
+                } catch (IOException e) {
+                    Log.e(TAG, e.getMessage());
+                }
+            }
+        }
+    }
+
+    public void logMessage(String text) {
+        logMsg(text);
+    }
+
+    public void logMsg(final String text) {
+        runOnUiThread(new Runnable() {
+            public void run() {
+                Message msg = new Message();
+                msg.obj = text;
+                mEventsTextView.append(text);
+                mEventsTextView.append("\n\n");
+            }
+        });
+        Log.i(TAG, text);
+
+        Intent intent = new Intent(getPackageName());
+        intent.putExtra(StringConstants.MESSAGE, text);
+        sendBroadcast(intent);
+    }
+
+    private class DiscoveryOTTransferAsyncTask extends AsyncTask<Void, String, String> {
+
+        @Override
+        protected void onPreExecute() {
+            super.onPreExecute();
+        }
+
+        @Override
+        protected String doInBackground(Void... params) {
+            try {
+                /**
+                 * Discover Un-owned devices
+                 */
+
+                publishProgress(TAG + "Discovering Unowned Devices");
+                deviceList = new ArrayList<OcSecureResource>();
+                deviceList = OcProvisioning.discoverUnownedDevices(5);
+
+
+                if (deviceList.size() > 0) {
+                    unownedDevCount = deviceList.size();
+                    for (int i = 0; i < deviceList.size(); i++) {
+                        publishProgress(TAG + "Un-owned Discovered Device " + (i + 1) + "= " +
+                                deviceList.get(i).getDeviceID());
+                    }
+
+
+                    try {
+
+                        OcProvisioning.SetownershipTransferCBdata(OxmType.OIC_JUST_WORKS,
+                                pinCallbackListener);
+
+                        for (int i = 0; i < deviceList.size(); i++) {
+                            publishProgress(TAG + "Doing Ownership Transfer for " +
+                                    deviceList.get(i).getDeviceID());
+                            deviceList.get(i).doOwnershipTransfer(ProvisioningClient.this);
+                        }
+                    } catch (OcException e) {
+                        publishProgress(TAG + "Ownership Transfer error: " + e.getMessage());
+                        return "Ownership Transfer error: " + e.getMessage();
+
+                    }
+
+
+                } else {
+                    publishProgress(TAG + "No un-owned devices present");
+                }
+
+            } catch (OcException e) {
+                publishProgress(TAG + "Un-owned discovery error: " + e.getMessage());
+                return "Un-owned discovery error:  " + e.getMessage();
+
+            }
+            return "success";
+        }
+
+        @Override
+        protected void onProgressUpdate(String... values) {
+            logMessage(values[0]);
+        }
+
+        @Override
+        protected void onPostExecute(String s) {
+            super.onPostExecute(s);
+        }
+    }
+
+    private class ProvisionACLAsyncTask extends AsyncTask<Void, String, Void> {
+
+        @Override
+        protected void onPreExecute() {
+            super.onPreExecute();
+        }
+
+        @Override
+        protected Void doInBackground(Void... params) {
+            try {
+
+
+                if (ownedDeviceList.size() > 1) {
+                    OcSecureResource ocSecureResource = ownedDeviceList.get(0);
+
+                    OcSecureResource ocSecureResourceDest = ownedDeviceList.get(1);
+
+                    publishProgress(TAG + "ACL Provision for " + ocSecureResource.getDeviceID());
+
+                    List<String> resources = new ArrayList<String>();
+                    List<String> owners = new ArrayList<String>();
+                    List<String> periods = new ArrayList<String>();
+                    List<String> recurrences = new ArrayList<String>();
+                    recurrences.add("Daily");
+                    resources.add("*");
+                    owners.add("adminDeviceUUID0");
+                    periods.add("01-01-15");
+
+                    OicSecAcl aclObject = new OicSecAcl(ocSecureResourceDest.getDeviceID(),
+                            recurrences, periods, 31, resources, owners);
+
+
+                    ocSecureResource.provisionACL(aclObject, provisionAclListener);
+
+                } else {
+                    publishProgress(TAG + "No Owned devices present");
+                }
+
+            } catch (Exception e) {
+                publishProgress(TAG + "ProvisionACL error: " + e.getMessage());
+
+
+            }
+            return null;
+        }
+
+        @Override
+        protected void onProgressUpdate(String... values) {
+            logMessage(values[0]);
+        }
+
+
+    }
+
+    private class ProvisionCredentialAsyncTask extends AsyncTask<Void, String, Void> {
+
+        @Override
+        protected void onPreExecute() {
+            super.onPreExecute();
+        }
+
+        @Override
+        protected Void doInBackground(Void... params) {
+            try {
+
+                if (ownedDeviceList.size() > 1) {
+
+                    OcSecureResource ocSecureResource = ownedDeviceList.get(0);
+                    OcSecureResource ocSecureResourceDest = ownedDeviceList.get(1);
+                    publishProgress(TAG + "ProvisionCredential for " +
+                            ocSecureResource.getDeviceID() + " with " +
+                            ocSecureResourceDest.getDeviceID());
+
+
+                    int credential_type = StringConstants.CREDENTIAL_TYPE; //symmetrical
+                    int psk_length = StringConstants.OWNER_PSK_LENGTH_128;
+
+                    ocSecureResource.provisionCredentials(EnumSet.of(CredType.SYMMETRIC_PAIR_WISE_KEY),
+                            KeySize.OWNER_PSK_LENGTH_128,
+                            ocSecureResourceDest, provisionCredentialsListener);
+
+
+                } else {
+                    publishProgress(TAG + "Cannot perform credentials between devices");
+                }
+
+            } catch (Exception e) {
+                publishProgress(TAG + "ProvisionACL error: " + e.getMessage());
+
+
+            }
+            return null;
+        }
+
+        @Override
+        protected void onProgressUpdate(String... values) {
+            logMessage(values[0]);
+        }
+
+
+    }
+
+    private class GetLinkedDevicesAsyncTask extends AsyncTask<Void, String, String> {
+
+        @Override
+        protected void onPreExecute() {
+            super.onPreExecute();
+        }
+
+        @Override
+        protected String doInBackground(Void... params) {
+            try {
+
+                if (ownedDeviceList.size() > 1) {
+
+                    OcSecureResource ocSecureResource = ownedDeviceList.get(0);
+                    publishProgress(TAG + "Get linked devices of " + ocSecureResource.getDeviceID());
+
+
+                    List<String> linkedDevices= ocSecureResource.getLinkedDevices();
+                    if(linkedDevices.size() >0 )
+                    {
+                        for (int i = 0; i < linkedDevices.size(); i++) {
+                            publishProgress(TAG + "Linked Devices "+
+                                            + (i + 1) + "= " + linkedDevices.get(i)
+                            );
+                        }
+                    }
+                    else
+                    {
+                        publishProgress(TAG + "No linked Devices found");
+                    }
+                } else {
+                    publishProgress(TAG + "Cannot perform linked devices");
+                }
+
+            } catch (Exception e) {
+                publishProgress(TAG + "getLinked device error: " + e.getMessage());
+                return "failed";
+
+
+            }
+            return "success";
+        }
+
+        @Override
+        protected void onProgressUpdate(String... values) {
+            logMessage(values[0]);
+        }
+
+
+        @Override
+        protected void onPostExecute(String s) {
+
+            if ("success".equals(s)) {
+                new ProvisionUnlinkAsyncTask().execute();
+
+            }
+
+
+        }
+
+    }
+
+
+    private class ProvisionUnlinkAsyncTask extends AsyncTask<Void, String, Void> {
+
+        @Override
+        protected void onPreExecute() {
+            super.onPreExecute();
+        }
+
+        @Override
+        protected Void doInBackground(Void... params) {
+            try {
+
+                if (ownedDeviceList.size() > 1) {
+
+                    OcSecureResource ocSecureResource = ownedDeviceList.get(0);
+                    OcSecureResource ocSecureResourceDest = ownedDeviceList.get(1);
+                    publishProgress(TAG + "Un linking  " + ocSecureResource.getDeviceID() +
+                            " with " + ocSecureResourceDest.getDeviceID());
+
+                    ocSecureResource.unlinkDevices(ocSecureResourceDest, unlinkDevicesListener);
+
+
+                } else {
+                    publishProgress(TAG + "Cannot perform unlink devices");
+                }
+
+            } catch (Exception e) {
+                publishProgress(TAG + "Unlink error: " + e.getMessage());
+
+
+            }
+            return null;
+        }
+
+        @Override
+        protected void onProgressUpdate(String... values) {
+            logMessage(values[0]);
+        }
+
+
+    }
+
+
+    private class DeviceRevocationAsyncTask extends AsyncTask<Void, String, Void> {
+
+        @Override
+        protected void onPreExecute() {
+            super.onPreExecute();
+        }
+
+        @Override
+        protected Void doInBackground(Void... params) {
+            try {
+
+                if (ownedDeviceList.size() > 0) {
+
+                    OcSecureResource ocSecureResource = ownedDeviceList.get(0);
+
+                    publishProgress(TAG + "Removing " + ocSecureResource.getDeviceID());
+
+                    ocSecureResource.removeDevice(20, removeDeviceListener);
+
+
+                } else {
+                    publishProgress(TAG + "Cannot remove");
+                }
+
+            } catch (Exception e) {
+                publishProgress(TAG + "Remove Device error: " + e.getMessage());
+
+
+            }
+            return null;
+        }
+
+        @Override
+        protected void onProgressUpdate(String... values) {
+            logMessage(values[0]);
+        }
+
+
+    }
+
+    private class OwnedDiscoveryAsyncTask extends AsyncTask<Void, String, String> {
+
+        @Override
+        protected void onPreExecute() {
+            super.onPreExecute();
+        }
+
+        @Override
+        protected String doInBackground(Void... params) {
+            try {
+                publishProgress(TAG + "Initiate Owned device Discovery");
+
+                ownedDeviceList = OcProvisioning.discoverOwnedDevices(10);
+
+                if (ownedDeviceList.size() > 0) {
+                    for (int i = 0; i < ownedDeviceList.size(); i++) {
+                        publishProgress(TAG + "Owned Discovered Device " + (i + 1) + "= " +
+                                        ownedDeviceList.get(i).getDeviceID()
+                                        + "\nIP Address= " + ownedDeviceList.get(i).getIpAddr()
+                                        + "\nOwned Status= " + ownedDeviceList.get(i).getOwnedStatus()
+                                        + "\nDevice Status= " + ((ownedDeviceList.get(i).
+                                        getDeviceStatus() == DeviceStatus.ON) ? "ON" : "OFF")
+                        );
+                    }
+                } else {
+                    publishProgress(TAG + "No Owned devices present");
+                }
+
+            } catch (OcException e) {
+                publishProgress(TAG + "Owned device Discovery error: " + e.getMessage());
+                return "Owned device Discovery error: " + e.getMessage();
+
+            }
+            return "success";
+        }
+
+        @Override
+        protected void onProgressUpdate(String... values) {
+            logMessage(values[0]);
+        }
+
+        @Override
+        protected void onPostExecute(String s) {
+
+            if (ownedDeviceList.size() > 1 && "success".equals(s)) {
+                doPairwiseProvisioning();
+
+            }
+
+
+        }
+
+    }
+
+    /**
+     * to display on Server Message on Client screen
+     */
+    public class MessageReceiver extends BroadcastReceiver {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            final String message = intent.getStringExtra(StringConstants.MESSAGE);
+            logMessage(message);
+        }
+    }
+}
diff --git a/android/examples/provisioningclient/src/main/java/org/iotivity/base/examples/provisioningclient/StringConstants.java b/android/examples/provisioningclient/src/main/java/org/iotivity/base/examples/provisioningclient/StringConstants.java
new file mode 100644 (file)
index 0000000..0854861
--- /dev/null
@@ -0,0 +1,12 @@
+package org.iotivity.base.examples.provisioningclient;
+
+public interface StringConstants {
+
+    public static final int NUMBER_ZERO =  0;
+    public static final int ERROR_CODE =  1;
+    public static final String OIC_CLIENT_JSON_DB_FILE =  "oic_svr_db_client.json";
+    public static final String MESSAGE = "message";
+    public static final String OIC_SQL_DB_FILE =  "Pdm.db";
+    public static final int  CREDENTIAL_TYPE=1;
+    public static final int  OWNER_PSK_LENGTH_128=128/8;
+}
diff --git a/android/examples/provisioningclient/src/main/res/layout/activity_secure_provision_client.xml b/android/examples/provisioningclient/src/main/res/layout/activity_secure_provision_client.xml
new file mode 100644 (file)
index 0000000..596ac98
--- /dev/null
@@ -0,0 +1,16 @@
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
+    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
+    android:paddingRight="@dimen/activity_horizontal_margin"
+    android:paddingTop="@dimen/activity_vertical_margin"
+    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
+    android:label="@string/app_name">
+
+    <LinearLayout
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent"
+        android:orientation="vertical"
+        android:id="@+id/linearLayout" >
+    </LinearLayout>
+</RelativeLayout>
+
diff --git a/android/examples/provisioningclient/src/main/res/menu/menu_secure_provision_client.xml b/android/examples/provisioningclient/src/main/res/menu/menu_secure_provision_client.xml
new file mode 100644 (file)
index 0000000..dd57e4d
--- /dev/null
@@ -0,0 +1,5 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools" tools:context=".SecureProvisionClientActivity">
+    <item android:id="@+id/action_settings" android:title="@string/action_settings"
+        android:orderInCategory="100" android:showAsAction="never" />
+</menu>
diff --git a/android/examples/provisioningclient/src/main/res/mipmap-hdpi/ic_launcher.png b/android/examples/provisioningclient/src/main/res/mipmap-hdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..cde69bc
Binary files /dev/null and b/android/examples/provisioningclient/src/main/res/mipmap-hdpi/ic_launcher.png differ
diff --git a/android/examples/provisioningclient/src/main/res/mipmap-mdpi/ic_launcher.png b/android/examples/provisioningclient/src/main/res/mipmap-mdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..c133a0c
Binary files /dev/null and b/android/examples/provisioningclient/src/main/res/mipmap-mdpi/ic_launcher.png differ
diff --git a/android/examples/provisioningclient/src/main/res/mipmap-xhdpi/ic_launcher.png b/android/examples/provisioningclient/src/main/res/mipmap-xhdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..bfa42f0
Binary files /dev/null and b/android/examples/provisioningclient/src/main/res/mipmap-xhdpi/ic_launcher.png differ
diff --git a/android/examples/provisioningclient/src/main/res/mipmap-xxhdpi/ic_launcher.png b/android/examples/provisioningclient/src/main/res/mipmap-xxhdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..324e72c
Binary files /dev/null and b/android/examples/provisioningclient/src/main/res/mipmap-xxhdpi/ic_launcher.png differ
diff --git a/android/examples/provisioningclient/src/main/res/values-v21/styles.xml b/android/examples/provisioningclient/src/main/res/values-v21/styles.xml
new file mode 100644 (file)
index 0000000..dba3c41
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <style name="AppTheme" parent="android:Theme.Material.Light">
+    </style>
+</resources>
diff --git a/android/examples/provisioningclient/src/main/res/values-w820dp/dimens.xml b/android/examples/provisioningclient/src/main/res/values-w820dp/dimens.xml
new file mode 100644 (file)
index 0000000..63fc816
--- /dev/null
@@ -0,0 +1,6 @@
+<resources>
+    <!-- Example customization of dimensions originally defined in res/values/dimens.xml
+         (such as screen margins) for screens with more than 820dp of available width. This
+         would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
+    <dimen name="activity_horizontal_margin">64dp</dimen>
+</resources>
diff --git a/android/examples/provisioningclient/src/main/res/values/dimens.xml b/android/examples/provisioningclient/src/main/res/values/dimens.xml
new file mode 100644 (file)
index 0000000..47c8224
--- /dev/null
@@ -0,0 +1,5 @@
+<resources>
+    <!-- Default screen margins, per the Android Design guidelines. -->
+    <dimen name="activity_horizontal_margin">16dp</dimen>
+    <dimen name="activity_vertical_margin">16dp</dimen>
+</resources>
diff --git a/android/examples/provisioningclient/src/main/res/values/strings.xml b/android/examples/provisioningclient/src/main/res/values/strings.xml
new file mode 100644 (file)
index 0000000..fafb434
--- /dev/null
@@ -0,0 +1,6 @@
+<resources>
+    <string name="app_name">Provisioning Client</string>
+
+    <string name="hello_world">Hello world!</string>
+    <string name="action_settings">Settings</string>
+</resources>
diff --git a/android/examples/provisioningclient/src/main/res/values/styles.xml b/android/examples/provisioningclient/src/main/res/values/styles.xml
new file mode 100644 (file)
index 0000000..ff6c9d2
--- /dev/null
@@ -0,0 +1,8 @@
+<resources>
+
+    <!-- Base application theme. -->
+    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+        <!-- Customize your theme here. -->
+    </style>
+
+</resources>
index 4cd41ac..fa802b9 100755 (executable)
@@ -1 +1 @@
-include ':simpleserver', ':simpleclient', ':message', ':fridgeserver', ':fridgeclient', ':guiclient'
+include ':simpleserver', ':simpleclient', ':message', ':fridgeserver', ':fridgeclient', ':guiclient', ':secureprovisionclient'
index 0266046..cf7ad92 100755 (executable)
@@ -126,6 +126,6 @@ libocsrm = libocsrm_env.StaticLibrary('libocsrm', libocsrm_src)
 libocsrm_env.InstallTarget(libocsrm, 'libocsrm')
 libocsrm_env.UserInstallTargetLib(libocsrm, 'libocsrm')
 
-if target_os == 'linux' and env.get('SECURED') == '1':
+if target_os in ['linux', 'android'] and env.get('SECURED') == '1':
        SConscript('provisioning/SConscript')