am d86082bf: am 9b971dc5: Merge "treat BTA_BUSY as success to avoid unpair the BLE device" into klp-modular-dev
* commit 'd86082bfabffa25f2af77cc69c590d6e0b14260c':
treat BTA_BUSY as success to avoid unpair the BLE device
diff --git a/audio_a2dp_hw/audio_a2dp_hw.c b/audio_a2dp_hw/audio_a2dp_hw.c
index 2fee588..607de34 100644
--- a/audio_a2dp_hw/audio_a2dp_hw.c
+++ b/audio_a2dp_hw/audio_a2dp_hw.c
@@ -583,7 +583,8 @@
struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
struct str_parms *parms;
char keyval[16];
- int retval = 0;
+ int retval;
+ int status = 0;
INFO("state %d", out->state);
@@ -612,7 +613,7 @@
if (strcmp(keyval, "true") == 0)
{
if (out->state == AUDIO_A2DP_STATE_STARTED)
- retval = suspend_audio_datapath(out, false);
+ status = suspend_audio_datapath(out, false);
}
else
{
@@ -622,14 +623,13 @@
if (out->state == AUDIO_A2DP_STATE_SUSPENDED)
out->state = AUDIO_A2DP_STATE_STANDBY;
/* Irrespective of the state, return 0 */
- retval = 0;
}
}
pthread_mutex_unlock(&out->lock);
str_parms_destroy(parms);
- return retval;
+ return status;
}
static char * out_get_parameters(const struct audio_stream *stream, const char *keys)
@@ -1146,7 +1146,7 @@
return -ENOMEM;
adev->device.common.tag = HARDWARE_DEVICE_TAG;
- adev->device.common.version = AUDIO_DEVICE_API_VERSION_CURRENT;
+ adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0;
adev->device.common.module = (struct hw_module_t *) module;
adev->device.common.close = adev_close;
diff --git a/bta/gatt/bta_gattc_act.c b/bta/gatt/bta_gattc_act.c
index 44f88e4..00e486f 100644
--- a/bta/gatt/bta_gattc_act.c
+++ b/bta/gatt/bta_gattc_act.c
@@ -786,7 +786,13 @@
bta_gattc_clcb_dealloc(p_clcb);
if (p_data->hdr.event == BTA_GATTC_API_CLOSE_EVT)
+ {
cb_data.close.status = GATT_Disconnect(p_data->hdr.layer_specific);
+ }
+ else if (p_data->hdr.event == BTA_GATTC_INT_DISCONN_EVT)
+ {
+ cb_data.close.status = p_data->int_conn.reason;
+ }
if(p_cback)
(* p_cback)(BTA_GATTC_CLOSE_EVT, (tBTA_GATTC *)&cb_data);
@@ -2238,7 +2244,7 @@
{
tBTA_GATTC_RCB *p_clreg = bta_gattc_cl_get_regcb(p_msg->api_listen.client_if);
tBTA_GATTC cb_data;
- (void)(p_cb);
+ UNUSED(p_cb);
cb_data.reg_oper.client_if = p_msg->api_listen.client_if;
cb_data.reg_oper.status = BTM_BleBroadcast(p_msg->api_listen.start);
diff --git a/btif/src/btif_av.c b/btif/src/btif_av.c
index 3c0c293..f893c9e 100755
--- a/btif/src/btif_av.c
+++ b/btif/src/btif_av.c
@@ -39,6 +39,7 @@
#include "gki.h"
#include "bd.h"
#include "btu.h"
+#include "bt_utils.h"
/*****************************************************************************
** Constants & Macros
@@ -587,9 +588,17 @@
HAL_CBACK(bt_av_callbacks, audio_state_cb,
BTAV_AUDIO_STATE_STARTED, &(btif_av_cb.peer_bda));
+
+ /* increase the a2dp consumer task priority temporarily when start
+ ** audio playing, to avoid overflow the audio packet queue. */
+ adjust_priority_a2dp(TRUE);
+
break;
case BTIF_SM_EXIT_EVT:
+ /* restore the a2dp consumer task priority when stop audio playing. */
+ adjust_priority_a2dp(FALSE);
+
break;
case BTIF_AV_START_STREAM_REQ_EVT:
diff --git a/gki/ulinux/gki_ulinux.c b/gki/ulinux/gki_ulinux.c
index d03eb05..e6f45f4 100755
--- a/gki/ulinux/gki_ulinux.c
+++ b/gki/ulinux/gki_ulinux.c
@@ -97,8 +97,6 @@
** Local type definitions
******************************************************************************/
-#define pthread_cond_timedwait_monotonic pthread_cond_timedwait
-
typedef struct
{
UINT8 task_id; /* GKI task id */
@@ -266,8 +264,12 @@
gki_cb.com.OSWaitEvt[task_id] = 0;
/* Initialize mutex and condition variable objects for events and timeouts */
+ pthread_condattr_t cond_attr;
+ pthread_condattr_init(&cond_attr);
+ pthread_condattr_setclock(&cond_attr, CLOCK_MONOTONIC);
+
pthread_mutex_init(&gki_cb.os.thread_evt_mutex[task_id], NULL);
- pthread_cond_init (&gki_cb.os.thread_evt_cond[task_id], NULL);
+ pthread_cond_init (&gki_cb.os.thread_evt_cond[task_id], &cond_attr);
pthread_mutex_init(&gki_cb.os.thread_timeout_mutex[task_id], NULL);
pthread_cond_init (&gki_cb.os.thread_timeout_cond[task_id], NULL);
@@ -944,9 +946,8 @@
}
abstime.tv_sec += sec;
- pthread_cond_timedwait_monotonic(&gki_cb.os.thread_evt_cond[rtask],
+ pthread_cond_timedwait(&gki_cb.os.thread_evt_cond[rtask],
&gki_cb.os.thread_evt_mutex[rtask], &abstime);
-
}
else
{
diff --git a/include/bt_target.h b/include/bt_target.h
index 8950207..0e8d9d2 100644
--- a/include/bt_target.h
+++ b/include/bt_target.h
@@ -1597,7 +1597,7 @@
/* The MTU size for the L2CAP configuration. */
#ifndef SDP_MTU_SIZE
-#define SDP_MTU_SIZE 256
+#define SDP_MTU_SIZE 672
#endif
/* The flush timeout for the L2CAP configuration. */
diff --git a/main/bte_main.c b/main/bte_main.c
index cf21456..b9cbf91 100644
--- a/main/bte_main.c
+++ b/main/bte_main.c
@@ -198,12 +198,12 @@
lpm_enabled = FALSE;
- bte_hci_enable();
-
GKI_create_task((TASKPTR)btu_task, BTU_TASK, BTE_BTU_TASK_STR,
(UINT16 *) ((UINT8 *)bte_btu_stack + BTE_BTU_STACK_SIZE),
sizeof(bte_btu_stack));
+ bte_hci_enable();
+
GKI_run(0);
}
diff --git a/stack/btm/btm_ble_gap.c b/stack/btm/btm_ble_gap.c
index 54f1b55..608fa7e 100644
--- a/stack/btm/btm_ble_gap.c
+++ b/stack/btm/btm_ble_gap.c
@@ -1215,6 +1215,10 @@
BD_NAME bd_name;
memset(bd_name, 0, (BD_NAME_LEN + 1));
+ if (length > BD_NAME_LEN)
+ {
+ length = BD_NAME_LEN;
+ }
memcpy((UINT8*)bd_name, p_name, length);
if ((!status) || (length==0))
diff --git a/stack/sdp/sdp_server.c b/stack/sdp/sdp_server.c
index 5d11cb4..84dd957 100644
--- a/stack/sdp/sdp_server.c
+++ b/stack/sdp/sdp_server.c
@@ -380,8 +380,14 @@
else
{
/* Get a scratch buffer to store response */
- if (!p_ccb->rsp_list)
+ if (!p_ccb->rsp_list || (GKI_get_buf_size(p_ccb->rsp_list) < max_list_len))
{
+ /* Free and reallocate if the earlier allocated buffer is small */
+ if (p_ccb->rsp_list)
+ {
+ GKI_freebuf (p_ccb->rsp_list);
+ }
+
p_ccb->rsp_list = (UINT8 *)GKI_getbuf (max_list_len);
if (p_ccb->rsp_list == NULL)
{
@@ -624,8 +630,14 @@
else
{
/* Get a scratch buffer to store response */
- if (!p_ccb->rsp_list)
+ if (!p_ccb->rsp_list || (GKI_get_buf_size(p_ccb->rsp_list) < max_list_len))
{
+ /* Free and reallocate if the earlier allocated buffer is small */
+ if (p_ccb->rsp_list)
+ {
+ GKI_freebuf (p_ccb->rsp_list);
+ }
+
p_ccb->rsp_list = (UINT8 *)GKI_getbuf (max_list_len);
if (p_ccb->rsp_list == NULL)
{
diff --git a/utils/include/bt_utils.h b/utils/include/bt_utils.h
index d601f2e..ee21861 100644
--- a/utils/include/bt_utils.h
+++ b/utils/include/bt_utils.h
@@ -39,6 +39,7 @@
void bt_utils_init();
void bt_utils_cleanup();
void raise_priority_a2dp(tHIGH_PRIORITY_TASK high_task);
+void adjust_priority_a2dp(int start);
#define UNUSED(x) (void)(x)
diff --git a/utils/src/bt_utils.c b/utils/src/bt_utils.c
index aeb9292..6decacf 100644
--- a/utils/src/bt_utils.c
+++ b/utils/src/bt_utils.c
@@ -50,6 +50,8 @@
static BOOLEAN g_DoSchedulingGroup[TASK_HIGH_MAX];
static pthread_mutex_t gIdxLock;
static int g_TaskIdx;
+static int g_TaskIDs[TASK_HIGH_MAX];
+#define INVALID_TASK_ID (-1)
/*****************************************************************************
**
@@ -67,6 +69,7 @@
for(i = 0; i < TASK_HIGH_MAX; i++) {
g_DoSchedulingGroupOnce[i] = PTHREAD_ONCE_INIT;
g_DoSchedulingGroup[i] = TRUE;
+ g_TaskIDs[i] = INVALID_TASK_ID;
}
pthread_mutexattr_init(&lock_attr);
pthread_mutex_init(&gIdxLock, &lock_attr);
@@ -126,6 +129,7 @@
// set_sched_policy does not support tid == 0
rc = set_sched_policy(tid, SP_FOREGROUND);
}
+ g_TaskIDs[high_task] = tid;
pthread_mutex_unlock(&gIdxLock);
if (rc) {
@@ -137,3 +141,31 @@
}
}
+/*****************************************************************************
+**
+** Function adjust_priority_a2dp
+**
+** Description increase the a2dp consumer task priority temporarily when start
+** audio playing, to avoid overflow the audio packet queue, restore
+** the a2dp consumer task priority when stop audio playing.
+**
+** Returns void
+**
+*******************************************************************************/
+void adjust_priority_a2dp(int start) {
+ int priority = start ? ANDROID_PRIORITY_URGENT_AUDIO : ANDROID_PRIORITY_AUDIO;
+ int tid;
+ int i;
+
+ for (i = TASK_HIGH_GKI_TIMER; i < TASK_HIGH_MAX; i++)
+ {
+ tid = g_TaskIDs[i];
+ if (tid != INVALID_TASK_ID)
+ {
+ if (setpriority(PRIO_PROCESS, tid, priority) < 0)
+ {
+ ALOGW("failed to change priority tid: %d to %d", tid, priority);
+ }
+ }
+ }
+}