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

Commit bc4e4763 authored by William Escande's avatar William Escande Committed by Android (Google) Code Review
Browse files

Merge changes Ib9d65164,I074e35ae into tm-qpr-dev

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


+15 −0
Original line number Original line Diff line number Diff line
@@ -26,6 +26,21 @@ namespace os {
// or if the platform does not support system property
// or if the platform does not support system property
std::optional<std::string> GetSystemProperty(const std::string& property);
std::optional<std::string> GetSystemProperty(const std::string& property);


// Get |property| keyed system property as uint32_t from supported platform, return |default_value| if the property
// does not exist or if the platform does not support system property
uint32_t GetSystemPropertyUint32(const std::string& property, uint32_t default_value);

// Get |property| keyed system property as uint32_t from supported platform, return |default_value|
// if the property does not exist or if the platform does not support system property if property is
// found it will call stoul with |base|
uint32_t GetSystemPropertyUint32Base(
    const std::string& property, uint32_t default_value, int base = 0);

// Get |property| keyed property as bool from supported platform, return
// |default_value| if the property does not exist or if the platform
// does not support system property
bool GetSystemPropertyBool(const std::string& property, bool default_value);

// Set |property| keyed system property to |value|, return true if the set was successful and false if the set failed
// Set |property| keyed system property to |value|, return true if the set was successful and false if the set failed
// Replace existing value if property already exists
// Replace existing value if property already exists
bool SetSystemProperty(const std::string& property, const std::string& value);
bool SetSystemProperty(const std::string& property, const std::string& value);
+53 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright 2022 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 "common/strings.h"
#include "os/system_properties.h"

namespace bluetooth {
namespace os {

uint32_t GetSystemPropertyUint32(const std::string& property, uint32_t default_value) {
  return GetSystemPropertyUint32Base(property, default_value, 10);
}

uint32_t GetSystemPropertyUint32Base(
    const std::string& property, uint32_t default_value, int base) {
  std::optional<std::string> result = GetSystemProperty(property);
  if (result.has_value()) {
    return static_cast<uint32_t>(std::stoul(*result, nullptr, base));
  }
  return default_value;
}

bool GetSystemPropertyBool(const std::string& property, bool default_value) {
  std::optional<std::string> result = GetSystemProperty(property);
  if (result.has_value()) {
    std::string trimmed_val = common::StringTrim(result.value());
    if (trimmed_val == "true" || trimmed_val == "1") {
      return true;
    }
    if (trimmed_val == "false" || trimmed_val == "0") {
      return false;
    }
  }
  return default_value;
}

}  // namespace os
}  // namespace bluetooth
Loading