summaryrefslogtreecommitdiff
path: root/osi
diff options
context:
space:
mode:
authorMarie Janssen <jamuraa@google.com>2016-03-25 13:37:13 -0700
committerMarie Janssen <jamuraa@google.com>2016-04-05 17:16:21 -0700
commitb9d28c30f9ef9f8f046bb08238abef9cba445be6 (patch)
tree8c9b438d14ba2a57d19cee80c34a1fa84e1f3620 /osi
parent236141f48707c5ed3ebc9549b3a9db5151fbb482 (diff)
downloadandroid-system-bt-b9d28c30f9ef9f8f046bb08238abef9cba445be6.tar.gz
android-system-bt-b9d28c30f9ef9f8f046bb08238abef9cba445be6.tar.xz
btif: Don't persist remote devices to the config
We don't need to persist the unpaired devices to NVRAM so skip saving them. This fixes a regression in a previous patch where the most recent instead of the least recent devices would be removed, making some devices unpairable in extremely busy environments. Bug: 26071376 Change-Id: If7ee9d960f70c836bf08b78da5f3fc852ba60a85
Diffstat (limited to 'osi')
-rw-r--r--osi/include/config.h8
-rw-r--r--osi/src/config.c24
-rw-r--r--osi/test/config_test.cpp13
3 files changed, 45 insertions, 0 deletions
diff --git a/osi/include/config.h b/osi/include/config.h
index ab3096d..3d7630f 100644
--- a/osi/include/config.h
+++ b/osi/include/config.h
@@ -37,6 +37,14 @@ 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.
+config_t *config_clone(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 740677a..8157bd5 100644
--- a/osi/src/config.c
+++ b/osi/src/config.c
@@ -94,6 +94,30 @@ config_t *config_new(const char *filename) {
return config;
}
+config_t *config_clone(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 4a0c4f8..2b61db1 100644
--- a/osi/test/config_test.cpp
+++ b/osi/test/config_test.cpp
@@ -80,6 +80,19 @@ TEST_F(ConfigTest, config_free_null) {
config_free(NULL);
}
+TEST_F(ConfigTest, config_clone) {
+ config_t *config = config_new(CONFIG_FILE);
+ config_t *clone = config_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"));