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

Commit c7f56007 authored by Joel Galenson's avatar Joel Galenson
Browse files

Migrate to bionic's Rust property bindings.

Bug: 182498247
Test: Build
Change-Id: I250a26143f0896ca2c4f60437c43b76255ded3c1
parent a9c16c84
Loading
Loading
Loading
Loading
+1 −21
Original line number Diff line number Diff line
@@ -25,8 +25,8 @@ rust_library {
        android: {
            rustlibs: [
                "libandroid_logger",
                "libsystem_properties-rust",
            ],
            whole_static_libs: ["libbt_common_sys_prop_cxx"],
            shared_libs: [
                "libcutils",
            ],
@@ -60,23 +60,3 @@ rust_test_host {
        "libpaste",
    ],
}

genrule {
    name: "libbt_common_sys_prop_bridge_code",
    tools: ["cxxbridge"],
    cmd: "$(location cxxbridge) $(in) >> $(out)",
    srcs: ["src/sys_prop.rs"],
    out: ["sys_prop_generated.cc"],
}

cc_library_static {
    name: "libbt_common_sys_prop_cxx",
    defaults: ["gd_ffi_defaults"],
    local_include_dirs: ["src/ffi"],
    srcs: ["src/ffi/sys_prop.cc"],
    generated_headers: ["cxx-bridge-header"],
    generated_sources: ["libbt_common_sys_prop_bridge_code"],
    shared_libs: [
        "libcutils",
    ],
}
+0 −20
Original line number Diff line number Diff line
#include "sys_prop.h"
#include <cutils/properties.h>

namespace bluetooth {
namespace common {
namespace sys_prop {

rust::String get(rust::Str property) {
  auto name = std::string(property.data(), property.length());
  std::array<char, PROPERTY_VALUE_MAX> value_array{0};
  auto value_len = property_get(name.c_str(), value_array.data(), nullptr);
  if (value_len <= 0) {
    value_len = 0;
  }
  return rust::String(value_array.data(), value_len);
}

}  // namespace sys_prop
}  // namespace common
}  // namespace bluetooth
+0 −12
Original line number Diff line number Diff line
#include <string>
#include "rust/cxx.h"

namespace bluetooth {
namespace common {
namespace sys_prop {

rust::String get(rust::Str property);

}
}  // namespace common
}  // namespace bluetooth
+1 −21
Original line number Diff line number Diff line
//! System properties on Android

#[cfg(target_os = "android")]
mod wrap {
    #[cxx::bridge(namespace = bluetooth::common::sys_prop)]
    pub mod ffi {
        unsafe extern "C++" {
            include!("src/ffi/sys_prop.h");
            fn get(name: &str) -> String;
        }
    }
}

#[cfg(target_os = "android")]
use wrap::ffi;

/// Gets the value of a system property on Android
#[cfg(target_os = "android")]
pub fn get(name: &str) -> Option<String> {
    let value = ffi::get(name);

    if !value.is_empty() {
        Some(value)
    } else {
        None
    }
    system_properties::read(name).ok()
}

/// Fake getter for non-Android, which will always return nothing.