Notification Service - add Android JNI in provider.
authorjaesick.shin <jaesick.shin@samsung.com>
Wed, 18 May 2016 06:43:01 +0000 (15:43 +0900)
committerUze Choi <uzchoi@samsung.com>
Wed, 18 May 2016 10:01:25 +0000 (10:01 +0000)
This patch is Add Android JNI in Provider side.
Our Notification support to android platform.

Added 6 source files. other files are related build.
four files - java, two files - jni native interface.c, h.

IoTNotification.java - this is user interface object.
NSMessage.java - notification message object.
NSSync.java - related read operation object.
NSConsumer.java - related Accept operation object.

notificationProvider.c, h - java native interface.

Change-Id: I8a97d5c329e0f05c1582f5ffc4bf51eee318353d
Signed-off-by: jaesick.shin <jaesick.shin@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8207
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
19 files changed:
service/notification/android/SConscript [new file with mode: 0644]
service/notification/android/android_api.iml [new file with mode: 0644]
service/notification/android/build.gradle [new file with mode: 0644]
service/notification/android/gradle.properties [new file with mode: 0644]
service/notification/android/gradlew [new file with mode: 0644]
service/notification/android/gradlew.bat [new file with mode: 0644]
service/notification/android/notification-service/base.iml [new file with mode: 0644]
service/notification/android/notification-service/build.gradle [new file with mode: 0644]
service/notification/android/notification-service/proguard-rules.pro [new file with mode: 0644]
service/notification/android/notification-service/src/main/AndroidManifest.xml [new file with mode: 0644]
service/notification/android/notification-service/src/main/java/org/iotivity/service/notification/IoTNotification.java [new file with mode: 0644]
service/notification/android/notification-service/src/main/java/org/iotivity/service/notification/NSConsumer.java [new file with mode: 0644]
service/notification/android/notification-service/src/main/java/org/iotivity/service/notification/NSMessage.java [new file with mode: 0644]
service/notification/android/notification-service/src/main/java/org/iotivity/service/notification/NSSync.java [new file with mode: 0644]
service/notification/android/notification-service/src/main/jni/Android.mk [new file with mode: 0644]
service/notification/android/notification-service/src/main/jni/Application.mk [new file with mode: 0644]
service/notification/android/notification-service/src/main/jni/notificationProvider.c [new file with mode: 0644]
service/notification/android/notification-service/src/main/jni/notificationProvider.h [new file with mode: 0644]
service/notification/android/settings.gradle [new file with mode: 0644]

diff --git a/service/notification/android/SConscript b/service/notification/android/SConscript
new file mode 100644 (file)
index 0000000..701b1a6
--- /dev/null
@@ -0,0 +1,55 @@
+import os
+import platform
+Import('env')
+
+android_home = env.get('ANDROID_HOME')
+
+ANDROID_TARGET_ARCH = env.get('TARGET_ARCH')
+if env.get('RELEASE'):
+       ANDROID_RELEASE="release"
+else:
+       ANDROID_RELEASE="debug"
+
+os.environ['ANDROID_HOME'] = env.get('ANDROID_HOME')
+os.environ['ANDROID_NDK_HOME'] = env.get('ANDROID_NDK')
+
+if not os.path.exists(android_home + '/platforms/android-21') or not os.path.exists(android_home + '/build-tools/20.0.0'):
+    print '''
+***************************************** Info ********************************
+*   Either 'Android API 21' is not installed or 'Android SDK Build Tools      *
+*   20.0.0' is not installed. The Android SDK Manager will now open. Please   *
+*   be sure to deselect all options, then select the following 2 packages:    *
+*       1. Under "Tools" select "Android SDK Build-tools" Revision 20.        *
+*       2. Under "Android 5.0.1 (API 21)" select "SDK Platform"               *
+*       3. Continue by selecting "Install 2 Packages"                         *
+*                                                                             *
+*   NOTE: If you have an http proxy, please press ctrl+c now and edit/create  *
+*         the following file in your $HOME directory as follows:              *
+*                                                                             *
+* Edit/Create file: "$HOME/.android/androidtool.cfg"                          *
+*                                                                             *
+*    http.proxyPort=<YOUR_PORT_NUMBER>                                        *
+*    sdkman.monitor.density=108                                               *
+*    http.proxyHost=<YOUR_HTTP_PROXY_ADDRESS>                                 *
+*    sdkman.show.update.only=true                                             *
+*    sdkman.ask.adb.restart=false                                             *
+*    sdkman.force.http=true                                                   *
+*    sdkman.show.updateonly=true                                              *
+*                                                                             *
+*******************************************************************************
+
+...Opening Android SDK Manager now. Once you are finished, the build will continue.
+'''
+    os.system(android_home + '/tools/android')
+
+
+def ensure_libs(target, source, env):
+    return target, [source, env.get('BUILD_DIR') + 'liboc.so', env.get('BUILD_DIR') + 'liboc_logger.so']
+
+jdk_env = Environment(ENV=os.environ)
+jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + 
+    ' build -bservice/notification/android/build.gradle -PTARGET_ARCH=%s -PRELEASE=%s --stacktrace' %(ANDROID_TARGET_ARCH, ANDROID_RELEASE),
+    emitter = ensure_libs)
+jdk_env['BUILD_DIR'] = env.get('BUILD_DIR')
+jdk_env.Gradle(target="notification-service/objs", 
+    source="notification-service/src/main/java/org/iotivity/service/notification/IoTNotification.java")
diff --git a/service/notification/android/android_api.iml b/service/notification/android/android_api.iml
new file mode 100644 (file)
index 0000000..0bb6048
--- /dev/null
@@ -0,0 +1,19 @@
+<?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$/build" />
+      </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/service/notification/android/build.gradle b/service/notification/android/build.gradle
new file mode 100644 (file)
index 0000000..cbfddfd
--- /dev/null
@@ -0,0 +1,40 @@
+/******************************************************************
+ *
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+
+buildscript {
+    repositories {
+        jcenter()
+    }
+    dependencies {
+        classpath 'com.android.tools.build:gradle:1.3.0'
+
+        // NOTE: Do not place your application dependencies here; they belong
+        // in the individual module build.gradle files
+    }
+}
+
+allprojects {
+    repositories {
+        jcenter {
+            url "http://jcenter.bintray.com/"
+        }
+    }
+}
diff --git a/service/notification/android/gradle.properties b/service/notification/android/gradle.properties
new file mode 100644 (file)
index 0000000..dff37f4
--- /dev/null
@@ -0,0 +1,40 @@
+#
+# //******************************************************************
+# //
+# // 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/service/notification/android/gradlew b/service/notification/android/gradlew
new file mode 100644 (file)
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/service/notification/android/gradlew.bat b/service/notification/android/gradlew.bat
new file mode 100644 (file)
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/service/notification/android/notification-service/base.iml b/service/notification/android/notification-service/base.iml
new file mode 100644 (file)
index 0000000..3bf0877
--- /dev/null
@@ -0,0 +1,90 @@
+<?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="android_api" 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=":base" />
+      </configuration>
+    </facet>
+    <facet type="android" name="Android">
+      <configuration>
+        <option name="SELECTED_BUILD_VARIANT" value="debug" />
+        <option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
+        <option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
+        <option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
+        <option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
+        <option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugTestSources" />
+        <option name="ALLOW_USER_CONFIGURATION" value="false" />
+        <option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
+        <option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
+        <option name="RES_FOLDERS_RELATIVE_PATH" value="" />
+        <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/test/debug" />
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/test/debug" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/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/native-libs" />
+      <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" />
+  </component>
+</module>
+
diff --git a/service/notification/android/notification-service/build.gradle b/service/notification/android/notification-service/build.gradle
new file mode 100644 (file)
index 0000000..50c7205
--- /dev/null
@@ -0,0 +1,107 @@
+/******************************************************************
+ *
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+apply plugin: 'com.android.library'
+
+android {
+    compileSdkVersion 21
+    buildToolsVersion "20.0.0"
+    archivesBaseName = "iotivity"
+
+    libraryVariants.all { variant ->
+        variant.outputs.each { output ->
+            def outputFile = output.outputFile
+            if (outputFile != null && outputFile.name.endsWith('.aar')) {
+                def fileName = "${archivesBaseName}-${TARGET_ARCH}-${outputFile.name}"
+                output.outputFile = new File(outputFile.parent, fileName)
+            }
+        }
+    }
+
+    defaultConfig {
+        minSdkVersion 21
+        targetSdkVersion 21
+        versionCode 1
+        versionName "1.0"
+    }
+    buildTypes {
+        release {
+            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+        }
+    }
+
+    lintOptions {
+       abortOnError false
+    }
+
+    sourceSets {
+        main {
+            manifest.srcFile 'src/main/AndroidManifest.xml'
+            jni.srcDirs = [] //disable automatic ndk-build call
+            jniLibs.srcDir new File(buildDir, 'native-libs')
+        }
+        androidTest.setRoot('src/androidTest')
+    }
+}
+
+
+dependencies {
+    compile fileTree(dir: 'libs', include: ['*.jar'])
+
+    androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.0'
+    androidTestCompile 'com.google.dexmaker:dexmaker:1.0'
+    androidTestCompile 'org.mockito:mockito-core:1.10.19'
+}
+
+////////////////
+////NDK Support
+////////////////
+//If using this, Android studio will fail run the following to set the environment variable for android studio:
+//launchctl setenv ANDROID_NDK_HOME
+//otherwise remove the dependsOn part and run ./gradlew buildNative from the command line
+task copyNativeLibs(type: Copy, dependsOn: 'buildNative') {
+    dependsOn 'buildNative'
+    from(new File('src/main/libs')) { include '**/*.so' exclude '**/libgnustl_shared.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, "APP_ABI=$TARGET_ARCH", "APP_OPTIM=$RELEASE", '-C', file('src/main').absolutePath
+    } else {
+        println '##################'
+        println 'Skipping NDK build'
+        println 'Reason: ANDROID_NDK_HOME not set.'
+        println '##################'
+    }
+}
diff --git a/service/notification/android/notification-service/proguard-rules.pro b/service/notification/android/notification-service/proguard-rules.pro
new file mode 100644 (file)
index 0000000..c5f9a5b
--- /dev/null
@@ -0,0 +1,17 @@
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in C:/android/sdk/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the proguardFiles
+# directive in build.gradle.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
diff --git a/service/notification/android/notification-service/src/main/AndroidManifest.xml b/service/notification/android/notification-service/src/main/AndroidManifest.xml
new file mode 100644 (file)
index 0000000..5274599
--- /dev/null
@@ -0,0 +1,2 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="org.iotivity.service.notification" />
\ No newline at end of file
diff --git a/service/notification/android/notification-service/src/main/java/org/iotivity/service/notification/IoTNotification.java b/service/notification/android/notification-service/src/main/java/org/iotivity/service/notification/IoTNotification.java
new file mode 100644 (file)
index 0000000..ca22906
--- /dev/null
@@ -0,0 +1,36 @@
+package org.iotivity.service.notification;\r
+\r
+import android.util.Log;\r
+import org.iotivity.service.notification.NSMessage;\r
+import org.iotivity.service.notification.NSConsumer;\r
+import org.iotivity.service.notification.NSSync;\r
+\r
+public class IoTNotification {\r
+    public IoTNotification(){}\r
+\r
+    static {\r
+        System.loadLibrary("notification_provider_jni");\r
+    }\r
+\r
+    public void onLogPrinted(String log)\r
+    {\r
+        Log.i("JNI_NS_CALLBACK", "[C->J] Log: " + log);\r
+    }\r
+\r
+    public void onSubscribeRequest(String consumer)\r
+    {\r
+        Log.i("JNI_NS_CALLBACK", "[C->J] Consumer IP: " + consumer);\r
+    }\r
+\r
+    public void onMessageSync(String sync)\r
+    {\r
+        Log.i("JNI_NS_CALLBACK", "[C->J] Sync Status" + sync);\r
+    }\r
+      \r
+    public native int NSStartProvider(boolean access);\r
+    public native int NSStopProvider();\r
+    public native int NSSendNotification(NSMessage message);\r
+    public native int NSProviderReadCheck(NSMessage message);\r
+    public native int NSAccept(NSConsumer consumer, boolean accepted);\r
+}\r
+\r
diff --git a/service/notification/android/notification-service/src/main/java/org/iotivity/service/notification/NSConsumer.java b/service/notification/android/notification-service/src/main/java/org/iotivity/service/notification/NSConsumer.java
new file mode 100644 (file)
index 0000000..cbb75be
--- /dev/null
@@ -0,0 +1,26 @@
+package org.iotivity.service.notification;\r
+\r
+import android.util.Log;\r
+\r
+public class NSConsumer {\r
+       \r
+       String mId = null;\r
+       String mAddress = null;\r
+       \r
+       public NSConsumer(String id) {\r
+           this.mId = id;\r
+       }\r
+\r
+       public String getId() {\r
+           return mId;\r
+       }\r
+\r
+       public String getAddress() {\r
+           return mAddress;\r
+       }\r
+\r
+       public void setAddress(String address) {\r
+           this.mAddress = address;\r
+       }\r
+\r
+}\r
diff --git a/service/notification/android/notification-service/src/main/java/org/iotivity/service/notification/NSMessage.java b/service/notification/android/notification-service/src/main/java/org/iotivity/service/notification/NSMessage.java
new file mode 100644 (file)
index 0000000..5b1285b
--- /dev/null
@@ -0,0 +1,38 @@
+package org.iotivity.service.notification;\r
+\r
+import android.util.Log;\r
+\r
+/**\r
+ * Created by jaesick.shin on 2016-04-26.\r
+ */\r
+public class NSMessage {\r
+       \r
+       String id = null;\r
+       String title = null;\r
+       String body = null;\r
+       \r
+       public NSMessage(String id) {\r
+           this.id = id;\r
+       }\r
+\r
+       public String getTitle() {\r
+               return title;\r
+       }\r
+\r
+       public void setTitle(String title) {\r
+               this.title = title;\r
+       }\r
+\r
+       public String getBody() {\r
+               return body;\r
+       }\r
+\r
+       public void setBody(String body) {\r
+               this.body = body;\r
+       }\r
+\r
+       public String getId() {\r
+               return id;\r
+       }\r
+       \r
+}\r
diff --git a/service/notification/android/notification-service/src/main/java/org/iotivity/service/notification/NSSync.java b/service/notification/android/notification-service/src/main/java/org/iotivity/service/notification/NSSync.java
new file mode 100644 (file)
index 0000000..29688f0
--- /dev/null
@@ -0,0 +1,26 @@
+package org.iotivity.service.notification;\r
+\r
+import android.util.Log;\r
+\r
+public class NSSync {\r
+       \r
+       String mMessageId = null;\r
+       String mDeviceId = null;\r
+       \r
+       public NSSync(String id) {\r
+           this.mMessageId = id;\r
+       }\r
+\r
+       public String getMessageId() {\r
+           return mMessageId;\r
+       }\r
+\r
+       public String getDeviceId() {\r
+           return mDeviceId;\r
+       }\r
+\r
+       public void setDeviceId(String id) {\r
+           this.mDeviceId = id;\r
+       }\r
+\r
+}\r
diff --git a/service/notification/android/notification-service/src/main/jni/Android.mk b/service/notification/android/notification-service/src/main/jni/Android.mk
new file mode 100644 (file)
index 0000000..1db4c3e
--- /dev/null
@@ -0,0 +1,40 @@
+LOCAL_PATH := $(call my-dir)
+
+ROOT_PATH := ../../../../../../..
+
+include $(CLEAR_VARS)
+OIC_LIB_PATH := $(ROOT_PATH)/out/android/$(TARGET_ARCH_ABI)/$(APP_OPTIM)
+LOCAL_MODULE := notification_provider
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/libnotification_provider.so
+include $(PREBUILT_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := notification_provider_jni
+LOCAL_CPPFLAGS := -std=c++0x -frtti -fexceptions
+
+LOCAL_STATIC_LIBRARIES := ca_interface
+LOCAL_STATIC_LIBRARIES += ca
+LOCAL_STATIC_LIBRARIES += oc_logger_core
+LOCAL_STATIC_LIBRARIES += oc_logger
+LOCAL_STATIC_LIBRARIES += octbstack
+LOCAL_STATIC_LIBRARIES += oc
+LOCAL_STATIC_LIBRARIES += ocstack-jni
+LOCAL_STATIC_LIBRARIES += notification_provider
+
+OIC_SRC_DIR := ../../../../../..
+
+LOCAL_C_INCLUDES := $(OIC_SRC_DIR)/resource/csdk/stack/include
+LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/resource/csdk/logger/include
+LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/resource/include
+LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/resource/c_common
+LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/resource/oc_logger/include
+LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/service/notification/include
+LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/service/notification/src/common
+LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/service/notification/src/provider
+                    
+LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/extlibs/
+
+LOCAL_SRC_FILES := notificationProvider.c
+LOCAL_LDLIBS := -llog
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/service/notification/android/notification-service/src/main/jni/Application.mk b/service/notification/android/notification-service/src/main/jni/Application.mk
new file mode 100644 (file)
index 0000000..3baa444
--- /dev/null
@@ -0,0 +1,2 @@
+APP_STL:=gnustl_shared
+NDK_TOOLCHAIN_VERSION := 4.9
diff --git a/service/notification/android/notification-service/src/main/jni/notificationProvider.c b/service/notification/android/notification-service/src/main/jni/notificationProvider.c
new file mode 100644 (file)
index 0000000..94d598f
--- /dev/null
@@ -0,0 +1,309 @@
+//\r
+// Created by jaesick.shin on 2016-04-26.\r
+//\r
+\r
+#include <android/log.h>\r
+#include <stdio.h>\r
+#include "notificationProvider.h"\r
+\r
+#define  LOG_TAG   "JNI_NS_INTERFACE"\r
+#define  LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)\r
+#define  LOGE(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)\r
+\r
+static JavaVM *g_jvm = NULL;\r
+static jobject g_obj = NULL;\r
+\r
+JNIEXPORT jint JNI_OnLoad(JavaVM *jvm, void *reserved)\r
+{\r
+    LOGI("Initialize NSInterface");\r
+    g_jvm = jvm;\r
+\r
+    return JNI_VERSION_1_6;\r
+}\r
+\r
+JNIEXPORT jint JNICALL Java_org_iotivity_service_notification_IoTNotification_NSStartProvider(\r
+        JNIEnv * env, jobject jObj, jboolean jAccess)\r
+{\r
+    LOGI("JNI TEST - NSStartProvider...");\r
+\r
+    g_obj = jObj;\r
+\r
+    //JNIlogPrintedCallback(env, jObj, "NSStartProvider");\r
+\r
+    NSAccessPolicy access = NS_ACCEPTER_PROVIDER;\r
+    if(NSStartProvider(access, NSSubscribeRequestCb, NSSyncCb) == 0)\r
+    {\r
+        LOGI("JNI TEST - Success to start NSProvider service");\r
+    }\r
+    else\r
+    {\r
+        LOGE("JNI TEST - Fail to start NSProvider service");\r
+    }\r
+    //NSStartProvider(access, NULL, NULL);\r
+\r
+    return 0;\r
+}\r
+\r
+JNIEXPORT jint JNICALL Java_org_iotivity_service_notification_IoTNotification_NSStopProvider(\r
+        JNIEnv * env, jobject jObj)\r
+{\r
+    LOGI("JNI TEST - NSStopProvider");\r
+    return NSStopProvider();\r
+\r
+    return 0;\r
+}\r
+\r
+JNIEXPORT jint JNICALL Java_org_iotivity_service_notification_IoTNotification_NSSendNotification(\r
+        JNIEnv * env, jobject jObj, jobject jMsg)\r
+{\r
+    LOGI("JNI TEST - NSSendNotification");\r
+\r
+//    bool isAttached = false;\r
+//    //JNIEnv* env;\r
+//    jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);\r
+//    if (JNI_OK != res)\r
+//    {\r
+//        LOGI("AttachCurrentThread for JNIEnv pointer");\r
+//        res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);\r
+//\r
+//        if (JNI_OK != res)\r
+//        {\r
+//            LOGE("AttachCurrentThread has failed");\r
+//            return -1;\r
+//        }\r
+//        isAttached = true;\r
+//    }\r
+\r
+    jclass cls = (*env)->GetObjectClass(env, jMsg);\r
+\r
+    // Message ID\r
+    jfieldID fid_id = (*env)->GetFieldID(env, cls, "id", "Ljava/lang/String;");\r
+    if (fid_id == NULL)\r
+    {\r
+        LOGI("JNI TEST - Error: jfieldID for message id is null");\r
+        return 0;\r
+    }\r
+    jstring jmsgId = (*env)->GetObjectField(env, jMsg, fid_id);\r
+    const char * messageId = (*env)->GetStringUTFChars(env, jmsgId, NULL);\r
+    if (messageId == NULL)\r
+    {\r
+        printf("JNI TEST - Error: messageId is null\n");\r
+        return 0;\r
+    }\r
+    LOGI("JNI TEST - Message ID: %s\n", messageId);\r
+    JNIlogPrintedCallback(env, jObj, messageId);\r
+\r
+    (*env)->ReleaseStringUTFChars(env, jmsgId, messageId);\r
+\r
+    // Message Title\r
+    jfieldID fid_title = (*env)->GetFieldID(env, cls, "title", "Ljava/lang/String;");\r
+    if (fid_title == NULL)\r
+    {\r
+        LOGE("JNI TEST - Error: jfieldID for message id is null");\r
+        return 0;\r
+    }\r
+    jstring jmsgTitle = (*env)->GetObjectField(env, jMsg, fid_title);\r
+    const char * messageTitle = (*env)->GetStringUTFChars(env, jmsgTitle, NULL);\r
+    if (messageTitle == NULL)\r
+    {\r
+        printf("JNI TEST - Error: messageTitle is null\n");\r
+        return 0;\r
+    }\r
+    LOGI("JNI TEST - Message Title: %s\n", messageTitle);\r
+    (*env)->ReleaseStringUTFChars(env, jmsgTitle, messageTitle);\r
+\r
+    // Message Body\r
+    jfieldID fid_body = (*env)->GetFieldID(env, cls, "body", "Ljava/lang/String;");\r
+    if (fid_body == NULL)\r
+    {\r
+        LOGE("JNI TEST - Error: jfieldID for message id is null");\r
+        return 0;\r
+    }\r
+    jstring jmsgBody = (*env)->GetObjectField(env, jMsg, fid_body);\r
+    const char * messageBody = (*env)->GetStringUTFChars(env, jmsgBody, NULL);\r
+    if (messageBody == NULL)\r
+    {\r
+        printf("JNI TEST - Error: messageBody is null\n");\r
+        return 0;\r
+    }\r
+    LOGI("JNI TEST - Message Body: %s\n", messageBody);\r
+    (*env)->ReleaseStringUTFChars(env, jmsgBody, messageBody);\r
+\r
+//    if (isAttached)\r
+//    {\r
+//        (*g_jvm)->DetachCurrentThread(g_jvm);\r
+//    }\r
+\r
+    return 0;\r
+}\r
+\r
+JNIEXPORT jint JNICALL Java_org_iotivity_service_notification_IoTNotification_NSProviderReadCheck(\r
+        JNIEnv * env, jobject jObj, jobject jMsg)\r
+{\r
+    printf("JNI TEST - NSReasCheck\n");\r
+    return 0;\r
+}\r
+\r
+JNIEXPORT jint JNICALL Java_org_iotivity_service_notification_IoTNotification_NSAccept(JNIEnv * env,\r
+        jobject jObj, jobject jConsumer, jboolean jAccepted)\r
+{\r
+    if (jAccepted)\r
+    {\r
+        printf("JNI TEST - Accepted\n");\r
+        //NSAccept(consumer, true);\r
+    }\r
+    else\r
+    {\r
+        printf("JNI TEST - Denied\n");\r
+        //NSAccept(consumer, false);\r
+    }\r
+\r
+    return 0;\r
+}\r
+\r
+void JNIlogPrintedCallback(JNIEnv * env, jobject jObj, const char * log)\r
+{\r
+    static jmethodID cb = NULL;\r
+    //jclass cls = (*env)->FindClass(env, "com/sec/notiproviderexample/ProviderExample");\r
+    jclass cls = (*env)->GetObjectClass(env, jObj);\r
+    if (cls == NULL)\r
+    {\r
+        LOGE("JNI TEST - Error: cannot find callback class");\r
+    }\r
+\r
+    if (cb == NULL)\r
+    {\r
+        cb = (*env)->GetMethodID(env, cls, "onLogPrinted", "(Ljava/lang/String;)V");\r
+        if (cb == NULL)\r
+        {\r
+            LOGE("JNI TEST - Error: cannot get callback method");\r
+            return;\r
+        }\r
+        LOGI("JNI TEST - Get callback method - onLogPrinted");\r
+\r
+        jstring msg = (*env)->NewStringUTF(env, log);\r
+        LOGI("print: %s", log);\r
+\r
+        (*env)->CallVoidMethod(env, jObj, cb, msg);\r
+    }\r
+}\r
+\r
+void JNISubscribeRequestCallback(JNIEnv * env, jobject jObj, char * consumer)\r
+{\r
+    static jmethodID cb = NULL;\r
+    //jclass cls = (*env)->FindClass(env, "com/sec/notiproviderexample/ProviderExample");\r
+    jclass cls = (*env)->GetObjectClass(env, jObj);\r
+    if (cls == NULL)\r
+    {\r
+        LOGE("JNI TEST - Error: cannot find callback class");\r
+    }\r
+\r
+    if (cb == NULL)\r
+    {\r
+        cb = (*env)->GetMethodID(env, cls, "onSubscribeRequest", "(Ljava/lang/String;)V");\r
+        if (cb == NULL)\r
+        {\r
+            LOGE("JNI TEST - Error: cannot get callback method");\r
+            return;\r
+        }\r
+        LOGI("JNI TEST - Get callback method - onSubscribeRequest");\r
+\r
+        jstring msg = (*env)->NewStringUTF(env, consumer);\r
+        LOGI("print: %s", consumer);\r
+\r
+        (*env)->CallVoidMethod(env, jObj, cb, msg);\r
+    }\r
+}\r
+\r
+void JNIMessageSyncCallback(JNIEnv * env, jobject jObj, char * message)\r
+{\r
+    static jmethodID cb = NULL;\r
+    //jclass cls = (*env)->FindClass(env, "com/sec/notiproviderexample/ProviderExample");\r
+    jclass cls = (*env)->GetObjectClass(env, jObj);\r
+    if (cls == NULL)\r
+    {\r
+        LOGE("JNI TEST - Error: cannot find callback class");\r
+    }\r
+\r
+    if (cb == NULL)\r
+    {\r
+        cb = (*env)->GetMethodID(env, cls, "onMessageSync", "(Ljava/lang/String;)V");\r
+        if (cb == NULL)\r
+        {\r
+            LOGE("JNI TEST - Error: cannot get callback method");\r
+            return;\r
+        }\r
+        LOGI("JNI TEST - Get callback method - onMessageSync");\r
+\r
+        jstring msg = (*env)->NewStringUTF(env, message);\r
+        LOGI("print: %s", message);\r
+\r
+        (*env)->CallVoidMethod(env, jObj, cb, msg);\r
+    }\r
+}\r
+\r
+void NSSubscribeRequestCb(NSConsumer *consumer)\r
+{\r
+    LOGI("JNI TEST - consumer requested to subscribe");\r
+\r
+    char *cid = consumer->mId;\r
+    LOGI("JNI TEST - NS_ Consumer ID: %s\n", cid);\r
+\r
+    bool isAttached = false;\r
+    JNIEnv* env;\r
+    jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);\r
+    if (JNI_OK != res)\r
+    {\r
+        LOGI("AttachCurrentThread for JNIEnv pointer");\r
+        res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);\r
+\r
+        if (JNI_OK != res)\r
+        {\r
+            LOGE("AttachCurrentThread has failed");\r
+            return;\r
+        }\r
+        isAttached = true;\r
+    }\r
+\r
+    // callback to app\r
+    JNISubscribeRequestCallback(env, g_obj, cid);\r
+\r
+    if (isAttached)\r
+    {\r
+        (*g_jvm)->DetachCurrentThread(g_jvm);\r
+    }\r
+\r
+    NSAccept(consumer, true);\r
+}\r
+\r
+void NSSyncCb(NSProvider *provider, NSSync *sync)\r
+{\r
+    LOGI("JNI TEST - sync requested");\r
+    LOGI("JNI TEST - NS_ Sync MessageID: %s\n", sync->mMessageId);\r
+    LOGI("JNI TEST - NS_ Sync State: %d\n", sync->mState);\r
+\r
+    bool isAttached = false;\r
+    JNIEnv* env;\r
+    jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);\r
+    if (JNI_OK != res)\r
+    {\r
+        LOGI("AttachCurrentThread for JNIEnv pointer");\r
+        res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);\r
+\r
+        if (JNI_OK != res)\r
+        {\r
+            LOGE("AttachCurrentThread has failed");\r
+            return;\r
+        }\r
+        isAttached = true;\r
+    }\r
+\r
+    // callback to app\r
+    JNIMessageSyncCallback(env, g_obj, sync->mMessageId);\r
+\r
+    if (isAttached)\r
+    {\r
+        (*g_jvm)->DetachCurrentThread(g_jvm);\r
+    }\r
+\r
+}\r
diff --git a/service/notification/android/notification-service/src/main/jni/notificationProvider.h b/service/notification/android/notification-service/src/main/jni/notificationProvider.h
new file mode 100644 (file)
index 0000000..406bd5f
--- /dev/null
@@ -0,0 +1,47 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */\r
+#include <jni.h>\r
+#include "NSProviderInterface.h"\r
+#include "NSCommon.h"\r
+/* Header for class com_sec_notiproviderjni_IoTNotification */\r
+\r
+#ifndef NOTIFICATION_JNI_H\r
+#define NOTIFICATION_JNI_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/*\r
+ * Class:     com_sec_notiproviderjni_IoTNotification\r
+ * Method:    stringFromJNI\r
+ * Signature: ()Ljava/lang/String;\r
+ */\r
+ JNIEXPORT jint JNICALL Java_org_iotivity_service_notification_IoTNotification_NSStartProvider\r
+ (JNIEnv *, jobject, jboolean);\r
+\r
+ JNIEXPORT jint JNICALL Java_org_iotivity_service_notification_IoTNotification_NSStopProvider\r
+  (JNIEnv *, jobject);\r
+\r
+ JNIEXPORT jint JNICALL Java_org_iotivity_service_notification_IoTNotification_NSSendNotification\r
+  (JNIEnv *, jobject, jobject);\r
+\r
+ JNIEXPORT jint JNICALL Java_org_iotivity_service_notification_IoTNotification_NSProviderReadCheck\r
+  (JNIEnv *, jobject, jobject);\r
+\r
+ JNIEXPORT jint JNICALL Java_org_iotivity_service_notification_IoTNotification_NSAccept\r
+  (JNIEnv *, jobject, jobject, jboolean);\r
+\r
+ void JNIlogPrintedCallback(JNIEnv*, jobject, const char*);\r
+\r
+ void JNISubscribeRequestCallback(JNIEnv*, jobject, char*);\r
+\r
+ void JNIMessageSyncCallback(JNIEnv*, jobject, char*);\r
+\r
+ void NSSubscribeRequestCb(NSConsumer*);\r
+\r
+ void NSSyncCb(NSProvider*, NSSync*);\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/service/notification/android/settings.gradle b/service/notification/android/settings.gradle
new file mode 100644 (file)
index 0000000..60ffa33
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * //******************************************************************
+ * //
+ * // 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.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+include ':notification-service'