From: weichinweng Date: Tue, 11 Jun 2019 14:02:46 +0000 (+0800) Subject: Load gatt_database if it is empty in bta_gattc_process_indicate X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=9a169893a89ee494dd01ada6ab129a46016aed7b;p=android-x86%2Fsystem-bt.git Load gatt_database if it is empty in bta_gattc_process_indicate If Service Changed indication is received but gatt_database is empty, will try to load database from storage. Bug: 131814072 Bug: 134994428 Test: 1.CTS Bluetooth LE Secure Test. 2.Unit test. 3. Pair BLE device via APP. 4. Pair device via Bluetooth Setting Change-Id: Id3f3f0f33d5e0469a6f2ac6612fa9f5ea0b24142 --- diff --git a/bta/gatt/bta_gattc_act.cc b/bta/gatt/bta_gattc_act.cc index 5e60049ee..b009e5a7f 100644 --- a/bta/gatt/bta_gattc_act.cc +++ b/bta/gatt/bta_gattc_act.cc @@ -478,7 +478,7 @@ void bta_gattc_conn(tBTA_GATTC_CLCB* p_clcb, tBTA_GATTC_DATA* p_data) { p_clcb->p_srcb->state != BTA_GATTC_SERV_IDLE) { if (p_clcb->p_srcb->state == BTA_GATTC_SERV_IDLE) { p_clcb->p_srcb->state = BTA_GATTC_SERV_LOAD; - if (bta_gattc_cache_load(p_clcb)) { + if (bta_gattc_cache_load(p_clcb->p_srcb)) { p_clcb->p_srcb->state = BTA_GATTC_SERV_IDLE; bta_gattc_reset_discover_st(p_clcb->p_srcb, GATT_SUCCESS); } else { @@ -1127,6 +1127,10 @@ bool bta_gattc_process_srvc_chg_ind(uint16_t conn_id, tBTA_GATTC_RCB* p_clrcb, Uuid gattp_uuid = Uuid::From16Bit(UUID_SERVCLASS_GATT_SERVER); Uuid srvc_chg_uuid = Uuid::From16Bit(GATT_UUID_GATT_SRV_CHGD); + if (p_srcb->gatt_database.IsEmpty() && p_srcb->state == BTA_GATTC_SERV_IDLE) { + bta_gattc_cache_load(p_srcb); + } + const gatt::Characteristic* p_char = bta_gattc_get_characteristic_srcb(p_srcb, p_notify->handle); if (!p_char) return false; diff --git a/bta/gatt/bta_gattc_cache.cc b/bta/gatt/bta_gattc_cache.cc index 6c793f18e..25b85ba88 100644 --- a/bta/gatt/bta_gattc_cache.cc +++ b/bta/gatt/bta_gattc_cache.cc @@ -704,15 +704,14 @@ void bta_gattc_get_gatt_db(uint16_t conn_id, uint16_t start_handle, * * Description Load GATT cache from storage for server. * - * Parameter p_clcb: pointer to server clcb, that will + * Parameter p_srcb: pointer to server cache, that will * be filled from storage * Returns true on success, false otherwise * ******************************************************************************/ -bool bta_gattc_cache_load(tBTA_GATTC_CLCB* p_clcb) { +bool bta_gattc_cache_load(tBTA_GATTC_SERV* p_srcb) { char fname[255] = {0}; - bta_gattc_generate_cache_file_name(fname, sizeof(fname), - p_clcb->p_srcb->server_bda); + bta_gattc_generate_cache_file_name(fname, sizeof(fname), p_srcb->server_bda); FILE* fd = fopen(fname, "rb"); if (!fd) { @@ -749,7 +748,7 @@ bool bta_gattc_cache_load(tBTA_GATTC_CLCB* p_clcb) { goto done; } - p_clcb->p_srcb->gatt_database = gatt::Database::Deserialize(attr, &success); + p_srcb->gatt_database = gatt::Database::Deserialize(attr, &success); } done: diff --git a/bta/gatt/bta_gattc_int.h b/bta/gatt/bta_gattc_int.h index 2b60ac720..6ee962d35 100644 --- a/bta/gatt/bta_gattc_int.h +++ b/bta/gatt/bta_gattc_int.h @@ -452,7 +452,7 @@ extern tBTA_GATTC_CONN* bta_gattc_conn_find(const RawAddress& remote_bda); extern tBTA_GATTC_CONN* bta_gattc_conn_find_alloc(const RawAddress& remote_bda); extern bool bta_gattc_conn_dealloc(const RawAddress& remote_bda); -extern bool bta_gattc_cache_load(tBTA_GATTC_CLCB* p_clcb); +extern bool bta_gattc_cache_load(tBTA_GATTC_SERV* p_srcb); extern void bta_gattc_cache_reset(const RawAddress& server_bda); #endif /* BTA_GATTC_INT_H */