From 0ff83edff0c13fcea2a2a1b21365867fd01e098a Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Mon, 22 Sep 2014 16:30:13 +0200 Subject: [PATCH] android/hal: Add helper for quering config from Android properties Helper searches config in "persis.sys.bluetooth." and "ro.bluetooth." namespaces and allows to fallback to custom property if none is found. --- android/client/if-gatt.c | 2 ++ android/cutils/properties.h | 1 + android/hal-utils.c | 32 ++++++++++++++++++++++++++++++++ android/hal-utils.h | 2 ++ 4 files changed, 37 insertions(+) diff --git a/android/client/if-gatt.c b/android/client/if-gatt.c index 0ceffa692..f021a8b0c 100644 --- a/android/client/if-gatt.c +++ b/android/client/if-gatt.c @@ -15,6 +15,8 @@ * */ +#include + #include #include "../hal-utils.h" diff --git a/android/cutils/properties.h b/android/cutils/properties.h index 43f07f152..0163eb5cb 100644 --- a/android/cutils/properties.h +++ b/android/cutils/properties.h @@ -29,6 +29,7 @@ #include #define PROPERTY_VALUE_MAX 32 +#define PROPERTY_KEY_MAX 32 #define BLUETOOTH_MODE_PROPERTY_NAME "persist.sys.bluetooth.mode" #define BLUETOOTH_MODE_PROPERTY_HANDSFREE "persist.sys.bluetooth.handsfree" diff --git a/android/hal-utils.c b/android/hal-utils.c index 64ab5a1d9..0311b81c5 100644 --- a/android/hal-utils.c +++ b/android/hal-utils.c @@ -18,6 +18,9 @@ #include #include #include +#include + +#include #include "hal-utils.h" @@ -330,3 +333,32 @@ const char *btproperty2str(const bt_property_t *property) return buf; } + +#define PROP_PREFIX "persist.sys.bluetooth." +#define PROP_PREFIX_RO "ro.bluetooth." + +int get_config(const char *config_key, char *value, const char *fallback) +{ + char key[PROPERTY_KEY_MAX]; + int ret; + + if (strlen(config_key) + sizeof(PROP_PREFIX) >= sizeof(key)) + return 0; + + snprintf(key, sizeof(key), PROP_PREFIX"%s", config_key); + + ret = property_get(key, value, ""); + if (ret > 0) + return ret; + + snprintf(key, sizeof(key), PROP_PREFIX_RO"%s", config_key); + + ret = property_get(key, value, ""); + if (ret > 0) + return ret; + + if (!fallback) + return 0; + + return property_get(fallback, value, ""); +} diff --git a/android/hal-utils.h b/android/hal-utils.h index a0aab573e..a2ae0f48b 100644 --- a/android/hal-utils.h +++ b/android/hal-utils.h @@ -36,6 +36,8 @@ void str2bt_uuid_t(const char *str, bt_uuid_t *uuid); const char *btproperty2str(const bt_property_t *property); const char *bdaddr2str(const bt_bdaddr_t *bd_addr); +int get_config(const char *config_key, char *value, const char *fallback); + /* * Begin mapping section * -- 2.47.3