From 19507536783b78ee280d88ed8de966c7a9d07cb3 Mon Sep 17 00:00:00 2001 From: Johanna Ye Date: Tue, 16 Feb 2021 14:10:55 +0100 Subject: [PATCH] Wipe cache when HID report cache isn't compatible with the current cache version. This is to fix a big triggered by the OTA from any previous version to S due to the structure change of the cache report entries. Also corrected minor typos in documentation. Tag: #stability Test: Bond with HID device, upgrade from Q to S, verify device is working. Bug: 178874105 Bug: 159868059 Change-Id: Ibbd5da90892a637ffe8ff09b2b98bfc9fe3fb0cd --- btif/co/bta_hh_co.cc | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/btif/co/bta_hh_co.cc b/btif/co/bta_hh_co.cc index 363010166..4b9510ddb 100644 --- a/btif/co/bta_hh_co.cc +++ b/btif/co/bta_hh_co.cc @@ -41,6 +41,7 @@ const char* dev_path = "/dev/uhid"; #define BTA_HH_NV_LOAD_MAX 16 static tBTA_HH_RPT_CACHE_ENTRY sReportCache[BTA_HH_NV_LOAD_MAX]; #define GET_RPT_RSP_OFFSET 9 +#define BTA_HH_CACHE_REPORT_VERSION 1 #define THREAD_NORMAL_PRIORITY 0 #define BT_HH_THREAD "bt_hh_thread" @@ -645,6 +646,7 @@ void bta_hh_le_co_rpt_info(const RawAddress& remote_bda, memcpy(&sReportCache[idx++], p_entry, sizeof(tBTA_HH_RPT_CACHE_ENTRY)); btif_config_set_bin(bdstr, "HidReport", (const uint8_t*)sReportCache, idx * sizeof(tBTA_HH_RPT_CACHE_ENTRY)); + btif_config_set_int(bdstr, "HidReportVersion", BTA_HH_CACHE_REPORT_VERSION); BTIF_TRACE_DEBUG("%s() - Saving report; dev=%s, idx=%d", __func__, bdstr, idx); } @@ -656,14 +658,14 @@ void bta_hh_le_co_rpt_info(const RawAddress& remote_bda, * * Description This callout function is to request the application to load * the cached HOGP report if there is any. When cache reading - * is completed, bta_hh_le_ci_cache_load() is called by the + * is completed, bta_hh_le_co_cache_load() is called by the * application. * * Parameters remote_bda - remote device address - * p_num_rpt: number of cached report + * p_num_rpt - number of cached report * app_id - application id * - * Returns the acched report array + * Returns the cached report array * ******************************************************************************/ tBTA_HH_RPT_CACHE_ENTRY* bta_hh_le_co_cache_load(const RawAddress& remote_bda, @@ -677,6 +679,15 @@ tBTA_HH_RPT_CACHE_ENTRY* bta_hh_le_co_cache_load(const RawAddress& remote_bda, if (len > sizeof(sReportCache)) len = sizeof(sReportCache); btif_config_get_bin(bdstr, "HidReport", (uint8_t*)sReportCache, &len); + + int cache_version = -1; + btif_config_get_int(bdstr, "HidReportVersion", &cache_version); + + if (cache_version != BTA_HH_CACHE_REPORT_VERSION) { + bta_hh_le_co_reset_rpt_cache(remote_bda, app_id); + return NULL; + } + *p_num_rpt = len / sizeof(tBTA_HH_RPT_CACHE_ENTRY); BTIF_TRACE_DEBUG("%s() - Loaded %d reports; dev=%s", __func__, *p_num_rpt, @@ -702,6 +713,6 @@ void bta_hh_le_co_reset_rpt_cache(const RawAddress& remote_bda, const char* bdstr = addrstr.c_str(); btif_config_remove(bdstr, "HidReport"); - + btif_config_remove(bdstr, "HidReportVersion"); BTIF_TRACE_DEBUG("%s() - Reset cache for bda %s", __func__, bdstr); } -- 2.11.0