OSDN Git Service

Load gatt_database if it is empty in bta_gattc_process_indicate
authorweichinweng <weichinweng@google.com>
Tue, 11 Jun 2019 14:02:46 +0000 (22:02 +0800)
committerJakub Pawlowski <jpawlowski@google.com>
Wed, 12 Jun 2019 07:23:41 +0000 (07:23 +0000)
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

bta/gatt/bta_gattc_act.cc
bta/gatt/bta_gattc_cache.cc
bta/gatt/bta_gattc_int.h

index 5e60049..b009e5a 100644 (file)
@@ -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;
index 6c793f1..25b85ba 100644 (file)
@@ -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:
index 2b60ac7..6ee962d 100644 (file)
@@ -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 */