complete android ca sample build with scons
authorjnashok <jn.ashok@samsung.com>
Thu, 25 Jun 2015 05:47:10 +0000 (14:47 +0900)
committerErich Keane <erich.keane@intel.com>
Mon, 20 Jul 2015 17:34:29 +0000 (17:34 +0000)
ca sample now has gradle support
gradle build is intiated from scons
this also takes care of building ca using ndk

Change-Id: Id681c508a8a4ef4e3fcca9e67dcf1a88a1cca989
Signed-off-by: jnashok <jn.ashok@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1423
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Erich Keane <erich.keane@intel.com>
51 files changed:
extlibs/tinydtls/Android.mk
resource/csdk/connectivity/SConscript
resource/csdk/connectivity/build/android/README.txt
resource/csdk/connectivity/build/android/jni/Android.mk
resource/csdk/connectivity/samples/android/SConscript
resource/csdk/connectivity/samples/android/casample/.gitignore [new file with mode: 0644]
resource/csdk/connectivity/samples/android/casample/SConscript [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/build.gradle [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/cAInterface/.gitignore [new file with mode: 0644]
resource/csdk/connectivity/samples/android/casample/cAInterface/build.gradle [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/cAInterface/cAInterface.iml [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/.gitignore [new file with mode: 0644]
resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/AndroidManifest.xml [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaEdrInterface.java [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaIpInterface.java [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaLeClientInterface.java [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaLeServerInterface.java [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/drawable-hdpi/ic_launcher.png [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/drawable-mdpi/ic_launcher.png [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/drawable-xhdpi/ic_launcher.png [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/values-v11/styles.xml [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/values-v14/styles.xml [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/values/strings.xml [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/values/styles.xml [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/casample.iml [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/gradle.properties [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/gradle/wrapper/gradle-wrapper.jar [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/gradle/wrapper/gradle-wrapper.properties [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/gradlew [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/gradlew.bat [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/sampleService/.gitignore [new file with mode: 0644]
resource/csdk/connectivity/samples/android/casample/sampleService/build.gradle [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/sampleService/sampleService.iml [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/sampleService/src/main/.gitignore [new file with mode: 0644]
resource/csdk/connectivity/samples/android/casample/sampleService/src/main/AndroidManifest.xml [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/sampleService/src/main/java/org/iotivity/ca/service/DLog.java [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/sampleService/src/main/java/org/iotivity/ca/service/MainActivity.java [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/sampleService/src/main/java/org/iotivity/ca/service/RMInterface.java [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/Android.mk [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/Application.mk [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/ResourceModel.c [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/org_iotivity_ca_service_RMInterface.h [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/layout/activity_main.xml [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/menu/main.xml [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/values-v11/styles.xml [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/values-v14/styles.xml [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/values-w820dp/dimens.xml [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/values/dimens.xml [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/values/strings.xml [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/values/styles.xml [new file with mode: 0755]
resource/csdk/connectivity/samples/android/casample/settings.gradle [new file with mode: 0755]

index d21965c..a507a51 100644 (file)
@@ -12,6 +12,6 @@ LOCAL_SRC_FILES += sha2/sha2.c
 LOCAL_C_INCLUDES := $(APP_PATH) $(APP_PATH)/aes $(APP_PATH)/ecc $(APP_PATH)/sha2
 
 #LOCAL_CFLAGS := -DWITH_OICSTACK -fPIC
-LOCAL_CFLAGS += -DDTLSv12 -DWITH_SHA256 -DDTLS_CHECK_CONTENTTYPE -DHAVE_SYS_TIME_H
+LOCAL_CFLAGS += -DDTLSv12 -DWITH_SHA256 -DDTLS_CHECK_CONTENTTYPE -DHAVE_SYS_TIME_H -DNDEBUG
 
 include $(BUILD_SHARED_LIBRARY)
index 4c0f448..f7560e6 100644 (file)
@@ -63,9 +63,17 @@ else:
 env.SConscript('./src/SConscript')
 
 if build_sample == 'ON':
-       if target_os in ['linux', 'arduino', 'android', 'darwin']:
+       if target_os in ['linux', 'arduino', 'darwin']:
                target_path = target_os
+
                if target_os == 'darwin':
                        target_path = 'linux'
                env.SConscript('./samples/' + target_path + '/SConscript')
 
+       elif target_os in ['android']:
+               env.SConscript('./samples/' + target_os + '/SConscript')
+
+               #to build sample apk, uncomment below line after ca libraries are built
+               #while building ca libraries comment the below line, to avoid build errors
+
+               #env.SConscript('./samples/' + target_os + '/casample/SConscript')
index 10fb9a3..fc98dce 100644 (file)
@@ -1,17 +1,26 @@
 Compiling Interface APIs FOR Android:
 ===================================
 •Preconditons :
-       Please download the following
-       1) tinydlts library and keep at $(CA_HOME)/lib/tinydtls
 •Supported version : 5.0 ( Lollipop )
 •Required NDK version : android-ndk-r10d ( https://developer.android.com/tools/sdk/ndk/index.html )
-• Modify Makefile ( connectivity/build/android/Makefile )
-    $ cd ${CA_HOME}/connectivity/build/android
-    $ vi Makefile
-  #  Change the NDK_PATH
-    NDK_PATH = ${your_ndk_path}
- Build : $(CA_HOME)/build/android/Makefile
-    $ cd ${CA_HOME}/connectivity/build/android
-    $ ndk-build clean; ndk-build
 
+Building CA Library for android :
 
+Run the SCons as mentioned in connectivity/build/How_To_Build.txt
+
+Building CA Samples for Android :
+
+Run the SCons as mentioned in connectivity/build/How_To_Build.txt
+Edit connectivity/SConscript to build the APK
+
+uncomment the below line to build the sample :
+env.SConscript('./samples/' + target_os + '/casample/SConscript')
+
+Note : If this is enabled before building the SO files, Build will fail. 
+Ensure to disable the script whenever not required
+
+Installing the APK :
+
+Run the following command :
+
+$(ADB_HOME)/adb install resource/csdk/connectivity/samples/android/casample/sampleService/build/outputs/apk/sampleService-debug.apk
index 8754e31..c0e68fd 100644 (file)
@@ -13,7 +13,7 @@ $(info PLATFORM=$(APP_PLATFORM))
 BUILD = debug
 
 PROJECT_ROOT_PATH           ?= ../..
-ROOT_DIR_PATH               = ../../../../../..
+ROOT_DIR_PATH               = $(PROJECT_ROOT_PATH)/../../..
 EXT_LIB_PATH                = $(ROOT_DIR_PATH)/extlibs
 PROJECT_API_PATH            = $(PROJECT_ROOT_PATH)/api
 PROJECT_INC_PATH            = $(PROJECT_ROOT_PATH)/inc
@@ -35,7 +35,7 @@ LE              = LE_ADAPTER
 
 #Add Pre processor definitions
 DEFINE_FLAG =  -DWITH_POSIX -D__ANDROID__
-DEFINE_FLAG =  -D__WITH_DTLS__
+DEFINE_FLAG +=  -D__WITH_DTLS__
 DEFINE_FLAG += -D$(EDR) -D$(LE) -D$(IP)
 
 #Add Debug flags here
index 373a3e7..94e8420 100644 (file)
@@ -31,7 +31,7 @@ secured = app_env.get('SECURED')
 \r
 print "Sample secured flag is %s" % secured\r
 \r
-sample_dir = 'sample_service/jni/'\r
+sample_dir = 'casample/sampleService/src/main/jni/'\r
 sample_src = [sample_dir + 'ResourceModel.c',]\r
 \r
 print " sample src %s" % sample_src\r
diff --git a/resource/csdk/connectivity/samples/android/casample/.gitignore b/resource/csdk/connectivity/samples/android/casample/.gitignore
new file mode 100644 (file)
index 0000000..6f9b76a
--- /dev/null
@@ -0,0 +1,5 @@
+local.properties
+import-summary.txt
+/.idea/
+/.gradle/
+/build/
diff --git a/resource/csdk/connectivity/samples/android/casample/SConscript b/resource/csdk/connectivity/samples/android/casample/SConscript
new file mode 100755 (executable)
index 0000000..1292297
--- /dev/null
@@ -0,0 +1,14 @@
+import os
+import platform
+Import('env')
+
+ANDROID_TARGET_ARCH = env.get('TARGET_ARCH')
+if env.get('RELEASE'):
+       ANDROID_RELEASE="release"
+else:
+       ANDROID_RELEASE="debug"
+
+jdk_env = Environment(ENV=os.environ)
+jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + Dir('.').srcnode().abspath + '/build.gradle -PTARGET_ARCH=%s -PRELEASE=%s' %(ANDROID_TARGET_ARCH, ANDROID_RELEASE))
+jdk_env.Gradle(target="base/objs", source="sampleService/src/main/java/org/iotivity/ca/service/MainActivity.java")
+
diff --git a/resource/csdk/connectivity/samples/android/casample/build.gradle b/resource/csdk/connectivity/samples/android/casample/build.gradle
new file mode 100755 (executable)
index 0000000..4035fa8
--- /dev/null
@@ -0,0 +1,21 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+buildscript {
+    repositories {
+        jcenter()
+               {
+                       url "http://jcenter.bintray.com"
+               }
+    }
+    dependencies {
+        classpath 'com.android.tools.build:gradle:1.1.0'
+    }
+}
+
+allprojects {
+    repositories {
+        jcenter()
+               {
+                       url "http://jcenter.bintray.com"
+               }
+    }
+}
diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/.gitignore b/resource/csdk/connectivity/samples/android/casample/cAInterface/.gitignore
new file mode 100644 (file)
index 0000000..84c048a
--- /dev/null
@@ -0,0 +1 @@
+/build/
diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/build.gradle b/resource/csdk/connectivity/samples/android/casample/cAInterface/build.gradle
new file mode 100755 (executable)
index 0000000..6ca1fe0
--- /dev/null
@@ -0,0 +1,26 @@
+apply plugin: 'com.android.library'
+
+android {
+    compileSdkVersion 21
+    buildToolsVersion "20.0.0"
+
+    defaultConfig {
+        minSdkVersion 21
+        targetSdkVersion 21
+    }
+
+    buildTypes {
+        release {
+            minifyEnabled false
+            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+        }
+    }
+
+    lintOptions {
+       abortOnError false
+    }
+}
+
+dependencies {
+//    compile 'com.android.support:support-v4:21.0.3'
+}
diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/cAInterface.iml b/resource/csdk/connectivity/samples/android/casample/cAInterface/cAInterface.iml
new file mode 100755 (executable)
index 0000000..217b60e
--- /dev/null
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="MainActivity" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
+  <component name="FacetManager">
+    <facet type="android-gradle" name="Android-Gradle">
+      <configuration>
+        <option name="GRADLE_PROJECT_PATH" value=":cAInterface" />
+      </configuration>
+    </facet>
+    <facet type="android" name="Android">
+      <configuration>
+        <option name="SELECTED_BUILD_VARIANT" value="debug" />
+        <option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
+        <option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
+        <option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
+        <option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
+        <option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
+        <option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugAndroidTestSources" />
+        <option name="ALLOW_USER_CONFIGURATION" value="false" />
+        <option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
+        <option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
+        <option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
+        <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
+        <option name="LIBRARY_PROJECT" value="true" />
+      </configuration>
+    </facet>
+  </component>
+  <component name="NewModuleRootManager" inherit-compiler-output="false">
+    <output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
+    <output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/androidTest/debug" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
+      <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
+    </content>
+    <orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
+    <orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
+  </component>
+</module>
+
diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/.gitignore b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/.gitignore
new file mode 100644 (file)
index 0000000..7cf58ac
--- /dev/null
@@ -0,0 +1 @@
+/assets/
diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/AndroidManifest.xml b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/AndroidManifest.xml
new file mode 100755 (executable)
index 0000000..4bc64f6
--- /dev/null
@@ -0,0 +1,17 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="org.iotivity.ca"
+    android:versionCode="1"
+    android:versionName="1.0" >
+
+    <uses-sdk
+        android:minSdkVersion="21"
+        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/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaEdrInterface.java b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaEdrInterface.java
new file mode 100755 (executable)
index 0000000..1e4d47c
--- /dev/null
@@ -0,0 +1,87 @@
+/******************************************************************
+ *
+ * Copyright 2014 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.ca;
+
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+
+public class CaEdrInterface {
+
+    private CaEdrInterface(Context context) {
+
+        registerIntentFilter(context);
+    }
+
+    private static IntentFilter registerIntentFilter(Context context) {
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
+        filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
+        context.registerReceiver(mReceiver, filter);
+        return filter;
+    }
+
+    // Network Monitor
+    private native static void caEdrStateChangedCallback(int state);
+
+    private native static void caEdrBondStateChangedCallback(String addr);
+
+    private static final BroadcastReceiver mReceiver = new BroadcastReceiver() {
+
+        @Override
+        public void onReceive(Context context, Intent intent) {
+
+            String action = intent.getAction();
+
+            if (action != null && action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
+
+                int state =
+                        intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
+
+                // STATE_ON:12, STATE_OFF:10
+                if (state == BluetoothAdapter.STATE_ON || state == BluetoothAdapter.STATE_OFF)
+                {
+                    caEdrStateChangedCallback(state);
+                }
+            }
+
+            if (action != null && action.equals(BluetoothDevice.ACTION_BOND_STATE_CHANGED)) {
+
+                int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE,
+                                                   BluetoothDevice.ERROR);
+
+                if (bondState == BluetoothDevice.BOND_NONE) {
+                    if ((intent.getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE,
+                                            BluetoothDevice.ERROR)
+                                                == BluetoothDevice.BOND_BONDED)) {
+                        BluetoothDevice device
+                            = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+
+                        caEdrBondStateChangedCallback(device.getAddress());
+                    }
+                }
+            }
+        }
+    };
+}
diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaIpInterface.java b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaIpInterface.java
new file mode 100755 (executable)
index 0000000..cbe0ec0
--- /dev/null
@@ -0,0 +1,68 @@
+/******************************************************************
+ *
+ * Copyright 2014 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.ca;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+import android.net.wifi.WifiManager;
+
+public class CaIpInterface {
+    private static Context mContext;
+
+    private CaIpInterface(Context context) {
+        mContext = context;
+        registerIpStateReceiver();
+    }
+
+    private void registerIpStateReceiver() {
+        IntentFilter intentFilter = new IntentFilter();
+        intentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
+        intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
+
+        mContext.registerReceiver(mReceiver, intentFilter);
+    }
+
+    private static BroadcastReceiver mReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
+                WifiManager.WIFI_STATE_UNKNOWN) == WifiManager.WIFI_STATE_DISABLED) {
+                caIpStateDisabled();
+            } else if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
+                ConnectivityManager manager = (ConnectivityManager)
+                        mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
+                NetworkInfo nwInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
+
+                if(nwInfo.isConnected()) {
+                    caIpStateEnabled();
+                }
+            }
+        }
+    };
+
+    private native static void caIpStateEnabled();
+
+    private native static void caIpStateDisabled();
+}
\ No newline at end of file
diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaLeClientInterface.java b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaLeClientInterface.java
new file mode 100755 (executable)
index 0000000..891cb40
--- /dev/null
@@ -0,0 +1,295 @@
+/******************************************************************
+ *
+ * Copyright 2014 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.ca;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothGatt;
+import android.bluetooth.BluetoothGattCallback;
+import android.bluetooth.BluetoothGattCharacteristic;
+import android.bluetooth.BluetoothGattDescriptor;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.util.Log;
+
+public class CaLeClientInterface {
+
+    private static String SERVICE_UUID = "ADE3D529-C784-4F63-A987-EB69F70EE816";
+    private static String TAG          = "Sample_Service : CaLeClientInterface";
+
+    private CaLeClientInterface(Context context) {
+
+        caLeRegisterLeScanCallback(mLeScanCallback);
+        caLeRegisterGattCallback(mGattCallback);
+
+        registerIntentFilter(context);
+    }
+
+    public static void getLeScanCallback() {
+        caLeRegisterLeScanCallback(mLeScanCallback);
+    }
+
+    public static void getLeGattCallback() {
+        caLeRegisterGattCallback(mGattCallback);
+    }
+
+    private static IntentFilter registerIntentFilter(Context context) {
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
+        filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
+        context.registerReceiver(mReceiver, filter);
+        return filter;
+    }
+
+    private native static void caLeRegisterLeScanCallback(BluetoothAdapter.LeScanCallback callback);
+
+    private native static void caLeRegisterGattCallback(BluetoothGattCallback callback);
+
+    // BluetoothAdapter.LeScanCallback
+    private native static void caLeScanCallback(BluetoothDevice device,
+                                                int rssi, byte[] scanRecord);
+
+    // BluetoothGattCallback
+    private native static void caLeGattConnectionStateChangeCallback(
+            BluetoothGatt gatt, int status, int newState);
+
+    private native static void caLeGattServicesDiscoveredCallback(BluetoothGatt gatt, int status);
+
+    private native static void caLeGattCharacteristicReadCallback(
+            BluetoothGatt gatt, BluetoothGattCharacteristic characteristic,
+            byte[] data, int status);
+
+    private native static void caLeGattCharacteristicWriteCallback(
+            BluetoothGatt gatt, BluetoothGattCharacteristic characteristic,
+            byte[] data, int status);
+
+    private native static void caLeGattCharacteristicChangedCallback(
+            BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, byte[] data);
+
+    private native static void caLeGattDescriptorReadCallback(BluetoothGatt gatt,
+                                                             BluetoothGattDescriptor descriptor,
+                                                             int status);
+
+    private native static void caLeGattDescriptorWriteCallback(BluetoothGatt gatt,
+                                                              BluetoothGattDescriptor descriptor,
+                                                              int status);
+
+    private native static void caLeGattReliableWriteCompletedCallback(BluetoothGatt gatt,
+                                                                     int status);
+
+    private native static void caLeGattReadRemoteRssiCallback(BluetoothGatt gatt, int rssi,
+                                                             int status);
+
+    // Network Monitor
+    private native static void caLeStateChangedCallback(int state);
+
+    // bond state
+    private native static void caLeBondStateChangedCallback(String address);
+
+    // Callback
+    private static BluetoothAdapter.LeScanCallback mLeScanCallback =
+                   new BluetoothAdapter.LeScanCallback() {
+
+        @Override
+        public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
+
+            try {
+                List<UUID> uuids = getUuids(scanRecord);
+                for (UUID uuid : uuids) {
+                    Log.d(TAG, "UUID : " + uuid.toString());
+                    if(uuid.toString().contains(SERVICE_UUID.toLowerCase())) {
+                        Log.d(TAG, "we found that has the Device");
+                        caLeScanCallback(device, rssi, scanRecord);
+                    }
+                }
+            } catch(UnsatisfiedLinkError e) {
+
+            }
+        }
+    };
+
+    private static List<UUID> getUuids(final byte[] scanRecord) {
+        List<UUID> uuids = new ArrayList<UUID>();
+
+        int offset = 0;
+        while (offset < (scanRecord.length - 2)) {
+            int len = scanRecord[offset++];
+            if (len == 0)
+                break;
+
+            int type = scanRecord[offset++];
+
+            switch (type) {
+            case 0x02:
+            case 0x03:
+                while (len > 1) {
+                    int uuid16 = scanRecord[offset++];
+                    uuid16 += (scanRecord[offset++] << 8);
+                    len -= 2;
+                    uuids.add(UUID.fromString(String.format(
+                            "%08x-0000-1000-8000-00805f9b34fb", uuid16)));
+                }
+                break;
+            case 0x06:
+            case 0x07:
+                while (len >= 16) {
+                    try {
+                        ByteBuffer buffer = ByteBuffer.wrap(scanRecord, offset++, 16).
+                                                            order(ByteOrder.LITTLE_ENDIAN);
+                        long mostSigBits = buffer.getLong();
+                        long leastSigBits = buffer.getLong();
+                        uuids.add(new UUID(leastSigBits, mostSigBits));
+                    } catch (IndexOutOfBoundsException e) {
+                        Log.e(TAG, e.toString());
+                        continue;
+                    } finally {
+                        offset += 15;
+                        len -= 16;
+                    }
+                }
+                break;
+            default:
+                offset += (len - 1);
+                break;
+            }
+        }
+        return uuids;
+    }
+
+    private static final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
+
+        @Override
+        public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
+            super.onConnectionStateChange(gatt, status, newState);
+
+            caLeGattConnectionStateChangeCallback(gatt, status, newState);
+        }
+
+        @Override
+        public void onServicesDiscovered(BluetoothGatt gatt, int status) {
+            super.onServicesDiscovered(gatt, status);
+
+            caLeGattServicesDiscoveredCallback(gatt, status);
+        }
+
+        @Override
+        public void onCharacteristicRead(BluetoothGatt gatt,
+                BluetoothGattCharacteristic characteristic, int status) {
+            super.onCharacteristicRead(gatt, characteristic, status);
+
+            caLeGattCharacteristicReadCallback(gatt, characteristic,
+                                               characteristic.getValue(), status);
+        }
+
+        @Override
+        public void onCharacteristicWrite(BluetoothGatt gatt,
+                BluetoothGattCharacteristic characteristic, int status) {
+            super.onCharacteristicWrite(gatt, characteristic, status);
+
+            caLeGattCharacteristicWriteCallback(gatt, characteristic,
+                                                characteristic.getValue(), status);
+        }
+
+        @Override
+        public void onCharacteristicChanged(BluetoothGatt gatt,
+                BluetoothGattCharacteristic characteristic) {
+            super.onCharacteristicChanged(gatt, characteristic);
+
+            caLeGattCharacteristicChangedCallback(gatt, characteristic,
+                                                  characteristic.getValue());
+        }
+
+        @Override
+        public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
+                int status) {
+            super.onDescriptorRead(gatt, descriptor, status);
+
+            caLeGattDescriptorReadCallback(gatt, descriptor, status);
+        }
+
+        @Override
+        public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
+                int status) {
+            super.onDescriptorWrite(gatt, descriptor, status);
+
+            caLeGattDescriptorWriteCallback(gatt, descriptor, status);
+        }
+
+        @Override
+        public void onReliableWriteCompleted(BluetoothGatt gatt, int status) {
+            super.onReliableWriteCompleted(gatt, status);
+
+            caLeGattReliableWriteCompletedCallback(gatt, status);
+        }
+
+        @Override
+        public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
+            super.onReadRemoteRssi(gatt, rssi, status);
+
+            caLeGattReadRemoteRssiCallback(gatt, rssi, status);
+        }
+    };
+
+    private static final BroadcastReceiver mReceiver = new BroadcastReceiver() {
+
+        @Override
+        public void onReceive(Context context, Intent intent) {
+
+            String action = intent.getAction();
+
+            if (action != null && action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
+
+                int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
+                                               BluetoothAdapter.ERROR);
+
+                if (state == BluetoothAdapter.STATE_ON || state == BluetoothAdapter.STATE_OFF)
+                {
+                    caLeStateChangedCallback(state);
+                }
+            }
+
+            if (action != null && action.equals(BluetoothDevice.ACTION_BOND_STATE_CHANGED)) {
+
+                int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE,
+                                                   BluetoothDevice.ERROR);
+
+                if (bondState == BluetoothDevice.BOND_NONE) {
+                    if ((intent.getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE,
+                            BluetoothDevice.ERROR) == BluetoothDevice.BOND_BONDED)) {
+                            BluetoothDevice device = intent
+                                .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+
+                        caLeBondStateChangedCallback(device.getAddress());
+                    }
+                }
+            }
+        }
+    };
+}
+
diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaLeServerInterface.java b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaLeServerInterface.java
new file mode 100755 (executable)
index 0000000..75f447b
--- /dev/null
@@ -0,0 +1,180 @@
+/******************************************************************
+ *
+ * Copyright 2014 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.ca;
+
+import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothGattCharacteristic;
+import android.bluetooth.BluetoothGattDescriptor;
+import android.bluetooth.BluetoothGattServerCallback;
+import android.bluetooth.BluetoothGattService;
+import android.bluetooth.le.AdvertiseCallback;
+import android.bluetooth.le.AdvertiseSettings;
+
+public class CaLeServerInterface {
+
+    private CaLeServerInterface() {
+
+        caLeRegisterGattServerCallback(mGattServerCallback);
+        caLeRegisterBluetoothLeAdvertiseCallback(mAdvertiseCallback);
+    }
+
+    public static void getLeGattServerCallback() {
+        caLeRegisterGattServerCallback(mGattServerCallback);
+    }
+
+    public static void getBluetoothLeAdvertiseCallback() {
+        caLeRegisterBluetoothLeAdvertiseCallback(mAdvertiseCallback);
+    }
+
+    private native static void caLeRegisterGattServerCallback(BluetoothGattServerCallback callback);
+
+    private native static void caLeRegisterBluetoothLeAdvertiseCallback(AdvertiseCallback callback);
+
+    // BluetoothGattServerCallback
+    private native static void caLeGattServerConnectionStateChangeCallback(
+            BluetoothDevice device, int status, int newState);
+
+    private native static void caLeGattServerServiceAddedCallback(int status,
+                                                                  BluetoothGattService service);
+
+    private native static void caLeGattServerCharacteristicReadRequestCallback(
+            BluetoothDevice device,
+            int requestId, int offset, BluetoothGattCharacteristic characteristic, byte[] data);
+
+    private native static void caLeGattServerCharacteristicWriteRequestCallback(
+            BluetoothDevice device, int requestId,
+            BluetoothGattCharacteristic characteristic, byte[] data, boolean preparedWrite,
+            boolean responseNeeded, int offset, byte[] value);
+
+    private native static void caLeGattServerDescriptorReadRequestCallback(
+            BluetoothDevice device, int requestId, int offset, BluetoothGattDescriptor descriptor);
+
+    public native static void caLeGattServerDescriptorWriteRequestCallback(
+            BluetoothDevice device, int requestId, BluetoothGattDescriptor descriptor,
+            boolean preparedWrite, boolean responseNeeded, int offset, byte[] value);
+
+    private native static void caLeGattServerExecuteWriteCallback(BluetoothDevice device,
+                                                                 int requestId, boolean execute);
+
+    private native static void caLeGattServerNotificationSentCallback(BluetoothDevice device,
+                                                                     int status);
+
+    // AdvertiseCallback
+    private native static void caLeAdvertiseStartSuccessCallback(
+            AdvertiseSettings settingsInEffect);
+
+    private native static void caLeAdvertiseStartFailureCallback(int errorCode);
+
+    private static final BluetoothGattServerCallback mGattServerCallback =
+                         new BluetoothGattServerCallback() {
+
+        @Override
+        public void onConnectionStateChange(BluetoothDevice device, int status,
+                int newState) {
+            super.onConnectionStateChange(device, status, newState);
+
+            caLeGattServerConnectionStateChangeCallback(device, status, newState);
+        }
+
+        @Override
+        public void onServiceAdded(int status, BluetoothGattService service) {
+            super.onServiceAdded(status, service);
+
+            caLeGattServerServiceAddedCallback(status, service);
+        }
+
+        @Override
+        public void onCharacteristicReadRequest(
+                BluetoothDevice device, int requestId, int offset,
+                BluetoothGattCharacteristic characteristic) {
+            super.onCharacteristicReadRequest(device, requestId, offset, characteristic);
+
+            caLeGattServerCharacteristicReadRequestCallback(device, requestId, offset,
+                                                            characteristic,
+                                                            characteristic.getValue());
+        }
+
+        @Override
+        public void onCharacteristicWriteRequest(
+                BluetoothDevice device, int requestId, BluetoothGattCharacteristic characteristic,
+                boolean preparedWrite, boolean responseNeeded, int offset, byte[] value) {
+            super.onCharacteristicWriteRequest(device, requestId, characteristic,
+                    preparedWrite, responseNeeded, offset, value);
+
+            caLeGattServerCharacteristicWriteRequestCallback(device, requestId, characteristic,
+                                                             value, preparedWrite, responseNeeded,
+                                                             offset, value);
+        }
+
+        @Override
+        public void onDescriptorReadRequest(
+                BluetoothDevice device,
+                int requestId, int offset, BluetoothGattDescriptor descriptor) {
+            super.onDescriptorReadRequest(device, requestId, offset, descriptor);
+
+            caLeGattServerDescriptorReadRequestCallback(device, requestId, offset, descriptor);
+        }
+
+        @Override
+        public void onDescriptorWriteRequest(
+                BluetoothDevice device, int requestId, BluetoothGattDescriptor descriptor,
+                boolean preparedWrite, boolean responseNeeded, int offset,
+                byte[] value) {
+            super.onDescriptorWriteRequest(device, requestId, descriptor, preparedWrite,
+                                           responseNeeded, offset, value);
+
+            caLeGattServerDescriptorWriteRequestCallback(device, requestId, descriptor,
+                                                         preparedWrite, responseNeeded, offset,
+                                                         value);
+        }
+
+        @Override
+        public void onExecuteWrite(BluetoothDevice device, int requestId, boolean execute) {
+            super.onExecuteWrite(device, requestId, execute);
+
+            caLeGattServerExecuteWriteCallback(device, requestId, execute);
+        }
+
+        @Override
+        public void onNotificationSent(BluetoothDevice device, int status) {
+            super.onNotificationSent(device, status);
+
+            caLeGattServerNotificationSentCallback(device, status);
+        }
+    };
+
+    private static final AdvertiseCallback mAdvertiseCallback = new AdvertiseCallback() {
+
+        @Override
+        public void onStartSuccess(AdvertiseSettings settingsInEffect) {
+            super.onStartSuccess(settingsInEffect);
+
+            caLeAdvertiseStartSuccessCallback(settingsInEffect);
+        }
+
+        @Override
+        public void onStartFailure(int errorCode) {
+            super.onStartFailure(errorCode);
+
+            caLeAdvertiseStartFailureCallback(errorCode);
+        }
+    };
+}
diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/drawable-hdpi/ic_launcher.png b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100755 (executable)
index 0000000..96a442e
Binary files /dev/null and b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/drawable-mdpi/ic_launcher.png b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100755 (executable)
index 0000000..359047d
Binary files /dev/null and b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/drawable-xhdpi/ic_launcher.png b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100755 (executable)
index 0000000..71c6d76
Binary files /dev/null and b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/values-v11/styles.xml b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/values-v11/styles.xml
new file mode 100755 (executable)
index 0000000..3c02242
--- /dev/null
@@ -0,0 +1,11 @@
+<resources>
+
+    <!--
+        Base application theme for API 11+. This theme completely replaces
+        AppBaseTheme from res/values/styles.xml on API 11+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
+        <!-- API 11 theme customizations can go here. -->
+    </style>
+
+</resources>
diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/values-v14/styles.xml b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/values-v14/styles.xml
new file mode 100755 (executable)
index 0000000..a91fd03
--- /dev/null
@@ -0,0 +1,12 @@
+<resources>
+
+    <!--
+        Base application theme for API 14+. This theme completely replaces
+        AppBaseTheme from BOTH res/values/styles.xml and
+        res/values-v11/styles.xml on API 14+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+        <!-- API 14 theme customizations can go here. -->
+    </style>
+
+</resources>
diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/values/strings.xml b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/values/strings.xml
new file mode 100755 (executable)
index 0000000..0e63d00
--- /dev/null
@@ -0,0 +1,5 @@
+<resources>
+
+    <string name="app_name">CAInterface</string>
+
+</resources>
diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/values/styles.xml b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/values/styles.xml
new file mode 100755 (executable)
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/resource/csdk/connectivity/samples/android/casample/casample.iml b/resource/csdk/connectivity/samples/android/casample/casample.iml
new file mode 100755 (executable)
index 0000000..ed92464
--- /dev/null
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
+  <component name="FacetManager">
+    <facet type="java-gradle" name="Java-Gradle">
+      <configuration>
+        <option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/../MainActivity/build" />
+      </configuration>
+    </facet>
+    <facet type="android-gradle" name="Android-Gradle">
+      <configuration>
+        <option name="GRADLE_PROJECT_PATH" value=":" />
+      </configuration>
+    </facet>
+    <facet type="android" name="Android">
+      <configuration>
+        <option name="ALLOW_USER_CONFIGURATION" value="false" />
+      </configuration>
+    </facet>
+  </component>
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <excludeFolder url="file://$MODULE_DIR$/.gradle" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>
+
diff --git a/resource/csdk/connectivity/samples/android/casample/gradle.properties b/resource/csdk/connectivity/samples/android/casample/gradle.properties
new file mode 100755 (executable)
index 0000000..b0f079c
--- /dev/null
@@ -0,0 +1,41 @@
+#
+# //******************************************************************
+# //
+# // Copyright 2015 Intel Corporation.
+# //
+# //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+# //
+# // 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.
+# //
+# //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#
+
+# Project-wide Gradle settings.
+
+# IDE (e.g. Android Studio) users:
+# Gradle settings configured through the IDE *will override*
+# any settings specified in this file.
+
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+# Default value: -Xmx10248m -XX:MaxPermSize=256m
+# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
+
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
+
diff --git a/resource/csdk/connectivity/samples/android/casample/gradle/wrapper/gradle-wrapper.jar b/resource/csdk/connectivity/samples/android/casample/gradle/wrapper/gradle-wrapper.jar
new file mode 100755 (executable)
index 0000000..8c0fb64
Binary files /dev/null and b/resource/csdk/connectivity/samples/android/casample/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/resource/csdk/connectivity/samples/android/casample/gradle/wrapper/gradle-wrapper.properties b/resource/csdk/connectivity/samples/android/casample/gradle/wrapper/gradle-wrapper.properties
new file mode 100755 (executable)
index 0000000..0c71e76
--- /dev/null
@@ -0,0 +1,6 @@
+#Wed Apr 10 15:27:10 PDT 2013
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
diff --git a/resource/csdk/connectivity/samples/android/casample/gradlew b/resource/csdk/connectivity/samples/android/casample/gradlew
new file mode 100755 (executable)
index 0000000..91a7e26
--- /dev/null
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+##  Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+    echo "$*"
+}
+
+die ( ) {
+    echo
+    echo "$*"
+    echo
+    exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+  CYGWIN* )
+    cygwin=true
+    ;;
+  Darwin* )
+    darwin=true
+    ;;
+  MINGW* )
+    msys=true
+    ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+    [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+    ls=`ls -ld "$PRG"`
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+    if expr "$link" : '/.*' > /dev/null; then
+        PRG="$link"
+    else
+        PRG=`dirname "$PRG"`"/$link"
+    fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+        # IBM's JDK on AIX uses strange locations for the executables
+        JAVACMD="$JAVA_HOME/jre/sh/java"
+    else
+        JAVACMD="$JAVA_HOME/bin/java"
+    fi
+    if [ ! -x "$JAVACMD" ] ; then
+        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+    fi
+else
+    JAVACMD="java"
+    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+    MAX_FD_LIMIT=`ulimit -H -n`
+    if [ $? -eq 0 ] ; then
+        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+            MAX_FD="$MAX_FD_LIMIT"
+        fi
+        ulimit -n $MAX_FD
+        if [ $? -ne 0 ] ; then
+            warn "Could not set maximum file descriptor limit: $MAX_FD"
+        fi
+    else
+        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+    fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+    # We build the pattern for arguments to be converted via cygpath
+    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+    SEP=""
+    for dir in $ROOTDIRSRAW ; do
+        ROOTDIRS="$ROOTDIRS$SEP$dir"
+        SEP="|"
+    done
+    OURCYGPATTERN="(^($ROOTDIRS))"
+    # Add a user-defined pattern to the cygpath arguments
+    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+    fi
+    # Now convert the arguments - kludge to limit ourselves to /bin/sh
+    i=0
+    for arg in "$@" ; do
+        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option
+
+        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
+            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+        else
+            eval `echo args$i`="\"$arg\""
+        fi
+        i=$((i+1))
+    done
+    case $i in
+        (0) set -- ;;
+        (1) set -- "$args0" ;;
+        (2) set -- "$args0" "$args1" ;;
+        (3) set -- "$args0" "$args1" "$args2" ;;
+        (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+        (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+        (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+        (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+        (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+        (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+    esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+    JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/resource/csdk/connectivity/samples/android/casample/gradlew.bat b/resource/csdk/connectivity/samples/android/casample/gradlew.bat
new file mode 100755 (executable)
index 0000000..8a0b282
--- /dev/null
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem  Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/.gitignore b/resource/csdk/connectivity/samples/android/casample/sampleService/.gitignore
new file mode 100644 (file)
index 0000000..84c048a
--- /dev/null
@@ -0,0 +1 @@
+/build/
diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/build.gradle b/resource/csdk/connectivity/samples/android/casample/sampleService/build.gradle
new file mode 100755 (executable)
index 0000000..1e31192
--- /dev/null
@@ -0,0 +1,70 @@
+apply plugin: 'com.android.application'
+
+android {
+    compileSdkVersion 21
+    buildToolsVersion "20.0.0"
+
+    defaultConfig {
+        applicationId "org.iotivity.ca.sample_service"
+        minSdkVersion 21
+        targetSdkVersion 21
+
+        ndk {
+            moduleName "RMInterface"
+        }
+    }
+
+    buildTypes {
+        release {
+            minifyEnabled false
+            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+        }
+    }
+
+    lintOptions {
+       abortOnError false
+    }
+
+    sourceSets {
+        main {
+            manifest.srcFile 'src/main/AndroidManifest.xml'
+            jniLibs.srcDir 'libs'
+            jni.srcDirs = [] //disable automatic ndk-build call
+        }
+    }
+}
+
+dependencies {
+    compile fileTree(dir: 'libs', include: ['*.jar'])
+    compile project(':cAInterface')
+}
+
+task copyNativeLibs(type: Copy, dependsOn: 'buildNative') {
+    dependsOn 'buildNative'
+    from(new File('src/main/libs')) { include '**/*.so' }
+    into new File(buildDir, 'native-libs')
+}
+
+tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn copyNativeLibs }
+
+clean.dependsOn 'cleanCopyNativeLibs'
+
+tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
+    pkgTask.jniFolders = new HashSet<File>()
+    pkgTask.jniFolders.add(new File(buildDir, 'native-libs'))
+}
+
+task buildNative(type: Exec) {
+    if (System.env.ANDROID_NDK_HOME != null) {
+        //for windows use 'ndk-build.cmd'
+        //def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build.cmd')
+        def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build')
+        commandLine ndkBuild, "-C", file("src/main"), "-B", "-j", Runtime.runtime.availableProcessors(),
+                              "APP_ABI=$TARGET_ARCH", "APP_OPTIM=$RELEASE"
+    } else {
+        println '##################'
+        println 'Skipping NDK build'
+        println 'Reason: ANDROID_NDK_HOME not set.'
+        println '##################'
+    }
+}
diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/sampleService.iml b/resource/csdk/connectivity/samples/android/casample/sampleService/sampleService.iml
new file mode 100755 (executable)
index 0000000..145e474
--- /dev/null
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="casample" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
+  <component name="FacetManager">
+    <facet type="android-gradle" name="Android-Gradle">
+      <configuration>
+        <option name="GRADLE_PROJECT_PATH" value=":sampleService" />
+      </configuration>
+    </facet>
+    <facet type="android" name="Android">
+      <configuration>
+        <option name="SELECTED_BUILD_VARIANT" value="debug" />
+        <option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
+        <option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
+        <option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
+        <option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
+        <option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
+        <option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugAndroidTestSources" />
+        <option name="ALLOW_USER_CONFIGURATION" value="false" />
+        <option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
+        <option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
+        <option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
+        <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
+      </configuration>
+    </facet>
+  </component>
+  <component name="NewModuleRootManager" inherit-compiler-output="false">
+    <output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
+    <output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/androidTest/debug" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
+      <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
+    </content>
+    <orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
+    <orderEntry type="module" module-name="cAInterface" exported="" />
+  </component>
+</module>
+
diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/.gitignore b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/.gitignore
new file mode 100644 (file)
index 0000000..89a3c7d
--- /dev/null
@@ -0,0 +1,3 @@
+/libs/
+/obj/
+/assets/
diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/AndroidManifest.xml b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/AndroidManifest.xml
new file mode 100755 (executable)
index 0000000..4848fee
--- /dev/null
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="org.iotivity.ca.sample_service"
+    android:versionCode="1"
+    android:versionName="1.0" >
+
+    <uses-sdk
+        android:minSdkVersion="21"
+        android:targetSdkVersion="21" />
+
+    <application
+        android:allowBackup="true"
+        android:label="@string/app_name"
+        android:theme="@style/AppTheme" >
+        <activity
+            android:name="org.iotivity.ca.service.MainActivity"
+            android:label="@string/app_name"
+            android:windowSoftInputMode="stateHidden" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+    </application>
+
+    <uses-permission android:name="android.permission.BLUETOOTH" />
+    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
+    <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+    <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
+    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
+
+</manifest>
+
diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/java/org/iotivity/ca/service/DLog.java b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/java/org/iotivity/ca/service/DLog.java
new file mode 100755 (executable)
index 0000000..9fe8422
--- /dev/null
@@ -0,0 +1,90 @@
+
+package org.iotivity.ca.service;
+
+import android.os.Handler;
+import android.widget.TextView;
+
+public final class DLog {
+
+    private final static String MAIN_TAG = "Sample_Service : DLog";
+
+    private static TextView mLogView = null;
+
+    private static Handler mHandler = null;
+
+    public static void setTextView(Handler handler, TextView logView) {
+        mHandler = handler;
+        mLogView = logView;
+    }
+
+    private static void addLogText(final String msg) {
+
+        mHandler.post(new Runnable() {
+
+            @Override
+            public void run() {
+
+                if (mLogView == null)
+                    return;
+
+                StringBuilder builder = new StringBuilder(mLogView.getText());
+                // add front
+                builder.append(msg + "\n");
+
+                mLogView.setText(builder.toString());
+            }
+
+        });
+
+    }
+
+    public static final void v(String className, String msg) {
+        android.util.Log.v(MAIN_TAG, className + "." + msg);
+
+        if (mLogView != null) {
+            addLogText(msg);
+        }
+    }
+
+    public static final void d(String className, String msg) {
+        android.util.Log.d(MAIN_TAG, className + "." + msg);
+
+        if (mLogView != null) {
+            addLogText(msg);
+        }
+    }
+
+    public static final void i(String className, String msg) {
+        android.util.Log.i(MAIN_TAG, className + "." + msg);
+
+        if (mLogView != null) {
+            addLogText(msg);
+        }
+    }
+
+    public static final void w(String className, String msg) {
+        android.util.Log.w(MAIN_TAG, className + "." + msg);
+
+        if (mLogView != null) {
+            addLogText(msg);
+        }
+    }
+
+    public static final void w(String className, String msg, Exception ex) {
+        android.util.Log.w(MAIN_TAG, className + "." + msg + ":" + ex.getMessage());
+
+        if (mLogView != null) {
+            addLogText(msg);
+        }
+    }
+
+    public static final void w(String className, String msg, Error e) {
+        android.util.Log.w(MAIN_TAG, className + "." + msg + ":" + e.getMessage());
+
+        if (mLogView != null) {
+            addLogText(msg);
+        }
+    }
+
+}
+
diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/java/org/iotivity/ca/service/MainActivity.java b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/java/org/iotivity/ca/service/MainActivity.java
new file mode 100755 (executable)
index 0000000..97d37e9
--- /dev/null
@@ -0,0 +1,713 @@
+package org.iotivity.ca.service;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.os.Handler;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+
+import org.iotivity.ca.sample_service.R;
+
+public class MainActivity extends Activity {
+
+    static RMInterface RM = new RMInterface();
+
+    private final static String TAG = "Sample_Service : MainActivity";
+
+    private final CharSequence[] mNetworkCheckBoxItems = { Network.IP.name(),
+            Network.LE.name(), Network.EDR.name()};
+
+    private final CharSequence[] mDTLSCheckBoxItems = { DTLS.UNSECURED.name(),
+            DTLS.SECURED.name() };
+
+    private final CharSequence[] mMsgTyleCheckBoxItems = { MsgType.CON.name(),
+            MsgType.NON.name(), MsgType.ACK.name(), MsgType.RESET.name() };
+
+    private final CharSequence[] mResponseResultCheckBoxItems = {
+            ResponseResult.CA_SUCCESS.name(), ResponseResult.CA_CREATED.name(),
+            ResponseResult.CA_DELETED.name(), ResponseResult.CA_VALID.name(),
+            ResponseResult.CA_CHANGED.name(), ResponseResult.CA_CONTENT.name(),
+            ResponseResult.CA_EMPTY.name(), ResponseResult.CA_BAD_REQ.name(),
+            ResponseResult.CA_BAD_OPT.name(), ResponseResult.CA_NOT_FOUND.name(),
+            ResponseResult.CA_INTERNAL_SERVER_ERROR.name(),
+            ResponseResult.CA_RETRANSMIT_TIMEOUT.name() };
+
+    private enum Mode {
+        SERVER, CLIENT, BOTH, UNKNOWN
+    };
+
+    private enum Network {
+        IP, LE, EDR
+    };
+
+    private enum DTLS {
+        UNSECURED, SECURED
+    };
+
+    private enum MsgType {
+        CON, NON, ACK, RESET
+    };
+
+    private enum ResponseResult {
+        CA_SUCCESS, CA_CREATED, CA_DELETED, CA_VALID, CA_CHANGED, CA_CONTENT, CA_EMPTY,
+        CA_BAD_REQ, CA_BAD_OPT, CA_NOT_FOUND, CA_INTERNAL_SERVER_ERROR, CA_RETRANSMIT_TIMEOUT
+    }
+
+    private boolean mCheckedItems[] = {
+            false, false, false, false
+    };
+
+    private int mSelectedItems[] = { 0, 0, 0 };
+
+    private int mUnSelectedItems[] = { 0, 0, 0 };
+
+    private Mode mCurrentMode = Mode.UNKNOWN;
+
+    private RelativeLayout mSendNotificationLayout = null;
+
+    private RelativeLayout mSendRequestLayout = null;
+
+    private RelativeLayout mSendRequestToAllLayout = null;
+
+    private RelativeLayout mSendRequestSettingLayout = null;
+
+    private RelativeLayout mSendRequestToAllSettingLayout = null;
+
+    private RelativeLayout mSendResponseNotiSettingLayout = null;
+
+    private RelativeLayout mReceiveLayout = null;
+
+    private RelativeLayout mRequestTitleLayout = null;
+
+    private RelativeLayout mRequestToAllTitleLayout = null;
+
+    private RelativeLayout mResponseNotificationTitleLayout = null;
+
+    private RelativeLayout mHandleTitleLayout = null;
+
+    private TextView mMode_tv = null;
+
+    private TextView mNetwork_tv = null;
+
+    private EditText mNotification_ed = null;
+
+    private EditText mReqData_ed = null;
+
+    private EditText mReqToAllData_ed = null;
+
+    private Button mNotify_btn = null;
+
+    private Button mReqeust_btn = null;
+
+    private Button mReqeust_setting_btn = null;
+
+    private Button mReqeustToAll_btn = null;
+
+    private Button mReqeustToAll_setting_btn = null;
+
+    private Button mResponse_Notify_setting_btn = null;
+
+    private Button mResponse_btn = null;
+
+    private Button mGetNetworkInfo_btn = null;
+
+    private Button mRecv_btn = null;
+
+    private Handler mLogHandler = null;
+
+    /**
+     * Defined ConnectivityType in cacommon.c
+     *
+     * CA_IP = (1 << 0) CA_LE = (1 << 2) CA_EDR = (1 << 3)
+     */
+    private int CA_IP = (1 << 0);
+    private int CA_LE = (1 << 1);
+    private int CA_EDR = (1 << 2);
+    private int isSecured = 0;
+    private int msgType = 1;
+    private int responseValue = 0;
+    private int selectedNetworkType = -1;
+    private int selectedMsgType = 1;
+    private int selectedMsgSecured = 0;
+    private int selectedResponseValue = 0;
+    int selectedNetwork = -1;
+    int interestedNetwork = 0;
+    int uninterestedNetwork = 0;
+    private boolean isSendResponseSetting = false;
+    private boolean isSendRequestToAllSetting = false;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_main);
+
+        RM.setResponseListener(this);
+
+        mLogHandler = new Handler();
+        TextView logView = (TextView) findViewById(R.id.tv_result);
+        DLog.setTextView(mLogHandler, logView);
+
+        // Initialize UI
+        // common
+        mReceiveLayout = (RelativeLayout) findViewById(R.id.layout_receive);
+
+        // client
+        mSendRequestLayout = (RelativeLayout) findViewById(R.id.layout_request);
+        mSendRequestToAllLayout = (RelativeLayout) findViewById(R.id.layout_request_to_all);
+        mSendRequestSettingLayout = (RelativeLayout)
+                findViewById(R.id.layout_request_setting_for_client);
+        mSendRequestToAllSettingLayout = (RelativeLayout)
+                findViewById(R.id.layout_request_to_all_setting_for_client);
+        mRequestTitleLayout = (RelativeLayout) findViewById(R.id.layout_request_title);
+        mRequestToAllTitleLayout = (RelativeLayout) findViewById(R.id.layout_request_to_all_title);
+        mHandleTitleLayout = (RelativeLayout) findViewById(R.id.layout_handle_title);
+
+        // server
+        mSendNotificationLayout = (RelativeLayout) findViewById(R.id.layout_notify);
+        mSendResponseNotiSettingLayout = (RelativeLayout)
+                findViewById(R.id.layout_request_setting_for_server);
+        mResponseNotificationTitleLayout = (RelativeLayout)
+                findViewById(R.id.layout_Response_Noti_title);
+
+        mMode_tv = (TextView) findViewById(R.id.tv_mode);
+        mNetwork_tv = (TextView) findViewById(R.id.tv_network);
+
+        mNotification_ed = (EditText) findViewById(R.id.et_notification);
+        mReqData_ed = (EditText) findViewById(R.id.et_req_data);
+        mReqToAllData_ed = (EditText) findViewById(R.id.et_req_to_all_data);
+
+        mResponse_btn = (Button) findViewById(R.id.btn_sendresponse);
+        mNotify_btn = (Button) findViewById(R.id.btn_notify);
+        mReqeust_btn = (Button) findViewById(R.id.btn_Request);
+        mReqeust_setting_btn = (Button) findViewById(R.id.btn_Request_setting_for_client);
+        mReqeustToAll_btn = (Button) findViewById(R.id.btn_request_to_all);
+        mReqeustToAll_setting_btn = (Button)
+                findViewById(R.id.btn_request_to_all_setting_for_client);
+        mResponse_Notify_setting_btn = (Button) findViewById(R.id.btn_Request_setting_for_server);
+        mGetNetworkInfo_btn = (Button) findViewById(R.id.btn_get_network_info);
+        mRecv_btn = (Button) findViewById(R.id.btn_receive);
+
+        mResponse_btn.setOnClickListener(mSendResponseHandler);
+        mNotify_btn.setOnClickListener(mNotifyHandler);
+        mReqeust_btn.setOnClickListener(mSendRequestHandler);
+        mReqeust_setting_btn.setOnClickListener(mSendRequestSettingHandler);
+        mReqeustToAll_btn.setOnClickListener(mSendRequestToAllHandler);
+        mReqeustToAll_setting_btn.setOnClickListener(mSendRequestToAllSettingHandler);
+        mResponse_Notify_setting_btn
+                .setOnClickListener(mSendResponseNotiSettingHandler);
+        mRecv_btn.setOnClickListener(mResponseHandler);
+        mGetNetworkInfo_btn.setOnClickListener(mGetNetworkInfoHandler);
+
+        showSelectModeView();
+
+        // Initialize Connectivity Abstraction
+        RM.RMInitialize(getApplicationContext());
+
+        // set handler
+        RM.RMRegisterHandler();
+    }
+
+    private void showSelectModeView() {
+
+        mSendNotificationLayout.setVisibility(View.INVISIBLE);
+        mSendRequestLayout.setVisibility(View.INVISIBLE);
+        mSendRequestToAllLayout.setVisibility(View.INVISIBLE);
+        mSendRequestSettingLayout.setVisibility(View.INVISIBLE);
+        mSendRequestToAllSettingLayout.setVisibility(View.INVISIBLE);
+        mReceiveLayout.setVisibility(View.INVISIBLE);
+        mRequestTitleLayout.setVisibility(View.INVISIBLE);
+        mRequestToAllTitleLayout.setVisibility(View.INVISIBLE);
+        mHandleTitleLayout.setVisibility(View.INVISIBLE);
+        mResponseNotificationTitleLayout.setVisibility(View.INVISIBLE);
+        mSendResponseNotiSettingLayout.setVisibility(View.INVISIBLE);
+
+        mMode_tv.setText("Select Mode (Server or Client)");
+        Log.i(TAG, "Select Mode (Server or Client)");
+    }
+
+    private void showNetworkView() {
+
+        mNetwork_tv.setText("Select Network Type");
+        Log.i(TAG, "Select Network Type");
+    }
+
+    private void showModeView() {
+
+        if (mCurrentMode == Mode.SERVER) {
+
+            mSendNotificationLayout.setVisibility(View.VISIBLE);
+            mSendRequestLayout.setVisibility(View.INVISIBLE);
+            mSendRequestToAllLayout.setVisibility(View.VISIBLE);
+            mSendRequestSettingLayout.setVisibility(View.INVISIBLE);
+            mSendRequestToAllSettingLayout.setVisibility(View.VISIBLE);
+            mReceiveLayout.setVisibility(View.VISIBLE);
+
+            mRequestTitleLayout.setVisibility(View.INVISIBLE);
+            mRequestToAllTitleLayout.setVisibility(View.VISIBLE);
+            mHandleTitleLayout.setVisibility(View.VISIBLE);
+
+            mResponseNotificationTitleLayout.setVisibility(View.VISIBLE);
+            mSendResponseNotiSettingLayout.setVisibility(View.VISIBLE);
+
+            mNetwork_tv.setText("");
+
+        } else if (mCurrentMode == Mode.CLIENT) {
+
+            mSendNotificationLayout.setVisibility(View.INVISIBLE);
+            mSendRequestLayout.setVisibility(View.VISIBLE);
+            mSendRequestToAllLayout.setVisibility(View.VISIBLE);
+            mSendRequestSettingLayout.setVisibility(View.VISIBLE);
+            mSendRequestToAllSettingLayout.setVisibility(View.VISIBLE);
+            mReceiveLayout.setVisibility(View.VISIBLE);
+
+            mRequestTitleLayout.setVisibility(View.VISIBLE);
+            mRequestToAllTitleLayout.setVisibility(View.VISIBLE);
+            mHandleTitleLayout.setVisibility(View.VISIBLE);
+
+            mResponseNotificationTitleLayout.setVisibility(View.INVISIBLE);
+            mSendResponseNotiSettingLayout.setVisibility(View.INVISIBLE);
+
+            mNetwork_tv.setText("");
+        }
+    }
+
+    @Override
+    protected void onDestroy() {
+        super.onDestroy();
+
+        // Terminate Connectivity Abstraction
+        RM.RMTerminate();
+        android.os.Process.killProcess(android.os.Process.myPid());
+    }
+
+    @Override
+    public boolean onCreateOptionsMenu(Menu menu) {
+
+        menu.add(0, 1, Menu.NONE, "Start Server");
+        menu.add(0, 2, Menu.NONE, "Start Client");
+        menu.add(0, 3, Menu.NONE, "Select Network");
+
+        return true;
+    }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+
+        switch (item.getItemId()) {
+
+        case 1:
+
+            RM.RMStartListeningServer();
+
+            if (interestedNetwork == 0) {
+                mCurrentMode = Mode.SERVER;
+                mMode_tv.setText("MODE: " + mCurrentMode.toString());
+                Log.i(TAG, "MODE: " + mCurrentMode.toString());
+                showNetworkView();
+
+            } else {
+                mCurrentMode = Mode.SERVER;
+                mMode_tv.setText("MODE: " + mCurrentMode.toString());
+                Log.i(TAG, "MODE: " + mCurrentMode.toString());
+                showModeView();
+            }
+
+            break;
+
+        case 2:
+
+            RM.RMStartDiscoveryServer();
+
+            if (interestedNetwork == 0) {
+                mCurrentMode = Mode.CLIENT;
+                mMode_tv.setText("MODE: " + mCurrentMode.toString());
+                Log.i(TAG, "MODE: " + mCurrentMode.toString());
+                showNetworkView();
+
+            } else {
+                mCurrentMode = Mode.CLIENT;
+                mMode_tv.setText("MODE: " + mCurrentMode.toString());
+                Log.i(TAG, "MODE: " + mCurrentMode.toString());
+                showModeView();
+            }
+
+            break;
+
+        case 3:
+
+            checkInterestedNetwork("Select Network");
+
+            break;
+        }
+
+        return super.onOptionsItemSelected(item);
+    }
+
+    private OnClickListener mSendResponseHandler = new OnClickListener() {
+
+        @Override
+        public void onClick(View v) {
+
+            DLog.v(TAG, "SendResponse click");
+            if ( selectedNetwork != -1) {
+                RM.RMSendResponse(selectedNetwork, isSecured, msgType, responseValue);
+            }
+            else {
+                DLog.v(TAG, "Please Select Network Type");
+            }
+        }
+    };
+
+    private OnClickListener mNotifyHandler = new OnClickListener() {
+
+        @Override
+        public void onClick(View v) {
+
+            DLog.v(TAG, "SendNotification click");
+            if ( selectedNetwork != -1) {
+                RM.RMSendNotification(mNotification_ed.getText().toString(),
+                    null, selectedNetwork, isSecured, msgType, responseValue);
+            }
+            else {
+                DLog.v(TAG, "Please Select Network Type");
+            }
+        }
+    };
+
+    private OnClickListener mSendRequestHandler = new OnClickListener() {
+
+        @Override
+        public void onClick(View v) {
+
+            DLog.v(TAG, "SendRequest click");
+            if ( selectedNetwork != -1) {
+                RM.RMSendRequest(mReqData_ed.getText().toString(), null,
+                    selectedNetwork, isSecured, msgType);
+            }
+            else {
+                DLog.v(TAG, "Please Select Network Type");
+            }
+        }
+    };
+
+    private OnClickListener mSendRequestSettingHandler = new OnClickListener() {
+
+        @Override
+        public void onClick(View v) {
+            checkSendNetworkType("Select Send Network Type");
+        }
+    };
+
+    private OnClickListener mSendRequestToAllHandler = new OnClickListener() {
+
+        @Override
+        public void onClick(View v) {
+
+            DLog.v(TAG, "SendRequestToAll click");
+            if ( selectedNetwork != -1) {
+                RM.RMSendReqestToAll(mReqToAllData_ed.getText().toString(), selectedNetwork);
+            }
+            else {
+                DLog.v(TAG, "Please Select Network Type");
+            }
+        }
+    };
+
+    private OnClickListener mSendRequestToAllSettingHandler = new OnClickListener() {
+
+        @Override
+        public void onClick(View v) {
+            isSendRequestToAllSetting = true;
+            checkSendNetworkType("Select Send Network Type");
+        }
+    };
+
+    private OnClickListener mSendResponseNotiSettingHandler = new OnClickListener() {
+
+        @Override
+        public void onClick(View v) {
+            isSendResponseSetting = true;
+            checkSendNetworkType("Select Send Network Type");
+        }
+    };
+
+    private OnClickListener mGetNetworkInfoHandler = new OnClickListener() {
+        @Override
+        public void onClick(View v) {
+
+            RM.RMGetNetworkInfomation();
+        }
+    };
+
+    private OnClickListener mResponseHandler = new OnClickListener() {
+
+        @Override
+        public void onClick(View v) {
+
+            RM.RMHandleRequestResponse();
+        }
+    };
+
+    private void checkInterestedNetwork(String title) {
+
+        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
+        builder.setTitle(title)
+                .setMultiChoiceItems(mNetworkCheckBoxItems, mCheckedItems,
+                        new DialogInterface.OnMultiChoiceClickListener() {
+
+                            @Override
+                            public void onClick(DialogInterface dialog,
+                                    int which, boolean isChecked) {
+
+                                if (isChecked) {
+
+                                    mSelectedItems[which] = 1;
+                                    mUnSelectedItems[which] = 0;
+
+                                } else if (mSelectedItems[which] == 1) {
+
+                                    mSelectedItems[which] = 0;
+                                    mUnSelectedItems[which] = 1;
+                                }
+                            }
+                        })
+                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+
+                    @Override
+                    public void onClick(DialogInterface dialog, int which) {
+
+                        interestedNetwork = 0;
+
+                        for (int i = 0; i < mSelectedItems.length; i++) {
+                            if (mSelectedItems[i] == 1) {
+                                interestedNetwork |= (1 << i);
+                            }
+                        }
+                        if(0 != interestedNetwork)
+                            RM.RMSelectNetwork(interestedNetwork);
+
+                        uninterestedNetwork = 0;
+
+                        for (int i = 0; i < mUnSelectedItems.length; i++) {
+                            if (mUnSelectedItems[i] == 1) {
+                                uninterestedNetwork |= (1 << i);
+                            }
+                        }
+                        if(0 != uninterestedNetwork)
+                            RM.RMUnSelectNetwork(uninterestedNetwork);
+
+                    }
+                }).show();
+    }
+
+    private void checkMsgSecured(String title) {
+
+        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
+
+        builder.setTitle(title)
+                .setSingleChoiceItems(mDTLSCheckBoxItems, selectedMsgSecured,
+                        new DialogInterface.OnClickListener() {
+
+                            @Override
+                            public void onClick(DialogInterface dialog,
+                                    int which) {
+                                selectedMsgSecured = which;
+                            }
+                        })
+                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+
+                    @Override
+                    public void onClick(DialogInterface dialog, int which) {
+
+                        if (selectedMsgSecured == DTLS.SECURED.ordinal()) {
+                            isSecured = 1;
+                            DLog.v(TAG, "Send secured message");
+
+                        } else if (selectedMsgSecured == DTLS.UNSECURED.ordinal()) {
+                            isSecured = 0;
+                            DLog.v(TAG, "Send unsecured message");
+                        }
+                        checkMsgType("Select Msg Type");
+                    }
+
+                }).show();
+    }
+
+    private void checkMsgType(String title) {
+
+        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
+        builder.setTitle(title)
+                .setSingleChoiceItems(mMsgTyleCheckBoxItems, selectedMsgType,
+                        new DialogInterface.OnClickListener() {
+
+                            @Override
+                            public void onClick(DialogInterface dialog,
+                                    int which) {
+                                selectedMsgType = which;
+                            }
+                        })
+                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+
+                    @Override
+                    public void onClick(DialogInterface dialog, int which) {
+
+                        if (selectedMsgType == MsgType.CON.ordinal()) {
+                            msgType = 0;
+                            DLog.v(TAG, "Message Type is CON");
+
+                        } else if (selectedMsgType == MsgType.NON.ordinal()) {
+                            msgType = 1;
+                            DLog.v(TAG, "Message Type is NON");
+                        } else if (selectedMsgType == MsgType.ACK.ordinal()) {
+                            msgType = 2;
+                            DLog.v(TAG, "Message Type is ACK");
+                        } else if (selectedMsgType == MsgType.RESET.ordinal()) {
+                            msgType = 3;
+                            DLog.v(TAG, "Message Type is RESET");
+                            }
+
+                        if (isSendResponseSetting == true && msgType != 3) {
+                            checkResponseResult("Select Value of Response Result");
+                            isSendResponseSetting = false;
+                        }
+                    }
+                }).show();
+    }
+
+    private void checkResponseResult(String title) {
+
+        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
+        builder.setTitle(title)
+                .setSingleChoiceItems(mResponseResultCheckBoxItems, selectedResponseValue,
+                        new DialogInterface.OnClickListener() {
+
+                            @Override
+                            public void onClick(DialogInterface dialog,
+                                    int which) {
+                                selectedResponseValue = which;
+                            }
+                        })
+                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+
+                    @Override
+                    public void onClick(DialogInterface dialog, int which) {
+
+                        if (selectedResponseValue == ResponseResult.CA_SUCCESS.ordinal()) {
+                            responseValue = 200;
+                            DLog.v(TAG, "Response Value is CA_SUCCESS");
+                        } else if (selectedResponseValue == ResponseResult.CA_CREATED
+                                .ordinal()) {
+                            responseValue = 201;
+                            DLog.v(TAG, "Response Value is CA_CREATED");
+                        } else if (selectedResponseValue == ResponseResult.CA_DELETED
+                                .ordinal()) {
+                            responseValue = 202;
+                            DLog.v(TAG, "Response Value is CA_DELETED");
+                        } else if (selectedResponseValue == ResponseResult.CA_VALID
+                                .ordinal()) {
+                            responseValue = 203;
+                            DLog.v(TAG, "Response Value is CA_VALID");
+                        } else if (selectedResponseValue == ResponseResult.CA_CHANGED
+                                .ordinal()) {
+                            responseValue = 204;
+                            DLog.v(TAG, "Response Value is CA_CHANGED");
+                        } else if (selectedResponseValue == ResponseResult.CA_CONTENT
+                                .ordinal()) {
+                            responseValue = 205;
+                            DLog.v(TAG, "Response Value is CA_CONTENT");
+                        } else if (selectedResponseValue == ResponseResult.CA_EMPTY
+                                .ordinal()) {
+                            responseValue = 0;
+                            DLog.v(TAG, "Response Value is CA_EMPTY");
+                        } else if (selectedResponseValue == ResponseResult.CA_BAD_REQ
+                                .ordinal()) {
+                            responseValue = 400;
+                            DLog.v(TAG, "Response Value is CA_BAD_REQ");
+                        } else if (selectedResponseValue == ResponseResult.CA_BAD_OPT
+                                .ordinal()) {
+                            responseValue = 402;
+                            DLog.v(TAG, "Response Value is CA_BAD_OPT");
+                        } else if (selectedResponseValue == ResponseResult.CA_NOT_FOUND
+                                .ordinal()) {
+                            responseValue = 404;
+                            DLog.v(TAG, "Response Value is CA_NOT_FOUND");
+                        } else if (selectedResponseValue ==
+                                ResponseResult.CA_INTERNAL_SERVER_ERROR
+                                .ordinal()) {
+                            responseValue = 500;
+                            DLog.v(TAG, "Response Value is CA_INTERNAL_SERVER_ERROR");
+                        } else if (selectedResponseValue == ResponseResult.CA_RETRANSMIT_TIMEOUT
+                                .ordinal()) {
+                            responseValue = 504;
+                            DLog.v(TAG, "Response Value is CA_RETRANSMIT_TIMEOUT");
+                        }
+                    }
+                }).show();
+    }
+
+    private void checkSendNetworkType(String title) {
+        selectedNetworkType = -1;
+        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
+
+        builder.setTitle(title)
+                .setSingleChoiceItems(mNetworkCheckBoxItems, -1,
+                        new DialogInterface.OnClickListener() {
+
+                            @Override
+                            public void onClick(DialogInterface dialog,
+                                    int which) {
+                                selectedNetworkType = which;
+                            }
+                        })
+                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+
+                    @Override
+                    public void onClick(DialogInterface dialog, int which) {
+
+                        if (selectedNetworkType == Network.IP.ordinal()) {
+                            selectedNetwork = CA_IP;
+                            DLog.v(TAG, "Selected Network is CA_IP");
+                        } else if (selectedNetworkType == Network.LE.ordinal()) {
+                            selectedNetwork = CA_LE;
+                            DLog.v(TAG, "Selected Network is LE");
+                        } else if (selectedNetworkType == Network.EDR.ordinal()) {
+                            selectedNetwork = CA_EDR;
+                            DLog.v(TAG, "Selected Network is EDR");
+                        } else {
+                            DLog.v(TAG, "Selected Network is NULL");
+                            selectedNetwork = -1;
+                        }
+
+                        if (isSendRequestToAllSetting != true) {
+                            checkMsgSecured("Select DTLS Type");
+                        }
+                        isSendRequestToAllSetting = false;
+                    }
+                }).show();
+    }
+
+    public void OnResponseReceived(String subject, String receivedData) {
+        String callbackData = subject + receivedData;
+        DLog.v(TAG, callbackData);
+
+        if (subject.equals(getString(R.string.remote_address))) {
+            StringBuilder sb = new StringBuilder();
+            sb.append(getString(R.string.coap_prefix)).append(receivedData);
+            if (receivedData.contains(".")) { // IP
+                sb.append(getString(R.string.port_num));
+            }
+            sb.append(getString(R.string.uri));
+            mReqData_ed.setText(sb.toString());
+            mNotification_ed.setText(sb.toString());
+        }
+    }
+}
diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/java/org/iotivity/ca/service/RMInterface.java b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/java/org/iotivity/ca/service/RMInterface.java
new file mode 100755 (executable)
index 0000000..0c9db02
--- /dev/null
@@ -0,0 +1,60 @@
+package org.iotivity.ca.service;
+
+import android.content.Context;
+
+public class RMInterface {
+
+    static {
+        // Load RI JNI interface
+        System.loadLibrary("RMInterface");
+    }
+
+    private org.iotivity.ca.service.MainActivity mResponseListener = null;
+
+    public native void setNativeResponseListener(Object listener);
+
+    public native void RMInitialize(Context context);
+
+    public native void RMTerminate();
+
+    public native void RMStartListeningServer();
+
+    public native void RMStartDiscoveryServer();
+
+    public native void RMRegisterHandler();
+
+    public native void RMFindResource(String uri);
+
+    public native void RMSendRequest(String uri, String payload,
+            int selectedNetwork, int isSecured, int msgType);
+
+    public native void RMSendReqestToAll(String uri, int selectedNetwork);
+
+    public native void RMSendResponse(int selectedNetwork, int isSecured,
+            int msgType, int responseValue);
+
+    public native void RMAdvertiseResource(String advertiseResource);
+
+    public native void RMSendNotification(String uri, String payload,
+            int selectedNetwork, int isSecured, int msgType, int responseValue);
+
+    public native void RMSelectNetwork(int interestedNetwork);
+
+    public native void RMUnSelectNetwork(int uninterestedNetwork);
+
+    public native void RMGetNetworkInfomation();
+
+    public native void RMHandleRequestResponse();
+
+    public void setResponseListener(org.iotivity.ca.service.MainActivity listener) {
+        mResponseListener = listener;
+        setNativeResponseListener(this);
+    }
+
+    private void OnResponseReceived(String subject, String receivedData) {
+        if (null != mResponseListener) {
+            mResponseListener.OnResponseReceived(subject, receivedData);
+        }
+    }
+
+}
diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/Android.mk b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/Android.mk
new file mode 100755 (executable)
index 0000000..be764d8
--- /dev/null
@@ -0,0 +1,14 @@
+APP_PATH := $(call my-dir)
+#specify project root path here wrt make file directory
+PROJECT_ROOT_PATH      = ../../../../../../
+include $(CLEAR_VARS)
+LOCAL_PATH= $(PROJECT_ROOT_PATH)/../../../out/android/$(APP_ABI)/$(APP_OPTIM)/resource/csdk/connectivity/src
+LOCAL_SRC_FILES = libconnectivity_abstraction.so
+LOCAL_MODULE = CA
+include $(PREBUILT_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_PATH= $(PROJECT_ROOT_PATH)/../../../out/android/$(APP_ABI)/$(APP_OPTIM)/resource/csdk/connectivity/samples/android
+LOCAL_SRC_FILES = libRMInterface.so
+LOCAL_MODULE = CASAMPLE
+include $(PREBUILT_SHARED_LIBRARY)
diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/Application.mk b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/Application.mk
new file mode 100755 (executable)
index 0000000..ed9b8b6
--- /dev/null
@@ -0,0 +1,8 @@
+
+APP_PROJECT_PATH = ./
+APP_STL := gnustl_shared
+
+APP_PLATFORM = android-21
+APP_CPPFLAGS += -fexceptions
+APP_CPPFLAGS += -frtti
+APP_CFLAGS = -Wno-error=format-security
diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/ResourceModel.c b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/ResourceModel.c
new file mode 100755 (executable)
index 0000000..21ba6b9
--- /dev/null
@@ -0,0 +1,1410 @@
+#include <jni.h>
+#include <android/log.h>
+#include <stdio.h>
+#include <dlfcn.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "cainterface.h"
+#include "cacommon.h"
+
+#include "org_iotivity_ca_service_RMInterface.h"
+
+#define  LOG_TAG   "JNI_INTERFACE_SAMPLE"
+#define  LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
+#define  LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
+
+/**
+ * @def RS_IDENTITY
+ * @brief
+ */
+#define IDENTITY     ("1111111111111111")
+/* @def RS_CLIENT_PSK
+ * @brief
+ */
+#define RS_CLIENT_PSK   ("AAAAAAAAAAAAAAAA")
+
+#define PORT_LENGTH 5
+#define SECURE_DEFAULT_PORT 5684
+#define RESOURCE_URI_LENGTH 14
+#define OPTION_INFO_LENGTH 1024
+#define NETWORK_INFO_LENGTH 1024
+
+typedef struct
+{
+    char ipAddress[CA_IPADDR_SIZE];
+    uint16_t port;
+} addressSet_t;
+
+void request_handler(const CAEndpoint_t* object, const CARequestInfo_t* requestInfo);
+void response_handler(const CAEndpoint_t* object, const CAResponseInfo_t* responseInfo);
+void error_handler(const CAEndpoint_t *object, const CAErrorInfo_t* errorInfo);
+void get_resource_uri(const char *URI, char *resourceURI, uint32_t length);
+uint32_t get_secure_information(CAPayload_t payLoad);
+CAResult_t get_network_type(uint32_t selectedNetwork);
+void callback(char *subject, char *receivedData);
+CAResult_t get_remote_address(CATransportAdapter_t transportType, const char *address);
+void parsing_coap_uri(const char* uri, addressSet_t* address, CATransportFlags_t *flags);
+
+uint16_t g_localSecurePort = SECURE_DEFAULT_PORT;
+CATransportAdapter_t g_selectedNwType = CA_ADAPTER_IP;
+static CAToken_t g_lastRequestToken = NULL;
+static uint8_t g_lastRequestTokenLength = 0;
+
+static const char COAP_PREFIX[] =  "coap://";
+static const char COAPS_PREFIX[] = "coaps://";
+static const uint16_t COAP_PREFIX_LEN = sizeof(COAP_PREFIX) - 1;
+static const uint16_t COAPS_PREFIX_LEN = sizeof(COAPS_PREFIX) - 1;
+
+static const char SECURE_INFO_DATA[]
+                                   = "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
+                                     "\"if\":[\"oic.if.baseline\"],\"obs\":1,\"sec\":1,\"port\":"
+                                     "%d}}]}";
+static const char NORMAL_INFO_DATA[]
+                                   = "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
+                                     "\"if\":[\"oic.if.baseline\"],\"obs\":1}}]}";
+
+static jobject g_responseListenerObject = NULL;
+static JavaVM *g_jvm;
+
+static CAEndpoint_t *g_clientEndpoint = NULL;
+static char *g_resourceUri = NULL;
+static CAToken_t g_clientToken = NULL;
+static uint8_t g_clientTokenLength = 0;
+
+static uint16_t g_clientMsgId = 0;
+static char *g_remoteAddress = NULL;
+
+// init
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_service_RMInterface_setNativeResponseListener(JNIEnv *env, jobject obj,
+                                                                   jobject listener)
+{
+    LOGI("setNativeResponseListener");
+    g_responseListenerObject = (*env)->NewGlobalRef(env, obj);
+}
+
+#ifdef __WITH_DTLS__
+static CADtlsPskCredsBlob_t *pskCredsBlob = NULL;
+
+void clearDtlsCredentialInfo()
+{
+    LOGI("clearDtlsCredentialInfo IN");
+    if (pskCredsBlob)
+    {
+        // Initialize sensitive data to zeroes before freeing.
+        if (NULL != pskCredsBlob->creds)
+        {
+            memset(pskCredsBlob->creds, 0, sizeof(OCDtlsPskCreds)*(pskCredsBlob->num));
+            free(pskCredsBlob->creds);
+        }
+
+        memset(pskCredsBlob, 0, sizeof(CADtlsPskCredsBlob_t));
+        free(pskCredsBlob);
+        pskCredsBlob = NULL;
+    }
+    LOGI("clearDtlsCredentialInfo OUT");
+}
+
+// Internal API. Invoked by OC stack to retrieve credentials from this module
+void CAGetDtlsPskCredentials(CADtlsPskCredsBlob_t **credInfo)
+{
+    LOGI("CAGetDtlsPskCredentials IN");
+    *credInfo = (CADtlsPskCredsBlob_t *) malloc(sizeof(CADtlsPskCredsBlob_t));
+    if (NULL == *credInfo)
+    {
+        LOGE("Failed to allocate credential blob.");
+        return;
+    }
+
+    int16_t credLen = sizeof(OCDtlsPskCreds) * (pskCredsBlob->num);
+    (*credInfo)->creds = (OCDtlsPskCreds *) malloc(credLen);
+    if (NULL == (*credInfo)->creds)
+    {
+        LOGE("Failed to allocate crentials.");
+        free(*credInfo);
+        *credInfo = NULL;
+        return;
+    }
+
+    memcpy((*credInfo)->identity, pskCredsBlob->identity, DTLS_PSK_ID_LEN);
+    (*credInfo)->num = pskCredsBlob->num;
+    memcpy((*credInfo)->creds, pskCredsBlob->creds, credLen);
+
+    LOGI("CAGetDtlsPskCredentials OUT");
+}
+
+CAResult_t SetCredentials()
+{
+    LOGI("SetCredentials IN");
+    pskCredsBlob = (CADtlsPskCredsBlob_t *)malloc(sizeof(CADtlsPskCredsBlob_t));
+    if (NULL == pskCredsBlob)
+    {
+        LOGE("Memory allocation failed!");
+        return CA_MEMORY_ALLOC_FAILED;
+    }
+    memcpy(pskCredsBlob->identity, IDENTITY, DTLS_PSK_ID_LEN);
+
+    pskCredsBlob->num = 1;
+
+    pskCredsBlob->creds = (OCDtlsPskCreds *)malloc(sizeof(OCDtlsPskCreds) *(pskCredsBlob->num));
+    if (NULL == pskCredsBlob->creds)
+    {
+        LOGE("Memory allocation failed!");
+        return CA_MEMORY_ALLOC_FAILED;
+    }
+    memcpy(pskCredsBlob->creds[0].id, IDENTITY, DTLS_PSK_ID_LEN);
+    memcpy(pskCredsBlob->creds[0].psk, RS_CLIENT_PSK, DTLS_PSK_PSK_LEN);
+
+    LOGI("SetCredentials OUT");
+    return CA_STATUS_OK;
+}
+#endif
+
+JNIEXPORT jint JNI_OnLoad(JavaVM *jvm, void *reserved)
+{
+    LOGI("JNI_OnLoad");
+
+    JNIEnv* env;
+    if (JNI_OK != (*jvm)->GetEnv(jvm, (void**) &env, JNI_VERSION_1_6))
+    {
+        return -1;
+    }
+    g_jvm = jvm; /* cache the JavaVM pointer */
+
+    CANativeJNISetJavaVM(g_jvm);
+
+    return JNI_VERSION_1_6;
+}
+
+void JNI_OnUnload(JavaVM *jvm, void *reserved)
+{
+    LOGI("JNI_OnUnload");
+
+    JNIEnv* env;
+    if (JNI_OK != (*jvm)->GetEnv(jvm, (void**) &env, JNI_VERSION_1_6))
+    {
+        return;
+    }
+    g_jvm = 0;
+    return;
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_service_RMInterface_RMInitialize(JNIEnv *env, jobject obj, jobject context)
+{
+    LOGI("RMInitialize");
+
+    //Currently set context for Android Platform
+    CANativeJNISetContext(env, context);
+
+    CAResult_t res = CAInitialize();
+
+    if (CA_STATUS_OK != res)
+    {
+        LOGE("Could not Initialize");
+    }
+
+#ifdef __WITH_DTLS__
+    if (CA_STATUS_OK != SetCredentials())
+    {
+        LOGE("SetCredentials failed");
+        return;
+    }
+
+    res = CARegisterDTLSCredentialsHandler(CAGetDtlsPskCredentials);
+    if(CA_STATUS_OK != res)
+    {
+        LOGE("Set credential handler fail");
+        return;
+    }
+#endif
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_service_RMInterface_RMTerminate(JNIEnv *env, jobject obj)
+{
+    LOGI("RMTerminate");
+    CADestroyToken(g_lastRequestToken);
+    CATerminate();
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_service_RMInterface_RMStartListeningServer(JNIEnv *env, jobject obj)
+{
+    LOGI("RMStartListeningServer");
+
+    if (CA_STATUS_OK != CAStartListeningServer())
+    {
+        LOGE("Could not start Listening server");
+    }
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_service_RMInterface_RMStartDiscoveryServer(JNIEnv *env, jobject obj)
+{
+    LOGI("RMStartDiscoveryServer");
+
+    if (CA_STATUS_OK != CAStartDiscoveryServer())
+    {
+        LOGE("Could not start discovery server");
+    }
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_service_RMInterface_RMRegisterHandler(JNIEnv *env, jobject obj)
+{
+    LOGI("RMRegisterHandler");
+
+    CARegisterHandler(request_handler, response_handler, error_handler);
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_service_RMInterface_RMSendRequest(JNIEnv *env, jobject obj, jstring uri,
+                                                       jstring payload, jint selectedNetwork,
+                                                       jint isSecured, jint msgType)
+{
+    LOGI("selectedNetwork - %d", selectedNetwork);
+    CAResult_t res = get_network_type(selectedNetwork);
+    if (CA_STATUS_OK != res)
+    {
+        return;
+    }
+
+    const char* strUri = (*env)->GetStringUTFChars(env, uri, NULL);
+    LOGI("RMSendRequest - %s", strUri);
+
+    CATransportFlags_t flags;
+    addressSet_t address = {};
+    parsing_coap_uri(strUri, &address, &flags);
+
+    //create remote endpoint
+    CAEndpoint_t* endpoint = NULL;
+    res = CACreateEndpoint(flags, g_selectedNwType, (const char*)address.ipAddress,
+                           address.port, &endpoint);
+    if (CA_STATUS_OK != res)
+    {
+        LOGE("Could not create remote end point");
+        (*env)->ReleaseStringUTFChars(env, uri, strUri);
+        return;
+    }
+
+    CAMessageType_t messageType = msgType;
+
+    // create token
+    CAToken_t token = NULL;
+    uint8_t tokenLength = CA_MAX_TOKEN_LEN;
+
+    res = CAGenerateToken(&token, tokenLength);
+    if ((CA_STATUS_OK != res) || (!token))
+    {
+        LOGE("token generate error!!");
+        // destroy remote endpoint
+        CADestroyEndpoint(endpoint);
+        (*env)->ReleaseStringUTFChars(env, uri, strUri);
+        return;
+    }
+
+    char resourceURI[RESOURCE_URI_LENGTH + 1] = { 0 };
+
+    get_resource_uri((const CAURI_t) strUri, resourceURI, RESOURCE_URI_LENGTH);
+    (*env)->ReleaseStringUTFChars(env, uri, strUri);
+
+    CAInfo_t requestData = { 0 };
+    requestData.token = token;
+    requestData.tokenLength = tokenLength;
+
+    if (1 == isSecured)
+    {
+        uint32_t length = sizeof(SECURE_INFO_DATA) + strlen(resourceURI);
+        requestData.payload = (CAPayload_t) malloc(length);
+        if (NULL == requestData.payload)
+        {
+            LOGE("Memory allocation failed!");
+            // destroy token
+            CADestroyToken(token);
+            // destroy remote endpoint
+            CADestroyEndpoint(endpoint);
+            return;
+        }
+        snprintf(requestData.payload, length, SECURE_INFO_DATA, resourceURI, g_localSecurePort);
+        requestData.payloadSize = length;
+    }
+    else
+    {
+        uint32_t length = sizeof(NORMAL_INFO_DATA) + strlen(resourceURI);
+        requestData.payload = (CAPayload_t) malloc(length);
+        if (NULL == requestData.payload)
+        {
+            LOGE("Memory allocation failed!");
+            // destroy token
+            CADestroyToken(token);
+            // destroy remote endpoint
+            CADestroyEndpoint(endpoint);
+            return;
+        }
+        snprintf(requestData.payload, length, NORMAL_INFO_DATA, resourceURI);
+        requestData.payloadSize = length;
+    }
+
+    requestData.type = messageType;
+    requestData.resourceUri = (CAURI_t) malloc(sizeof(resourceURI));
+    if (NULL == requestData.resourceUri)
+    {
+        LOGE("Memory allocation failed!");
+        // destroy token
+        CADestroyToken(token);
+        // destroy remote endpoint
+        CADestroyEndpoint(endpoint);
+        free(requestData.payload);
+        return;
+    }
+    memcpy(requestData.resourceUri, resourceURI, sizeof(resourceURI));
+
+    CARequestInfo_t requestInfo = { 0 };
+    requestInfo.method = CA_GET;
+    requestInfo.isMulticast = false;
+    requestInfo.info = requestData;
+
+    // send request
+    if (CA_STATUS_OK != CASendRequest(endpoint, &requestInfo))
+    {
+        LOGE("Could not send request");
+    }
+
+    // destroy token
+    CADestroyToken(token);
+
+    // destroy remote endpoint
+    CADestroyEndpoint(endpoint);
+
+    free(requestData.payload);
+    free(requestData.resourceUri);
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_service_RMInterface_RMSendReqestToAll(JNIEnv *env, jobject obj, jstring uri,
+                                                           jint selectedNetwork)
+{
+    LOGI("selectedNetwork - %d", selectedNetwork);
+    CAResult_t res = get_network_type(selectedNetwork);
+    if (CA_STATUS_OK != res)
+    {
+        return;
+    }
+
+    // create remote endpoint
+    CAEndpoint_t *endpoint = NULL;
+    res = CACreateEndpoint(CA_DEFAULT_FLAGS, g_selectedNwType, NULL, 0, &endpoint);
+
+    if (CA_STATUS_OK != res)
+    {
+        LOGE("create remote endpoint error, error code: %d", res);
+        return;
+    }
+
+    // create token
+    CAToken_t token = NULL;
+    uint8_t tokenLength = CA_MAX_TOKEN_LEN;
+
+    res = CAGenerateToken(&token, tokenLength);
+    if ((CA_STATUS_OK != res) || (!token))
+    {
+        LOGE("token generate error!!");
+        // destroy remote endpoint
+        CADestroyEndpoint(endpoint);
+        return;
+    }
+
+    LOGI("generated token %s", token);
+
+    CAInfo_t requestData = { 0 };
+    requestData.token = token;
+    requestData.tokenLength = tokenLength;
+    requestData.payload = (CAPayload_t) "TempJsonPayload";
+    requestData.payloadSize = strlen((const char *) requestData.payload);
+    requestData.type = CA_MSG_NONCONFIRM;
+
+    const char* strUri = (*env)->GetStringUTFChars(env, uri, NULL);
+    LOGI("resourceUri - %s", strUri);
+    requestData.resourceUri = (CAURI_t)strUri;
+
+    uint8_t optionNum = 2;
+    CAHeaderOption_t *headerOpt = (CAHeaderOption_t*) calloc(1,
+                                                             sizeof(CAHeaderOption_t) * optionNum);
+    if (NULL == headerOpt)
+    {
+        LOGE("Memory allocation failed");
+        // destroy remote endpoint
+        CADestroyEndpoint(endpoint);
+        return;
+    }
+
+    char* FirstOptionData = "Hello";
+    headerOpt[0].optionID = 3000;
+    memcpy(headerOpt[0].optionData, FirstOptionData, strlen(FirstOptionData));
+    headerOpt[0].optionLength = (uint16_t) strlen(FirstOptionData);
+
+    char* SecondOptionData2 = "World";
+    headerOpt[1].optionID = 3001;
+    memcpy(headerOpt[1].optionData, SecondOptionData2, strlen(SecondOptionData2));
+    headerOpt[1].optionLength = (uint16_t) strlen(SecondOptionData2);
+
+    requestData.numOptions = optionNum;
+    requestData.options = headerOpt;
+
+    CARequestInfo_t requestInfo = { 0 };
+    requestInfo.method = CA_GET;
+    requestInfo.isMulticast = true;
+    requestInfo.info = requestData;
+
+    // send request to all
+    res = CASendRequest(endpoint, &requestInfo);
+    if (CA_STATUS_OK != res)
+    {
+        LOGE("Could not send request to all");
+        //destroy token
+        CADestroyToken(token);
+    }
+    else
+    {
+        CADestroyToken(g_lastRequestToken);
+        g_lastRequestToken = token;
+        g_lastRequestTokenLength = tokenLength;
+    }
+
+    //ReleaseStringUTFChars for strUri
+    (*env)->ReleaseStringUTFChars(env, uri, strUri);
+
+    free(headerOpt);
+
+    // destroy remote endpoint
+    CADestroyEndpoint(endpoint);
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_service_RMInterface_RMSendResponse(JNIEnv *env, jobject obj,
+                                                        jint selectedNetwork,
+                                                        jint isSecured, jint msgType,
+                                                        jint responseValue)
+{
+    LOGI("RMSendResponse");
+
+    LOGI("selectedNetwork - %d", selectedNetwork);
+
+    CAResult_t res = get_network_type(selectedNetwork);
+    if (CA_STATUS_OK != res)
+    {
+        LOGE("Not supported network type");
+        return;
+    }
+
+    if (NULL == g_clientEndpoint)
+    {
+        LOGE("No Request received");
+        return;
+    }
+
+    CAMessageType_t messageType = msgType;
+
+    CAInfo_t responseData = { 0 };
+    responseData.type = messageType;
+    responseData.messageId = g_clientMsgId;
+    responseData.resourceUri = (CAURI_t)g_resourceUri;
+
+    CAResponseInfo_t responseInfo = { 0 };
+
+    if (msgType != CA_MSG_RESET)
+    {
+        responseData.token = g_clientToken;
+        responseData.tokenLength = g_clientTokenLength;
+        responseInfo.result = responseValue;
+
+        if (1 == isSecured)
+        {
+            uint32_t length = strlen(SECURE_INFO_DATA) + strlen(g_resourceUri) + 1;
+            responseData.payload = (CAPayload_t) malloc(length);
+            sprintf(responseData.payload, SECURE_INFO_DATA, g_resourceUri,
+                    g_localSecurePort);
+            responseData.payloadSize = length;
+        }
+        else
+        {
+            uint32_t length = strlen(NORMAL_INFO_DATA) + strlen(g_resourceUri) + 1;
+            responseData.payload = (CAPayload_t) malloc(length);
+            sprintf(responseData.payload, NORMAL_INFO_DATA, g_resourceUri);
+            responseData.payloadSize = length;
+        }
+    }
+    //msgType is RESET
+    else
+    {
+        responseInfo.result = CA_EMPTY;
+    }
+
+    responseInfo.info = responseData;
+
+    // send response
+    res = CASendResponse(g_clientEndpoint, &responseInfo);
+    if (CA_STATUS_OK != res)
+    {
+        LOGE("Could not send response");
+    }
+
+    // destroy token
+    CADestroyToken(g_clientToken);
+    g_clientToken = NULL;
+    g_clientTokenLength = 0;
+
+    // destroy remote endpoint
+    CADestroyEndpoint(g_clientEndpoint);
+    g_clientEndpoint = NULL;
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_service_RMInterface_RMSendNotification(JNIEnv *env, jobject obj, jstring uri,
+                                                            jstring payload, jint selectedNetwork,
+                                                            jint isSecured, jint msgType,
+                                                            jint responseValue)
+{
+    LOGI("selectedNetwork - %d", selectedNetwork);
+
+    CAResult_t res = get_network_type(selectedNetwork);
+    if (CA_STATUS_OK != res)
+    {
+        LOGE("Not supported network type");
+        return;
+    }
+
+    const char* strUri = (*env)->GetStringUTFChars(env, uri, NULL);
+    LOGI("RMSendNotification - %s", strUri);
+
+    CATransportFlags_t flags;
+    addressSet_t address = {};
+    parsing_coap_uri(strUri, &address, &flags);
+
+    //create remote endpoint
+    CAEndpoint_t* endpoint = NULL;
+    if (CA_STATUS_OK != CACreateEndpoint(flags, g_selectedNwType,
+                                         (const char*)address.ipAddress,
+                                         address.port, &endpoint))
+    {
+        //ReleaseStringUTFChars for strUri
+        (*env)->ReleaseStringUTFChars(env, uri, strUri);
+        LOGE("Could not create remote end point");
+        return;
+    }
+
+    char resourceURI[RESOURCE_URI_LENGTH + 1] = { 0 };
+    get_resource_uri(strUri, resourceURI, RESOURCE_URI_LENGTH);
+
+    //ReleaseStringUTFChars for strUri
+    (*env)->ReleaseStringUTFChars(env, uri, strUri);
+
+    CAMessageType_t messageType = msgType;
+
+    // create token
+    CAToken_t token = NULL;
+    uint8_t tokenLength = CA_MAX_TOKEN_LEN;
+
+    res = CAGenerateToken(&token, tokenLength);
+    if ((CA_STATUS_OK != res) || (!token))
+    {
+        LOGE("token generate error!");
+        CADestroyEndpoint(endpoint);
+        return;
+    }
+
+    CAInfo_t responseData = { 0 };
+    responseData.token = token;
+    responseData.tokenLength = tokenLength;
+    responseData.resourceUri = (CAURI_t) malloc(sizeof(resourceURI));
+    if (NULL == responseData.resourceUri)
+    {
+        LOGE("Memory allocation failed!");
+        // destroy token
+        CADestroyToken(token);
+        // destroy remote endpoint
+        CADestroyEndpoint(endpoint);
+        return;
+    }
+    memcpy(responseData.resourceUri, resourceURI, sizeof(resourceURI));
+
+    if (1 == isSecured)
+    {
+        uint32_t length = sizeof(SECURE_INFO_DATA) + strlen(resourceURI);
+        responseData.payload = (CAPayload_t) malloc(length);
+        if (NULL == responseData.payload)
+        {
+            LOGE("Memory allocation failed!");
+            // destroy token
+            CADestroyToken(token);
+            // destroy remote endpoint
+            CADestroyEndpoint(endpoint);
+
+            free(responseData.resourceUri);
+            return;
+        }
+        snprintf(responseData.payload, length, SECURE_INFO_DATA, resourceURI, g_localSecurePort);
+    }
+    else
+    {
+        uint32_t length = sizeof(NORMAL_INFO_DATA) + strlen(resourceURI);
+        responseData.payload = (CAPayload_t) malloc(length);
+        if (NULL == responseData.payload)
+        {
+            LOGE("Memory allocation failed!");
+            // destroy token
+            CADestroyToken(token);
+            // destroy remote endpoint
+            CADestroyEndpoint(endpoint);
+
+            free(responseData.resourceUri);
+            return;
+        }
+        snprintf(responseData.payload, length, NORMAL_INFO_DATA, resourceURI);
+    }
+
+    responseData.type = messageType;
+
+    CAResponseInfo_t responseInfo = { 0 };
+    responseInfo.result = responseValue;
+    responseInfo.info = responseData;
+
+    // send notification
+    if (CA_STATUS_OK != CASendNotification(endpoint, &responseInfo))
+    {
+        LOGE("Could not send notification");
+    }
+
+    LOGI("Send Notification");
+
+    // destroy token
+    CADestroyToken(token);
+
+    // destroy remote endpoint
+    CADestroyEndpoint(endpoint);
+
+    free(responseData.payload);
+    free(responseData.resourceUri);
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_service_RMInterface_RMSelectNetwork(JNIEnv *env, jobject obj,
+                                                         jint networkType)
+{
+    LOGI("RMSelectNetwork Type : %d", networkType);
+
+    if (CA_STATUS_OK != CASelectNetwork(networkType))
+    {
+        LOGE("Could not select network");
+    }
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_service_RMInterface_RMUnSelectNetwork(JNIEnv *env, jobject obj,
+                                                           jint networkType)
+{
+    LOGI("RMUnSelectNetwork Type : %d", networkType);
+
+    if (CA_STATUS_OK != CAUnSelectNetwork(networkType))
+    {
+        LOGE("Could not unselect network");
+    }
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_service_RMInterface_RMGetNetworkInfomation(JNIEnv *env, jobject obj)
+{
+    LOGI("RMGetNetworkInfomation");
+
+    CAEndpoint_t *tempInfo = NULL;
+    uint32_t tempSize = 0;
+
+    CAResult_t res = CAGetNetworkInformation(&tempInfo, &tempSize);
+    if (CA_STATUS_OK != res)
+    {
+        LOGE("Could not start get network information");
+        free(tempInfo);
+        return;
+    }
+
+    LOGI("################## Network Information #######################");
+    callback("######## Network Information", "#######");
+    LOGI("Network info total size is %d", tempSize);
+
+    uint32_t index;
+    for (index = 0; index < tempSize; index++)
+    {
+        res = get_remote_address(tempInfo[index].adapter, tempInfo[index].addr);
+        if (CA_STATUS_OK != res)
+        {
+            free(tempInfo);
+            return;
+        }
+        if (NULL != g_responseListenerObject)
+        {
+            char networkInfo[NETWORK_INFO_LENGTH];
+            LOGI("Type: %d", tempInfo[index].adapter);
+            sprintf(networkInfo, "%d",tempInfo[index].adapter);
+            callback("Type :", networkInfo);
+            if (CA_ADAPTER_IP == tempInfo[index].adapter)
+            {
+                LOGI("Port: %d", tempInfo[index].port);
+                sprintf(networkInfo, "%d",tempInfo[index].port);
+                callback("Port: ", networkInfo);
+            }
+            LOGI("Secured: %d", (tempInfo[index].flags & CA_SECURE));
+            LOGI("Address: %s", g_remoteAddress);
+            callback("Address: ", g_remoteAddress);
+            free(g_remoteAddress);
+        }
+        if (tempInfo[index].flags & CA_SECURE)
+        {
+            g_localSecurePort = tempInfo[index].port;
+        }
+    }
+
+    // free
+    free(tempInfo);
+
+    LOGI("##############################################################");
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_service_RMInterface_RMHandleRequestResponse(JNIEnv *env, jobject obj)
+{
+    LOGI("RMHandleRequestResponse");
+
+    if (CA_STATUS_OK != CAHandleRequestResponse())
+    {
+        LOGE("Could not handle request and response");
+    }
+}
+
+void request_handler(const CAEndpoint_t* object, const CARequestInfo_t* requestInfo)
+{
+
+    if (!object)
+    {
+        LOGE("Remote endpoint is NULL!");
+        return;
+    }
+
+    if (!requestInfo)
+    {
+        LOGE("Request info is NULL!");
+        return;
+    }
+
+    if ((NULL != g_lastRequestToken) && (NULL != requestInfo->info.token) &&
+            (strncmp(g_lastRequestToken, requestInfo->info.token,
+                     requestInfo->info.tokenLength) == 0))
+    {
+        LOGI("token is same. received request of it's own. skip.. ");
+        return;
+    }
+
+    CAResult_t res = get_remote_address(object->adapter, object->addr);
+    if (CA_STATUS_OK != res)
+    {
+        return;
+    }
+
+    LOGI("##########received request from remote device #############");
+    LOGI("Remote Address: %s", g_remoteAddress);
+    LOGI("Uri: %s", requestInfo->info.resourceUri);
+    LOGI("Data: %s", requestInfo->info.payload);
+    LOGI("Token: %s", requestInfo->info.token);
+    LOGI("Code: %d", requestInfo->method);
+    LOGI("MessageType: %d", requestInfo->info.type);
+
+    if (NULL != g_responseListenerObject)
+    {
+        callback("received request from remote device", "#######");
+        char *cloneUri = NULL;
+        uint32_t len = 0;
+
+        if (NULL != requestInfo->info.resourceUri)
+        {
+            len = strlen(requestInfo->info.resourceUri);
+            cloneUri = (char *)malloc(sizeof(char) * (len + 1));
+
+            if (NULL == cloneUri)
+            {
+                LOGE("cloneUri Out of memory");
+                free(g_remoteAddress);
+                return;
+            }
+
+            memcpy(cloneUri, requestInfo->info.resourceUri, len + 1);
+            callback("Uri: ", cloneUri);
+        }
+
+        len = strlen(g_remoteAddress);
+        char *cloneRemoteAddress = (char *) malloc(sizeof(char) * (len + 1));
+
+        if (NULL == cloneRemoteAddress)
+        {
+            LOGE("cloneRemoteAddress Out of memory");
+            free(g_remoteAddress);
+            free(cloneUri);
+            return;
+        }
+
+        memcpy(cloneRemoteAddress, g_remoteAddress, len + 1);
+
+        callback("Remote Address: ", cloneRemoteAddress);
+        free(cloneRemoteAddress);
+        free(g_remoteAddress);
+
+        //clone g_clientEndpoint
+        g_clientEndpoint = (CAEndpoint_t *) malloc(sizeof(CAEndpoint_t));
+        if (NULL == g_clientEndpoint)
+        {
+            LOGE("g_clientEndpoint Out of memory");
+            free(cloneUri);
+            return;
+        }
+        memcpy(g_clientEndpoint, object, sizeof(CAEndpoint_t));
+
+        if (NULL != cloneUri)
+        {
+            len = strlen(cloneUri);
+            g_resourceUri = (char *) malloc(sizeof(char) * (len + 1));
+            if (NULL == g_resourceUri)
+            {
+                LOGE("g_clientEndpoint->resourceUri Out of memory");
+                free(g_clientEndpoint);
+                free(cloneUri);
+                return;
+            }
+            memcpy(g_resourceUri, cloneUri, len + 1);
+            free(cloneUri);
+        }
+        //clone g_clientToken
+        len = requestInfo->info.tokenLength;
+
+        g_clientToken = (char *) malloc(sizeof(char) * len);
+        if (NULL == g_clientToken)
+        {
+            LOGE("g_clientToken Out of memory");
+            free(g_clientEndpoint);
+            return;
+        }
+
+        if (NULL != requestInfo->info.token)
+        {
+            memcpy(g_clientToken, requestInfo->info.token, len);
+            g_clientTokenLength = len;
+
+        }
+
+        //clone g_clientMsgId
+        g_clientMsgId = requestInfo->info.messageId;
+
+        if (NULL != requestInfo->info.payload)
+        {
+            len = strlen(requestInfo->info.payload);
+            char *clonePayload = (char *) malloc(sizeof(char) * (len + 1));
+
+            if (NULL == clonePayload)
+            {
+                LOGE("clonePayload Out of memory");
+                free(g_clientEndpoint);
+                return;
+            }
+
+            memcpy(clonePayload, requestInfo->info.payload, len + 1);
+
+            callback("Data: ", clonePayload);
+            free(clonePayload);
+        }
+    }
+
+    if (requestInfo->info.options)
+    {
+        uint32_t len = requestInfo->info.numOptions;
+        uint32_t i;
+
+        LOGI("Option count: %d", requestInfo->info.numOptions);
+
+        for (i = 0; i < len; i++)
+        {
+            LOGI("Option %d", i + 1);
+            LOGI("ID : %d", requestInfo->info.options[i].optionID);
+            LOGI("Data[%d]: %s", requestInfo->info.options[i].optionLength,
+                 requestInfo->info.options[i].optionData);
+
+            if (NULL != g_responseListenerObject)
+            {
+                char optionInfo[OPTION_INFO_LENGTH] = { 0, };
+                sprintf(optionInfo, "Num[%d] - ID : %d, Option Length : %d", i + 1,
+                        requestInfo->info.options[i].optionID,
+                        requestInfo->info.options[i].optionLength);
+
+                callback("Option info: ", optionInfo);
+
+                size_t optionDataLen = strlen(requestInfo->info.options[i].optionData);
+                char *cloneOptionData = (char *) malloc(sizeof(char) * (optionDataLen + 1));
+                if (NULL == cloneOptionData)
+                {
+                    LOGE("cloneOptionData Out of memory");
+                    free(g_clientEndpoint);
+                    return;
+                }
+
+                memcpy(cloneOptionData, requestInfo->info.options[i].optionData,
+                       optionDataLen + 1);
+
+                callback("Option Data: ", cloneOptionData);
+                free(cloneOptionData);
+            }
+        }
+    }
+    LOGI("############################################################");
+
+    //Check if this has secure communication information
+    if (requestInfo->info.payload && CA_ADAPTER_IP == object->adapter)
+    {
+        uint32_t securePort = get_secure_information(requestInfo->info.payload);
+        if (0 < securePort) //Set the remote endpoint secure details and send response
+        {
+            LOGI("This is secure resource...");
+
+            CAEndpoint_t *endpoint = NULL;
+            if (CA_STATUS_OK != CACreateEndpoint(CA_SECURE,
+                        object->adapter, object->addr, securePort, &endpoint))
+            {
+                LOGE("Failed to create duplicate of remote endpoint!");
+                return;
+            }
+            object = endpoint;
+        }
+    }
+}
+
+void response_handler(const CAEndpoint_t* object, const CAResponseInfo_t* responseInfo)
+{
+
+    CAResult_t res = get_remote_address(object->adapter, object->addr);
+    if (CA_STATUS_OK != res)
+    {
+        return;
+    }
+
+    LOGI("##########Received response from remote device #############");
+    LOGI("Uri: %s", responseInfo->info.resourceUri);
+    LOGI("Remote Address: %s", g_remoteAddress);
+    LOGI("response result: %d", responseInfo->result);
+    LOGI("Data: %s", responseInfo->info.payload);
+    LOGI("Token: %s", responseInfo->info.token);
+    LOGI("MessageType: %d", responseInfo->info.type);
+
+    if (NULL != g_responseListenerObject)
+    {
+        uint32_t len = 0;
+
+        if (NULL != responseInfo->info.resourceUri)
+        {
+            len = strlen(responseInfo->info.resourceUri);
+            char *cloneUri = (char *) malloc(sizeof(char) * (len + 1));
+
+            if (NULL == cloneUri)
+            {
+                LOGE("cloneUri Out of memory");
+                free(g_remoteAddress);
+                return;
+            }
+
+            memcpy(cloneUri, responseInfo->info.resourceUri, len + 1);
+
+            callback("Uri: ", cloneUri);
+            free(cloneUri);
+        }
+
+        len = strlen(g_remoteAddress);
+        char *cloneRemoteAddress = (char *) malloc(sizeof(char) * (len + 1));
+
+        if (NULL == cloneRemoteAddress)
+        {
+            LOGE("cloneRemoteAddress Out of memory");
+            free(g_remoteAddress);
+            return;
+        }
+
+        memcpy(cloneRemoteAddress, g_remoteAddress, len + 1);
+
+        callback("Remote Address: ", cloneRemoteAddress);
+        free(cloneRemoteAddress);
+        free(g_remoteAddress);
+
+        if (NULL != responseInfo->info.payload)
+        {
+            len = strlen(responseInfo->info.payload);
+            char *clonePayload = (char *) malloc(sizeof(char) * (len + 1));
+
+            if (NULL == clonePayload)
+            {
+                LOGE("clonePayload Out of memory");
+                return;
+            }
+
+            memcpy(clonePayload, responseInfo->info.payload, len + 1);
+
+            callback("Data: ", clonePayload);
+            free(clonePayload);
+        }
+    }
+
+    if (responseInfo->info.options)
+    {
+        uint32_t len = responseInfo->info.numOptions;
+        uint32_t i;
+        for (i = 0; i < len; i++)
+        {
+            LOGI("Option %d", i + 1);
+            LOGI("ID : %d", responseInfo->info.options[i].optionID);
+            LOGI("Data[%d]: %s", responseInfo->info.options[i].optionLength,
+                 responseInfo->info.options[i].optionData);
+
+            if (NULL != g_responseListenerObject)
+            {
+                char optionInfo[OPTION_INFO_LENGTH] = { 0, };
+                sprintf(optionInfo, "Num[%d] - ID : %d, Option Length : %d", i + 1,
+                        responseInfo->info.options[i].optionID,
+                        responseInfo->info.options[i].optionLength);
+
+                callback("Option info: ", optionInfo);
+
+                size_t optionDataLen = strlen(responseInfo->info.options[i].optionData);
+                char *cloneOptionData = (char *) malloc(sizeof(char) * (optionDataLen + 1));
+                if (NULL == cloneOptionData)
+                {
+                    LOGE("cloneOptionData Out of memory");
+                    return;
+                }
+                memcpy(cloneOptionData, responseInfo->info.options[i].optionData,
+                       optionDataLen + 1);
+                callback("Option Data: ", cloneOptionData);
+                free(cloneOptionData);
+            }
+        }
+    }
+    LOGI("############################################################");
+
+    //Check if this has secure communication information
+    if (responseInfo->info.payload && CA_ADAPTER_IP == object->adapter)
+    {
+        uint32_t securePort = get_secure_information(responseInfo->info.payload);
+        if (0 < securePort) //Set the remote endpoint secure details and send response
+        {
+            LOGI("This is secure resource...");
+        }
+    }
+}
+
+void error_handler(const CAEndpoint_t *rep, const CAErrorInfo_t* errorInfo)
+{
+    printf("+++++++++++++++++++++++++++++++++++ErrorInfo+++++++++++++++++++++++++++++++++++");
+
+    if(errorInfo)
+    {
+        const CAInfo_t *info = &errorInfo->info;
+        LOGI("Error Handler, ErrorInfo :");
+        LOGI("Error Handler result    : %d", errorInfo->result);
+        LOGI("Error Handler token     : %s", info->token);
+        LOGI("Error Handler messageId : %d", (uint16_t) info->messageId);
+        LOGI("Error Handler resourceUri : %s", info->resourceUri);
+        LOGI("Error Handler type      : %d", info->type);
+        LOGI("Error Handler payload   : %s", info->payload);
+
+        if(CA_ADAPTER_NOT_ENABLED == errorInfo->result)
+        {
+            LOGE("CA_ADAPTER_NOT_ENABLED, enable the adapter");
+        }
+        else if(CA_SEND_FAILED == errorInfo->result)
+        {
+            LOGE("CA_SEND_FAILED, unable to send the message, check parameters");
+        }
+        else if(CA_MEMORY_ALLOC_FAILED == errorInfo->result)
+        {
+            LOGE("CA_MEMORY_ALLOC_FAILED, insufficient memory");
+        }
+        else if(CA_SOCKET_OPERATION_FAILED == errorInfo->result)
+        {
+            LOGE("CA_SOCKET_OPERATION_FAILED, socket operation failed");
+        }
+        else if(CA_STATUS_FAILED == errorInfo->result)
+        {
+            LOGE("CA_STATUS_FAILED, message could not be delivered, internal error");
+        }
+    }
+    LOGI("++++++++++++++++++++++++++++++++End of ErrorInfo++++++++++++++++++++++++++++++++");
+
+    return;
+}
+
+void get_resource_uri(const char *URI, char *resourceURI, uint32_t length)
+{
+    const char *startPos = URI;
+    const char *temp = strstr(URI, "://");
+    if (NULL != temp)
+    {
+        startPos = strchr(temp + 3, '/');
+        if (!startPos)
+        {
+            LOGE("Resource URI is missing");
+            return;
+        }
+    }
+
+    const char *endPos = strchr(startPos, '?');
+    if (!endPos)
+    {
+        endPos = URI + strlen(URI);
+    }
+    --endPos;
+
+    if (endPos - startPos <= length)
+    {
+        memcpy(resourceURI, startPos + 1, endPos - startPos);
+    }
+
+    LOGI("URI: %s, ResourceURI: %s", URI, resourceURI);
+}
+
+uint32_t get_secure_information(CAPayload_t payLoad)
+{
+    LOGI("entering get_secure_information");
+
+    if (!payLoad)
+    {
+        LOGE("Payload is NULL");
+        return -1;
+    }
+
+    const char *subString = NULL;
+    if (NULL == (subString = strstr(payLoad, "\"sec\":1")))
+    {
+        LOGE("This is not secure resource");
+        return -1;
+    }
+
+    if (NULL == (subString = strstr(payLoad, "\"port\":")))
+    {
+        LOGE("This secure resource does not have port information");
+        return -1;
+    }
+
+    const char *startPos = strstr(subString, ":");
+    if (!startPos)
+    {
+        LOGE("Parsing failed !");
+        return -1;
+    }
+
+    const char *endPos = strstr(startPos, "}");
+    if (!endPos)
+    {
+        LOGE("Parsing failed !");
+        return -1;
+    }
+
+    char portStr[6] = { 0 };
+    memcpy(portStr, startPos + 1, (endPos - 1) - startPos);
+
+    LOGI("secured port is: %s", portStr);
+    return atoi(portStr);
+}
+
+CAResult_t get_network_type(uint32_t selectedNetwork)
+{
+
+    uint32_t number = selectedNetwork;
+
+    if (!(number & 0xf))
+    {
+        return CA_NOT_SUPPORTED;
+    }
+    if (number & CA_ADAPTER_IP)
+    {
+        g_selectedNwType = CA_ADAPTER_IP;
+        return CA_STATUS_OK;
+    }
+    if (number & CA_ADAPTER_RFCOMM_BTEDR)
+    {
+        g_selectedNwType = CA_ADAPTER_RFCOMM_BTEDR;
+        return CA_STATUS_OK;
+    }
+    if (number & CA_ADAPTER_GATT_BTLE)
+    {
+        g_selectedNwType = CA_ADAPTER_GATT_BTLE;
+        return CA_STATUS_OK;
+    }
+
+    return CA_NOT_SUPPORTED;
+}
+
+void callback(char *subject, char *receivedData)
+{
+    JNIEnv* env = NULL;
+    uint32_t status = (*g_jvm)->GetEnv(g_jvm, (void **) &env, JNI_VERSION_1_6);
+    uint32_t res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
+
+    jclass cls = (*env)->GetObjectClass(env, g_responseListenerObject);
+    jmethodID mid = (*env)->GetMethodID(env, cls, "OnResponseReceived",
+                                        "(Ljava/lang/String;Ljava/lang/String;)V");
+
+    jstring jsubject = (*env)->NewStringUTF(env, (char*) subject);
+    jstring jreceivedData = (*env)->NewStringUTF(env, (char*) receivedData);
+    (*env)->CallVoidMethod(env, g_responseListenerObject, mid, jsubject, jreceivedData);
+
+}
+
+CAResult_t get_remote_address(CATransportAdapter_t transportType, const char *address)
+{
+    uint32_t len = strlen(address);
+
+    g_remoteAddress = (char *)malloc(sizeof (char) * (len + 1));
+    if (NULL == g_remoteAddress)
+    {
+        LOGE("g_remoteAddress Out of memory");
+        return CA_MEMORY_ALLOC_FAILED;
+    }
+
+    memcpy(g_remoteAddress, address, len + 1);
+
+    return CA_STATUS_OK;
+}
+
+
+void parsing_coap_uri(const char* uri, addressSet_t* address, CATransportFlags_t *flags)
+{
+    if (NULL == uri || NULL == address)
+    {
+        LOGE("parameter is null");
+        return;
+    }
+
+    // parse uri
+    // #1. check prefix
+    uint8_t startIndex = 0;
+    if (strncmp(COAPS_PREFIX, uri, COAPS_PREFIX_LEN) == 0)
+    {
+        LOGI("uri has '%s' prefix", COAPS_PREFIX);
+        startIndex = COAPS_PREFIX_LEN;
+        *flags = CA_SECURE;
+    }
+    else if (strncmp(COAP_PREFIX, uri, COAP_PREFIX_LEN) == 0)
+    {
+        LOGI("uri has '%s' prefix", COAP_PREFIX);
+        startIndex = COAP_PREFIX_LEN;
+        *flags = CA_DEFAULT_FLAGS;
+    }
+
+    // #2. copy uri for parse
+    int32_t len = strlen(uri) - startIndex;
+
+    if (len <= 0)
+    {
+        LOGE("uri length is 0!");
+        return;
+    }
+
+    char *cloneUri = (char *) calloc(len + 1, sizeof(char));
+    if (NULL == cloneUri)
+    {
+        LOGE("Out of memory");
+        return;
+    }
+
+    memcpy(cloneUri, &uri[startIndex], sizeof(char) * len);
+    cloneUri[len] = '\0';
+
+    char *pAddress = cloneUri;
+    char *pResourceUri = NULL;
+
+    int32_t i = 0;
+    for (i = 0; i < len; i++)
+    {
+        if (cloneUri[i] == '/')
+        {
+            // separate
+            cloneUri[i] = 0;
+            pResourceUri = &cloneUri[i + 1];
+            break;
+        }
+    }
+    LOGI("pAddress : %s", pAddress);
+
+    int res = get_address_set(pAddress, address);
+    if (res == -1)
+    {
+        LOGE("address parse error");
+
+        free(cloneUri);
+        return;
+    }
+    return;
+}
+
+int get_address_set(const char *pAddress, addressSet_t* outAddress)
+{
+    if (NULL == pAddress || NULL == outAddress)
+    {
+        LOGE("parameter is null");
+        return -1;
+    }
+
+    int32_t len = strlen(pAddress);
+    int32_t isIp = 0;
+    int32_t ipLen = 0;
+
+    int32_t i = 0;
+    for (i = 0; i < len; i++)
+    {
+        if (pAddress[i] == '.')
+        {
+            isIp = 1;
+        }
+
+        // found port number start index
+        if (isIp && pAddress[i] == ':')
+        {
+            ipLen = i;
+            break;
+        }
+    }
+
+    if (isIp)
+    {
+        if(ipLen && ipLen < sizeof(outAddress->ipAddress))
+        {
+            strncpy(outAddress->ipAddress, pAddress, ipLen);
+            outAddress->ipAddress[ipLen] = '\0';
+        }
+        else if (!ipLen && len < sizeof(outAddress->ipAddress))
+        {
+            strncpy(outAddress->ipAddress, pAddress, len);
+            outAddress->ipAddress[len] = '\0';
+        }
+        else
+        {
+            LOGE("IP Address too long: %d", ipLen==0 ? len : ipLen);
+            return -1;
+        }
+
+        if (ipLen > 0)
+        {
+            outAddress->port = atoi(pAddress + ipLen + 1);
+        }
+    }
+    else
+    {
+        strncpy(outAddress->ipAddress, pAddress, len);
+        outAddress->ipAddress[len] = '\0';
+    }
+
+    return isIp;
+}
diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/org_iotivity_ca_service_RMInterface.h b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/org_iotivity_ca_service_RMInterface.h
new file mode 100755 (executable)
index 0000000..6f60059
--- /dev/null
@@ -0,0 +1,118 @@
+#include <jni.h>
+/* Header for class org_iotivity_ca_service_RMInterface */
+
+#ifndef _Included_org_iotivity_ca_service_RMInterface
+#define _Included_org_iotivity_ca_service_RMInterface
+#ifdef __cplusplus
+extern "C" {
+#endif
+JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_setNativeResponseListener
+  (JNIEnv *, jobject, jobject);
+/*
+ * Class:     org_iotivity_ca_service_RMInterface
+ * Method:    RMInitialize
+ * Signature: (Landroid/content/Context;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMInitialize
+  (JNIEnv *, jobject, jobject);
+
+/*
+ * Class:     org_iotivity_ca_service_RMInterface
+ * Method:    RMTerminate
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMTerminate
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     org_iotivity_ca_service_RMInterface
+ * Method:    RMStartListeningServer
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMStartListeningServer
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     org_iotivity_ca_service_RMInterface
+ * Method:    RMStartDiscoveryServer
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMStartDiscoveryServer
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     org_iotivity_ca_service_RMInterface
+ * Method:    RMRegisterHandler
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMRegisterHandler
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     org_iotivity_ca_service_RMInterface
+ * Method:    RMSendRequest
+ * Signature: (Ljava/lang/String;Ljava/lang/String;III)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMSendRequest
+  (JNIEnv *, jobject, jstring, jstring, jint, jint, jint);
+
+/*
+ * Class:     org_iotivity_ca_service_RMInterface
+ * Method:    RMSendReqestToAll
+ * Signature: (Ljava/lang/String;I)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMSendReqestToAll
+  (JNIEnv *, jobject, jstring, jint);
+
+/*
+ * Class:     org_iotivity_ca_service_RMInterface
+ * Method:    RMSendResponse
+ * Signature: (IIII)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMSendResponse
+  (JNIEnv *, jobject, jint, jint, jint, jint);
+
+/*
+ * Class:     org_iotivity_ca_service_RMInterface
+ * Method:    RMSendNotification
+ * Signature: (Ljava/lang/String;Ljava/lang/String;IIII)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMSendNotification
+  (JNIEnv *, jobject, jstring, jstring, jint, jint, jint, jint);
+
+/*
+ * Class:     org_iotivity_ca_service_RMInterface
+ * Method:    RMSelectNetwork
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMSelectNetwork
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     org_iotivity_ca_service_RMInterface
+ * Method:    RMUnSelectNetwork
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMUnSelectNetwork
+  (JNIEnv *, jobject, jint);
+
+/*
+ * Class:     org_iotivity_ca_service_RMInterface
+ * Method:    RMGetNetworkInfomation
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMGetNetworkInfomation
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     org_iotivity_ca_service_RMInterface
+ * Method:    RMHandleRequestResponse
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMHandleRequestResponse
+  (JNIEnv *, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/layout/activity_main.xml b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/layout/activity_main.xml
new file mode 100755 (executable)
index 0000000..7c35a9d
--- /dev/null
@@ -0,0 +1,258 @@
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:paddingBottom="@dimen/activity_vertical_margin"
+    android:paddingLeft="@dimen/activity_horizontal_margin"
+    android:paddingRight="@dimen/activity_horizontal_margin"
+    android:paddingTop="@dimen/activity_vertical_margin"
+    tools:context="org.iotivity.ca.service.MainActivity" >
+
+    <RelativeLayout
+        android:id="@+id/sample_service_layout"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:layout_alignParentTop="true"
+        android:background="#cccccc" >
+
+        <LinearLayout
+            android:id="@+id/layout_mode"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_alignParentTop="true"
+            android:orientation="horizontal" >
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content" />
+
+            <TextView
+                android:id="@+id/tv_mode"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content" />
+        </LinearLayout>
+
+        <RelativeLayout
+            android:id="@+id/layout_network"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/layout_mode"
+            android:orientation="horizontal" >
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content" />
+
+            <TextView
+                android:id="@+id/tv_network"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content" />
+        </RelativeLayout>
+
+        <RelativeLayout
+            android:id="@+id/layout_Response_Noti_title"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/layout_mode" >
+
+            <TextView
+                android:id="@+id/tv_Response_Noti"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:text="[Send Response / Send Notification]"
+                />
+
+        </RelativeLayout>
+
+        <RelativeLayout
+            android:id="@+id/layout_notify"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/layout_Response_Noti_title" >
+
+            <EditText
+                android:id="@+id/et_notification"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:layout_alignParentRight="true"
+                android:text="@string/notification" />
+        </RelativeLayout>
+
+        <RelativeLayout
+            android:id="@+id/layout_request_setting_for_server"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/layout_notify" >
+
+            <Button
+                android:id="@+id/btn_Request_setting_for_server"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_alignParentLeft="true"
+                android:text="@string/request_setting" />
+
+            <Button
+                android:id="@+id/btn_notify"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_toRightOf="@id/btn_Request_setting_for_server"
+                android:text="@string/notify" />
+
+            <Button
+                android:id="@+id/btn_sendresponse"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_toRightOf="@id/btn_notify"
+                android:text="@string/sendresponse" />
+        </RelativeLayout>
+
+        <RelativeLayout
+            android:id="@+id/layout_request_title"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/layout_mode" >
+
+            <TextView
+                android:id="@+id/tv_request"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:text="[Send Request]" />
+
+        </RelativeLayout>
+
+        <RelativeLayout
+            android:id="@+id/layout_request"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/layout_request_title" >
+
+            <EditText
+                android:id="@+id/et_req_data"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:layout_centerVertical="true"
+                android:text="@string/req_data" />
+        </RelativeLayout>
+
+        <RelativeLayout
+            android:id="@+id/layout_request_setting_for_client"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/layout_request" >
+
+            <Button
+                android:id="@+id/btn_Request_setting_for_client"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_alignParentLeft="true"
+                android:text="@string/request_setting" />
+
+            <Button
+                android:id="@+id/btn_Request"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_toRightOf="@id/btn_Request_setting_for_client"
+                android:text="@string/request" />
+
+        </RelativeLayout>
+
+        <RelativeLayout
+            android:id="@+id/layout_request_to_all_title"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/layout_request_setting_for_client" >
+
+            <TextView
+                android:id="@+id/tv_request_to_all"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content" 
+                android:text="[Send Request to All]"
+                />
+
+         </RelativeLayout>
+
+        <RelativeLayout
+            android:id="@+id/layout_request_to_all"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/layout_request_to_all_title" >
+
+            <EditText
+                android:id="@+id/et_req_to_all_data"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:layout_centerVertical="true"
+                android:text="@string/uri" />
+        </RelativeLayout>
+
+        <RelativeLayout
+            android:id="@+id/layout_request_to_all_setting_for_client"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/layout_request_to_all" >
+
+            <Button
+                android:id="@+id/btn_request_to_all_setting_for_client"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_alignParentLeft="true"
+                android:text="@string/request_setting" />
+
+            <Button
+                android:id="@+id/btn_request_to_all"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_toRightOf="@id/btn_request_to_all_setting_for_client"
+                android:text="@string/request_to_all" />
+        </RelativeLayout>
+
+        <RelativeLayout
+            android:id="@+id/layout_handle_title"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/layout_request_to_all_setting_for_client" >
+
+            <TextView
+                android:id="@+id/tv_handle"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:text="[Handle Reqeust,Response data / Get NetworkInfo]"/>
+        </RelativeLayout>
+
+        <RelativeLayout
+            android:id="@+id/layout_receive"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/layout_handle_title" >
+
+            <Button
+                android:id="@+id/btn_receive"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_alignParentLeft="true"
+                android:text="@string/receive" />
+
+            <Button
+                android:id="@+id/btn_get_network_info"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_toRightOf="@id/btn_receive"
+                android:text="@string/get_network_info" />
+
+        </RelativeLayout>
+    </RelativeLayout>
+
+    <ScrollView
+        android:id="@+id/sv_result_scoll"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent"
+        android:layout_below="@id/sample_service_layout"
+        android:layout_marginTop="10pt" >
+
+        <TextView
+            android:id="@+id/tv_result"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content" />
+    </ScrollView>
+
+</RelativeLayout>
diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/menu/main.xml b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/menu/main.xml
new file mode 100755 (executable)
index 0000000..e0d03f4
--- /dev/null
@@ -0,0 +1,12 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    tools:context="org.iotivity.ca.sample_service.MainActivity" >
+
+    <item
+        android:id="@+id/action_settings"
+        android:orderInCategory="100"
+        android:showAsAction="never"
+        android:title="@string/action_settings"/>
+
+</menu>
+
diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/values-v11/styles.xml b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/values-v11/styles.xml
new file mode 100755 (executable)
index 0000000..3df0c14
--- /dev/null
@@ -0,0 +1,12 @@
+<resources>
+
+    <!--
+        Base application theme for API 11+. This theme completely replaces
+        AppBaseTheme from res/values/styles.xml on API 11+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
+        <!-- API 11 theme customizations can go here. -->
+    </style>
+
+</resources>
+
diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/values-v14/styles.xml b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/values-v14/styles.xml
new file mode 100755 (executable)
index 0000000..13d7045
--- /dev/null
@@ -0,0 +1,13 @@
+<resources>
+
+    <!--
+        Base application theme for API 14+. This theme completely replaces
+        AppBaseTheme from BOTH res/values/styles.xml and
+        res/values-v11/styles.xml on API 14+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+        <!-- API 14 theme customizations can go here. -->
+    </style>
+
+</resources>
+
diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/values-w820dp/dimens.xml b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/values-w820dp/dimens.xml
new file mode 100755 (executable)
index 0000000..efaa062
--- /dev/null
@@ -0,0 +1,11 @@
+<resources>
+
+    <!--
+         Example customization of dimensions originally defined in res/values/dimens.xml
+         (such as screen margins) for screens with more than 820dp of available width. This
+         would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively).
+    -->
+    <dimen name="activity_horizontal_margin">64dp</dimen>
+
+</resources>
+
diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/values/dimens.xml b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/values/dimens.xml
new file mode 100755 (executable)
index 0000000..6ed10f5
--- /dev/null
@@ -0,0 +1,8 @@
+<resources>
+
+    <!-- Default screen margins, per the Android Design guidelines. -->
+    <dimen name="activity_horizontal_margin">16dp</dimen>
+    <dimen name="activity_vertical_margin">16dp</dimen>
+
+</resources>
+
diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/values/strings.xml b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/values/strings.xml
new file mode 100755 (executable)
index 0000000..d365f1e
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    <string name="app_name">CA Android Sample</string>
+    <string name="sendresponse">Response</string>
+    <string name="notify">Notification</string>
+    <string name="request_setting">Setting</string>
+    <string name="request">Request</string>
+    <string name="request_to_all">Request to All</string>
+    <string name="response">Response</string>
+    <string name="uri">/a/light</string>
+    <string name="coap_prefix">coap://</string>
+    <string name="port_num">:6298</string>
+    <string name="notification"></string>
+    <string name="req_data"></string>
+    <string name="resp_data">resourceUri/response</string>
+    <string name="get_network_info">Network Info</string>
+    <string name="receive">Receive</string>
+    <string name="received">Received Message</string>
+    <string name="remote_address">"Remote Address: "</string>
+    <string name="action_settings">Settings</string>
+</resources>
\ No newline at end of file
diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/values/styles.xml b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/values/styles.xml
new file mode 100755 (executable)
index 0000000..d77df4e
--- /dev/null
@@ -0,0 +1,21 @@
+<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/resource/csdk/connectivity/samples/android/casample/settings.gradle b/resource/csdk/connectivity/samples/android/casample/settings.gradle
new file mode 100755 (executable)
index 0000000..97b651e
--- /dev/null
@@ -0,0 +1,2 @@
+include ':cAInterface'
+include ':sampleService'