Disable adapter takes more time to disable 72/140272/1
authorSreeraj Mohan Kottapuzhackal <sreeraj.mk@samsung.com>
Mon, 24 Jul 2017 07:01:47 +0000 (12:31 +0530)
committerSreeraj Mohan Kottapuzhackal <sreeraj.mk@samsung.com>
Mon, 24 Jul 2017 09:03:42 +0000 (14:33 +0530)
[Model] All
[BinType] AP
[Customer] All

[Issue#] P170117-02987
[Request] PLM
[Occurrence Version] All

[Problem] Takes more than 4 seconds to disable adapter
[Cause & Measure] Cause: Profile level disconnection, device disconnection &
                  adapter disable was carried out sequentially. This process
                  takes time if more devices are connected at a time.
                  Measure: Profile disconnection is required only if LE
                  is enabled through adapter_enable_le
[Checking Method] Unit testing

[Team] Basic connection
[Developer] sreeraj.mk
[Solution company] Samsung
[Change Type] N/A

Change-Id: Ia2fd5afcb63c9e5d931e0689b7bd442b62bf9fcf

bt-service/bt-service-adapter.c

index a710491..610c8f3 100644 (file)
@@ -667,7 +667,7 @@ void _bt_set_le_disabled(int result)
 
        /* Send disabled event */
        _bt_send_event(BT_LE_ADAPTER_EVENT, BLUETOOTH_EVENT_LE_DISABLED,
-                       g_variant_new("(i)", result));
+                                               g_variant_new("(i)", result));
 }
 
 void *_bt_get_adapter_agent(void)
@@ -907,16 +907,16 @@ void _bt_handle_adapter_removed(void)
        if (0 != ret)
                ERR("vconf_ignore_key_changed failed\n");
 
-/* unregister all the services/servers/profiles registered on bluez-adapter
-    once adapter is removed, reinitializing of the state-varaibles becomes
-    a problem */
+       /* unregister all the services/servers/profiles registered on bluez-adapter
+       once adapter is removed, reinitializing of the state-varaibles becomes
+       a problem */
        if (_bt_unregister_obex_server() != BLUETOOTH_ERROR_NONE)
                BT_ERR("Fail to unregister obex server");
 
        if (_bt_unregister_media_player() != BLUETOOTH_ERROR_NONE)
                BT_ERR("Fail to unregister media player");
 
-/* Other unregister APIs should be placed here */
+       /* Other unregister APIs should be placed here */
 
 #ifndef TIZEN_FEATURE_BT_USB_DONGLE
        _bt_destroy_agent(adapter_agent);
@@ -1208,6 +1208,37 @@ int _bt_enable_adapter(void)
        return BLUETOOTH_ERROR_NONE;
 }
 
+static gboolean __bt_set_powered(gboolean powered)
+{
+       GDBusProxy *proxy;
+       GError *error = NULL;
+       GVariant *result;
+
+       BT_DBG("");
+
+       proxy = _bt_get_adapter_properties_proxy();
+       retv_if(proxy == NULL, FALSE);
+
+       result = g_dbus_proxy_call_sync(proxy, "Set",
+               g_variant_new("(ssv)", BT_ADAPTER_INTERFACE, "Powered",
+               g_variant_new("b", powered)),
+               G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (!result) {
+               if (error != NULL) {
+                       BT_ERR("Failed to set powered property (Error: %s)",
+                       error->message);
+                       g_clear_error(&error);
+               } else {
+                       BT_ERR("Failed to set powered property");
+               }
+               return FALSE;
+       }
+
+       BT_INFO("Set powered [%d]", powered);
+       g_variant_unref(result);
+       return TRUE;
+}
+
 static gboolean __bt_disconnect_all(void)
 {
        int i;
@@ -1382,6 +1413,7 @@ int _bt_disable_adapter(void)
 {
        BT_DBG("+");
        int ret;
+       bt_le_status_t le_status;
 
        if (_bt_adapter_get_status() == BT_DEACTIVATING) {
                BT_DBG("Disabling in progress");
@@ -1397,17 +1429,27 @@ int _bt_disable_adapter(void)
                g_source_remove(timer_id);
                timer_id = 0;
        }
-/* unregister all the services/servers/profiles registered on bluez-adapter
-    once adapter is removed, reinitializing of the state-varaibles becomes
-    a problem */
+
+       /* unregister all the services/servers/profiles registered on bluez-adapter
+       once adapter is removed, reinitializing of the state-varaibles becomes
+       a problem */
        if (_bt_unregister_obex_server() != BLUETOOTH_ERROR_NONE)
                BT_ERR("Fail to unregister obex server");
 
        if (_bt_unregister_media_player() != BLUETOOTH_ERROR_NONE)
                BT_ERR("Fail to unregister media player");
+       /* Other unregister APIs should be placed here */
+
+       le_status = _bt_adapter_get_le_status();
+       if (le_status == BT_LE_ACTIVATED && is_le_intended == TRUE) {
+               __bt_disconnect_all();
+       } else {
+               if (le_status == BT_LE_ACTIVATED)
+                       _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
+
+               __bt_set_powered(FALSE);
+       }
 
-/* Other unregister APIs should be placed here */
-       __bt_disconnect_all();
        ret = _bt_disable_cb();
 
        BT_DBG("-");
@@ -1561,6 +1603,7 @@ int _bt_enable_adapter_le(void)
 
        if (status == BT_DEACTIVATING || le_status == BT_LE_DEACTIVATING) {
                BT_ERR("Disabling in progress");
+               _bt_set_le_intended_status(FALSE);
                return BLUETOOTH_ERROR_DEVICE_BUSY;
        }