Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a8497de6 authored by Satya Calloji's avatar Satya Calloji Committed by Wei Wang
Browse files

Fix "no instances found for adv" when stop BLE scanning.

Bug:17703806
Change-Id: I103d3637ad38d33b4370850a300b0d72bdaeb562
parent a28c33b2
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -72,8 +72,8 @@ typedef struct
} btgatt_multi_adv_common_data;

extern btgatt_multi_adv_common_data *btif_obtain_multi_adv_data_cb();
extern void btif_gattc_init_multi_adv_cb(void);
extern void btif_gattc_destroy_multi_adv_cb();
extern void btif_gattc_incr_app_count(void);
extern void btif_gattc_decr_app_count(void);
extern int btif_multi_adv_add_instid_map(int client_if, int inst_id,
        BOOLEAN gen_temp_instid);
extern int btif_multi_adv_instid_for_clientif(int client_if);
+2 −2
Original line number Diff line number Diff line
@@ -1087,13 +1087,13 @@ static void btgattc_handle_event(uint16_t event, char* p_param)
    {
        case BTIF_GATTC_REGISTER_APP:
            btif_to_bta_uuid(&uuid, &p_cb->uuid);
            btif_gattc_init_multi_adv_cb();
            btif_gattc_incr_app_count();
            BTA_GATTC_AppRegister(&uuid, bta_gattc_cback);
            break;

        case BTIF_GATTC_UNREGISTER_APP:
            btif_gattc_clear_clientif(p_cb->client_if);
            btif_gattc_destroy_multi_adv_cb();
            btif_gattc_decr_app_count();
            BTA_GATTC_AppDeregister(p_cb->client_if);
            break;

+18 −15
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@
/*******************************************************************************
**  Static variables
********************************************************************************/
static int multi_adv_enable_count = 0;
static int user_app_count = 0;
static btgatt_multi_adv_common_data *p_multi_adv_com_data_cb = NULL;

btgatt_multi_adv_common_data *btif_obtain_multi_adv_data_cb()
@@ -52,9 +52,15 @@ btgatt_multi_adv_common_data *btif_obtain_multi_adv_data_cb()
        max_adv_inst = 1;

    BTIF_TRACE_DEBUG("%s, Count:%d", __FUNCTION__, max_adv_inst);
    if(0 == BTM_BleMaxMultiAdvInstanceCount())
    {
        BTIF_TRACE_WARNING("BTM_BleMaxMultiAdvInstanceCount - No instances found");
        return NULL;
    }

    BTIF_TRACE_DEBUG("BTM_BleMaxMultiAdvInstanceCount count:%d", BTM_BleMaxMultiAdvInstanceCount());
    if (NULL == p_multi_adv_com_data_cb)
    {
        BTIF_TRACE_DEBUG("Initializing in %s", __FUNCTION__);
        p_multi_adv_com_data_cb = GKI_getbuf(sizeof(btgatt_multi_adv_common_data));
        if (NULL != p_multi_adv_com_data_cb)
        {
@@ -82,21 +88,19 @@ btgatt_multi_adv_common_data *btif_obtain_multi_adv_data_cb()
    return p_multi_adv_com_data_cb;
}

void btif_gattc_init_multi_adv_cb(void)
void btif_gattc_incr_app_count(void)
{
    // TODO: Instead of using a fragile reference counter here, one could
    //       simply track the client_if instances that are in the map.
    ++multi_adv_enable_count;
    ++user_app_count;
}

void btif_gattc_destroy_multi_adv_cb(int client_if)
void btif_gattc_decr_app_count(void)
{
    if (multi_adv_enable_count > 0)
        multi_adv_enable_count --;
    if (user_app_count > 0)
        user_app_count --;

    if(multi_adv_enable_count == 0 && p_multi_adv_com_data_cb != 0)
    {
        if (NULL != p_multi_adv_com_data_cb)
    if(user_app_count == 0 && NULL != p_multi_adv_com_data_cb)
    {
       GKI_freebuf (p_multi_adv_com_data_cb->clntif_map);
       GKI_freebuf (p_multi_adv_com_data_cb->inst_cb);
@@ -104,7 +108,6 @@ void btif_gattc_destroy_multi_adv_cb(int client_if)
       p_multi_adv_com_data_cb = NULL;
    }
}
}

int btif_multi_adv_add_instid_map(int client_if, int inst_id, BOOLEAN gen_temp_instid)
{