uint16_t conn_int_min, uint16_t conn_int_max,
uint16_t slave_latency,
uint16_t supervision_tout) {
+ L2CA_AdjustConnectionIntervals(&conn_int_min, &conn_int_max,
+ BTM_BLE_CONN_INT_MIN);
+
BTM_BleSetPrefConnParams(bd_addr, conn_int_min, conn_int_max, slave_latency,
supervision_tout);
}
uint16_t max_int, uint16_t latency,
uint16_t timeout, uint16_t min_ce_len,
uint16_t max_ce_len) {
+ L2CA_AdjustConnectionIntervals(&min_int, &max_int, BTM_BLE_CONN_INT_MIN);
+
if (!L2CA_UpdateBleConnParams(bd_addr, min_int, max_int, latency, timeout,
min_ce_len, max_ce_len)) {
APPL_TRACE_ERROR("Update connection parameters failed!");
return false;
}
+ size_t size() { return (devices.size()); }
+
std::vector<HearingDevice> devices;
};
callbacks->OnDeviceAvailable(capabilities, hiSyncId, address);
}
+ int GetDeviceCount() { return (hearingDevices.size()); }
+
void OnGattConnected(tGATT_STATUS status, uint16_t conn_id,
tGATT_IF client_if, RawAddress address,
tBTA_TRANSPORT transport, uint16_t mtu) {
render_delay, preparation_delay, is_white_listed);
};
+int HearingAid::GetDeviceCount() {
+ if (!instance) {
+ LOG(INFO) << __func__ << ": Not initialized yet";
+ return 0;
+ }
+
+ return (instance->GetDeviceCount());
+}
+
void HearingAid::CleanUp() {
// Must stop audio source to make sure it doesn't call any of callbacks on our
// soon to be null instance
// Make sure both min, and max are bigger than 11.25ms, lower values can
// introduce audio issues if A2DP is also active.
- if (min_interval < BTM_BLE_CONN_INT_MIN_LIMIT) {
- APPL_TRACE_DEBUG("%s: requested min_interval=%d too small. Set to %d",
- __func__, min_interval, BTM_BLE_CONN_INT_MIN_LIMIT);
- min_interval = BTM_BLE_CONN_INT_MIN_LIMIT;
- }
- if (max_interval < BTM_BLE_CONN_INT_MIN_LIMIT) {
- APPL_TRACE_DEBUG("%s: requested max_interval=%d too small. Set to %d",
- __func__, max_interval, BTM_BLE_CONN_INT_MIN_LIMIT);
- max_interval = BTM_BLE_CONN_INT_MIN_LIMIT;
- }
+ L2CA_AdjustConnectionIntervals(&min_interval, &max_interval,
+ BTM_BLE_CONN_INT_MIN_LIMIT);
// If the device has no preferred connection timeout, use the default.
if (timeout == BTM_BLE_CONN_PARAM_UNDEF) timeout = BTM_BLE_CONN_TIMEOUT_DEF;
uint16_t render_delay, uint16_t preparation_delay,
uint16_t is_white_listed);
+ static int GetDeviceCount();
+
virtual void Connect(const RawAddress& address) = 0;
virtual void Disconnect(const RawAddress& address) = 0;
virtual void SetVolume(int8_t volume) = 0;
#define BTM_BLE_CONN_INT_MIN_LIMIT 0x0009
#endif
+/* minimum acceptable connection interval when there is bonded Hearing Aid
+ * device */
+#ifndef BTM_BLE_CONN_INT_MIN_HEARINGAID
+#define BTM_BLE_CONN_INT_MIN_HEARINGAID 0x0010
+#endif
+
#define BTM_BLE_DIR_CONN_FALLBACK_UNDIR 1
#define BTM_BLE_DIR_CONN_FALLBACK_NO_ADV 2
extern uint16_t L2CA_GetDisconnectReason(const RawAddress& remote_bda,
tBT_TRANSPORT transport);
+extern void L2CA_AdjustConnectionIntervals(uint16_t* min_interval,
+ uint16_t* max_interval,
+ uint16_t floor_interval);
#endif /* L2C_API_H */
#include <string.h>
#include "bt_target.h"
#include "bt_utils.h"
+#include "bta_hearing_aid_api.h"
#include "btm_int.h"
#include "btu.h"
#include "device/include/controller.h"
p_lcb->min_interval > BTM_BLE_CONN_INT_MIN) {
/* use 7.5 ms as fast connection parameter, 0 slave latency */
min_conn_int = max_conn_int = BTM_BLE_CONN_INT_MIN;
+
+ L2CA_AdjustConnectionIntervals(&min_conn_int, &max_conn_int,
+ BTM_BLE_CONN_INT_MIN);
+
slave_latency = BTM_BLE_CONN_SLAVE_LATENCY_DEF;
supervision_tout = BTM_BLE_CONN_TIMEOUT_DEF;
STREAM_TO_UINT16(timeout, p); /* 0x000A - 0x0C80 */
/* If we are a master, the slave wants to update the parameters */
if (p_lcb->link_role == HCI_ROLE_MASTER) {
- if (min_interval < BTM_BLE_CONN_INT_MIN_LIMIT) {
- L2CAP_TRACE_DEBUG(
- "%s: requested min_interval=%d too small. Set to %d", __func__,
- min_interval, BTM_BLE_CONN_INT_MIN_LIMIT);
- min_interval = BTM_BLE_CONN_INT_MIN_LIMIT;
- }
-
- // While this could result in connection parameters that fall
- // outside fo the range requested, this will allow the connection
- // to remain established.
- // In other words, this is a workaround for certain peripherals.
- if (max_interval < BTM_BLE_CONN_INT_MIN_LIMIT) {
- L2CAP_TRACE_DEBUG(
- "%s: requested max_interval=%d too small. Set to %d", __func__,
- max_interval, BTM_BLE_CONN_INT_MIN_LIMIT);
- max_interval = BTM_BLE_CONN_INT_MIN_LIMIT;
- }
+ L2CA_AdjustConnectionIntervals(&min_interval, &max_interval,
+ BTM_BLE_CONN_INT_MIN_LIMIT);
if (min_interval < BTM_BLE_CONN_INT_MIN ||
min_interval > BTM_BLE_CONN_INT_MAX ||
return status;
}
+
+/* This function is called to adjust the connection intervals based on various
+ * constraints. For example, when there is at least one Hearing Aid device
+ * bonded, the minimum interval is raised. On return, min_interval and
+ * max_interval are updated. */
+void L2CA_AdjustConnectionIntervals(uint16_t* min_interval,
+ uint16_t* max_interval,
+ uint16_t floor_interval) {
+ uint16_t phone_min_interval = floor_interval;
+
+ if (HearingAid::GetDeviceCount() > 0) {
+ // When there are bonded Hearing Aid devices, we will constrained this
+ // minimum interval.
+ phone_min_interval = BTM_BLE_CONN_INT_MIN_HEARINGAID;
+ L2CAP_TRACE_DEBUG("%s: Have Hearing Aids. Min. interval is set to %d",
+ __func__, phone_min_interval);
+ }
+
+ if (*min_interval < phone_min_interval) {
+ L2CAP_TRACE_DEBUG("%s: requested min_interval=%d too small. Set to %d",
+ __func__, *min_interval, phone_min_interval);
+ *min_interval = phone_min_interval;
+ }
+
+ // While this could result in connection parameters that fall
+ // outside fo the range requested, this will allow the connection
+ // to remain established.
+ // In other words, this is a workaround for certain peripherals.
+ if (*max_interval < phone_min_interval) {
+ L2CAP_TRACE_DEBUG("%s: requested max_interval=%d too small. Set to %d",
+ __func__, *max_interval, phone_min_interval);
+ *max_interval = phone_min_interval;
+ }
+}