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

Commit 3774c8be authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

service: don't use android::String16 in platform-independent code

Test: compile on linux with ninja
Change-Id: Iac421b43a5516418a33b8c804cfca4c777363b27
parent bf40b2e8
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ source_set("service") {
    "common/bluetooth/avrcp_int_value.cc",
    "common/bluetooth/avrcp_media_attr.cc",
    "common/bluetooth/avrcp_register_notification_response.cc",
    "common/bluetooth/avrcp_string_value.cc",
    "common/bluetooth/characteristic.cc",
    "common/bluetooth/descriptor.cc",
    "common/bluetooth/remote_device_props.cc",
+5 −10
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@
#include "service/low_energy_client.h"
#include "service/low_energy_scanner.h"

using android::String16;
using std::lock_guard;
using std::mutex;

@@ -47,8 +46,8 @@ namespace {

RemoteDeviceProps ParseRemoteDeviceProps(int num_properties,
                                         bt_property_t* properties) {
  android::String16 name;
  android::String16 address;
  std::string name;
  std::string address;
  std::vector<Uuid> service_uuids;
  int32_t device_class = 0;
  int32_t device_type = 0;
@@ -63,7 +62,7 @@ RemoteDeviceProps ParseRemoteDeviceProps(int num_properties,
          break;
        }
        bt_bdname_t* hal_name = reinterpret_cast<bt_bdname_t*>(property->val);
        name = String16(reinterpret_cast<char*>(hal_name->name));
        name = reinterpret_cast<char*>(hal_name->name);
        break;
      }
      case BT_PROPERTY_BDADDR: {
@@ -71,9 +70,7 @@ RemoteDeviceProps ParseRemoteDeviceProps(int num_properties,
          NOTREACHED() << "Invalid length for BT_PROPERTY_BDADDR";
          break;
        }
        std::string remote_bdaddr_str =
            BtAddrString(reinterpret_cast<RawAddress*>(property->val));
        address = String16(remote_bdaddr_str.c_str(), remote_bdaddr_str.size());
        address = BtAddrString(reinterpret_cast<RawAddress*>(property->val));
        break;
      }
      case BT_PROPERTY_UUIDS: {
@@ -623,9 +620,7 @@ class AdapterImpl : public Adapter, public hal::BluetoothInterface::Observer {
    RemoteDeviceProps props =
        ParseRemoteDeviceProps(num_properties, properties);

    std::string remote_bdaddr_str = BtAddrString(remote_bdaddr);
    android::String16 address =
        String16(remote_bdaddr_str.c_str(), remote_bdaddr_str.size());
    std::string address = BtAddrString(remote_bdaddr);
    props.set_address(address);

    lock_guard<mutex> lock(observers_lock_);
+8 −9
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@

#include "stack/include/avrc_defs.h"

using android::String16;

namespace bluetooth {

@@ -163,10 +162,10 @@ void AvrcpControl::CtrlTrackChangedCallback(const RawAddress& bd_addr,
                                            btrc_element_attr_val_t* p_attrs) {
  std::string device_address = BtAddrString(&bd_addr);

  String16 title;
  String16 artist;
  String16 album;
  String16 genre;
  std::string title;
  std::string artist;
  std::string album;
  std::string genre;
  int track_num = -1;
  int num_tracks = -1;
  int play_time = -1;
@@ -175,13 +174,13 @@ void AvrcpControl::CtrlTrackChangedCallback(const RawAddress& bd_addr,
    auto attr_text = reinterpret_cast<char*>(p_attrs[i].text);
    switch (p_attrs[i].attr_id) {
      case BTRC_MEDIA_ATTR_ID_TITLE:
        title = String16(attr_text);
        title = attr_text;
        break;
      case BTRC_MEDIA_ATTR_ID_ARTIST:
        artist = String16(attr_text);
        artist = attr_text;
        break;
      case BTRC_MEDIA_ATTR_ID_ALBUM:
        album = String16(attr_text);
        album = attr_text;
        break;
      case BTRC_MEDIA_ATTR_ID_TRACK_NUM:
        if (!base::StringToInt(attr_text, &track_num)) {
@@ -194,7 +193,7 @@ void AvrcpControl::CtrlTrackChangedCallback(const RawAddress& bd_addr,
        }
        break;
      case BTRC_MEDIA_ATTR_ID_GENRE:
        genre = String16(attr_text);
        genre = attr_text;
        break;
      case BTRC_MEDIA_ATTR_ID_PLAYING_TIME:
        if (!base::StringToInt(attr_text, &play_time)) {
+8 −9
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@

#define TRY_RET_FUNC(expr) TRY_RET(expr, __func__ << " failed")

using android::String8;
using LockGuard = std::lock_guard<std::mutex>;

namespace bluetooth {
@@ -61,13 +60,13 @@ std::vector<btrc_player_setting_text_t> StringValueToPlayerSettingsText(
  std::vector<btrc_player_setting_text_t> btrc_attrs(attrs.size());
  for (size_t i = 0; i < attrs.size(); ++i) {
    btrc_attrs[i].id = attrs[i].id();
    String8 str(attrs[i].value());
    size_t to_copy = std::min(sizeof(btrc_attrs[i].text) - 1, str.bytes());
    if (to_copy < str.bytes()) {
    std::string str(attrs[i].value());
    size_t to_copy = std::min(sizeof(btrc_attrs[i].text) - 1, str.size());
    if (to_copy < str.size()) {
      LOG(WARNING) << "Value truncated";
    }

    memcpy(btrc_attrs[i].text, str.string(), to_copy);
    memcpy(btrc_attrs[i].text, str.data(), to_copy);
    btrc_attrs[i].text[to_copy] = '\0';
  }

@@ -79,13 +78,13 @@ std::vector<btrc_element_attr_val_t> StringValueToElementAttrVal(
  std::vector<btrc_element_attr_val_t> btrc_attrs(attrs.size());
  for (size_t i = 0; i < attrs.size(); ++i) {
    btrc_attrs[i].attr_id = attrs[i].id();
    String8 str(attrs[i].value());
    size_t to_copy = std::min(sizeof(btrc_attrs[i].text) - 1, str.bytes());
    if (to_copy < str.bytes()) {
    std::string str(attrs[i].value());
    size_t to_copy = std::min(sizeof(btrc_attrs[i].text) - 1, str.size());
    if (to_copy < str.size()) {
      LOG(WARNING) << "Value truncated";
    }

    memcpy(btrc_attrs[i].text, str.string(), to_copy);
    memcpy(btrc_attrs[i].text, str.data(), to_copy);
    btrc_attrs[i].text[to_copy] = '\0';
  }

+0 −1
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@ cc_library_static {
        "bluetooth/avrcp_int_value.cc",
        "bluetooth/avrcp_media_attr.cc",
        "bluetooth/avrcp_register_notification_response.cc",
        "bluetooth/avrcp_string_value.cc",
        "bluetooth/characteristic.cc",
        "bluetooth/descriptor.cc",
        "bluetooth/remote_device_props.cc",
Loading