| From a8eb5834b23e74994ba1796adcd902dbc646be5d Mon Sep 17 00:00:00 2001 |
| From: Alex Deymo <deymo@chromium.org> |
| Date: Fri, 8 Mar 2013 14:48:27 -0800 |
| Subject: [PATCH] Make "Powered" property persistent across reboots. |
| |
| As part of the daemon shutdown the adapter is powered off. Restarting the |
| daemon will recover the current status from the adapter, but those will |
| always show the adapter as powered off. This patch adds a new property to |
| the "settings" adapter's file storing the last Powered status before |
| shutdown. This status is restored on startup. |
| |
| diff --git a/src/adapter.c b/src/adapter.c |
| index e553626..0c9acbc 100644 |
| --- a/src/adapter.c |
| +++ b/src/adapter.c |
| @@ -384,6 +384,10 @@ static void store_adapter_info(struct btd_adapter *adapter) |
| g_key_file_set_string(key_file, "General", "Alias", |
| adapter->stored_alias); |
| |
| + /* Always store the powered status */ |
| + g_key_file_set_boolean(key_file, "General", "Powered", |
| + btd_adapter_get_powered(adapter)); |
| + |
| ba2str(&adapter->bdaddr, address); |
| snprintf(filename, PATH_MAX, STORAGEDIR "/%s/settings", address); |
| filename[PATH_MAX] = '\0'; |
| @@ -441,6 +445,12 @@ static void settings_changed(struct btd_adapter *adapter, uint32_t settings) |
| g_dbus_emit_property_changed(dbus_conn, adapter->path, |
| ADAPTER_INTERFACE, "Powered"); |
| |
| + /* Don't store the adapter information during daemon shutdown. |
| + * It will store the adapter as powered "off" as part of the |
| + * shutdown. */ |
| + if (!powering_down) |
| + store_adapter_info(adapter); |
| + |
| if (adapter->current_settings & MGMT_SETTING_POWERED) { |
| adapter_start(adapter); |
| } else { |
| @@ -3846,6 +3856,7 @@ static void load_config(struct btd_adapter *adapter) |
| char address[18]; |
| struct stat st; |
| GError *gerr = NULL; |
| + gboolean powered; |
| |
| ba2str(&adapter->bdaddr, address); |
| |
| @@ -3897,6 +3908,16 @@ static void load_config(struct btd_adapter *adapter) |
| gerr = NULL; |
| } |
| |
| + /* Get power status */ |
| + powered = g_key_file_get_boolean(key_file, "General", "Powered", &gerr); |
| + if (gerr) { |
| + powered = false; |
| + g_error_free(gerr); |
| + gerr = NULL; |
| + } |
| + /* Update the power status for this adapter */ |
| + set_mode(adapter, MGMT_OP_SET_POWERED, powered ? 0x01 : 0x00); |
| + |
| g_key_file_free(key_file); |
| } |
| |