Loading system/gd/Android.bp +5 −0 Original line number Original line Diff line number Diff line Loading @@ -121,6 +121,7 @@ cc_defaults { host: { host: { srcs: [ srcs: [ ":BluetoothHalSources_hci_rootcanal", ":BluetoothHalSources_hci_rootcanal", ":BluetoothOsSources_host", ], ], shared_libs: [ shared_libs: [ "libprotobuf-cpp-full", "libprotobuf-cpp-full", Loading @@ -129,11 +130,13 @@ cc_defaults { android: { android: { srcs: [ srcs: [ ":BluetoothHalSources_hci_android_hidl", ":BluetoothHalSources_hci_android_hidl", ":BluetoothOsSources_android", ], ], shared_libs: [ shared_libs: [ "android.hardware.bluetooth@1.0", "android.hardware.bluetooth@1.0", "libhidlbase", "libhidlbase", "libutils", "libutils", "libcutils", ], ], }, }, }, }, Loading Loading @@ -265,11 +268,13 @@ cc_test { android: { android: { srcs: [ srcs: [ ":BluetoothHalTestSources_hci_android_hidl", ":BluetoothHalTestSources_hci_android_hidl", ":BluetoothOsTestSources_android", ], ], shared_libs: [ shared_libs: [ "android.hardware.bluetooth@1.0", "android.hardware.bluetooth@1.0", "libhidlbase", "libhidlbase", "libutils", "libutils", "libcutils", ], ], }, }, }, }, Loading system/gd/os/Android.bp +21 −0 Original line number Original line Diff line number Diff line filegroup { name: "BluetoothOsSources_android", srcs: [ "android/system_properties.cc", ], } filegroup { name: "BluetoothOsTestSources_android", srcs: [ "android/system_properties_test.cc", ], } filegroup { name: "BluetoothOsSources_host", srcs: [ "host/system_properties.cc", ], } filegroup { filegroup { name: "BluetoothOsSources_linux_generic", name: "BluetoothOsSources_linux_generic", srcs: [ srcs: [ Loading system/gd/os/android/system_properties.cc 0 → 100644 +59 −0 Original line number Original line Diff line number Diff line /* * Copyright 2019 The Android Open Source Project * * 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 "os/system_properties.h" #include <cutils/properties.h> #include <array> #include "os/log.h" namespace bluetooth { namespace os { std::optional<std::string> GetSystemProperty(const std::string& property) { if (property.size() >= PROP_NAME_MAX) { LOG_ERROR("Property name's maximum size is %d, but %zu chars were given", PROP_NAME_MAX - 1, property.size()); return std::nullopt; } std::array<char, PROPERTY_VALUE_MAX> value_array{0}; auto value_len = property_get(property.c_str(), value_array.data(), nullptr); if (value_len <= 0) { return std::nullopt; } return std::string(value_array.data(), value_len); } bool SetSystemProperty(const std::string& property, const std::string& value) { if (property.size() >= PROP_NAME_MAX) { LOG_ERROR("Property name's maximum size is %d, but %zu chars were given", PROP_NAME_MAX - 1, property.size()); return false; } if (value.size() >= PROPERTY_VALUE_MAX) { LOG_ERROR("Property value's maximum size is %d, but %zu chars were given", PROPERTY_VALUE_MAX - 1, value.size()); return false; } auto ret = property_set(property.c_str(), value.c_str()); if (ret != 0) { LOG_ERROR("Set property %s failed with error code %d", property.c_str(), ret); return false; } return true; } } // namespace os } // namespace bluetooth No newline at end of file system/gd/os/android/system_properties_test.cc 0 → 100644 +57 −0 Original line number Original line Diff line number Diff line /* * Copyright 2019 The Android Open Source Project * * 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> #include <gtest/gtest.h> #include <cutils/properties.h> #include "os/system_properties.h" namespace testing { using bluetooth::os::GetSystemProperty; using bluetooth::os::SetSystemProperty; TEST(SystemPropertiesTest, set_and_get_test) { ASSERT_TRUE(SetSystemProperty("persist.bluetooth.factoryreset", "true")); auto ret = GetSystemProperty("persist.bluetooth.factoryreset"); ASSERT_TRUE(ret); ASSERT_EQ(ret, "true"); ASSERT_TRUE(SetSystemProperty("persist.bluetooth.factoryreset", "false")); ret = GetSystemProperty("persist.bluetooth.factoryreset"); ASSERT_TRUE(ret); ASSERT_EQ(ret, "false"); ret = GetSystemProperty("persist.bluetooth.factoryreset_do_not_exist"); ASSERT_FALSE(ret); } TEST(SystemPropertiesTest, max_length_test) { std::string property(PROP_NAME_MAX, 'a'); std::string value(PROP_VALUE_MAX, '1'); ASSERT_TRUE(SetSystemProperty("persist.bluetooth.factoryreset", "false")); ASSERT_FALSE(SetSystemProperty(property, "true")); ASSERT_FALSE(SetSystemProperty("persist.bluetooth.factoryreset", value)); ASSERT_FALSE(SetSystemProperty(property, value)); ASSERT_FALSE(GetSystemProperty(property)); // make sure no actual operations on system property happened auto ret = GetSystemProperty("persist.bluetooth.factoryreset"); ASSERT_TRUE(ret); ASSERT_EQ(ret, "false"); } } // namespace testing No newline at end of file system/gd/os/host/system_properties.cc 0 → 100644 +31 −0 Original line number Original line Diff line number Diff line /* * Copyright 2019 The Android Open Source Project * * 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 "os/system_properties.h" namespace bluetooth { namespace os { std::optional<std::string> GetSystemProperty(const std::string& property) { return std::nullopt; } bool SetSystemProperty(const std::string& property, const std::string& value) { return false; } } // namespace os } // namespace bluetooth No newline at end of file Loading
system/gd/Android.bp +5 −0 Original line number Original line Diff line number Diff line Loading @@ -121,6 +121,7 @@ cc_defaults { host: { host: { srcs: [ srcs: [ ":BluetoothHalSources_hci_rootcanal", ":BluetoothHalSources_hci_rootcanal", ":BluetoothOsSources_host", ], ], shared_libs: [ shared_libs: [ "libprotobuf-cpp-full", "libprotobuf-cpp-full", Loading @@ -129,11 +130,13 @@ cc_defaults { android: { android: { srcs: [ srcs: [ ":BluetoothHalSources_hci_android_hidl", ":BluetoothHalSources_hci_android_hidl", ":BluetoothOsSources_android", ], ], shared_libs: [ shared_libs: [ "android.hardware.bluetooth@1.0", "android.hardware.bluetooth@1.0", "libhidlbase", "libhidlbase", "libutils", "libutils", "libcutils", ], ], }, }, }, }, Loading Loading @@ -265,11 +268,13 @@ cc_test { android: { android: { srcs: [ srcs: [ ":BluetoothHalTestSources_hci_android_hidl", ":BluetoothHalTestSources_hci_android_hidl", ":BluetoothOsTestSources_android", ], ], shared_libs: [ shared_libs: [ "android.hardware.bluetooth@1.0", "android.hardware.bluetooth@1.0", "libhidlbase", "libhidlbase", "libutils", "libutils", "libcutils", ], ], }, }, }, }, Loading
system/gd/os/Android.bp +21 −0 Original line number Original line Diff line number Diff line filegroup { name: "BluetoothOsSources_android", srcs: [ "android/system_properties.cc", ], } filegroup { name: "BluetoothOsTestSources_android", srcs: [ "android/system_properties_test.cc", ], } filegroup { name: "BluetoothOsSources_host", srcs: [ "host/system_properties.cc", ], } filegroup { filegroup { name: "BluetoothOsSources_linux_generic", name: "BluetoothOsSources_linux_generic", srcs: [ srcs: [ Loading
system/gd/os/android/system_properties.cc 0 → 100644 +59 −0 Original line number Original line Diff line number Diff line /* * Copyright 2019 The Android Open Source Project * * 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 "os/system_properties.h" #include <cutils/properties.h> #include <array> #include "os/log.h" namespace bluetooth { namespace os { std::optional<std::string> GetSystemProperty(const std::string& property) { if (property.size() >= PROP_NAME_MAX) { LOG_ERROR("Property name's maximum size is %d, but %zu chars were given", PROP_NAME_MAX - 1, property.size()); return std::nullopt; } std::array<char, PROPERTY_VALUE_MAX> value_array{0}; auto value_len = property_get(property.c_str(), value_array.data(), nullptr); if (value_len <= 0) { return std::nullopt; } return std::string(value_array.data(), value_len); } bool SetSystemProperty(const std::string& property, const std::string& value) { if (property.size() >= PROP_NAME_MAX) { LOG_ERROR("Property name's maximum size is %d, but %zu chars were given", PROP_NAME_MAX - 1, property.size()); return false; } if (value.size() >= PROPERTY_VALUE_MAX) { LOG_ERROR("Property value's maximum size is %d, but %zu chars were given", PROPERTY_VALUE_MAX - 1, value.size()); return false; } auto ret = property_set(property.c_str(), value.c_str()); if (ret != 0) { LOG_ERROR("Set property %s failed with error code %d", property.c_str(), ret); return false; } return true; } } // namespace os } // namespace bluetooth No newline at end of file
system/gd/os/android/system_properties_test.cc 0 → 100644 +57 −0 Original line number Original line Diff line number Diff line /* * Copyright 2019 The Android Open Source Project * * 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> #include <gtest/gtest.h> #include <cutils/properties.h> #include "os/system_properties.h" namespace testing { using bluetooth::os::GetSystemProperty; using bluetooth::os::SetSystemProperty; TEST(SystemPropertiesTest, set_and_get_test) { ASSERT_TRUE(SetSystemProperty("persist.bluetooth.factoryreset", "true")); auto ret = GetSystemProperty("persist.bluetooth.factoryreset"); ASSERT_TRUE(ret); ASSERT_EQ(ret, "true"); ASSERT_TRUE(SetSystemProperty("persist.bluetooth.factoryreset", "false")); ret = GetSystemProperty("persist.bluetooth.factoryreset"); ASSERT_TRUE(ret); ASSERT_EQ(ret, "false"); ret = GetSystemProperty("persist.bluetooth.factoryreset_do_not_exist"); ASSERT_FALSE(ret); } TEST(SystemPropertiesTest, max_length_test) { std::string property(PROP_NAME_MAX, 'a'); std::string value(PROP_VALUE_MAX, '1'); ASSERT_TRUE(SetSystemProperty("persist.bluetooth.factoryreset", "false")); ASSERT_FALSE(SetSystemProperty(property, "true")); ASSERT_FALSE(SetSystemProperty("persist.bluetooth.factoryreset", value)); ASSERT_FALSE(SetSystemProperty(property, value)); ASSERT_FALSE(GetSystemProperty(property)); // make sure no actual operations on system property happened auto ret = GetSystemProperty("persist.bluetooth.factoryreset"); ASSERT_TRUE(ret); ASSERT_EQ(ret, "false"); } } // namespace testing No newline at end of file
system/gd/os/host/system_properties.cc 0 → 100644 +31 −0 Original line number Original line Diff line number Diff line /* * Copyright 2019 The Android Open Source Project * * 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 "os/system_properties.h" namespace bluetooth { namespace os { std::optional<std::string> GetSystemProperty(const std::string& property) { return std::nullopt; } bool SetSystemProperty(const std::string& property, const std::string& value) { return false; } } // namespace os } // namespace bluetooth No newline at end of file