summaryrefslogtreecommitdiff
path: root/osi
diff options
context:
space:
mode:
authorJakub Pawlowski <jpawlowski@google.com>2016-02-24 10:39:46 -0800
committerAndre Eisenbach <eisenbach@google.com>2016-03-25 11:53:13 -0700
commit2998946db9b820806d4a3e6decf1d01f090a8031 (patch)
tree3645c0653bd0ac720784558af8c1770d43294485 /osi
parent41c155cbfd43c99fed14d3d9b7c277679ade69a5 (diff)
downloadandroid-system-bt-2998946db9b820806d4a3e6decf1d01f090a8031.tar.gz
android-system-bt-2998946db9b820806d4a3e6decf1d01f090a8031.tar.xz
Move properties get/set code to osi
Currently we use Android-specific property_get and property_set through the code. This patch adds osi_property_get and osi_property_set that is encapsulating all external dependencies. This is step further for errorless compilation on linux. Bug: 27324453 Change-Id: I97c34344617a5855b683328bcd196a21a2fae6f9
Diffstat (limited to 'osi')
-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
6 files changed, 136 insertions, 3 deletions
diff --git a/osi/Android.mk b/osi/Android.mk
index 3eda8cc..23b01f1 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 \
@@ -143,7 +145,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)
@@ -161,7 +163,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)
@@ -182,7 +184,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 a52647a..88cdbdd 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 0000000..bb3e61d
--- /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 0000000..7fddfff
--- /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 ba518eb..fc19cc4 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 0000000..3d27526
--- /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");
+}