service: don't use android::String16 in platform-independent code
Test: compile on linux with ninja
Change-Id: Iac421b43a5516418a33b8c804cfca4c777363b27
diff --git a/service/BUILD.gn b/service/BUILD.gn
index 6e8a7d8..59acb16 100644
--- a/service/BUILD.gn
+++ b/service/BUILD.gn
@@ -28,7 +28,6 @@
"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",
diff --git a/service/adapter.cc b/service/adapter.cc
index b721ef8..669aeff 100644
--- a/service/adapter.cc
+++ b/service/adapter.cc
@@ -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 @@
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 @@
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 @@
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 @@
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_);
diff --git a/service/avrcp_control.cc b/service/avrcp_control.cc
index 7692400..18dc2aa 100644
--- a/service/avrcp_control.cc
+++ b/service/avrcp_control.cc
@@ -28,7 +28,6 @@
#include "stack/include/avrc_defs.h"
-using android::String16;
namespace bluetooth {
@@ -163,10 +162,10 @@
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 @@
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 @@
}
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)) {
diff --git a/service/avrcp_target.cc b/service/avrcp_target.cc
index f502774..fb63fba 100644
--- a/service/avrcp_target.cc
+++ b/service/avrcp_target.cc
@@ -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> 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> 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';
}
diff --git a/service/common/Android.bp b/service/common/Android.bp
index ef08b21..fa63cf9 100644
--- a/service/common/Android.bp
+++ b/service/common/Android.bp
@@ -16,7 +16,6 @@
"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",
diff --git a/service/common/android/bluetooth/bluetooth_avrcp_media_attr.cc b/service/common/android/bluetooth/bluetooth_avrcp_media_attr.cc
index 18c10b1..b29204e 100644
--- a/service/common/android/bluetooth/bluetooth_avrcp_media_attr.cc
+++ b/service/common/android/bluetooth/bluetooth_avrcp_media_attr.cc
@@ -27,16 +27,17 @@
namespace bluetooth {
status_t BluetoothAvrcpMediaAttr::writeToParcel(Parcel* parcel) const {
- status_t status = parcel->writeString16(title_);
+ status_t status =
+ parcel->writeString16(String16(title_.c_str(), title_.size()));
if (status != OK) return status;
- status = parcel->writeString16(artist_);
+ status = parcel->writeString16(String16(artist_.c_str(), artist_.size()));
if (status != OK) return status;
- status = parcel->writeString16(album_);
+ status = parcel->writeString16(String16(album_.c_str(), album_.size()));
if (status != OK) return status;
- status = parcel->writeString16(genre_);
+ status = parcel->writeString16(String16(genre_.c_str(), genre_.size()));
if (status != OK) return status;
status = parcel->writeInt32(track_num_);
@@ -52,17 +53,25 @@
}
status_t BluetoothAvrcpMediaAttr::readFromParcel(const Parcel* parcel) {
- status_t status = parcel->readString16(&title_);
+ String16 title;
+ status_t status = parcel->readString16(&title);
if (status != OK) return status;
+ title_ = String8(title).string();
- status = parcel->readString16(&artist_);
+ String16 artist;
+ status = parcel->readString16(&artist);
if (status != OK) return status;
+ artist_ = String8(artist).string();
- status = parcel->readString16(&album_);
+ String16 album;
+ status = parcel->readString16(&album);
if (status != OK) return status;
+ album_ = String8(album).string();
- status = parcel->readString16(&genre_);
+ String16 genre;
+ status = parcel->readString16(&genre);
if (status != OK) return status;
+ genre_ = String8(genre).string();
int32_t tmp;
status = parcel->readInt32(&tmp);
diff --git a/service/common/android/bluetooth/bluetooth_avrcp_string_value.cc b/service/common/android/bluetooth/bluetooth_avrcp_string_value.cc
index 72ed179..ded9105 100644
--- a/service/common/android/bluetooth/bluetooth_avrcp_string_value.cc
+++ b/service/common/android/bluetooth/bluetooth_avrcp_string_value.cc
@@ -30,7 +30,7 @@
status_t status = parcel->writeInt32(id_);
if (status != OK) return status;
- status = parcel->writeString16(value_);
+ status = parcel->writeString16(String16(value_.c_str(), value_.size()));
if (status != OK) return status;
return status;
@@ -42,8 +42,10 @@
if (status != OK) return status;
id_ = tmp;
- status = parcel->readString16(&value_);
+ String16 value;
+ status = parcel->readString16(&value);
if (status != OK) return status;
+ value_ = String8(value).string();
return status;
}
diff --git a/service/common/android/bluetooth/bluetooth_remote_device_props.cc b/service/common/android/bluetooth/bluetooth_remote_device_props.cc
index 190fa94..21974da 100644
--- a/service/common/android/bluetooth/bluetooth_remote_device_props.cc
+++ b/service/common/android/bluetooth/bluetooth_remote_device_props.cc
@@ -29,10 +29,11 @@
namespace bluetooth {
status_t BluetoothRemoteDeviceProps::writeToParcel(Parcel* parcel) const {
- status_t status = parcel->writeString16(name_);
+ status_t status =
+ parcel->writeString16(String16(name_.c_str(), name_.size()));
if (status != OK) return status;
- status = parcel->writeString16(address_);
+ status = parcel->writeString16(String16(address_.c_str(), address_.size()));
if (status != OK) return status;
std::vector<UUID> uuids;
@@ -56,11 +57,15 @@
}
status_t BluetoothRemoteDeviceProps::readFromParcel(const Parcel* parcel) {
- status_t status = parcel->readString16(&name_);
+ String16 name;
+ status_t status = parcel->readString16(&name);
if (status != OK) return status;
+ name_ = String8(name).string();
- status = parcel->readString16(&address_);
+ String16 address;
+ status = parcel->readString16(&address);
if (status != OK) return status;
+ address_ = String8(address).string();
std::vector<UUID> uuids;
status = parcel->readParcelableVector(&uuids);
diff --git a/service/common/bluetooth/avrcp_media_attr.cc b/service/common/bluetooth/avrcp_media_attr.cc
index 652ee6c..fc50957 100644
--- a/service/common/bluetooth/avrcp_media_attr.cc
+++ b/service/common/bluetooth/avrcp_media_attr.cc
@@ -16,15 +16,15 @@
#include "bluetooth/avrcp_media_attr.h"
-using android::String16;
-
namespace bluetooth {
AvrcpMediaAttr::AvrcpMediaAttr() = default;
AvrcpMediaAttr::AvrcpMediaAttr(const AvrcpMediaAttr& other) = default;
-AvrcpMediaAttr::AvrcpMediaAttr(const String16& title, const String16& artist,
- const String16& album, const String16& genre,
- int track_num, int num_tracks, int play_time)
+AvrcpMediaAttr::AvrcpMediaAttr(const std::string& title,
+ const std::string& artist,
+ const std::string& album,
+ const std::string& genre, int track_num,
+ int num_tracks, int play_time)
: title_(title),
artist_(artist),
album_(album),
diff --git a/service/common/bluetooth/avrcp_media_attr.h b/service/common/bluetooth/avrcp_media_attr.h
index 7ae69e2..31a7cfd 100644
--- a/service/common/bluetooth/avrcp_media_attr.h
+++ b/service/common/bluetooth/avrcp_media_attr.h
@@ -16,7 +16,7 @@
#pragma once
-#include <utils/String16.h>
+#include <string>
namespace bluetooth {
@@ -24,25 +24,24 @@
public:
AvrcpMediaAttr();
AvrcpMediaAttr(const AvrcpMediaAttr& other);
- AvrcpMediaAttr(const android::String16& title,
- const android::String16& artist,
- const android::String16& album, const android::String16& genre,
+ AvrcpMediaAttr(const std::string& title, const std::string& artist,
+ const std::string& album, const std::string& genre,
int track_num, int num_tracks, int play_time);
~AvrcpMediaAttr();
- const android::String16& title() const { return title_; }
- const android::String16& artist() const { return artist_; }
- const android::String16& album() const { return album_; }
- const android::String16& genre() const { return genre_; }
+ const std::string& title() const { return title_; }
+ const std::string& artist() const { return artist_; }
+ const std::string& album() const { return album_; }
+ const std::string& genre() const { return genre_; }
int track_num() const { return track_num_; }
int num_tracks() const { return num_tracks_; }
int play_time() const { return play_time_; }
protected:
- android::String16 title_;
- android::String16 artist_;
- android::String16 album_;
- android::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;
diff --git a/service/common/bluetooth/avrcp_string_value.cc b/service/common/bluetooth/avrcp_string_value.cc
deleted file mode 100644
index 65f7ffa..0000000
--- a/service/common/bluetooth/avrcp_string_value.cc
+++ /dev/null
@@ -1,29 +0,0 @@
-//
-// Copyright (C) 2017 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.
-//
-
-#include "bluetooth/avrcp_string_value.h"
-
-using android::String16;
-
-namespace bluetooth {
-
-AvrcpStringValue::AvrcpStringValue() = default;
-AvrcpStringValue::AvrcpStringValue(const AvrcpStringValue& other) = default;
-AvrcpStringValue::AvrcpStringValue(int id, const String16& value)
- : id_(id), value_(value) {}
-AvrcpStringValue::~AvrcpStringValue() = default;
-
-} // namespace bluetooth
diff --git a/service/common/bluetooth/avrcp_string_value.h b/service/common/bluetooth/avrcp_string_value.h
index 8ba6cb4..0b5cca4 100644
--- a/service/common/bluetooth/avrcp_string_value.h
+++ b/service/common/bluetooth/avrcp_string_value.h
@@ -16,23 +16,23 @@
#pragma once
-#include <utils/String16.h>
+#include <string>
namespace bluetooth {
class AvrcpStringValue {
public:
- AvrcpStringValue();
- AvrcpStringValue(const AvrcpStringValue& other);
- AvrcpStringValue(int id, const android::String16& value);
- ~AvrcpStringValue();
+ AvrcpStringValue() = default;
+ AvrcpStringValue(const AvrcpStringValue& other) = default;
+ AvrcpStringValue(int id, const std::string& value) : id_(id), value_(value){};
+ ~AvrcpStringValue() = default;
int id() const { return id_; }
- const android::String16& value() const { return value_; }
+ const std::string& value() const { return value_; }
protected:
int id_ = 0;
- android::String16 value_;
+ std::string value_;
};
} // namespace bluetooth
diff --git a/service/common/bluetooth/remote_device_props.cc b/service/common/bluetooth/remote_device_props.cc
index 61ee462..930421f 100644
--- a/service/common/bluetooth/remote_device_props.cc
+++ b/service/common/bluetooth/remote_device_props.cc
@@ -16,14 +16,14 @@
#include "bluetooth/remote_device_props.h"
-using android::String16;
+using std::string;
namespace bluetooth {
RemoteDeviceProps::RemoteDeviceProps() = default;
RemoteDeviceProps::RemoteDeviceProps(const RemoteDeviceProps& other) = default;
-RemoteDeviceProps::RemoteDeviceProps(const android::String16& name,
- const android::String16& address,
+RemoteDeviceProps::RemoteDeviceProps(const std::string& name,
+ const std::string& address,
const std::vector<Uuid>& service_uuids,
int32_t device_class, int32_t device_type,
int32_t rssi)
diff --git a/service/common/bluetooth/remote_device_props.h b/service/common/bluetooth/remote_device_props.h
index f6997ff..f8b3b1b 100644
--- a/service/common/bluetooth/remote_device_props.h
+++ b/service/common/bluetooth/remote_device_props.h
@@ -16,10 +16,9 @@
#pragma once
+#include <string>
#include <vector>
-#include <utils/String16.h>
-
#include "bluetooth/uuid.h"
namespace bluetooth {
@@ -28,24 +27,23 @@
public:
RemoteDeviceProps();
RemoteDeviceProps(const RemoteDeviceProps& other);
- RemoteDeviceProps(const android::String16& name,
- const android::String16& address,
+ RemoteDeviceProps(const std::string& name, const std::string& address,
const std::vector<Uuid>& service_uuids,
int32_t device_class, int32_t device_type, int32_t rssi);
~RemoteDeviceProps();
- void set_address(const android::String16& address) { address_ = address; }
+ void set_address(const std::string& address) { address_ = address; }
- const android::String16& name() const { return name_; }
- const android::String16& address() const { return address_; }
+ const std::string& name() const { return name_; }
+ const std::string& address() const { return address_; }
const std::vector<Uuid>& service_uuids() const { return service_uuids_; }
int32_t device_class() const { return device_class_; }
int32_t device_type() const { return device_type_; }
int32_t rssi() const { return rssi_; }
protected:
- android::String16 name_;
- android::String16 address_;
+ std::string name_;
+ std::string address_;
std::vector<Uuid> service_uuids_;
int32_t device_class_ = -1;
int32_t device_type_ = -1;