From c088a0f5c60f26441ef8b7418acfc71089e20ff0 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Mon, 3 Mar 2014 00:50:49 +0100 Subject: [PATCH] android/handsfree: Add support for disabling HSP or HFP AGs This allows to tune what profiles are supported by handsfree HAL. --- android/cutils/properties.h | 8 ++++++++ android/hal-handsfree.c | 15 ++++++++++++++- android/hal-msg.h | 2 ++ android/handsfree.c | 4 ++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/android/cutils/properties.h b/android/cutils/properties.h index dff812faa..66a4a8438 100644 --- a/android/cutils/properties.h +++ b/android/cutils/properties.h @@ -27,6 +27,14 @@ #include #include +#define PROPERTY_VALUE_MAX 32 + +static inline int property_get(const char *key, char *value, + const char *default_value) +{ + return 0; +} + /* property_set: returns 0 on success, < 0 on failure */ static inline int property_set(const char *key, const char *value) diff --git a/android/hal-handsfree.c b/android/hal-handsfree.c index 7a28e0f5c..4117ed0a9 100644 --- a/android/hal-handsfree.c +++ b/android/hal-handsfree.c @@ -20,6 +20,8 @@ #include #include +#include + #include "hal-log.h" #include "hal.h" #include "hal-msg.h" @@ -196,6 +198,17 @@ static const struct hal_ipc_handler ev_handlers[] = { {handle_hsp_key_press, false, 0}, }; +static uint8_t get_mode(void) +{ + char value[PROPERTY_VALUE_MAX]; + + if (property_get("bluetooth.handsfree_mode", value, "") > 0 && + (!strcasecmp(value, "hsp_only"))) + return HAL_MODE_HANDSFREE_HSP_ONLY; + + return HAL_MODE_DEFAULT; +} + static bt_status_t init(bthf_callbacks_t *callbacks) { struct hal_cmd_register_module cmd; @@ -212,7 +225,7 @@ static bt_status_t init(bthf_callbacks_t *callbacks) sizeof(ev_handlers)/sizeof(ev_handlers[0])); cmd.service_id = HAL_SERVICE_ID_HANDSFREE; - cmd.mode = HAL_MODE_DEFAULT; + cmd.mode = get_mode(); ret = hal_ipc_cmd(HAL_SERVICE_ID_CORE, HAL_OP_REGISTER_MODULE, sizeof(cmd), &cmd, 0, NULL, NULL); diff --git a/android/hal-msg.h b/android/hal-msg.h index 8eb97c3a3..dd25f6e04 100644 --- a/android/hal-msg.h +++ b/android/hal-msg.h @@ -385,6 +385,8 @@ struct hal_cmd_pan_disconnect { /* Handsfree HAL API */ +#define HAL_MODE_HANDSFREE_HSP_ONLY 0x01 + #define HAL_OP_HANDSFREE_CONNECT 0x01 struct hal_cmd_handsfree_connect { uint8_t bdaddr[6]; diff --git a/android/handsfree.c b/android/handsfree.c index 6149c62de..4f69e687b 100644 --- a/android/handsfree.c +++ b/android/handsfree.c @@ -820,14 +820,14 @@ static void cleanup_hfp_ag(void) bool bt_handsfree_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t mode) { - DBG(""); + DBG("mode 0x%x", mode); bacpy(&adapter_addr, addr); if (!enable_hsp_ag()) return false; - if (!enable_hfp_ag()) { + if (mode != HAL_MODE_HANDSFREE_HSP_ONLY && !enable_hfp_ag()) { cleanup_hsp_ag(); return false; } -- 2.47.3