[Mediator]Java SDK for the new C++ APIs
authorJay Sharma <jay.sharma@samsung.com>
Wed, 10 Feb 2016 06:51:45 +0000 (12:21 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Thu, 11 Feb 2016 03:01:58 +0000 (03:01 +0000)
- Added Java SDK
- Added JNI layer
- Updated Sample Application for new APIS

Signed-off-by: Jay Sharma <jay.sharma@samsung.com>
Change-Id: Ic60f8511000720c642144f77541a4b3ad32645b5
Reviewed-on: https://gerrit.iotivity.org/gerrit/4969
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
49 files changed:
service/easy-setup/SConscript
service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/java/org/iotivity/service/easysetup/MainActivity.java
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/build.gradle [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/androidTest/androidTest.iml [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/mediator/EasySetupServiceConfigTest.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/mediator/EasySetupServiceTest.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/mediator/EasySetupStatusTest.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/mediator/EnrolleeDeviceFactoryTest.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/mediator/Utility.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/AndroidManifest.xml [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeInfo.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeOnBoardingInfo.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/IOnBoardingStatus.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/ip/WiFiSoftAPManager.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ESException.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetupService.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetupStatus.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeDevice.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeDeviceFactory.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeDeviceWiFiOnboarding.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeSetupError.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeState.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/IProvisionStatusNativeHandler.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/IpOnBoardingConnection.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/OnBoardingCallback.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/OnBoardingConfig.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/OnBoardingConnection.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ProvisioningCallback.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ProvisioningConfig.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/RemoteEnrollee.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/WiFiOnBoardingConfig.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/WiFiProvConfig.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/main.iml [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/res/drawable-hdpi/ic_launcher.png [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/res/values/strings.xml [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/res/values/styles.xml [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/jni/Android.mk [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/jni/Application.mk [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/jni/JniEasySetup.cpp [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/jni/JniEasySetup.h [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/jni/JniEsListenerManager.h [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/jni/JniEsUtils.cpp [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/jni/JniEsUtils.h [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/jni/JniJvm.cpp [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/jni/JniJvm.h [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/jni/JniProvisioningStatusLisener.cpp [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/jni/JniProvisioningStatusListener.h [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/jni/JniRemoteEnrollee.cpp [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/richsdk/jni/JniRemoteEnrollee.h [new file with mode: 0644]

index fc474a1..840b987 100755 (executable)
@@ -64,7 +64,7 @@ easy_setup_env.AppendUnique(CPPPATH = ['sdk/inc', 'sdk/src', 'sdk/common'])
 
 if target_os not in ['windows', 'winrt']:
     easy_setup_env.AppendUnique(CXXFLAGS = ['-Wall', '-std=c++0x'])
-       
+
 if target_os == 'linux':
    easy_setup_env.AppendUnique(LIBS = ['pthread', 'dl'])
 
@@ -72,7 +72,7 @@ if target_os in ['android']:
        easy_setup_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
        easy_setup_env.AppendUnique(RPATH = [env.get('BUILD_DIR')])
        easy_setup_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
-       easy_setup_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'gnustl_shared'])      
+       easy_setup_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'gnustl_shared'])
        if not env.get('RELEASE'):
                easy_setup_env.AppendUnique(LIBS = ['log'])
 
@@ -89,7 +89,7 @@ if target_os == 'tizen':
        easy_setup_env.AppendUnique(RPATH = [env.get('BUILD_DIR')])
        easy_setup_env.AppendUnique(CXXFLAGS = ['-pthread'])
        easy_setup_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'pthread', 'connectivity_abstraction'])
-               
+
 if target_os == 'arduino':
        easy_setup_env.AppendUnique(CPPPATH = [
                       env.get('SRC_DIR') + '/resource/c_common/oic_malloc/include',
@@ -102,10 +102,10 @@ if target_os == 'arduino':
                               'sdk/enrollee/src',
                               'sdk/enrollee/inc'])
        easy_setup_env.AppendUnique(CPPDEFINES = ['ESWIFI'])
-       
-if target_os in ['android','linux']:                                      
+
+if target_os in ['android','linux']:
        easy_setup_env.PrependUnique(CPPPATH = [
-               env.get('SRC_DIR') + '/resource/c_common/oic_malloc/include',           
+               env.get('SRC_DIR') + '/resource/c_common/oic_malloc/include',
                env.get('SRC_DIR') + '/resource/include',
                env.get('SRC_DIR') + '/resource/csdk/logger/include',
         env.get('SRC_DIR') + '/resource/csdk/stack/include',
@@ -167,7 +167,7 @@ print"easysetup_path %s" % easysetup_path
 
 es_src = None
 
-if target_os == 'linux':
+if target_os in ['android','linux']:
        if env.get('SECURED') == '1':
                env.AppendUnique(es_src = [os.path.join(easysetup_path, 'sdk/mediator/src/EnrolleeSecurity.cpp')])
 
index c10a0c0..cb3827d 100755 (executable)
@@ -250,7 +250,17 @@ public class MainActivity extends Activity {
                                 mEnrollerPassword);\r
                         mDevice = mDeviceFactory\r
                                 .newEnrolleeDevice(mWiFiProvConfig);\r
-                        mEasySetupService.startSetup(mDevice);\r
+                            Thread thread = new Thread() {\r
+                            @Override\r
+                            public void run() {\r
+                                try {\r
+                                       mEasySetupService.startSetup(mDevice);\r
+                                }catch (Exception e) {\r
+                                    e.printStackTrace();\r
+                                }\r
+                            }\r
+                        };\r
+                        thread.start();\r
                     } else {\r
                         mSoftAPSsid = mSoftAPSsidText.getText().toString();\r
                         mSoftAPPassword = mSoftAPPassText.getText().toString();\r
@@ -303,7 +313,22 @@ public class MainActivity extends Activity {
                 mResultTextView.setText(R.string.stopped);\r
                 mProgressbar.setIndeterminate(false);\r
                 mProgressbar.setVisibility(View.INVISIBLE);\r
-                mEasySetupService.stopSetup(mDevice);\r
+                try {\r
+                    Thread thread = new Thread() {\r
+                        @Override\r
+                        public void run() {\r
+                            try {\r
+                                mEasySetupService.stopSetup(mDevice);\r
+                            }catch (Exception e) {\r
+                                e.printStackTrace();\r
+                            }\r
+                        }\r
+                    };\r
+                    thread.start();\r
+\r
+                }catch(Exception e){\r
+                    Log.i("Stop setup", "Exception");\r
+                }\r
             }\r
         });\r
     }\r
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/build.gradle b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/build.gradle
new file mode 100644 (file)
index 0000000..a002297
--- /dev/null
@@ -0,0 +1,34 @@
+apply plugin: 'com.android.library'
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+buildscript {
+    repositories {
+        jcenter()
+    }
+    dependencies {
+        classpath 'com.android.tools.build:gradle:1.2.3'
+    }
+}
+allprojects {
+    repositories {
+        jcenter()
+    }
+}
+android {
+    compileSdkVersion 21
+    buildToolsVersion '21.1.2'
+
+    defaultConfig {
+        minSdkVersion 21
+        targetSdkVersion 21
+    }
+
+    buildTypes {
+        release {
+            minifyEnabled false
+            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+        }
+    }
+    sourceSets {
+        main { java.srcDirs = ['src/main/java', 'src/main/java/common', 'src/main/java/interface'] }
+    }
+}
\ No newline at end of file
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/androidTest/androidTest.iml b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/androidTest/androidTest.iml
new file mode 100644 (file)
index 0000000..a862cc8
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/java" isTestSource="false" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="library" name="classes" level="project" />
+    <orderEntry type="module" module-name="main" />
+  </component>
+</module>
\ No newline at end of file
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/mediator/EasySetupServiceConfigTest.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/mediator/EasySetupServiceConfigTest.java
new file mode 100644 (file)
index 0000000..3ee90fd
--- /dev/null
@@ -0,0 +1,74 @@
+/**
+ * ***************************************************************
+ * <p/>
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p/>
+ * <p/>
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+import android.test.AndroidTestCase;
+
+
+public class EasySetupServiceConfigTest extends AndroidTestCase {
+
+
+    public void testConstruction() {
+
+        EasySetupService service = EasySetupService.getInstance(getContext(), new EasySetupStatus() {
+            @Override
+            public void onFinished(EnrolleeDevice enrolledevice) {
+
+            }
+
+            @Override
+            public void onProgress(EnrolleeDevice enrolleeDevice) {
+
+            }
+        });
+
+        assertTrue(service != null);
+
+
+    }
+
+    public void testFinish() {
+        EasySetupService service = EasySetupService.getInstance(getContext(), new EasySetupStatus() {
+            @Override
+            public void onFinished(EnrolleeDevice enrolledevice) {
+
+            }
+
+            @Override
+            public void onProgress(EnrolleeDevice enrolleeDevice) {
+
+            }
+        });
+        service.finish();
+
+        // No runtime exception is thrown means test is successful
+        assertTrue(true);
+
+    }
+
+    public void testEnrolleeDeviceFacotryConstruction() {
+        EnrolleeDeviceFactory factory = EnrolleeDeviceFactory.newInstance(getContext());
+        assertTrue(factory != null);
+    }
+
+}
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/mediator/EasySetupServiceTest.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/mediator/EasySetupServiceTest.java
new file mode 100644 (file)
index 0000000..f298bb7
--- /dev/null
@@ -0,0 +1,155 @@
+//******************************************************************
+//
+// 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.service.easysetup.mediator;
+
+import android.net.wifi.WifiConfiguration;
+import android.test.AndroidTestCase;
+import android.util.Log;
+
+import java.io.IOException;
+
+public class EasySetupServiceTest extends AndroidTestCase {
+
+
+    public void testStartSetupWithWiFiOnboarding() {
+
+        EasySetupService mService;
+        EnrolleeDevice mDevice;
+        EnrolleeDeviceFactory mFactory;
+
+        final Object lock = new Object();
+
+
+        /* Create Easy Setup service */
+        mService = EasySetupService.getInstance(getContext(), new EasySetupStatus() {
+            @Override
+            public void onFinished(EnrolleeDevice enrolledevice) {
+
+                //countDownLatch.countDown();
+                Utility.toNotify(lock);
+
+                if (enrolledevice.isSetupSuccessful()) {
+
+                    if (enrolledevice.mOnBoardingConfig.getConnType() == WiFiOnBoardingConfig.ConnType.WiFi) {
+                        IpOnBoardingConnection conn = (IpOnBoardingConnection) enrolledevice.getConnection();
+                        String ip = conn.getIp();
+                        if (ip == null || ip.isEmpty()) {
+                            assertTrue(false);
+                            return;
+                        }
+                        String mac = conn.getHardwareAddress();
+                        if (mac == null || mac.isEmpty()) {
+                            assertTrue(false);
+                            return;
+                        }
+                        // Device configured successfully
+                        assertTrue(true);
+                    }
+
+                } else {
+                    assertTrue(false);
+                }
+            }
+
+            @Override
+            public void onProgress(EnrolleeDevice enrolleeDevice) {
+                // Handled in EasySetupStatusTest
+            }
+        });
+
+
+        /* Create On boarding configuration */
+        WiFiOnBoardingConfig mWiFiOnBoardingConfig = new WiFiOnBoardingConfig();
+        mWiFiOnBoardingConfig.setSSId("EasySetup123");
+        mWiFiOnBoardingConfig.setSharedKey("EasySetup123");
+        mWiFiOnBoardingConfig.setAuthAlgo(WifiConfiguration.AuthAlgorithm.OPEN);
+        mWiFiOnBoardingConfig.setKms(WifiConfiguration.KeyMgmt.WPA_PSK);
+
+        /* Create provisioning configuration */
+        WiFiProvConfig mWiFiProvConfig = new WiFiProvConfig("hub2.4G", "11112222");
+
+        /* Create enrolling device factory instance */
+        mFactory = EnrolleeDeviceFactory.newInstance(getContext());
+
+        /* Check if the factory created successfully */
+        assertTrue(mFactory != null);
+
+        /* Create enrolling device */
+        mDevice = mFactory.newEnrolleeDevice(mWiFiOnBoardingConfig, mWiFiProvConfig);
+
+        /* Check if the the device is created successfully*/
+        assertTrue(mDevice != null);
+
+        /* Check if the the correct device is created as per the given configuration*/
+        assertTrue((mDevice instanceof EnrolleeDeviceWiFiOnboarding));
+
+
+        try {
+            mService.startSetup(mDevice);
+            // If no exception is thrown means setup started successfully.
+            assertTrue(true);
+
+        } catch (IOException e) {
+            assertTrue(false);
+        }
+
+        try {
+
+            Utility.toWait(lock);
+
+            Log.i("EasySetupTest", "Lock is released");
+
+            if (!mDevice.isSetupSuccessful()) {
+                assertTrue(false);
+                return;
+            }
+
+            IpOnBoardingConnection conn = (IpOnBoardingConnection) mDevice.getConnection();
+            if (conn == null) {
+                assertTrue(false);
+                return;
+            }
+
+            String ip = conn.getIp();
+            if (ip == null || ip.isEmpty()) {
+                assertTrue(false);
+                return;
+            }
+
+            String mac = conn.getHardwareAddress();
+            if (mac == null || mac.isEmpty()) {
+                assertTrue(false);
+                return;
+            }
+
+            Log.i("EasySetupTest", "Ip" + conn.getIp());
+            Log.i("EasySetupTest", "MAC" + conn.getHardwareAddress());
+
+            // Device configured successfully
+            assertTrue(true);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            assertTrue(false);
+        }
+
+    }
+
+}
\ No newline at end of file
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/mediator/EasySetupStatusTest.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/mediator/EasySetupStatusTest.java
new file mode 100644 (file)
index 0000000..d1a1370
--- /dev/null
@@ -0,0 +1,163 @@
+//******************************************************************
+//
+// 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.service.easysetup.mediator;
+
+import android.net.wifi.WifiConfiguration;
+import android.test.AndroidTestCase;
+import android.util.Log;
+
+import java.io.IOException;
+
+public class EasySetupStatusTest extends AndroidTestCase {
+
+
+    public void testStartSetupWithWiFiOnboarding() {
+
+        EasySetupService mService;
+        EnrolleeDevice mDevice;
+        EnrolleeDeviceFactory mFactory;
+
+        final Object lock = new Object();
+
+
+        /* Create Easy Setup service */
+        mService = EasySetupService.getInstance(getContext(), new EasySetupStatus() {
+            EnrolleeState old_state = null;
+
+            @Override
+            public void onFinished(EnrolleeDevice enrolledevice) {
+
+                //countDownLatch.countDown();
+                Utility.toNotify(lock);
+
+                if (enrolledevice.isSetupSuccessful()) {
+
+                    if (enrolledevice.mOnBoardingConfig.getConnType() == WiFiOnBoardingConfig.ConnType.WiFi) {
+                        IpOnBoardingConnection conn = (IpOnBoardingConnection) enrolledevice.getConnection();
+                        String ip = conn.getIp();
+                        if (ip == null || ip.isEmpty()) {
+                            assertTrue(false);
+                            return;
+                        }
+                        String mac = conn.getHardwareAddress();
+                        if (mac == null || mac.isEmpty()) {
+                            assertTrue(false);
+                            return;
+                        }
+                        // Device configured successfully
+                        assertTrue(true);
+                    }
+
+                } else {
+                    assertTrue(false);
+                }
+            }
+
+            @Override
+            public void onProgress(EnrolleeDevice enrolleeDevice) {
+                EnrolleeState state = enrolleeDevice.mState;
+                // TODO
+                switch (state) {
+                    case DEVICE_INIT_STATE:
+                        Log.d("enrollee state", "DEVICE_INIT_STATE");
+                        assertTrue(false);
+                        break;
+                    case DEVICE_ON_BOARDING_STATE:
+                        if (old_state == null)
+                            assertTrue(true);
+                        else assertTrue(false);
+                        old_state = EnrolleeState.DEVICE_ON_BOARDING_STATE;
+                        Log.d("enrollee state", "DEVICE_ON_BOARDING_STATE");
+                        break;
+
+                    case DEVICE_ON_BOARDED_STATE:
+                        if (old_state == EnrolleeState.DEVICE_ON_BOARDING_STATE)
+                            assertTrue(true);
+                        else assertTrue(false);
+                        old_state = EnrolleeState.DEVICE_ON_BOARDED_STATE;
+                        Log.d("enrollee state", "DEVICE_ON_BOARDED_STATE");
+                        break;
+
+                    case DEVICE_PROVISIONING_STATE:
+                        if (old_state == EnrolleeState.DEVICE_ON_BOARDED_STATE)
+                            assertTrue(true);
+                        else assertTrue(false);
+                        old_state = EnrolleeState.DEVICE_PROVISIONING_STATE;
+                        Log.d("enrollee state", "DEVICE_PROVISIONING_STATE");
+                        break;
+
+                    case DEVICE_PROVISIONED_STATE:
+                        if (old_state == EnrolleeState.DEVICE_PROVISIONING_STATE)
+                            assertTrue(true);
+                        else assertTrue(false);
+                        Log.d("enrollee state", "DEVICE_PROVISIONING_SUCCESS_STATE");
+                        break;
+
+                    default:
+                        Log.d("enrollee state", "unknown state");
+                        assertTrue(false);
+                        break;
+                }
+
+            }
+        });
+
+
+        /* Create On boarding configuration */
+        WiFiOnBoardingConfig mWiFiOnBoardingConfig = new WiFiOnBoardingConfig();
+        mWiFiOnBoardingConfig.setSSId("EasySetup123");
+        mWiFiOnBoardingConfig.setSharedKey("EasySetup123");
+        mWiFiOnBoardingConfig.setAuthAlgo(WifiConfiguration.AuthAlgorithm.OPEN);
+        mWiFiOnBoardingConfig.setKms(WifiConfiguration.KeyMgmt.WPA_PSK);
+
+        /* Create provisioning configuration */
+        WiFiProvConfig mWiFiProvConfig = new WiFiProvConfig("hub2.4G", "11112222");
+
+        /* Create enrolling device factory instance */
+        mFactory = EnrolleeDeviceFactory.newInstance(getContext());
+
+        /* Create enrolling device */
+        mDevice = mFactory.newEnrolleeDevice(mWiFiOnBoardingConfig, mWiFiProvConfig);
+
+        try {
+            mService.startSetup(mDevice);
+        } catch (IOException e) {
+        }
+
+        try {
+
+            Utility.toWait(lock);
+
+            Log.i("EasySetupTest", "Lock is released");
+
+            IpOnBoardingConnection conn = (IpOnBoardingConnection) mDevice.getConnection();
+
+            Log.i("EasySetupTest", "Ip" + conn.getIp());
+            Log.i("EasySetupTest", "MAC" + conn.getHardwareAddress());
+
+            // Device configured successfully
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+
+}
\ No newline at end of file
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/mediator/EnrolleeDeviceFactoryTest.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/mediator/EnrolleeDeviceFactoryTest.java
new file mode 100644 (file)
index 0000000..b0f955c
--- /dev/null
@@ -0,0 +1,70 @@
+/**
+ * ***************************************************************
+ * <p/>
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p/>
+ * <p/>
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+import android.net.wifi.WifiConfiguration;
+import android.test.AndroidTestCase;
+
+public class EnrolleeDeviceFactoryTest extends AndroidTestCase {
+
+    EnrolleeDeviceFactory mFactory;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mFactory = EnrolleeDeviceFactory.newInstance(getContext());
+        assertTrue(mFactory != null);
+
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        mFactory = null;
+    }
+
+
+    public void testNewEnrolleeDevice_with_WiFiOnboarding() {
+
+        /* Create On boarding configuration */
+        WiFiOnBoardingConfig mWiFiOnBoardingConfig = new WiFiOnBoardingConfig();
+        mWiFiOnBoardingConfig.setSSId("EasySetup123");
+        mWiFiOnBoardingConfig.setSharedKey("EasySetup123");
+        mWiFiOnBoardingConfig.setAuthAlgo(WifiConfiguration.AuthAlgorithm.OPEN);
+        mWiFiOnBoardingConfig.setKms(WifiConfiguration.KeyMgmt.WPA_PSK);
+
+        /* Create provisioning configuration */
+        WiFiProvConfig mWiFiProvConfig = new WiFiProvConfig("hub2.4G", "11112222");
+
+        /* Create enrolling device */
+        EnrolleeDevice device = mFactory.newEnrolleeDevice(mWiFiOnBoardingConfig, mWiFiProvConfig);
+
+        /* Check if the the device is created */
+        assertTrue(device != null);
+
+        /* Check if the the correct device is created as per the given configuration*/
+        assertTrue((device instanceof EnrolleeDeviceWiFiOnboarding));
+
+    }
+
+}
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/mediator/Utility.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/mediator/Utility.java
new file mode 100644 (file)
index 0000000..6b0484e
--- /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.service.easysetup.mediator;
+
+
+public class Utility {
+
+    public static void toNotify(Object toLock) {
+        synchronized (toLock) {
+            toLock.notify();
+        }
+    }
+
+    public static void toWait(Object toLock) {
+        synchronized (toLock) {
+            try {
+                toLock.wait(45000);
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+}
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/AndroidManifest.xml b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/AndroidManifest.xml
new file mode 100644 (file)
index 0000000..64487cd
--- /dev/null
@@ -0,0 +1,17 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="org.iotivity.service.easysetup.mediator"
+    android:versionCode="1"
+    android:versionName="1.0" >
+
+    <uses-sdk
+        android:minSdkVersion="8"
+        android:targetSdkVersion="21" />
+
+    <application
+        android:allowBackup="true"
+        android:icon="@drawable/ic_launcher"
+        android:label="@string/app_name"
+        android:theme="@style/AppTheme" >
+    </application>
+
+</manifest>
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeInfo.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeInfo.java
new file mode 100644 (file)
index 0000000..29b7432
--- /dev/null
@@ -0,0 +1,64 @@
+/**
+ * ***************************************************************
+ * <p>
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p>
+ * <p>
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ * <p>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.core;
+
+public class EnrolleeInfo {
+
+    private String IpAddr;
+    private String HWAddr;
+    private String Device;
+    private boolean isReachable;
+
+    public String getIpAddr() {
+        return IpAddr;
+    }
+
+    public void setIpAddr(String ipAddr) {
+        IpAddr = ipAddr;
+    }
+
+    public String getHWAddr() {
+        return HWAddr;
+    }
+
+    public void setHWAddr(String hWAddr) {
+        HWAddr = hWAddr;
+    }
+
+    public String getDevice() {
+        return Device;
+    }
+
+    public void setDevice(String device) {
+        Device = device;
+    }
+
+    public boolean isReachable() {
+        return isReachable;
+    }
+
+    public void setReachable(boolean isReachable) {
+        this.isReachable = isReachable;
+    }
+
+}
\ No newline at end of file
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeOnBoardingInfo.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeOnBoardingInfo.java
new file mode 100644 (file)
index 0000000..cb67017
--- /dev/null
@@ -0,0 +1,92 @@
+/**
+ * ***************************************************************
+ * <p>
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p>
+ * <p>
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ * <p>
+ * ****************************************************************
+ */
+package org.iotivity.service.easysetup.core;
+
+public class EnrolleeOnBoardingInfo {
+
+    private String IpAddr;
+    private String HWAddr;
+    private String Device;
+    private boolean isReachable;
+    private boolean isAdditionNotified;
+    private boolean isRemovalNotified;
+
+    public EnrolleeOnBoardingInfo(String ipAddr, String hWAddr, String device,
+                                  boolean isReachable, boolean isRemovalNotified,
+                                  boolean isAdditionNotified) {
+        this.IpAddr = ipAddr;
+        this.HWAddr = hWAddr;
+        this.Device = device;
+        this.isReachable = isReachable;
+        this.isRemovalNotified = isRemovalNotified;
+        this.isAdditionNotified = isAdditionNotified;
+    }
+
+    public String getIpAddr() {
+        return IpAddr;
+    }
+
+    public void setIpAddr(String ipAddr) {
+        IpAddr = ipAddr;
+    }
+
+    public String getHWAddr() {
+        return HWAddr;
+    }
+
+    public void setHWAddr(String hWAddr) {
+        HWAddr = hWAddr;
+    }
+
+    public String getDevice() {
+        return Device;
+    }
+
+    public void setDevice(String device) {
+        Device = device;
+    }
+
+    public boolean isReachable() {
+        return isReachable;
+    }
+
+    public void setReachable(boolean isReachable) {
+        this.isReachable = isReachable;
+    }
+
+    public boolean isRemovalNotified() {
+        return isRemovalNotified;
+    }
+
+    public void setRemovalNotified(boolean isRemovalNotified) {
+        this.isRemovalNotified = isRemovalNotified;
+    }
+
+    public boolean isAdditionNotified() {
+        return isAdditionNotified;
+    }
+
+    public void setAdditionNotified(boolean isAdditionNotified) {
+        this.isAdditionNotified = isAdditionNotified;
+    }
+
+}
\ No newline at end of file
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/IOnBoardingStatus.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/IOnBoardingStatus.java
new file mode 100644 (file)
index 0000000..c709af8
--- /dev/null
@@ -0,0 +1,35 @@
+/**
+ * ***************************************************************
+ * <p>
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p>
+ * <p>
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ * <p>
+ * ****************************************************************
+ */
+package org.iotivity.service.easysetup.core;
+
+public interface IOnBoardingStatus {
+
+    /**
+     * Interface called when the scan method finishes. Network operations should
+     * not execute on UI thread
+     *
+     * @param clients of {@link EnrolleeInfo}
+     */
+
+    public void deviceOnBoardingStatus(EnrolleeInfo clients);
+
+}
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/ip/WiFiSoftAPManager.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/ip/WiFiSoftAPManager.java
new file mode 100644 (file)
index 0000000..40bfd12
--- /dev/null
@@ -0,0 +1,301 @@
+/**
+ * ***************************************************************
+ * <p>
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p>
+ * <p>
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ * <p>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.core.ip;
+
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.lang.reflect.Method;
+import java.net.InetAddress;
+import java.util.ArrayList;
+
+import android.content.Context;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiManager;
+import android.util.Log;
+
+import org.iotivity.service.easysetup.core.EnrolleeInfo;
+import org.iotivity.service.easysetup.core.EnrolleeOnBoardingInfo;
+import org.iotivity.service.easysetup.core.IOnBoardingStatus;
+
+/**
+ * WiFiSoftAPManager provides wrapper methods for accessing Android Soft Access Point functionality.
+ * This is a convenient class, providing Android "WiFiManager" kind of equivalent class for Soft AP.
+ * <p>
+ * Note: Android doesn't provide public APIs for Soft Access Point feature access.
+ * This class provides only reference implementation to use the Soft AP and it uses Java reflection
+ * for access Soft Access point features.
+ * </p>
+ */
+public class WiFiSoftAPManager {
+    private static final String TAG = WiFiSoftAPManager.class.getName();
+    private final WifiManager mWifiManager;
+    private Context context;
+    static ArrayList<EnrolleeOnBoardingInfo> appNotification =
+            new ArrayList<EnrolleeOnBoardingInfo>();
+    IOnBoardingStatus finishListener = null;
+
+    public enum WIFI_AP_STATE {
+        WIFI_AP_STATE_DISABLING,
+        WIFI_AP_STATE_DISABLED,
+        WIFI_AP_STATE_ENABLING,
+        WIFI_AP_STATE_ENABLED,
+        WIFI_AP_STATE_FAILED
+    }
+
+    public WiFiSoftAPManager(Context context) {
+        this.context = context;
+        mWifiManager = (WifiManager) this.context
+                .getSystemService(Context.WIFI_SERVICE);
+    }
+
+    /*
+    * Utility API to check the validity of the MAC Address read from the ARP cache
+    */
+    private boolean CheckIfValidMacAddress(String macAddr) {
+        if (macAddr.matches("..:..:..:..:..:..")) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /*
+    * The API is used for checking the device entry in the list maintained for the device
+    * notifications.
+    * If device entry is not found in the list, app is notified.
+    * If the device entry is found in the device, as application is already notified it will
+    * continue
+    */
+    private boolean CheckForDeviceEntryAndNotify(String ipAddr,
+                                                 String macAddr, boolean isReachable) {
+        final EnrolleeInfo result = new EnrolleeInfo();
+        boolean deviceAddedToList = false;
+
+        if (appNotification.size() > 0) {
+            for (EnrolleeOnBoardingInfo ipDeviceOnBoardingNotification : appNotification) {
+                EnrolleeOnBoardingInfo ipEnrolleeDevice = (EnrolleeOnBoardingInfo)
+                        ipDeviceOnBoardingNotification;
+                boolean macAddressComparison = ipEnrolleeDevice.getHWAddr().equalsIgnoreCase(
+                        macAddr) ? true : false;
+
+                if (macAddressComparison) {
+                    deviceAddedToList = true;
+
+                    if (ipDeviceOnBoardingNotification
+                            .isAdditionNotified()
+                            && isReachable) {
+                        continue;
+                    } else if (ipDeviceOnBoardingNotification
+                            .isRemovalNotified()
+                            && !isReachable) {
+                        continue;
+                    } else {
+                        result.setIpAddr(ipAddr);
+                        result.setHWAddr(macAddr);
+                        result.setReachable(isReachable);
+
+                        appNotification
+                                .remove(ipDeviceOnBoardingNotification);
+                        if (isReachable) {
+                            appNotification
+                                    .add(new EnrolleeOnBoardingInfo(ipAddr, macAddr, "",
+                                            isReachable,
+                                            false, true));
+                        } else {
+                            //This case will happen during the transition from connected to
+                            // disconneted. This case need not be notified to application.
+                            // Notifying this state will cause failure of OnBoarding
+                        }
+                        NotifyApplication(result);
+                        return true;
+                    }
+                }
+            }
+            if (!deviceAddedToList) {
+                if (isReachable) {
+                    appNotification
+                            .add(new EnrolleeOnBoardingInfo(ipAddr, macAddr, "", isReachable, false,
+                                    true));
+
+                    result.setIpAddr(ipAddr);
+                    result.setHWAddr(macAddr);
+                    result.setReachable(isReachable);
+
+                    NotifyApplication(result);
+                } else {
+                    //This case will happen for the first time device is listed, but reachability
+                    // is false. This case need not be notified to application. Notifying this
+                    // state will cause failure of OnBoarding
+                }
+                return true;
+            }
+        } else {
+            if (isReachable) {
+                appNotification
+                        .add(new EnrolleeOnBoardingInfo(ipAddr, macAddr, "", isReachable, false,
+                                true));
+                result.setIpAddr(ipAddr);
+                result.setHWAddr(macAddr);
+                result.setReachable(isReachable);
+
+                NotifyApplication(result);
+            } else {
+                //This case will happen for the first time device is listed,  but
+                // reachability is false. This case need not be notified to
+                // application. Notifying this state will cause failure of OnBoarding
+            }
+
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Start WiFi Soft AccessPoint mode with the specified configuration.
+     * If the Soft AP is already running, this API call will update the new configuration.
+     * <p>
+     * Note: Starting Wi-Fi Soft Access Point will disable the Wi-Fi normal operation.
+     * </p>
+     *
+     * @param wifiConfig SSID, security and channel details as part of WifiConfiguration
+     * @return {@code true} if the operation succeeds, {@code false} otherwise
+     */
+    public boolean setWifiApEnabled(WifiConfiguration wifiConfig,
+                                    boolean enabled) {
+        try {
+            appNotification.clear();
+            // Stopping Wi-Fi mode
+            if (enabled) {
+                mWifiManager.setWifiEnabled(false);
+            }
+
+            Method method = mWifiManager.getClass().getMethod(
+                    "setWifiApEnabled", WifiConfiguration.class, boolean.class);
+            return (Boolean) method.invoke(mWifiManager, wifiConfig, enabled);
+        } catch (Exception e) {
+            Log.e(this.getClass().toString(), "", e);
+            return false;
+        }
+    }
+
+    /**
+     * Gets a list of the Soft AP clients connected to the Wi-Fi Soft Access point
+     *
+     * @param finishListener   Interface called when the scan method finishes
+     * @param reachableTimeout Reachable Timeout in miliseconds
+     */
+    public synchronized void getClientList(IOnBoardingStatus finishListener, final int
+            reachableTimeout) {
+        this.finishListener = finishListener;
+        //Clearing the scan list for providing u
+        appNotification.clear();
+        Runnable runnable = new Runnable() {
+            public void run() {
+                Log.i(TAG, "Scanning enrolling device in the network");
+
+                BufferedReader bufferedReader = null;
+
+                try {
+                    // Note : This is a reference implementation for getting the list of Enrollee's
+                    // connected to the Soft AP.
+                    // There is no Android API for getting list of connected devices to the Soft AP.
+                    // The connected device information is fetched from Arp cache for Soft AP and
+                    // it is maintained in the file "/proc/net/arp"
+                    // This holds an ASCII readable dump of the kernel ARP  table  used
+                    // for  address resolutions.  It will show both dynamically learned
+                    // and preprogrammed ARP entries.  The format is:
+                    // IP address     HW type   Flags     HW address          Mask   Device
+                    // 192.168.0.50   0x1       0x2       00:50:BF:25:68:F3   *      eth0
+                    // 192.168.0.250  0x1       0xc       00:00:00:00:00:00   *      eth0
+                    bufferedReader = new BufferedReader(new InputStreamReader(
+                            new FileInputStream("/proc/net/arp"), "UTF-8"));
+                    String line;
+                    while ((line = bufferedReader.readLine()) != null) {
+                        //ARP entries are splitted using Regex for getting the IP and MAC Address
+                        // info
+                        String[] arpEntry = line.split(" +");
+
+                        if ((arpEntry != null) && (arpEntry.length >= 4)) {
+                            String ipAddr = arpEntry[0];
+                            String macAddr = arpEntry[3];
+
+
+                            // Checking if the string is matching MAC Address is matching the
+                            // standard MAC address format.
+                            // If the entry is not matching with MAC address format,
+                            // it will continue
+                            if (CheckIfValidMacAddress(macAddr)) {
+                                boolean isReachable = InetAddress.getByName(
+                                        ipAddr).isReachable(
+                                        reachableTimeout);
+
+                                Log.i("exec statement", ipAddr);
+                                Log.i("Return Value", " " + isReachable);
+
+                                // Checking if the app notification entries are available in the
+                                // list for the current device
+                                // API returns true is there is a notification to the application.
+                                // API returns false if there is no entry or if device is
+                                // already notified
+                                if (CheckForDeviceEntryAndNotify(ipAddr, macAddr, isReachable)) {
+                                    break;
+                                }
+                            }
+                        }
+                    }
+                } catch (Exception e) {
+                    Log.e(this.getClass().toString(), e.toString());
+                } finally {
+                    try {
+                        bufferedReader.close();
+                    } catch (IOException e) {
+                        Log.e(this.getClass().toString(), e.getMessage());
+                    }
+                }
+            }
+        };
+
+        Thread mythread = new Thread(runnable);
+        mythread.start();
+    }
+
+    void NotifyApplication(final EnrolleeInfo result) {
+        // Get a handler that can be used to post to the main thread
+/*
+        Handler mainHandler = new Handler(context.getMainLooper());
+        Runnable myRunnable = new Runnable() {
+            @Override
+            public void run() {
+                finishListener.deviceOnBoardingStatus(result);
+            }
+        };
+        mainHandler.post(myRunnable);
+*/
+        Log.i(TAG, "Scanning is finished with result, IP : " + result.getIpAddr() + "Notifying " +
+                "to Application");
+        finishListener.deviceOnBoardingStatus(result);
+
+    }
+}
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ESException.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ESException.java
new file mode 100644 (file)
index 0000000..86b41d8
--- /dev/null
@@ -0,0 +1,32 @@
+/**
+ * ***************************************************************
+ * <p>
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p>
+ * <p>
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ * <p>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+/**
+ * This is the Exception class for the EasySetup APIs
+ */
+public class ESException extends Exception {
+    public ESException(String exception) {
+        super(exception);
+    }
+}
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetupService.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetupService.java
new file mode 100644 (file)
index 0000000..36c0633
--- /dev/null
@@ -0,0 +1,228 @@
+/**
+ * ***************************************************************
+ * <p/>
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p/>
+ * <p/>
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+import android.content.Context;
+import android.net.wifi.WifiConfiguration;
+import android.util.Log;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+/**
+ * This is facade class, a single point of contact for Application.
+ * It contains set of APIs to do easy setup of the enrolling device.
+ * ON-BOARDING - This is a step to establish connectivity between the device & Mediator device.
+ * PROVISION   - This is a step where the netowork's detail & credentials are given to the
+ * enrolling device.
+ */
+public class EasySetupService {
+
+    private static final String TAG = EasySetupService.class.getName();
+
+    private static EasySetupService sInstance;
+
+    private final EasySetupStatus mCallback;
+
+    private ArrayList<EnrolleeDevice> mEnrolleeDeviceList;
+
+    private final ProvisioningCallback mProvisioningCallback;
+
+    private static Context mContext;
+
+    protected RemoteEnrollee mRemoteEnrollee;
+
+    //function to call the native createEnrolleeDevice
+    private native RemoteEnrollee nativeCreateEnrolleeDevice(String ip, String ssid,
+                                                     String password, int type, boolean isSecured );
+
+    static {
+        // Load Easy Setup JNI interface
+        System.loadLibrary("gnustl_shared");
+        System.loadLibrary("octbstack");
+        System.loadLibrary("connectivity_abstraction");
+        System.loadLibrary("ESSDKLibrary");
+        System.loadLibrary("easysetup-jni");
+    }
+
+    private EasySetupService(EasySetupStatus callback) {
+        mCallback = callback;
+        mProvisioningCallback = new ProvisioningCallbackImpl(mCallback);
+        mEnrolleeDeviceList = new ArrayList<EnrolleeDevice>();
+        mContext = null;
+    }
+
+    /**
+     * Gives a singleton instance of Easy setup service and initialize the service
+     *
+     * @param callback Application needs to provide this callback to receive the status of easy
+     *                 setup process.
+     */
+
+    public synchronized static EasySetupService getInstance(Context context, EasySetupStatus
+            callback) {
+        if (sInstance == null) {
+            sInstance = new EasySetupService(callback);
+            mContext = context;
+        }
+        return sInstance;
+    }
+
+    /**
+     * Reset the Easy setup Service
+     */
+
+    public void finish() {
+            //Call the stop Provisioning
+            for (EnrolleeDevice enrolleeDevice : mEnrolleeDeviceList) {
+                enrolleeDevice.stopProvisioningProcess();
+        }
+    }
+
+    /**
+     * Starts Easy setup process for the enrolling device.
+     *
+     * @param enrolledevice Device to be enrolled in network
+     * @throws IOException Throws exception in case of any connection error.
+     */
+
+    public synchronized void startSetup(final EnrolleeDevice enrolledevice) throws IOException,ESException {
+
+        mEnrolleeDeviceList.add(enrolledevice);
+
+        // Starts the provisioning directly if the device is already on boarded on the network.
+        if (enrolledevice.onBoarded()) {
+            if(null == enrolledevice.mRemoteEnrollee){
+                //create Native RemoteEnrollee
+                WiFiProvConfig config = (WiFiProvConfig)enrolledevice.mProvConfig;
+                String ip = "";
+                String ssid = config.getSsId();
+                String password = config.getPassword();
+                int connectivityType = config.getConnType().getValue();
+                boolean isSecured = config.isSecured();
+
+                //native call
+                mRemoteEnrollee = nativeCreateEnrolleeDevice(ip, ssid, password,
+                        connectivityType, isSecured);
+                enrolledevice.mRemoteEnrollee = mRemoteEnrollee;
+            }
+            enrolledevice.startProvisioning(mProvisioningCallback);
+            return;
+        }
+        enrolledevice.mState = EnrolleeState.DEVICE_ON_BOARDING_STATE;
+        mCallback.onProgress(enrolledevice);
+        enrolledevice.startOnBoarding(new OnBoardingCallback() {
+
+            @Override
+            public void onFinished(OnBoardingConnection connection) {
+                if (connection.isConnected()) {
+                    Log.i(TAG, "On boarding is successful ");
+                    // Start provisioning here
+                    enrolledevice.mState = EnrolleeState.DEVICE_ON_BOARDED_STATE;
+                    mCallback.onProgress(enrolledevice);
+                    enrolledevice.setConnection(connection);
+
+                    //create a native RemoteEnrollee with network info
+                    IpOnBoardingConnection conn = (IpOnBoardingConnection) connection;
+                    WiFiProvConfig config = (WiFiProvConfig)enrolledevice.mProvConfig;
+                    String ip = conn.getIp();
+                    String ssid = config.getSsId();
+                    String password = config.getPassword();
+                    int connectivityType = config.getConnType().getValue();
+                    boolean isSecured = config.isSecured();
+
+                    //native call
+                    mRemoteEnrollee = nativeCreateEnrolleeDevice(ip, ssid, password,
+                                connectivityType, isSecured);
+
+                    enrolledevice.mRemoteEnrollee = mRemoteEnrollee;
+
+                    /* Delay is set according to Soft AP host and Mediator platform;
+                    *  For Android with Soft AP it is 2000 ms
+                    */
+                    delayProvisioning(connection);
+                    enrolledevice.startProvisioning(mProvisioningCallback);
+                } else {
+                    enrolledevice.mState = EnrolleeState.DEVICE_INIT_STATE;
+                    mProvisioningCallback.onFinished(enrolledevice);
+                }
+            }
+        });
+    }
+
+    /**
+     * Stops on-going Easy setup process for enrolling device.
+     *
+     * @param enrolleedevice Device to be enrolled in network
+     */
+    public synchronized void stopSetup(EnrolleeDevice enrolleedevice) throws ESException {
+        if (mEnrolleeDeviceList.contains(enrolleedevice)) {
+            if (enrolleedevice.mState == EnrolleeState.DEVICE_ON_BOARDING_STATE) {
+                Log.i(TAG, "stopOnBoardingProcess for enrolleedevice");
+                enrolleedevice.stopOnBoardingProcess();
+            }else if (enrolleedevice.mState == EnrolleeState.DEVICE_PROVISIONING_STATE) {
+                Log.i(TAG, "stopEnrolleeProvisioning for enrolleedevice");
+                enrolleedevice.stopProvisioningProcess();
+            }
+            enrolleedevice.mState = EnrolleeState.DEVICE_INIT_STATE;
+            mCallback.onProgress(enrolleedevice);
+            mEnrolleeDeviceList.remove(enrolleedevice);
+        }
+    }
+
+    class ProvisioningCallbackImpl extends ProvisioningCallback {
+
+        private final EasySetupStatus mCallback;
+
+        ProvisioningCallbackImpl(EasySetupStatus callback) {
+            mCallback = callback;
+        }
+
+        @Override
+        public void onFinished(EnrolleeDevice enrolledevice) {
+            synchronized (EasySetupService.this) {
+                if (mEnrolleeDeviceList.contains(enrolledevice)) {
+                    Log.i(TAG, "onFinished() is received " + enrolledevice.isSetupSuccessful());
+                    mCallback.onFinished(enrolledevice);
+                    mEnrolleeDeviceList.remove(enrolledevice);
+                }
+            }
+        }
+
+        @Override
+        public void onProgress(EnrolleeDevice enrolledevice) {
+            mCallback.onProgress(enrolledevice);
+        }
+    }
+
+    private void delayProvisioning(OnBoardingConnection conn) {
+        if (((IpOnBoardingConnection)conn).getThrottlingDelay()>0) {
+            try {
+                Log.i(TAG, "waiting for 20 seconds to start provisioning");
+                Thread.sleep(20000);//Sleep for allowing thin device to start the services
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetupStatus.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetupStatus.java
new file mode 100644 (file)
index 0000000..b9da262
--- /dev/null
@@ -0,0 +1,50 @@
+/**
+ * ***************************************************************
+ * <p>
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p>
+ * <p>
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ * <p>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+/**
+ * This interface facilitates Application to get progress & result of Easy setup
+ * process Easy setup process.
+ */
+public interface EasySetupStatus {
+
+    /**
+     * This method is called back when easy setup process is finished. Easy
+     * setup process status can read from the APIs given in Enrollee class.This
+     * method is called on worker thread, UI operations to be executed on main /
+     * Ui Thread.
+     *
+     * @param enrolledevice Device to be enrolled in network through Easy setup process
+     */
+    public void onFinished(EnrolleeDevice enrolledevice);
+
+    /**
+     * This method is called back to give intermediate progress on the easy
+     * setup process This method is called on worker thread, UI operations to be
+     * executed on main / Ui Thread.
+     *
+     * @param enrolleeDevice Gives state of the device changed during easy setup process
+     */
+    public void onProgress(EnrolleeDevice enrolleeDevice);
+
+}
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeDevice.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeDevice.java
new file mode 100644 (file)
index 0000000..abb080d
--- /dev/null
@@ -0,0 +1,173 @@
+/**
+ * ***************************************************************
+ * <p/>
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p/>
+ * <p/>
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+/**
+ * This is an abstract class represents the device being provisioned into the network. The
+ * device being enrolled or provisioned into the network is called Enrollee.
+ * Application has to extend this class and provide implementation of abstract methods according
+ * to the ON-BOARDING & PROVISION connectivity i.e. WiFi etc.
+ */
+
+public abstract class EnrolleeDevice {
+
+    protected EnrolleeState mState;
+    private EnrolleeSetupError mError;
+
+    OnBoardingConnection mConnection;
+    final ProvisioningConfig mProvConfig;
+    final OnBoardingConfig mOnBoardingConfig;
+
+    protected OnBoardingCallback mOnBoardingCallback;
+    protected ProvisioningCallback mProvisioningCallback;
+    protected RemoteEnrollee mRemoteEnrollee;
+
+    /**
+     * @param onBoardingConfig Contains details about the connectivity to be established between
+     *                         the Enrollee device & Mediator device in order to perform
+     *                         on-boarding
+     * @param provConfig       Contains details about the network to which Enrollee device is
+     *                         going to connect.
+     */
+    protected EnrolleeDevice(OnBoardingConfig onBoardingConfig, ProvisioningConfig provConfig) {
+        mProvConfig = provConfig;
+        mOnBoardingConfig = onBoardingConfig;
+    }
+
+    /**
+     * Application has to implement it according to the on boarding connectivity the device is
+     * having.
+     * This method will be called back during the easy setup process.
+     */
+    protected abstract void startOnBoardingProcess();
+
+    /**
+     * This method is called back during the easy setup process if Application cancels the setup.
+     * Easy setup service checks the state of device and calls this function accordingly.
+     * Application has to provide implementation for this method to cancel the on boarding step.
+     */
+    protected abstract void stopOnBoardingProcess();
+
+    /**
+     * Application has to implement it according to the type of the network device is going to
+     * connect or provisioned.
+     * This method will be called back once on-boarding of the device is successful.
+     *
+     * @param conn Contains detail about the network established between the Enrollee device &
+     *             Mediator device. Its implementation vary according to the connectivity type.
+     */
+    protected abstract void startProvisioningProcess(OnBoardingConnection conn);
+
+    /**
+     * Application has to implement it according to the type of the network device is going to
+     * connect or provisioned.
+     * This method will stop the provisioning process if it is in progress
+     *
+     */
+    protected abstract void stopProvisioningProcess();
+
+    /**
+     * Once on boarding is successful concrete Enrollee class would call this method and set the
+     * Connection.
+     *
+     * @param conn Connectivity between Enrollee device & Mediator device.
+     */
+    protected void setConnection(OnBoardingConnection conn) {
+        mConnection = conn;
+    }
+
+    /**
+     * This method returns the OnBoardingConnection object depending on the connection type
+     *
+     * @return onBoardingConnection object
+     */
+    public OnBoardingConnection getConnection() {
+        return mConnection;
+    }
+
+
+    /**
+     * This method is called back by Easy setup service if on boarding needs to be done.
+     *
+     * @param onBoardingCallback This is called back once the on boarding is completed.
+     */
+    void startOnBoarding(OnBoardingCallback onBoardingCallback) {
+        mOnBoardingCallback = onBoardingCallback;
+        startOnBoardingProcess();
+    }
+
+    /**
+     * This method is called back by Easy setup service once on boarding is successful
+     *
+     * @param provisioningCallback This is called back once the provisioning process is completed
+     */
+    void startProvisioning(ProvisioningCallback provisioningCallback) {
+        mProvisioningCallback = provisioningCallback;
+        startProvisioningProcess(mConnection);
+    }
+
+    /**
+     * This method is used to check easy setup status
+     *
+     * @return true if successful or false
+     */
+
+    public boolean isSetupSuccessful() {
+        return (mState == EnrolleeState.DEVICE_PROVISIONED_STATE) ? true : false;
+    }
+
+    /**
+     * sets error occured during easy setup process
+     */
+    protected void setError(EnrolleeSetupError error) {
+        mError = error;
+    }
+
+    /**
+     * Returns error occured during easy setup process
+     *
+     * @return True EnrolleeSetupError object
+     */
+    public EnrolleeSetupError getError() {
+        return mError;
+    }
+
+    /**
+     * Gives the state of the device being enrolled during the easy setup process.
+     *
+     * @return Returns EnrolleeState object
+     */
+    public EnrolleeState getState() {
+        return mState;
+    }
+
+    /**
+     * This method is used to know if the device is on boarded or not
+     *
+     * @return True if on-boarded successfully or False
+     */
+
+    protected boolean onBoarded() {
+        return (mState == EnrolleeState.DEVICE_ON_BOARDED_STATE) ? true : false;
+    }
+}
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeDeviceFactory.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeDeviceFactory.java
new file mode 100644 (file)
index 0000000..9f62ca1
--- /dev/null
@@ -0,0 +1,76 @@
+/**
+ * ***************************************************************
+ * <p/>
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p/>
+ * <p/>
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+import android.content.Context;
+
+/**
+ * This a factory class provides the native implementation of the various Enrollee devices.
+ * Application can make use of Enrollee factory if it does not want to create its own Enrollee devices.
+ */
+public class EnrolleeDeviceFactory {
+
+    Context mContext;
+
+    /**
+     * This method create & returns instance of EnrolleeDeviceFactory
+     *
+     * @param context This is Android Application context
+     */
+    public static EnrolleeDeviceFactory newInstance(Context context) {
+        return new EnrolleeDeviceFactory(context);
+    }
+
+    private EnrolleeDeviceFactory(Context context) {
+        mContext = context;
+    }
+
+    /**
+     * This method create & returns instance of Enrollee device of supported configuration
+     *
+     * @param onboardingConfig Contains details about the connectivity to be established between the Enrollee device & Mediator device in order to perform on-boarding
+     * @param provConfig       Contains details about the network to which Enrollee device is going to connect.
+     * @return Instance of the Enrollee device created natively.
+     */
+
+    public EnrolleeDevice newEnrolleeDevice(ProvisioningConfig provConfig, OnBoardingConfig onboardingConfig) {
+
+        if (onboardingConfig.getConnType() != OnBoardingConfig.ConnType.WiFi) {
+            throw new IllegalArgumentException("OnBoarding configuration is not supported");
+        }
+
+        return new EnrolleeDeviceWiFiOnboarding(mContext, onboardingConfig, provConfig);
+    }
+
+    /**
+     * This method create & returns instance of Enrollee device of supported configuration
+     * [When SoftAP is going to be created on Enrollee side]
+     *
+     * @param provConfig       Contains details about the network to which Enrollee device is going to connect.
+     * @return Instance of the Enrollee device created natively.
+     */
+    public EnrolleeDevice newEnrolleeDevice(ProvisioningConfig provConfig){
+        return new EnrolleeDeviceWiFiOnboarding(mContext, new IpOnBoardingConnection(true), provConfig);
+    }
+
+}
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeDeviceWiFiOnboarding.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeDeviceWiFiOnboarding.java
new file mode 100644 (file)
index 0000000..66f12d0
--- /dev/null
@@ -0,0 +1,193 @@
+/**
+ * ***************************************************************
+ * <p/>
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p/>
+ * <p/>
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+import java.util.Timer;
+import java.util.TimerTask;
+
+import org.iotivity.service.easysetup.core.EnrolleeInfo;
+import org.iotivity.service.easysetup.core.IOnBoardingStatus;
+import org.iotivity.service.easysetup.core.ip.WiFiSoftAPManager;
+
+import android.content.Context;
+import android.net.wifi.WifiConfiguration;
+import android.util.Log;
+
+/**
+ * This is a ready to use class for Enrollee device having Soft AP as on-boarding connectivity.
+ */
+public class EnrolleeDeviceWiFiOnboarding extends EnrolleeDevice {
+
+    public static final String TAG = EnrolleeDeviceWiFiOnboarding.class.getName();
+
+    final Context mContext;
+    final WiFiSoftAPManager mWifiSoftAPManager;
+    EnrolleeInfo connectedDevice;
+    Timer myTimer = null;
+
+    IOnBoardingStatus deviceScanListener = new IOnBoardingStatus() {
+
+        @Override
+        public void deviceOnBoardingStatus(EnrolleeInfo enrolleStatus) {
+            myTimer.cancel();
+            Log.d("ESSoftAPOnBoarding", "Entered");
+            if (mState == EnrolleeState.DEVICE_ON_BOARDING_STATE) {
+                Log.d("ESSoftAPOnBoarding", "Device in OnBoarding State");
+                if (enrolleStatus != null && enrolleStatus.getIpAddr() != null) {
+                    String finalResult = "Easy Connect : ";
+
+                    if (enrolleStatus.isReachable()) {
+                        finalResult = "Device OnBoarded" + "["
+                                + enrolleStatus.getIpAddr() + "]";
+
+                        connectedDevice = enrolleStatus;
+                        IpOnBoardingConnection conn = new IpOnBoardingConnection();
+
+                        conn.setConnectivity(true);
+                        conn.setIp(connectedDevice.getIpAddr());
+                        conn.setHardwareAddress(enrolleStatus.getHWAddr());
+                        conn.setDeviceName(enrolleStatus.getDevice());
+
+                        Log.d("ESSoftAPOnBoarding", "Entered" + finalResult);
+                        mOnBoardingCallback.onFinished(conn);
+                        return;
+
+                    }
+                }
+
+                IpOnBoardingConnection conn = new IpOnBoardingConnection();
+                conn.setConnectivity(false);
+                mOnBoardingCallback.onFinished(conn);
+            } else {
+                Log.e("ESSoftAPOnBoarding", "Device NOT in OnBoarding State. Ignoring the event");
+            }
+        }
+    };
+
+
+    protected EnrolleeDeviceWiFiOnboarding(Context context, OnBoardingConfig onBoardingConfig,
+                                           ProvisioningConfig provConfig) {
+        super(onBoardingConfig, provConfig);
+        mContext = context;
+        mState = EnrolleeState.DEVICE_INIT_STATE;
+        mWifiSoftAPManager = new WiFiSoftAPManager(mContext);
+    }
+
+    protected EnrolleeDeviceWiFiOnboarding(Context context, IpOnBoardingConnection conn,
+                                           ProvisioningConfig provConfig) {
+        super(new WiFiOnBoardingConfig(), provConfig);
+        mContext = context;
+        mState = EnrolleeState.DEVICE_ON_BOARDED_STATE;
+        mConnection = conn;
+        mWifiSoftAPManager = new WiFiSoftAPManager(mContext);
+    }
+
+    @Override
+    protected void startOnBoardingProcess() {
+        Log.i(TAG, "Starting on boarding process");
+
+        //1. Create Soft AP
+        boolean status = mWifiSoftAPManager.setWifiApEnabled((WifiConfiguration)
+                mOnBoardingConfig.getConfig(), true);
+
+        mState = EnrolleeState.DEVICE_ON_BOARDING_STATE;
+
+        Log.i(TAG, "Soft AP is created with status " + status);
+
+        myTimer = new Timer();
+        myTimer.schedule(new TimerTask() {
+            @Override
+            public void run() {
+                // Below function to be called after 5 seconds
+                mWifiSoftAPManager.getClientList(deviceScanListener, 300);
+            }
+
+        }, 0, 5000);
+    }
+
+    protected void stopOnBoardingProcess() {
+        Log.i(TAG, "Stopping on boarding process");
+        if(myTimer != null)
+        {
+            myTimer.cancel();
+        }
+        boolean status = mWifiSoftAPManager.setWifiApEnabled(null, false);
+        Log.i(TAG, "Soft AP is disabled with status " + status);
+    }
+
+    @Override
+    protected void startProvisioningProcess(OnBoardingConnection conn)  {
+
+        mState = EnrolleeState.DEVICE_PROVISIONING_STATE;
+        mProvisioningCallback.onProgress(this);
+        final EnrolleeDevice device = this;
+        if (mProvConfig.getConnType() == ProvisioningConfig.ConnType.WiFi) {
+             try {
+                 mRemoteEnrollee.registerProvisioningHandler(new IProvisionStatusNativeHandler() {
+                     @Override
+                     public void onStatusRecieved(int state) {
+                         device.mState = convertIntToProvisioningState(state);
+                         Log.i(TAG,"Device state changed :"+device.mState);
+                         mProvisioningCallback.onProgress(device);
+                         if(0==state) {
+                             mProvisioningCallback.onFinished(EnrolleeDeviceWiFiOnboarding.this);
+                         }
+                     }
+                 });
+                 //native call
+                mRemoteEnrollee.startProvision();
+             }catch(ESException e) {
+                 Log.i(TAG,"startProvisioningProcess Register Listener to native exception");
+             }
+        }
+    }
+
+    protected void stopProvisioningProcess(){
+        if(mState == EnrolleeState.DEVICE_PROVISIONING_STATE)
+        {    //native call
+            try {
+                mRemoteEnrollee.stopProvision();
+            } catch (ESException e) {
+                Log.i(TAG,"stopProvisioningProcess exception");
+            }
+        }else{
+           Log.i(TAG,"stopProvisioningProcess : Provisioning is not in progress");
+        }
+    }
+
+    private EnrolleeState convertIntToProvisioningState(int state){
+
+        switch(state)
+        {
+            case 0 :
+                return EnrolleeState.DEVICE_PROVISIONED_STATE;
+            case 1:
+                return EnrolleeState.DEVICE_NOT_PROVISIONED;
+            case 2:
+                return EnrolleeState.DEVICE_PROVISIONED_STATE;
+            case 3:
+                return EnrolleeState.DEVICE_NOT_PROVISIONED;
+        }
+        return EnrolleeState.DEVICE_INIT_STATE;
+    }
+}
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeSetupError.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeSetupError.java
new file mode 100644 (file)
index 0000000..036d24d
--- /dev/null
@@ -0,0 +1,37 @@
+/**
+ * ***************************************************************
+ * <p>
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p>
+ * <p>
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ * <p>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+/**
+ * This class defines constants for Errors comes during Easy setup process
+ */
+public enum EnrolleeSetupError {
+    /**
+     * Device setup successful
+     */
+    DEVICE_SETUP_SUCCESSFUL,
+    /**
+     * Device setup failed
+     */
+    DEVICE_SETUP_FAILED,
+}
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeState.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeState.java
new file mode 100644 (file)
index 0000000..91b8231
--- /dev/null
@@ -0,0 +1,88 @@
+/**
+ * ***************************************************************
+ * <p>
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p>
+ * <p>
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ * <p>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+/**
+ * It defines various states of the Enrollee device during easy setup process
+ */
+
+public enum EnrolleeState {
+
+    /**
+     * Default state of the device
+     */
+    DEVICE_INIT_STATE,
+
+    /**
+     * Device will move to this state after successful on-boarding of the device
+     */
+    DEVICE_ON_BOARDED_STATE,
+
+    /**
+     * Device will move to this state once the on boarding begins
+     */
+    DEVICE_ON_BOARDING_STATE,
+
+    /**
+     * Device will move to this state once the on boarding is done
+     */
+    DEVICE_PROVISIONING_STATE,
+
+    /**
+     * Easy setup process is successful.
+     */
+    DEVICE_PROVISIONED_STATE,
+
+    /**
+     * Easy setup process failed.
+     */
+    DEVICE_NOT_PROVISIONED,
+
+    /**
+     * This state is arbitrary one, any time device can come into this state
+     * Device will move to this state if the ownership transfer initiated  by the Application
+     */
+    DEVICE_OWNERSHIP_TRANSFERRING_STATE,
+
+    /**
+     * This state is arbitrary one, any time device can come into this state
+     * Device will move to this state if the ownership transfer is completed
+     */
+    DEVICE_OWNERSHIP_TRANSFERRED_STATE,
+
+    /**
+     * This state is arbitrary one, any time device can come into this state
+     * Device will move to this state if the ownership transfer is not completed
+     */
+    DEVICE_NOT_OWNED,
+
+    /**
+     * This state is arbitrary one, any time device can come into this state
+     * Device will move to this state once the Application factory reset the device
+     */
+    DEVICE_FACTORY_RESET_STATE,
+
+
+
+
+}
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/IProvisionStatusNativeHandler.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/IProvisionStatusNativeHandler.java
new file mode 100644 (file)
index 0000000..c66288f
--- /dev/null
@@ -0,0 +1,8 @@
+package org.iotivity.service.easysetup.mediator;
+
+
+public interface IProvisionStatusNativeHandler {
+
+    public void onStatusRecieved(int state);
+
+}
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/IpOnBoardingConnection.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/IpOnBoardingConnection.java
new file mode 100644 (file)
index 0000000..64599f8
--- /dev/null
@@ -0,0 +1,94 @@
+/**
+ * ***************************************************************
+ * <p/>
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p/>
+ * <p/>
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+public class IpOnBoardingConnection implements OnBoardingConnection {
+
+    private boolean mIsConnected;
+    private String mIp;
+    private String mHardwareAddress;
+    private String mDeviceName;
+
+    /**
+     * @mThrottlingDelay
+     * After creating the Soft AP at Mediator & on-boarding the-
+     * -Enrollee device on it provisioning needs to be delayed by at least 2000 ms for Android Mediator
+     */
+    private int mThrottlingDelay = 2000 ;
+
+    int getThrottlingDelay() {
+        return mThrottlingDelay;
+    }
+
+    IpOnBoardingConnection(boolean enrolleeOnboarded) {
+        mThrottlingDelay = 0;
+        mIp = "0.0.0.01";
+        mIsConnected = enrolleeOnboarded; // Always true for this constructor
+    }
+
+    IpOnBoardingConnection(){}
+
+    public void setHardwareAddress(String address) {
+        mHardwareAddress = address;
+    }
+
+    public String getHardwareAddress() {
+        return mHardwareAddress;
+    }
+
+    public void setDeviceName(String name) {
+        mDeviceName = name;
+    }
+
+    public String getDeviceName() {
+        return mDeviceName;
+    }
+
+    public void setConnectivity(boolean connected) {
+        mIsConnected = connected;
+    }
+
+    public void setIp(String ip) {
+        mIp = ip;
+    }
+
+    public String getIp() {
+        return mIp;
+    }
+
+    @Override
+    public String getDesc() {
+        return "Description";
+    }
+
+    @Override
+    public boolean isConnected() {
+        return mIsConnected;
+    }
+
+    @Override
+    public Object getConnection() {
+        return this;
+    }
+
+}
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/OnBoardingCallback.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/OnBoardingCallback.java
new file mode 100644 (file)
index 0000000..08c75f9
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * ***************************************************************
+ * <p/>
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p/>
+ * <p/>
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+public abstract class OnBoardingCallback {
+    public abstract void onFinished(OnBoardingConnection connection);
+}
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/OnBoardingConfig.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/OnBoardingConfig.java
new file mode 100644 (file)
index 0000000..db62640
--- /dev/null
@@ -0,0 +1,73 @@
+/**
+ * ***************************************************************
+ * <p/>
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p/>
+ * <p/>
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+import android.util.Log;
+
+import org.iotivity.base.OcConnectivityType;
+
+/**
+ * It contains configuration details about the connectivity type between the Enrollee device &
+ * Mediator device in order to perform on-boarding.
+ */
+
+public interface OnBoardingConfig {
+    /**
+     * It provides constants for connectivity types used for on-boarding Enrollee device
+     */
+    public static enum ConnType {
+        // Note : Enum Ids should matched with Native Ids
+        WiFi(OcConnectivityType.CT_ADAPTER_IP.getValue()),
+        BLE(OcConnectivityType.CT_ADAPTER_GATT_BTLE.getValue());
+
+        private int mConnType;
+
+        ConnType(int connType) {
+            mConnType = connType;
+        }
+
+        public int getValue() {
+            return mConnType;
+        }
+
+    }
+
+    /**
+     * Gives configuration object specific to the on-boarding connectivity of the enrolling device.
+     *
+     * @return instance object of configuration according to connectivity type
+     */
+    public Object getConfig();
+
+    /**
+     * Gives connectivity type of on-boarding device
+     *
+     * @return on-boarding connectivity type
+     */
+    public ConnType getConnType();
+
+    public boolean isSecured();
+
+    public void setSecured(boolean isSecured);
+
+}
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/OnBoardingConnection.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/OnBoardingConnection.java
new file mode 100644 (file)
index 0000000..3267536
--- /dev/null
@@ -0,0 +1,50 @@
+/**
+ * ***************************************************************
+ * <p/>
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p/>
+ * <p/>
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ * ****************************************************************
+ */
+package org.iotivity.service.easysetup.mediator;
+
+/**
+ * This interface contains the connection details of the enrollee device
+ */
+public interface OnBoardingConnection {
+
+    /**
+     * This method returns the implementation of the Connection
+     *
+     * @return implementation
+     */
+    public Object getConnection();
+
+    /**
+     * This method returns description on the connectivity.
+     *
+     * @return description
+     */
+    public String getDesc();
+
+    /**
+     * This method is used to know if the device is connected or not
+     *
+     * @return True if connected or False
+     */
+    public boolean isConnected();
+
+}
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ProvisioningCallback.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ProvisioningCallback.java
new file mode 100644 (file)
index 0000000..569f6fe
--- /dev/null
@@ -0,0 +1,28 @@
+/**
+ * ***************************************************************
+ * <p>
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p>
+ * <p>
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ * <p>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+public abstract class ProvisioningCallback {
+    public abstract void onFinished(EnrolleeDevice enrolledevice);
+    public abstract void onProgress(EnrolleeDevice enrolledevice);
+}
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ProvisioningConfig.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ProvisioningConfig.java
new file mode 100644 (file)
index 0000000..a1b96c8
--- /dev/null
@@ -0,0 +1,73 @@
+/**
+ * ***************************************************************
+ * <p>
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p>
+ * <p>
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ * <p>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+import android.util.Log;
+
+import org.iotivity.base.OcConnectivityType;
+/**
+ * It contains configuration details about the the target network where Enrollee device is
+ * going to be enrolled.
+ */
+public interface ProvisioningConfig {
+
+    /**
+     * It provides constants for connectivity types of target network
+     */
+    public static enum ConnType {
+        // Note : Enum Ids should matched with Native Ids
+        WiFi(OcConnectivityType.CT_ADAPTER_IP.getValue()),
+        BLE(OcConnectivityType.CT_ADAPTER_GATT_BTLE.getValue());
+
+        private int mConnType;
+
+        ConnType(int connType) {
+            mConnType = connType;
+        }
+
+        public int getValue() {
+            return mConnType;
+        }
+    }
+
+    /**
+     * Gives the instance of the configuration object created according to the connectivity
+     * type of target network.
+     *
+     * @return instance object of configuration according to connectivity type of target network
+     */
+    Object getConfig();
+
+
+    /**
+     * Gives connectivity type of target network
+     *
+     * @return Connectivity type of target network
+     */
+    ConnType getConnType();
+
+    public boolean isSecured();
+
+    public void setSecured(boolean isSecured);
+
+}
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/RemoteEnrollee.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/RemoteEnrollee.java
new file mode 100644 (file)
index 0000000..5e80025
--- /dev/null
@@ -0,0 +1,61 @@
+/**
+ * ***************************************************************
+ * <p/>
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p/>
+ * <p/>
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ * ****************************************************************
+ */
+
+
+package org.iotivity.service.easysetup.mediator;
+
+import android.util.Log;
+
+public class RemoteEnrollee{
+
+    public static final String TAG = RemoteEnrollee.class.getName();
+    private long m_nativeHandle;
+
+    private native void nativeStartProvision();
+    private native void nativeStopProvision();
+    private native void nativeRegisterProvisioningHandler(IProvisionStatusNativeHandler listener);
+   //private IProvisionStatusNativeHandler provisioningListener;
+
+
+    /* constructor will be invoked from the native layer */
+    private RemoteEnrollee(long nativeHandle){
+        this.m_nativeHandle = nativeHandle;
+    }
+
+    /* Register native Listener for the Provisioning state */
+    public void registerProvisioningHandler( IProvisionStatusNativeHandler provisioningListener) throws ESException{
+       // this.provisioningListener = provisioningListener;
+        nativeRegisterProvisioningHandler(provisioningListener);
+        Log.i(TAG, "JNI Callback is registered for getting provisioning status");
+    }
+
+    /* native StartProvision */
+    public void startProvision() throws ESException{
+    nativeStartProvision();
+}
+
+    /* native stopProvision */
+    public void stopProvision() throws  ESException{
+    nativeStopProvision();
+}
+
+}
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/WiFiOnBoardingConfig.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/WiFiOnBoardingConfig.java
new file mode 100644 (file)
index 0000000..4369cf4
--- /dev/null
@@ -0,0 +1,75 @@
+/**
+ * ***************************************************************
+ * <p/>
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p/>
+ * <p/>
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+import org.iotivity.service.easysetup.mediator.OnBoardingConfig;
+
+import android.net.wifi.WifiConfiguration;
+
+/**
+ * This class contains on boarding configuration information for Soft AP on boarding connectivity.
+ * It implements OnBoardingConfig interface & provide implementation for WiFi Soft AP connectivity.
+ */
+
+public class WiFiOnBoardingConfig implements OnBoardingConfig {
+
+    private boolean isSecured;
+    private final WifiConfiguration config = new WifiConfiguration();
+    private final ConnType mConnType = OnBoardingConfig.ConnType.WiFi;
+
+    @Override
+    public Object getConfig() {
+        return config;
+    }
+
+    public void setSSId(String ssid) {
+        config.SSID = ssid;
+    }
+
+    public void setSharedKey(String sharedKey) {
+        config.preSharedKey = sharedKey;
+    }
+
+    public void setAuthAlgo(int aurthAlgo) {
+        config.allowedAuthAlgorithms.set(aurthAlgo);
+    }
+
+    public void setKms(int kms) {
+        config.allowedKeyManagement.set(kms);
+    }
+
+    @Override
+    public ConnType getConnType() {
+        return mConnType;
+    }
+
+    @Override
+    public boolean isSecured(){
+        return isSecured;
+    }
+
+    @Override
+    public void setSecured(boolean flag) {
+        isSecured = flag;
+    }
+}
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/WiFiProvConfig.java b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/WiFiProvConfig.java
new file mode 100644 (file)
index 0000000..1087f6e
--- /dev/null
@@ -0,0 +1,79 @@
+/**
+ * ***************************************************************
+ * <p>
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p>
+ * <p>
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ * <p>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+import org.iotivity.service.easysetup.mediator.ProvisioningConfig;
+
+/**
+ * This class contains on provisioning configuration information for for target network.
+ * It implements ProvisioningConfig interface and provide configuration object specific to WiFi target network
+ */
+public class WiFiProvConfig implements ProvisioningConfig {
+
+    private final ConnType mConnType = ProvisioningConfig.ConnType.WiFi;
+    private boolean isSecured;
+
+    private final String mSsId;
+    private final String mPassword;
+
+    public WiFiProvConfig(String ssid, String pass) {
+        mSsId = ssid;
+        mPassword = pass;
+    }
+
+    @Override
+    public Object getConfig() {
+        return this;
+    }
+
+    @Override
+    public ConnType getConnType() {
+        return mConnType;
+    }
+
+    /**
+     * This method returns the SSID of the Target WIFI network
+     * @return SSID of Target Network
+     */
+    public String getSsId() {
+        return mSsId;
+    }
+
+    /**
+     * This method returns the password of the Target WIFI network
+     * @return password of Target Network
+     */
+    public String getPassword() {
+        return mPassword;
+    }
+
+    @Override
+    public boolean isSecured(){
+        return isSecured;
+    }
+
+    @Override
+    public void setSecured(boolean flag) {
+        isSecured = flag;
+    }
+}
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/main.iml b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/main.iml
new file mode 100644 (file)
index 0000000..80242f3
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+  <component name="FacetManager">
+    <facet type="android" name="Android">
+      <configuration />
+    </facet>
+  </component>
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
+    </content>
+    <orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="library" name="classes1" level="project" />
+  </component>
+</module>
\ No newline at end of file
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/res/drawable-hdpi/ic_launcher.png b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..288b665
Binary files /dev/null and b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/res/values/strings.xml b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/res/values/strings.xml
new file mode 100644 (file)
index 0000000..830c7cd
--- /dev/null
@@ -0,0 +1,5 @@
+<resources>
+
+    <string name="app_name">EasySetupCore</string>
+
+</resources>
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/res/values/styles.xml b/service/easy-setup/sdk/mediator/android/richsdk/EasySetupCore/src/main/res/values/styles.xml
new file mode 100644 (file)
index 0000000..6ce89c7
--- /dev/null
@@ -0,0 +1,20 @@
+<resources>
+
+    <!--
+        Base application theme, dependent on API level. This theme is replaced
+        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Light">
+        <!--
+            Theme customizations available in newer API levels can go in
+            res/values-vXX/styles.xml, while customizations related to
+            backward-compatibility can go here.
+        -->
+    </style>
+
+    <!-- Application theme. -->
+    <style name="AppTheme" parent="AppBaseTheme">
+        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
+    </style>
+
+</resources>
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/jni/Android.mk b/service/easy-setup/sdk/mediator/android/richsdk/jni/Android.mk
new file mode 100644 (file)
index 0000000..3e6dae4
--- /dev/null
@@ -0,0 +1,66 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+OIC_LIB_PATH := ../../../../../../../out/android/$(TARGET_ARCH_ABI)/debug
+LOCAL_MODULE := android-octbstack
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/liboctbstack.so
+include $(PREBUILT_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+OIC_LIB_PATH := ../../../../../../../out/android/$(TARGET_ARCH_ABI)/debug
+LOCAL_MODULE := android-connectivity_abstraction
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/libconnectivity_abstraction.so
+include $(PREBUILT_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+OIC_LIB_PATH := ../../../../../../../out/android/$(TARGET_ARCH_ABI)/debug
+LOCAL_MODULE := android-easysetup
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/libESSDKLibrary.so
+include $(PREBUILT_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE    := easysetup-jni
+
+#Add Pre processor definitions
+DEFINE_FLAG =  -DWITH_POSIX -D__ANDROID__
+
+#Add Debug flags here
+DEBUG_FLAG      = -DTB_LOG
+
+BUILD_FLAG = $(DEFINE_FLAG) $(DEBUG_FLAG)
+
+LOCAL_CPPFLAGS = $(BUILD_FLAG)
+LOCAL_CPPFLAGS += -std=c++0x -frtti -fexceptions
+
+$(info CPPFLAGSUPDATED=$(LOCAL_CPPFLAGS))
+
+LOCAL_C_INCLUDES := $(LOCAL_PATH) \
+                                       $(LOCAL_PATH)/../../../../../../../service/easy-setup/sdk/mediator/include \
+                                       $(LOCAL_PATH)/../../../../../../../service/easy-setup/sdk/mediator/src \
+                                       $(LOCAL_PATH)/../../../../../../../service/easy-setup/sdk/common \
+                                       $(LOCAL_PATH)/../../../../../../../resource/csdk/logger/include \
+                                   $(LOCAL_PATH)/../../../../../../../resource/csdk/connectivity/common/inc \
+                                       $(LOCAL_PATH)/../../../../../../../resource/c_common/oic_string/include \
+                                       $(LOCAL_PATH)/../../../../../../../resource/include \
+                                       $(LOCAL_PATH)/../../../../../../../resource/c_common \
+                                       $(LOCAL_PATH)/../../../../../../../resource/oc_logger/include \
+                                       $(LOCAL_PATH)/../../../../../../../resource/csdk/ocmalloc/include \
+                                       $(LOCAL_PATH)/../../../../../../../resource/csdk/connectivity/api \
+                                       $(LOCAL_PATH)/../../../../../../../resource/csdk/stack/include \
+                                       $(LOCAL_PATH)/../../../../../../../resource/csdk/logger/include \
+                                       $(LOCAL_PATH)/../../../../../../../resource/csdk/security/include \
+                                       $(LOCAL_PATH)/../../../../../../../extlibs/cjson \
+                                       $(LOCAL_PATH)/../../../../../../../extlibs/boost/boost_1_58_0 \
+                    $(LOCAL_PATH)/../../../../../../../extlibs/timer \
+                                       $(LOCAL_PATH)/../../../../../../../android/android_api/base/jni \
+
+LOCAL_SRC_FILES += $(patsubst $(LOCAL_PATH)/%, %, $(wildcard $(LOCAL_PATH)/*.cpp))
+LOCAL_SRC_FILES += $(patsubst $(LOCAL_PATH)/%, %, $(wildcard $(LOCAL_PATH)/*.h))
+
+LOCAL_LDLIBS := -llog
+LOCAL_SHARED_LIBRARIES += android-connectivity_abstraction
+LOCAL_SHARED_LIBRARIES += android-octbstack
+LOCAL_SHARED_LIBRARIES += android-easysetup
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/jni/Application.mk b/service/easy-setup/sdk/mediator/android/richsdk/jni/Application.mk
new file mode 100644 (file)
index 0000000..d5fc03c
--- /dev/null
@@ -0,0 +1,4 @@
+APP_STL               := gnustl_shared
+APP_PLATFORM = android-21
+NDK_TOOLCHAIN_VERSION := 4.8
+
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/jni/JniEasySetup.cpp b/service/easy-setup/sdk/mediator/android/richsdk/jni/JniEasySetup.cpp
new file mode 100644 (file)
index 0000000..972b6da
--- /dev/null
@@ -0,0 +1,85 @@
+/******************************************************************
+ *
+ * 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 "JniEasySetup.h"
+
+using namespace OIC::Service;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+JNIEXPORT jobject JNICALL
+Java_org_iotivity_service_easysetup_mediator_EasySetupService_nativeCreateEnrolleeDevice
+(JNIEnv *env, jobject interfaceClass, jstring ip, jstring ssid, jstring password,
+ jint connectivityType, jboolean needSecuredEasysetup)
+{
+
+    LOGI("JniEasySetup::nativeCreateEnrolleeDevice enter");
+
+    std::shared_ptr<RemoteEnrollee> nativeRemoteEnrollee;
+    jobject jRemoteEnrollee;
+    EnrolleeNWProvInfo netInfo;
+
+    const char *cIp = (env)->GetStringUTFChars(ip, NULL);
+    const char *cSssid = (env)->GetStringUTFChars(ssid, NULL);
+    const char *cPassword = (env)->GetStringUTFChars(password, NULL);
+
+    std::string sIp(cIp);
+    std::string sSssid(cSssid);
+    std::string sPassword(cPassword);
+
+    netInfo.connType = getOCConnectivityTypeFromInt(connectivityType);
+    netInfo.isSecured = bool(
+                            needSecuredEasysetup);       // may be need to remove, if removed from c++ layer
+    netInfo.needSecuredEasysetup =  bool(needSecuredEasysetup);
+
+    OICStrcpy(netInfo.netAddressInfo.WIFI.ipAddress, IPV4_ADDR_SIZE - 1, sIp.c_str());
+    OICStrcpy(netInfo.netAddressInfo.WIFI.ssid, NET_WIFI_SSID_SIZE - 1, sSssid.c_str());
+    OICStrcpy(netInfo.netAddressInfo.WIFI.pwd, NET_WIFI_PWD_SIZE - 1, sPassword.c_str());
+
+    try
+    {
+        nativeRemoteEnrollee = EasySetup::getInstance()->createEnrolleeDevice(netInfo);
+        //create the java object
+        jRemoteEnrollee = env->NewObject(g_cls_RemoteEnrollee, g_mid_RemoteEnrollee_ctor);
+        if (!jRemoteEnrollee)
+        {
+            LOGE("JniEasySetup::nativeCreateEnrolleeDevice Unable to create the java object");
+            return NULL;
+        }
+
+        JniRemoteEnrollee *jniRemoteEnrollee = new JniRemoteEnrollee(nativeRemoteEnrollee);
+        ESSetHandle<JniRemoteEnrollee>(env, jRemoteEnrollee, jniRemoteEnrollee);
+    }
+    catch (ESBadRequestException exception)
+    {
+        LOGE("JniEasySetup::nativeCreateEnrolleeDevice Unable to create the Native EnrolleeDevice");
+        //throw the exception to java layer
+        throwESException( env,  exception.what());
+    }
+
+    LOGI("JniEasySetup::nativeCreateEnrolleeDevice exit");
+
+    return jRemoteEnrollee;
+}
+#ifdef __cplusplus
+}
+#endif
+
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/jni/JniEasySetup.h b/service/easy-setup/sdk/mediator/android/richsdk/jni/JniEasySetup.h
new file mode 100644 (file)
index 0000000..177c612
--- /dev/null
@@ -0,0 +1,66 @@
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+/** @file   JniEasySetup.h
+ *
+ *   @brief  This file contains native API for creating RemoteEnrollee Device
+ */
+
+#ifndef __JNI_ES_EASYSETUP_H
+#define __JNI_ES_EASYSETUP_H
+
+#include <jni.h>
+
+#include "EasySetup.h"
+#include "RemoteEnrollee.h"
+#include "ESException.h"
+#include "oic_string.h"
+
+#include "JniJvm.h"
+#include "JniEasySetup.h"
+#include "JniRemoteEnrollee.h"
+#include "JniEsUtils.h"
+
+using namespace OIC::Service;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * API for creating and returning the RemoteEnrollee object to Java Layer
+ *
+ * @param ip - ip address of Enrollee
+ * @param ssid - ssid of the Enroller
+ * @param password - password of the enroller
+ * @param connectivityType - Connectivity Type
+ * @param needSecuredEasysetup - need secured easy setup or not
+ *
+ * @return jobject - RemoteEnrolleee
+ */
+JNIEXPORT jobject JNICALL
+Java_org_iotivity_service_easysetup_mediator_EasySetupService_nativeCreateEnrolleeDevice
+(JNIEnv *env, jobject interfaceClass, jstring ip, jstring ssid, jstring password,
+ jint connectivityType, jboolean needSecuredEasysetup);
+
+#ifdef __cplusplus
+}
+#endif
+#endif // __JNI_ES_EASYSETUP_H
\ No newline at end of file
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/jni/JniEsListenerManager.h b/service/easy-setup/sdk/mediator/android/richsdk/jni/JniEsListenerManager.h
new file mode 100644 (file)
index 0000000..105ef3d
--- /dev/null
@@ -0,0 +1,145 @@
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+/** @file   JniEsLisenerManager.h
+ *
+ *   @brief  This file contains JNI Listener Manager class for JniRemoteEnrollee
+ */
+
+#ifndef __JNI_ES_LISTENER_MANAGER_H_
+#define __JNI_ES_LISTENER_MANAGER_H_
+
+#include <mutex>
+#include <map>
+
+class JniRemoteEnrollee;
+
+/**
+ * @class   JniEsListenerManager
+ * @brief   This class provides functions for managing listeners
+ *
+ */
+template <class T>
+class JniEsListenerManager
+{
+    public:
+        /**
+         * API for Adding the Listener to listener Map.
+         *
+         * @param owner - JniRemoteEnrollee
+         */
+        T *addListener(JNIEnv *env, jobject jListener, JniRemoteEnrollee *owner)
+        {
+            T *onEventListener = NULL;
+
+            m_mapMutex.lock();
+
+            for (auto it = m_listenerMap.begin(); it != m_listenerMap.end(); ++it)
+            {
+                if (env->IsSameObject(jListener, it->first))
+                {
+                    auto refPair = it->second;
+                    onEventListener = refPair.first;
+                    refPair.second++;
+                    it->second = refPair;
+                    m_listenerMap.insert(*it);
+                    LOGD("OnEventListener: ref. count is incremented");
+                    break;
+                }
+            }
+            if (!onEventListener)
+            {
+                onEventListener = new T(env, jListener, owner);
+                jobject jgListener = env->NewGlobalRef(jListener);
+
+                if (jgListener)
+                {
+                    m_listenerMap.insert(
+                        std::pair < jobject,
+                        std::pair<T *, int >> (jgListener, std::pair<T *, int>(onEventListener, 1)));
+                }
+                else
+                {
+                    LOGD("OnEventListener: Failed to create global listener ref.");
+                    delete onEventListener;
+                }
+                LOGD("OnEventListener: new listener");
+            }
+            m_mapMutex.unlock();
+            return onEventListener;
+        }
+
+        /**
+         * @brief API for removing the Listener from listener Map.
+         */
+        void removeListener(JNIEnv *env, jobject jListener)
+        {
+            m_mapMutex.lock();
+            for (auto it = m_listenerMap.begin(); it != m_listenerMap.end(); ++it)
+            {
+                if (env->IsSameObject(jListener, it->first))
+                {
+                    auto refPair = it->second;
+                    if (refPair.second > 1)
+                    {
+                        refPair.second--;
+                        it->second = refPair;
+                        m_listenerMap.insert(*it);
+                        LOGI("OnEventListener: ref. count is decremented");
+                    }
+                    else
+                    {
+                        env->DeleteGlobalRef(it->first);
+                        T *listener = refPair.first;
+                        delete listener;
+                        m_listenerMap.erase(it);
+
+                        LOGI("OnEventListener is removed");
+                    }
+                    break;
+                }
+            }
+            m_mapMutex.unlock();
+        }
+
+        /**
+         * @brief API for removing all the Listener from listener Map.
+         */
+        void removeAllListeners(JNIEnv *env)
+        {
+            m_mapMutex.lock();
+
+            for (auto &pair : m_listenerMap)
+            {
+                env->DeleteGlobalRef(pair.first);
+                auto refPair = pair.second;
+                delete refPair.first;
+            }
+            m_listenerMap.clear();
+
+            m_mapMutex.unlock();
+        }
+
+    private:
+        std::map<jobject, std::pair<T *, int>> m_listenerMap;
+        std::mutex m_mapMutex;
+};
+
+#endif //__JNI_ES_LISTENER_MANAGER_H_
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/jni/JniEsUtils.cpp b/service/easy-setup/sdk/mediator/android/richsdk/jni/JniEsUtils.cpp
new file mode 100644 (file)
index 0000000..3334f04
--- /dev/null
@@ -0,0 +1,62 @@
+/******************************************************************
+ *
+ * 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 "JniEsUtils.h"
+
+void throwESException(JNIEnv *env, std::string reason)
+{
+    jobject ex = env->NewObject(g_cls_ESException, g_mid_ESException_ctor,
+                                env->NewStringUTF(reason.c_str()));
+    if (!ex)
+    {
+        LOGI("throwException : jobject is NULL");
+    }
+    env->Throw((jthrowable)ex);
+}
+
+OCConnectivityType  getOCConnectivityTypeFromInt(int connectivityType)
+{
+    switch (connectivityType)
+    {
+        case CT_DEFAULT:
+            return CT_DEFAULT;
+        case CT_ADAPTER_IP:
+            return CT_ADAPTER_IP;
+
+            //May be need to add more types, if easy setup service support more transport.
+    }
+    return CT_DEFAULT;
+}
+
+int convertNativeProvisionStateToInt(EasySetupState nativeState)
+{
+    switch (nativeState)
+    {
+        case EasySetupState::DEVICE_PROVISIONED:
+            return 0;
+        case EasySetupState::DEVICE_NOT_PROVISIONED:
+            return 1;
+        case EasySetupState::DEVICE_OWNED:
+            return 2;
+        case EasySetupState::DEVICE_NOT_OWNED:
+            return 3;
+    }
+    return -1;
+}
\ No newline at end of file
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/jni/JniEsUtils.h b/service/easy-setup/sdk/mediator/android/richsdk/jni/JniEsUtils.h
new file mode 100644 (file)
index 0000000..f9d6388
--- /dev/null
@@ -0,0 +1,53 @@
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+/**
+  * @file   JniESUtils.h
+  *
+  * @brief  This file contains the utility functions for JNI layer
+  */
+
+#ifndef __JNI_ES_UTILS_H_
+#define __JNI_ES_UTILS_H_
+
+#include <jni.h>
+#include <string>
+
+#include "escommon.h"
+#include "octypes.h"
+
+#include "JniJvm.h"
+
+/**
+ * @brief Throw the Exception to the java layer
+ */
+void throwESException(JNIEnv *env, std::string reason);
+
+/**
+* @brief Convert integer to OCconnectivity Enum
+*/
+OCConnectivityType  getOCConnectivityTypeFromInt(int connectivityType);
+
+/**
+* @brief Convert EasySetupState Enum Value to int
+*/
+int convertNativeProvisionStateToInt(EasySetupState nativeState);
+
+#endif //__JNI_ES_UTILS_H_
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/jni/JniJvm.cpp b/service/easy-setup/sdk/mediator/android/richsdk/jni/JniJvm.cpp
new file mode 100644 (file)
index 0000000..00adaeb
--- /dev/null
@@ -0,0 +1,80 @@
+/******************************************************************
+ *
+ * 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 "JniJvm.h"
+
+JavaVM *g_jvm = NULL;
+
+jclass g_cls_RemoteEnrollee = NULL;
+jclass g_cls_ESException = NULL;
+
+jmethodID g_mid_RemoteEnrollee_ctor = NULL;
+jmethodID g_mid_ESException_ctor = NULL;
+
+// JNI OnLoad
+JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
+{
+    LOGI("JNI_OnLoad");
+    JNIEnv *env;
+    g_jvm = vm;
+
+    if (g_jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK)
+    {
+        LOGE("Failed to get the environment using GetEnv()");
+        return JNI_ERR;
+    }
+
+    jclass clazz = nullptr;
+
+    //Remote Enrollee
+    clazz = env->FindClass("org/iotivity/service/easysetup/mediator/RemoteEnrollee");
+    if (!clazz) return JNI_ERR;
+    g_cls_RemoteEnrollee = (jclass)env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+
+    g_mid_RemoteEnrollee_ctor = env->GetMethodID(g_cls_RemoteEnrollee, "<init>",
+                                "(J)V");
+    if (!g_mid_RemoteEnrollee_ctor) return JNI_ERR;
+
+    //ESException
+    clazz = env->FindClass("org/iotivity/service/easysetup/mediator/ESException");
+    if (!clazz) return JNI_ERR;
+    g_cls_ESException = (jclass)env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+
+    g_mid_ESException_ctor = env->GetMethodID(g_cls_ESException, "<init>", "(Ljava/lang/String;)V");
+    if (!g_mid_ESException_ctor) return JNI_ERR;
+
+    return JNI_CURRENT_VERSION;
+}
+
+//JNI OnUnload
+JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
+{
+    LOGI("JNI_OnUnload");
+    JNIEnv *env;
+
+    if (g_jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK)
+    {
+        LOGE("Failed to get the environment using GetEnv()");
+        return;
+    }
+    env->DeleteGlobalRef(g_cls_RemoteEnrollee);
+    env->DeleteGlobalRef(g_cls_ESException);
+}
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/jni/JniJvm.h b/service/easy-setup/sdk/mediator/android/richsdk/jni/JniJvm.h
new file mode 100644 (file)
index 0000000..8bd160e
--- /dev/null
@@ -0,0 +1,112 @@
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+/**
+  * @file   JniJvm.h
+  *
+  * @brief  This file contains the essential declarations and functions required
+  *            for JNI implementation
+  */
+
+#ifndef __JNI_ES_JVM_H
+#define __JNI_ES_JVM_H
+
+#include <jni.h>
+#include<string>
+#include <android/log.h>
+
+#define ESTAG "ES-JNI"
+#define JNI_CURRENT_VERSION JNI_VERSION_1_6
+
+#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, ESTAG, __VA_ARGS__)
+#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, ESTAG, __VA_ARGS__)
+#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, ESTAG, __VA_ARGS__)
+
+extern JavaVM *g_jvm;
+
+extern jclass g_cls_RemoteEnrollee;
+extern jclass g_cls_ESException;
+
+extern jmethodID g_mid_RemoteEnrollee_ctor ;
+extern jmethodID g_mid_ESException_ctor;
+
+typedef void(*RemoveListenerCallback)(JNIEnv *env, jobject jListener);
+
+/**
+ * @brief Get the native handle field
+ */
+static jfieldID ESGetHandleField(JNIEnv *env, jobject jobj)
+{
+    jclass cls = env->GetObjectClass(jobj);
+    return env->GetFieldID(cls, "m_nativeHandle", "J");
+}
+
+/**
+ * @brief Get the native handle
+ */
+template <typename T>
+static T *ESGetHandle(JNIEnv *env, jobject jobj)
+{
+    jlong handle = env->GetLongField(jobj, ESGetHandleField(env, jobj));
+    return reinterpret_cast<T *>(handle);
+}
+
+/**
+ * @brief Set the native handle
+ */
+template <typename T>
+static void ESSetHandle(JNIEnv *env, jobject jobj, T *type)
+{
+    jlong handle = reinterpret_cast<jlong>(type);
+
+    env->SetLongField(jobj, ESGetHandleField(env, jobj), handle);
+}
+
+/**
+ * @brief Get the JNI Environment
+ */
+static JNIEnv *GetESJNIEnv(jint &ret)
+{
+    JNIEnv *env = NULL;
+
+    ret = g_jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION);
+    switch (ret)
+    {
+        case JNI_OK:
+            return env;
+        case JNI_EDETACHED:
+            if (g_jvm->AttachCurrentThread(&env, NULL) < 0)
+            {
+                LOGE("Failed to get the environment");
+                return nullptr;
+            }
+            else
+            {
+                return env;
+            }
+
+        case JNI_EVERSION:
+            LOGE("JNI version not supported");
+        default:
+            LOGE("Failed to get the environment");
+            return nullptr;
+    }
+}
+#endif // __JNI_ES_JVM_H
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/jni/JniProvisioningStatusLisener.cpp b/service/easy-setup/sdk/mediator/android/richsdk/jni/JniProvisioningStatusLisener.cpp
new file mode 100644 (file)
index 0000000..f44e97d
--- /dev/null
@@ -0,0 +1,107 @@
+/******************************************************************
+ *
+ * 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 "JniProvisioningStatusListener.h"
+#include "JniRemoteEnrollee.h"
+
+using namespace OIC::Service;
+
+JniProvisioningStatusListener::JniProvisioningStatusListener(JNIEnv *env, jobject jListener,
+        JniRemoteEnrollee *owner)
+    : m_ownerResource(owner)
+{
+    m_jwListener = env->NewWeakGlobalRef(jListener);
+}
+
+JniProvisioningStatusListener::~JniProvisioningStatusListener()
+{
+    LOGI("~JniProvisioningStatusListener()");
+    if (m_jwListener)
+    {
+        jint ret;
+        JNIEnv *env = GetESJNIEnv(ret);
+        if (NULL == env) return;
+        env->DeleteWeakGlobalRef(m_jwListener);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+    }
+}
+
+void JniProvisioningStatusListener::provisionStatusCallback (std::shared_ptr<EasySetupStatus>
+        easySetupStatus)
+{
+
+    LOGI("JniProvisioningStatusListener::provisioiningStatusCallback enter");
+
+    jint ret;
+    JNIEnv *env = GetESJNIEnv(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;
+    }
+
+    jmethodID midL = env->GetMethodID(clsL, "onStatusRecieved",
+                                      "(I)V");
+    if (!midL)
+    {
+        checkExAndRemoveListener(env);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        return;
+    }
+
+    EasySetupState nativeProvisioningState = easySetupStatus->getEasySetupState();
+    int provisionState = convertNativeProvisionStateToInt(nativeProvisioningState);
+    env->CallVoidMethod(jListener, midL, provisionState);
+    if (env->ExceptionCheck())
+    {
+        LOGE("Java exception is thrown");
+        checkExAndRemoveListener(env);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        return;
+    }
+
+    if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+}
+
+void JniProvisioningStatusListener::checkExAndRemoveListener(JNIEnv *env)
+{
+    if (env->ExceptionCheck())
+    {
+        jthrowable ex = env->ExceptionOccurred();
+        env->ExceptionClear();
+        m_ownerResource->removeProvisioningStatusListener(env, m_jwListener);
+        env->Throw((jthrowable)ex);
+    }
+    else
+    {
+        m_ownerResource->removeProvisioningStatusListener(env, m_jwListener);
+    }
+}
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/jni/JniProvisioningStatusListener.h b/service/easy-setup/sdk/mediator/android/richsdk/jni/JniProvisioningStatusListener.h
new file mode 100644 (file)
index 0000000..bba3baf
--- /dev/null
@@ -0,0 +1,68 @@
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+/** @file   JniProvisioningStatusListener.h
+ *
+ *   @brief  This file contains JNI Provisioing status Listener class
+ */
+
+#ifndef __JNI_ES_PROVISIONING_STATUS_LISTENER_H_
+#define __JNI_ES_PROVISIONING_STATUS_LISTENER_H_
+
+#include <jni.h>
+
+#include "RemoteEnrollee.h"
+#include "escommon.h"
+
+#include "JniJvm.h"
+
+class JniRemoteEnrollee;
+
+using namespace OIC::Service;
+
+/**
+ * @class   JniProvisioningStatusListener
+ * @brief   This class provides functions for handling the provisioning status callback between the Java and native layer
+ *
+ */
+class JniProvisioningStatusListener
+{
+    public:
+        /**
+         * @brief constructor
+         */
+        JniProvisioningStatusListener(JNIEnv *env, jobject jListener, JniRemoteEnrollee *resource);
+
+        /**
+         * @brief destructor
+        */
+        ~JniProvisioningStatusListener();
+
+        /**
+         * @brief callback function that will be passed to Native layer
+        */
+        void provisionStatusCallback (std::shared_ptr<EasySetupStatus> easySetupStatus);
+
+    private:
+        jweak m_jwListener;
+        JniRemoteEnrollee *m_ownerResource;
+        void checkExAndRemoveListener(JNIEnv *env);
+};
+
+#endif //__JNI_ES_PROVISIONING_STATUS_LISTENER_H_
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/jni/JniRemoteEnrollee.cpp b/service/easy-setup/sdk/mediator/android/richsdk/jni/JniRemoteEnrollee.cpp
new file mode 100644 (file)
index 0000000..9003a65
--- /dev/null
@@ -0,0 +1,159 @@
+/******************************************************************
+ *
+ * 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 "JniRemoteEnrollee.h"
+
+using namespace OIC::Service;
+
+JniRemoteEnrollee::JniRemoteEnrollee(std::shared_ptr<RemoteEnrollee> remoteEnrollee)
+    : m_sharedResource(remoteEnrollee) {}
+
+JniRemoteEnrollee::~JniRemoteEnrollee()
+{
+    LOGD("JniRemoteEnrollee::~JniRemoteEnrollee()");
+    m_sharedResource = NULL;
+
+    jint envRet;
+    JNIEnv *env = GetESJNIEnv(envRet);
+    if (NULL == env) return;
+
+    if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+
+}
+
+JniRemoteEnrollee *JniRemoteEnrollee::getJniRemoteEnrollee(JNIEnv *env, jobject thiz)
+{
+    JniRemoteEnrollee *remoteEnrollee = ESGetHandle<JniRemoteEnrollee>(env, thiz);
+    if (env->ExceptionCheck())
+    {
+        LOGE("getJniRemoteEnrollee :: Failed to get native handle from RemoteEnrollee object");
+    }
+    if (!remoteEnrollee)
+    {
+        LOGE("getJniRemoteEnrollee :: no resource");
+    }
+    return remoteEnrollee;
+}
+
+void JniRemoteEnrollee::startProvisioning(JNIEnv *env)
+{
+    try
+    {
+        m_sharedResource->startProvisioning();
+    }
+    catch (ESBadRequestException exception)
+    {
+        LOGE("JNI startProvisioning :: Exception occured");
+        //throw the exception to java
+        throwESException( env,  exception.what());
+    }
+}
+void JniRemoteEnrollee::stopProvisioning(JNIEnv *env)
+{
+    try
+    {
+        m_sharedResource->stopProvisioning();
+    }
+    catch (ESBadRequestException exception)
+    {
+        LOGE("JNI stopProvisioning :: Exception occured");
+        //throw the exception to java
+        throwESException( env,  exception.what());
+    }
+}
+
+void JniRemoteEnrollee::registerProvisioningHandler(JNIEnv *env, jobject jListener)
+{
+    JniProvisioningStatusListener *onProvisioningStatusReceived = addProvisioningStatusListener(env,
+            jListener);
+
+    RemoteEnrollee::EasySetupStatusCB provisionStatusCallback = [onProvisioningStatusReceived]
+            (std::shared_ptr< OIC::Service::EasySetupStatus > easySetupStatus)
+
+    {
+        onProvisioningStatusReceived->provisionStatusCallback(easySetupStatus);
+    };
+
+    try
+    {
+        m_sharedResource->registerEasySetupStatusHandler(provisionStatusCallback);
+    }
+    catch (ESException exception)
+    {
+        LOGE("JNI stopProvisioning :: Exception occured");
+        //throw the exception to java
+        throwESException( env,  exception.what());
+    }
+
+}
+
+JniProvisioningStatusListener *JniRemoteEnrollee::addProvisioningStatusListener(JNIEnv *env,
+        jobject jListener)
+{
+    return this->m_provisioingStatus.addListener(env, jListener, this);
+}
+
+void JniRemoteEnrollee::removeProvisioningStatusListener(JNIEnv *env, jobject jListener)
+{
+    this->m_provisioingStatus.removeListener(env, jListener);
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStartProvision
+(JNIEnv *env, jobject jClass)
+{
+    LOGD("nativeStartProvision Enter");
+
+    JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
+    remoteEnrollee->startProvisioning(env);
+
+    LOGD("nativeStartProvision Exit");
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStopProvision
+(JNIEnv *env, jobject jClass)
+{
+
+    LOGD("nativeStopProvision Enter");
+
+    JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
+    remoteEnrollee->stopProvisioning(env);
+
+    LOGD("nativeStopProvision Exit");
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeRegisterProvisioningHandler
+(JNIEnv *env, jobject jClass, jobject provisiongListener)
+{
+    LOGD("nativeRegisterProvisioningHandler Enter");
+
+    if (!provisiongListener)
+    {
+        LOGE("nativeRegisterProvisioningHandler : listener is NULL");
+        return;
+    }
+    JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
+    remoteEnrollee->registerProvisioningHandler(env, provisiongListener);
+
+    LOGD("nativeRegisterProvisioningHandler Exit");
+}
+
diff --git a/service/easy-setup/sdk/mediator/android/richsdk/jni/JniRemoteEnrollee.h b/service/easy-setup/sdk/mediator/android/richsdk/jni/JniRemoteEnrollee.h
new file mode 100644 (file)
index 0000000..9681771
--- /dev/null
@@ -0,0 +1,109 @@
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+/** @file   JniRemoteEnrollee.h
+ *
+ *   @brief  This file contains the JniRemoteEnrollee class
+ *               & declaration of RemoteEnrollee APIs for JNI implementation
+ */
+
+#ifndef __JNI_ES_REMOTEENROLLEE_H
+#define __JNI_ES_REMOTEENROLLEE_H
+
+#include "RemoteEnrollee.h"
+#include "escommon.h"
+#include "ESException.h"
+
+#include "JniJvm.h"
+#include "JniEsUtils.h"
+#include "JniProvisioningStatusListener.h"
+#include "JniEsListenerManager.h"
+
+using namespace OIC::Service;
+
+/**
+ * @class   JniRemoteEnrollee
+ * @brief   This class contains all the APIs for RemoteEnrollee
+ *
+ * NOTE: JNI APIs internally call the APIs of this class.
+ */
+class JniRemoteEnrollee
+{
+    public:
+
+        /**
+        *@brief constructor
+        */
+        JniRemoteEnrollee(std::shared_ptr< RemoteEnrollee> remoteEnrollee);
+
+        /**
+         *@brief destructor
+        */
+        ~JniRemoteEnrollee();
+
+        // ***** JNI APIs internally call the APIs of this class ***** //
+
+        void startProvisioning(JNIEnv *env);
+        void stopProvisioning(JNIEnv *env);
+        void registerProvisioningHandler(JNIEnv *env, jobject jListener);
+
+        JniProvisioningStatusListener *addProvisioningStatusListener(JNIEnv *env, jobject jListener);
+        void removeProvisioningStatusListener(JNIEnv *env, jobject jListener);
+
+        static JniRemoteEnrollee *getJniRemoteEnrollee(JNIEnv *env, jobject thiz);
+
+    private:
+        JniEsListenerManager<JniProvisioningStatusListener> m_provisioingStatus;
+        std::shared_ptr<RemoteEnrollee> m_sharedResource;
+
+};
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * API for starting the provisioning process.
+ */
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStartProvision
+(JNIEnv *env, jobject jClass);
+
+/**
+ * API for stopping the provisioning process.
+ */
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStopProvision
+(JNIEnv *env, jobject jClass);
+
+/**
+ * API for setting the lisener for recieiving provisioning status.
+ *
+ * @param provisiongListener - Provisioning listener [callback from native layer will be passing to this listener]
+ */
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeRegisterProvisioningHandler
+(JNIEnv *env, jobject jClass, jobject provisiongListener);
+
+#ifdef __cplusplus
+}
+#endif
+#endif // __JNI_ES_REMOTEENROLLEE_H