diff options
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | system/btif/Android.mk | 2 | ||||
-rw-r--r-- | system/btif/BUILD.gn | 1 | ||||
-rw-r--r-- | system/btif/include/btif_config_transcode.h | 23 | ||||
-rw-r--r-- | system/btif/src/btif_config.c | 33 | ||||
-rw-r--r-- | system/btif/src/btif_config_transcode.cpp | 62 | ||||
-rw-r--r-- | system/doc/style_guide.md | 4 | ||||
-rw-r--r-- | system/main/Android.mk | 2 | ||||
-rw-r--r-- | system/main/BUILD.gn | 1 |
9 files changed, 118 insertions, 11 deletions
@@ -62,6 +62,7 @@ cd third_party git clone https://github.com/google/googletest.git git clone https://android.googlesource.com/platform/external/libchrome git clone https://android.googlesource.com/platform/external/modp_b64 +git clone https://android.googlesource.com/platform/external/tinyxml2 ``` And third party dependencies of third party dependencies: diff --git a/system/btif/Android.mk b/system/btif/Android.mk index 6628766b97..78a475bef1 100644 --- a/system/btif/Android.mk +++ b/system/btif/Android.mk @@ -30,6 +30,7 @@ btifCommonSrc += \ src/btif_av.c \ src/btif_avrcp_audio_track.cpp \ src/btif_config.c \ + src/btif_config_transcode.cpp \ src/btif_core.c \ src/btif_debug.c \ src/btif_debug_btsnoop.c \ @@ -105,6 +106,7 @@ btifCommonIncludes := \ $(LOCAL_PATH)/../audio_a2dp_hw \ $(LOCAL_PATH)/../utils/include \ $(bluetooth_C_INCLUDES) \ + external/tinyxml2 \ external/zlib # libbtif static library for target diff --git a/system/btif/BUILD.gn b/system/btif/BUILD.gn index d7171b0dda..f0d3ef8b5f 100644 --- a/system/btif/BUILD.gn +++ b/system/btif/BUILD.gn @@ -80,6 +80,7 @@ static_library("btif") { "//stack/a2dp", "//stack/btm", "//stack/include", + "//third_party/tinyxml2", "//include", "//udrv/include", "//utils/include", diff --git a/system/btif/include/btif_config_transcode.h b/system/btif/include/btif_config_transcode.h new file mode 100644 index 0000000000..e020ba6313 --- /dev/null +++ b/system/btif/include/btif_config_transcode.h @@ -0,0 +1,23 @@ +/****************************************************************************** + * + * Copyright (C) 2014 Google, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#pragma once + +typedef struct config_t config_t; + +config_t *btif_config_transcode(const char *xml_filename); diff --git a/system/btif/src/btif_config.c b/system/btif/src/btif_config.c index 82c6069bbc..ef90f89908 100644 --- a/system/btif/src/btif_config.c +++ b/system/btif/src/btif_config.c @@ -32,6 +32,7 @@ #include "btcore/include/module.h" #include "btif_common.h" #include "btif_config.h" +#include "btif_config_transcode.h" #include "btif_util.h" #include "osi/include/alarm.h" #include "osi/include/allocator.h" @@ -53,9 +54,11 @@ #if defined(OS_GENERIC) static const char *CONFIG_FILE_PATH = "bt_config.conf"; static const char *CONFIG_BACKUP_PATH = "bt_config.bak"; +static const char *CONFIG_LEGACY_FILE_PATH = "bt_config.xml"; #else // !defined(OS_GENERIC) static const char *CONFIG_FILE_PATH = "/data/misc/bluedroid/bt_config.conf"; static const char *CONFIG_BACKUP_PATH = "/data/misc/bluedroid/bt_config.bak"; +static const char *CONFIG_LEGACY_FILE_PATH = "/data/misc/bluedroid/bt_config.xml"; #endif // defined(OS_GENERIC) static const period_ms_t CONFIG_SETTLE_PERIOD_MS = 3000; @@ -69,6 +72,7 @@ static enum ConfigSource { NOT_LOADED, ORIGINAL, BACKUP, + LEGACY, NEW_FILE, RESET } btif_config_source = NOT_LOADED; @@ -127,19 +131,24 @@ static future_t *init(void) { config = config_new(CONFIG_FILE_PATH); btif_config_source = ORIGINAL; if (!config) { - LOG_WARN(LOG_TAG, "%s unable to load config file: %s; using backup.", + LOG_WARN("%s unable to load config file: %s; using backup.", __func__, CONFIG_FILE_PATH); config = config_new(CONFIG_BACKUP_PATH); btif_config_source = BACKUP; - if (!config) { - LOG_ERROR(LOG_TAG, "%s unable to load backup; creating empty config.", __func__); - config = config_new_empty(); - btif_config_source = NEW_FILE; - if (!config) { - LOG_ERROR(LOG_TAG, "%s unable to allocate a config object.", __func__); - goto error; - } - } + } + if (!config) { + LOG_WARN("%s unable to load backup; attempting to transcode legacy file.", __func__); + config = btif_config_transcode(CONFIG_LEGACY_FILE_PATH); + btif_config_source = LEGACY; + } + if (!config) { + LOG_ERROR("%s unable to transcode legacy file; creating empty config.", __func__); + config = config_new_empty(); + btif_config_source = NEW_FILE; + } + if (!config) { + LOG_ERROR("%s unable to allocate a config object.", __func__); + goto error; } btif_config_devcache_cleanup(); @@ -161,6 +170,7 @@ error: pthread_mutex_destroy(&lock); config_timer = NULL; config = NULL; + btif_config_source = NOT_LOADED; return future_new_immediate(FUTURE_FAIL); } @@ -487,6 +497,9 @@ void btif_debug_config_dump(int fd) { case BACKUP: dprintf(fd, "Backup file\n"); break; + case LEGACY: + dprintf(fd, "Legacy file\n"); + break; case NEW_FILE: dprintf(fd, "New file\n"); break; diff --git a/system/btif/src/btif_config_transcode.cpp b/system/btif/src/btif_config_transcode.cpp new file mode 100644 index 0000000000..e9d859eedd --- /dev/null +++ b/system/btif/src/btif_config_transcode.cpp @@ -0,0 +1,62 @@ +/****************************************************************************** + * + * Copyright (C) 2014 Google, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#define LOG_TAG "bt_btif_config_transcode" + +#include <tinyxml2.h> + +extern "C" { +#include "osi/include/config.h" +#include "osi/include/log.h" +} + +using namespace tinyxml2; + +extern "C" config_t *btif_config_transcode(const char *xml_filename) { + XMLDocument document; + int error = document.LoadFile(xml_filename); + if (error != XML_SUCCESS) { + LOG_ERROR("%s unable to load XML file '%s': %d", __func__, xml_filename, error); + return NULL; + } + + XMLElement *rootElement = document.RootElement(); + if (!rootElement) { + LOG_ERROR("%s unable to find root element; assuming corrupted config file.", __func__); + return NULL; + } + + config_t *config = config_new_empty(); + if (!config) { + LOG_ERROR("%s unable to allocate config object.", __func__); + return NULL; + } + + for (XMLElement *i = rootElement->FirstChildElement(); i != NULL; i = i->NextSiblingElement()) + for (XMLElement *j = i->FirstChildElement(); j != NULL; j = j->NextSiblingElement()) { + const char *section = j->Attribute("Tag"); + for (XMLElement *k = j->FirstChildElement(); k != NULL; k = k->NextSiblingElement()) { + const char *key = k->Attribute("Tag"); + const char *value = k->GetText(); + if (section && key && value) + config_set_string(config, section, key, value); + } + } + + return config; +} diff --git a/system/doc/style_guide.md b/system/doc/style_guide.md index c424a27429..9a83206458 100644 --- a/system/doc/style_guide.md +++ b/system/doc/style_guide.md @@ -70,7 +70,9 @@ the `2^n` build configurations is untenable for `n` greater than, say, 4. Although C++ offers constructs that may make Fluoride development faster, safer, more pleasant, etc. the decision _for the time being_ is to stick with pure C99. The exceptions are when linking against libraries that are written -in C++. At the time of writing the library used is `gtest`, +in C++. At the time of writing these libraries are `gtest` and `tinyxml2`, +where the latter is a dependency that should be eliminated in favor of simpler, +non-XML formats. ### Variadic functions Variadic functions are dangerous and should be avoided for most code. The diff --git a/system/main/Android.mk b/system/main/Android.mk index 303f395424..7fb545e4ad 100644 --- a/system/main/Android.mk +++ b/system/main/Android.mk @@ -52,6 +52,7 @@ LOCAL_C_INCLUDES+= . \ $(LOCAL_PATH)/../audio_a2dp_hw \ $(LOCAL_PATH)/../utils/include \ $(bluetooth_C_INCLUDES) \ + external/tinyxml2 \ external/zlib LOCAL_SHARED_LIBRARIES := \ @@ -66,6 +67,7 @@ LOCAL_SHARED_LIBRARIES := \ libchrome LOCAL_STATIC_LIBRARIES := \ + libtinyxml2 \ libbt-qcom_sbc_decoder LOCAL_WHOLE_STATIC_LIBRARIES := \ diff --git a/system/main/BUILD.gn b/system/main/BUILD.gn index d7d0790c53..05bcb6f895 100644 --- a/system/main/BUILD.gn +++ b/system/main/BUILD.gn @@ -66,6 +66,7 @@ shared_library("bluetooth.default") { "//hci", "//osi", "//stack", + "//third_party/tinyxml2", "//udrv", "//utils", ] |