aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bta/av/bta_av_aact.c13
-rw-r--r--bta/av/bta_av_act.c10
-rw-r--r--bta/hf_client/bta_hf_client_main.c20
-rw-r--r--btif/src/btif_core.c31
-rw-r--r--btif/src/btif_dm.c48
-rw-r--r--btif/src/btif_hf_client.c29
-rw-r--r--btif/src/btif_rc.c14
-rw-r--r--build/BUILD.gn1
-rw-r--r--hci/src/hci_layer.c12
-rw-r--r--osi/Android.mk8
-rw-r--r--osi/BUILD.gn2
-rw-r--r--osi/include/properties.h37
-rw-r--r--osi/src/properties.c48
-rw-r--r--osi/src/wakelock.c1
-rw-r--r--osi/test/properties_test.cpp43
-rw-r--r--utils/src/bt_utils.c15
-rw-r--r--vendor_libs/linux/bt_vendor_linux.c13
17 files changed, 170 insertions, 175 deletions
diff --git a/bta/av/bta_av_aact.c b/bta/av/bta_av_aact.c
index fce185121..007e9b558 100644
--- a/bta/av/bta_av_aact.c
+++ b/bta/av/bta_av_aact.c
@@ -30,14 +30,13 @@
#include <assert.h>
#include <string.h>
-#include <cutils/properties.h>
-
-#include "bta_av_int.h"
#include "avdt_api.h"
-#include "utl.h"
-#include "l2c_api.h"
-#include "l2cdefs.h"
+#include "bta_av_int.h"
#include "bt_utils.h"
+#include "l2cdefs.h"
+#include "l2c_api.h"
+#include "osi/include/properties.h"
+#include "utl.h"
#include "vendor.h"
#if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE)
@@ -1438,7 +1437,7 @@ void bta_av_str_opened (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
// This code is used to pass PTS TC for AVDTP ABORT
char value[PROPERTY_VALUE_MAX] = {0};
- if ((property_get("bluetooth.pts.force_a2dp_abort", value, "false"))
+ if ((osi_property_get("bluetooth.pts.force_a2dp_abort", value, "false"))
&& (!strcmp(value, "true")))
{
APPL_TRACE_ERROR ("%s: Calling AVDT_AbortReq", __func__);
diff --git a/bta/av/bta_av_act.c b/bta/av/bta_av_act.c
index baaf0199d..160eae447 100644
--- a/bta/av/bta_av_act.c
+++ b/bta/av/bta_av_act.c
@@ -36,19 +36,15 @@
#include "bta_av_int.h"
#include "l2c_api.h"
#include "osi/include/list.h"
+#include "osi/include/log.h"
#include "osi/include/osi.h"
+#include "osi/include/properties.h"
#include "utl.h"
#if ( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE)
#include "bta_ar_api.h"
#endif
-#include "osi/include/log.h"
-
-#if (AVRC_CTLR_INCLUDED == TRUE)
-#include <cutils/properties.h>
-#endif
-
/*****************************************************************************
** Constants
*****************************************************************************/
@@ -892,7 +888,7 @@ void bta_av_rc_msg(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
{
/* check if operation is supported */
char avrcp_ct_support[PROPERTY_VALUE_MAX];
- property_get("bluetooth.pts.avrcp_ct.support", avrcp_ct_support, "false");
+ osi_property_get("bluetooth.pts.avrcp_ct.support", avrcp_ct_support, "false");
if (p_data->rc_msg.msg.pass.op_id == AVRC_ID_VENDOR)
{
p_data->rc_msg.msg.hdr.ctype = BTA_AV_RSP_NOT_IMPL;
diff --git a/bta/hf_client/bta_hf_client_main.c b/bta/hf_client/bta_hf_client_main.c
index b5314b352..5df418bb4 100644
--- a/bta/hf_client/bta_hf_client_main.c
+++ b/bta/hf_client/bta_hf_client_main.c
@@ -20,14 +20,8 @@
#include <string.h>
#include <stdlib.h>
-// TODO(armansito): cutils/properties.h is only being used to pull-in runtime
-// settings on Android. Remove this conditional include once we have a generic
-// way to obtain system properties.
-#if !defined(OS_GENERIC)
-#include <cutils/properties.h>
-#endif // !defined(OS_GENERIC)
-
#include "osi/include/osi.h"
+#include "osi/include/properties.h"
#include "bt_utils.h"
#include "bta_api.h"
#include "bta_sys.h"
@@ -384,12 +378,7 @@ void bta_hf_client_collision_cback (tBTA_SYS_CONN_STATUS status, UINT8 id,
*******************************************************************************/
static void bta_hf_client_api_enable(tBTA_HF_CLIENT_DATA *p_data)
{
- // TODO(armansito): For non-Android systems we need a common method of
- // loading system properties. Remove the conditionally compiled code once we
- // have that in place.
-#if !defined(OS_GENERIC)
char value[PROPERTY_VALUE_MAX];
-#endif // !defined(OS_GENERIC)
/* initialize control block */
memset(&bta_hf_client_cb, 0, sizeof(tBTA_HF_CLIENT_CB));
@@ -397,17 +386,12 @@ static void bta_hf_client_api_enable(tBTA_HF_CLIENT_DATA *p_data)
/* store callback function */
bta_hf_client_cb.p_cback = p_data->api_enable.p_cback;
- // TODO(armansito): For non-Android systems we need a common method of
- // loading system properties. Remove the conditionally compiled code once we
- // have that in place.
-#if !defined(OS_GENERIC)
/* check if mSBC support enabled */
- property_get("ro.bluetooth.hfp.ver", value, "0");
+ osi_property_get("ro.bluetooth.hfp.ver", value, "0");
if (strcmp(value,"1.6") == 0)
{
bta_hf_client_cb.msbc_enabled = TRUE;
}
-#endif // !defined(OS_GENERIC)
bta_hf_client_cb.scb.negotiated_codec = BTM_SCO_CODEC_CVSD;
diff --git a/btif/src/btif_core.c b/btif/src/btif_core.c
index a162ca45f..5415f1a77 100644
--- a/btif/src/btif_core.c
+++ b/btif/src/btif_core.c
@@ -38,15 +38,6 @@
#include <sys/types.h>
#include <unistd.h>
-/**
- * TODO(armansito): On OSs other than Android, the sys/properties.h system
- * does not exist. Remove this conditional include once we have a generic way
- * to obtain system properties.
- */
-#if !defined(OS_GENERIC)
-#include <cutils/properties.h>
-#endif /* !defined(OS_GENERIC) */
-
#include "bdaddr.h"
#include "bt_utils.h"
#include "bta_api.h"
@@ -68,6 +59,7 @@
#include "osi/include/future.h"
#include "osi/include/log.h"
#include "osi/include/osi.h"
+#include "osi/include/properties.h"
#include "osi/include/thread.h"
#include "stack_manager.h"
@@ -326,7 +318,7 @@ void btif_thread_post(thread_fn func, void *context) {
static bool btif_fetch_property(const char *key, bt_bdaddr_t *addr) {
char val[PROPERTY_VALUE_MAX] = {0};
- if (property_get(key, val, NULL)) {
+ if (osi_property_get(key, val, NULL)) {
if (string_to_bdaddr(val, addr)) {
BTIF_TRACE_DEBUG("%s: Got BDA %s", __func__, val);
return TRUE;
@@ -342,16 +334,10 @@ static void btif_fetch_local_bdaddr(bt_bdaddr_t *local_addr)
uint8_t valid_bda = FALSE;
int val_size = 0;
- /**
- * TODO(armansito): On OSs other than Android, the sys/properties.h system
- * does not exist. Remove this conditional include once we have a generic way
- * to obtain system properties.
- */
-#if !defined(OS_GENERIC)
const uint8_t null_bdaddr[BD_ADDR_LEN] = {0,0,0,0,0,0};
/* Get local bdaddr storage path from property */
- if (property_get(PROPERTY_BT_BDADDR_PATH, val, NULL))
+ if (osi_property_get(PROPERTY_BT_BDADDR_PATH, val, NULL))
{
int addr_fd;
@@ -392,7 +378,6 @@ static void btif_fetch_local_bdaddr(bt_bdaddr_t *local_addr)
if (!valid_bda) {
valid_bda = btif_fetch_property(FACTORY_BT_ADDR_PROPERTY, local_addr);
}
-#endif /* !defined(OS_GENERIC) */
/* Generate new BDA if necessary */
if (!valid_bda)
@@ -415,16 +400,8 @@ static void btif_fetch_local_bdaddr(bt_bdaddr_t *local_addr)
BTIF_TRACE_DEBUG("No preset BDA. Generating BDA: %s for prop %s",
(char*)bdstr, PERSIST_BDADDR_PROPERTY);
-
- /**
- * TODO(armansito): On OSs other than Android, the sys/properties.h system
- * does not exist. Remove this conditional include once we have a generic way
- * to obtain system properties.
- */
-#if !defined(OS_GENERIC)
- if (property_set(PERSIST_BDADDR_PROPERTY, (char*)bdstr) < 0)
+ if (osi_property_set(PERSIST_BDADDR_PROPERTY, (char*)bdstr) < 0)
BTIF_TRACE_ERROR("Failed to set random BDA in prop %s",PERSIST_BDADDR_PROPERTY);
-#endif /* !defined(OS_GENERIC) */
}
//save the bd address to config file
diff --git a/btif/src/btif_dm.c b/btif/src/btif_dm.c
index 2aceb6ea7..3a2430ebe 100644
--- a/btif/src/btif_dm.c
+++ b/btif/src/btif_dm.c
@@ -41,15 +41,6 @@
#include <hardware/bluetooth.h>
-/**
- * TODO(armansito): cutils/properties.h is only being used to pull-in runtime
- * settings on Android. Remove this conditional include once we have a generic
- * way to obtain system properties.
- */
-#if !defined(OS_GENERIC)
-#include <cutils/properties.h>
-#endif /* !defined(OS_GENERIC) */
-
#include "bdaddr.h"
#include "bta_gatt_api.h"
#include "btif_api.h"
@@ -66,6 +57,7 @@
#include "osi/include/allocator.h"
#include "osi/include/log.h"
#include "osi/include/metrics.h"
+#include "osi/include/properties.h"
#include "stack_config.h"
#include "stack/btm/btm_int.h"
@@ -2863,14 +2855,8 @@ void btif_dm_set_oob_for_le_io_req(BD_ADDR bd_addr, tBTA_OOB_DATA *p_has_oob_da
#ifdef BTIF_DM_OOB_TEST
void btif_dm_load_local_oob(void)
{
- /**
- * TODO(armansito): On OSs other than Android, the sys/properties.h system
- * does not exist. Remove this conditional include once we have a generic way
- * to obtain system properties.
- */
-#if !defined(OS_GENERIC)
char prop_oob[PROPERTY_VALUE_MAX];
- property_get("service.brcm.bt.oob", prop_oob, "3");
+ osi_property_get("service.brcm.bt.oob", prop_oob, "3");
BTIF_TRACE_DEBUG("%s: prop_oob = %s", __func__, prop_oob);
if (prop_oob[0] != '3')
{
@@ -2880,17 +2866,10 @@ void btif_dm_load_local_oob(void)
BTA_DmLocalOob();
}
}
-#endif /* !defined(OS_GENERIC) */
}
void btif_dm_proc_loc_oob(BOOLEAN valid, BT_OCTET16 c, BT_OCTET16 r)
{
- /**
- * TODO(armansito): On OSs other than Android, the sys/properties.h system
- * does not exist. Remove this conditional include once we have a generic way
- * to obtain system properties.
- */
-#if !defined(OS_GENERIC)
FILE *fp;
char *path_a = "/data/misc/bluedroid/LOCAL/a.key";
char *path_b = "/data/misc/bluedroid/LOCAL/b.key";
@@ -2902,7 +2881,7 @@ void btif_dm_proc_loc_oob(BOOLEAN valid, BT_OCTET16 c, BT_OCTET16 r)
BTIF_TRACE_DEBUG("save local OOB data in memory");
memcpy(oob_cb.oob_data.c192, c, BT_OCTET16_LEN);
memcpy(oob_cb.oob_data.r192, r, BT_OCTET16_LEN);
- property_get("service.brcm.bt.oob", prop_oob, "3");
+ osi_property_get("service.brcm.bt.oob", prop_oob, "3");
BTIF_TRACE_DEBUG("%s: prop_oob = %s", __func__, prop_oob);
if (prop_oob[0] == '1')
path = path_a;
@@ -2924,17 +2903,10 @@ void btif_dm_proc_loc_oob(BOOLEAN valid, BT_OCTET16 c, BT_OCTET16 r)
}
}
}
-#endif /* !defined(OS_GENERIC) */
}
BOOLEAN btif_dm_proc_rmt_oob(BD_ADDR bd_addr, BT_OCTET16 p_c, BT_OCTET16 p_r)
{
- /**
- * TODO(armansito): On OSs other than Android, the sys/properties.h system
- * does not exist. Remove this conditional include once we have a generic way
- * to obtain system properties.
- */
-#if !defined(OS_GENERIC)
char t[128];
FILE *fp;
char *path_a = "/data/misc/bluedroid/LOCAL/a.key";
@@ -2944,7 +2916,7 @@ BOOLEAN btif_dm_proc_rmt_oob(BD_ADDR bd_addr, BT_OCTET16 p_c, BT_OCTET16 p_r)
BOOLEAN result = FALSE;
bt_bdaddr_t bt_bd_addr;
bdcpy(oob_cb.bdaddr, bd_addr);
- property_get("service.brcm.bt.oob", prop_oob, "3");
+ osi_property_get("service.brcm.bt.oob", prop_oob, "3");
BTIF_TRACE_DEBUG("%s: prop_oob = %s", __func__, prop_oob);
if (prop_oob[0] == '1')
path = path_b;
@@ -2985,9 +2957,6 @@ BOOLEAN btif_dm_proc_rmt_oob(BD_ADDR bd_addr, BT_OCTET16 p_c, BT_OCTET16 p_r)
}
BTIF_TRACE_DEBUG("%s: result=%d", __func__, result);
return result;
-#else /* defined(OS_GENERIC) */
- return FALSE;
-#endif /* !defined(OS_GENERIC) */
}
#endif /* BTIF_DM_OOB_TEST */
#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
@@ -3426,12 +3395,6 @@ void btif_dm_read_energy_info()
}
static char* btif_get_default_local_name() {
- /**
- * TODO(armansito): On OSs other than Android, the sys/properties.h system
- * does not exist. Remove this conditional include once we have a generic way
- * to obtain system properties.
- */
-#if !defined(OS_GENERIC)
if (btif_default_local_name[0] == '\0')
{
int max_len = sizeof(btif_default_local_name) - 1;
@@ -3442,12 +3405,11 @@ static char* btif_get_default_local_name() {
else
{
char prop_model[PROPERTY_VALUE_MAX];
- property_get(PROPERTY_PRODUCT_MODEL, prop_model, "");
+ osi_property_get(PROPERTY_PRODUCT_MODEL, prop_model, "");
strncpy(btif_default_local_name, prop_model, max_len);
}
btif_default_local_name[max_len] = '\0';
}
-#endif /* !defined(OS_GENERIC) */
return btif_default_local_name;
}
diff --git a/btif/src/btif_hf_client.c b/btif/src/btif_hf_client.c
index 04190132d..5458dac21 100644
--- a/btif/src/btif_hf_client.c
+++ b/btif/src/btif_hf_client.c
@@ -34,21 +34,13 @@
#include <hardware/bluetooth.h>
#include <hardware/bt_hf_client.h>
-/**
- * TODO(armansito): On OSs other than Android, the sys/properties.h system
- * does not exist. Remove this conditional include once we have a generic way
- * to obtain system properties.
- */
-#if !defined(OS_GENERIC)
-#include <cutils/properties.h>
-#endif /* !defined(OS_GENERIC) */
-
#include "bt_utils.h"
#include "bta_hf_client_api.h"
#include "btcore/include/bdaddr.h"
#include "btif_common.h"
#include "btif_profile_queue.h"
#include "btif_util.h"
+#include "osi/include/properties.h"
/************************************************************************************
** Constants & Macros
@@ -83,17 +75,7 @@
static bthf_client_callbacks_t *bt_hf_client_callbacks = NULL;
static UINT32 btif_hf_client_features = 0;
-/**
- * TODO(armansito): On OSs other than Android, the sys/properties.h system
- * does not exist. Since that is how the HFP version is currently obtained, on
- * systems other than Android, hardcode 1.5 as the profile version for now,
- * until there is a generic way to obtain these configuration properties.
- */
-#if defined(OS_GENERIC)
-const char btif_hf_client_version[] = "1.5";
-#else /* !defined(OS_GENERIC) */
char btif_hf_client_version[PROPERTY_VALUE_MAX];
-#endif /* defined(OS_GENERIC) */
#define CHECK_BTHF_CLIENT_INIT() if (bt_hf_client_callbacks == NULL)\
{\
@@ -956,14 +938,7 @@ bt_status_t btif_hf_client_execute_service(BOOLEAN b_enable)
{
BTIF_TRACE_EVENT("%s enable:%d", __FUNCTION__, b_enable);
-/**
- * TODO(armansito): On OSs other than Android, the sys/properties.h system
- * does not exist. Since that is how the HFP version is currently obtained, on
- * systems other than Android we're hardcoding the version to 1.5 above.
- */
-#if !defined(OS_GENERIC)
- property_get("ro.bluetooth.hfp.ver", btif_hf_client_version, "1.5");
-#endif /* !defined(OS_GENERIC) */
+ osi_property_get("ro.bluetooth.hfp.ver", btif_hf_client_version, "1.5");
if (b_enable)
{
diff --git a/btif/src/btif_rc.c b/btif/src/btif_rc.c
index 95beec3aa..7bb24c757 100644
--- a/btif/src/btif_rc.c
+++ b/btif/src/btif_rc.c
@@ -34,15 +34,6 @@
#include <hardware/bluetooth.h>
#include <hardware/bt_rc.h>
-/**
- * TODO(eisenbach): cutils/properties.h is only being used to pull-in runtime
- * settings on Android. Remove this conditional include once we have a generic
- * way to obtain system properties.
- */
-#if !defined(OS_GENERIC)
-#include <cutils/properties.h>
-#endif /* !defined(OS_GENERIC) */
-
#include "avrc_defs.h"
#include "bta_api.h"
#include "bta_av_api.h"
@@ -53,6 +44,7 @@
#include "device/include/interop.h"
#include "uinput.h"
#include "osi/include/list.h"
+#include "osi/include/properties.h"
#include "btu.h"
#define RC_INVALID_TRACK_ID (0xFFFFFFFFFFFFFFFFULL)
/*****************************************************************************
@@ -4245,13 +4237,11 @@ static void sleep_ms(period_ms_t timeout_ms) {
}
static bool absolute_volume_disabled() {
-#if !defined(OS_GENERIC)
char volume_disabled[PROPERTY_VALUE_MAX] = {0};
- property_get("persist.bluetooth.disableabsvol", volume_disabled, "false");
+ osi_property_get("persist.bluetooth.disableabsvol", volume_disabled, "false");
if (strncmp(volume_disabled, "true", 4) == 0) {
BTIF_TRACE_WARNING("%s: Absolute volume disabled by property", __func__);
return true;
}
-#endif /* !defined(OS_GENERIC) */
return false;
}
diff --git a/build/BUILD.gn b/build/BUILD.gn
index eae173727..151869dd3 100644
--- a/build/BUILD.gn
+++ b/build/BUILD.gn
@@ -65,7 +65,6 @@ config("linux") {
"HAS_NO_BDROID_BUILDCFG",
"LOG_NDEBUG=1",
"EXPORT_SYMBOL=__attribute__((visibility(\"default\")))",
- "PROPERTY_VALUE_MAX=256",
"KERNEL_MISSING_CLOCK_BOOTTIME_ALARM=TRUE",
# This is a macro to that can be used by source code to detect if the
diff --git a/hci/src/hci_layer.c b/hci/src/hci_layer.c
index 9ec77d3ec..b169b031d 100644
--- a/hci/src/hci_layer.c
+++ b/hci/src/hci_layer.c
@@ -27,13 +27,6 @@
#include <sys/types.h>
#include <unistd.h>
-// TODO(armansito): cutils/properties.h is only being used to pull-in runtime
-// settings on Android. Remove this conditional include once we have a generic
-// way to obtain system properties.
-#if !defined(OS_GENERIC)
-#include <cutils/properties.h>
-#endif // !defined(OS_GENERIC)
-
#include "btcore/include/module.h"
#include "btsnoop.h"
#include "buffer_allocator.h"
@@ -46,6 +39,7 @@
#include "osi/include/alarm.h"
#include "osi/include/list.h"
#include "osi/include/log.h"
+#include "osi/include/properties.h"
#include "osi/include/reactor.h"
#include "packet_fragmenter.h"
#include "vendor.h"
@@ -187,13 +181,11 @@ static future_t *start_up(void) {
// non-Android builds.
period_ms_t startup_timeout_ms = DEFAULT_STARTUP_TIMEOUT_MS;
-#if !defined(OS_GENERIC)
// Grab the override startup timeout ms, if present.
char timeout_prop[PROPERTY_VALUE_MAX];
- if (!property_get("bluetooth.enable_timeout_ms", timeout_prop, STRING_VALUE_OF(DEFAULT_STARTUP_TIMEOUT_MS))
+ if (!osi_property_get("bluetooth.enable_timeout_ms", timeout_prop, STRING_VALUE_OF(DEFAULT_STARTUP_TIMEOUT_MS))
|| (startup_timeout_ms = atoi(timeout_prop)) < 100)
startup_timeout_ms = DEFAULT_STARTUP_TIMEOUT_MS;
-#endif // !defined(OS_GENERIC)
startup_timer = alarm_new("hci.startup_timer");
if (!startup_timer) {
diff --git a/osi/Android.mk b/osi/Android.mk
index e6af855dc..e3d8043e0 100644
--- a/osi/Android.mk
+++ b/osi/Android.mk
@@ -41,6 +41,7 @@ btosiCommonSrc := \
./src/list.c \
./src/metrics.cpp \
./src/mutex.c \
+ ./src/properties.c \
./src/reactor.c \
./src/ringbuffer.c \
./src/semaphore.c \
@@ -66,6 +67,7 @@ btosiCommonTestSrc := \
./test/hash_map_test.cpp \
./test/hash_map_utils_test.cpp \
./test/list_test.cpp \
+ ./test/properties_test.cpp \
./test/reactor_test.cpp \
./test/ringbuffer_test.cpp \
./test/semaphore_test.cpp \
@@ -142,7 +144,7 @@ LOCAL_MODULE_CLASS := STATIC_LIBRARIES
# TODO(armansito): Setting _GNU_SOURCE isn't very platform-independent but
# should be compatible for a Linux host OS. We should figure out what to do for
# a non-Linux host OS.
-LOCAL_CFLAGS += $(bluetooth_CFLAGS) -D_GNU_SOURCE
+LOCAL_CFLAGS += $(bluetooth_CFLAGS) -D_GNU_SOURCE -DOS_GENERIC
LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
@@ -160,7 +162,7 @@ LOCAL_C_INCLUDES := $(btosiCommonIncludes)
LOCAL_SRC_FILES := $(btosiCommonTestSrc)
LOCAL_MODULE := net_test_osi
LOCAL_MODULE_TAGS := tests
-LOCAL_SHARED_LIBRARIES := liblog libprotobuf-cpp-full libchrome
+LOCAL_SHARED_LIBRARIES := libc liblog libprotobuf-cpp-full libchrome libcutils
LOCAL_STATIC_LIBRARIES := libosi libbt-protos
LOCAL_CFLAGS += $(bluetooth_CFLAGS)
@@ -181,7 +183,7 @@ LOCAL_MODULE_TAGS := tests
LOCAL_SHARED_LIBRARIES := liblog libprotobuf-cpp-full libchrome
LOCAL_STATIC_LIBRARIES := libosi-host libbt-protos
-LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CFLAGS += $(bluetooth_CFLAGS) -DOS_GENERIC
LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
diff --git a/osi/BUILD.gn b/osi/BUILD.gn
index a52647a51..88cdbdd92 100644
--- a/osi/BUILD.gn
+++ b/osi/BUILD.gn
@@ -33,6 +33,7 @@ static_library("osi") {
"src/list.c",
"src/metrics_linux.cpp",
"src/mutex.c",
+ "src/properties.c",
"src/reactor.c",
"src/ringbuffer.c",
"src/semaphore.c",
@@ -70,6 +71,7 @@ executable("net_test_osi") {
"test/hash_map_test.cpp",
"test/hash_map_utils_test.cpp",
"test/list_test.cpp",
+ "test/properties_test.cpp",
"test/reactor_test.cpp",
"test/ringbuffer_test.cpp",
"test/thread_test.cpp",
diff --git a/osi/include/properties.h b/osi/include/properties.h
new file mode 100644
index 000000000..bb3e61db3
--- /dev/null
+++ b/osi/include/properties.h
@@ -0,0 +1,37 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2016 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
+
+#if defined(OS_GENERIC)
+#define PROPERTY_VALUE_MAX 92
+#else
+#include <cutils/properties.h>
+#endif // defined(OS_GENERIC)
+
+// Get value associated with key |key| into |value|.
+// Returns the length of the value which will never be greater than
+// PROPERTY_VALUE_MAX - 1 and will always be zero terminated.
+// (the length does not include the terminating zero).
+// If the property read fails or returns an empty value, the |default_value|
+// is used (if nonnull).
+int osi_property_get(const char *key, char *value, const char *default_value);
+
+// Write value of property associated with key |key| to |value|.
+// Returns 0 on success, < 0 on failure
+int osi_property_set(const char *key, const char *value);
diff --git a/osi/src/properties.c b/osi/src/properties.c
new file mode 100644
index 000000000..7fddfffe2
--- /dev/null
+++ b/osi/src/properties.c
@@ -0,0 +1,48 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2016 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.
+ *
+ ******************************************************************************/
+
+#include <string.h>
+
+#include "osi/include/properties.h"
+
+int osi_property_get(const char *key, char *value, const char *default_value) {
+#if defined(OS_GENERIC)
+ /* For linux right now just return default value, if present */
+ int len = -1;
+ if (!default_value)
+ return len;
+
+ len = strlen(default_value);
+ if (len >= PROPERTY_VALUE_MAX)
+ len = PROPERTY_VALUE_MAX - 1;
+
+ memcpy(value, default_value, len);
+ value[len] = '\0';
+ return len;
+#else
+ return property_get(key, value, default_value);
+#endif // defined(OS_GENERIC)
+}
+
+int osi_property_set(const char *key, const char *value) {
+#if defined(OS_GENERIC)
+ return -1;
+#else
+ return property_set(key, value);
+#endif // defined(OS_GENERIC)
+} \ No newline at end of file
diff --git a/osi/src/wakelock.c b/osi/src/wakelock.c
index bb4709b29..527ce4b26 100644
--- a/osi/src/wakelock.c
+++ b/osi/src/wakelock.c
@@ -29,6 +29,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
+#include <unistd.h>
#include "osi/include/alarm.h"
#include "osi/include/allocator.h"
diff --git a/osi/test/properties_test.cpp b/osi/test/properties_test.cpp
new file mode 100644
index 000000000..3d2752610
--- /dev/null
+++ b/osi/test/properties_test.cpp
@@ -0,0 +1,43 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2016 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.
+ *
+ ******************************************************************************/
+
+#include <gtest/gtest.h>
+
+#include "AllocationTestHarness.h"
+
+extern "C" {
+#include "osi/include/properties.h"
+}
+
+class PropertiesTest : public AllocationTestHarness {};
+
+TEST_F(PropertiesTest, test_default_value) {
+ char value[PROPERTY_VALUE_MAX] = {0};
+ osi_property_get("very.useful.test", value, "very_useful_value");
+ ASSERT_STREQ(value, "very_useful_value");
+}
+
+TEST_F(PropertiesTest, test_successfull_set_and_get_value) {
+ char value[PROPERTY_VALUE_MAX] = "nothing_interesting";
+ int ret = osi_property_set("very.useful.set.test", value);
+ ASSERT_EQ(0, ret);
+
+ char received[PROPERTY_VALUE_MAX];
+ osi_property_get("very.useful.set.test", received, NULL);
+ ASSERT_STREQ(received, "nothing_interesting");
+}
diff --git a/utils/src/bt_utils.c b/utils/src/bt_utils.c
index 6bc429b6c..2c3422a9f 100644
--- a/utils/src/bt_utils.c
+++ b/utils/src/bt_utils.c
@@ -39,17 +39,11 @@
#include <utils/ThreadDefs.h>
#include <cutils/sched_policy.h>
-// TODO(armansito): cutils/properties.h is only being used to pull-in runtime
-// settings on Android. Remove this conditional include once we have a generic
-// way to obtain system properties.
-#if !defined(OS_GENERIC)
-#include <cutils/properties.h>
-#endif // !defined(OS_GENERIC)
-
#include "bt_types.h"
#include "btcore/include/module.h"
#include "osi/include/compat.h"
#include "osi/include/log.h"
+#include "osi/include/properties.h"
/*******************************************************************************
** Type definitions for callback functions
@@ -92,10 +86,6 @@ EXPORT_SYMBOL const module_t bt_utils_module = {
}
};
-// TODO(armansito): Remove this conditional code once there is a generic way
-// to obtain system properties. System properties are only available on
-// Android. Don't do the following check if this is a generic build.
-#if !defined(OS_GENERIC)
/*****************************************************************************
**
** Function check_do_scheduling_group
@@ -107,7 +97,7 @@ EXPORT_SYMBOL const module_t bt_utils_module = {
*******************************************************************************/
static void check_do_scheduling_group(void) {
char buf[PROPERTY_VALUE_MAX];
- int len = property_get("debug.sys.noschedgroups", buf, "");
+ int len = osi_property_get("debug.sys.noschedgroups", buf, "");
if (len > 0) {
int temp;
if (sscanf(buf, "%d", &temp) == 1) {
@@ -115,7 +105,6 @@ static void check_do_scheduling_group(void) {
}
}
}
-#endif // !defined(OS_GENERIC)
/*****************************************************************************
**
diff --git a/vendor_libs/linux/bt_vendor_linux.c b/vendor_libs/linux/bt_vendor_linux.c
index be4fa7c2b..c6cd6123c 100644
--- a/vendor_libs/linux/bt_vendor_linux.c
+++ b/vendor_libs/linux/bt_vendor_linux.c
@@ -29,10 +29,9 @@
#include <sys/socket.h>
#include <sys/ioctl.h>
-#include <cutils/properties.h>
-
#include "hci/include/bt_vendor_lib.h"
#include "osi/include/log.h"
+#include "osi/include/properties.h"
#define BTPROTO_HCI 1
#define HCI_CHANNEL_USER 1
@@ -101,7 +100,7 @@ static int bt_vendor_init(const bt_vendor_callbacks_t *p_cb,
memcpy(bt_vendor_local_bdaddr, local_bdaddr,
sizeof(bt_vendor_local_bdaddr));
- property_get("bluetooth.interface", prop_value, "0");
+ osi_property_get("bluetooth.interface", prop_value, "0");
errno = 0;
if (memcmp(prop_value, "hci", 3))
@@ -113,13 +112,13 @@ static int bt_vendor_init(const bt_vendor_callbacks_t *p_cb,
LOG_INFO(LOG_TAG, "Using interface hci%d", hci_interface);
- property_get("bluetooth.rfkill", prop_value, "0");
+ osi_property_get("bluetooth.rfkill", prop_value, "0");
rfkill_en = atoi(prop_value);
if (rfkill_en)
LOG_INFO(LOG_TAG, "RFKILL enabled");
- bt_hwcfg_en = property_get("bluetooth.hwcfg",
+ bt_hwcfg_en = osi_property_get("bluetooth.hwcfg",
prop_value, NULL) > 0 ? 1 : 0;
if (bt_hwcfg_en)
LOG_INFO(LOG_TAG, "HWCFG enabled");
@@ -133,12 +132,12 @@ static int bt_vendor_hw_cfg(int stop)
return 0;
if (stop) {
- if (property_set("bluetooth.hwcfg", "stop") < 0) {
+ if (osi_property_set("bluetooth.hwcfg", "stop") < 0) {
LOG_ERROR(LOG_TAG, "%s cannot stop btcfg service via prop", __func__);
return 1;
}
} else {
- if (property_set("bluetooth.hwcfg", "start") < 0) {
+ if (osi_property_set("bluetooth.hwcfg", "start") < 0) {
LOG_ERROR(LOG_TAG, "%s cannot start btcfg service via prop", __func__);
return 1;
}