From 95646376dc7f52cce82d025600b2d30d46c2c697 Mon Sep 17 00:00:00 2001 From: "nikhil.a" Date: Tue, 9 Aug 2016 13:06:14 +0530 Subject: [PATCH] Notification ProviderService Java API Updation 1) Updated the JAVA API's for the NS ProviderService using C++ wrapper 2) Modified the JNI API's for NS ProviderService 3) Added the sample Android application for testing the Java API for Provider. Change-Id: I1df1509e9f95d5c7df3d6711dadd0889d1997045 Signed-off-by: nikhil.a Reviewed-on: https://gerrit.iotivity.org/gerrit/10031 Tested-by: jenkins-iotivity Reviewed-by: Abitha Shankar Reviewed-by: Madan Lanka --- .../org/iotivity/service/ns/IoTNotification.java | 35 - .../java/org/iotivity/service/ns/NSMessage.java | 71 -- .../main/java/org/iotivity/service/ns/NSSync.java | 46 -- .../ns/{NSConsumer.java => provider/Consumer.java} | 93 +-- .../service/ns/provider/ProviderService.java | 109 +++ .../notification-service/src/main/jni/Android.mk | 31 +- .../src/main/jni/notificationProvider.c | 313 --------- .../src/main/jni/notificationProvider.h | 57 -- .../main/jni/provider/JniNotificationProvider.cpp | 752 +++++++++++++++++++++ .../main/jni/provider/JniNotificationProvider.h | 94 +++ .../android/NotiProviderExample/.idea/.name | 1 - .../android/NotiProviderExample/.idea/compiler.xml | 22 - .../.idea/copyright/profiles_settings.xml | 3 - .../android/NotiProviderExample/.idea/gradle.xml | 20 - .../.idea/inspectionProfiles/Project_Default.xml | 6 - .../.idea/inspectionProfiles/profiles_settings.xml | 7 - .../android/NotiProviderExample/.idea/misc.xml | 46 -- .../android/NotiProviderExample/.idea/modules.xml | 13 - .../.idea/runConfigurations.xml | 12 - .../android/NotiProviderExample/.idea/vcs.xml | 6 - .../android/NotiProviderExample/app/build.gradle | 6 +- .../com/sec/notiproviderexample/MainActivity.java | 56 +- .../com/sec/notiproviderexample/NotiListener.java | 51 +- .../com/sec/notiproviderexample/ProviderProxy.java | 180 +++-- .../build.gradle | 2 +- .../iotivity-base-armeabi-debug/build.gradle | 2 + .../iotivity-base-armeabi-release/build.gradle | 2 - .../android/NotiProviderExample/settings.gradle | 2 +- 28 files changed, 1198 insertions(+), 840 deletions(-) delete mode 100644 service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/IoTNotification.java delete mode 100644 service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/NSMessage.java delete mode 100644 service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/NSSync.java rename service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/{NSConsumer.java => provider/Consumer.java} (54%) create mode 100644 service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/provider/ProviderService.java delete mode 100755 service/notification/android/notification-service/src/main/jni/notificationProvider.c delete mode 100644 service/notification/android/notification-service/src/main/jni/notificationProvider.h create mode 100644 service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.cpp create mode 100644 service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.h delete mode 100644 service/notification/examples/android/NotiProviderExample/.idea/.name delete mode 100644 service/notification/examples/android/NotiProviderExample/.idea/compiler.xml delete mode 100644 service/notification/examples/android/NotiProviderExample/.idea/copyright/profiles_settings.xml delete mode 100644 service/notification/examples/android/NotiProviderExample/.idea/gradle.xml delete mode 100644 service/notification/examples/android/NotiProviderExample/.idea/inspectionProfiles/Project_Default.xml delete mode 100644 service/notification/examples/android/NotiProviderExample/.idea/inspectionProfiles/profiles_settings.xml delete mode 100644 service/notification/examples/android/NotiProviderExample/.idea/misc.xml delete mode 100644 service/notification/examples/android/NotiProviderExample/.idea/modules.xml delete mode 100644 service/notification/examples/android/NotiProviderExample/.idea/runConfigurations.xml delete mode 100644 service/notification/examples/android/NotiProviderExample/.idea/vcs.xml rename service/notification/examples/android/NotiProviderExample/{iotivity-armeabi-notification-service-release => iotivity-armeabi-notification-service-debug}/build.gradle (83%) create mode 100644 service/notification/examples/android/NotiProviderExample/iotivity-base-armeabi-debug/build.gradle delete mode 100644 service/notification/examples/android/NotiProviderExample/iotivity-base-armeabi-release/build.gradle diff --git a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/IoTNotification.java b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/IoTNotification.java deleted file mode 100644 index a27afbc..0000000 --- a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/IoTNotification.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.iotivity.service.ns; - -import android.util.Log; -import org.iotivity.service.ns.NSMessage; -import org.iotivity.service.ns.NSConsumer; -import org.iotivity.service.ns.NSSync; - -public class IoTNotification -{ - public IoTNotification() - { - } - - static - { - System.loadLibrary("notification_provider_jni"); - } - - public native int NSStartProvider(boolean access, - NSSubscriptionListner subscriptionListener, - NSSynchListner syncListener); - public native int NSStopProvider(); - public native int NSSendNotification(NSMessage message); - public native int NSProviderReadCheck(NSMessage message); - public native int NSAccept(NSConsumer consumer, boolean accepted); - - public interface NSSubscriptionListner { - public void OnNSSubscribedEvent(String consumerId); - } - - public interface NSSynchListner { - public void OnNSSynchronizedEvent(String messageId, int syncState); - } -} - diff --git a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/NSMessage.java b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/NSMessage.java deleted file mode 100644 index 66e7540..0000000 --- a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/NSMessage.java +++ /dev/null @@ -1,71 +0,0 @@ -//****************************************************************** -// -// Copyright 2016 Samsung Electronics All Rights Reserved. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - -package org.iotivity.service.ns; - -import android.util.Log; - -public class NSMessage -{ - String id = null; - String title = null; - String body = null; - String source = null; - - public NSMessage(String id) - { - this.id = id; - } - - public String getId() - { - return id; - } - - public String getTitle() - { - return title; - } - - public void setTitle(String title) - { - this.title = title; - } - - public String getBody() - { - return body; - } - - public void setBody(String body) - { - this.body = body; - } - - public String getSource() - { - return source; - } - - public void setSource(String source) - { - this.source = source; - } -} diff --git a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/NSSync.java b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/NSSync.java deleted file mode 100644 index 065ae99..0000000 --- a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/NSSync.java +++ /dev/null @@ -1,46 +0,0 @@ -//****************************************************************** -// -// Copyright 2016 Samsung Electronics All Rights Reserved. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - -package org.iotivity.service.ns; - -import android.util.Log; - -public class NSSync { - - String mMessageId = null; - String mDeviceId = null; - - public NSSync(String id) { - this.mMessageId = id; - } - - public String getMessageId() { - return mMessageId; - } - - public String getDeviceId() { - return mDeviceId; - } - - public void setDeviceId(String id) { - this.mDeviceId = id; - } - -} diff --git a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/NSConsumer.java b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/provider/Consumer.java similarity index 54% rename from service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/NSConsumer.java rename to service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/provider/Consumer.java index 58b04cd..6875ffc 100644 --- a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/NSConsumer.java +++ b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/provider/Consumer.java @@ -1,46 +1,47 @@ -//****************************************************************** -// -// Copyright 2016 Samsung Electronics All Rights Reserved. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - -package org.iotivity.service.ns; - -import android.util.Log; - -public class NSConsumer { - - String mId = null; - String mAddress = null; - - public NSConsumer(String id) { - this.mId = id; - } - - public String getId() { - return mId; - } - - public String getAddress() { - return mAddress; - } - - public void setAddress(String address) { - this.mAddress = address; - } - -} +//****************************************************************** +// +// Copyright 2016 Samsung Electronics All Rights Reserved. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +package org.iotivity.service.ns.provider; +import org.iotivity.service.ns.common.*; +/** + * @class Consumer + * @brief This class provides implementation of Notification Consumer object. + */ +public class Consumer +{ + public native int nativeAcceptSubscription(Consumer consumer, boolean accepted); + + public String mConsumerId; + + public Consumer(final String consumerId) + { + mConsumerId = consumerId; + } + public String getConsumerId( ) + { + return mConsumerId; + } + public int AcceptSubscription(Consumer consumer, boolean accepted) throws NSException + { + if (consumer != null) + return nativeAcceptSubscription(consumer, accepted); + return -1; + } + +} \ No newline at end of file diff --git a/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/provider/ProviderService.java b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/provider/ProviderService.java new file mode 100644 index 0000000..d09133d --- /dev/null +++ b/service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/provider/ProviderService.java @@ -0,0 +1,109 @@ +//****************************************************************** +// +// Copyright 2016 Samsung Electronics All Rights Reserved. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +package org.iotivity.service.ns.provider; +import org.iotivity.service.ns.common.*; +/** + * @class ProviderService + * @brief This class provides a set of Java APIs for Notification ProviderService. + */ +public class ProviderService +{ + + static + { + System.loadLibrary("gnustl_shared"); + System.loadLibrary("oc_logger"); + System.loadLibrary("connectivity_abstraction"); + System.loadLibrary("ca-interface"); + System.loadLibrary("octbstack"); + System.loadLibrary("oc"); + System.loadLibrary("ocstack-jni"); + System.loadLibrary("notification_provider"); + System.loadLibrary("notification_provider_wrapper"); + System.loadLibrary("notification_provider_jni"); + } + public native int nativeStart(boolean policy, + OnSubscriptionListener subscriptionListener, + OnSyncInfoListener syncInfoListener); + public native int nativeStop(); + public native int nativeSendMessage(Message message); + public native void nativeSendSyncInfo( long messageId , int type); + public native int nativeEnableRemoteService(String servAdd); + public native int nativeDisableRemoteService(String servAdd); + + private static ProviderService instance; + + static + { + instance = new ProviderService(); + } + public interface OnSubscriptionListener + { + public void onConsumerSubscribed(Consumer consumer); + } + public interface OnSyncInfoListener + { + public void onMessageSynchronized(SyncInfo syncInfo); + } + + public static ProviderService getInstance() + { + return instance; + } + public int Start(boolean policy, + OnSubscriptionListener subscriptionListener, + OnSyncInfoListener syncInfoListener) throws NSException + { + + int result = nativeStart(policy, subscriptionListener, syncInfoListener); + return result; + } + + public int Stop() throws NSException + { + int result = nativeStop(); + return result; + } + + public int SendMessage(Message message) throws NSException + { + int result = nativeSendMessage(message); + return result; + } + + public void SendSyncInfo ( long messageId , SyncInfo.SyncType syncType) throws NSException + { + nativeSendSyncInfo(messageId, syncType.ordinal()); + return ; + } + + public int EnableRemoteService(String servAdd) throws NSException + { + int result = nativeEnableRemoteService(servAdd); + return result; + } + + public int DisableRemoteService(String servAdd) throws NSException + { + int result = nativeDisableRemoteService(servAdd); + return result; + } + +} diff --git a/service/notification/android/notification-service/src/main/jni/Android.mk b/service/notification/android/notification-service/src/main/jni/Android.mk index fa15363..13a1dfb 100755 --- a/service/notification/android/notification-service/src/main/jni/Android.mk +++ b/service/notification/android/notification-service/src/main/jni/Android.mk @@ -51,24 +51,30 @@ LOCAL_SRC_FILES += common/JniNotificationCommon.cpp include $(BUILD_SHARED_LIBRARY) include $(CLEAR_VARS) OIC_LIB_PATH := $(ROOT_PATH)/out/android/$(TARGET_ARCH_ABI)/$(APP_OPTIM) +LOCAL_MODULE := notification_provider_wrapper +LOCAL_SRC_FILES := $(OIC_LIB_PATH)/libnotification_provider_wrapper.so +include $(PREBUILT_SHARED_LIBRARY) + +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_LDLIBS := -llog -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 +LOCAL_SHARED_LIBRARIES := ca_interface +LOCAL_SHARED_LIBRARIES += ca +LOCAL_SHARED_LIBRARIES += oc_logger_core +LOCAL_SHARED_LIBRARIES += oc_logger +LOCAL_SHARED_LIBRARIES += octbstack +LOCAL_SHARED_LIBRARIES += oc +LOCAL_SHARED_LIBRARIES += ocstack-jni +LOCAL_SHARED_LIBRARIES += notification_provider +LOCAL_SHARED_LIBRARIES += notification_provider_wrapper OIC_SRC_DIR := ../../../../../.. @@ -76,13 +82,18 @@ 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/c_common/oic_string/include 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)/service/notification/android/notification-service/src/main/jni/common +LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/service/notification/cpp-wrapper/common +LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/service/notification/cpp-wrapper/provider/inc LOCAL_C_INCLUDES += $(OIC_SRC_DIR)/extlibs/ -LOCAL_SRC_FILES := notificationProvider.c +LOCAL_SRC_FILES := provider/JniNotificationProvider.cpp +LOCAL_SRC_FILES += common/JniNotificationCommon.cpp include $(BUILD_SHARED_LIBRARY) \ No newline at end of file diff --git a/service/notification/android/notification-service/src/main/jni/notificationProvider.c b/service/notification/android/notification-service/src/main/jni/notificationProvider.c deleted file mode 100755 index b60367e..0000000 --- a/service/notification/android/notification-service/src/main/jni/notificationProvider.c +++ /dev/null @@ -1,313 +0,0 @@ -//****************************************************************** -// -// Copyright 2016 Samsung Electronics All Rights Reserved. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - -#include -#include -#include "notificationProvider.h" - -#define LOG_TAG "JNI_NS_INTERFACE" -#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) -#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) - -static JavaVM *g_jvm = NULL; -static jobject g_obj_subscriptionListener = NULL; -static jobject g_obj_syncListener = NULL; - -JNIEXPORT jint JNI_OnLoad(JavaVM *jvm, void *reserved) -{ - LOGI("Initialize NSInterface"); - g_jvm = jvm; - - return JNI_VERSION_1_6; -} - -JNIEXPORT jint JNICALL Java_org_iotivity_service_notification_IoTNotification_NSStartProvider( - JNIEnv * env, jobject jObj, jboolean jAccess, jobject jSubscriptionListener, - jobject jSyncListener) -{ - LOGI("NSStartProvider..."); - - if (!jSubscriptionListener || !jSyncListener) - { - LOGI("Fail to set listeners"); - } - - g_obj_subscriptionListener = (jobject) (*env)->NewGlobalRef(env, jSubscriptionListener); - g_obj_syncListener = (jobject) (*env)->NewGlobalRef(env, jSyncListener); - - NSProviderConfig config; - config.subRequestCallback = NSSubscribeRequestCb; - config.syncInfoCallback = NSSyncCb; - config.policy = true; - if (NSStartProvider(config) != NS_OK) - { - LOGE("Fail to start NSProvider service"); - return (jint) NS_ERROR; - } - - return (jint) NS_OK; -} - -JNIEXPORT jint JNICALL Java_org_iotivity_service_notification_IoTNotification_NSStopProvider( - JNIEnv * env, jobject jObj) -{ - LOGI("NSStopProvider"); - - (*env)->DeleteGlobalRef(env, g_obj_subscriptionListener); - (*env)->DeleteGlobalRef(env, g_obj_syncListener); - - if (NSStopProvider() != NS_OK) - { - LOGE("Fail to stop NSProvider service"); - return (jint) NS_ERROR; - } - - return (jint) NS_OK; -} - -JNIEXPORT jint JNICALL Java_org_iotivity_service_notification_IoTNotification_NSSendNotification( - JNIEnv * env, jobject jObj, jobject jMsg) -{ - LOGI("NSSendNotification"); - - if (!jMsg) - { - LOGI("Fail to send notification - Message is null"); - return (jint) NS_ERROR; - } - - NSMessage * nsMsg = NSGetMessage(env, jMsg); - - LOGI("JNI TEST - NSSendNotification"); - NSSendNotification(nsMsg); - - return (jint) NS_OK; -} - -JNIEXPORT jint JNICALL Java_org_iotivity_service_notification_IoTNotification_NSProviderReadCheck( - JNIEnv * env, jobject jObj, jobject jMsg) -{ - LOGI("NSReasCheck"); - return 0; -} - -JNIEXPORT jint JNICALL Java_org_iotivity_service_notification_IoTNotification_NSAcceptSubscription(JNIEnv * env, - jobject jObj, jobject jConsumer, jboolean jAccepted) -{ - if (jAccepted) - { - LOGI("Accepted"); - //NSAccept(consumer, true); - } - else - { - LOGI("Denied"); - //NSAccept(consumer, false); - } - - return 0; -} - -void NSSubscribeRequestCb(NSConsumer *consumer) -{ - LOGI("Subscription requested by consumer"); - - JNIEnv * env; - jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6); - if (JNI_OK != res) - { - if (res == JNI_EDETACHED) - { - if ((*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL) != JNI_OK) - { - LOGE("Failed to get the environment"); - return; - } - else - { - LOGE("Success to get the environment"); - } - } - else - { - LOGE("Failed to get the environment using GetEnv()"); - return; - } - } - - LOGI("consumer ID : %s\n", consumer->consumerId); - jstring consumerId = (*env)->NewStringUTF(env, consumer->consumerId); - - jclass cls = (*env)->GetObjectClass(env, g_obj_subscriptionListener); - if (!cls) - { - LOGE("Failed to Get ObjectClass"); - return; - } - jmethodID mid = (*env)->GetMethodID(env, cls, "OnNSSubscribedEvent", "(Ljava/lang/String;)V"); - if (!mid) - { - LOGE("Failed to Get MethodID"); - return; - } - - (*env)->CallVoidMethod(env, g_obj_subscriptionListener, mid, consumerId); - - (*g_jvm)->DetachCurrentThread(g_jvm); - - NSAcceptSubscription(consumer, true); - - return; -} - -void NSSyncCb(NSSyncInfo *sync) -{ - LOGI("Sync requested"); - - JNIEnv * env; - jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6); - if (JNI_OK != res) - { - if (JNI_EDETACHED) - { - if ((*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL) < 0) - { - LOGE("Failed to get the environment"); - return; - } - else - { - LOGE("Success to get the environment"); - } - } - else - { - LOGE("Failed to get the environment using GetEnv()"); - return; - } - } - - LOGI("Sync ID : %s\n", sync->messageId); - LOGI("Sync STATE : %d\n", sync->state); - - jstring strMessageId = (*env)->NewStringUTF(env, sync->messageId); - - jclass cls = (*env)->GetObjectClass(env, g_obj_syncListener); - if (!cls) - { - LOGE("Failed to Get ObjectClass"); - return; - } - jmethodID mid = (*env)->GetMethodID(env, cls, "OnNSSynchronizedEvent", - "(Ljava/lang/String;I)V"); - if (!mid) - { - LOGE("Failed to Get MethodID"); - return; - } - - (*env)->CallVoidMethod(env, g_obj_syncListener, mid, strMessageId, (jint) sync->state); - - (*g_jvm)->DetachCurrentThread(g_jvm); - - return; - -} - -NSMessage * NSGetMessage(JNIEnv * env, jobject jMsg) -{ - LOGI("NSGetMessage"); - - jclass cls = (*env)->GetObjectClass(env, jMsg); - - // Message ID - jfieldID fid_id = (*env)->GetFieldID(env, cls, "id", "Ljava/lang/String;"); - if (fid_id == NULL) - { - LOGE("Error: jfieldID for message id is null"); - return (jint) NS_ERROR; - } - jstring jmsgId = (*env)->GetObjectField(env, jMsg, fid_id); - const char * messageId = (*env)->GetStringUTFChars(env, jmsgId, NULL); - if (messageId == NULL) - { - LOGE("Error: messageId is null"); - return (jint) NS_ERROR; - } - LOGI("Message ID: %s\n", messageId); - - // Message Title - jfieldID fid_title = (*env)->GetFieldID(env, cls, "title", "Ljava/lang/String;"); - if (fid_title == NULL) - { - LOGE("Error: jfieldID for message id is null"); - return (jint) NS_ERROR; - } - jstring jmsgTitle = (*env)->GetObjectField(env, jMsg, fid_title); - const char * messageTitle = (*env)->GetStringUTFChars(env, jmsgTitle, NULL); - if (messageTitle == NULL) - { - LOGE("Error: messageTitle is null"); - return (jint) NS_ERROR; - } - LOGI("Message Title: %s\n", messageTitle); - - // Message Body - jfieldID fid_body = (*env)->GetFieldID(env, cls, "body", "Ljava/lang/String;"); - if (fid_body == NULL) - { - LOGE("Error: jfieldID for message id is null"); - return (jint) NS_ERROR; - } - jstring jmsgBody = (*env)->GetObjectField(env, jMsg, fid_body); - const char * messageBody = (*env)->GetStringUTFChars(env, jmsgBody, NULL); - if (messageBody == NULL) - { - LOGE("Error: messageBody is null"); - return (jint) NS_ERROR; - } - LOGI("Message Body: %s\n", messageBody); - - // Message Source - jfieldID fid_source = (*env)->GetFieldID(env, cls, "source", "Ljava/lang/String;"); - if (fid_source == NULL) - { - LOGE("Error: jfieldID for message source is null"); - return (jint) NS_ERROR; - } - jstring jmsgSource = (*env)->GetObjectField(env, jMsg, fid_source); - const char * messageSource = (*env)->GetStringUTFChars(env, jmsgSource, NULL); - if (messageSource == NULL) - { - LOGE("Error: messageSource is null"); - return (jint) NS_ERROR; - } - LOGI("Message Source: %s\n", messageSource); - - NSMessage * nsMsg = (NSMessage *) malloc(sizeof(NSMessage)); - - nsMsg->messageId = strdup(messageId); - nsMsg->title = strdup(messageTitle); - nsMsg->contentText = strdup(messageBody); - nsMsg->sourceName = strdup(messageSource); - - return nsMsg; - -} diff --git a/service/notification/android/notification-service/src/main/jni/notificationProvider.h b/service/notification/android/notification-service/src/main/jni/notificationProvider.h deleted file mode 100644 index 93c0ca4..0000000 --- a/service/notification/android/notification-service/src/main/jni/notificationProvider.h +++ /dev/null @@ -1,57 +0,0 @@ -//****************************************************************** -// -// Copyright 2016 Samsung Electronics All Rights Reserved. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - -#include - -#include "NSProviderInterface.h" -#include "NSCommon.h" - -#ifndef NOTIFICATION_JNI_H -#define NOTIFICATION_JNI_H -#ifdef __cplusplus -extern "C" -{ -#endif - - JNIEXPORT jint JNICALL Java_org_iotivity_service_notification_IoTNotification_NSStartProvider( - JNIEnv *, jobject, jboolean, jobject, jobject); - - JNIEXPORT jint JNICALL Java_org_iotivity_service_notification_IoTNotification_NSStopProvider( - JNIEnv *, jobject); - - JNIEXPORT jint JNICALL Java_org_iotivity_service_notification_IoTNotification_NSSendNotification( - JNIEnv *, jobject, jobject); - - JNIEXPORT jint JNICALL Java_org_iotivity_service_notification_IoTNotification_NSProviderReadCheck( - JNIEnv *, jobject, jobject); - - JNIEXPORT jint JNICALL Java_org_iotivity_service_notification_IoTNotification_NSAcceptSubscription(JNIEnv *, - jobject, jobject, jboolean); - - void NSSubscribeRequestCb(NSConsumer*); - - void NSSyncCb(NSSyncInfo*); - - NSMessage * NSGetMessage(JNIEnv *, jobject); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.cpp b/service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.cpp new file mode 100644 index 0000000..595a0d9 --- /dev/null +++ b/service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.cpp @@ -0,0 +1,752 @@ +//****************************************************************** +// +// Copyright 2016 Samsung Electronics All Rights Reserved. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +#include "JniNotificationProvider.h" +#include "NSProviderService.h" + +static JavaVM *g_jvm = NULL; + +static jobject g_obj_subscriptionListener = NULL; +static jobject g_obj_syncListener = NULL; + +jclass g_cls_Message; +jclass g_cls_Message_Type; +jclass g_cls_Consumer; +jclass g_cls_SyncInfo; +jclass g_cls_SyncType; +jclass g_cls_MediaContents; + +static JNIEnv *GetJNIEnv(jint *ret) +{ + JNIEnv *env = NULL; + + *ret = g_jvm->GetEnv((void **) &env, JNI_CURRENT_VERSION); + switch (*ret) + { + case JNI_OK: + return env; + case JNI_EDETACHED: + if (g_jvm->AttachCurrentThread(&env, NULL) != JNI_OK) + { + LOGE ("Failed to get the environment"); + return NULL; + } + else + { + return env; + } + case JNI_EVERSION: + LOGE ("JNI version is not supported"); + default: + LOGE ("Failed to get the environment"); + return NULL; + } +} + +void onSubscribeListenerCb(OIC::Service::NSConsumer *consumer) +{ + LOGI("JNIProviderService_onSubscribeListenerCb - IN"); + + jint envRet; + JNIEnv *env = GetJNIEnv(&envRet); + if (NULL == env) return ; + + jobject jSubscriptionListener = (jobject) env->NewLocalRef(g_obj_subscriptionListener); + if (!jSubscriptionListener) + { + LOGE ("Failed to Get jSubscriptionListener"); + if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + return ; + } + + LOGI("consumer ID : %s\n", consumer->getConsumerId().c_str()); + + jstring jConsumerId = env->NewStringUTF( consumer->getConsumerId().c_str()); + + jclass cls_consumer = (jclass) (env->NewLocalRef(g_cls_Consumer)); + if (!cls_consumer) + { + LOGE ("Failed to Get ObjectClass for Consumer"); + if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + return ; + } + + jmethodID mid_consumer = env->GetMethodID( + cls_consumer, + "", + "(JLjava/lang/String;Lorg/iotivity/service/ns/provider/Consumer)V"); + if (!mid_consumer) + { + LOGE ("Failed to Get MethodID for Consumer"); + if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + return ; + } + jobject obj_consumer = env->NewObject( cls_consumer, mid_consumer, jConsumerId); + + jclass cls = env->GetObjectClass( jSubscriptionListener); + if (!cls) + { + LOGE("Failed to Get ObjectClass of jSubscriptionListener"); + if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + return; + } + jmethodID mid = env->GetMethodID( + cls, + "onConsumerSubscribed", + "(Lorg/iotivity/service/ns/provider/Consumer;)V"); + if (!mid) + { + LOGE("Failed to Get MethodID of onConsumerSubscribed"); + if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + return; + } + + env->CallVoidMethod( jSubscriptionListener, mid, obj_consumer); + env->DeleteLocalRef(jSubscriptionListener); + env->DeleteLocalRef(cls_consumer); + if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + LOGI("JNIProviderService_onSubscribeListenerCb - OUT"); + return; +} + +void onSyncInfoListenerCb(OIC::Service::NSSyncInfo *sync) +{ + LOGI("JNIProviderService_onSyncInfoListenerCb - IN"); + + jint envRet; + JNIEnv *env = GetJNIEnv(&envRet); + if (NULL == env) return ; + + jobject jSyncListener = (jobject) env->NewLocalRef(g_obj_syncListener); + if (!jSyncListener) + { + LOGE ("Failed to Get jSyncListener"); + if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + return ; + } + + LOGI("Sync ID : %ld\n", (long) sync->getMessageId()); + LOGI("Sync STATE : %d\n", (int) sync->getState()); + + jlong jMessageId = (long) sync->getMessageId(); + jstring jProviderId = env->NewStringUTF(sync->getProviderId().c_str()); + jobject syncType; + + jclass cls_SyncType = (jclass) (env->NewLocalRef(g_cls_SyncType)); + if (!cls_SyncType) + { + LOGE ("Failed to Get ObjectClass for SyncType"); + if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + return ; + } + switch (sync->getState()) + { + case OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_UNREAD: + { + static jfieldID fieldID = env->GetStaticFieldID(cls_SyncType, + "UNREAD", "Lorg/iotivity/service/ns/common/SyncInfo$SyncType;"); + syncType = env->GetStaticObjectField(cls_SyncType, fieldID); + } + case OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ : + { + static jfieldID fieldID = env->GetStaticFieldID(cls_SyncType, + "READ", "Lorg/iotivity/service/ns/common/SyncInfo$SyncType;"); + syncType = env->GetStaticObjectField(cls_SyncType, fieldID); + } + case OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED : + { + static jfieldID fieldID = env->GetStaticFieldID(cls_SyncType, + "DELETED", "Lorg/iotivity/service/ns/common/SyncInfo$SyncType;"); + syncType = env->GetStaticObjectField(cls_SyncType, fieldID); + } + + } + + jclass cls_SyncInfo = (jclass) (env->NewLocalRef(g_cls_SyncInfo)); + if (!cls_SyncInfo) + { + LOGE ("Failed to Get ObjectClass for SyncInfo"); + if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + return ; + } + jmethodID mid_syncInfo = env->GetMethodID( + cls_SyncInfo, + "", + "(JLjava/lang/String;Lorg/iotivity/service/ns/common/SyncInfo$SyncType)V"); + if (!mid_syncInfo) + { + LOGE ("Failed to Get MethodID for SyncInfo"); + if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + return ; + } + + jobject obj_syncInfo = env->NewObject( cls_SyncInfo, mid_syncInfo, jMessageId, jProviderId, + syncType); + + jclass cls = env->GetObjectClass( jSyncListener); + if (!cls) + { + LOGE("Failed to Get ObjectClass"); + if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + return; + } + jmethodID mid = env->GetMethodID( cls, "onMessageSynchronized", + "(Lorg/iotivity/service/ns/common/SyncInfo)V"); + if (!mid) + { + LOGE("Failed to Get MethodID"); + if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + return; + } + env->CallVoidMethod( jSyncListener, mid, obj_syncInfo); + + env->DeleteLocalRef(jSyncListener); + env->DeleteLocalRef(cls_SyncInfo); + env->DeleteLocalRef(cls_SyncType); + if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + + LOGI("JNIProviderService: OnSyncInfoListenerCb - OUT"); + return; + +} + +OIC::Service::NSMessage *getMessage(JNIEnv *env, jobject jMsg) +{ + LOGI("JNIProviderService: getMessage - IN"); + + jclass cls = env->GetObjectClass( jMsg); + + // Message type + jclass cls_messageType = (jclass) (env->NewLocalRef(g_cls_Message_Type)); + if (!cls_messageType) + { + LOGE ("Failed to Get ObjectClass for Message Type"); + return nullptr; + } + jmethodID mid = env->GetMethodID(cls_messageType, "ordinal", "()I"); + jfieldID fid_type = env->GetFieldID( cls, "mType", + "Lorg/iotivity/service/ns/common/Message$MessageType;"); + if (fid_type == NULL) + { + LOGE("Error: jfieldID for message type is null"); + return nullptr; + } + jobject jobj = env->GetObjectField( jMsg, fid_type); + if (jobj == NULL) + { + LOGE("Error: object of field Message Type is null"); + return nullptr; + } + jint jtype = env->CallIntMethod(jobj, mid); + OIC::Service::NSMessage::NSMessageType type = (OIC::Service::NSMessage::NSMessageType) jtype; + + LOGI("Message Type: %ld\n", (long )type); + + // Message Time + jfieldID fid_tm = env->GetFieldID( cls, "mTime", "Ljava/lang/String;"); + if (fid_tm == NULL) + { + LOGE("Error: jfieldID for message time is null"); + return nullptr; + } + jstring jtime = (jstring)env->GetObjectField( jMsg, fid_tm); + const char *time = ""; + if (jtime) + { + time = env->GetStringUTFChars( jtime, NULL); + } + else + { + LOGI("Info: messageTitle is null"); + } + LOGI("Message Time: %s\n", time); + + // Message TTL + jfieldID fid_ttl = env->GetFieldID( cls, "mTTL", "J"); + if (fid_ttl == NULL) + { + LOGE("Error: jfieldID for message ttl is null"); + return nullptr; + } + jlong jttl = (jlong) env->GetObjectField( jMsg, fid_ttl); + uint64_t ttl = jttl; + + LOGI("Message ID: %lld\n", ttl); + + // Message Title + jfieldID fid_title = env->GetFieldID( cls, "mTitle", "Ljava/lang/String;"); + if (fid_title == NULL) + { + LOGE("Error: jfieldID for message title is null"); + return nullptr; + } + jstring jmsgTitle = (jstring)env->GetObjectField( jMsg, fid_title); + const char *messageTitle = ""; + if (jmsgTitle) + { + messageTitle = env->GetStringUTFChars( jmsgTitle, NULL); + } + else + { + LOGI("Info: messageTitle is null"); + } + LOGI("Message Title: %s\n", messageTitle); + + // Message Content Text + jfieldID fid_body = env->GetFieldID( cls, "mContentText", "Ljava/lang/String;"); + if (fid_body == NULL) + { + LOGE("Error: jfieldID for message context Text is null"); + return nullptr; + } + jstring jmsgBody = (jstring)env->GetObjectField( jMsg, fid_body); + const char *messageBody = ""; + if (jmsgBody) + { + messageBody = env->GetStringUTFChars( jmsgBody, NULL); + } + else + { + LOGI("Info: messageBody is null"); + } + LOGI("Message Body: %s\n", messageBody); + + // Message Source + jfieldID fid_source = env->GetFieldID( cls, "mSourceName", "Ljava/lang/String;"); + if (fid_source == NULL) + { + LOGE("Error: jfieldID for message source is null"); + return nullptr; + } + jstring jmsgSource = (jstring)env->GetObjectField( jMsg, fid_source); + const char *messageSource = ""; + if (jmsgSource) + { + messageSource = env->GetStringUTFChars( jmsgSource, NULL); + } + else + { + LOGI("Info: messageSource is null"); + } + LOGI("Message Source: %s\n", messageSource); + + // Message MediaContents + jfieldID fid_media = env->GetFieldID( cls, "mMediaContents", + "Lorg/iotivity/service/ns/common/MediaContents;"); + if (fid_media == NULL) + { + LOGE("Error: jfieldID for MediaContents is null"); + return nullptr; + } + jobject jmedia = env->GetObjectField( jMsg, fid_media); + if (jmedia == NULL) + { + LOGE("Error: jmedia object of MediaContents inside Message is null"); + return nullptr; + } + jclass cls_MediaContents = (jclass) (env->NewLocalRef(g_cls_MediaContents)); + if (!cls_MediaContents) + { + LOGE ("Failed to Get ObjectClass for class MediaContents"); + return nullptr; + } + jfieldID fid_icon = env->GetFieldID( cls_MediaContents, "mIconImage", "Ljava/lang/String;"); + if (fid_icon == NULL) + { + LOGE("Error: jfieldID for iconImage is null"); + return nullptr; + } + jstring jiconImage = (jstring)env->GetObjectField( jmedia, fid_icon); + const char *iconImage = ""; + if (jiconImage) + { + iconImage = env->GetStringUTFChars( jiconImage, NULL); + } + else + { + LOGI("Info: iconImage is null"); + } + + LOGI("iconImage: %s\n", iconImage); + + OIC::Service::NSMediaContents *media = new OIC::Service::NSMediaContents(std::string(iconImage)); + OIC::Service::NSMessage *nsMsg = OIC::Service::NSProviderService::getInstance()->CreateMessage(); + + nsMsg->setType(type); + nsMsg->setTime(std::string(time)); + nsMsg->setTTL(ttl); + nsMsg->setTitle(std::string(messageTitle)); + nsMsg->setContentText(std::string(messageBody)); + nsMsg->setSourceName(std::string(messageSource)); + nsMsg->setMediaContents(media); + + env->DeleteLocalRef(cls_messageType); + env->DeleteLocalRef(cls_MediaContents); + + if (jtime) + { + env->ReleaseStringUTFChars(jtime, time); + } + if (jmsgTitle) + { + env->ReleaseStringUTFChars(jmsgTitle, messageTitle); + } + if (jmsgBody) + { + env->ReleaseStringUTFChars(jmsgBody, messageBody); + } + if (jmsgSource) + { + env->ReleaseStringUTFChars(jmsgSource, messageSource); + } + if (jiconImage) + { + env->ReleaseStringUTFChars(jiconImage, iconImage); + } + + LOGI("JNIProviderService: getMessage - OUT"); + return nsMsg; + +} + +JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeStart( + JNIEnv *env, jobject jObj, jboolean jPolicy, jobject jSubscriptionListener, + jobject jSyncListener) +{ + LOGI("JNIProviderService: nativeStart - IN"); + if (!jSubscriptionListener || !jSyncListener) + { + LOGE("Fail to set listeners"); + ThrowNSException(NS_ERROR, "Listener cannot be null"); + return (jint) OIC::Service::Result::ERROR; + } + + if (g_obj_subscriptionListener != NULL) + { + env->DeleteGlobalRef(g_obj_subscriptionListener); + } + if (g_obj_syncListener != NULL) + { + env->DeleteGlobalRef(g_obj_syncListener); + } + + g_obj_subscriptionListener = (jobject) env->NewGlobalRef(jSubscriptionListener); + g_obj_syncListener = (jobject) env->NewGlobalRef(jSyncListener); + + // check access policy + + OIC::Service::NSProviderService::ProviderConfig cfg; + cfg.m_subscribeRequestCb = onSubscribeListenerCb; + cfg.m_syncInfoCb = onSyncInfoListenerCb; + cfg.policy = (bool) jPolicy; + + OIC::Service::Result result = OIC::Service::NSProviderService::getInstance()->Start(cfg); + if (result != OIC::Service::Result::OK) + { + LOGE("Fail to start NSProviderService"); + + } + + LOGI("JNIProviderService: nativeStart - OUT"); + return (jint) result; +} + +JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeStop( + JNIEnv *env, jobject jObj) +{ + LOGI("JNIProviderService: nativeStop - IN"); + + OIC::Service::Result result = OIC::Service::NSProviderService::getInstance()->Stop(); + if (result != OIC::Service::Result::OK) + { + LOGI("Fail to stop NSProvider service"); + return (jint) result; + } + + env->DeleteGlobalRef( g_obj_subscriptionListener); + env->DeleteGlobalRef( g_obj_syncListener); + g_obj_subscriptionListener = NULL; + g_obj_syncListener = NULL; + + LOGI("JNIProviderService: nativeStop - OUT"); + return (jint) result; +} + +JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeSendMessage( + JNIEnv *env, jobject jObj, jobject jMsg) +{ + LOGI("JNIProviderService: nativeSendMessage - IN"); + if (!jMsg) + { + LOGI("Fail to send notification - Message is null"); + ThrowNSException(NS_ERROR, "Message cannot be null"); + return (jint) OIC::Service::Result::ERROR; + } + OIC::Service::NSMessage *nsMsg = getMessage(env, jMsg); + if (nsMsg == nullptr) + { + ThrowNSException(NS_ERROR, "Message didn't have a field ID "); + return (jint) OIC::Service::Result::ERROR; + } + + OIC::Service::Result result = OIC::Service::NSProviderService::getInstance()->SendMessage(nsMsg); + if (result != OIC::Service::Result::OK) + { + LOGI("Fail to send NSProvider Message"); + } + LOGI("JNIProviderService: nativeSendMessage - OUT"); + return (jint) result; +} + +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeSendSyncInfo( + JNIEnv *env, jobject jObj, jlong messageId , jint syncState) +{ + LOGI("JNIProviderService: nativeSendSyncInfo - IN"); + OIC::Service::NSProviderService::getInstance()->SendSyncInfo( messageId, + (OIC::Service::NSSyncInfo::NSSyncType) syncState); + LOGI("JNIProviderService: nativeSendSyncInfo - OUT"); + return; +} + +JNIEXPORT jint JNICALL +Java_org_iotivity_service_ns_provider_ProviderService_nativeEnableRemoteService(JNIEnv *env, + jobject jObj, jstring jstr) +{ + LOGI("JNIProviderService: nativeEnableRemoteService - IN"); + if (!jstr) + { + ThrowNSException(NS_ERROR, "Server Address Can't be NULL"); + return (jint) OIC::Service::Result::ERROR; + } + + const char *address = env->GetStringUTFChars( jstr, NULL); + std::string servAddress(address); + OIC::Service::Result result = OIC::Service::NSProviderService::getInstance()->EnableRemoteService( + servAddress); + if (result != OIC::Service::Result::OK) + { + LOGE("Fail to Enable Remote Service"); + } + env->ReleaseStringUTFChars(jstr, address); + LOGI("JNIProviderService: nativeEnableRemoteService - OUT"); + return (jint) result; +} + +JNIEXPORT jint JNICALL +Java_org_iotivity_service_ns_provider_ProviderService_nativeDisableRemoteService(JNIEnv *env, + jobject jObj, jstring jstr) +{ + LOGI("JNIProviderService: nativeDisableRemoteService - IN"); + if (!jstr) + { + ThrowNSException(NS_ERROR, "Server Address Can't be NULL"); + return (jint) OIC::Service::Result::ERROR; + } + + const char *address = env->GetStringUTFChars( jstr, NULL); + std::string servAddress(address); + OIC::Service::Result result = OIC::Service::NSProviderService::getInstance()->DisableRemoteService( + servAddress); + if (result != OIC::Service::Result::OK) + { + LOGE("Fail to Disable Remote Service"); + } + env->ReleaseStringUTFChars(jstr, address); + LOGI("JNIProviderService: nativeDisableRemoteService - OUT"); + return (jint) result; +} + +JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeAcceptSubscription( + JNIEnv *env, + jobject jObj, jobject jConsumer, jboolean jAccepted) +{ + LOGD("JNIProviderService: nativeAcceptSubscription - IN"); + + jclass consumerClass = env->GetObjectClass( jConsumer); + if (!consumerClass) + { + ThrowNSException(NS_ERROR, "Failed to Get ObjectClass for Consumer"); + return (jint) OIC::Service::Result::ERROR; + } + + // Consumer ID + jfieldID fid_id = env->GetFieldID(consumerClass, "mConsumerId", "Ljava/lang/String;"); + if (fid_id == NULL) + { + LOGE("Error: jfieldID for mConsumerId is null"); + ThrowNSException(NS_ERROR, "ConsumerId not found"); + return (jint) OIC::Service::Result::ERROR; + } + + jstring jconId = (jstring)env->GetObjectField( jConsumer, fid_id); + const char *conId = ""; + if (conId) + { + conId = env->GetStringUTFChars( jconId, NULL); + } + else + { + LOGI("Info: Consumer Id is null"); + } + std::string consumerId(conId); + env->ReleaseStringUTFChars(jconId, conId); + + LOGI("Consumer ID: %s\n", consumerId.c_str()); + + OIC::Service::NSConsumer *consumer = new OIC::Service::NSConsumer(consumerId); + int result = consumer->acceptSubscription(consumer, (bool)jAccepted); + if (jAccepted) + { + LOGI("Subscription Accepted"); + } + else + { + LOGI("Subscription Denied"); + } + + LOGD("JNIProviderService: nativeAcceptSubscription - OUT"); + return result; +} + +// JNI OnLoad +JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) +{ + LOGD("ProviderService_JNI_OnLoad"); + g_jvm = jvm; + + JNIEnv *env; + if (jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK) + { + LOGE("Failed to get the environment using GetEnv()"); + return JNI_ERR; + } + + jclass localMessage = env->FindClass( + "org/iotivity/service/ns/common/Message"); + if (!localMessage) + { + LOGE("Failed to get local Message class"); + return JNI_ERR; + } + g_cls_Message = (jclass) (env->NewGlobalRef(localMessage)); + if (!g_cls_Message) + { + LOGE("Failed to set Global Message reference"); + return JNI_ERR; + } + + jclass localMessageType = env->FindClass( + "org/iotivity/service/ns/common/Message$MessageType"); + if (!localMessageType) + { + LOGE("Failed to get local Message Type class"); + return JNI_ERR; + } + g_cls_Message_Type = (jclass) (env->NewGlobalRef(localMessageType)); + if (!g_cls_Message_Type) + { + LOGE("Failed to set Global Message Type reference"); + return JNI_ERR; + } + + jclass localConsumer = env->FindClass( + "org/iotivity/service/ns/provider/Consumer"); + if (!localConsumer) + { + LOGE("Failed to get local Provider class"); + return JNI_ERR; + } + g_cls_Consumer = (jclass) (env->NewGlobalRef(localConsumer)); + if (!g_cls_Consumer) + { + LOGE("Failed to set Global Provider reference"); + return JNI_ERR; + } + + jclass localSyncInfo = env->FindClass( + "org/iotivity/service/ns/common/SyncInfo"); + if (!localSyncInfo) + { + LOGE("Failed to get local SyncInfo class"); + return JNI_ERR; + } + g_cls_SyncInfo = (jclass) (env->NewGlobalRef(localSyncInfo)); + if (!g_cls_SyncInfo) + { + LOGE("Failed to set Global SyncInfo reference"); + return JNI_ERR; + } + + jclass localSyncType = env->FindClass( + "org/iotivity/service/ns/common/SyncInfo$SyncType"); + if (!localSyncType) + { + LOGE("Failed to get local SyncType enum"); + return JNI_ERR; + } + g_cls_SyncType = (jclass) (env->NewGlobalRef(localSyncType)); + if (!g_cls_SyncType) + { + LOGE("Failed to set Global SyncType reference"); + return JNI_ERR; + } + + jclass localMediaContents = env->FindClass( + "org/iotivity/service/ns/common/MediaContents"); + if (!localMediaContents) + { + LOGE("Failed to get local MediaContents class"); + return JNI_ERR; + } + g_cls_MediaContents = (jclass) (env->NewGlobalRef(localMediaContents)); + if (!g_cls_MediaContents) + { + LOGE("Failed to set Global MediaContents reference"); + return JNI_ERR; + } + + env->DeleteLocalRef(localMessage); + env->DeleteLocalRef(localMessageType); + env->DeleteLocalRef(localConsumer); + env->DeleteLocalRef(localSyncInfo); + env->DeleteLocalRef(localSyncType); + env->DeleteLocalRef(localMediaContents); + + return NSExceptionInit(env); +} + +JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *jvm, void *reserved) +{ + LOGI("ProviderService_JNI_OnUnload"); + JNIEnv *env; + + if (jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK) + { + LOGE("Failed to get the environment using GetEnv()"); + return ; + } + + env->DeleteGlobalRef(g_cls_Message); + env->DeleteGlobalRef(g_cls_Consumer); + env->DeleteGlobalRef(g_cls_SyncInfo); + env->DeleteGlobalRef(g_cls_SyncType); + env->DeleteGlobalRef(g_cls_MediaContents); + env->DeleteGlobalRef(g_cls_Message_Type); +} diff --git a/service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.h b/service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.h new file mode 100644 index 0000000..694edfc --- /dev/null +++ b/service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.h @@ -0,0 +1,94 @@ +//****************************************************************** +// +// Copyright 2016 Samsung Electronics All Rights Reserved. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +#include "JniNotificationCommon.h" + +#ifndef JNI_NOTIFICATION_PROVIDER_H +#define JNI_NOTIFICATION_PROVIDER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Class: org_iotivity_service_ns_provider_ProviderService + * Method: nativeStart + * Signature: (ZLorg/iotivity/service/ns/provider/ProviderService/OnSubscriptionListener;Lorg/iotivity/service/ns/provider/ProviderService/OnSyncInfoListener;)I + */ +JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeStart +(JNIEnv *, jobject, jboolean, jobject, jobject); + +/* + * Class: org_iotivity_service_ns_provider_ProviderService + * Method: nativeStop + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeStop +(JNIEnv *, jobject); + +/* + * Class: org_iotivity_service_ns_provider_ProviderService + * Method: nativeSendMessage + * Signature: (Lorg/iotivity/service/ns/common/Message;)I + */ +JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeSendMessage +(JNIEnv *, jobject, jobject); + +/* + * Class: org_iotivity_service_ns_provider_ProviderService + * Method: nativeSendSyncInfo + * Signature: (JI)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeSendSyncInfo +(JNIEnv *, jobject, jlong, jint); + +/* + * Class: org_iotivity_service_ns_provider_ProviderService + * Method: nativeEnableRemoteService + * Signature: (Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL +Java_org_iotivity_service_ns_provider_ProviderService_nativeEnableRemoteService +(JNIEnv *, jobject, jstring); + +/* + * Class: org_iotivity_service_ns_provider_ProviderService + * Method: nativeDisableRemoteService + * Signature: (Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL +Java_org_iotivity_service_ns_provider_ProviderService_nativeDisableRemoteService +(JNIEnv *, jobject, jstring); + +/* + * Class: org_iotivity_service_ns_provider_Consumer + * Method: nativeAcceptSubscription + * Signature: (Lorg/iotivity/service/ns/provider/Consumer;Z)I + */ +JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeAcceptSubscription +(JNIEnv *, jobject, jobject, jboolean); + + +#ifdef __cplusplus +} +#endif +#endif + + diff --git a/service/notification/examples/android/NotiProviderExample/.idea/.name b/service/notification/examples/android/NotiProviderExample/.idea/.name deleted file mode 100644 index 28684b4..0000000 --- a/service/notification/examples/android/NotiProviderExample/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -NotiProviderExample \ No newline at end of file diff --git a/service/notification/examples/android/NotiProviderExample/.idea/compiler.xml b/service/notification/examples/android/NotiProviderExample/.idea/compiler.xml deleted file mode 100644 index 96cc43e..0000000 --- a/service/notification/examples/android/NotiProviderExample/.idea/compiler.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/service/notification/examples/android/NotiProviderExample/.idea/copyright/profiles_settings.xml b/service/notification/examples/android/NotiProviderExample/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/service/notification/examples/android/NotiProviderExample/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/service/notification/examples/android/NotiProviderExample/.idea/gradle.xml b/service/notification/examples/android/NotiProviderExample/.idea/gradle.xml deleted file mode 100644 index 5dd336e..0000000 --- a/service/notification/examples/android/NotiProviderExample/.idea/gradle.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/service/notification/examples/android/NotiProviderExample/.idea/inspectionProfiles/Project_Default.xml b/service/notification/examples/android/NotiProviderExample/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index a950918..0000000 --- a/service/notification/examples/android/NotiProviderExample/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/service/notification/examples/android/NotiProviderExample/.idea/inspectionProfiles/profiles_settings.xml b/service/notification/examples/android/NotiProviderExample/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 3b31283..0000000 --- a/service/notification/examples/android/NotiProviderExample/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/service/notification/examples/android/NotiProviderExample/.idea/misc.xml b/service/notification/examples/android/NotiProviderExample/.idea/misc.xml deleted file mode 100644 index 5d19981..0000000 --- a/service/notification/examples/android/NotiProviderExample/.idea/misc.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/service/notification/examples/android/NotiProviderExample/.idea/modules.xml b/service/notification/examples/android/NotiProviderExample/.idea/modules.xml deleted file mode 100644 index 20c9fec..0000000 --- a/service/notification/examples/android/NotiProviderExample/.idea/modules.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/service/notification/examples/android/NotiProviderExample/.idea/runConfigurations.xml b/service/notification/examples/android/NotiProviderExample/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/service/notification/examples/android/NotiProviderExample/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/service/notification/examples/android/NotiProviderExample/.idea/vcs.xml b/service/notification/examples/android/NotiProviderExample/.idea/vcs.xml deleted file mode 100644 index b082f7b..0000000 --- a/service/notification/examples/android/NotiProviderExample/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/service/notification/examples/android/NotiProviderExample/app/build.gradle b/service/notification/examples/android/NotiProviderExample/app/build.gradle index 79f0bf3..c20792d 100644 --- a/service/notification/examples/android/NotiProviderExample/app/build.gradle +++ b/service/notification/examples/android/NotiProviderExample/app/build.gradle @@ -6,7 +6,7 @@ android { defaultConfig { applicationId "sample.notification.service.iotivity.org.notificationsample" - minSdkVersion 23 + minSdkVersion 21 targetSdkVersion 23 versionCode 1 versionName "1.0" @@ -16,6 +16,6 @@ android { dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:appcompat-v7:23.0.1' - compile project(':iotivity-base-armeabi-release') - compile project(':iotivity-armeabi-notification-service-release') + compile project(':iotivity-armeabi-notification-service-debug') + compile project(':iotivity-base-armeabi-debug') } diff --git a/service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/MainActivity.java b/service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/MainActivity.java index fc9998e..b2772bb 100755 --- a/service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/MainActivity.java +++ b/service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/MainActivity.java @@ -1,23 +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. - * - *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +//****************************************************************** +// +// Copyright 2016 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 com.sec.notiproviderexample; @@ -25,6 +25,7 @@ package com.sec.notiproviderexample; import android.app.Notification; import android.app.NotificationManager; import android.content.Intent; +import android.content.SyncInfo; import android.os.Bundle; import android.os.Handler; import android.os.Message; @@ -36,6 +37,7 @@ import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; +import org.iotivity.service.ns.common.MediaContents; public class MainActivity extends AppCompatActivity { private final String TAG = "NS_MAIN_ACTIVITY"; @@ -157,8 +159,8 @@ public class MainActivity extends AppCompatActivity { TvLog.setText("Start NS-Provider\n"); - boolean access = true; // ptovider controls the acceptance of consumers - mProviderProxy.startNotificationServer(access); + boolean policy = true; // provider controls the acceptance of consumers + mProviderProxy.Start(policy); isStarted = true; } else { Log.e(TAG, "NS Provider Service had already started"); @@ -172,7 +174,6 @@ public class MainActivity extends AppCompatActivity { Log.e(TAG, "Fail to request Accept"); break; } - mProviderProxy.accept("#consumerid", true); } break; @@ -201,6 +202,12 @@ public class MainActivity extends AppCompatActivity { Log.i(TAG, "#" + notiId + " notified .."); TvLog.append("Send Notitication(Msg ID: " + notiId + ")\n"); notiId++; + org.iotivity.service.ns.common.Message notiMessage = new org.iotivity.service.ns.common.Message(title,body,"dss"); + notiMessage.setTTL(10); + notiMessage.setTime("12:10"); + MediaContents media = new MediaContents("daasd"); + notiMessage.setMediaContents(media); + mProviderProxy.SendMessage(notiMessage); } break; @@ -210,7 +217,8 @@ public class MainActivity extends AppCompatActivity { Log.e(TAG, "Fail to send sync"); break; } - //mProviderProxy.readCheck(LastMessageId); + org.iotivity.service.ns.common.SyncInfo.SyncType syncType = org.iotivity.service.ns.common.SyncInfo.SyncType.READ; + mProviderProxy.SendSyncInfo(1,syncType); } break; @@ -221,7 +229,7 @@ public class MainActivity extends AppCompatActivity { break; } - mProviderProxy.stopNotificationServer(); + mProviderProxy.Stop(); isStarted = false; TvLog.append("Stop NS-Provider\n"); diff --git a/service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/NotiListener.java b/service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/NotiListener.java index 4492799..d68560b 100755 --- a/service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/NotiListener.java +++ b/service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/NotiListener.java @@ -1,32 +1,35 @@ /* - ******************************************************************* - * - * 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. - * - *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +//****************************************************************** +// +// Copyright 2016 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 com.sec.notiproviderexample; import android.app.Notification; +import android.content.SyncInfo; import android.os.Bundle; import android.service.notification.NotificationListenerService; import android.service.notification.StatusBarNotification; import android.util.Log; +import org.iotivity.service.ns.common.MediaContents; +import org.iotivity.service.ns.common.Message; import java.util.ArrayList; public class NotiListener extends NotificationListenerService { @@ -103,8 +106,13 @@ public class NotiListener extends NotificationListenerService { Log.i(TAG, "Title : " + title); Log.i(TAG, "Body : " + body); + Message notiMessage = new Message(title,body,source); + notiMessage.setTTL(10); + notiMessage.setTime("12:10"); + MediaContents media = new MediaContents("daasd"); + notiMessage.setMediaContents(media); if (mProviderProxy != null) { - mProviderProxy.sendNSMessage(id, title, body, source); + mProviderProxy.SendMessage(notiMessage); } else { Log.i(TAG, "providerExample is NULL"); } @@ -126,7 +134,8 @@ public class NotiListener extends NotificationListenerService { { if(mProviderProxy.getMsgMap().get(sbn.getId()) == 2) { - mProviderProxy.readCheck(Integer.toString(sbn.getId())); + org.iotivity.service.ns.common.SyncInfo.SyncType type = org.iotivity.service.ns.common.SyncInfo.SyncType.READ; + mProviderProxy.SendSyncInfo(1,type); } } } diff --git a/service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/ProviderProxy.java b/service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/ProviderProxy.java index 9e72f9c..789afe1 100755 --- a/service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/ProviderProxy.java +++ b/service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/ProviderProxy.java @@ -1,31 +1,29 @@ /* - ******************************************************************* - * - * 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. - * - *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +//****************************************************************** +// +// Copyright 2016 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 com.sec.notiproviderexample; -import android.app.NotificationManager; import android.content.Context; import android.os.Handler; -import android.os.Message; import android.util.Log; import android.widget.Toast; @@ -35,20 +33,20 @@ import org.iotivity.base.OcResourceHandle; import org.iotivity.base.PlatformConfig; import org.iotivity.base.QualityOfService; import org.iotivity.base.ServiceType; -import org.iotivity.service.ns.IoTNotification; -import org.iotivity.service.ns.NSConsumer; -import org.iotivity.service.ns.NSMessage; +import org.iotivity.service.ns.provider.*; +import org.iotivity.service.ns.common.*; + import java.util.HashMap; public class ProviderProxy - implements IoTNotification.NSSubscriptionListner, IoTNotification.NSSynchListner{ + implements ProviderService.OnSubscriptionListener, ProviderService.OnSyncInfoListener{ private static final String TAG = "NS_PROVIDER_PROXY"; private Context mContext = null; private OcResourceHandle mResourceHandle; //resource handle - private IoTNotification ioTNotification = null; + private ProviderService ioTNotification = null; private HashMap msgMap; private Handler mHandler = null; @@ -65,7 +63,7 @@ public class ProviderProxy this.msgMap = new HashMap<>(); this.mContext = context; - ioTNotification = new IoTNotification(); + ioTNotification = ProviderService.getInstance(); } public void setHandler(Handler handler) @@ -94,32 +92,51 @@ public class ProviderProxy Log.i(TAG, "Configuration done Successfully"); } - public void startNotificationServer(boolean access) + public void Start(boolean policy) { + Log.i(TAG, "Start ProviderService -IN"); configurePlatform(); - ioTNotification.NSStartProvider(access, this, this); - } + try{ + int result = ioTNotification.Start(policy, this, this); + Log.i(TAG, "Notification Start: " + result); + } + catch(Exception e){ + + } - public void stopNotificationServer() { + Log.i(TAG, "Start ProviderService - OUT"); + } + public void Stop() { + Log.i(TAG, "Stop ProviderService - IN"); try { OcPlatform.stopPresence(); } catch (Exception e) { Log.e(TAG, "Exception: stopping presence when terminating NS server: " + e); } + try{ + int result = ioTNotification.Stop(); + Log.i(TAG, "Notification Stop: " + result); + } + catch(Exception e){ + + } - ioTNotification.NSStopProvider(); + Log.i(TAG, "Stop ProviderService - OUT"); } - public void sendNSMessage(String id, String title, String body, String source) { + public void SendMessage(Message notiMessage) { + Log.i(TAG, "SendMessage ProviderService - IN"); + + try{ + int result = ioTNotification.SendMessage(notiMessage); + Log.i(TAG, "Notification Send Message: " + result); + } + catch(Exception e){ - NSMessage notiMessage = new NSMessage(id); - notiMessage.setTitle(title); - notiMessage.setBody(body); - notiMessage.setSource(source); - msgMap.put(id, SYNC_UNREAD); - ioTNotification.NSSendNotification(notiMessage); + } + Log.i(TAG, "SendMessage ProviderService - OUT"); mHandler.post(new Runnable() { @Override public void run() { @@ -128,56 +145,71 @@ public class ProviderProxy }); } - public void readCheck(String messageId) { + public void SendSyncInfo(long messageId, SyncInfo.SyncType syncType) { + Log.i(TAG, "SendSyncInfo ProviderService - IN"); if(msgMap.containsKey(messageId)) { if(msgMap.get(messageId) == SYNC_UNREAD) { - NSMessage notiMessage = new NSMessage(messageId); - ioTNotification.NSProviderReadCheck(notiMessage); - msgMap.put(messageId, SYNC_READ); + try{ + ioTNotification.SendSyncInfo(messageId,syncType ); + Log.i(TAG, "Notification Sync " ); + } + catch(Exception e) { + + } + Log.i(TAG, "SendSyncInfo ProviderService - OUT"); + msgMap.put("ID: "+messageId, SYNC_READ); } } } - public void accept(String consumerId, boolean accepted) - { - NSConsumer consumer = new NSConsumer(consumerId); - ioTNotification.NSAccept(consumer, accepted); + public void EnableRemoteService(String servAdd) { + Log.i(TAG, "EnableRemoteService ProviderService - IN"); + try{ + int result = ioTNotification.EnableRemoteService(servAdd); + Log.i(TAG, "Notification EnableRemoteService: "+ result ); + } + catch(Exception e) { + + } + Log.i(TAG, "EnableRemoteService ProviderService - OUT"); } - @Override - public void OnNSSubscribedEvent(String consumerId) { - Log.i(TAG, "OnNSSubscribedEvent"); + public void DisableRemoteService(String servAdd) { + Log.i(TAG, "DisableRemoteService ProviderService - IN"); + try{ + int result = ioTNotification.DisableRemoteService(servAdd); + Log.i(TAG, "Notification DisableRemoteService: "+ result ); + } + catch(Exception e) { - Log.i(TAG, "Consumer: " + consumerId); - Message msg = mHandler.obtainMessage(MESSAGE_SUBSCRIPTION, consumerId); - mHandler.sendMessage(msg); + } + Log.i(TAG, "DisableRemoteService ProviderService - OUT"); } - @Override - public void OnNSSynchronizedEvent(String messageId, int syncState) { - Log.i(TAG, "OnNSSynchronizedEvent"); - - Log.i(TAG, "Message Id: " + messageId); - Log.i(TAG, "Sync state: " + syncState); + public void AcceptSubscription(Consumer consumer, boolean accepted) + { + Log.i(TAG,"AcceptSubscription ProviderService - IN"); + try{ + int result = consumer.AcceptSubscription(consumer, accepted); + Log.i(TAG, "Notification AcceptSubscription: "+result ); + } + catch(Exception e) { - Message msg = mHandler.obtainMessage(MESSAGE_SYNC, messageId + " / Sync State: " + syncState); - mHandler.sendMessage(msg); + } + Log.i(TAG, "AcceptSubscription ProviderService - OUT"); + } - NotificationManager manager = (NotificationManager)mContext - .getSystemService(Context.NOTIFICATION_SERVICE); + @Override + public void onConsumerSubscribed(Consumer consumer) { + Log.i(TAG, "onConsumerSubscribed - IN"); + AcceptSubscription(consumer, true); + Log.i(TAG, "onConsumerSubscribed - OUT"); + } - if(messageId != null) - try - { - manager.cancel(Integer.valueOf(messageId)); - } - catch (Exception e) - { - Log.e(TAG, "Handle exception for invalid message id" + e); - } - else - Log.i(TAG, "message id is null"); + @Override + public void onMessageSynchronized(SyncInfo syncInfo) { + Log.i(TAG, "Received SyncInfo with messageID: "+syncInfo.getMessageId()); } public HashMap getMsgMap() { diff --git a/service/notification/examples/android/NotiProviderExample/iotivity-armeabi-notification-service-release/build.gradle b/service/notification/examples/android/NotiProviderExample/iotivity-armeabi-notification-service-debug/build.gradle similarity index 83% rename from service/notification/examples/android/NotiProviderExample/iotivity-armeabi-notification-service-release/build.gradle rename to service/notification/examples/android/NotiProviderExample/iotivity-armeabi-notification-service-debug/build.gradle index f7c5895..3fbdd9f 100644 --- a/service/notification/examples/android/NotiProviderExample/iotivity-armeabi-notification-service-release/build.gradle +++ b/service/notification/examples/android/NotiProviderExample/iotivity-armeabi-notification-service-debug/build.gradle @@ -1,2 +1,2 @@ configurations.create("default") -artifacts.add("default", file('iotivity-armeabi-notification-service-release.aar')) \ No newline at end of file +artifacts.add("default", file('iotivity-armeabi-notification-service-debug.aar')) \ No newline at end of file diff --git a/service/notification/examples/android/NotiProviderExample/iotivity-base-armeabi-debug/build.gradle b/service/notification/examples/android/NotiProviderExample/iotivity-base-armeabi-debug/build.gradle new file mode 100644 index 0000000..305a7ec --- /dev/null +++ b/service/notification/examples/android/NotiProviderExample/iotivity-base-armeabi-debug/build.gradle @@ -0,0 +1,2 @@ +configurations.create("default") +artifacts.add("default", file('iotivity-base-armeabi-debug.aar')) \ No newline at end of file diff --git a/service/notification/examples/android/NotiProviderExample/iotivity-base-armeabi-release/build.gradle b/service/notification/examples/android/NotiProviderExample/iotivity-base-armeabi-release/build.gradle deleted file mode 100644 index 44cd131..0000000 --- a/service/notification/examples/android/NotiProviderExample/iotivity-base-armeabi-release/build.gradle +++ /dev/null @@ -1,2 +0,0 @@ -configurations.create("default") -artifacts.add("default", file('iotivity-base-armeabi-release.aar')) \ No newline at end of file diff --git a/service/notification/examples/android/NotiProviderExample/settings.gradle b/service/notification/examples/android/NotiProviderExample/settings.gradle index 1d296f6..36fd2b5 100644 --- a/service/notification/examples/android/NotiProviderExample/settings.gradle +++ b/service/notification/examples/android/NotiProviderExample/settings.gradle @@ -1 +1 @@ -include ':app', ':iotivity-armeabi-notification-service-release', ':iotivity-base-armeabi-release' +include ':app', ':iotivity-armeabi-notification-service-debug', ':iotivity-base-armeabi-debug' -- 2.7.4