Enhance BT On scenario in power off 06/186006/1
authorSeungyoun Ju <sy39.ju@samsung.com>
Fri, 27 Jul 2018 09:30:20 +0000 (18:30 +0900)
committerSeungyoun Ju <sy39.ju@samsung.com>
Mon, 6 Aug 2018 11:46:38 +0000 (20:46 +0900)
[Problem] BT is not turned on when flight mode is unset during power
 off. This is not usual case but it happens sometimes in wearable model.
 Specific case is described in "Checking Method".
[Cause & Measure] If BT on is requested during power off, just update
 vconf of bt state. So that in next boot, BT is turned on.
[Checking Method] BT On -> Cool down (LimitAction) / Flight mode on ->
 BT Off -> Cool down (ShutDown) -> Flight mode off -> BT On, but it's not done
 -> Power off -> Power On -> BT should be turned on

Change-Id: I63775e38b09b77d7eb7c4cf9ae8e8445902b793a

bt-service/bt-service-adapter.c
bt-service/bt-service-main.c
bt-service/include/bt-service-adapter.h
bt-service/include/bt-service-common.h

index 16af447..eb358f2 100644 (file)
@@ -81,7 +81,9 @@ static GDBusProxy *core_proxy = NULL;
 static guint timer_id = 0;
 static guint le_timer_id = 0;
 static gboolean is_recovery_mode;
+static gboolean in_power_off;
 
+static guint poweroff_subscribe_id;
 static uint status_reg_id;
 
 #define BT_CORE_NAME "org.projectx.bt_core"
@@ -452,6 +454,17 @@ void _bt_set_le_intended_status(gboolean value)
        is_le_intended = value;
 }
 
+static void __bt_set_in_poweroff(void)
+{
+       BT_INFO("Set in_power_off to TRUE");
+       in_power_off = TRUE;
+}
+
+static gboolean __bt_is_in_poweroff(void)
+{
+       return in_power_off;
+}
+
 static void __bt_phone_name_changed_cb(keynode_t *node, void *data)
 {
        char *phone_name = NULL;
@@ -742,6 +755,53 @@ static void __bt_service_flight_ps_mode_cb(keynode_t *node, void *data)
 }
 #endif
 
+static void __bt_poweroff_event_filter(GDBusConnection *connection,
+               const gchar *sender_name, const gchar *object_path,
+               const gchar *interface_name, const gchar *signal_name,
+               GVariant *parameters, gpointer user_data)
+{
+       int state = 0;
+
+       g_variant_get(parameters, "(i)", &state);
+
+       if (state != BT_DEVICED_POWEROFF_SIGNAL_POWEROFF &&
+           state != BT_DEVICED_POWEROFF_SIGNAL_REBOOT) {
+               BT_DBG("Not interested event : %d", state);
+               return;
+       }
+
+       if (_bt_adapter_get_status() == BT_ACTIVATING) {
+               BT_INFO("Just update VCONFKEY_BT_STATUS in Power off");
+               if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_ON))
+                       BT_ERR("Set VCONFKEY_BT_STATUS failed");
+       } else {
+               __bt_set_in_poweroff();
+       }
+}
+
+void _bt_service_register_poweroff_event(void)
+{
+       if (poweroff_subscribe_id)
+               return;
+
+       poweroff_subscribe_id = g_dbus_connection_signal_subscribe(
+                       _bt_gdbus_get_system_gconn(), NULL,
+                       BT_DEVICED_POWEROFF_INTERFACE,
+                       BT_DEVICED_POWEROFF_SIGNAL,
+                       BT_DEVICED_POWEROFF_OBJECT_PATH,
+                       NULL, 0, __bt_poweroff_event_filter, NULL, NULL);
+}
+
+void _bt_service_unregister_poweroff_event(void)
+{
+       if (poweroff_subscribe_id == 0)
+               return;
+
+       g_dbus_connection_signal_unsubscribe(_bt_gdbus_get_system_gconn(),
+                                            poweroff_subscribe_id);
+       poweroff_subscribe_id = 0;
+}
+
 void _bt_service_register_vconf_handler(void)
 {
        BT_DBG("+");
@@ -1102,6 +1162,13 @@ int _bt_enable_adapter(void)
 }
 #endif
 
+       if (__bt_is_in_poweroff() == TRUE) {
+               BT_INFO("Just update VCONFKEY_BT_STATUS in Power off");
+               if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_ON) != 0)
+                       BT_ERR("Set VCONFKEY_BT_STATUS failed");
+               return BLUETOOTH_ERROR_NONE;
+       }
+
        proxy = __bt_get_core_proxy();
        if (!proxy)
                return BLUETOOTH_ERROR_INTERNAL;
index e77ffbd..e4a29d2 100644 (file)
@@ -45,6 +45,7 @@ static void __on_log_glib(const gchar *log_domain, GLogLevelFlags log_level,
 static void __bt_release_service(void)
 {
        _bt_service_unregister_vconf_handler();
+       _bt_service_unregister_poweroff_event();
 
        _bt_service_adapter_le_deinit();
        _bt_deinit_service_event_sender();
@@ -216,6 +217,7 @@ int _bt_service_initialize(void)
        }
 
        _bt_service_register_vconf_handler();
+       _bt_service_register_poweroff_event();
 
        /* Event reciever Init */
        ret = _bt_init_service_event_receiver();
index 1787cc5..aa03b6d 100644 (file)
@@ -74,6 +74,10 @@ int _bt_check_adapter(int *status);
 
 void *_bt_get_adapter_agent(void);
 
+void _bt_service_register_poweroff_event(void);
+
+void _bt_service_unregister_poweroff_event(void);
+
 void _bt_service_register_vconf_handler(void);
 
 void _bt_service_unregister_vconf_handler(void);
index e3af264..27953b6 100644 (file)
@@ -208,6 +208,15 @@ extern "C" {
 #define BT_DUMP_SERVICE_FINISH_SIGNAL "Finish"
 
 
+#define BT_DEVICED_POWEROFF_INTERFACE "org.tizen.system.deviced.PowerOff"
+#define BT_DEVICED_POWEROFF_OBJECT_PATH "/Org/Tizen/System/DeviceD/PowerOff"
+
+#define BT_DEVICED_POWEROFF_SIGNAL "ChangeState"
+#define BT_DEVICED_POWEROFF_SIGNAL_POWEROFF_POPUP (1)
+#define BT_DEVICED_POWEROFF_SIGNAL_POWEROFF (2)
+#define BT_DEVICED_POWEROFF_SIGNAL_REBOOT (3)
+
+
 #define BT_INTERFACES_ADDED "InterfacesAdded"
 #define BT_INTERFACES_REMOVED "InterfacesRemoved"
 #define BT_NAME_OWNER_CHANGED "NameOwnerChanged"