static void timer_config_save_cb(void *data);
static void btif_config_write(UINT16 event, char *p_param);
-static void btif_config_devcache_cleanup(void);
static bool is_factory_reset(void);
static void delete_config_files(void);
+static void btif_config_remove_unpaired(config_t *config);
static enum ConfigSource {
NOT_LOADED,
goto error;
}
- 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
}
void btif_config_save(void) {
- assert(config_timer != NULL);
assert(config != NULL);
+ assert(config_timer != NULL);
alarm_set(config_timer, CONFIG_SETTLE_PERIOD_MS, timer_config_save_cb, NULL);
}
alarm_cancel(config_timer);
btif_config_write(0, NULL);
-
- pthread_mutex_lock(&lock);
- config_save(config, CONFIG_FILE_PATH);
- pthread_mutex_unlock(&lock);
}
bool btif_config_clear(void) {
assert(config != NULL);
assert(config_timer != NULL);
- btif_config_devcache_cleanup();
-
pthread_mutex_lock(&lock);
rename(CONFIG_FILE_PATH, CONFIG_BACKUP_PATH);
sync();
- config_save(config, CONFIG_FILE_PATH);
+ config_t *config_paired = config_clone(config);
+ btif_config_remove_unpaired(config_paired);
+ config_save(config_paired, CONFIG_FILE_PATH);
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);
}
void btif_debug_config_dump(int fd) {