Add notifications in bt-service 36/10136/2 tizen_ivi_genivi accepted/tizen/20130920.214306 accepted/tizen/20130920.214356 accepted/tizen/20130920.214404 accepted/tizen/20130923.030153 accepted/tizen/20131023.232451 accepted/tizen/ivi/genivi/20140131.062302 accepted/tizen_ivi_release/20131120.050430 ivi_oct_m2 submit/tizen/20130920.214118 submit/tizen/20131023.214908 submit/tizen_ivi_genivi/20140131.061517 submit/tizen_ivi_release/20131120.030000
authorCorentin Lecouvey <corentin.lecouvey@eurogiciel.fr>
Thu, 19 Sep 2013 14:30:32 +0000 (16:30 +0200)
committerRusty Lynch <rusty.lynch@intel.com>
Fri, 20 Sep 2013 00:52:23 +0000 (17:52 -0700)
- use LIBNOTIFICATION_SUPPORT build option
- bt-service-agent-notification.c source code sends bluetooth notifications to
the notification daemon.

This fix is a part of TIVI-1690 (bluetooth pairing) since it just sends requests
to the notification daemon. Homescreen part should display the notification themselves.

Change-Id: Id82dee9de9199a37b700d27c0d0804c3e11bdd1a

CMakeLists.txt
bt-service/CMakeLists.txt
bt-service/bt-service-agent-notification.c [new file with mode: 0644]
bt-service/bt-service-agent.c
bt-service/include/bt-service-agent-notification.h [new file with mode: 0644]
packaging/bluetooth-frwk.spec

index 3f82e79..81a231c 100644 (file)
@@ -3,6 +3,12 @@ OPTION(LIBNOTIFY_SUPPORT "Enable libnotify for popup" Off)
 IF(LIBNOTIFY_SUPPORT)
     ADD_DEFINITIONS("-DLIBNOTIFY_SUPPORT")
 ENDIF(LIBNOTIFY_SUPPORT)
+
+OPTION(LIBNOTIFICATION_SUPPORT "Use Tizen notification system" Off)
+IF(LIBNOTIFICATION_SUPPORT)
+    ADD_DEFINITIONS("-DLIBNOTIFICATION_SUPPORT")
+ENDIF(LIBNOTIFICATION_SUPPORT)
+
 OPTION(MULTI_USER_SUPPORT "Enable multi-user support" OFF)
 IF(MULTI_USER_SUPPORT)
     ADD_DEFINITIONS("-DMULTI_USER_SUPPORT")
index fb2df17..33831d7 100644 (file)
@@ -31,6 +31,12 @@ bt-popup.c
 )
 ENDIF(LIBNOTIFY_SUPPORT)
 
+IF(LIBNOTIFICATION_SUPPORT)
+LIST(APPEND SRCS
+bt-service-agent-notification.c
+)
+ENDIF(LIBNOTIFICATION_SUPPORT)
+
 IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
        SET(CMAKE_BUILD_TYPE "Release")
 ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
@@ -80,10 +86,10 @@ ADD_DEFINITIONS("-DAPP_DIR=\"${APP_DIR}\"")
 ADD_DEFINITIONS("-DAPP_LOCALEDIR=\"${APP_LOCALEDIR}\"")
 ADD_DEFINITIONS("-DAPP_SYSCONFDIR=\"${APP_SYSCONFDIR}\"")
 
-IF(LIBNOTIFY_SUPPORT)
+IF(LIBNOTIFY_SUPPORT OR LIBNOTIFICATION_SUPPORT)
        ADD_DEFINITIONS("-DDATA_DIR_ICON=\"${SHARE_INSTALL_PREFIX}\"")
        MESSAGE("Icon used for notification is : ${SHARE_INSTALL_PREFIX}/icons/default/bt-icon.png")
-ENDIF(LIBNOTIFY_SUPPORT)
+ENDIF(LIBNOTIFY_SUPPORT OR LIBNOTIFICATION_SUPPORT)
 
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
 
@@ -100,7 +106,7 @@ ENDIF(LIBNOTIFY_SUPPORT)
 
 IF(NOT MULTI_USER_SUPPORT)
        INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.projectx.bt.service DESTINATION share/dbus-1/system-services)
-ENDIF(MULTI_USER_SUPPORT)
+ENDIF(NOT MULTI_USER_SUPPORT)
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
 
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/auto-pair-blacklist DESTINATION /opt/var/lib/bluetooth)
@@ -108,7 +114,7 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/auto-pair-blacklist DESTINATION /opt/v
 # install booting script
 IF(NOT MULTI_USER_SUPPORT)
 INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bluetooth-frwk-service DESTINATION /etc/rc.d/init.d)
-ENDIF(MULTI_USER_SUPPORT)
+ENDIF(NOT MULTI_USER_SUPPORT)
 
 IF(MULTI_USER_SUPPORT)
        install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/bluetooth-frwk-service_user.conf DESTINATION /etc/dbus-1/system.d)
diff --git a/bt-service/bt-service-agent-notification.c b/bt-service/bt-service-agent-notification.c
new file mode 100644 (file)
index 0000000..d240d7a
--- /dev/null
@@ -0,0 +1,242 @@
+/*
+ * bluetooth-frwk
+ *
+ * Copyright (c) 2013 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 "bt-service-agent-notification.h"
+
+const char*
+error_to_string(notification_error_e error)
+{
+    if (error == NOTIFICATION_ERROR_INVALID_DATA)
+        return "NOTIFICATION_ERROR_INVALID_DATA";
+    if (error == NOTIFICATION_ERROR_NO_MEMORY)
+        return "NOTIFICATION_ERROR_NO_MEMORY";
+    if (error == NOTIFICATION_ERROR_FROM_DB)
+        return "NOTIFICATION_ERROR_FROM_DB";
+    if (error == NOTIFICATION_ERROR_ALREADY_EXIST_ID)
+        return "NOTIFICATION_ERROR_ALREADY_EXIST_ID";
+    if (error == NOTIFICATION_ERROR_FROM_DBUS)
+        return "NOTIFICATION_ERROR_FROM_DBUS";
+    if (error == NOTIFICATION_ERROR_NOT_EXIST_ID)
+        return "NOTIFICATION_ERROR_NOT_EXIST_ID";
+    if (error == NOTIFICATION_ERROR_IO)
+        return "NOTIFICATION_ERROR_IO";
+    if (error == NOTIFICATION_ERROR_SERVICE_NOT_READY)
+        return "NOTIFICATION_ERROR_SERVICE_NOT_READY";
+    if (error == NOTIFICATION_ERROR_NONE)
+        return "NOTIFICATION_ERROR_NONE";
+
+    return "UNHANDLED ERROR";
+}
+
+static int
+__notification_set_text(notification_h noti, char *title, char *body)
+{
+    notification_error_e err = NOTIFICATION_ERROR_NONE;
+
+    err = notification_set_text(    noti, NOTIFICATION_TEXT_TYPE_TITLE,
+                                    title,
+                                    NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+    if (err != NOTIFICATION_ERROR_NONE) {
+        BT_ERR("Unable to set notification title: %s", error_to_string(err));
+        return BT_FAILED;
+    }
+
+    err = notification_set_text(    noti, NOTIFICATION_TEXT_TYPE_CONTENT,
+                                    body,
+                                    NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+    if (err != NOTIFICATION_ERROR_NONE) {
+        BT_ERR("Unable to set notification content: %s", error_to_string(err));
+        return BT_FAILED;
+    }
+    return BT_SUCCESS;
+}
+
+int
+notification_launch(bundle * user_data)
+{
+    int ret = BT_SUCCESS;
+    const char *device_name = NULL;
+    const char *passkey = NULL;
+    const char *file = NULL;
+    const char *event_type = NULL;
+    char *title = NULL;
+    char *body = NULL;
+    notification_h notif;
+    notification_error_e err = NOTIFICATION_ERROR_NONE;
+
+    event_type = bundle_get_val(user_data, "event-type");
+    BT_DBG("create notification for '%s' event", event_type);
+
+    notif = notification_new(NOTIFICATION_TYPE_NOTI,
+                             NOTIFICATION_GROUP_ID_NONE,
+                             NOTIFICATION_PRIV_ID_NONE);
+    if (notif == NULL) {
+        BT_ERR("Failed to create notification: %s", error_to_string(err));
+        return BT_FAILED;
+    }
+
+    err = notification_set_pkgname(notif, "bluetooth-frwk-bt-service");
+    if (err != NOTIFICATION_ERROR_NONE) {
+        BT_ERR("Unable to set pkgname: %s", error_to_string(err));
+        return BT_FAILED;
+    }
+
+    err = notification_set_image(notif, NOTIFICATION_IMAGE_TYPE_ICON, BT_ICON);
+    if (err != NOTIFICATION_ERROR_NONE) {
+        BT_ERR("Unable to set notification icon path: %s", error_to_string(err));
+        return BT_FAILED;
+    }
+
+    /* 
+     * Pass the full bundle to the notification
+     */
+    err  = notification_set_execute_option(notif, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, user_data);
+    if (err != NOTIFICATION_ERROR_NONE) {
+        BT_ERR("Unable to set notification icon path: %s", error_to_string(err));
+        return BT_FAILED;
+    }
+
+    if(!strcasecmp(event_type, "pin-request")) {
+        device_name = (gchar*) bundle_get_val(user_data, "device-name");
+
+        title = g_strdup_printf("Bluetooth pairing request");
+        body = g_strdup_printf("Enter PIN to pair with %s (Try 0000 or 1234)", device_name);
+
+        ret = __notification_set_text(notif, title, body);
+
+        g_free(title);
+        g_free(body);
+    } else if (!strcasecmp(event_type, "passkey-confirm-request")){
+        device_name = (gchar*) bundle_get_val(user_data, "device-name");
+        passkey = (gchar*) bundle_get_val(user_data, "passkey");
+
+        title = g_strdup_printf("Bluetooth passkey confirm request");
+        body = g_strdup_printf("Confirm passkey is %s to pair with %s", passkey, device_name);
+
+        ret = __notification_set_text(notif, title, body);
+
+        g_free(title);
+        g_free(body);
+    }  else if (!strcasecmp(event_type, "passkey-request")) {
+        device_name = (gchar*) bundle_get_val(user_data, "device-name");
+
+        title = g_strdup_printf("Bluetooth pairing request");
+        body = g_strdup_printf("Enter PIN to pair with %s (Try 0000 or 1234)", device_name);
+
+        ret = __notification_set_text(notif, title, body);
+
+        g_free(title);
+        g_free(body);
+    } else if (!strcasecmp(event_type, "passkey-display-request")) {
+        device_name = (gchar*) bundle_get_val(user_data, "device-name");
+        passkey = (gchar*) bundle_get_val(user_data, "passkey");
+
+        title = g_strdup_printf("Bluetooth passkey display request");
+        body = g_strdup_printf("Enter %s on %s to pair", passkey, device_name);
+
+        ret = __notification_set_text(notif, title, body);
+
+        g_free(title);
+        g_free(body);
+    } else if (!strcasecmp(event_type, "authorize-request")) {
+        device_name = (gchar*) bundle_get_val(user_data, "device-name");
+
+        title = g_strdup_printf("Bluetooth authorize request");
+        body = g_strdup_printf("Allow %s to connect?", device_name);
+
+        ret = __notification_set_text(notif, title, body);
+
+        g_free(title);
+        g_free(body);
+    } else if (!strcasecmp(event_type, "app-confirm-request")) {
+        /* FIXME Seems to be an osp mechanism so not implemented to be confirmed */
+        BT_DBG("app-confirm-request even_type seems to be an osp mechanism so not implemented in gnome environment; to be confirmed");
+        ret = BT_FAILED;
+    } else if (!strcasecmp(event_type, "push-authorize-request")) {
+        file = (gchar*) bundle_get_val(user_data, "file");
+        device_name = (gchar*) bundle_get_val(user_data, "device-name");
+
+        title = g_strdup_printf("Bluetooth push authorize request");
+        body = g_strdup_printf("Receive %s from %s?", file, device_name);
+
+        ret = __notification_set_text(notif, title, body);
+
+        g_free(title);
+        g_free(body);
+    } else if (!strcasecmp(event_type, "confirm-overwrite-request")) {
+        /* FIXME Seems to be an osp mechanism so not implemented to be confirmed*/
+        BT_DBG("confirm-overwrite-request even_type seems to be an osp mechanism so not implemented in gnome environment; to be confirmed");
+        ret = BT_FAILED;
+    } else if (!strcasecmp(event_type, "keyboard-passkey-request")) {
+        device_name = (gchar*) bundle_get_val(user_data, "device-name");
+        passkey = (gchar*) bundle_get_val(user_data, "passkey");
+
+        title = g_strdup_printf("Bluetooth keyboard passkey request");
+        body = g_strdup_printf("Enter %s on %s to pair", passkey, device_name);
+
+        ret = __notification_set_text(notif, title, body);
+
+        g_free(title);
+        g_free(body);
+    } else if (!strcasecmp(event_type, "bt-information")) {
+        /* FIXME Seems to be an osp mechanism so not implemented to be confirmed */
+        BT_DBG("bt-information even_type seems to be an osp mechanism so not implemented in gnome environment; to be confirmed");
+        ret = BT_FAILED;
+    } else if (!strcasecmp(event_type, "exchange-request")) {
+        device_name = (gchar*) bundle_get_val(user_data, "device-name");
+
+        title = g_strdup_printf("Bluetooth exchange request");
+        body = g_strdup_printf("exchange-request from %s", device_name);
+
+        ret = __notification_set_text(notif, title, body);
+        g_free(title);
+        g_free(body);
+    } else if (!strcasecmp(event_type, "phonebook-request")) {
+        device_name = bundle_get_val(user_data, "device-name");
+
+        title = g_strdup_printf("Bluetooth phonebook request");
+        body = g_strdup_printf("Allow %s phonebook access", device_name);
+
+        ret = __notification_set_text(notif, title, body);
+
+        g_free(title);
+        g_free(body);
+    } else if (!strcasecmp(event_type, "message-request")) {
+        device_name = bundle_get_val(user_data, "device-name");
+
+        title = g_strdup_printf("Bluetooth keyboard passkey request");
+        body = g_strdup_printf("Allow %s to access messages?", device_name);
+
+        ret = __notification_set_text(notif, title, body);
+
+        g_free(title);
+        g_free(body);
+    } else {
+        ret = BT_FAILED;
+    }
+
+    err = notification_insert(notif, NULL);
+    if (err != NOTIFICATION_ERROR_NONE) {
+        BT_ERR("Unable to insert notification: %s\n", error_to_string(err));
+        return BT_FAILED;
+    }
+
+    return ret;
+}
+
index 345a65a..4892930 100644 (file)
 #include "bt-service-device.h"
 #include "bt-service-audio.h"
 
-#ifdef LIBNOTIFY_SUPPORT
+#if defined(LIBNOTIFY_SUPPORT)
 #include "bt-popup.h"
+#elif defined(LIBNOTIFICATION_SUPPORT)
+#include "bt-service-agent-notification.h"
 #else
 #include <syspopup_caller.h>
 #endif
@@ -85,8 +87,10 @@ static int __syspopup_launch(gpointer user_data)
 {
        int ret;
        bundle *b = (bundle *) user_data;
-#ifdef LIBNOTIFY_SUPPORT
+#if defined(LIBNOTIFY_SUPPORT)
        ret = notify_launch(b);
+#elif defined(LIBNOTIFICATION_SUPPORT)
+       ret = notification_launch(b);
 #else
        ret = syspopup_launch("bt-syspopup", b);
 #endif
diff --git a/bt-service/include/bt-service-agent-notification.h b/bt-service/include/bt-service-agent-notification.h
new file mode 100644 (file)
index 0000000..19d1634
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * bluetooth-frwk
+ *
+ * Copyright (c) 2013 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 <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <bundle.h>
+#include <notification.h>
+#include "bt-service-common.h"
+
+#define BT_ICON        DATA_DIR_ICON"/icons/default/bt-icon.png"
+#define BT_SUCCESS     0
+#define BT_FAILED      1
+
+int notification_launch(bundle *user_data);
index d6d6fb7..8cbfc5d 100644 (file)
@@ -1,5 +1,7 @@
 %bcond_with bluetooth_frwk_libnotify
+%bcond_with bluetooth_frwk_libnotification
 %bcond_with multi_user
+
 Name:       bluetooth-frwk
 Summary:    Bluetooth framework for BlueZ and Obexd
 Version:    0.2.57
@@ -91,9 +93,14 @@ export LDFLAGS+=" -Wl,--rpath=%{_libdir} -Wl,--as-needed -Wl,--unresolved-symbol
        -DMULTI_USER_SUPPORT=Off \
 %endif
 %if %{with bluetooth_frwk_libnotify}
- -DLIBNOTIFY_SUPPORT=On
+ -DLIBNOTIFY_SUPPORT=On \
+%else
+ -DLIBNOTIFY_SUPPORT=Off \
+%endif
+%if %{with bluetooth_frwk_libnotification}
+ -DLIBNOTIFICATION_SUPPORT=On
 %else
- -DLIBNOTIFY_SUPPORT=Off
+ -DLIBNOTIFICATION_SUPPORT=Off
 %endif
 
 make