Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c4d022fc authored by Hui Peng's avatar Hui Peng
Browse files

Clean up GetSystemProperty.* APIs

1. Factor out duplicated implementation of
   GetSystemPropertyUint32 on host/linux/android
2. Add GetSystemPropertyBool and factor out the code
   for retrieving bool properties in system/gd/hal/snoop_logger.cc

Test: refactoring CL. Existing unit tests still pass.

Change-Id: I5a24533f2ce6d146e528661e7cf6b86008537f3f
parent 9b232a14
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -447,9 +447,8 @@ size_t SnoopLogger::GetMaxPacketsPerFile() {
size_t SnoopLogger::GetMaxPacketsPerBuffer() {
  // We want to use at most 256 KB memory for btsnooz log for release builds
  // and 512 KB memory for userdebug/eng builds
  auto is_debuggable = os::GetSystemProperty(kIsDebuggableProperty);
  size_t btsnooz_max_memory_usage_bytes =
      ((is_debuggable.has_value() && common::StringTrim(is_debuggable.value()) == "1") ? 1024 : 256) * 1024;
  auto is_debuggable = os::GetSystemPropertyBool(kIsDebuggableProperty, false);
  size_t btsnooz_max_memory_usage_bytes = (is_debuggable ? 1024 : 256) * 1024;
  // Calculate max number of packets based on max memory usage and max packet size
  return btsnooz_max_memory_usage_bytes / kDefaultBtSnoozMaxBytesPerPacket;
}
@@ -459,8 +458,8 @@ std::string SnoopLogger::GetBtSnoopMode() {
  // In userdebug/eng build, it can also be overwritten by modifying the global setting
  std::string default_mode = kBtSnoopLogModeDisabled;
  {
    auto is_debuggable = os::GetSystemProperty(kIsDebuggableProperty);
    if (is_debuggable.has_value() && common::StringTrim(is_debuggable.value()) == "1") {
    auto is_debuggable = os::GetSystemPropertyBool(kIsDebuggableProperty, false);
    if (is_debuggable) {
      auto default_mode_property = os::GetSystemProperty(kBtSnoopDefaultLogModeProperty);
      if (default_mode_property) {
        default_mode = std::move(default_mode_property.value());
+2 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ filegroup {
filegroup {
    name: "BluetoothOsSources_android",
    srcs: [
        "system_properties_common.cc",
        "android/metrics.cc",
        "android/parameter_provider.cc",
        "android/system_properties.cc",
@@ -35,6 +36,7 @@ filegroup {
filegroup {
    name: "BluetoothOsSources_host",
    srcs: [
        "system_properties_common.cc",
        "host/metrics.cc",
        "host/parameter_provider.cc",
        "host/system_properties.cc",
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ source_set("BluetoothOsSources_linux") {
    "linux/parameter_provider.cc",
    "linux/system_properties.cc",
    "linux/wakelock_native.cc",
    "system_properties_common.cc",
    "syslog.cc",
  ]

+0 −9
Original line number Diff line number Diff line
@@ -36,15 +36,6 @@ std::optional<std::string> GetSystemProperty(const std::string& property) {
  return std::string(value_array.data(), value_len);
}

uint32_t GetSystemPropertyUint32(const std::string& property, uint32_t default_value) {
  std::optional<std::string> result = GetSystemProperty(property);
  if (result) {
    return static_cast<uint32_t>(std::stoul(*result));
  } else {
    return default_value;
  }
}

bool SetSystemProperty(const std::string& property, const std::string& value) {
  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());
+0 −9
Original line number Diff line number Diff line
@@ -37,15 +37,6 @@ std::optional<std::string> GetSystemProperty(const std::string& property) {
  return iter->second;
}

uint32_t GetSystemPropertyUint32(const std::string& property, uint32_t default_value) {
  std::optional<std::string> result = GetSystemProperty(property);
  if (result) {
    return static_cast<uint32_t>(std::stoul(*result));
  } else {
    return default_value;
  }
}

bool SetSystemProperty(const std::string& property, const std::string& value) {
  std::lock_guard<std::mutex> lock(properties_mutex);
  properties.insert_or_assign(property, value);
Loading