bluetooth/types: Make RawAddress::FromOctets static
Bug: 424272093
Test: m .
Flag: EXEMPT no logical change
Change-Id: I9ebe0d7f9c3cc5cbfbfd9b0acab4bee8f1be16ac
diff --git a/android/app/jni/com_android_bluetooth_a2dp.cpp b/android/app/jni/com_android_bluetooth_a2dp.cpp
index 9ad942a..c25184c 100644
--- a/android/app/jni/com_android_bluetooth_a2dp.cpp
+++ b/android/app/jni/com_android_bluetooth_a2dp.cpp
@@ -413,8 +413,7 @@
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
log::info("{}", bd_addr);
bt_status_t status = btif_av_source_connect(bd_addr);
@@ -433,8 +432,7 @@
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
log::info("{}", bd_addr);
bt_status_t status = btif_av_source_disconnect(bd_addr);
@@ -450,10 +448,10 @@
std::shared_lock<std::shared_timed_mutex> lock(interface_mutex);
jbyte* addr = env->GetByteArrayElements(address, nullptr);
- RawAddress bd_addr = RawAddress::kEmpty;
- if (addr) {
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
- }
+
+ RawAddress bd_addr = addr ? RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr))
+ : RawAddress::kEmpty;
+
if (bd_addr == RawAddress::kEmpty) {
return JNI_FALSE;
}
@@ -471,10 +469,9 @@
std::shared_lock<std::shared_timed_mutex> lock(interface_mutex);
jbyte* addr = env->GetByteArrayElements(address, nullptr);
- RawAddress bd_addr = RawAddress::kEmpty;
- if (addr) {
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
- }
+
+ RawAddress bd_addr = addr ? RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr))
+ : RawAddress::kEmpty;
log::info("{}", bd_addr);
bt_status_t status = btif_av_source_set_active_device(bd_addr);
@@ -494,8 +491,7 @@
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
std::vector<btav_a2dp_codec_config_t> codec_preferences =
prepareCodecPreferences(env, object, codecConfigArray);
diff --git a/android/app/jni/com_android_bluetooth_a2dp_sink.cpp b/android/app/jni/com_android_bluetooth_a2dp_sink.cpp
index 8e9e1ea..a5a8048 100644
--- a/android/app/jni/com_android_bluetooth_a2dp_sink.cpp
+++ b/android/app/jni/com_android_bluetooth_a2dp_sink.cpp
@@ -173,8 +173,7 @@
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
log::info("{}", bd_addr);
bt_status_t status = btif_av_sink_connect(bd_addr);
@@ -193,8 +192,7 @@
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
log::info("{}", bd_addr);
bt_status_t status = btif_av_sink_disconnect(bd_addr);
@@ -221,8 +219,7 @@
return JNI_FALSE;
}
- RawAddress rawAddress;
- rawAddress.FromOctets(reinterpret_cast<uint8_t*>(addr));
+ RawAddress rawAddress = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
log::info("{}", rawAddress);
bt_status_t status = btif_av_sink_set_active_device(rawAddress);
diff --git a/android/app/jni/com_android_bluetooth_avrcp_controller.cpp b/android/app/jni/com_android_bluetooth_avrcp_controller.cpp
index ddf0730..8307eb3 100644
--- a/android/app/jni/com_android_bluetooth_avrcp_controller.cpp
+++ b/android/app/jni/com_android_bluetooth_avrcp_controller.cpp
@@ -803,8 +803,7 @@
return JNI_FALSE;
}
- RawAddress rawAddress;
- rawAddress.FromOctets((uint8_t*)addr);
+ RawAddress rawAddress = RawAddress::FromOctets((uint8_t*)addr);
bt_status_t status = sBluetoothAvrcpInterface->send_pass_through_cmd(
rawAddress, (uint8_t)key_code, (uint8_t)key_state);
if (status != BT_STATUS_SUCCESS) {
@@ -831,8 +830,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress rawAddress;
- rawAddress.FromOctets((uint8_t*)addr);
+ RawAddress rawAddress = RawAddress::FromOctets((uint8_t*)addr);
bt_status_t status = sBluetoothAvrcpInterface->send_group_navigation_cmd(
rawAddress, (uint8_t)key_code, (uint8_t)key_state);
@@ -879,8 +877,7 @@
pAttrs[i] = (uint8_t)attr[i];
pAttrsVal[i] = (uint8_t)attr_val[i];
}
- RawAddress rawAddress;
- rawAddress.FromOctets((uint8_t*)addr);
+ RawAddress rawAddress = RawAddress::FromOctets((uint8_t*)addr);
bt_status_t status = sBluetoothAvrcpInterface->set_player_app_setting_cmd(
rawAddress, (uint8_t)num_attrib, pAttrs, pAttrsVal);
@@ -907,8 +904,7 @@
}
log::info("sBluetoothAvrcpInterface: {}", std::format_ptr(sBluetoothAvrcpInterface));
- RawAddress rawAddress;
- rawAddress.FromOctets((uint8_t*)addr);
+ RawAddress rawAddress = RawAddress::FromOctets((uint8_t*)addr);
bt_status_t status =
sBluetoothAvrcpInterface->set_volume_rsp(rawAddress, (uint8_t)abs_vol, (uint8_t)label);
@@ -930,8 +926,7 @@
return;
}
log::info("sBluetoothAvrcpInterface: {}", std::format_ptr(sBluetoothAvrcpInterface));
- RawAddress rawAddress;
- rawAddress.FromOctets((uint8_t*)addr);
+ RawAddress rawAddress = RawAddress::FromOctets((uint8_t*)addr);
bt_status_t status = sBluetoothAvrcpInterface->register_abs_vol_rsp(
rawAddress, (btrc_notification_type_t)rsp_type, (uint8_t)abs_vol, (uint8_t)label);
@@ -953,8 +948,7 @@
return;
}
log::verbose("sBluetoothAvrcpInterface: {}", std::format_ptr(sBluetoothAvrcpInterface));
- RawAddress rawAddress;
- rawAddress.FromOctets((uint8_t*)addr);
+ RawAddress rawAddress = RawAddress::FromOctets((uint8_t*)addr);
bt_status_t status = sBluetoothAvrcpInterface->get_current_metadata_cmd(rawAddress);
if (status != BT_STATUS_SUCCESS) {
@@ -975,8 +969,7 @@
return;
}
log::verbose("sBluetoothAvrcpInterface: {}", std::format_ptr(sBluetoothAvrcpInterface));
- RawAddress rawAddress;
- rawAddress.FromOctets((uint8_t*)addr);
+ RawAddress rawAddress = RawAddress::FromOctets((uint8_t*)addr);
bt_status_t status = sBluetoothAvrcpInterface->get_playback_state_cmd(rawAddress);
if (status != BT_STATUS_SUCCESS) {
@@ -996,8 +989,7 @@
return;
}
log::verbose("sBluetoothAvrcpInterface: {}", std::format_ptr(sBluetoothAvrcpInterface));
- RawAddress rawAddress;
- rawAddress.FromOctets((uint8_t*)addr);
+ RawAddress rawAddress = RawAddress::FromOctets((uint8_t*)addr);
bt_status_t status = sBluetoothAvrcpInterface->get_now_playing_list_cmd(rawAddress, start, end);
if (status != BT_STATUS_SUCCESS) {
@@ -1018,8 +1010,7 @@
return;
}
log::verbose("sBluetoothAvrcpInterface: {}", std::format_ptr(sBluetoothAvrcpInterface));
- RawAddress rawAddress;
- rawAddress.FromOctets((uint8_t*)addr);
+ RawAddress rawAddress = RawAddress::FromOctets((uint8_t*)addr);
bt_status_t status = sBluetoothAvrcpInterface->get_folder_list_cmd(rawAddress, start, end);
if (status != BT_STATUS_SUCCESS) {
@@ -1039,8 +1030,7 @@
return;
}
log::info("sBluetoothAvrcpInterface: {}", std::format_ptr(sBluetoothAvrcpInterface));
- RawAddress rawAddress;
- rawAddress.FromOctets((uint8_t*)addr);
+ RawAddress rawAddress = RawAddress::FromOctets((uint8_t*)addr);
bt_status_t status = sBluetoothAvrcpInterface->get_player_list_cmd(rawAddress, start, end);
if (status != BT_STATUS_SUCCESS) {
@@ -1061,8 +1051,7 @@
}
log::info("sBluetoothAvrcpInterface: {}", std::format_ptr(sBluetoothAvrcpInterface));
- RawAddress rawAddress;
- rawAddress.FromOctets((uint8_t*)addr);
+ RawAddress rawAddress = RawAddress::FromOctets((uint8_t*)addr);
bt_status_t status = sBluetoothAvrcpInterface->change_folder_path_cmd(
rawAddress, (uint8_t)direction, (uint8_t*)&uid);
@@ -1081,8 +1070,7 @@
jniThrowIOException(env, EINVAL);
return;
}
- RawAddress rawAddress;
- rawAddress.FromOctets((uint8_t*)addr);
+ RawAddress rawAddress = RawAddress::FromOctets((uint8_t*)addr);
log::info("sBluetoothAvrcpInterface: {}", std::format_ptr(sBluetoothAvrcpInterface));
bt_status_t status = sBluetoothAvrcpInterface->set_browsed_player_cmd(rawAddress, (uint16_t)id);
@@ -1102,8 +1090,7 @@
jniThrowIOException(env, EINVAL);
return;
}
- RawAddress rawAddress;
- rawAddress.FromOctets((uint8_t*)addr);
+ RawAddress rawAddress = RawAddress::FromOctets((uint8_t*)addr);
log::info("sBluetoothAvrcpInterface: {}", std::format_ptr(sBluetoothAvrcpInterface));
bt_status_t status = sBluetoothAvrcpInterface->set_addressed_player_cmd(rawAddress, (uint16_t)id);
@@ -1125,8 +1112,7 @@
return;
}
- RawAddress rawAddress;
- rawAddress.FromOctets((uint8_t*)addr);
+ RawAddress rawAddress = RawAddress::FromOctets((uint8_t*)addr);
log::info("sBluetoothAvrcpInterface: {}", std::format_ptr(sBluetoothAvrcpInterface));
bt_status_t status = sBluetoothAvrcpInterface->play_item_cmd(
diff --git a/android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp b/android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp
index edcb4a8..4729865 100644
--- a/android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp
+++ b/android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp
@@ -1414,8 +1414,7 @@
return JNI_FALSE;
}
- RawAddress addr_obj = {};
- addr_obj.FromOctets(reinterpret_cast<uint8_t*>(addr));
+ RawAddress addr_obj = RawAddress::FromOctets(reinterpret_cast<uint8_t*>(addr));
env->ReleaseByteArrayElements(address, addr, 0);
// Convert P192 data from Java POJO to C Struct
@@ -1751,8 +1750,7 @@
jniThrowIOException(env, EINVAL);
return env->NewByteArray(0);
}
- RawAddress addr_obj = {};
- addr_obj.FromOctets(reinterpret_cast<uint8_t*>(addr));
+ RawAddress addr_obj = RawAddress::FromOctets(reinterpret_cast<uint8_t*>(addr));
env->ReleaseByteArrayElements(address, addr, 0);
std::string output = sBluetoothInterface->obfuscate_address(addr_obj);
jsize output_size = output.size() * sizeof(char);
@@ -1889,8 +1887,7 @@
jniThrowIOException(env, EINVAL);
return 0;
}
- RawAddress addr_obj = {};
- addr_obj.FromOctets(reinterpret_cast<uint8_t*>(addr));
+ RawAddress addr_obj = RawAddress::FromOctets(reinterpret_cast<uint8_t*>(addr));
env->ReleaseByteArrayElements(address, addr, 0);
return sBluetoothInterface->get_metric_id(addr_obj);
}
@@ -1907,8 +1904,7 @@
return false;
}
- RawAddress addr_obj = {};
- addr_obj.FromOctets(reinterpret_cast<uint8_t*>(addr));
+ RawAddress addr_obj = RawAddress::FromOctets(reinterpret_cast<uint8_t*>(addr));
env->ReleaseByteArrayElements(address, addr, 0);
sBluetoothInterface->allow_low_latency_audio(allowed, addr_obj);
return true;
@@ -1925,8 +1921,7 @@
jniThrowIOException(env, EINVAL);
return;
}
- RawAddress addr_obj = {};
- addr_obj.FromOctets(reinterpret_cast<uint8_t*>(addr));
+ RawAddress addr_obj = RawAddress::FromOctets(reinterpret_cast<uint8_t*>(addr));
env->ReleaseByteArrayElements(address, addr, 0);
if (value == NULL) {
@@ -2171,8 +2166,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress addr_obj = {};
- addr_obj.FromOctets(reinterpret_cast<uint8_t*>(addr));
+ RawAddress addr_obj = RawAddress::FromOctets(reinterpret_cast<uint8_t*>(addr));
env->ReleaseByteArrayElements(address, addr, 0);
return sBluetoothInterface->disconnect_acl(addr_obj, transport);
diff --git a/android/app/jni/com_android_bluetooth_hfp.cpp b/android/app/jni/com_android_bluetooth_hfp.cpp
index 64d8b5c..da8a8ee 100644
--- a/android/app/jni/com_android_bluetooth_hfp.cpp
+++ b/android/app/jni/com_android_bluetooth_hfp.cpp
@@ -559,8 +559,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
log::info("device {}", bd_addr);
bt_status_t status = sBluetoothHfpInterface->Connect(bd_addr);
@@ -583,8 +582,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
log::info("device {}", bd_addr);
bt_status_t status = sBluetoothHfpInterface->Disconnect(bd_addr);
@@ -607,8 +605,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
log::info("device {}", bd_addr);
bt_status_t status = sBluetoothHfpInterface->ConnectAudio(bd_addr, 0);
@@ -631,8 +628,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
log::info("device {}", bd_addr);
bt_status_t status = sBluetoothHfpInterface->DisconnectAudio(bd_addr);
@@ -656,8 +652,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpInterface->isNoiseReductionSupported(bd_addr);
env->ReleaseByteArrayElements(address, addr, 0);
@@ -677,8 +672,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpInterface->isVoiceRecognitionSupported(bd_addr);
env->ReleaseByteArrayElements(address, addr, 0);
@@ -698,8 +692,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpInterface->StartVoiceRecognition(bd_addr, sendResult);
if (status != BT_STATUS_SUCCESS) {
@@ -721,8 +714,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpInterface->StopVoiceRecognition(bd_addr);
if (status != BT_STATUS_SUCCESS) {
@@ -745,8 +737,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpInterface->VolumeControl(
(bluetooth::headset::bthf_volume_type_t)volume_type, volume, bd_addr);
@@ -771,8 +762,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpInterface->DeviceStatusNotification(
(bluetooth::headset::bthf_network_state_t)network_state,
@@ -797,8 +787,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
const char* operator_name = env->GetStringUTFChars(operator_str, nullptr);
bt_status_t status = sBluetoothHfpInterface->CopsResponse(operator_name, bd_addr);
@@ -824,8 +813,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpInterface->CindResponse(
service, num_active, num_held, (bluetooth::headset::bthf_call_state_t)call_state, signal,
@@ -850,8 +838,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
const char* response = env->GetStringUTFChars(response_str, nullptr);
bt_status_t status = sBluetoothHfpInterface->FormattedAtResponse(response, bd_addr);
@@ -876,8 +863,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpInterface->AtResponse(
(bluetooth::headset::bthf_at_response_t)response_code, cmee_code, bd_addr);
@@ -906,8 +892,7 @@
if (number_str) {
number = env->GetStringUTFChars(number_str, nullptr);
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpInterface->ClccResponse(
index, (bluetooth::headset::bthf_call_direction_t)dir,
@@ -945,8 +930,7 @@
if (name_str != nullptr) {
name = env->GetStringUTFChars(name_str, nullptr);
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpInterface->PhoneStateChange(
num_active, num_held, (bluetooth::headset::bthf_call_state_t)call_state, number,
@@ -988,8 +972,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpInterface->SendBsir(value == JNI_TRUE, bd_addr);
if (status != BT_STATUS_SUCCESS) {
@@ -1011,8 +994,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpInterface->SetActiveDevice(bd_addr);
if (status != BT_STATUS_SUCCESS) {
@@ -1035,8 +1017,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t ret = sBluetoothHfpInterface->EnableSwb(
(bluetooth::headset::bthf_swb_codec_t)swbCodec, (bool)enable, bd_addr);
diff --git a/android/app/jni/com_android_bluetooth_hfpclient.cpp b/android/app/jni/com_android_bluetooth_hfpclient.cpp
index 1e35cad..e18340e 100644
--- a/android/app/jni/com_android_bluetooth_hfpclient.cpp
+++ b/android/app/jni/com_android_bluetooth_hfpclient.cpp
@@ -562,8 +562,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpClientInterface->connect(bd_addr);
if (status != BT_STATUS_SUCCESS) {
@@ -584,8 +583,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpClientInterface->disconnect(bd_addr);
if (status != BT_STATUS_SUCCESS) {
@@ -606,8 +604,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpClientInterface->connect_audio(bd_addr);
if (status != BT_STATUS_SUCCESS) {
@@ -628,8 +625,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpClientInterface->disconnect_audio(bd_addr);
if (status != BT_STATUS_SUCCESS) {
@@ -650,8 +646,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpClientInterface->start_voice_recognition(bd_addr);
if (status != BT_STATUS_SUCCESS) {
@@ -672,8 +667,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpClientInterface->stop_voice_recognition(bd_addr);
if (status != BT_STATUS_SUCCESS) {
@@ -695,8 +689,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpClientInterface->volume_control(
bd_addr, (bthf_client_volume_type_t)volume_type, volume);
@@ -724,8 +717,7 @@
if (number_str != nullptr) {
number = env->GetStringUTFChars(number_str, nullptr);
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpClientInterface->dial(bd_addr, number == nullptr ? "" : number);
@@ -751,8 +743,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpClientInterface->dial_memory(bd_addr, (int)location);
if (status != BT_STATUS_SUCCESS) {
@@ -775,8 +766,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpClientInterface->handle_call_action(
bd_addr, (bthf_client_call_action_t)action, (int)index);
@@ -799,8 +789,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpClientInterface->query_current_calls(bd_addr);
@@ -823,8 +812,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpClientInterface->query_current_operator_name(bd_addr);
if (status != BT_STATUS_SUCCESS) {
@@ -847,8 +835,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpClientInterface->retrieve_subscriber_info(bd_addr);
if (status != BT_STATUS_SUCCESS) {
@@ -870,8 +857,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpClientInterface->send_dtmf(bd_addr, (char)code);
if (status != BT_STATUS_SUCCESS) {
@@ -894,8 +880,7 @@
jniThrowIOException(env, EINVAL);
return JNI_FALSE;
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpClientInterface->request_last_voice_tag_number(bd_addr);
@@ -923,8 +908,7 @@
if (arg_str != NULL) {
arg = env->GetStringUTFChars(arg_str, NULL);
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpClientInterface->send_at_cmd(bd_addr, cmd, val1, val2, arg);
@@ -957,8 +941,7 @@
if (arg_str != NULL) {
arg = env->GetStringUTFChars(arg_str, NULL);
}
- RawAddress bd_addr;
- bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
+ RawAddress bd_addr = RawAddress::FromOctets(reinterpret_cast<const uint8_t*>(addr));
bt_status_t status = sBluetoothHfpClientInterface->send_android_at(bd_addr, arg);
diff --git a/system/bta/le_audio/broadcaster/state_machine_test.cc b/system/bta/le_audio/broadcaster/state_machine_test.cc
index bec8c8e..923f5b9 100644
--- a/system/bta/le_audio/broadcaster/state_machine_test.cc
+++ b/system/bta/le_audio/broadcaster/state_machine_test.cc
@@ -156,9 +156,7 @@
.WillByDefault(
[](uint8_t /*inst_id*/, ::BleAdvertiserInterface::GetAddressCallback cb) {
uint8_t address_type = 0x02;
- RawAddress address;
- const uint8_t addr[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
- address.FromOctets(addr);
+ RawAddress address({0x11, 0x22, 0x33, 0x44, 0x55, 0x66});
cb.Run(address_type, address);
});
diff --git a/system/types/include/bluetooth/types/address.h b/system/types/include/bluetooth/types/address.h
index e99f774..11d42d6 100644
--- a/system/types/include/bluetooth/types/address.h
+++ b/system/types/include/bluetooth/types/address.h
@@ -59,7 +59,7 @@
// Copies |from| raw Bluetooth address octets to the local object.
// Returns the number of copied octets - should be always RawAddress::kLength
- size_t FromOctets(const uint8_t* from);
+ static RawAddress FromOctets(const uint8_t* from);
static bool IsValidAddress(const std::string& address);
diff --git a/system/types/src/address.cc b/system/types/src/address.cc
index 01017a6..d3bde39 100644
--- a/system/types/src/address.cc
+++ b/system/types/src/address.cc
@@ -84,9 +84,10 @@
return RawAddress(address);
}
-size_t RawAddress::FromOctets(const uint8_t* from) {
- std::copy(from, from + kLength, address.begin());
- return kLength;
+RawAddress RawAddress::FromOctets(const uint8_t* from) {
+ std::array<uint8_t, 6> address;
+ std::copy(from, from + kLength, address.data());
+ return RawAddress(address);
}
bool RawAddress::IsValidAddress(const std::string& address) {
diff --git a/system/types/test/address_unittest.cc b/system/types/test/address_unittest.cc
index 1d5d13a..e1e815d 100644
--- a/system/types/test/address_unittest.cc
+++ b/system/types/test/address_unittest.cc
@@ -63,9 +63,7 @@
TEST(RawAddressUnittest, test_from_octets) {
static const uint8_t test_addr_array[] = {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc};
- RawAddress bdaddr;
- size_t expected_result = RawAddress::kLength;
- ASSERT_EQ(expected_result, bdaddr.FromOctets(test_addr_array));
+ RawAddress bdaddr = RawAddress::FromOctets(test_addr_array);
ASSERT_EQ(0x12, bdaddr.address[0]);
ASSERT_EQ(0x34, bdaddr.address[1]);