[PATCH v2 7/7] android/handsfree: Add support for disabling HSP or HFP AGs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This allows to tune what profiles are supported by handsfree HAL.
---
 android/cutils/properties.h |  8 ++++++++
 android/hal-handsfree.c     | 20 +++++++++++++++++++-
 android/hal-msg.h           |  3 +++
 android/handsfree.c         | 12 +++++++++---
 4 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/android/cutils/properties.h b/android/cutils/properties.h
index dff812f..66a4a84 100644
--- a/android/cutils/properties.h
+++ b/android/cutils/properties.h
@@ -27,6 +27,14 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 
+#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 422f52c..df14bdd 100644
--- a/android/hal-handsfree.c
+++ b/android/hal-handsfree.c
@@ -20,6 +20,8 @@
 #include <string.h>
 #include <stdlib.h>
 
+#include <cutils/properties.h>
+
 #include "hal-log.h"
 #include "hal.h"
 #include "hal-msg.h"
@@ -196,6 +198,22 @@ static const struct hal_ipc_handler ev_handlers[] = {
 	{handle_hsp_key_press, false, 0},
 };
 
+static uint8_t get_flags(void)
+{
+	char value[PROPERTY_VALUE_MAX];
+	uint8_t flags = 0;
+
+	if (property_get("bluetooth.handsfree.no_hfp", value, "") > 0 &&
+			(!strcasecmp(value, "true") || atoi(value) > 0))
+		flags |= HAL_FLAGS_HANDSFREE_DISABLE_HFP_AG;
+
+	if (property_get("bluetooth.handsfree.no_hsp", value, "") > 0 &&
+			(!strcasecmp(value, "true") || atoi(value) > 0))
+		flags |= HAL_FLAGS_HANDSFREE_DISABLE_HSP_AG;
+
+	return flags;
+}
+
 static bt_status_t init(bthf_callbacks_t *callbacks)
 {
 	struct hal_cmd_register_module cmd;
@@ -212,7 +230,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.flags = 0;
+	cmd.flags = get_flags();
 
 	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 e66043e..8c8ab04 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -383,6 +383,9 @@ struct hal_cmd_pan_disconnect {
 
 /* Handsfree HAL API */
 
+#define HAL_FLAGS_HANDSFREE_DISABLE_HSP_AG	0x01
+#define HAL_FLAGS_HANDSFREE_DISABLE_HFP_AG	0x02
+
 #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 f229c53..1418299 100644
--- a/android/handsfree.c
+++ b/android/handsfree.c
@@ -820,14 +820,20 @@ static void cleanup_hfp_ag(void)
 
 bool bt_handsfree_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t flags)
 {
-	DBG("");
+	bool disable_hsp = flags & HAL_FLAGS_HANDSFREE_DISABLE_HSP_AG;
+	bool disable_hfp = flags & HAL_FLAGS_HANDSFREE_DISABLE_HFP_AG;
+
+	DBG("flags 0x%x", flags);
 
 	bacpy(&adapter_addr, addr);
 
-	if (!enable_hsp_ag())
+	if (disable_hsp && disable_hfp)
+		return false;
+
+	if (!disable_hsp && !enable_hsp_ag())
 		return false;
 
-	if (!enable_hfp_ag()) {
+	if (!disable_hfp && !enable_hfp_ag()) {
 		cleanup_hsp_ag();
 		return false;
 	}
-- 
1.8.5.3

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux