Immediate convert ByteArray to string to avoid using ByteArray in Fast Pair internal code

PiperOrigin-RevId: 514833850
This commit is contained in:
Qin Wang
2023-03-07 14:06:33 -08:00
committed by Copybara-Service
parent 7e1ca7d458
commit 53d4f55e70
4 changed files with 11 additions and 11 deletions
@@ -101,9 +101,9 @@ FastPairDiscoverableScannerImpl::FastPairDiscoverableScannerImpl(
void FastPairDiscoverableScannerImpl::OnDeviceFound(
const BlePeripheral& peripheral) {
ByteArray fast_pair_service_data =
peripheral.GetAdvertisementBytes(kServiceId);
if (fast_pair_service_data.Empty()) {
std::string fast_pair_service_data =
peripheral.GetAdvertisementBytes(kServiceId).string_data();
if (fast_pair_service_data.empty()) {
NEARBY_LOGS(WARNING) << __func__
<< ": Device doesn't have any Fast Pair Service Data.";
return;
@@ -112,9 +112,8 @@ void FastPairDiscoverableScannerImpl::OnDeviceFound(
model_id_parse_attempts_[peripheral.GetName()] = 1;
NEARBY_LOGS(INFO) << __func__ << ": Attempting to get model ID";
std::vector<uint8_t> service_data;
std::string model_id_bytes = fast_pair_service_data.data();
std::move(std::begin(model_id_bytes), std::end(model_id_bytes),
std::back_inserter(service_data));
std::move(std::begin(fast_pair_service_data),
std::end(fast_pair_service_data), std::back_inserter(service_data));
FastPairDataParser::GetHexModelIdFromServiceData(
service_data,
@@ -115,14 +115,15 @@ void FastPairScannerImpl::StopScanning() {
void FastPairScannerImpl::OnDeviceFound(const BlePeripheral& peripheral) {
NEARBY_LOGS(INFO) << __func__ << "Found device with ble Address = "
<< peripheral.GetName();
ByteArray service_data = peripheral.GetAdvertisementBytes(kServiceId);
if (service_data.Empty()) {
std::string service_data =
peripheral.GetAdvertisementBytes(kServiceId).string_data();
if (service_data.empty()) {
NEARBY_LOGS(WARNING) << "No Fast Pair service data found on device";
return;
}
device_address_advertisement_data_map_[peripheral.GetName()].insert(
peripheral.GetAdvertisementBytes(kServiceId));
service_data);
NotifyDeviceFound(peripheral);
}
@@ -21,6 +21,7 @@
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "fastpair/internal/ble/ble.h"
#include "fastpair/scanning/fastpair/fast_pair_scanner.h"
#include "internal/base/observer_list.h"
@@ -75,7 +76,7 @@ class FastPairScannerImpl : public FastPairScanner {
// Map of a Bluetooth device address to a set of advertisement data we have
// seen.
absl::flat_hash_map<std::string, std::set<ByteArray>>
absl::flat_hash_map<std::string, std::set<std::string>>
device_address_advertisement_data_map_;
BluetoothAdapter bluetooth_adapter_;
@@ -165,7 +165,6 @@ struct GattCharacteristic {
// https://developer.android.com/reference/android/bluetooth/BluetoothGatt
//
// Representation of a client GATT connection to a remote GATT server.
// TODO(b/271625842) Convert ByteArray to std::string
class GattClient {
public:
virtual ~GattClient() = default;