summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Katherine Lai <laikatherine@google.com> 2022-06-29 23:44:13 +0000
committer Katherine Lai <laikatherine@google.com> 2022-07-26 21:41:35 +0000
commit95f689550f7e92d3ce26c16e092b870cfa4a85e6 (patch)
tree61e05607c5ca87badc910aa87ea735388a443244
parent6d03930657d75ee9f0e6d0e59e06ef5ea40119cb (diff)
Create new sysprops module
New module loads sysprops defaults from config file and merges config fragments from the corresponding .d directory if it exists. This allows non-Android OS's to use sysprops and gives them a way to set and override sysprop defaults. Also migrates bluetooth.core.gap.le.privacy.enabled on Linux to use the new module. Bug: 233119381 Bug: 233119695 Tag: #floss Test: Unit tests and manually verified privacy sysprop Change-Id: I7167f6fdfa9ec2ec3c1504b8b44f92c5ae2ba174
-rw-r--r--system/btif/src/btif_dm.cc25
-rw-r--r--system/gd/Android.bp4
-rw-r--r--system/gd/BUILD.gn1
-rw-r--r--system/gd/os/android/parameter_provider.cc5
-rw-r--r--system/gd/os/host/parameter_provider.cc4
-rw-r--r--system/gd/os/linux/parameter_provider.cc16
-rw-r--r--system/gd/os/linux/system_properties.cc2
-rw-r--r--system/gd/os/parameter_provider.h5
-rw-r--r--system/gd/sysprops/Android.bp15
-rw-r--r--system/gd/sysprops/BUILD.gn22
-rw-r--r--system/gd/sysprops/sysprops_module.cc83
-rw-r--r--system/gd/sysprops/sysprops_module.h49
-rw-r--r--system/main/shim/stack.cc8
13 files changed, 221 insertions, 18 deletions
diff --git a/system/btif/src/btif_dm.cc b/system/btif/src/btif_dm.cc
index a9c56c743e..5afa7aa80b 100644
--- a/system/btif/src/btif_dm.cc
+++ b/system/btif/src/btif_dm.cc
@@ -1572,19 +1572,18 @@ void BTIF_dm_enable() {
/* Enable or disable local privacy */
bool ble_privacy_enabled = true;
- #ifdef OS_ANDROID
- ble_privacy_enabled =
- android::sysprop::BluetoothProperties::isGapLePrivacyEnabled().value_or(
- true);
- #else
- char ble_privacy_text[PROPERTY_VALUE_MAX] = "true"; // default is enabled
- if (osi_property_get(PROPERTY_BLE_PRIVACY_ENABLED, ble_privacy_text,
- "true") &&
- !strcmp(ble_privacy_text, "false")) {
- ble_privacy_enabled = false;
- }
- #endif
-
+#ifdef OS_ANDROID
+ ble_privacy_enabled =
+ android::sysprop::BluetoothProperties::isGapLePrivacyEnabled().value_or(
+ true);
+#else
+ char ble_privacy_text[PROPERTY_VALUE_MAX] = "true"; // default is enabled
+ if (osi_property_get(PROPERTY_BLE_PRIVACY_ENABLED, ble_privacy_text,
+ "true") &&
+ !strcmp(ble_privacy_text, "false")) {
+ ble_privacy_enabled = false;
+ }
+#endif
LOG_INFO("%s BLE Privacy: %d", __func__, ble_privacy_enabled);
BTA_DmBleConfigLocalPrivacy(ble_privacy_enabled);
diff --git a/system/gd/Android.bp b/system/gd/Android.bp
index 8034dff468..ef16a6a426 100644
--- a/system/gd/Android.bp
+++ b/system/gd/Android.bp
@@ -188,6 +188,7 @@ cc_defaults {
":BluetoothShimSources",
":BluetoothSecuritySources",
":BluetoothStorageSources",
+ ":BluetoothSyspropsSources",
],
generated_headers: [
"BluetoothGeneratedBundlerSchema_h_bfbs",
@@ -199,6 +200,9 @@ cc_defaults {
"libcrypto",
"libflatbuffers-cpp",
],
+ whole_static_libs: [
+ "libc++fs",
+ ],
static_libs: [
"libbluetooth-dumpsys",
"libbluetooth-protos",
diff --git a/system/gd/BUILD.gn b/system/gd/BUILD.gn
index 0641fcc1d2..33a35e1181 100644
--- a/system/gd/BUILD.gn
+++ b/system/gd/BUILD.gn
@@ -80,6 +80,7 @@ static_library("libbluetooth_gd") {
"//bt/system/gd/security:BluetoothSecuritySources",
"//bt/system/gd/shim:BluetoothShimSources",
"//bt/system/gd/storage:BluetoothStorageSources",
+ "//bt/system/gd/sysprops:BluetoothSyspropsSources",
]
}
diff --git a/system/gd/os/android/parameter_provider.cc b/system/gd/os/android/parameter_provider.cc
index 0d78067c0b..f4d4751cf8 100644
--- a/system/gd/os/android/parameter_provider.cc
+++ b/system/gd/os/android/parameter_provider.cc
@@ -82,6 +82,11 @@ void ParameterProvider::OverrideSnoozLogFilePath(const std::string& path) {
snooz_log_file_path = path;
}
+// Android doesn't have a need for the sysprops module
+std::string ParameterProvider::SyspropsFilePath() {
+ return "";
+}
+
bluetooth_keystore::BluetoothKeystoreInterface* ParameterProvider::GetBtKeystoreInterface() {
std::lock_guard<std::mutex> lock(parameter_mutex);
return bt_keystore_interface;
diff --git a/system/gd/os/host/parameter_provider.cc b/system/gd/os/host/parameter_provider.cc
index ef5ca4bc75..aee9b1659c 100644
--- a/system/gd/os/host/parameter_provider.cc
+++ b/system/gd/os/host/parameter_provider.cc
@@ -96,6 +96,10 @@ void ParameterProvider::OverrideSnoozLogFilePath(const std::string& path) {
snooz_log_file_path = path;
}
+std::string ParameterProvider::SyspropsFilePath() {
+ return "";
+}
+
bluetooth_keystore::BluetoothKeystoreInterface* ParameterProvider::GetBtKeystoreInterface() {
return nullptr;
}
diff --git a/system/gd/os/linux/parameter_provider.cc b/system/gd/os/linux/parameter_provider.cc
index 10144ae670..8e26154cee 100644
--- a/system/gd/os/linux/parameter_provider.cc
+++ b/system/gd/os/linux/parameter_provider.cc
@@ -32,6 +32,7 @@ std::mutex parameter_mutex;
std::string config_file_path;
std::string snoop_log_file_path;
std::string snooz_log_file_path;
+std::string sysprops_file_path;
} // namespace
// Write to $PWD/bt_stack.conf if $PWD can be found, otherwise, write to $HOME/bt_stack.conf
@@ -76,6 +77,21 @@ std::string ParameterProvider::SnoozLogFilePath() {
return "/var/log/bluetooth/btsnooz_hci.log";
}
+std::string ParameterProvider::SyspropsFilePath() {
+ {
+ std::lock_guard<std::mutex> lock(parameter_mutex);
+ if (!sysprops_file_path.empty()) {
+ return sysprops_file_path;
+ }
+ }
+ return "/etc/bluetooth/sysprops.conf";
+}
+
+void ParameterProvider::OverrideSyspropsFilePath(const std::string& path) {
+ std::lock_guard<std::mutex> lock(parameter_mutex);
+ sysprops_file_path = path;
+}
+
bluetooth_keystore::BluetoothKeystoreInterface* ParameterProvider::GetBtKeystoreInterface() {
return nullptr;
}
diff --git a/system/gd/os/linux/system_properties.cc b/system/gd/os/linux/system_properties.cc
index 7130743e94..0dba2ba196 100644
--- a/system/gd/os/linux/system_properties.cc
+++ b/system/gd/os/linux/system_properties.cc
@@ -29,8 +29,6 @@ std::mutex properties_mutex;
// Properties set along with some default values for Floss.
std::unordered_map<std::string, std::string> properties = {
{"bluetooth.profile.avrcp.target.enabled", "true"},
- // TODO (b/235218533): Re-enable LL privacy on Floss
- {"bluetooth.core.gap.le.privacy.enabled", "false"},
};
} // namespace
diff --git a/system/gd/os/parameter_provider.h b/system/gd/os/parameter_provider.h
index 1113918533..da33270c29 100644
--- a/system/gd/os/parameter_provider.h
+++ b/system/gd/os/parameter_provider.h
@@ -40,6 +40,11 @@ class ParameterProvider {
static void OverrideSnoozLogFilePath(const std::string& path);
+ // Return the path to the default sysprops file
+ static std::string SyspropsFilePath();
+
+ static void OverrideSyspropsFilePath(const std::string& path);
+
static bluetooth_keystore::BluetoothKeystoreInterface* GetBtKeystoreInterface();
static void SetBtKeystoreInterface(bluetooth_keystore::BluetoothKeystoreInterface* bt_keystore);
diff --git a/system/gd/sysprops/Android.bp b/system/gd/sysprops/Android.bp
new file mode 100644
index 0000000000..bddede7f6e
--- /dev/null
+++ b/system/gd/sysprops/Android.bp
@@ -0,0 +1,15 @@
+package {
+ // See: http://go/android-license-faq
+ // A large-scale-change added 'default_applicable_licenses' to import
+ // all of the 'license_kinds' from "system_bt_license"
+ // to get the below license kinds:
+ // SPDX-license-identifier-Apache-2.0
+ default_applicable_licenses: ["system_bt_license"],
+}
+
+filegroup {
+ name: "BluetoothSyspropsSources",
+ srcs: [
+ "sysprops_module.cc",
+ ],
+}
diff --git a/system/gd/sysprops/BUILD.gn b/system/gd/sysprops/BUILD.gn
new file mode 100644
index 0000000000..c6401a0b29
--- /dev/null
+++ b/system/gd/sysprops/BUILD.gn
@@ -0,0 +1,22 @@
+#
+# Copyright 2021 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.
+#
+
+source_set("BluetoothSyspropsSources") {
+ sources = [ "sysprops_module.cc" ]
+
+ configs += [ "//bt/system/gd:gd_defaults" ]
+ deps = [ "//bt/system/gd:gd_default_deps" ]
+}
diff --git a/system/gd/sysprops/sysprops_module.cc b/system/gd/sysprops/sysprops_module.cc
new file mode 100644
index 0000000000..4ba3cad18f
--- /dev/null
+++ b/system/gd/sysprops/sysprops_module.cc
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2020 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 "sysprops/sysprops_module.h"
+
+#include <filesystem>
+
+#include "os/handler.h"
+#include "os/log.h"
+#include "os/parameter_provider.h"
+#include "os/system_properties.h"
+#include "storage/legacy_config_file.h"
+
+namespace bluetooth {
+namespace sysprops {
+
+static const size_t kDefaultCapacity = 10000;
+
+const ModuleFactory SyspropsModule::Factory = ModuleFactory([]() { return new SyspropsModule(); });
+
+struct SyspropsModule::impl {
+ impl(os::Handler* sysprops_handler) : sysprops_handler_(sysprops_handler) {}
+
+ os::Handler* sysprops_handler_;
+};
+
+void SyspropsModule::ListDependencies(ModuleList* list) const {}
+
+void SyspropsModule::Start() {
+ std::string file_path = os::ParameterProvider::SyspropsFilePath();
+ if (!file_path.empty()) {
+ parse_config(file_path);
+ // Merge config fragments
+ std::string override_dir = file_path + ".d";
+ if (std::filesystem::exists(override_dir)) {
+ for (const auto& entry : std::filesystem::directory_iterator(override_dir)) {
+ parse_config(entry.path());
+ }
+ }
+ }
+
+ pimpl_ = std::make_unique<impl>(GetHandler());
+}
+
+void SyspropsModule::Stop() {
+ pimpl_.reset();
+}
+
+std::string SyspropsModule::ToString() const {
+ return "Sysprops Module";
+}
+
+void SyspropsModule::parse_config(std::string file_path) {
+ const std::list<std::string> supported_sysprops = {"bluetooth.core.gap.le.privacy.enabled"};
+
+ auto config = storage::LegacyConfigFile::FromPath(file_path).Read(kDefaultCapacity);
+ if (!config) {
+ return;
+ }
+
+ for (auto s = supported_sysprops.begin(); s != supported_sysprops.end(); s++) {
+ auto str = config->GetProperty("Sysprops", *s);
+ if (str) {
+ bluetooth::os::SetSystemProperty(*s, *str);
+ }
+ }
+}
+
+} // namespace sysprops
+} // namespace bluetooth
diff --git a/system/gd/sysprops/sysprops_module.h b/system/gd/sysprops/sysprops_module.h
new file mode 100644
index 0000000000..c7a72191cd
--- /dev/null
+++ b/system/gd/sysprops/sysprops_module.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2020 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.
+ */
+#pragma once
+
+#include "module.h"
+
+namespace bluetooth {
+namespace sysprops {
+
+class SyspropsModule : public bluetooth::Module {
+ public:
+ SyspropsModule() = default;
+ SyspropsModule(const SyspropsModule&) = delete;
+ SyspropsModule& operator=(const SyspropsModule&) = delete;
+
+ ~SyspropsModule() = default;
+
+ static const ModuleFactory Factory;
+
+ protected:
+ void ListDependencies(ModuleList* list) const override;
+
+ void Start() override;
+
+ void Stop() override;
+
+ std::string ToString() const override;
+
+ private:
+ struct impl;
+ std::unique_ptr<impl> pimpl_;
+ void parse_config(std::string file_path);
+};
+
+} // namespace sysprops
+} // namespace bluetooth
diff --git a/system/main/shim/stack.cc b/system/main/shim/stack.cc
index 89573eb760..c4039c479c 100644
--- a/system/main/shim/stack.cc
+++ b/system/main/shim/stack.cc
@@ -16,13 +16,15 @@
#define LOG_TAG "bt_gd_shim"
-#include "device/include/controller.h"
+#include "main/shim/stack.h"
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
+
#include <string>
+#include "device/include/controller.h"
#include "gd/att/att_module.h"
#include "gd/btaa/activity_attribution.h"
#include "gd/common/init_flags.h"
@@ -48,7 +50,7 @@
#include "gd/security/security_module.h"
#include "gd/shim/dumpsys.h"
#include "gd/storage/storage_module.h"
-
+#include "gd/sysprops/sysprops_module.h"
#include "main/shim/acl_legacy_interface.h"
#include "main/shim/activity_attribution.h"
#include "main/shim/hci_layer.h"
@@ -57,7 +59,6 @@
#include "main/shim/le_advertising_manager.h"
#include "main/shim/le_scanning_manager.h"
#include "main/shim/shim.h"
-#include "main/shim/stack.h"
namespace bluetooth {
namespace shim {
@@ -142,6 +143,7 @@ void Stack::StartEverything() {
modules.add<storage::StorageModule>();
modules.add<shim::Dumpsys>();
modules.add<hci::VendorSpecificEventManager>();
+ modules.add<sysprops::SyspropsModule>();
modules.add<hci::Controller>();
modules.add<hci::AclManager>();