Fix the rebond and crash issue 98/48798/5 accepted/tizen/mobile/20150930.115719 accepted/tizen/tv/20150930.115747 accepted/tizen/wearable/20150930.115755 submit/tizen_mobile/20150930.073015 submit/tizen_tv/20150930.073020 submit/tizen_wearable/20150930.073024 tizen_3.0.m2.a1_mobile_release tizen_3.0.m2.a1_tv_release
authorTaejin Woo <tt.woo@samsung.com>
Wed, 30 Sep 2015 04:17:51 +0000 (13:17 +0900)
committerTaejin Woo <tt.woo@samsung.com>
Wed, 30 Sep 2015 07:26:40 +0000 (16:26 +0900)
Change-Id: I5c77b1826622a9626851469e052068bf3d93b13c
Signed-off-by: Taejin Woo <tt.woo@samsung.com>
bt-service/bt-service-device.c

index 8a2fd79..cd31f7a 100644 (file)
@@ -573,6 +573,7 @@ static int __bt_remove_and_bond(void)
        GDBusProxy *adapter_proxy;
        GVariant *result = NULL;
        GError *err = NULL;
+       char *data = NULL;
        char *device_path = NULL;
 
        BT_CHECK_PARAMETER(bonding_info, return);
@@ -590,7 +591,8 @@ static int __bt_remove_and_bond(void)
        if (result == NULL)
                return BLUETOOTH_ERROR_INTERNAL;
 
-       g_variant_get(result , "(&o)", &device_path);
+       g_variant_get(result , "(&o)", &data);
+       device_path = g_strdup(data);
        g_variant_unref(result);
 
        retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
@@ -602,11 +604,16 @@ static int __bt_remove_and_bond(void)
                                NULL,
                                &err);
 
-       if (err != NULL) {
-               BT_ERR("UnpairDevice Fail: %s", err->message);
-               g_error_free(err);
-               return BLUETOOTH_ERROR_INTERNAL;
+       g_free(device_path);
+
+       if (result == NULL) {
+               if (err != NULL) {
+                       BT_ERR("UnpairDevice Fail: %s", err->message);
+                       g_error_free(err);
+                       return BLUETOOTH_ERROR_INTERNAL;
+               }
        }
+       g_variant_unref(result);
 
        return __bt_retry_bond();
 }
@@ -663,31 +670,31 @@ static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res,
        if (err != NULL) {
                BT_ERR("Error occured in CreateBonding [%s]", err->message);
 
-               if (!strcmp(err->message, "Already Exists")) {
+               if (g_strrstr(err->message, "Already Exists")) {
                        BT_INFO("Existing Bond, remove and retry");
                        ret_if(__bt_remove_and_bond() == BLUETOOTH_ERROR_NONE);
 
                        result = BLUETOOTH_ERROR_PARING_FAILED;
                } else if (_bt_agent_is_canceled() ||
-                       !strcmp(err->message, "Authentication Canceled")) {
+                       g_strrstr(err->message, "Authentication Canceled")) {
                        BT_INFO("Cancelled by USER");
                        result = BLUETOOTH_ERROR_CANCEL_BY_USER;
-               } else if (!strcmp(err->message, "Authentication Rejected")) {
+               } else if (g_strrstr(err->message, "Authentication Rejected")) {
                        BT_INFO("REJECTED");
                        result = BLUETOOTH_ERROR_ACCESS_DENIED;
-               } else if (!strcmp(err->message, "In Progress")) {
+               } else if (g_strrstr(err->message, "In Progress")) {
                        BT_INFO("Bond in progress, cancel and retry");
                        ret_if(__bt_cancel_and_bond() == BLUETOOTH_ERROR_NONE);
 
                        result = BLUETOOTH_ERROR_PARING_FAILED;
-               } else if (!strcmp(err->message, "Authentication Failed")) {
+               } else if (g_strrstr(err->message, "Authentication Failed")) {
                        BT_INFO("Authentication Failed");
                        if (bonding_info->is_autopair == TRUE) {
                                _bt_set_autopair_status_in_bonding_info(FALSE);
                                __ignore_auto_pairing_request(bonding_info->addr);
                        }
                        result = BLUETOOTH_ERROR_AUTHENTICATION_FAILED;
-               } else if (!strcmp(err->message, "Page Timeout")) {
+               } else if (g_strrstr(err->message, "Page Timeout")) {
                        BT_INFO("Page Timeout");
                        /* This is the special case
                             As soon as call bluetooth_bond_device, try to cancel bonding.
@@ -695,7 +702,7 @@ static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res,
                             the procedure is stopped. So 'Cancle' error is not return.
                        */
                        result = BLUETOOTH_ERROR_HOST_DOWN;
-               } else if (!strcmp(err->message, BT_TIMEOUT_MESSAGE)) {
+               } else if (g_strrstr(err->message, BT_TIMEOUT_MESSAGE)) {
                        g_dbus_proxy_call_sync(proxy, "CancelDeviceCreation",
                                                g_variant_new("(s)", bonding_info->addr),
                                                G_DBUS_CALL_FLAGS_NONE,
@@ -704,10 +711,10 @@ static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res,
                                                NULL);
 
                        result = BLUETOOTH_ERROR_INTERNAL;
-               } else if (!strcmp(err->message, "Connection Timeout")) {
+               } else if (g_strrstr(err->message, "Connection Timeout")) {
                        /* Pairing request timeout */
                        result = BLUETOOTH_ERROR_TIMEOUT;
-               } else if (!strcmp(err->message, "Authentication Timeout")) {
+               } else if (g_strrstr(err->message, "Authentication Timeout")) {
                        /* Pairing request timeout */
                        result = BLUETOOTH_ERROR_TIMEOUT;
                } else {