From 3d5f9242be6c4ba8a9621bdec8436d10a20649eb Mon Sep 17 00:00:00 2001 From: Benson Li Date: Tue, 17 Jul 2018 18:05:16 +0800 Subject: [PATCH] HFP: Send caller ID in +CLIP command (3/4) * Append caller display name in ag_reslut data if there is name in CALL_STATE_INCOMING state * Process all clip data and store the formatted string to ag_result data Bug: 111378831 Test: runtest bluetooth, runtest -x BluetoothPhoneServiceTest.java Change-Id: Ief48ed9cb5e0b32274624a90799ab9922dbd656e --- binder/android/bluetooth/IBluetoothHeadset.aidl | 2 +- bta/ag/bta_ag_cmd.cc | 26 ++--------- bta/include/bta_ag_api.h | 6 +++ btif/src/btif_hf.cc | 62 +++++++++++++++++++------ include/hardware/bluetooth_headset_interface.h | 2 + 5 files changed, 59 insertions(+), 39 deletions(-) diff --git a/binder/android/bluetooth/IBluetoothHeadset.aidl b/binder/android/bluetooth/IBluetoothHeadset.aidl index f8dfb6543..0f6954cd1 100644 --- a/binder/android/bluetooth/IBluetoothHeadset.aidl +++ b/binder/android/bluetooth/IBluetoothHeadset.aidl @@ -53,7 +53,7 @@ interface IBluetoothHeadset { void setForceScoAudio(boolean forced); boolean startScoUsingVirtualVoiceCall(); boolean stopScoUsingVirtualVoiceCall(); - oneway void phoneStateChanged(int numActive, int numHeld, int callState, String number, int type); + oneway void phoneStateChanged(int numActive, int numHeld, int callState, String number, int type, String name); void clccResponse(int index, int direction, int status, int mode, boolean mpty, String number, int type); boolean setActiveDevice(in BluetoothDevice device); diff --git a/bta/ag/bta_ag_cmd.cc b/bta/ag/bta_ag_cmd.cc index 763fabd0f..a1d372828 100644 --- a/bta/ag/bta_ag_cmd.cc +++ b/bta/ag/bta_ag_cmd.cc @@ -47,12 +47,6 @@ /* Invalid Chld command */ #define BTA_AG_INVALID_CHLD 255 -/* clip type constants */ -#define BTA_AG_CLIP_TYPE_MIN 128 -#define BTA_AG_CLIP_TYPE_MAX 175 -#define BTA_AG_CLIP_TYPE_DEFAULT 129 -#define BTA_AG_CLIP_TYPE_VOIP 255 - #define COLON_IDX_4_VGSVGM 4 /* Local events which will not trigger a higher layer callback */ @@ -1430,24 +1424,10 @@ void bta_ag_hfp_result(tBTA_AG_SCB* p_scb, const tBTA_AG_API_RESULT& result) { /* tell sys to stop av if any */ bta_sys_sco_use(BTA_ID_AG, p_scb->app_id, p_scb->peer_addr); - /* Store caller id string. - * Append type info at the end. - * Make sure a valid type info is passed. - * Otherwise add 129 as default type */ - uint16_t clip_type = result.data.num; - if ((clip_type < BTA_AG_CLIP_TYPE_MIN) || - (clip_type > BTA_AG_CLIP_TYPE_MAX)) { - if (clip_type != BTA_AG_CLIP_TYPE_VOIP) { - clip_type = BTA_AG_CLIP_TYPE_DEFAULT; - } - } - - APPL_TRACE_DEBUG("CLIP type :%d", clip_type); p_scb->clip[0] = 0; - if (result.data.str[0] != 0) - snprintf(p_scb->clip, sizeof(p_scb->clip), "%s,%d", result.data.str, - clip_type); - + if (result.data.str[0] != 0) { + snprintf(p_scb->clip, sizeof(p_scb->clip), "%s", result.data.str); + } /* send callsetup indicator */ if (p_scb->post_sco == BTA_AG_POST_SCO_CALL_END) { /* Need to sent 2 callsetup IND's(Call End and Incoming call) after SCO diff --git a/bta/include/bta_ag_api.h b/bta/include/bta_ag_api.h index b968ae66b..c5d4f3619 100644 --- a/bta/include/bta_ag_api.h +++ b/bta/include/bta_ag_api.h @@ -264,6 +264,12 @@ typedef uint16_t tBTA_AG_PEER_CODEC; #define BTA_AG_BTRH_READ 3 /* Read the current value */ #define BTA_AG_BTRH_NO_RESP 4 /* Not in RH States (reply to read) */ +/* clip type constants */ +#define BTA_AG_CLIP_TYPE_MIN 128 +#define BTA_AG_CLIP_TYPE_MAX 175 +#define BTA_AG_CLIP_TYPE_DEFAULT 129 +#define BTA_AG_CLIP_TYPE_VOIP 255 + /* ASCII character string of arguments to the AT command or result */ #ifndef BTA_AG_AT_MAX_LEN #define BTA_AG_AT_MAX_LEN 256 diff --git a/btif/src/btif_hf.cc b/btif/src/btif_hf.cc index ea55d2a0b..e0e9515ec 100644 --- a/btif/src/btif_hf.cc +++ b/btif/src/btif_hf.cc @@ -700,7 +700,7 @@ class HeadsetInterface : Interface { bt_status_t PhoneStateChange(int num_active, int num_held, bthf_call_state_t call_setup_state, const char* number, bthf_call_addrtype_t type, - RawAddress* bd_addr) override; + const char* name, RawAddress* bd_addr) override; void Cleanup() override; bt_status_t SetScoAllowed(bool value) override; @@ -1043,7 +1043,8 @@ bt_status_t HeadsetInterface::ClccResponse( bt_status_t HeadsetInterface::PhoneStateChange( int num_active, int num_held, bthf_call_state_t call_setup_state, - const char* number, bthf_call_addrtype_t type, RawAddress* bd_addr) { + const char* number, bthf_call_addrtype_t type, const char* name, + RawAddress* bd_addr) { CHECK_BTHF_INIT(); if (!bd_addr) { BTIF_TRACE_WARNING("%s: bd_addr is null", __func__); @@ -1175,22 +1176,53 @@ bt_status_t HeadsetInterface::PhoneStateChange( } } if (number) { - int xx = 0; - if ((type == BTHF_CALL_ADDRTYPE_INTERNATIONAL) && (*number != '+')) - xx = snprintf(ag_res.str, sizeof(ag_res.str), "\"+%s\"", number); - else - xx = snprintf(ag_res.str, sizeof(ag_res.str), "\"%s\"", number); - ag_res.num = type; - // 5 = [,][3_digit_type][null_terminator] - if (xx > static_cast(sizeof(ag_res.str) - 5)) { + std::ostringstream call_number_stream; + if ((type == BTHF_CALL_ADDRTYPE_INTERNATIONAL) && (*number != '+')) { + call_number_stream << "\"+"; + } else { + call_number_stream << "\""; + } + + std::string name_str; + if (name) { + name_str.append(name); + } + std::string number_str(number); + // 13 = ["][+]["][,][3_digit_type][,,,]["]["][null_terminator] + int overflow_size = + 13 + static_cast(number_str.length() + name_str.length()) - + static_cast(sizeof(ag_res.str)); + if (overflow_size > 0) { android_errorWriteLog(0x534e4554, "79431031"); - xx = sizeof(ag_res.str) - 5; - // Null terminating the string - memset(&ag_res.str[xx], 0, 5); + int extra_overflow_size = + overflow_size - static_cast(name_str.length()); + if (extra_overflow_size > 0) { + number_str.resize(number_str.length() - extra_overflow_size); + name_str.clear(); + } else { + name_str.resize(name_str.length() - overflow_size); + } + } + call_number_stream << number_str << "\""; + + // Store caller id string and append type info. + // Make sure type info is valid, otherwise add 129 as default type + ag_res.num = static_cast(type); + if ((ag_res.num < BTA_AG_CLIP_TYPE_MIN) || + (ag_res.num > BTA_AG_CLIP_TYPE_MAX)) { + if (ag_res.num != BTA_AG_CLIP_TYPE_VOIP) { + ag_res.num = BTA_AG_CLIP_TYPE_DEFAULT; + } } - if (res == BTA_AG_CALL_WAIT_RES) - snprintf(&ag_res.str[xx], sizeof(ag_res.str) - xx, ",%d", type); + if (res == BTA_AG_CALL_WAIT_RES || name_str.empty()) { + call_number_stream << "," << std::to_string(ag_res.num); + } else { + call_number_stream << "," << std::to_string(ag_res.num) << ",,,\"" + << name_str << "\""; + } + snprintf(ag_res.str, sizeof(ag_res.str), "%s", + call_number_stream.str().c_str()); } break; case BTHF_CALL_STATE_DIALING: diff --git a/include/hardware/bluetooth_headset_interface.h b/include/hardware/bluetooth_headset_interface.h index a3e0e37d3..8527919a9 100644 --- a/include/hardware/bluetooth_headset_interface.h +++ b/include/hardware/bluetooth_headset_interface.h @@ -195,6 +195,7 @@ class Interface { * @param call_setup_state current call setup state * @param number phone number of the call * @param type type of the call + * @param name caller display name * @param bd_addr remote device address * @return BT_STATUS_SUCCESS on success */ @@ -202,6 +203,7 @@ class Interface { bthf_call_state_t call_setup_state, const char* number, bthf_call_addrtype_t type, + const char* name, RawAddress* bd_addr) = 0; /** -- 2.11.0