summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJessica Wagantall <jwagantall@cyngn.com>2016-06-07 10:32:39 -0700
committerJessica Wagantall <jwagantall@cyngn.com>2016-06-07 10:32:39 -0700
commit600e1a9d2a620de62476dfec140385d9233a1f7f (patch)
treef663582327062fe9108ae096d9bba1289505a475
parente1914075def5fb01ec1e4db80d337dd0589a9f39 (diff)
parent158910b4aaf2a72babdb4bf4176377c3de50b017 (diff)
downloadandroid_system_bt-600e1a9d2a620de62476dfec140385d9233a1f7f.tar.gz
android_system_bt-600e1a9d2a620de62476dfec140385d9233a1f7f.tar.bz2
android_system_bt-600e1a9d2a620de62476dfec140385d9233a1f7f.zip
Merge tag 'android-6.0.1_r46' into HEAD
Android 6.0.1 release 46 Change-Id: I6567a4b546ac813a2f4d6b0767fb582d40dfcb29
-rw-r--r--btif/include/btif_storage.h6
-rw-r--r--btif/src/btif_config.c51
-rw-r--r--osi/include/config.h9
-rw-r--r--osi/src/config.c24
-rw-r--r--osi/test/config_test.cpp13
5 files changed, 69 insertions, 34 deletions
diff --git a/btif/include/btif_storage.h b/btif/include/btif_storage.h
index 159f1aa04..e4d465c9f 100644
--- a/btif/include/btif_storage.h
+++ b/btif/include/btif_storage.h
@@ -95,11 +95,11 @@ bt_status_t btif_storage_set_remote_device_property(bt_bdaddr_t *remote_bd_addr,
**
** Function btif_storage_add_remote_device
**
-** Description BTIF storage API - Adds a newly discovered device to NVRAM
-** along with the timestamp. Also, stores the various
+** Description BTIF storage API - Adds a newly discovered device to
+** track along with the timestamp. Also, stores the various
** properties - RSSI, BDADDR, NAME (if found in EIR)
**
-** Returns BT_STATUS_SUCCESS if the store was successful,
+** Returns BT_STATUS_SUCCESS if successful,
** BT_STATUS_FAIL otherwise
**
*******************************************************************************/
diff --git a/btif/src/btif_config.c b/btif/src/btif_config.c
index 5fa6fbb40..39f4bbcaf 100644
--- a/btif/src/btif_config.c
+++ b/btif/src/btif_config.c
@@ -46,7 +46,7 @@ static const period_ms_t CONFIG_SETTLE_PERIOD_MS = 3000;
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 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}
@@ -111,7 +111,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
@@ -362,9 +362,6 @@ void btif_config_flush(void) {
alarm_cancel(alarm_timer);
btif_config_write(0, NULL);
- pthread_mutex_lock(&lock);
- config_flush(CONFIG_FILE_PATH);
- pthread_mutex_unlock(&lock);
}
int btif_config_clear(void){
@@ -398,43 +395,35 @@ static void btif_config_write(UNUSED_ATTR UINT16 event, UNUSED_ATTR char *p_para
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);
+static void btif_config_remove_unpaired(config_t *conf) {
+ assert(conf != 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;
-
- 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);
}
diff --git a/osi/include/config.h b/osi/include/config.h
index ea96058da..a067fd8e3 100644
--- a/osi/include/config.h
+++ b/osi/include/config.h
@@ -37,6 +37,15 @@ config_t *config_new_empty(void);
// file on the filesystem.
config_t *config_new(const char *filename);
+// Clones |src|, including all of it's sections, keys, and values.
+// Returns a new config which is a copy and separated from the original;
+// changes to the new config are not reflected in any way in the original.
+//
+// |src| must not be NULL
+// This function will not return NULL.
+// Clients must call config_free on the returned object.
+config_t *config_new_clone(const config_t *src);
+
// Frees resources associated with the config file. No further operations may
// be performed on the |config| object after calling this function. |config|
// may be NULL.
diff --git a/osi/src/config.c b/osi/src/config.c
index 9734265d0..b342a2e9b 100644
--- a/osi/src/config.c
+++ b/osi/src/config.c
@@ -97,6 +97,30 @@ config_t *config_new(const char *filename) {
return config;
}
+config_t *config_new_clone(const config_t *src) {
+ assert(src != NULL);
+
+ config_t *ret = config_new_empty();
+
+ assert(ret != NULL);
+
+ for (const list_node_t *node = list_begin(src->sections);
+ node != list_end(src->sections);
+ node = list_next(node)) {
+ section_t *sec = list_node(node);
+
+ for (const list_node_t *node_entry = list_begin(sec->entries);
+ node_entry != list_end(sec->entries);
+ node_entry = list_next(node_entry)) {
+ entry_t *entry = list_node(node_entry);
+
+ config_set_string(ret, sec->name, entry->key, entry->value);
+ }
+ }
+
+ return ret;
+}
+
void config_free(config_t *config) {
if (!config)
return;
diff --git a/osi/test/config_test.cpp b/osi/test/config_test.cpp
index 14649f549..88111093a 100644
--- a/osi/test/config_test.cpp
+++ b/osi/test/config_test.cpp
@@ -82,6 +82,19 @@ TEST_F(ConfigTest, config_free_null) {
config_free(NULL);
}
+TEST_F(ConfigTest, config_new_clone) {
+ config_t *config = config_new(CONFIG_FILE);
+ config_t *clone = config_new_clone(config);
+
+ config_set_string(clone, CONFIG_DEFAULT_SECTION, "first_key", "not_value");
+
+ EXPECT_STRNE(config_get_string(config, CONFIG_DEFAULT_SECTION, "first_key", "one"),
+ config_get_string(clone, CONFIG_DEFAULT_SECTION, "first_key", "one"));
+
+ config_free(config);
+ config_free(clone);
+}
+
TEST_F(ConfigTest, config_has_section) {
config_t *config = config_new(CONFIG_FILE);
EXPECT_TRUE(config_has_section(config, "DID"));