From: DoHyun Pyun Date: Thu, 12 Dec 2019 00:00:50 +0000 (+0900) Subject: Merge branch 'tizen' into tizen_5.5 X-Git-Tag: accepted/tizen/5.5/unified/20191230.212305~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=46d61111ac9b6af0302cb4b0d82533db84856474;hp=8e128f36696163d51866acf170c0d18bebe9650a;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git Merge branch 'tizen' into tizen_5.5 --- diff --git a/bt-core/bt-core-adapter.c b/bt-core/bt-core-adapter.c index 1d4c723..f89fda5 100644 --- a/bt-core/bt-core-adapter.c +++ b/bt-core/bt-core-adapter.c @@ -833,14 +833,11 @@ gboolean _bt_core_factory_test_mode(const char *type, const char *arg) static gboolean __bt_core_recovery_cb(gpointer data) { int ret = 0; -#ifdef TIZEN_FEATURE_BUSACT gboolean is_request_failed = FALSE; static gboolean is_first_failure = TRUE; -#endif BT_DBG("+"); -#ifdef TIZEN_FEATURE_BUSACT if (_bt_core_get_bt_status(BT_RECOVERY_MODE) == 1) { ret = _bt_core_service_request_adapter(BT_ENABLE_ADAPTER); if (ret < 0) @@ -865,7 +862,6 @@ static gboolean __bt_core_recovery_cb(gpointer data) } } else is_first_failure = TRUE; -#endif if (_bt_core_get_bt_status(BT_RECOVERY_MODE) == 1) { _bt_core_set_bt_status(BT_RECOVERY_MODE, 0); diff --git a/bt-oal/bluez_hal/src/bt-hal-adapter-dbus-handler.c b/bt-oal/bluez_hal/src/bt-hal-adapter-dbus-handler.c index 50e06b6..e46afbb 100644 --- a/bt-oal/bluez_hal/src/bt-hal-adapter-dbus-handler.c +++ b/bt-oal/bluez_hal/src/bt-hal-adapter-dbus-handler.c @@ -275,6 +275,36 @@ int _bt_hal_dbus_disable_adapter(void) return BT_STATUS_SUCCESS; } +int _bt_hal_dbus_recover_adapter(void) +{ + GDBusProxy *proxy; + GVariant *result = NULL; + GError *error = NULL; + + DBG("+"); + proxy = __bt_get_core_proxy(); + + if (!proxy) { + DBG("_bt_hal_dbus_recover_adapter: Core proxy get failed!!!"); + return BT_STATUS_FAIL; + } + + result = g_dbus_proxy_call_sync(proxy, "RecoverAdapter", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, &error); + if (error) { + DBG("RecoverAdapter failed: %s", error->message); + g_clear_error(&error); + error = NULL; + return BT_STATUS_FAIL; + } + + DBG("-"); + g_variant_unref(result); + return BT_STATUS_SUCCESS; +} + #ifdef TIZEN_BT_HAL int _bt_hal_dbus_enable_le(void) { diff --git a/bt-oal/bluez_hal/src/bt-hal-adapter-dbus-handler.h b/bt-oal/bluez_hal/src/bt-hal-adapter-dbus-handler.h index a0a36bc..ee7ac3f 100644 --- a/bt-oal/bluez_hal/src/bt-hal-adapter-dbus-handler.h +++ b/bt-oal/bluez_hal/src/bt-hal-adapter-dbus-handler.h @@ -48,6 +48,8 @@ int _bt_hal_dbus_enable_adapter(void); int _bt_hal_dbus_disable_adapter(void); +int _bt_hal_dbus_recover_adapter(void); + #ifdef TIZEN_BT_HAL int _bt_hal_dbus_reset_adapter(void); #endif diff --git a/bt-oal/bluez_hal/src/bt-hal-bluetooth.c b/bt-oal/bluez_hal/src/bt-hal-bluetooth.c index dedc067..79c63b7 100644 --- a/bt-oal/bluez_hal/src/bt-hal-bluetooth.c +++ b/bt-oal/bluez_hal/src/bt-hal-bluetooth.c @@ -115,6 +115,14 @@ static int disable(void) } #ifdef TIZEN_BT_HAL +/* Tizen Specific Recover Adapter */ +static int recover(void) +{ + return _bt_hal_dbus_recover_adapter(); +} +#endif + +#ifdef TIZEN_BT_HAL /* Tizen Specific Reset Adapter */ static int reset(void) { @@ -426,7 +434,9 @@ static const bt_interface_t bluetooth_if = { .init = init, .enable = enable, .disable = disable, + #ifdef TIZEN_BT_HAL + .recover = recover, .reset = reset, #endif diff --git a/bt-oal/hardware/bluetooth.h b/bt-oal/hardware/bluetooth.h index affaa83..deaa2ce 100644 --- a/bt-oal/hardware/bluetooth.h +++ b/bt-oal/hardware/bluetooth.h @@ -716,6 +716,11 @@ typedef struct { int (*disable)(void); #ifdef TIZEN_BT_HAL + /** Recovers Adapter. */ + int (*recover)(void); +#endif + +#ifdef TIZEN_BT_HAL /** Reset Bluetooth. */ int (*reset)(void); #endif diff --git a/bt-oal/include/oal-adapter-mgr.h b/bt-oal/include/oal-adapter-mgr.h index bbe0083..71ebadf 100644 --- a/bt-oal/include/oal-adapter-mgr.h +++ b/bt-oal/include/oal-adapter-mgr.h @@ -183,6 +183,19 @@ oal_status_t adapter_get_powered_status(gboolean *status); oal_status_t adapter_reset(void); /** + * @brief Recovers Adapter. + * + * @remarks Disables the BT stack and chip, enables after after seconds. + * + * @details EVENT: OAL_EVENT_ADAPTER_DISABLED + * + * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value. + * @retval #OAL_STATUS_SUCCESS Successful + * + */ +oal_status_t adapter_recover(void); + +/** * @brief Start device discovery * * @details For each device found either OAL_EVENT_ADAPTER_INQUIRY_RESULT_BREDR_ONLY diff --git a/bt-oal/oal-adapter-mgr.c b/bt-oal/oal-adapter-mgr.c index c1707d2..886d3f9 100644 --- a/bt-oal/oal-adapter-mgr.c +++ b/bt-oal/oal-adapter-mgr.c @@ -374,6 +374,24 @@ oal_status_t adapter_reset(void) return ret; } +oal_status_t adapter_recover(void) +{ + int result; + + API_TRACE(); + + CHECK_OAL_INITIALIZED(); + BT_INFO("Adapter Recover"); + + result = blued_api->recover(); + if (result != BT_STATUS_SUCCESS) { + BT_ERR("Adapter Recover Failed: [%s]", status2string(result)); + return convert_to_oal_status(result); + } + + return result; +} + oal_status_t adapter_start_inquiry(unsigned short duration) { int ret; diff --git a/bt-service-adaptation/services/adapter/bt-service-core-adapter.c b/bt-service-adaptation/services/adapter/bt-service-core-adapter.c index d12b97a..b0e4ffa 100644 --- a/bt-service-adaptation/services/adapter/bt-service-core-adapter.c +++ b/bt-service-adaptation/services/adapter/bt-service-core-adapter.c @@ -105,6 +105,8 @@ static gboolean __bt_is_service_request_present(int service_function); static void __bt_set_visible_mode(void); static void __bt_set_local_name(void); +static gboolean __bt_disconnect_all(void); + /* Initialize BT stack (Initialize OAL layer) */ int _bt_stack_init(void) { @@ -171,9 +173,28 @@ int _bt_enable_core(void) int _bt_recover_adapter(void) { - /* TODO_40 : 4.0 merge */ - BT_INFO("Not Supported"); - return BLUETOOTH_ERROR_NOT_SUPPORT; + int result = BLUETOOTH_ERROR_NONE; + + if (_bt_adapter_get_status() == BT_DEACTIVATING) { + BT_ERR("Disabling in progress"); + return BLUETOOTH_ERROR_IN_PROGRESS; + } + + if (_bt_adapter_get_status() == BT_DEACTIVATED) { + BT_ERR("Already Disabled"); + return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED; + } + + _bt_adapter_set_status(BT_DEACTIVATING); + + result = adapter_recover(); + + if (result != OAL_STATUS_SUCCESS) + return BLUETOOTH_ERROR_INTERNAL; + + __bt_disconnect_all(); + + return result; } int _bt_reset_adapter(void) @@ -794,6 +815,43 @@ int _bt_get_profile_connected_devices(char *profile_uuid, GArray **addr_list) return BLUETOOTH_ERROR_NONE; } +static gboolean __bt_disconnect_all(void) +{ + int i; + gboolean ret = FALSE; + GArray *device_list; + guint size; + int result; + bluetooth_device_info_t *info; + + BT_DBG(""); + device_list = g_array_new(FALSE, FALSE, sizeof(gchar)); + + BT_DBG("The length of device list after the initialisation is [%d]", device_list->len); + + _bt_service_get_bonded_dev_list(&device_list); + + size = (device_list->len) / sizeof(bluetooth_device_info_t); + + for (i = 0; i < size; i++) { + info = &g_array_index(device_list, + bluetooth_device_info_t, i); + if (info->connected != BLUETOOTH_CONNECTED_LINK_NONE) { + BT_DBG("Found Connected Device"); + result = _bt_disconnect_device(&info->device_address); + if (result != BLUETOOTH_ERROR_NONE) { + BT_ERR("Cannot disconnect all the devices. bt_disconnect_device Failed"); + g_array_free(device_list, TRUE); + return ret; + } + } + } + ret = TRUE; + g_array_free(device_list, TRUE); + + return ret; +} + static void __bt_handle_pending_a2dp_init(unsigned int a2dp_role) { int ret; diff --git a/bt-service-adaptation/services/device/bt-service-bonded-device.c b/bt-service-adaptation/services/device/bt-service-bonded-device.c index f0830fd..66cd8f9 100644 --- a/bt-service-adaptation/services/device/bt-service-bonded-device.c +++ b/bt-service-adaptation/services/device/bt-service-bonded-device.c @@ -43,7 +43,7 @@ static GSList *bonded_addr_list; static unsigned int bonded_list_index = 0; static gboolean bonded_list_retrieved = FALSE; -static void __bt_service_get_bonded_dev_list(GArray **dev_list) +void _bt_service_get_bonded_dev_list(GArray **dev_list) { GSList *l; @@ -136,7 +136,7 @@ static void __bt_handle_pending_request(int result, int service_function) } case BT_GET_BONDED_DEVICES: { out_param = g_array_new(FALSE, FALSE, sizeof(gchar)); - __bt_service_get_bonded_dev_list(&out_param); + _bt_service_get_bonded_dev_list(&out_param); _bt_service_method_return(req_info->context, out_param, result); _bt_free_info_from_invocation_list(req_info); g_array_free(out_param, TRUE); diff --git a/bt-service-adaptation/services/include/bt-service-core-device.h b/bt-service-adaptation/services/include/bt-service-core-device.h index 24615e7..301cdb6 100755 --- a/bt-service-adaptation/services/include/bt-service-core-device.h +++ b/bt-service-adaptation/services/include/bt-service-core-device.h @@ -89,6 +89,8 @@ int _bt_get_bonded_device_info(bluetooth_device_address_t *dev_addr); int _bt_get_bonded_devices(void); +void _bt_service_get_bonded_dev_list(GArray **dev_list); + bt_remote_dev_info_t *_bt_service_get_remote_dev_info(const char *address); gboolean _bt_is_bonded_devices_retrived(void);