Remove flight mode implementation from core and add it to bt-service 73/224373/5
authorSudipto <sudipto.bal@samsung.com>
Mon, 10 Feb 2020 06:29:04 +0000 (11:59 +0530)
committerSudipto <sudipto.bal@samsung.com>
Wed, 12 Feb 2020 06:30:34 +0000 (12:00 +0530)
Change-Id: I856539d5e36c11a0e02e6ff9ada8078c2848ebff
Signed-off-by: Sudipto <sudipto.bal@samsung.com>
bt-core/bt-core-adapter.c
bt-core/bt-core-main.c
bt-core/bt-core-noti-handler.c
bt-core/include/bt-core-noti-handler.h
bt-oal/bluez_hal/src/bt-hal-event-receiver.c
bt-service-adaptation/services/adapter/bt-service-core-adapter.c
bt-service-adaptation/services/bt-service-main.c
bt-service-adaptation/services/include/bt-service-core-adapter.h
bt-service-adaptation/services/include/bt-service-main.h

index 975a5d2..27fdeaf 100644 (file)
@@ -648,8 +648,6 @@ gboolean _bt_core_disable_adapter(void)
        gboolean adapter_state;
 
        _bt_set_flightmode_request(FALSE);
-       if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
-               BT_ERR("Set vconf failed");
 
        adapter_state = __bt_core_check_the_adapter_path();
        if (adapter_state == FALSE)
index 299a6ca..ea8748a 100644 (file)
@@ -113,7 +113,7 @@ static gboolean __bt_check_bt_core(void *data)
 #endif
        } else if (bt_status == VCONFKEY_BT_STATUS_OFF &&
                        (flight_mode_deactivation == 1 || ps_mode_deactivation > 0)) {
-               _bt_core_handle_flight_mode_noti();
+               //_bt_core_handle_flight_mode_noti();
                _bt_core_handle_power_saving_mode_noti();
 
                _bt_core_set_bt_status(BT_FLIGHT_MODE, flight_mode_deactivation);
index 9231efa..9fdca7f 100644 (file)
@@ -53,100 +53,6 @@ static gboolean __bt_off_cause_conflict_check(void)
        return ret;
 }
 
-static void __bt_core_handle_adapter_with_flight_mode(gboolean flight_mode)
-{
-       bt_status_t adapter_status;
-       bt_le_status_t adapter_status_le;
-
-       adapter_status = _bt_core_get_status();
-       adapter_status_le = _bt_core_get_le_status();
-
-       BT_INFO("bt status %d, le status %d", adapter_status, adapter_status_le);
-       if (flight_mode == TRUE) {
-               BT_INFO_C("Flight mode on. Turn off BT");
-
-               if (adapter_status == BT_ACTIVATING || adapter_status_le == BT_LE_ACTIVATING) {
-                       BT_INFO("BT adapter is activating. Turn off BT after activation");
-                       _bt_set_flightmode_request(TRUE);
-                       return;
-               }
-               if (adapter_status != BT_ACTIVATED && adapter_status_le != BT_LE_ACTIVATED) {
-                       BT_INFO("No need to control bt status");
-                       return;
-               }
-
-               if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 1) != 0)
-                       BT_ERR("Set vconf failed");
-
-               if (adapter_status == BT_ACTIVATED) {
-                       int bt_status_before_mode = 0;
-
-                       if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status_before_mode) == 0)
-                               _bt_core_set_bt_status(BT_FLIGHT_MODE, bt_status_before_mode);
-
-#ifdef TIZEN_FEATURE_BUSACT
-                       _bt_core_service_request_adapter(BT_DISABLE_ADAPTER);
-#endif
-                       if (!TIZEN_FEATURE_BT_USB_DONGLE)
-                               _bt_disable_adapter();
-               }
-
-               if (adapter_status_le == BT_LE_ACTIVATED) {
-                       int bt_le_status_before_mode = 0;
-
-                       if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status_before_mode) == 0)
-                               _bt_core_set_bt_le_status(BT_FLIGHT_MODE, bt_le_status_before_mode);
-
-#ifdef TIZEN_FEATURE_BUSACT
-                       _bt_core_service_request_adapter(BT_DISABLE_ADAPTER_LE);
-#endif
-                       if (!TIZEN_FEATURE_BT_USB_DONGLE)
-                               _bt_disable_adapter_le();
-               }
-       } else {
-               int flight_mode_value = 0;
-
-               BT_INFO_C("Flight mode off. Turn on BT");
-
-               if (adapter_status == BT_DEACTIVATING || adapter_status_le == BT_LE_DEACTIVATING) {
-                       BT_INFO("BT adapter is activating. Turn off BT after activation");
-                       _bt_set_flightmode_request(TRUE);
-                       return;
-               }
-               if (adapter_status != BT_DEACTIVATED && adapter_status_le != BT_LE_DEACTIVATED) {
-                       BT_INFO("No need to control bt status");
-                       return;
-               }
-
-               if (vconf_get_int(BT_OFF_DUE_TO_FLIGHT_MODE, &flight_mode_value))
-                       BT_ERR("Fail get flight mode value");
-
-               if (flight_mode_value == 0)
-                       return;
-
-               if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
-                       BT_ERR("Set vconf failed");
-
-               ret_if(__bt_off_cause_conflict_check());
-
-               if (adapter_status == BT_DEACTIVATED &&
-                   _bt_core_get_bt_status(BT_FLIGHT_MODE) != 0) {
-                       _bt_core_set_bt_status(BT_FLIGHT_MODE, 0);
-                       _bt_core_service_request_adapter(BT_ENABLE_ADAPTER);
-                       if (!TIZEN_FEATURE_BT_USB_DONGLE)
-                               _bt_enable_adapter();
-               }
-
-               if (adapter_status_le == BT_LE_DEACTIVATED &&
-                   _bt_core_get_bt_le_status(BT_FLIGHT_MODE) != 0) {
-                       _bt_core_set_bt_le_status(BT_FLIGHT_MODE, 0);
-                       _bt_core_service_request_adapter(BT_ENABLE_ADAPTER_LE);
-                       if (!TIZEN_FEATURE_BT_USB_DONGLE)
-                               _bt_enable_adapter_le();
-               }
-       }
-}
-
 static void __bt_core_handle_adapter_with_power_saving_mode(int power_saving_mode)
 {
        bt_status_t adapter_status;
@@ -219,24 +125,6 @@ static void __bt_core_handle_adapter_with_power_saving_mode(int power_saving_mod
        }
 }
 
-static void __bt_core_flight_mode_cb(keynode_t *node, void *data)
-{
-       gboolean flight_mode = FALSE;
-       int type;
-
-       BT_DBG("key = %s", vconf_keynode_get_name(node));
-
-       type = vconf_keynode_get_type(node);
-       if (type != VCONF_TYPE_BOOL) {
-               BT_ERR("Invaild vconf key type : %d", type);
-               return;
-       }
-
-       flight_mode = vconf_keynode_get_bool(node);
-
-       __bt_core_handle_adapter_with_flight_mode(flight_mode);
-}
-
 #ifdef ENABLE_TIZEN_2_4
 static void __bt_core_power_saving_mode_cb(keynode_t *node, void *data)
 {
@@ -266,7 +154,7 @@ void _bt_core_init_vconf_value(void)
        int bt_flight_mode = 0;
        int bt_ps_mode = 0;
 
-       _bt_core_handle_flight_mode_noti();
+       //_bt_core_handle_flight_mode_noti();
        _bt_core_handle_power_saving_mode_noti();
 
        flight_mode = _bt_core_is_flight_mode_enabled();
@@ -287,31 +175,12 @@ void _bt_core_init_vconf_value(void)
        if (vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, &bt_ps_mode))
                BT_ERR("Fail get power saving mode value");
        _bt_core_set_bt_status(BT_POWER_SAVING_MODE, bt_ps_mode);
-
-       if (flight_mode == TRUE)
-               __bt_core_handle_adapter_with_flight_mode(flight_mode);
 #ifndef ENABLE_TIZEN_2_4
-       else if (power_saving_mode > 0)
+       if (power_saving_mode > 0)
                __bt_core_handle_adapter_with_power_saving_mode(power_saving_mode);
-#endif
        else
                BT_ERR("");
-}
-
-void _bt_core_handle_flight_mode_noti(void)
-{
-       int ret;
-
-       if (TIZEN_FEATURE_FLIGHTMODE_ENABLED) {
-               BT_DBG("+");
-
-               ret = vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
-                               (vconf_callback_fn)__bt_core_flight_mode_cb, NULL);
-               if (ret < 0)
-                       BT_ERR("Unable to register key handler");
-       } else {
-               BT_DBG("Telephony is disabled");
-       }
+#endif
 }
 
 void _bt_core_handle_power_saving_mode_noti(void)
@@ -332,18 +201,11 @@ void _bt_core_handle_power_saving_mode_noti(void)
 
 void _bt_core_unregister_vconf_handler(void)
 {
-       if (TIZEN_FEATURE_FLIGHTMODE_ENABLED) {
-               vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
-                               (vconf_callback_fn)__bt_core_flight_mode_cb);
-       }
-
 #ifdef ENABLE_TIZEN_2_4
        if (!TIZEN_PROFILE_WEARABLE) {
                vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE,
                                (vconf_callback_fn)__bt_core_power_saving_mode_cb);
        }
 #endif
-
-       return;
 }
 
index 8749c4c..d456bfb 100755 (executable)
@@ -29,7 +29,6 @@ gboolean _bt_is_flightmode_request(void);
 
 void _bt_core_init_vconf_value(void);
 
-void _bt_core_handle_flight_mode_noti(void);
 void _bt_core_handle_power_saving_mode_noti(void);
 void _bt_core_unregister_vconf_handler(void);
 
index 1bbd4c3..bf962ff 100644 (file)
@@ -505,42 +505,6 @@ static void __bt_hal_adapter_property_changed_event(GVariant *msg)
        }
 }
 
-static void __bt_hal_flight_ps_mode_cb(keynode_t *node, void *data)
-{
-       gboolean flight_mode = FALSE;
-       int type;
-       DBG_SECURE("HAL callback hit");
-       DBG_SECURE("key=%s", vconf_keynode_get_name(node));
-       type = vconf_keynode_get_type(node);
-       if (type == VCONF_TYPE_BOOL) {
-               flight_mode = vconf_keynode_get_bool(node);
-               if (flight_mode != TRUE) {
-                       ERR("Ignore the event");
-                       return;
-               } else {
-                       ERR("Flight Mode == TRUE");
-               }
-       } else {
-               ERR("Invaild vconf key type : %d", type);
-               return;
-       }
-       DBG("Enabling core now");
-       _bt_hal_enable_core();
-}
-
-static void _bt_hal_register_vconf_handler(void)
-{
-       DBG("+");
-
-       if (vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
-               (vconf_callback_fn)__bt_hal_flight_ps_mode_cb, NULL) < 0)
-                       ERR("Unable to register key handler");
-       DBG("Telephony is disabled");
-       if (vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE,
-               (vconf_callback_fn)__bt_hal_flight_ps_mode_cb, NULL) < 0)
-                       ERR("Unable to register key handler");
-}
-
 void _bt_hal_handle_adapter_event(GVariant *msg, const char *member)
 {
        if (member == NULL)
@@ -1571,9 +1535,6 @@ int _bt_hal_initialize_event_receiver(handle_stack_msg cb)
 
        /*TODO: Initialize Obexd Event receiver */
 
-       /* Initialize event receiver for flight mode  */
-       _bt_hal_register_vconf_handler();
-
        event_cb = cb;
 
        return BT_HAL_ERROR_NONE;
index 453022f..6679aa8 100644 (file)
@@ -75,6 +75,14 @@ typedef struct {
 
 static bt_adapter_timer_t visible_timer;
 
+typedef enum {
+       BT_ADAPTER_FLIGHT_MODE_NONE = -1,
+       BT_ADAPTER_FLIGHT_MODE_OFF,
+       BT_ADAPTER_FLIGHT_MODE_ON,
+} bt_adapter_flightmode_req_e;
+
+static bt_adapter_flightmode_req_e flightmode_request = BT_ADAPTER_FLIGHT_MODE_NONE;
+
 static guint timer_id = 0;
 
 static gboolean a2dp_init_pending = TRUE;
@@ -288,6 +296,132 @@ gboolean _bt_is_discovering(void)
                return FALSE;
 }
 
+static void __bt_set_flightmode_request(int value)
+{
+       BT_INFO("Setting flightmode request to %d", value);
+       flightmode_request = value;
+}
+
+static int __bt_is_flightmode_request(void)
+{
+       return flightmode_request;
+}
+
+static void __bt_service_handle_flight_mode(gboolean flight_mode, bt_status_t adapter_status)
+{
+       int flight_mode_value = 0;
+       int ps_mode_value = 0;
+
+       if (flight_mode == TRUE) {
+               BT_INFO_C("### Flight mode on. Turn off BT");
+
+               if (adapter_status != BT_ACTIVATED) {
+                       BT_INFO("No need to control bt status");
+                       if (vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, &ps_mode_value))
+                               BT_ERR("Fail get PS mode value");
+
+                       BT_DBG("ps_mode_value %d", ps_mode_value);
+                       if (ps_mode_value > 0) {
+                               if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 1) != 0)
+                                       BT_ERR("Set vconf failed");
+                       }
+                       return;
+               }
+
+               __bt_set_flightmode_request(BT_ADAPTER_FLIGHT_MODE_ON);
+
+               if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 1) != 0)
+                       BT_ERR("Set vconf failed");
+
+               if (adapter_status == BT_ACTIVATED)
+                       _bt_disable_adapter();
+
+       } else {
+               BT_INFO_C("### Flight mode off. Turn on BT");
+
+               if (adapter_status == BT_ACTIVATED)
+                       return;
+
+               if (vconf_get_int(BT_OFF_DUE_TO_FLIGHT_MODE, &flight_mode_value))
+                       BT_ERR("Fail get flight mode value");
+
+               BT_DBG("flight_mode_value %d", flight_mode_value);
+               if (flight_mode_value == 0)
+                       return;
+
+               if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
+                       BT_ERR("Set vconf failed");
+
+               if (vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, &ps_mode_value))
+                       BT_ERR("Fail get PS mode value");
+
+               BT_DBG("ps_mode_value %d", ps_mode_value);
+               if (ps_mode_value > 0) {
+                       BT_DBG("Bt should not turn on");
+                       return;
+               }
+
+               if (adapter_status == BT_DEACTIVATING) {
+                       BT_INFO("BT adapter is deactivating. Turn on BT after deactivation");
+                       __bt_set_flightmode_request(BT_ADAPTER_FLIGHT_MODE_OFF);
+                       return;
+               }
+
+               if (adapter_status != BT_DEACTIVATED) {
+                       BT_INFO("No need to control bt status");
+                       return;
+               }
+               _bt_service_initialize();
+
+               if (adapter_status == BT_DEACTIVATED)
+                       _bt_enable_adapter();
+
+       }
+}
+
+static void __bt_service_flight_ps_mode_cb(keynode_t *node, void *data)
+{
+       int type;
+       bt_status_t adapter_status = BT_DEACTIVATED;
+       gboolean flight_mode = FALSE;
+
+       adapter_status = _bt_adapter_get_status();
+       BT_INFO("Flight mode changed. Current bt status is %d", adapter_status);
+
+       DBG_SECURE("key=%s", vconf_keynode_get_name(node));
+       type = vconf_keynode_get_type(node);
+
+       if (type == VCONF_TYPE_BOOL) {
+               flight_mode = vconf_keynode_get_bool(node);
+               __bt_service_handle_flight_mode(flight_mode, adapter_status);
+       } else {
+               BT_ERR("Invaild vconf key type : %d", type);
+       }
+}
+
+void _bt_service_register_vconf_handler(void)
+{
+       BT_DBG("+");
+
+       if (vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
+               (vconf_callback_fn)__bt_service_flight_ps_mode_cb, NULL) < 0)
+                       BT_ERR("Unable to register key handler");
+       if (vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE,
+               (vconf_callback_fn)__bt_service_flight_ps_mode_cb, NULL) < 0)
+                       BT_ERR("Unable to register key handler");
+}
+
+void _bt_service_unregister_vconf_handler(void)
+{
+       BT_DBG("+");
+
+       vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
+                       (vconf_callback_fn)__bt_service_flight_ps_mode_cb);
+
+       vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE,
+                       (vconf_callback_fn)__bt_service_flight_ps_mode_cb);
+}
+
 int _bt_get_local_address(void)
 {
        int result;
@@ -1387,9 +1521,19 @@ static gboolean __bt_adapter_post_set_disabled(gpointer user_data)
        /* bt-service should be terminated when BT is off */
        if (!TIZEN_FEATURE_BT_USB_DONGLE) {
                /* TODO: Implement to check if it is the recovery mode or not */
-               _bt_reliable_terminate_service(NULL);
-       } else {
-               _bt_set_disabled(BLUETOOTH_ERROR_NONE);
+               if (__bt_is_flightmode_request() == BT_ADAPTER_FLIGHT_MODE_ON) {
+                       /* Keep bt-service to handle Flight mode OFF */
+                       BT_DBG("Deactived due to flight mode. Keep bt-service");
+                       _bt_set_disabled(BLUETOOTH_ERROR_NONE);
+                       __bt_set_flightmode_request(BT_ADAPTER_FLIGHT_MODE_NONE);
+               } else if (__bt_is_flightmode_request() == BT_ADAPTER_FLIGHT_MODE_OFF) {
+                       BT_DBG("Durning deactivation, receive Flight mode Off. Enable BT adapter");
+                       _bt_set_disabled(BLUETOOTH_ERROR_NONE);
+                       _bt_service_initialize();
+                       _bt_enable_adapter();
+                       __bt_set_flightmode_request(BT_ADAPTER_FLIGHT_MODE_NONE);
+               } else
+                       _bt_reliable_terminate_service(NULL);
        }
 
        return FALSE;
@@ -1455,7 +1599,7 @@ static void __bt_adapter_update_discovery_status(bt_adapter_discovery_state_t st
 
 static void __bt_adapter_state_change_callback(int bt_status)
 {
-       BT_INFO("__bt_adapter_state_change_callback: status [%d]", bt_status);
+       BT_INFO("BT adapter status changed [%d]", bt_status);
 
        switch (bt_status) {
        case BT_DEACTIVATED:
@@ -1475,6 +1619,14 @@ static void __bt_adapter_state_change_callback(int bt_status)
                        g_source_remove(timer_id);
                        timer_id = 0;
                }
+
+               /*If adapter gets activated when flight mode is ON*/
+               if (__bt_is_flightmode_request() == BT_ADAPTER_FLIGHT_MODE_ON) {
+                       BT_DBG("Receive Flight mode On. Disable BT adapter");
+                       _bt_disable_adapter();
+                       return;
+               }
+
                __bt_adapter_update_bt_enabled();
                break;
        default:
index 34394c1..2ad0871 100644 (file)
@@ -262,7 +262,8 @@ int _bt_service_initialize(void)
                return EXIT_FAILURE;
        }
 
-       /* Flight mode handler implemented in HAL */
+       /* Flight mode handler */
+       _bt_service_register_vconf_handler();
 
        /* Event sender Init */
        ret = _bt_init_service_event_sender();
index c937aa1..1713c01 100644 (file)
@@ -65,7 +65,7 @@ int _bt_cancel_discovery(void);
 
 void _bt_service_register_vconf_handler(void);
 
-void _bt_service_register_vconf_handler(void);
+void _bt_service_unregister_vconf_handler(void);
 
 gboolean _bt_is_discovering(void);
 
index 866df9b..06e948b 100755 (executable)
@@ -29,6 +29,8 @@ gboolean _bt_terminate_service(gpointer user_data);
 
 gboolean _bt_reliable_terminate_service(gpointer user_data);
 
+int _bt_service_initialize(void);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */