diff options
Diffstat (limited to 'btif/src/btif_config.c')
-rw-r--r-- | btif/src/btif_config.c | 49 |
1 files changed, 20 insertions, 29 deletions
diff --git a/btif/src/btif_config.c b/btif/src/btif_config.c index dfd308e90..ad5b60728 100644 --- a/btif/src/btif_config.c +++ b/btif/src/btif_config.c @@ -44,7 +44,7 @@ static const period_ms_t CONFIG_SETTLE_PERIOD_MS = 3000; static void timer_config_save_cb(void *data); static void btif_config_write(void); -static void btif_config_devcache_cleanup(void); +static void btif_config_remove_unpaired(config_t *config); // TODO(zachoverflow): Move these two functions out, because they are too specific for this file // {grumpy-cat/no, monty-python/you-make-me-sad} @@ -109,7 +109,7 @@ static future_t *init(void) { unlink(LEGACY_CONFIG_FILE_PATH); } - btif_config_devcache_cleanup(); + btif_config_remove_unpaired(config); // TODO(sharvil): use a non-wake alarm for this once we have // API support for it. There's no need to wake the system to @@ -358,7 +358,6 @@ void btif_config_flush(void) { assert(alarm_timer != NULL); alarm_cancel(alarm_timer); - btif_config_write(); } @@ -390,43 +389,35 @@ static void btif_config_write(void) { assert(config != NULL); assert(alarm_timer != NULL); - btif_config_devcache_cleanup(); - pthread_mutex_lock(&lock); - config_save(config, CONFIG_FILE_PATH); + config_t *config_paired = config_new_clone(config); + btif_config_remove_unpaired(config_paired); + config_save(config_paired, CONFIG_FILE_PATH); + config_free(config_paired); pthread_mutex_unlock(&lock); } -static void btif_config_devcache_cleanup(void) { - assert(config != NULL); - - // The config accumulates cached information about remote - // devices during regular inquiry scans. We remove some of these - // so the cache doesn't grow indefinitely. - // We don't remove information about bonded devices (which have link keys). - static const size_t ADDRS_MAX = 512; - size_t total_addrs = 0; +static void btif_config_remove_unpaired(config_t *conf) { + assert(conf != NULL); - pthread_mutex_lock(&lock); - const config_section_node_t *snode = config_section_begin(config); - while (snode != config_section_end(config)) { + // The paired config used to carry information about + // discovered devices during regular inquiry scans. + // We remove these now and cache them in memory instead. + const config_section_node_t *snode = config_section_begin(conf); + while (snode != config_section_end(conf)) { const char *section = config_section_name(snode); if (string_is_bdaddr(section)) { - ++total_addrs; - - if ((total_addrs > ADDRS_MAX) && - !config_has_key(config, section, "LinkKey") && - !config_has_key(config, section, "LE_KEY_PENC") && - !config_has_key(config, section, "LE_KEY_PID") && - !config_has_key(config, section, "LE_KEY_PCSRK") && - !config_has_key(config, section, "LE_KEY_LENC") && - !config_has_key(config, section, "LE_KEY_LCSRK")) { + if (!config_has_key(conf, section, "LinkKey") && + !config_has_key(conf, section, "LE_KEY_PENC") && + !config_has_key(conf, section, "LE_KEY_PID") && + !config_has_key(conf, section, "LE_KEY_PCSRK") && + !config_has_key(conf, section, "LE_KEY_LENC") && + !config_has_key(conf, section, "LE_KEY_LCSRK")) { snode = config_section_next(snode); - config_remove_section(config, section); + config_remove_section(conf, section); continue; } } snode = config_section_next(snode); } - pthread_mutex_unlock(&lock); } |