Add the NULL point check and free for visibility timeout 35/83935/2
authorHyuk Lee <hyuk0512.lee@samsung.com>
Tue, 16 Aug 2016 01:06:33 +0000 (10:06 +0900)
committerHyuk Lee <hyuk0512.lee@samsung.com>
Tue, 16 Aug 2016 05:14:19 +0000 (14:14 +0900)
- add the timeout limit
- modify the popup text

Change-Id: Ic30047b5b09eb46f2997c94abeaa42643b052b4b
Signed-off-by: Hyuk Lee <hyuk0512.lee@samsung.com>
src/bt-syspopup-m.c
src/bt-syspopup-m.h

index b20a245..ced6508 100644 (file)
@@ -22,6 +22,7 @@
 */
 
 #include <stdio.h>
+#include <stdarg.h>
 #include <dd-display.h>
 #include <app.h>
 #include <device/display.h>
@@ -70,6 +71,23 @@ static void __bluetooth_remove_all_event(struct bt_popup_appdata *ad);
 
 static void __popup_terminate(void);
 
+static char *format_string(const char *format, ...)
+{
+       va_list arg;
+       char* chTemp = NULL;
+       chTemp= (char*)malloc(1024 * sizeof(char));
+       if (!chTemp) {
+               BT_DBG("memory alloc failed");
+               return NULL;
+       }
+
+       va_start(arg,format);
+       vsnprintf(chTemp,1024,format,arg);
+       va_end(arg);
+       return chTemp;
+}
+
+
 static int __bluetooth_term(bundle *b, void *data)
 {
        struct bt_popup_appdata *ad;
@@ -699,16 +717,31 @@ static void __bluetooth_adapter_state_changed_cb(int result, bt_adapter_state_e
 {
        BT_DBG("bluetooth state changed callback");
        int ret;
+       int timeout;
        struct bt_popup_appdata *ad = (struct bt_popup_appdata *)user_data;
 
        if (state == BT_ADAPTER_ENABLED) {
                BT_DBG("bt enabled");
 
                if (ad->visibility_timeout) {
-                       ret = bt_adapter_set_visibility(BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE, atoi(ad->visibility_timeout));
-                       BT_DBG("set visibility, returns:%d", ret);
+                       timeout = atoi(ad->visibility_timeout);
+
+                       if (timeout <= BT_VISIBILITY_TIMEOUT_MIN) {
+                               ret = bt_adapter_set_visibility(BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE, BT_VISIBILITY_TIMEOUT_MIN);
+                               BT_DBG("set visibility, returns:%d", ret);
+                       } else if (timeout >= BT_VISIBILITY_TIMEOUT_MAX) {
+                               ret = bt_adapter_set_visibility(BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE, BT_VISIBILITY_TIMEOUT_MAX);
+                               BT_DBG("set visibility, returns:%d", ret);
+                       } else {
+                               ret = bt_adapter_set_visibility(BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE, timeout);
+                               BT_DBG("set visibility, returns:%d", ret);
+                       }
+
+                       free(ad->visibility_timeout);
+                       ad->visibility_timeout = NULL;
                } else {
-                       ret = bt_adapter_set_visibility(BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE, 120);
+                       /* default timeout value */
+                       ret = bt_adapter_set_visibility(BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE, BT_VISIBILITY_TIMEOUT_DEFAULT);
                        BT_DBG("set visibility, returns:%d", ret);
                }
 
@@ -1900,6 +1933,8 @@ static int __bluetooth_launch_handler(struct bt_popup_appdata *ad,
        char *agent_path;
        char *conv_str = NULL;
        char *stms_str = NULL;
+       char *popup_text = NULL;
+       char *tmp_timeout = NULL;
        int ret;
 
        if (!reset_data || !event_type)
@@ -1971,8 +2006,24 @@ static int __bluetooth_launch_handler(struct bt_popup_appdata *ad,
        } else if (!strcasecmp(event_type, "visibility-request")) {
                BT_INFO("visibility request popup");
 
-               __bluetooth_draw_popup(ad, "Bluetooth permission request",
-                                       "Requesting permission to turn on Bluetooth and to set Visibility. Do you want to do this?", BT_STR_CANCEL, BT_STR_CONFIRM,
+               if (ad->visibility_timeout) {
+                       timeout = atoi(ad->visibility_timeout);
+
+                       if (timeout <= BT_VISIBILITY_TIMEOUT_MIN)
+                               tmp_timeout = BT_VISIBILITY_TIMEOUT_MIN_STR;
+                       else if (timeout >= BT_VISIBILITY_TIMEOUT_MAX)
+                               tmp_timeout = BT_VISIBILITY_TIMEOUT_MAX_STR;
+                       else
+                               tmp_timeout = ad->visibility_timeout;
+               } else {
+                       /* default timeout value */
+                       tmp_timeout = BT_VISIBILITY_TIMEOUT_DEFAULT_STR;
+               }
+
+               popup_text = format_string("Requesting permission to turn on Bluetooth and to set Visibility during %s seconds. Do you want to do this?",
+                               tmp_timeout);
+
+               __bluetooth_draw_popup(ad, "Bluetooth permission request", popup_text, BT_STR_CANCEL, BT_STR_CONFIRM,
                                        __bluetooth_visibility_confirm_cb);
 
        } else if (!strcasecmp(event_type, "passkey-request")) {
@@ -2557,6 +2608,7 @@ static void __bluetooth_reset(app_control_h app_control, void *data)
                return;
        }
 
+       ad->visibility_timeout = NULL;
        ret = app_control_get_extra_data(app_control, "timeout", &timeout);
        if (ret < 0) {
                BT_ERR("Get data error");
@@ -2575,10 +2627,12 @@ static void __bluetooth_reset(app_control_h app_control, void *data)
        if (app_control_get_operation(app_control, &operation) < 0)
                BT_ERR("Get operation error");
 
-       BT_INFO("operation: %s", operation);
-       BT_DBG("event-type: %s", event_type);
+       if (operation)
+               BT_INFO("operation: %s", operation);
 
        if (event_type != NULL) {
+               BT_DBG("event-type: %s", event_type);
+
                if (!strcasecmp(event_type, "terminate")) {
                        __bluetooth_win_del(ad);
                        goto release;
index 65f6876..d8973d3 100644 (file)
 #define BT_NOTIFICATION_TIMEOUT                2
 #define BT_ERROR_TIMEOUT                       1
 
+#define BT_VISIBILITY_TIMEOUT_DEFAULT 120
+#define BT_VISIBILITY_TIMEOUT_MIN 1
+#define BT_VISIBILITY_TIMEOUT_MAX 600
+
+#define BT_VISIBILITY_TIMEOUT_DEFAULT_STR "120"
+#define BT_VISIBILITY_TIMEOUT_MIN_STR "1"
+#define BT_VISIBILITY_TIMEOUT_MAX_STR "600"
+
 #define BT_PIN_MLEN 16         /* Pin key max length */
 #define BT_PK_MLEN 6           /* Passkey max length */
 #define BT_CONTROLBAR_MAX_LENGTH 3