{
int ret = BT_ERROR_NONE;
int error_code;
+ gboolean is_advertising = FALSE;
+
bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser;
BT_CHECK_LE_SUPPORT();
_bt_unset_cb(BT_EVENT_ADVERTISING_STATE_CHANGED);
- error_code = bluetooth_set_advertising(__adv->handle, FALSE);
- ret = _bt_get_error_code(error_code);
- if (ret != BT_ERROR_NONE)
- BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret),
- ret); /* LCOV_EXCL_LINE */
+ /* This operation is not related to the result */
+ error_code = bluetooth_is_advertising(&is_advertising);
+
+ if (is_advertising == TRUE) {
+ error_code = bluetooth_set_advertising(__adv->handle, FALSE);
+
+ ret = _bt_get_error_code(error_code);
+ if (ret != BT_ERROR_NONE)
+ BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret),
+ ret); /* LCOV_EXCL_LINE */
+ }
advertiser_list = g_slist_remove(advertiser_list, __adv);