2014-11-06 12:55:06

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCH 1/3] android/client: Add new API support for handsfree client

From: Andrei Emeltchenko <[email protected]>

Add support for handsfree client new API by adding missing parameters
to functions and callbacks.
---
android/client/if-hf.c | 209 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 208 insertions(+), 1 deletion(-)

diff --git a/android/client/if-hf.c b/android/client/if-hf.c
index 77216df..161ae14 100644
--- a/android/client/if-hf.c
+++ b/android/client/if-hf.c
@@ -136,110 +136,226 @@ static void audio_state_cb(bthf_audio_state_t state, bt_bdaddr_t *bd_addr)
* Callback for VR connection state change.
* state will have one of the values from BtHfVRState
*/
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void vr_cmd_cb(bthf_vr_state_t state, bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: state=%s bd_addr=%s\n", __func__,
+ bthf_vr_state_t2str(state),
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void vr_cmd_cb(bthf_vr_state_t state)
{
haltest_info("%s: state=%s\n", __func__, bthf_vr_state_t2str(state));
}
+#endif

/* Callback for answer incoming call (ATA) */
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void answer_call_cmd_cb(bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: bd_addr=%s\n", __func__,
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void answer_call_cmd_cb(void)
{
haltest_info("%s\n", __func__);
}
+#endif

/* Callback for disconnect call (AT+CHUP) */
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void hangup_call_cmd_cb(bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: bd_addr=%s\n", __func__,
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void hangup_call_cmd_cb(void)
{
haltest_info("%s\n", __func__);
}
+#endif

/*
* Callback for disconnect call (AT+CHUP)
* type will denote Speaker/Mic gain (BtHfVolumeControl).
*/
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void volume_cmd_cb(bthf_volume_type_t type, int volume,
+ bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: type=%s volume=%d bd_addr=%s\n", __func__,
+ bthf_volume_type_t2str(type), volume,
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void volume_cmd_cb(bthf_volume_type_t type, int volume)
{
haltest_info("%s: type=%s volume=%d\n", __func__,
bthf_volume_type_t2str(type), volume);
}
+#endif

/*
* Callback for dialing an outgoing call
* If number is NULL, redial
*/
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void dial_call_cmd_cb(char *number, bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: number=%s bd_addr=%s\n", __func__, number,
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void dial_call_cmd_cb(char *number)
{
haltest_info("%s: number=%s\n", __func__, number);
}
+#endif

/*
* Callback for sending DTMF tones
* tone contains the dtmf character to be sent
*/
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void dtmf_cmd_cb(char tone, bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: tone=%d bd_addr=%s\n", __func__, tone,
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void dtmf_cmd_cb(char tone)
{
haltest_info("%s: tone=%d\n", __func__, tone);
}
+#endif

/*
* Callback for enabling/disabling noise reduction/echo cancellation
* value will be 1 to enable, 0 to disable
*/
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void nrec_cmd_cb(bthf_nrec_t nrec, bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: nrec=%s bd_addr=%s\n", __func__,
+ bthf_nrec_t2str(nrec),
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void nrec_cmd_cb(bthf_nrec_t nrec)
{
haltest_info("%s: nrec=%s\n", __func__, bthf_nrec_t2str(nrec));
}
+#endif

/*
* Callback for call hold handling (AT+CHLD)
* value will contain the call hold command (0, 1, 2, 3)
*/
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void chld_cmd_cb(bthf_chld_type_t chld, bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: chld=%s bd_addr=%s\n", __func__,
+ bthf_chld_type_t2str(chld),
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void chld_cmd_cb(bthf_chld_type_t chld)
{
haltest_info("%s: chld=%s\n", __func__, bthf_chld_type_t2str(chld));
}
+#endif

/* Callback for CNUM (subscriber number) */
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void cnum_cmd_cb(bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: bd_addr=%s\n", __func__,
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void cnum_cmd_cb(void)
{
haltest_info("%s\n", __func__);
}
+#endif

/* Callback for indicators (CIND) */
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void cind_cmd_cb(bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: bd_addr=%s\n", __func__,
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void cind_cmd_cb(void)
{
haltest_info("%s\n", __func__);
}
+#endif

/* Callback for operator selection (COPS) */
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void cops_cmd_cb(bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: bd_addr=%s\n", __func__,
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void cops_cmd_cb(void)
{
haltest_info("%s\n", __func__);
}
+#endif

/* Callback for call list (AT+CLCC) */
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void clcc_cmd_cb(bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: bd_addr=%s\n", __func__,
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void clcc_cmd_cb(void)
{
haltest_info("%s\n", __func__);
}
+#endif

/*
* Callback for unknown AT command recd from HF
* at_string will contain the unparsed AT string
*/
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void unknown_at_cmd_cb(char *at_string, bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: at_string=%s bd_addr=%s\n", __func__, at_string,
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void unknown_at_cmd_cb(char *at_string)
{
haltest_info("%s: at_string=%s\n", __func__, at_string);
}
+#endif

/* Callback for keypressed (HSP) event. */
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void key_pressed_cmd_cb(bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: bd_addr=%s\n", __func__,
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void key_pressed_cmd_cb(void)
{
haltest_info("%s\n", __func__);
}
+#endif

static bthf_callbacks_t hf_cbacks = {
-
.size = sizeof(hf_cbacks),
.connection_state_cb = connection_state_cb,
.audio_state_cb = audio_state_cb,
@@ -263,9 +379,22 @@ static bthf_callbacks_t hf_cbacks = {

static void init_p(int argc, const char **argv)
{
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ int max_hf_clients;
+#endif
+
RETURN_IF_NULL(if_hf);

+#if ANDROID_VERSION <= PLATFORM_VER(4, 4, 4)
EXEC(if_hf->init, &hf_cbacks);
+#else
+ if (argc < 2)
+ max_hf_clients = 1;
+ else
+ max_hf_clients = atoi(argv[2]);
+
+ EXEC(if_hf->init, &hf_cbacks, max_hf_clients);
+#endif
}

/* connect */
@@ -351,18 +480,38 @@ static void disconnect_audio_p(int argc, const char **argv)

static void start_voice_recognition_p(int argc, const char **argv)
{
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ bt_bdaddr_t addr;
+#endif
+
RETURN_IF_NULL(if_hf);

+#if ANDROID_VERSION <= PLATFORM_VER(4, 4, 4)
EXEC(if_hf->start_voice_recognition);
+#else
+ VERIFY_ADDR_ARG(2, &addr);
+
+ EXEC(if_hf->start_voice_recognition, &addr);
+#endif
}

/* stop voice recognition */

static void stop_voice_recognition_p(int argc, const char **argv)
{
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ bt_bdaddr_t addr;
+#endif
+
RETURN_IF_NULL(if_hf);

+#if ANDROID_VERSION <= PLATFORM_VER(4, 4, 4)
EXEC(if_hf->stop_voice_recognition);
+#else
+ VERIFY_ADDR_ARG(2, &addr);
+
+ EXEC(if_hf->stop_voice_recognition, &addr);
+#endif
}

/* volume control */
@@ -380,6 +529,9 @@ static void volume_control_p(int argc, const char **argv)
{
bthf_volume_type_t type;
int volume;
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ bt_bdaddr_t addr;
+#endif

RETURN_IF_NULL(if_hf);

@@ -397,7 +549,13 @@ static void volume_control_p(int argc, const char **argv)
}
volume = atoi(argv[3]);

+#if ANDROID_VERSION <= PLATFORM_VER(4, 4, 4)
EXEC(if_hf->volume_control, type, volume);
+#else
+ VERIFY_ADDR_ARG(4, &addr);
+
+ EXEC(if_hf->volume_control, type, volume, &addr);
+#endif
}

/* Combined device status change notification */
@@ -460,6 +618,10 @@ static void device_status_notification_p(int argc, const char **argv)

static void cops_response_p(int argc, const char **argv)
{
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ bt_bdaddr_t addr;
+#endif
+
RETURN_IF_NULL(if_hf);

/* response */
@@ -468,7 +630,13 @@ static void cops_response_p(int argc, const char **argv)
return;
}

+#if ANDROID_VERSION <= PLATFORM_VER(4, 4, 4)
EXEC(if_hf->cops_response, argv[2]);
+#else
+ VERIFY_ADDR_ARG(3, &addr);
+
+ EXEC(if_hf->cops_response, argv[2], &addr);
+#endif
}

/* Response for CIND command */
@@ -491,6 +659,9 @@ static void cind_response_p(int argc, const char **argv)
int signal;
int roam;
int batt_chg;
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ bt_bdaddr_t addr;
+#endif

RETURN_IF_NULL(if_hf);

@@ -543,14 +714,25 @@ static void cind_response_p(int argc, const char **argv)
}
batt_chg = atoi(argv[8]);

+#if ANDROID_VERSION <= PLATFORM_VER(4, 4, 4)
EXEC(if_hf->cind_response, svc, num_active, num_held, call_setup_state,
signal, roam, batt_chg);
+#else
+ VERIFY_ADDR_ARG(9, &addr);
+
+ EXEC(if_hf->cind_response, svc, num_active, num_held, call_setup_state,
+ signal, roam, batt_chg, &addr);
+#endif
}

/* Pre-formatted AT response, typically in response to unknown AT cmd */

static void formatted_at_response_p(int argc, const char **argv)
{
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ bt_bdaddr_t addr;
+#endif
+
RETURN_IF_NULL(if_hf);

/* response */
@@ -559,7 +741,13 @@ static void formatted_at_response_p(int argc, const char **argv)
return;
}

+#if ANDROID_VERSION <= PLATFORM_VER(4, 4, 4)
EXEC(if_hf->formatted_at_response, argv[2]);
+#else
+ VERIFY_ADDR_ARG(3, &addr);
+
+ EXEC(if_hf->formatted_at_response, argv[2], &addr);
+#endif
}

/* at_response */
@@ -577,6 +765,9 @@ static void at_response_p(int argc, const char **argv)
{
bthf_at_response_t response_code;
int error_code;
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ bt_bdaddr_t addr;
+#endif

RETURN_IF_NULL(if_hf);

@@ -593,7 +784,13 @@ static void at_response_p(int argc, const char **argv)
else
error_code = atoi(argv[3]);

+#if ANDROID_VERSION <= PLATFORM_VER(4, 4, 4)
EXEC(if_hf->at_response, response_code, error_code);
+#else
+ VERIFY_ADDR_ARG(4, &addr);
+
+ EXEC(if_hf->at_response, response_code, error_code, &addr);
+#endif
}

/* response for CLCC command */
@@ -628,6 +825,9 @@ static void clcc_response_p(int argc, const char **argv)
bthf_call_mpty_type_t mpty;
const char *number;
bthf_call_addrtype_t type;
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ bt_bdaddr_t addr;
+#endif

RETURN_IF_NULL(if_hf);

@@ -680,8 +880,15 @@ static void clcc_response_p(int argc, const char **argv)
}
type = str2bthf_call_addrtype_t(argv[8]);

+#if ANDROID_VERSION <= PLATFORM_VER(4, 4, 4)
EXEC(if_hf->clcc_response, index, dir, state, mode, mpty, number,
type);
+#else
+ VERIFY_ADDR_ARG(9, &addr);
+
+ EXEC(if_hf->clcc_response, index, dir, state, mode, mpty, number,
+ type, &addr);
+#endif
}

/* phone state change */
--
1.9.1



2014-11-06 15:38:28

by Szymon Janc

[permalink] [raw]
Subject: Re: [PATCHv2 1/3] android/client: Add new API support for handsfree client

Hi Andrei,

On Thursday 06 of November 2014 17:00:51 Andrei Emeltchenko wrote:
> From: Andrei Emeltchenko <[email protected]>
>
> Add support for handsfree client new API by adding missing parameters
> to functions and callbacks.
> ---
> android/client/if-hf.c | 209 ++++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 208 insertions(+), 1 deletion(-)
>
> diff --git a/android/client/if-hf.c b/android/client/if-hf.c
> index 77216df..26c0139 100644
> --- a/android/client/if-hf.c
> +++ b/android/client/if-hf.c
> @@ -136,110 +136,226 @@ static void audio_state_cb(bthf_audio_state_t state, bt_bdaddr_t *bd_addr)
> * Callback for VR connection state change.
> * state will have one of the values from BtHfVRState
> */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void vr_cmd_cb(bthf_vr_state_t state, bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: state=%s bd_addr=%s\n", __func__,
> + bthf_vr_state_t2str(state),
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void vr_cmd_cb(bthf_vr_state_t state)
> {
> haltest_info("%s: state=%s\n", __func__, bthf_vr_state_t2str(state));
> }
> +#endif
>
> /* Callback for answer incoming call (ATA) */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void answer_call_cmd_cb(bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: bd_addr=%s\n", __func__,
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void answer_call_cmd_cb(void)
> {
> haltest_info("%s\n", __func__);
> }
> +#endif
>
> /* Callback for disconnect call (AT+CHUP) */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void hangup_call_cmd_cb(bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: bd_addr=%s\n", __func__,
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void hangup_call_cmd_cb(void)
> {
> haltest_info("%s\n", __func__);
> }
> +#endif
>
> /*
> * Callback for disconnect call (AT+CHUP)
> * type will denote Speaker/Mic gain (BtHfVolumeControl).
> */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void volume_cmd_cb(bthf_volume_type_t type, int volume,
> + bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: type=%s volume=%d bd_addr=%s\n", __func__,
> + bthf_volume_type_t2str(type), volume,
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void volume_cmd_cb(bthf_volume_type_t type, int volume)
> {
> haltest_info("%s: type=%s volume=%d\n", __func__,
> bthf_volume_type_t2str(type), volume);
> }
> +#endif
>
> /*
> * Callback for dialing an outgoing call
> * If number is NULL, redial
> */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void dial_call_cmd_cb(char *number, bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: number=%s bd_addr=%s\n", __func__, number,
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void dial_call_cmd_cb(char *number)
> {
> haltest_info("%s: number=%s\n", __func__, number);
> }
> +#endif
>
> /*
> * Callback for sending DTMF tones
> * tone contains the dtmf character to be sent
> */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void dtmf_cmd_cb(char tone, bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: tone=%d bd_addr=%s\n", __func__, tone,
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void dtmf_cmd_cb(char tone)
> {
> haltest_info("%s: tone=%d\n", __func__, tone);
> }
> +#endif
>
> /*
> * Callback for enabling/disabling noise reduction/echo cancellation
> * value will be 1 to enable, 0 to disable
> */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void nrec_cmd_cb(bthf_nrec_t nrec, bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: nrec=%s bd_addr=%s\n", __func__,
> + bthf_nrec_t2str(nrec),
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void nrec_cmd_cb(bthf_nrec_t nrec)
> {
> haltest_info("%s: nrec=%s\n", __func__, bthf_nrec_t2str(nrec));
> }
> +#endif
>
> /*
> * Callback for call hold handling (AT+CHLD)
> * value will contain the call hold command (0, 1, 2, 3)
> */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void chld_cmd_cb(bthf_chld_type_t chld, bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: chld=%s bd_addr=%s\n", __func__,
> + bthf_chld_type_t2str(chld),
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void chld_cmd_cb(bthf_chld_type_t chld)
> {
> haltest_info("%s: chld=%s\n", __func__, bthf_chld_type_t2str(chld));
> }
> +#endif
>
> /* Callback for CNUM (subscriber number) */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void cnum_cmd_cb(bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: bd_addr=%s\n", __func__,
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void cnum_cmd_cb(void)
> {
> haltest_info("%s\n", __func__);
> }
> +#endif
>
> /* Callback for indicators (CIND) */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void cind_cmd_cb(bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: bd_addr=%s\n", __func__,
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void cind_cmd_cb(void)
> {
> haltest_info("%s\n", __func__);
> }
> +#endif
>
> /* Callback for operator selection (COPS) */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void cops_cmd_cb(bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: bd_addr=%s\n", __func__,
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void cops_cmd_cb(void)
> {
> haltest_info("%s\n", __func__);
> }
> +#endif
>
> /* Callback for call list (AT+CLCC) */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void clcc_cmd_cb(bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: bd_addr=%s\n", __func__,
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void clcc_cmd_cb(void)
> {
> haltest_info("%s\n", __func__);
> }
> +#endif
>
> /*
> * Callback for unknown AT command recd from HF
> * at_string will contain the unparsed AT string
> */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void unknown_at_cmd_cb(char *at_string, bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: at_string=%s bd_addr=%s\n", __func__, at_string,
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void unknown_at_cmd_cb(char *at_string)
> {
> haltest_info("%s: at_string=%s\n", __func__, at_string);
> }
> +#endif
>
> /* Callback for keypressed (HSP) event. */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void key_pressed_cmd_cb(bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: bd_addr=%s\n", __func__,
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void key_pressed_cmd_cb(void)
> {
> haltest_info("%s\n", __func__);
> }
> +#endif
>
> static bthf_callbacks_t hf_cbacks = {
> -
> .size = sizeof(hf_cbacks),
> .connection_state_cb = connection_state_cb,
> .audio_state_cb = audio_state_cb,
> @@ -263,9 +379,22 @@ static bthf_callbacks_t hf_cbacks = {
>
> static void init_p(int argc, const char **argv)
> {
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + int max_hf_clients;
> +#endif
> +
> RETURN_IF_NULL(if_hf);
>
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + if (argc < 2)
> + max_hf_clients = 1;
> + else
> + max_hf_clients = atoi(argv[2]);
> +
> + EXEC(if_hf->init, &hf_cbacks, max_hf_clients);
> +#else
> EXEC(if_hf->init, &hf_cbacks);
> +#endif
> }
>
> /* connect */
> @@ -351,18 +480,38 @@ static void disconnect_audio_p(int argc, const char **argv)
>
> static void start_voice_recognition_p(int argc, const char **argv)
> {
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + bt_bdaddr_t addr;
> +#endif
> +
> RETURN_IF_NULL(if_hf);
>
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + VERIFY_ADDR_ARG(2, &addr);
> +
> + EXEC(if_hf->start_voice_recognition, &addr);
> +#else
> EXEC(if_hf->start_voice_recognition);
> +#endif
> }
>
> /* stop voice recognition */
>
> static void stop_voice_recognition_p(int argc, const char **argv)
> {
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + bt_bdaddr_t addr;
> +#endif
> +
> RETURN_IF_NULL(if_hf);
>
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + VERIFY_ADDR_ARG(2, &addr);
> +
> + EXEC(if_hf->stop_voice_recognition, &addr);
> +#else
> EXEC(if_hf->stop_voice_recognition);
> +#endif
> }
>
> /* volume control */
> @@ -380,6 +529,9 @@ static void volume_control_p(int argc, const char **argv)
> {
> bthf_volume_type_t type;
> int volume;
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + bt_bdaddr_t addr;
> +#endif
>
> RETURN_IF_NULL(if_hf);
>
> @@ -397,7 +549,13 @@ static void volume_control_p(int argc, const char **argv)
> }
> volume = atoi(argv[3]);
>
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + VERIFY_ADDR_ARG(4, &addr);
> +
> + EXEC(if_hf->volume_control, type, volume, &addr);
> +#else
> EXEC(if_hf->volume_control, type, volume);
> +#endif
> }
>
> /* Combined device status change notification */
> @@ -460,6 +618,10 @@ static void device_status_notification_p(int argc, const char **argv)
>
> static void cops_response_p(int argc, const char **argv)
> {
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + bt_bdaddr_t addr;
> +#endif
> +
> RETURN_IF_NULL(if_hf);
>
> /* response */
> @@ -468,7 +630,13 @@ static void cops_response_p(int argc, const char **argv)
> return;
> }
>
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + VERIFY_ADDR_ARG(3, &addr);
> +
> + EXEC(if_hf->cops_response, argv[2], &addr);
> +#else
> EXEC(if_hf->cops_response, argv[2]);
> +#endif
> }
>
> /* Response for CIND command */
> @@ -491,6 +659,9 @@ static void cind_response_p(int argc, const char **argv)
> int signal;
> int roam;
> int batt_chg;
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + bt_bdaddr_t addr;
> +#endif
>
> RETURN_IF_NULL(if_hf);
>
> @@ -543,14 +714,25 @@ static void cind_response_p(int argc, const char **argv)
> }
> batt_chg = atoi(argv[8]);
>
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + VERIFY_ADDR_ARG(9, &addr);
> +
> + EXEC(if_hf->cind_response, svc, num_active, num_held, call_setup_state,
> + signal, roam, batt_chg, &addr);
> +#else
> EXEC(if_hf->cind_response, svc, num_active, num_held, call_setup_state,
> signal, roam, batt_chg);
> +#endif
> }
>
> /* Pre-formatted AT response, typically in response to unknown AT cmd */
>
> static void formatted_at_response_p(int argc, const char **argv)
> {
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + bt_bdaddr_t addr;
> +#endif
> +
> RETURN_IF_NULL(if_hf);
>
> /* response */
> @@ -559,7 +741,13 @@ static void formatted_at_response_p(int argc, const char **argv)
> return;
> }
>
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + VERIFY_ADDR_ARG(3, &addr);
> +
> + EXEC(if_hf->formatted_at_response, argv[2], &addr);
> +#else
> EXEC(if_hf->formatted_at_response, argv[2]);
> +#endif
> }
>
> /* at_response */
> @@ -577,6 +765,9 @@ static void at_response_p(int argc, const char **argv)
> {
> bthf_at_response_t response_code;
> int error_code;
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + bt_bdaddr_t addr;
> +#endif
>
> RETURN_IF_NULL(if_hf);
>
> @@ -593,7 +784,13 @@ static void at_response_p(int argc, const char **argv)
> else
> error_code = atoi(argv[3]);
>
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + VERIFY_ADDR_ARG(4, &addr);
> +
> + EXEC(if_hf->at_response, response_code, error_code, &addr);
> +#else
> EXEC(if_hf->at_response, response_code, error_code);
> +#endif
> }
>
> /* response for CLCC command */
> @@ -628,6 +825,9 @@ static void clcc_response_p(int argc, const char **argv)
> bthf_call_mpty_type_t mpty;
> const char *number;
> bthf_call_addrtype_t type;
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + bt_bdaddr_t addr;
> +#endif
>
> RETURN_IF_NULL(if_hf);
>
> @@ -680,8 +880,15 @@ static void clcc_response_p(int argc, const char **argv)
> }
> type = str2bthf_call_addrtype_t(argv[8]);
>
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + VERIFY_ADDR_ARG(9, &addr);
> +
> + EXEC(if_hf->clcc_response, index, dir, state, mode, mpty, number,
> + type, &addr);
> +#else
> EXEC(if_hf->clcc_response, index, dir, state, mode, mpty, number,
> type);
> +#endif
> }
>
> /* phone state change */

All three patches applied, thanks.

--
Best regards,
Szymon Janc

2014-11-06 15:00:53

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv2 3/3] android/client: Fix unused warning for gatt client in Android 5

From: Andrei Emeltchenko <[email protected]>

---
android/client/if-gatt.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/android/client/if-gatt.c b/android/client/if-gatt.c
index 6a09012..5f0eb1c 100644
--- a/android/client/if-gatt.c
+++ b/android/client/if-gatt.c
@@ -928,7 +928,9 @@ static void unregister_client_p(int argc, const char **argv)

static void scan_p(int argc, const char **argv)
{
+#if ANDROID_VERSION < PLATFORM_VER(5, 0, 0)
int client_if;
+#endif
int start = 1;

RETURN_IF_NULL(if_gatt);
--
1.9.1


2014-11-06 15:00:51

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv2 1/3] android/client: Add new API support for handsfree client

From: Andrei Emeltchenko <[email protected]>

Add support for handsfree client new API by adding missing parameters
to functions and callbacks.
---
android/client/if-hf.c | 209 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 208 insertions(+), 1 deletion(-)

diff --git a/android/client/if-hf.c b/android/client/if-hf.c
index 77216df..26c0139 100644
--- a/android/client/if-hf.c
+++ b/android/client/if-hf.c
@@ -136,110 +136,226 @@ static void audio_state_cb(bthf_audio_state_t state, bt_bdaddr_t *bd_addr)
* Callback for VR connection state change.
* state will have one of the values from BtHfVRState
*/
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void vr_cmd_cb(bthf_vr_state_t state, bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: state=%s bd_addr=%s\n", __func__,
+ bthf_vr_state_t2str(state),
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void vr_cmd_cb(bthf_vr_state_t state)
{
haltest_info("%s: state=%s\n", __func__, bthf_vr_state_t2str(state));
}
+#endif

/* Callback for answer incoming call (ATA) */
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void answer_call_cmd_cb(bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: bd_addr=%s\n", __func__,
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void answer_call_cmd_cb(void)
{
haltest_info("%s\n", __func__);
}
+#endif

/* Callback for disconnect call (AT+CHUP) */
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void hangup_call_cmd_cb(bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: bd_addr=%s\n", __func__,
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void hangup_call_cmd_cb(void)
{
haltest_info("%s\n", __func__);
}
+#endif

/*
* Callback for disconnect call (AT+CHUP)
* type will denote Speaker/Mic gain (BtHfVolumeControl).
*/
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void volume_cmd_cb(bthf_volume_type_t type, int volume,
+ bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: type=%s volume=%d bd_addr=%s\n", __func__,
+ bthf_volume_type_t2str(type), volume,
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void volume_cmd_cb(bthf_volume_type_t type, int volume)
{
haltest_info("%s: type=%s volume=%d\n", __func__,
bthf_volume_type_t2str(type), volume);
}
+#endif

/*
* Callback for dialing an outgoing call
* If number is NULL, redial
*/
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void dial_call_cmd_cb(char *number, bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: number=%s bd_addr=%s\n", __func__, number,
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void dial_call_cmd_cb(char *number)
{
haltest_info("%s: number=%s\n", __func__, number);
}
+#endif

/*
* Callback for sending DTMF tones
* tone contains the dtmf character to be sent
*/
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void dtmf_cmd_cb(char tone, bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: tone=%d bd_addr=%s\n", __func__, tone,
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void dtmf_cmd_cb(char tone)
{
haltest_info("%s: tone=%d\n", __func__, tone);
}
+#endif

/*
* Callback for enabling/disabling noise reduction/echo cancellation
* value will be 1 to enable, 0 to disable
*/
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void nrec_cmd_cb(bthf_nrec_t nrec, bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: nrec=%s bd_addr=%s\n", __func__,
+ bthf_nrec_t2str(nrec),
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void nrec_cmd_cb(bthf_nrec_t nrec)
{
haltest_info("%s: nrec=%s\n", __func__, bthf_nrec_t2str(nrec));
}
+#endif

/*
* Callback for call hold handling (AT+CHLD)
* value will contain the call hold command (0, 1, 2, 3)
*/
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void chld_cmd_cb(bthf_chld_type_t chld, bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: chld=%s bd_addr=%s\n", __func__,
+ bthf_chld_type_t2str(chld),
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void chld_cmd_cb(bthf_chld_type_t chld)
{
haltest_info("%s: chld=%s\n", __func__, bthf_chld_type_t2str(chld));
}
+#endif

/* Callback for CNUM (subscriber number) */
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void cnum_cmd_cb(bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: bd_addr=%s\n", __func__,
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void cnum_cmd_cb(void)
{
haltest_info("%s\n", __func__);
}
+#endif

/* Callback for indicators (CIND) */
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void cind_cmd_cb(bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: bd_addr=%s\n", __func__,
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void cind_cmd_cb(void)
{
haltest_info("%s\n", __func__);
}
+#endif

/* Callback for operator selection (COPS) */
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void cops_cmd_cb(bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: bd_addr=%s\n", __func__,
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void cops_cmd_cb(void)
{
haltest_info("%s\n", __func__);
}
+#endif

/* Callback for call list (AT+CLCC) */
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void clcc_cmd_cb(bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: bd_addr=%s\n", __func__,
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void clcc_cmd_cb(void)
{
haltest_info("%s\n", __func__);
}
+#endif

/*
* Callback for unknown AT command recd from HF
* at_string will contain the unparsed AT string
*/
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void unknown_at_cmd_cb(char *at_string, bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: at_string=%s bd_addr=%s\n", __func__, at_string,
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void unknown_at_cmd_cb(char *at_string)
{
haltest_info("%s: at_string=%s\n", __func__, at_string);
}
+#endif

/* Callback for keypressed (HSP) event. */
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void key_pressed_cmd_cb(bt_bdaddr_t *bd_addr)
+{
+ haltest_info("%s: bd_addr=%s\n", __func__,
+ bt_bdaddr_t2str(bd_addr, last_addr));
+}
+#else
static void key_pressed_cmd_cb(void)
{
haltest_info("%s\n", __func__);
}
+#endif

static bthf_callbacks_t hf_cbacks = {
-
.size = sizeof(hf_cbacks),
.connection_state_cb = connection_state_cb,
.audio_state_cb = audio_state_cb,
@@ -263,9 +379,22 @@ static bthf_callbacks_t hf_cbacks = {

static void init_p(int argc, const char **argv)
{
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ int max_hf_clients;
+#endif
+
RETURN_IF_NULL(if_hf);

+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ if (argc < 2)
+ max_hf_clients = 1;
+ else
+ max_hf_clients = atoi(argv[2]);
+
+ EXEC(if_hf->init, &hf_cbacks, max_hf_clients);
+#else
EXEC(if_hf->init, &hf_cbacks);
+#endif
}

/* connect */
@@ -351,18 +480,38 @@ static void disconnect_audio_p(int argc, const char **argv)

static void start_voice_recognition_p(int argc, const char **argv)
{
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ bt_bdaddr_t addr;
+#endif
+
RETURN_IF_NULL(if_hf);

+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ VERIFY_ADDR_ARG(2, &addr);
+
+ EXEC(if_hf->start_voice_recognition, &addr);
+#else
EXEC(if_hf->start_voice_recognition);
+#endif
}

/* stop voice recognition */

static void stop_voice_recognition_p(int argc, const char **argv)
{
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ bt_bdaddr_t addr;
+#endif
+
RETURN_IF_NULL(if_hf);

+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ VERIFY_ADDR_ARG(2, &addr);
+
+ EXEC(if_hf->stop_voice_recognition, &addr);
+#else
EXEC(if_hf->stop_voice_recognition);
+#endif
}

/* volume control */
@@ -380,6 +529,9 @@ static void volume_control_p(int argc, const char **argv)
{
bthf_volume_type_t type;
int volume;
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ bt_bdaddr_t addr;
+#endif

RETURN_IF_NULL(if_hf);

@@ -397,7 +549,13 @@ static void volume_control_p(int argc, const char **argv)
}
volume = atoi(argv[3]);

+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ VERIFY_ADDR_ARG(4, &addr);
+
+ EXEC(if_hf->volume_control, type, volume, &addr);
+#else
EXEC(if_hf->volume_control, type, volume);
+#endif
}

/* Combined device status change notification */
@@ -460,6 +618,10 @@ static void device_status_notification_p(int argc, const char **argv)

static void cops_response_p(int argc, const char **argv)
{
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ bt_bdaddr_t addr;
+#endif
+
RETURN_IF_NULL(if_hf);

/* response */
@@ -468,7 +630,13 @@ static void cops_response_p(int argc, const char **argv)
return;
}

+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ VERIFY_ADDR_ARG(3, &addr);
+
+ EXEC(if_hf->cops_response, argv[2], &addr);
+#else
EXEC(if_hf->cops_response, argv[2]);
+#endif
}

/* Response for CIND command */
@@ -491,6 +659,9 @@ static void cind_response_p(int argc, const char **argv)
int signal;
int roam;
int batt_chg;
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ bt_bdaddr_t addr;
+#endif

RETURN_IF_NULL(if_hf);

@@ -543,14 +714,25 @@ static void cind_response_p(int argc, const char **argv)
}
batt_chg = atoi(argv[8]);

+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ VERIFY_ADDR_ARG(9, &addr);
+
+ EXEC(if_hf->cind_response, svc, num_active, num_held, call_setup_state,
+ signal, roam, batt_chg, &addr);
+#else
EXEC(if_hf->cind_response, svc, num_active, num_held, call_setup_state,
signal, roam, batt_chg);
+#endif
}

/* Pre-formatted AT response, typically in response to unknown AT cmd */

static void formatted_at_response_p(int argc, const char **argv)
{
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ bt_bdaddr_t addr;
+#endif
+
RETURN_IF_NULL(if_hf);

/* response */
@@ -559,7 +741,13 @@ static void formatted_at_response_p(int argc, const char **argv)
return;
}

+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ VERIFY_ADDR_ARG(3, &addr);
+
+ EXEC(if_hf->formatted_at_response, argv[2], &addr);
+#else
EXEC(if_hf->formatted_at_response, argv[2]);
+#endif
}

/* at_response */
@@ -577,6 +765,9 @@ static void at_response_p(int argc, const char **argv)
{
bthf_at_response_t response_code;
int error_code;
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ bt_bdaddr_t addr;
+#endif

RETURN_IF_NULL(if_hf);

@@ -593,7 +784,13 @@ static void at_response_p(int argc, const char **argv)
else
error_code = atoi(argv[3]);

+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ VERIFY_ADDR_ARG(4, &addr);
+
+ EXEC(if_hf->at_response, response_code, error_code, &addr);
+#else
EXEC(if_hf->at_response, response_code, error_code);
+#endif
}

/* response for CLCC command */
@@ -628,6 +825,9 @@ static void clcc_response_p(int argc, const char **argv)
bthf_call_mpty_type_t mpty;
const char *number;
bthf_call_addrtype_t type;
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ bt_bdaddr_t addr;
+#endif

RETURN_IF_NULL(if_hf);

@@ -680,8 +880,15 @@ static void clcc_response_p(int argc, const char **argv)
}
type = str2bthf_call_addrtype_t(argv[8]);

+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ VERIFY_ADDR_ARG(9, &addr);
+
+ EXEC(if_hf->clcc_response, index, dir, state, mode, mpty, number,
+ type, &addr);
+#else
EXEC(if_hf->clcc_response, index, dir, state, mode, mpty, number,
type);
+#endif
}

/* phone state change */
--
1.9.1


2014-11-06 15:00:52

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv2 2/3] android/handsfree: Add dummy configure_wbs() function

From: Andrei Emeltchenko <[email protected]>

In a case Android runs this print debug message.
---
android/hal-handsfree.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/android/hal-handsfree.c b/android/hal-handsfree.c
index 8b644f3..c2b3fd5 100644
--- a/android/hal-handsfree.c
+++ b/android/hal-handsfree.c
@@ -828,6 +828,17 @@ static void cleanup(void)
hal_ipc_unregister(HAL_SERVICE_ID_HANDSFREE);
}

+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static bt_status_t configure_wbs(bt_bdaddr_t *bd_addr, bthf_wbs_config_t config)
+{
+ /* TODO: implement */
+
+ DBG("");
+
+ return BT_STATUS_UNSUPPORTED;
+}
+#endif
+
static bthf_interface_t iface = {
.size = sizeof(iface),
.init = init,
@@ -845,7 +856,10 @@ static bthf_interface_t iface = {
.at_response = at_response,
.clcc_response = clcc_response,
.phone_state_change = phone_state_change,
- .cleanup = cleanup
+ .cleanup = cleanup,
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ .configure_wbs = configure_wbs,
+#endif
};

bthf_interface_t *bt_get_handsfree_interface(void)
--
1.9.1


2014-11-06 13:29:11

by Szymon Janc

[permalink] [raw]
Subject: Re: [PATCH 1/3] android/client: Add new API support for handsfree client

Hi Andrei,

On Thursday 06 of November 2014 14:55:06 Andrei Emeltchenko wrote:
> From: Andrei Emeltchenko <[email protected]>
>
> Add support for handsfree client new API by adding missing parameters
> to functions and callbacks.
> ---
> android/client/if-hf.c | 209 ++++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 208 insertions(+), 1 deletion(-)

Patches 2 and 3 are now applied. For this I have some comments:

>
> diff --git a/android/client/if-hf.c b/android/client/if-hf.c
> index 77216df..161ae14 100644
> --- a/android/client/if-hf.c
> +++ b/android/client/if-hf.c
> @@ -136,110 +136,226 @@ static void audio_state_cb(bthf_audio_state_t state, bt_bdaddr_t *bd_addr)
> * Callback for VR connection state change.
> * state will have one of the values from BtHfVRState
> */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void vr_cmd_cb(bthf_vr_state_t state, bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: state=%s bd_addr=%s\n", __func__,
> + bthf_vr_state_t2str(state),
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void vr_cmd_cb(bthf_vr_state_t state)
> {
> haltest_info("%s: state=%s\n", __func__, bthf_vr_state_t2str(state));
> }
> +#endif
>
> /* Callback for answer incoming call (ATA) */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void answer_call_cmd_cb(bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: bd_addr=%s\n", __func__,
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void answer_call_cmd_cb(void)
> {
> haltest_info("%s\n", __func__);
> }
> +#endif
>
> /* Callback for disconnect call (AT+CHUP) */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void hangup_call_cmd_cb(bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: bd_addr=%s\n", __func__,
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void hangup_call_cmd_cb(void)
> {
> haltest_info("%s\n", __func__);
> }
> +#endif
>
> /*
> * Callback for disconnect call (AT+CHUP)
> * type will denote Speaker/Mic gain (BtHfVolumeControl).
> */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void volume_cmd_cb(bthf_volume_type_t type, int volume,
> + bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: type=%s volume=%d bd_addr=%s\n", __func__,
> + bthf_volume_type_t2str(type), volume,
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void volume_cmd_cb(bthf_volume_type_t type, int volume)
> {
> haltest_info("%s: type=%s volume=%d\n", __func__,
> bthf_volume_type_t2str(type), volume);
> }
> +#endif
>
> /*
> * Callback for dialing an outgoing call
> * If number is NULL, redial
> */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void dial_call_cmd_cb(char *number, bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: number=%s bd_addr=%s\n", __func__, number,
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void dial_call_cmd_cb(char *number)
> {
> haltest_info("%s: number=%s\n", __func__, number);
> }
> +#endif
>
> /*
> * Callback for sending DTMF tones
> * tone contains the dtmf character to be sent
> */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void dtmf_cmd_cb(char tone, bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: tone=%d bd_addr=%s\n", __func__, tone,
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void dtmf_cmd_cb(char tone)
> {
> haltest_info("%s: tone=%d\n", __func__, tone);
> }
> +#endif
>
> /*
> * Callback for enabling/disabling noise reduction/echo cancellation
> * value will be 1 to enable, 0 to disable
> */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void nrec_cmd_cb(bthf_nrec_t nrec, bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: nrec=%s bd_addr=%s\n", __func__,
> + bthf_nrec_t2str(nrec),
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void nrec_cmd_cb(bthf_nrec_t nrec)
> {
> haltest_info("%s: nrec=%s\n", __func__, bthf_nrec_t2str(nrec));
> }
> +#endif
>
> /*
> * Callback for call hold handling (AT+CHLD)
> * value will contain the call hold command (0, 1, 2, 3)
> */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void chld_cmd_cb(bthf_chld_type_t chld, bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: chld=%s bd_addr=%s\n", __func__,
> + bthf_chld_type_t2str(chld),
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void chld_cmd_cb(bthf_chld_type_t chld)
> {
> haltest_info("%s: chld=%s\n", __func__, bthf_chld_type_t2str(chld));
> }
> +#endif
>
> /* Callback for CNUM (subscriber number) */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void cnum_cmd_cb(bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: bd_addr=%s\n", __func__,
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void cnum_cmd_cb(void)
> {
> haltest_info("%s\n", __func__);
> }
> +#endif
>
> /* Callback for indicators (CIND) */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void cind_cmd_cb(bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: bd_addr=%s\n", __func__,
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void cind_cmd_cb(void)
> {
> haltest_info("%s\n", __func__);
> }
> +#endif
>
> /* Callback for operator selection (COPS) */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void cops_cmd_cb(bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: bd_addr=%s\n", __func__,
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void cops_cmd_cb(void)
> {
> haltest_info("%s\n", __func__);
> }
> +#endif
>
> /* Callback for call list (AT+CLCC) */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void clcc_cmd_cb(bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: bd_addr=%s\n", __func__,
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void clcc_cmd_cb(void)
> {
> haltest_info("%s\n", __func__);
> }
> +#endif
>
> /*
> * Callback for unknown AT command recd from HF
> * at_string will contain the unparsed AT string
> */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void unknown_at_cmd_cb(char *at_string, bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: at_string=%s bd_addr=%s\n", __func__, at_string,
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void unknown_at_cmd_cb(char *at_string)
> {
> haltest_info("%s: at_string=%s\n", __func__, at_string);
> }
> +#endif
>
> /* Callback for keypressed (HSP) event. */
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void key_pressed_cmd_cb(bt_bdaddr_t *bd_addr)
> +{
> + haltest_info("%s: bd_addr=%s\n", __func__,
> + bt_bdaddr_t2str(bd_addr, last_addr));
> +}
> +#else
> static void key_pressed_cmd_cb(void)
> {
> haltest_info("%s\n", __func__);
> }
> +#endif
>
> static bthf_callbacks_t hf_cbacks = {
> -
> .size = sizeof(hf_cbacks),
> .connection_state_cb = connection_state_cb,
> .audio_state_cb = audio_state_cb,
> @@ -263,9 +379,22 @@ static bthf_callbacks_t hf_cbacks = {
>
> static void init_p(int argc, const char **argv)
> {
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + int max_hf_clients;
> +#endif
> +
> RETURN_IF_NULL(if_hf);
>
> +#if ANDROID_VERSION <= PLATFORM_VER(4, 4, 4)

I'd prefer if we stick to >= 5.0.0 whenever possible. Especially like this
(and few similar cases below), where single function is cut in two places.

> EXEC(if_hf->init, &hf_cbacks);
> +#else
> + if (argc < 2)
> + max_hf_clients = 1;
> + else
> + max_hf_clients = atoi(argv[2]);
> +
> + EXEC(if_hf->init, &hf_cbacks, max_hf_clients);
> +#endif
> }
>
> /* connect */
> @@ -351,18 +480,38 @@ static void disconnect_audio_p(int argc, const char **argv)
>
> static void start_voice_recognition_p(int argc, const char **argv)
> {
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + bt_bdaddr_t addr;
> +#endif
> +
> RETURN_IF_NULL(if_hf);
>
> +#if ANDROID_VERSION <= PLATFORM_VER(4, 4, 4)
> EXEC(if_hf->start_voice_recognition);
> +#else
> + VERIFY_ADDR_ARG(2, &addr);
> +
> + EXEC(if_hf->start_voice_recognition, &addr);
> +#endif
> }
>
> /* stop voice recognition */
>
> static void stop_voice_recognition_p(int argc, const char **argv)
> {
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + bt_bdaddr_t addr;
> +#endif
> +
> RETURN_IF_NULL(if_hf);
>
> +#if ANDROID_VERSION <= PLATFORM_VER(4, 4, 4)
> EXEC(if_hf->stop_voice_recognition);
> +#else
> + VERIFY_ADDR_ARG(2, &addr);
> +
> + EXEC(if_hf->stop_voice_recognition, &addr);
> +#endif
> }
>
> /* volume control */
> @@ -380,6 +529,9 @@ static void volume_control_p(int argc, const char **argv)
> {
> bthf_volume_type_t type;
> int volume;
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + bt_bdaddr_t addr;
> +#endif
>
> RETURN_IF_NULL(if_hf);
>
> @@ -397,7 +549,13 @@ static void volume_control_p(int argc, const char **argv)
> }
> volume = atoi(argv[3]);
>
> +#if ANDROID_VERSION <= PLATFORM_VER(4, 4, 4)
> EXEC(if_hf->volume_control, type, volume);
> +#else
> + VERIFY_ADDR_ARG(4, &addr);
> +
> + EXEC(if_hf->volume_control, type, volume, &addr);
> +#endif
> }
>
> /* Combined device status change notification */
> @@ -460,6 +618,10 @@ static void device_status_notification_p(int argc, const char **argv)
>
> static void cops_response_p(int argc, const char **argv)
> {
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + bt_bdaddr_t addr;
> +#endif
> +
> RETURN_IF_NULL(if_hf);
>
> /* response */
> @@ -468,7 +630,13 @@ static void cops_response_p(int argc, const char **argv)
> return;
> }
>
> +#if ANDROID_VERSION <= PLATFORM_VER(4, 4, 4)
> EXEC(if_hf->cops_response, argv[2]);
> +#else
> + VERIFY_ADDR_ARG(3, &addr);
> +
> + EXEC(if_hf->cops_response, argv[2], &addr);
> +#endif
> }
>
> /* Response for CIND command */
> @@ -491,6 +659,9 @@ static void cind_response_p(int argc, const char **argv)
> int signal;
> int roam;
> int batt_chg;
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + bt_bdaddr_t addr;
> +#endif
>
> RETURN_IF_NULL(if_hf);
>
> @@ -543,14 +714,25 @@ static void cind_response_p(int argc, const char **argv)
> }
> batt_chg = atoi(argv[8]);
>
> +#if ANDROID_VERSION <= PLATFORM_VER(4, 4, 4)
> EXEC(if_hf->cind_response, svc, num_active, num_held, call_setup_state,
> signal, roam, batt_chg);
> +#else
> + VERIFY_ADDR_ARG(9, &addr);
> +
> + EXEC(if_hf->cind_response, svc, num_active, num_held, call_setup_state,
> + signal, roam, batt_chg, &addr);
> +#endif
> }
>
> /* Pre-formatted AT response, typically in response to unknown AT cmd */
>
> static void formatted_at_response_p(int argc, const char **argv)
> {
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + bt_bdaddr_t addr;
> +#endif
> +
> RETURN_IF_NULL(if_hf);
>
> /* response */
> @@ -559,7 +741,13 @@ static void formatted_at_response_p(int argc, const char **argv)
> return;
> }
>
> +#if ANDROID_VERSION <= PLATFORM_VER(4, 4, 4)
> EXEC(if_hf->formatted_at_response, argv[2]);
> +#else
> + VERIFY_ADDR_ARG(3, &addr);
> +
> + EXEC(if_hf->formatted_at_response, argv[2], &addr);
> +#endif
> }
>
> /* at_response */
> @@ -577,6 +765,9 @@ static void at_response_p(int argc, const char **argv)
> {
> bthf_at_response_t response_code;
> int error_code;
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + bt_bdaddr_t addr;
> +#endif
>
> RETURN_IF_NULL(if_hf);
>
> @@ -593,7 +784,13 @@ static void at_response_p(int argc, const char **argv)
> else
> error_code = atoi(argv[3]);
>
> +#if ANDROID_VERSION <= PLATFORM_VER(4, 4, 4)
> EXEC(if_hf->at_response, response_code, error_code);
> +#else
> + VERIFY_ADDR_ARG(4, &addr);
> +
> + EXEC(if_hf->at_response, response_code, error_code, &addr);
> +#endif
> }
>
> /* response for CLCC command */
> @@ -628,6 +825,9 @@ static void clcc_response_p(int argc, const char **argv)
> bthf_call_mpty_type_t mpty;
> const char *number;
> bthf_call_addrtype_t type;
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> + bt_bdaddr_t addr;
> +#endif
>
> RETURN_IF_NULL(if_hf);
>
> @@ -680,8 +880,15 @@ static void clcc_response_p(int argc, const char **argv)
> }
> type = str2bthf_call_addrtype_t(argv[8]);
>
> +#if ANDROID_VERSION <= PLATFORM_VER(4, 4, 4)
> EXEC(if_hf->clcc_response, index, dir, state, mode, mpty, number,
> type);
> +#else
> + VERIFY_ADDR_ARG(9, &addr);
> +
> + EXEC(if_hf->clcc_response, index, dir, state, mode, mpty, number,
> + type, &addr);
> +#endif
> }
>
> /* phone state change */
>

--
Best regards,
Szymon Janc

2014-11-06 12:55:07

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCH 2/3] android/handsfree: Fix cut and paste typo

From: Andrei Emeltchenko <[email protected]>

---
android/hal-handsfree.c | 2 --
1 file changed, 2 deletions(-)

diff --git a/android/hal-handsfree.c b/android/hal-handsfree.c
index 2834c80..8b644f3 100644
--- a/android/hal-handsfree.c
+++ b/android/hal-handsfree.c
@@ -466,8 +466,6 @@ static bt_status_t stop_voice_recognition_real(bt_bdaddr_t *bd_addr)
if (bd_addr)
memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));

- memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
-
return hal_ipc_cmd(HAL_SERVICE_ID_HANDSFREE, HAL_OP_HANDSFREE_STOP_VR,
sizeof(cmd), &cmd, NULL, NULL, NULL);
}
--
1.9.1


2014-11-06 12:55:08

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCH 3/3] android/handsfree: Use bdaddr provided for find_device()

From: Andrei Emeltchenko <[email protected]>

---
android/handsfree.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/android/handsfree.c b/android/handsfree.c
index 33fcbdd..9a2fdd0 100644
--- a/android/handsfree.c
+++ b/android/handsfree.c
@@ -2904,14 +2904,18 @@ static void disable_sco_server(void)

static void bt_sco_get_fd(const void *buf, uint16_t len)
{
- int fd;
- GError *err;
+ const struct sco_cmd_get_fd *cmd = buf;
struct sco_rsp_get_fd rsp;
struct hf_device *dev;
+ bdaddr_t bdaddr;
+ GError *err;
+ int fd;

DBG("");

- dev = find_default_device();
+ android2bdaddr(cmd->bdaddr, &bdaddr);
+
+ dev = find_device(&bdaddr);
if (!dev || !dev->sco)
goto failed;

--
1.9.1