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

Commit 01a659f5 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "HFP: Send caller ID in +CLIP command (3/4)"

parents ce60db8e cea4d84b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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);
+3 −23
Original line number Diff line number Diff line
@@ -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
+6 −0
Original line number Diff line number Diff line
@@ -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
+47 −15
Original line number Diff line number Diff line
@@ -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<int>(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<int>(number_str.length() + name_str.length()) -
              static_cast<int>(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<int>(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 << "\"";

          if (res == BTA_AG_CALL_WAIT_RES)
            snprintf(&ag_res.str[xx], sizeof(ag_res.str) - xx, ",%d", type);
          // 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<uint16_t>(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 || 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:
+2 −0
Original line number Diff line number Diff line
@@ -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;

  /**