OSDN Git Service

HFP: Fix static check errors
authorJack He <siyuanh@google.com>
Tue, 12 Dec 2017 03:49:30 +0000 (19:49 -0800)
committerJack He <siyuanh@google.com>
Thu, 14 Dec 2017 00:10:11 +0000 (00:10 +0000)
* In bta/ag and btif/btif_hf.cc
* Simplify boolean values
* Use nullptr intead of NULL
* Use C++ style include headers instead of C style ones
* Remove unused struct definitions
* Remove unused code from bta_ag_ci.h/cc
* Use range based for-loop when it can be converted automatically
* Use C++ style zero-initialization instead of memset so that non-POD
  members of structs can be initialized properly
* Use "" to initliaze char array since the rest of the array will be
  zero padded if the array is assigned to a shorter string than its
  length

Bug: 68340193
Test: make, connect to HFP enabled device
Change-Id: I25c1e48ca1cb40629b9b60243ec462f498d8fc24

17 files changed:
bta/Android.bp
bta/ag/bta_ag_act.cc
bta/ag/bta_ag_api.cc
bta/ag/bta_ag_at.cc
bta/ag/bta_ag_cfg.cc
bta/ag/bta_ag_ci.cc [deleted file]
bta/ag/bta_ag_cmd.cc
bta/ag/bta_ag_int.h
bta/ag/bta_ag_main.cc
bta/ag/bta_ag_rfc.cc
bta/ag/bta_ag_sco.cc
bta/ag/bta_ag_sdp.cc
bta/include/bta_ag_api.h
bta/include/bta_ag_ci.h [deleted file]
btif/co/bta_ag_co.cc
btif/src/btif_hf.cc
btif/src/btif_rc.cc

index 98f8946..f7ea8cf 100644 (file)
@@ -37,7 +37,6 @@ cc_library_static {
         "ag/bta_ag_api.cc",
         "ag/bta_ag_at.cc",
         "ag/bta_ag_cfg.cc",
-        "ag/bta_ag_ci.cc",
         "ag/bta_ag_cmd.cc",
         "ag/bta_ag_main.cc",
         "ag/bta_ag_rfc.cc",
index 0c69a51..98a4e26 100644 (file)
@@ -22,7 +22,7 @@
  *
  ******************************************************************************/
 
-#include <string.h>
+#include <cstring>
 
 #include "bta_ag_api.h"
 #include "bta_ag_co.h"
@@ -76,7 +76,7 @@ const tBTA_AG_ATCMD_CBACK bta_ag_at_cback_tbl[BTA_AG_NUM_IDX] = {
  ******************************************************************************/
 static void bta_ag_cback_open(tBTA_AG_SCB* p_scb, tBTA_AG_DATA* p_data,
                               tBTA_AG_STATUS status) {
-  tBTA_AG_OPEN open;
+  tBTA_AG_OPEN open = {};
 
   /* call app callback with open event */
   open.hdr.handle = bta_ag_scb_to_idx(p_scb);
@@ -106,7 +106,7 @@ static void bta_ag_cback_open(tBTA_AG_SCB* p_scb, tBTA_AG_DATA* p_data,
  *
  ******************************************************************************/
 void bta_ag_register(tBTA_AG_SCB* p_scb, tBTA_AG_DATA* p_data) {
-  tBTA_AG_REGISTER reg;
+  tBTA_AG_REGISTER reg = {};
 
   /* initialize control block */
   p_scb->reg_services = p_data->api_register.services;
@@ -181,7 +181,7 @@ void bta_ag_start_dereg(tBTA_AG_SCB* p_scb, tBTA_AG_DATA* p_data) {
  *
  ******************************************************************************/
 void bta_ag_start_open(tBTA_AG_SCB* p_scb, tBTA_AG_DATA* p_data) {
-  RawAddress pending_bd_addr;
+  RawAddress pending_bd_addr = {};
 
   /* store parameters */
   if (p_data) {
@@ -308,7 +308,7 @@ void bta_ag_disc_fail(tBTA_AG_SCB* p_scb, UNUSED_ATTR tBTA_AG_DATA* p_data) {
   p_scb->peer_addr = RawAddress::kEmpty;
 
   /* call open cback w. failure */
-  bta_ag_cback_open(p_scb, NULL, BTA_AG_FAIL_SDP);
+  bta_ag_cback_open(p_scb, nullptr, BTA_AG_FAIL_SDP);
 }
 
 /*******************************************************************************
@@ -353,7 +353,7 @@ void bta_ag_rfc_fail(tBTA_AG_SCB* p_scb, UNUSED_ATTR tBTA_AG_DATA* p_data) {
   bta_ag_start_servers(p_scb, p_scb->reg_services);
 
   /* call open cback w. failure */
-  bta_ag_cback_open(p_scb, NULL, BTA_AG_FAIL_RFCOMM);
+  bta_ag_cback_open(p_scb, nullptr, BTA_AG_FAIL_RFCOMM);
 }
 
 /*******************************************************************************
@@ -367,7 +367,7 @@ void bta_ag_rfc_fail(tBTA_AG_SCB* p_scb, UNUSED_ATTR tBTA_AG_DATA* p_data) {
  *
  ******************************************************************************/
 void bta_ag_rfc_close(tBTA_AG_SCB* p_scb, UNUSED_ATTR tBTA_AG_DATA* p_data) {
-  tBTA_AG_CLOSE close;
+  tBTA_AG_CLOSE close = {};
   tBTA_SERVICE_MASK services;
   int i, num_active_conn = 0;
 
@@ -386,8 +386,12 @@ void bta_ag_rfc_close(tBTA_AG_SCB* p_scb, UNUSED_ATTR tBTA_AG_DATA* p_data) {
   p_scb->hsp_version = HSP_VERSION_1_2;
   bta_ag_at_reinit(&p_scb->at_cb);
 
-  memset(&(p_scb->peer_hf_indicators), 0, sizeof(p_scb->peer_hf_indicators));
-  memset(&(p_scb->local_hf_indicators), 0, sizeof(p_scb->local_hf_indicators));
+  for (auto& peer_hf_indicator : p_scb->peer_hf_indicators) {
+    peer_hf_indicator = {};
+  }
+  for (auto& local_hf_indicator : p_scb->local_hf_indicators) {
+    local_hf_indicator = {};
+  }
 
   /* stop timers */
   alarm_cancel(p_scb->ring_timer);
@@ -421,7 +425,7 @@ void bta_ag_rfc_close(tBTA_AG_SCB* p_scb, UNUSED_ATTR tBTA_AG_DATA* p_data) {
     p_scb->conn_handle = 0;
 
     /* Make sure SCO state is BTA_AG_SCO_SHUTDOWN_ST */
-    bta_ag_sco_shutdown(p_scb, NULL);
+    bta_ag_sco_shutdown(p_scb, nullptr);
 
     /* Check if all the SLCs are down */
     for (i = 0; i < BTA_AG_NUM_SCB; i++) {
@@ -475,7 +479,7 @@ void bta_ag_rfc_open(tBTA_AG_SCB* p_scb, tBTA_AG_DATA* p_data) {
 
   bta_sys_conn_open(BTA_ID_AG, p_scb->app_id, p_scb->peer_addr);
 
-  bta_ag_cback_open(p_scb, NULL, BTA_AG_SUCCESS);
+  bta_ag_cback_open(p_scb, nullptr, BTA_AG_SUCCESS);
 
   if (p_scb->conn_service == BTA_AG_HFP) {
     /* if hfp start timer for service level conn */
@@ -501,7 +505,7 @@ void bta_ag_rfc_acp_open(tBTA_AG_SCB* p_scb, tBTA_AG_DATA* p_data) {
   uint16_t lcid;
   int i;
   tBTA_AG_SCB *ag_scb, *other_scb;
-  RawAddress dev_addr;
+  RawAddress dev_addr = {};
   int status;
 
   /* set role */
@@ -584,9 +588,7 @@ void bta_ag_rfc_acp_open(tBTA_AG_SCB* p_scb, tBTA_AG_DATA* p_data) {
  ******************************************************************************/
 void bta_ag_rfc_data(tBTA_AG_SCB* p_scb, UNUSED_ATTR tBTA_AG_DATA* p_data) {
   uint16_t len;
-  char buf[BTA_AG_RFC_READ_MAX];
-
-  memset(buf, 0, BTA_AG_RFC_READ_MAX);
+  char buf[BTA_AG_RFC_READ_MAX] = "";
 
   APPL_TRACE_DEBUG("%s", __func__);
 
@@ -740,7 +742,7 @@ void bta_ag_post_sco_close(tBTA_AG_SCB* p_scb, tBTA_AG_DATA* p_data) {
  ******************************************************************************/
 void bta_ag_svc_conn_open(tBTA_AG_SCB* p_scb,
                           UNUSED_ATTR tBTA_AG_DATA* p_data) {
-  tBTA_AG_CONN evt;
+  tBTA_AG_CONN evt = {};
 
   if (!p_scb->svc_conn) {
     /* set state variable */
@@ -811,7 +813,7 @@ void bta_ag_rcvd_slc_ready(tBTA_AG_SCB* p_scb,
   if (bta_ag_cb.parse_mode == BTA_AG_PASS_THROUGH) {
     /* In pass-through mode, BTA knows that SLC is ready only through call-in.
      */
-    bta_ag_svc_conn_open(p_scb, NULL);
+    bta_ag_svc_conn_open(p_scb, nullptr);
   }
 }
 
@@ -827,7 +829,7 @@ void bta_ag_rcvd_slc_ready(tBTA_AG_SCB* p_scb,
  ******************************************************************************/
 void bta_ag_setcodec(tBTA_AG_SCB* p_scb, tBTA_AG_DATA* p_data) {
   tBTA_AG_PEER_CODEC codec_type = p_data->api_setcodec.codec;
-  tBTA_AG_VAL val;
+  tBTA_AG_VAL val = {};
 
   /* Check if the requested codec type is valid */
   if ((codec_type != BTA_AG_CODEC_NONE) && (codec_type != BTA_AG_CODEC_CVSD) &&
index 57ba702..abd320d 100644 (file)
@@ -25,7 +25,7 @@
  ******************************************************************************/
 
 #include "bta_ag_api.h"
-#include <string.h>
+#include <cstring>
 #include "bt_common.h"
 #include "bta_ag_int.h"
 #include "bta_api.h"
@@ -53,8 +53,8 @@ static const tBTA_SYS_REG bta_ag_reg = {bta_ag_hdl_event, BTA_AgDisable};
 tBTA_STATUS BTA_AgEnable(tBTA_AG_PARSE_MODE parse_mode,
                          tBTA_AG_CBACK* p_cback) {
   /* Error if AG is already enabled, or AG is in the middle of disabling. */
-  for (int idx = 0; idx < BTA_AG_NUM_SCB; idx++) {
-    if (bta_ag_cb.scb[idx].in_use) {
+  for (const tBTA_AG_SCB& scb : bta_ag_cb.scb) {
+    if (scb.in_use) {
       APPL_TRACE_ERROR("BTA_AgEnable: FAILED, AG already enabled.");
       return BTA_FAILURE;
     }
@@ -84,7 +84,7 @@ tBTA_STATUS BTA_AgEnable(tBTA_AG_PARSE_MODE parse_mode,
  * Returns          void
  *
  ******************************************************************************/
-void BTA_AgDisable(void) {
+void BTA_AgDisable() {
   BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
 
   p_buf->event = BTA_AG_API_DISABLE_EVT;
index 1870d1c..ecd9053 100644 (file)
@@ -22,7 +22,7 @@
  *
  ******************************************************************************/
 
-#include <string.h>
+#include <cstring>
 
 #include "bt_common.h"
 #include "bta_ag_at.h"
@@ -43,7 +43,7 @@
  *
  *****************************************************************************/
 void bta_ag_at_init(tBTA_AG_AT_CB* p_cb) {
-  p_cb->p_cmd_buf = NULL;
+  p_cb->p_cmd_buf = nullptr;
   p_cb->cmd_pos = 0;
 }
 
@@ -129,7 +129,7 @@ void bta_ag_process_at(tBTA_AG_AT_CB* p_cb) {
         if (int_arg < (int16_t)p_cb->p_at_tbl[idx].min ||
             int_arg > (int16_t)p_cb->p_at_tbl[idx].max) {
           /* arg out of range; error */
-          (*p_cb->p_err_cback)((tBTA_AG_SCB*)p_cb->p_user, false, NULL);
+          (*p_cb->p_err_cback)((tBTA_AG_SCB*)p_cb->p_user, false, nullptr);
         } else {
           (*p_cb->p_cmd_cback)((tBTA_AG_SCB*)p_cb->p_user,
                                p_cb->p_at_tbl[idx].command_id, arg_type, p_arg,
@@ -143,7 +143,7 @@ void bta_ag_process_at(tBTA_AG_AT_CB* p_cb) {
     }
     /* else error */
     else {
-      (*p_cb->p_err_cback)((tBTA_AG_SCB*)p_cb->p_user, false, NULL);
+      (*p_cb->p_err_cback)((tBTA_AG_SCB*)p_cb->p_user, false, nullptr);
     }
   }
   /* else no match call error callback */
@@ -168,7 +168,7 @@ void bta_ag_at_parse(tBTA_AG_AT_CB* p_cb, char* p_buf, uint16_t len) {
   int i = 0;
   char* p_save;
 
-  if (p_cb->p_cmd_buf == NULL) {
+  if (p_cb->p_cmd_buf == nullptr) {
     p_cb->p_cmd_buf = (char*)osi_malloc(p_cb->cmd_max_len);
     p_cb->cmd_pos = 0;
   }
index 1bb6040..23da44d 100644 (file)
 const tBTA_AG_HF_IND bta_ag_local_hf_ind_cfg[] = {
     /* The first row contains the number of indicators. Need to be updated
        accordingly */
-    {BTA_AG_NUM_LOCAL_HF_IND, 0, 0, 0, 0},
+    {BTA_AG_NUM_LOCAL_HF_IND, false, false, 0, 0},
 
-    {1, 1, 1, 0,
+    {1, true, true, 0,
      1}, /* Enhanced Driver Status, supported, enabled, range 0 ~ 1 */
-    {2, 1, 1, 0,
+    {2, true, true, 0,
      100} /* Battery Level Status, supported, enabled, range 0 ~ 100 */
 };
 
diff --git a/bta/ag/bta_ag_ci.cc b/bta/ag/bta_ag_ci.cc
deleted file mode 100644 (file)
index ef16cab..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/******************************************************************************
- *
- *  Copyright 2003-2012 Broadcom Corporation
- *
- *  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.
- *
- ******************************************************************************/
-
-/******************************************************************************
- *
- *  This is the implementation file for audio gateway call-in functions.
- *
- ******************************************************************************/
-
-#include <string.h>
-
-#include "bt_common.h"
-#include "bta_ag_api.h"
-#include "bta_ag_ci.h"
-#include "bta_ag_int.h"
-#include "bta_api.h"
-
-/******************************************************************************
- *
- * Function         bta_ag_ci_rx_write
- *
- * Description      This function is called to send data to the AG when the AG
- *                  is configured for AT command pass-through.  The function
- *                  copies data to an event buffer and sends it.
- *
- * Returns          void
- *
- *****************************************************************************/
-void bta_ag_ci_rx_write(uint16_t handle, char* p_data, uint16_t len) {
-  uint16_t len_remaining = len;
-  char* p_data_area;
-
-  if (len > (RFCOMM_DATA_BUF_SIZE - sizeof(tBTA_AG_CI_RX_WRITE) - 1))
-    len = RFCOMM_DATA_BUF_SIZE - sizeof(tBTA_AG_CI_RX_WRITE) - 1;
-
-  while (len_remaining) {
-    if (len_remaining < len) len = len_remaining;
-
-    tBTA_AG_CI_RX_WRITE* p_buf =
-        (tBTA_AG_CI_RX_WRITE*)osi_malloc(sizeof(tBTA_AG_CI_RX_WRITE) + len + 1);
-    p_buf->hdr.event = BTA_AG_CI_RX_WRITE_EVT;
-    p_buf->hdr.layer_specific = handle;
-
-    p_data_area = (char*)(p_buf + 1); /* Point to data area after header */
-    strncpy(p_data_area, p_data, len);
-    p_data_area[len] = 0;
-
-    bta_sys_sendmsg(p_buf);
-
-    len_remaining -= len;
-    p_data += len;
-  }
-}
-
-/******************************************************************************
- *
- * Function         bta_ag_ci_slc_ready
- *
- * Description      This function is called to notify AG that SLC is up at
- *                  the application. This funcion is only used when the app
- *                  is running in pass-through mode.
- *
- * Returns          void
- *
- *****************************************************************************/
-void bta_ag_ci_slc_ready(uint16_t handle) {
-  tBTA_AG_DATA* p_buf = (tBTA_AG_DATA*)osi_malloc(sizeof(tBTA_AG_DATA));
-
-  p_buf->hdr.event = BTA_AG_CI_SLC_READY_EVT;
-  p_buf->hdr.layer_specific = handle;
-
-  bta_sys_sendmsg(p_buf);
-}
index 61d7969..2b9df64 100644 (file)
@@ -18,9 +18,9 @@
 
 #define LOG_TAG "bta_ag_cmd"
 
-#include <ctype.h>
-#include <stdio.h>
-#include <string.h>
+#include <cctype>
+#include <cstdio>
+#include <cstring>
 
 #include "bt_common.h"
 #include "bt_target.h"
@@ -173,7 +173,7 @@ static const tBTA_AG_RESULT* bta_ag_result_by_code(size_t code) {
        i != sizeof(bta_ag_result_tbl) / sizeof(bta_ag_result_tbl[0]); ++i) {
     if (code == bta_ag_result_tbl[i].result_id) return &bta_ag_result_tbl[i];
   }
-  return 0;
+  return nullptr;
 }
 
 const tBTA_AG_AT_CMD* bta_ag_at_tbl[BTA_AG_NUM_IDX] = {bta_ag_hsp_cmd,
@@ -215,15 +215,14 @@ static size_t bta_ag_indicator_by_result_code(size_t code) {
 static void bta_ag_send_result(tBTA_AG_SCB* p_scb, size_t code,
                                const char* p_arg, int16_t int_arg) {
   const tBTA_AG_RESULT* result = bta_ag_result_by_code(code);
-  if (result == 0) {
+  if (result == nullptr) {
     LOG_ERROR(LOG_TAG, "%s Unable to lookup result for code %zu", __func__,
               code);
     return;
   }
 
-  char buf[BTA_AG_AT_MAX_LEN + 16];
+  char buf[BTA_AG_AT_MAX_LEN + 16] = "";
   char* p = buf;
-  memset(buf, 0, sizeof(buf));
 
   /* init with \r\n */
   *p++ = '\r';
@@ -274,7 +273,7 @@ static void bta_ag_send_result(tBTA_AG_SCB* p_scb, size_t code,
  *
  ******************************************************************************/
 static void bta_ag_send_ok(tBTA_AG_SCB* p_scb) {
-  bta_ag_send_result(p_scb, BTA_AG_LOCAL_RES_OK, NULL, 0);
+  bta_ag_send_result(p_scb, BTA_AG_LOCAL_RES_OK, nullptr, 0);
 }
 
 /*******************************************************************************
@@ -291,9 +290,9 @@ static void bta_ag_send_ok(tBTA_AG_SCB* p_scb) {
 static void bta_ag_send_error(tBTA_AG_SCB* p_scb, int16_t errcode) {
   /* If HFP and extended audio gateway error codes are enabled */
   if (p_scb->conn_service == BTA_AG_HFP && p_scb->cmee_enabled)
-    bta_ag_send_result(p_scb, BTA_AG_LOCAL_RES_CMEE, NULL, errcode);
+    bta_ag_send_result(p_scb, BTA_AG_LOCAL_RES_CMEE, nullptr, errcode);
   else
-    bta_ag_send_result(p_scb, BTA_AG_LOCAL_RES_ERROR, NULL, 0);
+    bta_ag_send_result(p_scb, BTA_AG_LOCAL_RES_ERROR, nullptr, 0);
 }
 
 /*******************************************************************************
@@ -392,7 +391,7 @@ static bool bta_ag_parse_cmer(char* p_s, bool* p_enabled) {
     *p = 0;
     n[i] = utl_str2int(p_s);
     p_s = p + 1;
-    if (p_s == 0) {
+    if (p_s == nullptr) {
       break;
     }
   }
@@ -424,7 +423,6 @@ static bool bta_ag_parse_cmer(char* p_s, bool* p_enabled) {
  ******************************************************************************/
 static uint8_t bta_ag_parse_chld(UNUSED_ATTR tBTA_AG_SCB* p_scb, char* p_s) {
   uint8_t retval = 0;
-  int16_t idx = -1;
 
   if (!isdigit(p_s[0])) {
     return BTA_AG_INVALID_CHLD;
@@ -432,7 +430,7 @@ static uint8_t bta_ag_parse_chld(UNUSED_ATTR tBTA_AG_SCB* p_scb, char* p_s) {
 
   if (p_s[1] != 0) {
     /* p_idxstr++;  point to beginning of call number */
-    idx = utl_str2int(&p_s[1]);
+    int16_t idx = utl_str2int(&p_s[1]);
     if (idx != -1 && idx < 255) {
       retval = (uint8_t)idx;
     } else {
@@ -455,7 +453,6 @@ static uint8_t bta_ag_parse_chld(UNUSED_ATTR tBTA_AG_SCB* p_scb, char* p_s) {
 static tBTA_AG_PEER_CODEC bta_ag_parse_bac(tBTA_AG_SCB* p_scb, char* p_s) {
   tBTA_AG_PEER_CODEC retval = BTA_AG_CODEC_NONE;
   uint16_t uuid_codec;
-  bool cont = false; /* Continue processing */
   char* p;
 
   while (p_s) {
@@ -463,13 +460,12 @@ static tBTA_AG_PEER_CODEC bta_ag_parse_bac(tBTA_AG_SCB* p_scb, char* p_s) {
     for (p = p_s; *p != ',' && *p != 0; p++)
       ;
 
-    /* get integre value */
+    /* get integer value */
+    bool cont = false;  // Continue processing
     if (*p != 0) {
       *p = 0;
       cont = true;
-    } else
-      cont = false;
-
+    }
     uuid_codec = utl_str2int(p_s);
     switch (uuid_codec) {
       case UUID_CODEC_CVSD:
@@ -505,13 +501,11 @@ static tBTA_AG_PEER_CODEC bta_ag_parse_bac(tBTA_AG_SCB* p_scb, char* p_s) {
  ******************************************************************************/
 
 static void bta_ag_process_unat_res(char* unat_result) {
-  uint8_t str_leng;
-  uint8_t i = 0;
   uint8_t j = 0;
   uint8_t pairs_of_nl_cr;
   char trim_data[BTA_AG_AT_MAX_LEN];
 
-  str_leng = strlen(unat_result);
+  uint8_t str_leng = strlen(unat_result);
 
   /* If no extra CR and LF, just return */
   if (str_leng < 4) return;
@@ -521,19 +515,17 @@ static void bta_ag_process_unat_res(char* unat_result) {
          unat_result[str_leng - 2] == '\r' &&
          unat_result[str_leng - 1] == '\n') {
     pairs_of_nl_cr = 1;
-    for (i = 0; i < (str_leng - 4 * pairs_of_nl_cr); i++) {
+    for (int i = 0; i < (str_leng - 4 * pairs_of_nl_cr); i++) {
       trim_data[j++] = unat_result[i + pairs_of_nl_cr * 2];
     }
     /* Add EOF */
     trim_data[j] = '\0';
     str_leng = str_leng - 4;
     strlcpy(unat_result, trim_data, str_leng + 1);
-    i = 0;
     j = 0;
 
     if (str_leng < 4) return;
   }
-  return;
 }
 
 /*******************************************************************************
@@ -548,11 +540,7 @@ static void bta_ag_process_unat_res(char* unat_result) {
  ******************************************************************************/
 bool bta_ag_inband_enabled(tBTA_AG_SCB* p_scb) {
   /* if feature is enabled and no other scbs connected */
-  if (p_scb->inband_enabled && !bta_ag_other_scb_open(p_scb)) {
-    return true;
-  } else {
-    return false;
-  }
+  return p_scb->inband_enabled && !bta_ag_other_scb_open(p_scb);
 }
 
 /*******************************************************************************
@@ -566,7 +554,7 @@ bool bta_ag_inband_enabled(tBTA_AG_SCB* p_scb) {
  *
  ******************************************************************************/
 void bta_ag_send_call_inds(tBTA_AG_SCB* p_scb, tBTA_AG_RES result) {
-  uint8_t call = p_scb->call_ind;
+  uint8_t call;
 
   /* set new call and callsetup values based on BTA_AgResult */
   size_t callsetup = bta_ag_indicator_by_result_code(result);
@@ -603,7 +591,7 @@ void bta_ag_at_hsp_cback(tBTA_AG_SCB* p_scb, uint16_t command_id,
 
   bta_ag_send_ok(p_scb);
 
-  tBTA_AG_VAL val;
+  tBTA_AG_VAL val = {};
   val.hdr.handle = bta_ag_scb_to_idx(p_scb);
   val.hdr.app_id = p_scb->app_id;
   val.num = (uint16_t)int_arg;
@@ -678,9 +666,9 @@ static int bta_ag_find_hf_ind_by_id(tBTA_AG_HF_IND* p_hf_ind, int size,
  ******************************************************************************/
 static bool bta_ag_parse_bind_set(tBTA_AG_SCB* p_scb, tBTA_AG_VAL val) {
   char* p_token = strtok(val.str, ",");
-  if (p_token == NULL) return false;
+  if (p_token == nullptr) return false;
 
-  while (p_token != NULL) {
+  while (p_token != nullptr) {
     uint16_t rcv_ind_id = atoi(p_token);
     int index = bta_ag_find_empty_hf_ind(p_scb);
     if (index == -1) {
@@ -691,7 +679,7 @@ static bool bta_ag_parse_bind_set(tBTA_AG_SCB* p_scb, tBTA_AG_VAL val) {
     p_scb->peer_hf_indicators[index].ind_id = rcv_ind_id;
     APPL_TRACE_DEBUG("%s peer_hf_ind[%d] = %d", __func__, index, rcv_ind_id);
 
-    p_token = strtok(NULL, ",");
+    p_token = strtok(nullptr, ",");
   }
 
   return true;
@@ -708,8 +696,7 @@ static bool bta_ag_parse_bind_set(tBTA_AG_SCB* p_scb, tBTA_AG_VAL val) {
  *
  ******************************************************************************/
 static void bta_ag_bind_response(tBTA_AG_SCB* p_scb, uint8_t arg_type) {
-  char buffer[BTA_AG_AT_MAX_LEN];
-  memset(buffer, 0, BTA_AG_AT_MAX_LEN);
+  char buffer[BTA_AG_AT_MAX_LEN] = "";
 
   if (arg_type == BTA_AG_AT_TEST) {
     int index = 0;
@@ -757,7 +744,8 @@ static void bta_ag_bind_response(tBTA_AG_SCB* p_scb, uint8_t arg_type) {
         p += utl_itoa((uint16_t)p_scb->local_hf_indicators[i].is_enable, p);
 
         bta_ag_send_result(p_scb, BTA_AG_BIND_RES, buffer, 0);
-
+        // have to use memset here because assigning to "" will not zero
+        // initialize the rest of the buffer
         memset(buffer, 0, sizeof(buffer));
         p = buffer;
       } else {
@@ -769,7 +757,7 @@ static void bta_ag_bind_response(tBTA_AG_SCB* p_scb, uint8_t arg_type) {
     bta_ag_send_ok(p_scb);
 
     /* If the service level connection wan't already open, now it's open */
-    if (!p_scb->svc_conn) bta_ag_svc_conn_open(p_scb, NULL);
+    if (!p_scb->svc_conn) bta_ag_svc_conn_open(p_scb, nullptr);
   }
 }
 
@@ -787,7 +775,7 @@ static bool bta_ag_parse_biev_response(tBTA_AG_SCB* p_scb, tBTA_AG_VAL* val) {
   char* p_token = strtok(val->str, ",");
   uint16_t rcv_ind_id = atoi(p_token);
 
-  p_token = strtok(NULL, ",");
+  p_token = strtok(nullptr, ",");
   uint16_t rcv_ind_val = atoi(p_token);
 
   APPL_TRACE_DEBUG("%s BIEV indicator id %d, value %d", __func__, rcv_ind_id,
@@ -804,8 +792,8 @@ static bool bta_ag_parse_biev_response(tBTA_AG_SCB* p_scb, tBTA_AG_VAL* val) {
   int local_index = bta_ag_find_hf_ind_by_id(
       p_scb->local_hf_indicators, BTA_AG_MAX_NUM_LOCAL_HF_IND, rcv_ind_id);
   if (local_index == -1 ||
-      p_scb->local_hf_indicators[local_index].is_supported != true ||
-      p_scb->local_hf_indicators[local_index].is_enable != true) {
+      !p_scb->local_hf_indicators[local_index].is_supported ||
+      !p_scb->local_hf_indicators[local_index].is_enable) {
     APPL_TRACE_WARNING("%s indicator id %d not supported or disabled", __func__,
                        rcv_ind_id);
     return false;
@@ -836,11 +824,11 @@ static bool bta_ag_parse_biev_response(tBTA_AG_SCB* p_scb, tBTA_AG_VAL* val) {
  ******************************************************************************/
 void bta_ag_at_hfp_cback(tBTA_AG_SCB* p_scb, uint16_t cmd, uint8_t arg_type,
                          char* p_arg, int16_t int_arg) {
-  tBTA_AG_VAL val;
+  tBTA_AG_VAL val = {};
   tBTA_AG_SCB* ag_scb;
   uint32_t i, ind_id;
   uint32_t bia_masked_out;
-  if (p_arg == NULL) {
+  if (p_arg == nullptr) {
     APPL_TRACE_ERROR("%s: p_arg is null, send error and return", __func__);
     bta_ag_send_error(p_scb, BTA_AG_ERR_INV_CHAR_IN_TSTR);
     return;
@@ -849,7 +837,6 @@ void bta_ag_at_hfp_cback(tBTA_AG_SCB* p_scb, uint16_t cmd, uint8_t arg_type,
   APPL_TRACE_DEBUG("%s: AT command %d, arg_type %d, int_arg %d, arg %s",
                    __func__, cmd, arg_type, int_arg, p_arg);
 
-  memset(&val, 0, sizeof(tBTA_AG_VAL));
   val.hdr.handle = bta_ag_scb_to_idx(p_scb);
   val.hdr.app_id = p_scb->app_id;
   val.hdr.status = BTA_AG_SUCCESS;
@@ -946,7 +933,7 @@ void bta_ag_at_hfp_cback(tBTA_AG_SCB* p_scb, uint16_t cmd, uint8_t arg_type,
         bta_ag_send_ok(p_scb);
 
         /* if service level conn. not already open, now it's open */
-        bta_ag_svc_conn_open(p_scb, NULL);
+        bta_ag_svc_conn_open(p_scb, nullptr);
       } else {
         val.idx = bta_ag_parse_chld(p_scb, val.str);
 
@@ -1042,7 +1029,7 @@ void bta_ag_at_hfp_cback(tBTA_AG_SCB* p_scb, uint16_t cmd, uint8_t arg_type,
         if (!p_scb->svc_conn &&
             !((p_scb->features & BTA_AG_FEAT_3WAY) &&
               (p_scb->peer_features & BTA_AG_PEER_FEAT_3WAY))) {
-          bta_ag_svc_conn_open(p_scb, NULL);
+          bta_ag_svc_conn_open(p_scb, nullptr);
         }
       } else {
         bta_ag_send_error(p_scb, BTA_AG_ERR_INV_CHAR_IN_TSTR);
@@ -1089,7 +1076,8 @@ void bta_ag_at_hfp_cback(tBTA_AG_SCB* p_scb, uint16_t cmd, uint8_t arg_type,
                        p_scb->peer_features, features);
 
       /* send BRSF, send OK */
-      bta_ag_send_result(p_scb, BTA_AG_LOCAL_RES_BRSF, NULL, (int16_t)features);
+      bta_ag_send_result(p_scb, BTA_AG_LOCAL_RES_BRSF, nullptr,
+                         (int16_t)features);
       bta_ag_send_ok(p_scb);
       break;
     }
@@ -1112,7 +1100,7 @@ void bta_ag_at_hfp_cback(tBTA_AG_SCB* p_scb, uint16_t cmd, uint8_t arg_type,
           for (i = 0, ag_scb = &bta_ag_cb.scb[0]; i < BTA_AG_NUM_SCB;
                i++, ag_scb++) {
             if (ag_scb->in_use) {
-              bta_ag_send_result(ag_scb, BTA_AG_BTRH_RES, NULL, int_arg);
+              bta_ag_send_result(ag_scb, BTA_AG_BTRH_RES, nullptr, int_arg);
             }
           }
           bta_ag_send_ok(p_scb);
@@ -1246,10 +1234,7 @@ void bta_ag_at_hfp_cback(tBTA_AG_SCB* p_scb, uint16_t cmd, uint8_t arg_type,
       else
         codec_sent = p_scb->sco_codec;
 
-      if (codec_type == codec_sent)
-        bta_ag_sco_codec_nego(p_scb, true);
-      else
-        bta_ag_sco_codec_nego(p_scb, false);
+      bta_ag_sco_codec_nego(p_scb, codec_type == codec_sent);
 
       /* send final codec info to callback */
       val.num = codec_sent;
@@ -1257,7 +1242,7 @@ void bta_ag_at_hfp_cback(tBTA_AG_SCB* p_scb, uint16_t cmd, uint8_t arg_type,
     }
     case BTA_AG_LOCAL_EVT_BCC:
       bta_ag_send_ok(p_scb);
-      bta_ag_sco_open(p_scb, NULL);
+      bta_ag_sco_open(p_scb, nullptr);
       break;
 
     default:
@@ -1282,14 +1267,13 @@ void bta_ag_at_hfp_cback(tBTA_AG_SCB* p_scb, uint16_t cmd, uint8_t arg_type,
  *
  ******************************************************************************/
 void bta_ag_at_err_cback(tBTA_AG_SCB* p_scb, bool unknown, char* p_arg) {
-  tBTA_AG_VAL val;
-
   if (unknown && (!strlen(p_arg))) {
     APPL_TRACE_DEBUG("Empty AT cmd string received");
     bta_ag_send_ok(p_scb);
     return;
   }
 
+  tBTA_AG_VAL val = {};
   /* if unknown AT command and configured to pass these to app */
   if (unknown && (p_scb->features & BTA_AG_FEAT_UNAT)) {
     val.hdr.handle = bta_ag_scb_to_idx(p_scb);
@@ -1319,7 +1303,7 @@ void bta_ag_hsp_result(tBTA_AG_SCB* p_scb, tBTA_AG_API_RESULT* p_result) {
   switch (p_result->result) {
     case BTA_AG_SPK_RES:
     case BTA_AG_MIC_RES:
-      bta_ag_send_result(p_scb, p_result->result, NULL, p_result->data.num);
+      bta_ag_send_result(p_scb, p_result->result, nullptr, p_result->data.num);
       break;
 
     case BTA_AG_IN_CALL_RES:
@@ -1415,7 +1399,7 @@ void bta_ag_hfp_result(tBTA_AG_SCB* p_scb, tBTA_AG_API_RESULT* p_result) {
   switch (p_result->result) {
     case BTA_AG_SPK_RES:
     case BTA_AG_MIC_RES:
-      bta_ag_send_result(p_scb, p_result->result, NULL, p_result->data.num);
+      bta_ag_send_result(p_scb, p_result->result, nullptr, p_result->data.num);
       break;
 
     case BTA_AG_IN_CALL_RES:
@@ -1554,7 +1538,8 @@ void bta_ag_hfp_result(tBTA_AG_SCB* p_scb, tBTA_AG_API_RESULT* p_result) {
     case BTA_AG_INBAND_RING_RES:
       p_scb->inband_enabled = p_result->data.state;
       APPL_TRACE_DEBUG("inband_enabled set to %d", p_scb->inband_enabled);
-      bta_ag_send_result(p_scb, p_result->result, NULL, p_result->data.state);
+      bta_ag_send_result(p_scb, p_result->result, nullptr,
+                         p_result->data.state);
       break;
 
     case BTA_AG_CIND_RES:
@@ -1620,14 +1605,16 @@ void bta_ag_hfp_result(tBTA_AG_SCB* p_scb, tBTA_AG_API_RESULT* p_result) {
       break;
 
     case BTA_AG_BVRA_RES:
-      bta_ag_send_result(p_scb, p_result->result, NULL, p_result->data.state);
+      bta_ag_send_result(p_scb, p_result->result, nullptr,
+                         p_result->data.state);
       break;
 
     case BTA_AG_BTRH_RES:
       if (p_result->data.ok_flag != BTA_AG_OK_ERROR) {
         /* Don't respond to read if not in response & hold state */
         if (p_result->data.num != BTA_AG_BTRH_NO_RESP) {
-          bta_ag_send_result(p_scb, p_result->result, NULL, p_result->data.num);
+          bta_ag_send_result(p_scb, p_result->result, nullptr,
+                             p_result->data.num);
         }
 
         /* In case of a response to a read request we need to send OK */
@@ -1738,7 +1725,7 @@ void bta_ag_send_bcs(tBTA_AG_SCB* p_scb, tBTA_AG_DATA* p_data) {
 
   /* send +BCS */
   APPL_TRACE_DEBUG("send +BCS codec is %d", codec_uuid);
-  bta_ag_send_result(p_scb, BTA_AG_LOCAL_RES_BCS, NULL, codec_uuid);
+  bta_ag_send_result(p_scb, BTA_AG_LOCAL_RES_BCS, nullptr, codec_uuid);
 }
 
 /*******************************************************************************
@@ -1758,7 +1745,7 @@ void bta_ag_send_ring(tBTA_AG_SCB* p_scb, UNUSED_ATTR tBTA_AG_DATA* p_data) {
     return;
   }
   /* send RING */
-  bta_ag_send_result(p_scb, BTA_AG_LOCAL_RES_RING, NULL, 0);
+  bta_ag_send_result(p_scb, BTA_AG_LOCAL_RES_RING, nullptr, 0);
 
   /* if HFP and clip enabled and clip data send CLIP */
   if (p_scb->conn_service == BTA_AG_HFP && p_scb->clip_enabled &&
index 9e45a5f..48f9c5b 100644 (file)
 #define BTA_AG_ACP 0 /* accepted connection */
 #define BTA_AG_INT 1 /* initiating connection */
 
-/* feature mask that matches spec */
-#define BTA_AG_BSRF_FEAT_SPEC                                   \
-  (BTA_AG_FEAT_3WAY | BTA_AG_FEAT_ECNR | BTA_AG_FEAT_VREC |     \
-   BTA_AG_FEAT_INBAND | BTA_AG_FEAT_VTAG | BTA_AG_FEAT_REJECT | \
-   BTA_AG_FEAT_ECS | BTA_AG_FEAT_ECC | BTA_AG_FEAT_EXTERR |     \
-   BTA_AG_FEAT_CODEC | BTA_AG_FEAT_HF_IND | BTA_AG_FEAT_ESCO |  \
-   BTA_AG_FEAT_VOIP)
-
 #define BTA_AG_SDP_FEAT_SPEC                                \
   (BTA_AG_FEAT_3WAY | BTA_AG_FEAT_ECNR | BTA_AG_FEAT_VREC | \
    BTA_AG_FEAT_INBAND | BTA_AG_FEAT_VTAG)
index 8b4975d..9f1bb22 100644 (file)
@@ -275,7 +275,7 @@ static tBTA_AG_SCB* bta_ag_scb_alloc(void) {
 
   if (i == BTA_AG_NUM_SCB) {
     /* out of scbs */
-    p_scb = NULL;
+    p_scb = nullptr;
     APPL_TRACE_WARNING("%s: Out of scbs", __func__);
   }
   return p_scb;
@@ -303,7 +303,7 @@ void bta_ag_scb_dealloc(tBTA_AG_SCB* p_scb) {
   alarm_free(p_scb->collision_timer);
 
   /* initialize control block */
-  memset(p_scb, 0, sizeof(tBTA_AG_SCB));
+  *p_scb = {};
   p_scb->sco_idx = BTM_INVALID_SCO_INDEX;
 
   /* If all scbs are deallocated, callback with disable event */
@@ -316,7 +316,7 @@ void bta_ag_scb_dealloc(tBTA_AG_SCB* p_scb) {
     }
 
     if (!allocated) {
-      (*bta_ag_cb.p_cback)(BTA_AG_DISABLE_EVT, NULL);
+      (*bta_ag_cb.p_cback)(BTA_AG_DISABLE_EVT, nullptr);
     }
   }
 }
@@ -353,11 +353,11 @@ tBTA_AG_SCB* bta_ag_scb_by_idx(uint16_t idx) {
   if (idx > 0 && idx <= BTA_AG_NUM_SCB) {
     p_scb = &bta_ag_cb.scb[idx - 1];
     if (!p_scb->in_use) {
-      p_scb = NULL;
+      p_scb = nullptr;
       APPL_TRACE_WARNING("ag scb idx %d not allocated", idx);
     }
   } else {
-    p_scb = NULL;
+    p_scb = nullptr;
     APPL_TRACE_DEBUG("ag scb idx %d out of range", idx);
   }
   return p_scb;
@@ -393,10 +393,8 @@ uint8_t bta_ag_service_to_idx(tBTA_SERVICE_MASK services) {
  ******************************************************************************/
 uint16_t bta_ag_idx_by_bdaddr(const RawAddress* peer_addr) {
   tBTA_AG_SCB* p_scb = &bta_ag_cb.scb[0];
-  uint16_t i;
-
-  if (peer_addr != NULL) {
-    for (i = 0; i < BTA_AG_NUM_SCB; i++, p_scb++) {
+  if (peer_addr != nullptr) {
+    for (uint16_t i = 0; i < BTA_AG_NUM_SCB; i++, p_scb++) {
       if (p_scb->in_use && *peer_addr == p_scb->peer_addr) {
         return (i + 1);
       }
@@ -420,15 +418,12 @@ uint16_t bta_ag_idx_by_bdaddr(const RawAddress* peer_addr) {
  ******************************************************************************/
 bool bta_ag_other_scb_open(tBTA_AG_SCB* p_curr_scb) {
   tBTA_AG_SCB* p_scb = &bta_ag_cb.scb[0];
-  int i;
-
-  for (i = 0; i < BTA_AG_NUM_SCB; i++, p_scb++) {
+  for (int i = 0; i < BTA_AG_NUM_SCB; i++, p_scb++) {
     if (p_scb->in_use && p_scb != p_curr_scb &&
         p_scb->state == BTA_AG_OPEN_ST) {
       return true;
     }
   }
-
   /* no other scb found */
   APPL_TRACE_DEBUG("No other ag scb open");
   return false;
@@ -445,11 +440,8 @@ bool bta_ag_other_scb_open(tBTA_AG_SCB* p_curr_scb) {
  *
  ******************************************************************************/
 bool bta_ag_scb_open(tBTA_AG_SCB* p_curr_scb) {
-  if (p_curr_scb && p_curr_scb->in_use && p_curr_scb->state == BTA_AG_OPEN_ST) {
-    return true;
-  }
-
-  return false;
+  return p_curr_scb && p_curr_scb->in_use &&
+         p_curr_scb->state == BTA_AG_OPEN_ST;
 }
 
 /*******************************************************************************
@@ -475,7 +467,7 @@ tBTA_AG_SCB* bta_ag_get_other_idle_scb(tBTA_AG_SCB* p_curr_scb) {
 
   /* no other scb found */
   APPL_TRACE_DEBUG("bta_ag_get_other_idle_scb: No idle AG scb");
-  return NULL;
+  return nullptr;
 }
 
 /*******************************************************************************
@@ -519,11 +511,11 @@ void bta_ag_collision_cback(UNUSED_ATTR tBTA_SYS_CONN_STATUS status, uint8_t id,
   p_scb = bta_ag_scb_by_idx(handle);
 
   if (p_scb && (p_scb->state == BTA_AG_OPENING_ST)) {
-    if (id == BTA_ID_SYS) /* ACL collision */
-    {
+    if (id == BTA_ID_SYS) {
+      /* ACL collision */
       APPL_TRACE_WARNING("AG found collision (ACL) ...");
-    } else if (id == BTA_ID_AG) /* RFCOMM collision */
-    {
+    } else if (id == BTA_ID_AG) {
+      /* RFCOMM collision */
       APPL_TRACE_WARNING("AG found collision (RFCOMM) ...");
     } else {
       APPL_TRACE_WARNING("AG found collision (\?\?\?) ...");
@@ -534,7 +526,7 @@ void bta_ag_collision_cback(UNUSED_ATTR tBTA_SYS_CONN_STATUS status, uint8_t id,
     /* Cancel SDP if it had been started. */
     if (p_scb->p_disc_db) {
       (void)SDP_CancelServiceSearch(p_scb->p_disc_db);
-      bta_ag_free_db(p_scb, NULL);
+      bta_ag_free_db(p_scb, nullptr);
     }
 
     /* reopen registered servers */
@@ -566,7 +558,7 @@ void bta_ag_resume_open(tBTA_AG_SCB* p_scb) {
     /* resume opening process.  */
     if (p_scb->state == BTA_AG_INIT_ST) {
       p_scb->state = BTA_AG_OPENING_ST;
-      bta_ag_start_open(p_scb, NULL);
+      bta_ag_start_open(p_scb, nullptr);
     }
   } else {
     APPL_TRACE_ERROR("bta_ag_resume_open, Null p_scb");
@@ -585,12 +577,12 @@ void bta_ag_resume_open(tBTA_AG_SCB* p_scb) {
  ******************************************************************************/
 static void bta_ag_api_enable(tBTA_AG_DATA* p_data) {
   /* initialize control block */
-  for (size_t i = 0; i < BTA_AG_NUM_SCB; i++) {
-    alarm_free(bta_ag_cb.scb[i].ring_timer);
-    alarm_free(bta_ag_cb.scb[i].codec_negotiation_timer);
-    alarm_free(bta_ag_cb.scb[i].collision_timer);
+  for (tBTA_AG_SCB& scb : bta_ag_cb.scb) {
+    alarm_free(scb.ring_timer);
+    alarm_free(scb.codec_negotiation_timer);
+    alarm_free(scb.collision_timer);
+    scb = {};
   }
-  memset(&bta_ag_cb, 0, sizeof(tBTA_AG_CB));
 
   /* store callback function */
   bta_ag_cb.p_cback = p_data->api_enable.p_cback;
@@ -602,7 +594,7 @@ static void bta_ag_api_enable(tBTA_AG_DATA* p_data) {
   bta_sys_collision_register(BTA_ID_AG, bta_ag_collision_cback);
 
   /* call callback with enable event */
-  (*bta_ag_cb.p_cback)(BTA_AG_ENABLE_EVT, NULL);
+  (*bta_ag_cb.p_cback)(BTA_AG_ENABLE_EVT, nullptr);
 }
 
 /*******************************************************************************
@@ -638,10 +630,10 @@ static void bta_ag_api_disable(tBTA_AG_DATA* p_data) {
 
   if (!do_dereg) {
     /* Done, send callback evt to app */
-    (*bta_ag_cb.p_cback)(BTA_AG_DISABLE_EVT, NULL);
+    (*bta_ag_cb.p_cback)(BTA_AG_DISABLE_EVT, nullptr);
   }
 
-  bta_sys_collision_register(BTA_ID_AG, NULL);
+  bta_sys_collision_register(BTA_ID_AG, nullptr);
 }
 
 /*******************************************************************************
@@ -659,11 +651,11 @@ static void bta_ag_api_register(tBTA_AG_DATA* p_data) {
 
   /* allocate an scb */
   p_scb = bta_ag_scb_alloc();
-  if (p_scb != NULL) {
+  if (p_scb != nullptr) {
     APPL_TRACE_DEBUG("bta_ag_api_register: p_scb 0x%08x ", p_scb);
     bta_ag_sm_execute(p_scb, p_data->hdr.event, p_data);
   } else {
-    tBTA_AG bta_ag;
+    tBTA_AG bta_ag = {};
     bta_ag.reg.status = BTA_AG_FAIL_RESOURCES;
     (*bta_ag_cb.p_cback)(BTA_AG_REGISTER_EVT, &bta_ag);
   }
@@ -685,7 +677,7 @@ static void bta_ag_api_result(tBTA_AG_DATA* p_data) {
 
   if (p_data->hdr.layer_specific != BTA_AG_HANDLE_ALL) {
     p_scb = bta_ag_scb_by_idx(p_data->hdr.layer_specific);
-    if (p_scb != NULL) {
+    if (p_scb != nullptr) {
       APPL_TRACE_DEBUG("bta_ag_api_result: p_scb 0x%08x ", p_scb);
       bta_ag_sm_execute(p_scb, BTA_AG_API_RESULT_EVT, p_data);
     }
@@ -804,7 +796,7 @@ bool bta_ag_hdl_event(BT_HDR* p_msg) {
     /* all others reference scb by handle */
     default:
       p_scb = bta_ag_scb_by_idx(p_msg->layer_specific);
-      if (p_scb != NULL) {
+      if (p_scb != nullptr) {
         APPL_TRACE_DEBUG("bta_ag_hdl_event: p_scb 0x%08x ", p_scb);
         bta_ag_sm_execute(p_scb, p_msg->event, (tBTA_AG_DATA*)p_msg);
       }
index c9dece0..a3adf07 100644 (file)
@@ -23,7 +23,7 @@
  *
  ******************************************************************************/
 
-#include <string.h>
+#include <cstring>
 
 #include "bt_common.h"
 #include "bta_ag_api.h"
@@ -80,7 +80,7 @@ static void bta_ag_port_cback(UNUSED_ATTR uint32_t code, uint16_t port_handle,
   tBTA_AG_SCB* p_scb;
 
   p_scb = bta_ag_scb_by_idx(handle);
-  if (p_scb != NULL) {
+  if (p_scb != nullptr) {
     /* ignore port events for port handles other than connected handle */
     if (port_handle != p_scb->conn_handle) {
       APPL_TRACE_DEBUG(
@@ -117,7 +117,7 @@ static void bta_ag_mgmt_cback(uint32_t code, uint16_t port_handle,
                    code, port_handle, handle);
 
   p_scb = bta_ag_scb_by_idx(handle);
-  if (p_scb != NULL) {
+  if (p_scb != nullptr) {
     /* ignore close event for port handles other than connected handle */
     if ((code != PORT_SUCCESS) && (port_handle != p_scb->conn_handle)) {
       APPL_TRACE_DEBUG("ag_mgmt_cback ignoring handle:%d", port_handle);
index 8486331..557ee1f 100644 (file)
@@ -54,10 +54,6 @@ static char* bta_ag_sco_state_str(uint8_t state);
 
 static bool sco_allowed = true;
 
-#define BTA_AG_NO_EDR_ESCO                                       \
-  (ESCO_PKT_TYPES_MASK_NO_2_EV3 | ESCO_PKT_TYPES_MASK_NO_3_EV3 | \
-   ESCO_PKT_TYPES_MASK_NO_2_EV5 | ESCO_PKT_TYPES_MASK_NO_3_EV5)
-
 /* sco events */
 enum {
   BTA_AG_SCO_LISTEN_E,       /* listen request */
@@ -89,7 +85,7 @@ static void bta_ag_sco_conn_cback(uint16_t sco_idx) {
   tBTA_AG_SCB* p_scb;
 
   /* match callback to scb; first check current sco scb */
-  if (bta_ag_cb.sco.p_curr_scb != NULL && bta_ag_cb.sco.p_curr_scb->in_use) {
+  if (bta_ag_cb.sco.p_curr_scb != nullptr && bta_ag_cb.sco.p_curr_scb->in_use) {
     handle = bta_ag_scb_to_idx(bta_ag_cb.sco.p_curr_scb);
   }
   /* then check for scb connected to this peer */
@@ -107,7 +103,7 @@ static void bta_ag_sco_conn_cback(uint16_t sco_idx) {
     bta_sys_sendmsg(p_buf);
   } else {
     /* no match found; disconnect sco, init sco variables */
-    bta_ag_cb.sco.p_curr_scb = NULL;
+    bta_ag_cb.sco.p_curr_scb = nullptr;
     bta_ag_cb.sco.state = BTA_AG_SCO_SHUTDOWN_ST;
     BTM_RemoveSco(sco_idx);
   }
@@ -143,7 +139,7 @@ static void bta_ag_sco_disc_cback(uint16_t sco_idx) {
       bta_ag_cb.scb[1].state);
 
   /* match callback to scb */
-  if (bta_ag_cb.sco.p_curr_scb != NULL && bta_ag_cb.sco.p_curr_scb->in_use) {
+  if (bta_ag_cb.sco.p_curr_scb != nullptr && bta_ag_cb.sco.p_curr_scb->in_use) {
     /* We only care about callbacks for the active SCO */
     if (bta_ag_cb.sco.p_curr_scb->sco_idx != sco_idx) {
       if (bta_ag_cb.sco.p_curr_scb->sco_idx != 0xFFFF) return;
@@ -202,9 +198,9 @@ static void bta_ag_sco_disc_cback(uint16_t sco_idx) {
     APPL_TRACE_DEBUG("no scb for ag_sco_disc_cback");
 
     /* sco could be closed after scb dealloc'ed */
-    if (bta_ag_cb.sco.p_curr_scb != NULL) {
+    if (bta_ag_cb.sco.p_curr_scb != nullptr) {
       bta_ag_cb.sco.p_curr_scb->sco_idx = BTM_INVALID_SCO_INDEX;
-      bta_ag_cb.sco.p_curr_scb = NULL;
+      bta_ag_cb.sco.p_curr_scb = nullptr;
       bta_ag_cb.sco.state = BTA_AG_SCO_SHUTDOWN_ST;
     }
   }
@@ -279,7 +275,7 @@ static void bta_ag_esco_connreq_cback(tBTM_ESCO_EVT event,
   /* Only process connection requests */
   if (event == BTM_ESCO_CONN_REQ_EVT) {
     if ((handle = bta_ag_idx_by_bdaddr(BTM_ReadScoBdAddr(sco_inx))) != 0 &&
-        ((p_scb = bta_ag_scb_by_idx(handle)) != NULL) && p_scb->svc_conn) {
+        ((p_scb = bta_ag_scb_by_idx(handle)) != nullptr) && p_scb->svc_conn) {
       p_scb->sco_idx = sco_inx;
 
       /* If no other SCO active, allow this one */
@@ -302,7 +298,7 @@ static void bta_ag_esco_connreq_cback(tBTM_ESCO_EVT event,
           APPL_TRACE_ERROR(
               "%s: Nothing to remove,so accept Conn Request(sco_inx 0x%04x)",
               __func__, sco_inx);
-          bta_ag_cb.sco.p_xfer_scb = NULL;
+          bta_ag_cb.sco.p_xfer_scb = nullptr;
           bta_ag_cb.sco.state = BTA_AG_SCO_LISTEN_ST;
 
           bta_ag_sco_conn_rsp(p_scb, &p_data->conn_evt);
@@ -313,7 +309,7 @@ static void bta_ag_esco_connreq_cback(tBTM_ESCO_EVT event,
       APPL_TRACE_WARNING(
           "no scb for bta_ag_esco_connreq_cback or no resources");
       BTM_EScoConnRsp(p_data->conn_evt.sco_inx, HCI_ERR_HOST_REJECT_RESOURCES,
-                      (enh_esco_params_t*)NULL);
+                      (enh_esco_params_t*)nullptr);
     }
   } else if (event == BTM_ESCO_CHG_EVT) {
     /* Received a change in the esco link */
@@ -337,11 +333,9 @@ static void bta_ag_esco_connreq_cback(tBTM_ESCO_EVT event,
  *
  ******************************************************************************/
 static void bta_ag_cback_sco(tBTA_AG_SCB* p_scb, uint8_t event) {
-  tBTA_AG_HDR sco;
-
+  tBTA_AG_HDR sco = {};
   sco.handle = bta_ag_scb_to_idx(p_scb);
   sco.app_id = p_scb->app_id;
-
   /* call close cback */
   (*bta_ag_cb.p_cback)(event, (tBTA_AG*)&sco);
 }
@@ -456,7 +450,7 @@ static void bta_ag_create_sco(tBTA_AG_SCB* p_scb, bool is_orig) {
  ******************************************************************************/
 static void bta_ag_create_pending_sco(tBTA_AG_SCB* p_scb, bool is_local) {
   tBTA_AG_PEER_CODEC esco_codec = p_scb->inuse_codec;
-  enh_esco_params_t params;
+  enh_esco_params_t params = {};
   bta_ag_cb.sco.p_curr_scb = p_scb;
   bta_ag_cb.sco.cur_idx = p_scb->sco_idx;
 
@@ -553,7 +547,7 @@ void bta_ag_codec_negotiate(tBTA_AG_SCB* p_scb) {
     bta_sys_busy(BTA_ID_AG, p_scb->app_id, p_scb->peer_addr);
 
     /* Send +BCS to the peer */
-    bta_ag_send_bcs(p_scb, NULL);
+    bta_ag_send_bcs(p_scb, nullptr);
 
     /* Start timer to handle timeout */
     alarm_set_on_mloop(p_scb->codec_negotiation_timer,
@@ -653,7 +647,7 @@ static void bta_ag_sco_event(tBTA_AG_SCB* p_scb, uint8_t event) {
           /* remove listening connection */
           bta_ag_remove_sco(p_scb, false);
 
-          if (p_scb == p_sco->p_curr_scb) p_sco->p_curr_scb = NULL;
+          if (p_scb == p_sco->p_curr_scb) p_sco->p_curr_scb = nullptr;
 
           /* If last SCO instance then finish shutting down */
           if (!bta_ag_other_scb_open(p_scb)) {
@@ -705,7 +699,7 @@ static void bta_ag_sco_event(tBTA_AG_SCB* p_scb, uint8_t event) {
           /* remove listening connection */
           bta_ag_remove_sco(p_scb, false);
 
-          if (p_scb == p_sco->p_curr_scb) p_sco->p_curr_scb = NULL;
+          if (p_scb == p_sco->p_curr_scb) p_sco->p_curr_scb = nullptr;
 
           /* If last SCO instance then finish shutting down */
           if (!bta_ag_other_scb_open(p_scb)) {
@@ -853,7 +847,7 @@ static void bta_ag_sco_event(tBTA_AG_SCB* p_scb, uint8_t event) {
           p_sco->state = BTA_AG_SCO_OPENING_ST;
           p_sco->p_curr_scb = p_sco->p_xfer_scb;
           p_sco->cur_idx = p_sco->p_xfer_scb->sco_idx;
-          p_sco->p_xfer_scb = NULL;
+          p_sco->p_xfer_scb = nullptr;
           break;
 
         default:
@@ -997,14 +991,14 @@ static void bta_ag_sco_event(tBTA_AG_SCB* p_scb, uint8_t event) {
 
         case BTA_AG_SCO_CLOSE_E:
           /* clear xfer scb */
-          p_sco->p_xfer_scb = NULL;
+          p_sco->p_xfer_scb = nullptr;
 
           p_sco->state = BTA_AG_SCO_CLOSING_ST;
           break;
 
         case BTA_AG_SCO_SHUTDOWN_E:
           /* clear xfer scb */
-          p_sco->p_xfer_scb = NULL;
+          p_sco->p_xfer_scb = nullptr;
 
           p_sco->state = BTA_AG_SCO_SHUTTING_ST;
           break;
@@ -1019,7 +1013,7 @@ static void bta_ag_sco_event(tBTA_AG_SCB* p_scb, uint8_t event) {
           /* start codec negotiation */
           p_sco->state = BTA_AG_SCO_CODEC_ST;
           tBTA_AG_SCB* p_cn_scb = p_sco->p_xfer_scb;
-          p_sco->p_xfer_scb = NULL;
+          p_sco->p_xfer_scb = nullptr;
           bta_ag_codec_negotiate(p_cn_scb);
           break;
         }
@@ -1056,7 +1050,7 @@ static void bta_ag_sco_event(tBTA_AG_SCB* p_scb, uint8_t event) {
 
           if (p_scb == p_sco->p_curr_scb) {
             p_sco->p_curr_scb->sco_idx = BTM_INVALID_SCO_INDEX;
-            p_sco->p_curr_scb = NULL;
+            p_sco->p_curr_scb = nullptr;
           }
           break;
 
@@ -1077,7 +1071,7 @@ static void bta_ag_sco_event(tBTA_AG_SCB* p_scb, uint8_t event) {
 
           if (p_scb == p_sco->p_curr_scb) {
             p_sco->p_curr_scb->sco_idx = BTM_INVALID_SCO_INDEX;
-            p_sco->p_curr_scb = NULL;
+            p_sco->p_curr_scb = nullptr;
           }
           break;
 
@@ -1165,7 +1159,8 @@ void bta_ag_sco_open(tBTA_AG_SCB* p_scb, UNUSED_ATTR tBTA_AG_DATA* p_data) {
   }
 
   /* if another scb using sco, this is a transfer */
-  if (bta_ag_cb.sco.p_curr_scb != NULL && bta_ag_cb.sco.p_curr_scb != p_scb) {
+  if (bta_ag_cb.sco.p_curr_scb != nullptr &&
+      bta_ag_cb.sco.p_curr_scb != p_scb) {
     event = BTA_AG_SCO_XFER_E;
   }
   /* else it is an open */
@@ -1278,7 +1273,7 @@ void bta_ag_sco_conn_open(tBTA_AG_SCB* p_scb,
 void bta_ag_sco_conn_close(tBTA_AG_SCB* p_scb,
                            UNUSED_ATTR tBTA_AG_DATA* p_data) {
   /* clear current scb */
-  bta_ag_cb.sco.p_curr_scb = NULL;
+  bta_ag_cb.sco.p_curr_scb = nullptr;
   p_scb->sco_idx = BTM_INVALID_SCO_INDEX;
 
   /* codec_fallback is set when AG is initiator and connection failed for mSBC.
index ad67e4c..5c3d433 100644 (file)
@@ -23,7 +23,7 @@
  *
  ******************************************************************************/
 
-#include <string.h>
+#include <cstring>
 
 #include "bt_common.h"
 #include "bta_ag_api.h"
@@ -75,7 +75,7 @@ static void bta_ag_sdp_cback(uint16_t status, uint8_t idx) {
   APPL_TRACE_DEBUG("%s status:0x%x", __func__, status);
 
   p_scb = bta_ag_scb_by_idx(idx);
-  if (p_scb != NULL) {
+  if (p_scb != nullptr) {
     /* set event according to int/acp */
     if (p_scb->role == BTA_AG_ACP) {
       event = BTA_AG_DISC_ACP_RES_EVT;
@@ -135,8 +135,9 @@ bool bta_ag_add_record(uint16_t service_uuid, char* p_service_name, uint8_t scn,
 
   APPL_TRACE_DEBUG("%s uuid: %x", __func__, service_uuid);
 
-  memset(proto_elem_list, 0,
-         BTA_AG_NUM_PROTO_ELEMS * sizeof(tSDP_PROTOCOL_ELEM));
+  for (auto& proto_element : proto_elem_list) {
+    proto_element = {};
+  }
 
   /* add the protocol element sequence */
   proto_elem_list[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
@@ -164,7 +165,7 @@ bool bta_ag_add_record(uint16_t service_uuid, char* p_service_name, uint8_t scn,
   result &= SDP_AddProfileDescriptorList(sdp_handle, profile_uuid, version);
 
   /* add service name */
-  if (p_service_name != NULL && p_service_name[0] != 0) {
+  if (p_service_name != nullptr && p_service_name[0] != 0) {
     result &= SDP_AddAttribute(
         sdp_handle, ATTR_ID_SERVICE_NAME, TEXT_STR_DESC_TYPE,
         (uint32_t)(strlen(p_service_name) + 1), (uint8_t*)p_service_name);
@@ -287,7 +288,7 @@ void bta_ag_del_records(tBTA_AG_SCB* p_scb, UNUSED_ATTR tBTA_AG_DATA* p_data) {
  *
  ******************************************************************************/
 bool bta_ag_sdp_find_attr(tBTA_AG_SCB* p_scb, tBTA_SERVICE_MASK service) {
-  tSDP_DISC_REC* p_rec = NULL;
+  tSDP_DISC_REC* p_rec = nullptr;
   tSDP_DISC_ATTR* p_attr;
   tSDP_PROTOCOL_ELEM pe;
   uint16_t uuid;
@@ -307,13 +308,13 @@ bool bta_ag_sdp_find_attr(tBTA_AG_SCB* p_scb, tBTA_SERVICE_MASK service) {
   while (true) {
     /* get next record; if none found, we're done */
     p_rec = SDP_FindServiceInDb(p_scb->p_disc_db, uuid, p_rec);
-    if (p_rec == NULL) {
+    if (p_rec == nullptr) {
       if (uuid == UUID_SERVCLASS_HEADSET_HS) {
         /* Search again in case the peer device uses the old HSP UUID */
         uuid = UUID_SERVCLASS_HEADSET;
         p_scb->peer_version = HSP_VERSION_1_0;
         p_rec = SDP_FindServiceInDb(p_scb->p_disc_db, uuid, p_rec);
-        if (p_rec == NULL) {
+        if (p_rec == nullptr) {
           break;
         }
       } else
@@ -338,7 +339,7 @@ bool bta_ag_sdp_find_attr(tBTA_AG_SCB* p_scb, tBTA_SERVICE_MASK service) {
     /* get features if HFP */
     if (service & BTA_HFP_SERVICE_MASK) {
       p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SUPPORTED_FEATURES);
-      if (p_attr != NULL) {
+      if (p_attr != nullptr) {
         /* Found attribute. Get value. */
         /* There might be race condition between SDP and BRSF.  */
         /* Do not update if we already received BRSF.           */
@@ -349,7 +350,7 @@ bool bta_ag_sdp_find_attr(tBTA_AG_SCB* p_scb, tBTA_SERVICE_MASK service) {
     {
       p_attr =
           SDP_FindAttributeInRec(p_rec, ATTR_ID_REMOTE_AUDIO_VOLUME_CONTROL);
-      if (p_attr != NULL) {
+      if (p_attr != nullptr) {
         /* Remote volume control of HSP */
         if (p_attr->attr_value.v.u8)
           p_scb->peer_features |= BTA_AG_PEER_FEAT_VOL;
@@ -380,7 +381,6 @@ void bta_ag_do_disc(tBTA_AG_SCB* p_scb, tBTA_SERVICE_MASK service) {
   uint16_t num_uuid = 1;
   uint16_t attr_list[4];
   uint8_t num_attr;
-  bool db_inited = false;
 
   /* HFP initiator; get proto list and features */
   if (service & BTA_HFP_SERVICE_MASK && p_scb->role == BTA_AG_INT) {
@@ -424,8 +424,9 @@ void bta_ag_do_disc(tBTA_AG_SCB* p_scb, tBTA_SERVICE_MASK service) {
   /* allocate buffer for sdp database */
   p_scb->p_disc_db = (tSDP_DISCOVERY_DB*)osi_malloc(BTA_AG_DISC_BUF_SIZE);
   /* set up service discovery database; attr happens to be attr_list len */
-  db_inited = SDP_InitDiscoveryDb(p_scb->p_disc_db, BTA_AG_DISC_BUF_SIZE,
-                                  num_uuid, uuid_list, num_attr, attr_list);
+  bool db_inited =
+      SDP_InitDiscoveryDb(p_scb->p_disc_db, BTA_AG_DISC_BUF_SIZE, num_uuid,
+                          uuid_list, num_attr, attr_list);
 
   if (db_inited) {
     /*Service discovery not initiated */
@@ -436,9 +437,9 @@ void bta_ag_do_disc(tBTA_AG_SCB* p_scb, tBTA_SERVICE_MASK service) {
 
   if (!db_inited) {
     /*free discover db */
-    bta_ag_free_db(p_scb, NULL);
+    bta_ag_free_db(p_scb, nullptr);
     /* sent failed event */
-    bta_ag_sm_execute(p_scb, BTA_AG_DISC_FAIL_EVT, NULL);
+    bta_ag_sm_execute(p_scb, BTA_AG_DISC_FAIL_EVT, nullptr);
   }
 }
 
index 8430ee1..a04ba75 100644 (file)
@@ -472,7 +472,7 @@ tBTA_STATUS BTA_AgEnable(tBTA_AG_PARSE_MODE parse_mode, tBTA_AG_CBACK* p_cback);
  * Returns          void
  *
  ******************************************************************************/
-void BTA_AgDisable(void);
+void BTA_AgDisable();
 
 /*******************************************************************************
  *
diff --git a/bta/include/bta_ag_ci.h b/bta/include/bta_ag_ci.h
deleted file mode 100644 (file)
index ef2b581..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/******************************************************************************
- *
- *  Copyright 2003-2012 Broadcom Corporation
- *
- *  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.
- *
- ******************************************************************************/
-
-/******************************************************************************
- *
- *  This is the interface file for audio gateway call-in functions.
- *
- ******************************************************************************/
-#ifndef BTA_AG_CI_H
-#define BTA_AG_CI_H
-
-#include "bta_ag_api.h"
-
-/*****************************************************************************
- *  Function Declarations
- ****************************************************************************/
-/*******************************************************************************
- *
- * Function         bta_ag_ci_rx_write
- *
- * Description      This function is called to send data to the AG when the AG
- *                  is configured for AT command pass-through.  The function
- *                  copies data to an event buffer and sends it.
- *
- * Returns          void
- *
- ******************************************************************************/
-extern void bta_ag_ci_rx_write(uint16_t handle, char* p_data, uint16_t len);
-
-/******************************************************************************
- *
- * Function         bta_ag_ci_slc_ready
- *
- * Description      This function is called to notify AG that SLC is up at
- *                  the application. This funcion is only used when the app
- *                  is running in pass-through mode.
- *
- * Returns          void
- *
- *****************************************************************************/
-extern void bta_ag_ci_slc_ready(uint16_t handle);
-
-/******************************************************************************
- *
- * Function         bta_ag_ci_wbs_command
- *
- * Description      This function is called to notify AG that a WBS command is
- *                  received
- *
- * Returns          void
- *
- *****************************************************************************/
-extern void bta_ag_ci_wbs_command(uint16_t handle, char* p_data, uint16_t len);
-
-#endif /* BTA_AG_CI_H */
index 6708d07..46f7b59 100644 (file)
@@ -21,7 +21,6 @@
 #include "bta/include/bta_ag_co.h"
 #include "bta/ag/bta_ag_int.h"
 #include "bta/include/bta_ag_api.h"
-#include "bta/include/bta_ag_ci.h"
 #include "osi/include/osi.h"
 
 /*******************************************************************************
index a86c8d1..c2dc6d8 100644 (file)
@@ -27,9 +27,9 @@
 
 #define LOG_TAG "bt_btif_hf"
 
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
 
 #include <hardware/bluetooth.h>
 #include <hardware/bt_hf.h>
 /* HF features supported at runtime */
 static uint32_t btif_hf_features = BTIF_HF_FEATURES;
 
-#define BTIF_HF_CALL_END_TIMEOUT 6
-
 #define BTIF_HF_INVALID_IDX (-1)
 
 /* Number of BTIF-HF control blocks */
 #define BTIF_HF_NUM_CB 2
 
 /* Max HF clients supported from App */
-uint16_t btif_max_hf_clients = 1;
+int btif_max_hf_clients = 1;
 
 /* HF app ids for service registration */
 typedef enum {
@@ -109,12 +107,12 @@ uint16_t bthf_hf_id[BTIF_HF_NUM_CB] = {BTIF_HF_ID_1, BTIF_HF_ID_2,
 /*******************************************************************************
  *  Static variables
  ******************************************************************************/
-static bthf_callbacks_t* bt_hf_callbacks = NULL;
+static bthf_callbacks_t* bt_hf_callbacks = nullptr;
 static int hf_idx = BTIF_HF_INVALID_IDX;
 
 #define CHECK_BTHF_INIT()                                             \
   do {                                                                \
-    if (bt_hf_callbacks == NULL) {                                    \
+    if (bt_hf_callbacks == nullptr) {                                 \
       BTIF_TRACE_WARNING("BTHF: %s: BTHF not initialized", __func__); \
       return BT_STATUS_NOT_READY;                                     \
     } else {                                                          \
@@ -127,7 +125,6 @@ typedef struct _btif_hf_cb {
   uint16_t handle;
   RawAddress connected_bda;
   bthf_connection_state_t state;
-  bthf_vr_state_t vr_state;
   tBTA_AG_PEER_FEAT peer_feat;
   int num_active;
   int num_held;
@@ -224,14 +221,11 @@ static uint8_t callstate_to_callsetup(bthf_call_state_t call_state) {
  *
  ******************************************************************************/
 static void send_at_result(uint8_t ok_flag, uint16_t errcode, int idx) {
-  tBTA_AG_RES_DATA ag_res;
-  memset(&ag_res, 0, sizeof(ag_res));
-
+  tBTA_AG_RES_DATA ag_res = {};
   ag_res.ok_flag = ok_flag;
   if (ok_flag == BTA_AG_OK_ERROR) {
     ag_res.errcode = errcode;
   }
-
   BTA_AgResult(btif_hf_cb[idx].handle, BTA_AG_UNAT_RES, &ag_res);
 }
 
@@ -245,12 +239,9 @@ static void send_at_result(uint8_t ok_flag, uint16_t errcode, int idx) {
  *
  ******************************************************************************/
 static void send_indicator_update(uint16_t indicator, uint16_t value) {
-  tBTA_AG_RES_DATA ag_res;
-
-  memset(&ag_res, 0, sizeof(tBTA_AG_RES_DATA));
+  tBTA_AG_RES_DATA ag_res = {};
   ag_res.ind.id = indicator;
   ag_res.ind.value = value;
-
   BTA_AgResult(BTA_AG_HANDLE_ALL, BTA_AG_IND_RES, &ag_res);
 }
 
@@ -264,13 +255,9 @@ static void send_indicator_update(uint16_t indicator, uint16_t value) {
  *
  *******************************************************************************/
 static void send_call_status_forcibly(uint16_t value) {
-  tBTA_AG_RES_DATA ag_res;
-
-  memset(&ag_res, 0, sizeof(tBTA_AG_RES_DATA));
-
+  tBTA_AG_RES_DATA ag_res = {};
   ag_res.ind.id = BTA_AG_IND_CALL;
   ag_res.ind.value = value;
-
   BTA_AgResult(BTA_AG_HANDLE_ALL, BTA_AG_IND_RES_ON_DEMAND, &ag_res);
 }
 
@@ -318,7 +305,7 @@ static int btif_hf_latest_connected_idx() {
  *
  ******************************************************************************/
 static bt_status_t btif_hf_check_if_slc_connected() {
-  if (bt_hf_callbacks == NULL) {
+  if (bt_hf_callbacks == nullptr) {
     BTIF_TRACE_WARNING("BTHF: %s: BTHF not initialized", __func__);
     return BT_STATUS_NOT_READY;
   } else {
@@ -474,7 +461,7 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) {
         BTIF_TRACE_DEBUG("Donot set hf_idx for BLDN/D since already in a call");
 
       HAL_CBACK(bt_hf_callbacks, dial_call_cmd_cb,
-                (event == BTA_AG_AT_D_EVT) ? p_data->val.str : NULL,
+                (event == BTA_AG_AT_D_EVT) ? p_data->val.str : nullptr,
                 &btif_hf_cb[idx].connected_bda);
       break;
 
@@ -639,7 +626,7 @@ static void bte_hf_evt(tBTA_AG_EVT event, tBTA_AG* p_data) {
   /* switch context to btif task context (copy full union size for convenience)
    */
   status = btif_transfer_context(btif_hf_upstreams_evt, (uint16_t)event,
-                                 (char*)p_data, param_len, NULL);
+                                 (char*)p_data, param_len, nullptr);
 
   /* catch any failed context transfers */
   ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed", status);
@@ -825,7 +812,7 @@ static bt_status_t connect_audio(RawAddress* bd_addr) {
     /* Inform the application that the audio connection has been initiated
      * successfully */
     btif_transfer_context(btif_in_hf_generic_evt, BTIF_HFP_CB_AUDIO_CONNECTING,
-                          (char*)bd_addr, sizeof(RawAddress), NULL);
+                          (char*)bd_addr, sizeof(RawAddress), nullptr);
     return BT_STATUS_SUCCESS;
   }
 
@@ -880,8 +867,7 @@ static bt_status_t start_voice_recognition(RawAddress* bd_addr) {
 
   if (is_connected(bd_addr) && (idx != BTIF_HF_INVALID_IDX)) {
     if (btif_hf_cb[idx].peer_feat & BTA_AG_PEER_FEAT_VREC) {
-      tBTA_AG_RES_DATA ag_res;
-      memset(&ag_res, 0, sizeof(ag_res));
+      tBTA_AG_RES_DATA ag_res = {};
       ag_res.state = 1;
       BTA_AgResult(btif_hf_cb[idx].handle, BTA_AG_BVRA_RES, &ag_res);
 
@@ -915,8 +901,7 @@ static bt_status_t stop_voice_recognition(RawAddress* bd_addr) {
 
   if (is_connected(bd_addr) && (idx != BTIF_HF_INVALID_IDX)) {
     if (btif_hf_cb[idx].peer_feat & BTA_AG_PEER_FEAT_VREC) {
-      tBTA_AG_RES_DATA ag_res;
-      memset(&ag_res, 0, sizeof(ag_res));
+      tBTA_AG_RES_DATA ag_res = {};
       ag_res.state = 0;
       BTA_AgResult(btif_hf_cb[idx].handle, BTA_AG_BVRA_RES, &ag_res);
 
@@ -949,8 +934,7 @@ static bt_status_t volume_control(bthf_volume_type_t type, int volume,
     return BT_STATUS_FAIL;
   }
 
-  tBTA_AG_RES_DATA ag_res;
-  memset(&ag_res, 0, sizeof(tBTA_AG_RES_DATA));
+  tBTA_AG_RES_DATA ag_res = {};
   if (is_connected(bd_addr) && (idx != BTIF_HF_INVALID_IDX)) {
     ag_res.num = volume;
     BTA_AgResult(
@@ -977,7 +961,7 @@ static bt_status_t device_status_notification(bthf_network_state_t ntk_state,
                                               int signal, int batt_chg) {
   CHECK_BTHF_INIT();
 
-  if (is_connected(NULL)) {
+  if (is_connected(nullptr)) {
     /* send all indicators to BTA.
     ** BTA will make sure no duplicates are sent out
     */
@@ -1013,7 +997,7 @@ static bt_status_t cops_response(const char* cops, RawAddress* bd_addr) {
   }
 
   if (is_connected(bd_addr) && (idx != BTIF_HF_INVALID_IDX)) {
-    tBTA_AG_RES_DATA ag_res;
+    tBTA_AG_RES_DATA ag_res = {};
 
     /* Format the response */
     snprintf(ag_res.str, sizeof(ag_res.str), "0,0,\"%.16s\"", cops);
@@ -1047,9 +1031,7 @@ static bt_status_t cind_response(int svc, int num_active, int num_held,
   }
 
   if (is_connected(bd_addr) && (idx != BTIF_HF_INVALID_IDX)) {
-    tBTA_AG_RES_DATA ag_res;
-
-    memset(&ag_res, 0, sizeof(ag_res));
+    tBTA_AG_RES_DATA ag_res = {};
     /* per the errata 2043, call=1 implies atleast one call is in progress
      *(active/held)
      ** https://www.bluetooth.org/errata/errata_view.cfm?errata_id=2043
@@ -1074,7 +1056,6 @@ static bt_status_t cind_response(int svc, int num_active, int num_held,
 
 static bt_status_t set_sco_allowed(bool value) {
   CHECK_BTHF_INIT();
-
   BTA_AgSetScoAllowed(value);
   return BT_STATUS_SUCCESS;
 }
@@ -1091,7 +1072,7 @@ static bt_status_t set_sco_allowed(bool value) {
  ******************************************************************************/
 static bt_status_t formatted_at_response(const char* rsp, RawAddress* bd_addr) {
   CHECK_BTHF_INIT();
-  tBTA_AG_RES_DATA ag_res;
+  tBTA_AG_RES_DATA ag_res = {};
   int idx = btif_hf_idx_by_bdaddr(bd_addr);
 
   if ((idx < 0) || (idx >= BTIF_HF_NUM_CB)) {
@@ -1101,7 +1082,6 @@ static bt_status_t formatted_at_response(const char* rsp, RawAddress* bd_addr) {
 
   if (is_connected(bd_addr) && (idx != BTIF_HF_INVALID_IDX)) {
     /* Format the response and send */
-    memset(&ag_res, 0, sizeof(ag_res));
     strncpy(ag_res.str, rsp, BTA_AG_AT_MAX_LEN);
     BTA_AgResult(btif_hf_cb[idx].handle, BTA_AG_UNAT_RES, &ag_res);
 
@@ -1168,9 +1148,7 @@ static bt_status_t clcc_response(int index, bthf_call_direction_t dir,
   }
 
   if (is_connected(bd_addr) && (idx != BTIF_HF_INVALID_IDX)) {
-    tBTA_AG_RES_DATA ag_res;
-    memset(&ag_res, 0, sizeof(ag_res));
-
+    tBTA_AG_RES_DATA ag_res = {};
     /* Format the response */
     if (index == 0) {
       ag_res.ok_flag = BTA_AG_OK_DONE;
@@ -1223,7 +1201,6 @@ static bt_status_t phone_state_change(int num_active, int num_held,
                                       const char* number,
                                       bthf_call_addrtype_t type) {
   tBTA_AG_RES res = 0xff;
-  tBTA_AG_RES_DATA ag_res;
   bt_status_t status = BT_STATUS_SUCCESS;
   bool activeCallUpdated = false;
   int idx, i;
@@ -1260,7 +1237,7 @@ static bt_status_t phone_state_change(int num_active, int num_held,
       BTIF_TRACE_DEBUG("%s: Record call termination timestamp", __func__);
       clock_gettime(CLOCK_MONOTONIC, &btif_hf_cb[0].call_end_timestamp);
     }
-    BTA_AgResult(BTA_AG_HANDLE_ALL, BTA_AG_END_CALL_RES, NULL);
+    BTA_AgResult(BTA_AG_HANDLE_ALL, BTA_AG_END_CALL_RES, nullptr);
     hf_idx = BTIF_HF_INVALID_IDX;
 
     /* if held call was present, reset that as well */
@@ -1283,11 +1260,11 @@ static bt_status_t phone_state_change(int num_active, int num_held,
   if (((num_active + num_held) > 0) && (btif_hf_cb[idx].num_active == 0) &&
       (btif_hf_cb[idx].num_held == 0) &&
       (btif_hf_cb[idx].call_setup_state == BTHF_CALL_STATE_IDLE)) {
+    tBTA_AG_RES_DATA ag_res = {};
     BTIF_TRACE_DEBUG(
         "%s: Active/Held call notification received without call setup update",
         __func__);
 
-    memset(&ag_res, 0, sizeof(tBTA_AG_RES_DATA));
     ag_res.audio_handle = BTA_AG_HANDLE_SCO_NO_CHANGE;
     /* Addition call setup with the Active call
     ** CIND response should have been updated.
@@ -1303,11 +1280,10 @@ static bt_status_t phone_state_change(int num_active, int num_held,
 
   /* Ringing call changed? */
   if (call_setup_state != btif_hf_cb[idx].call_setup_state) {
+    tBTA_AG_RES_DATA ag_res = {};
     BTIF_TRACE_DEBUG("%s: Call setup states changed. old: %s new: %s", __func__,
                      dump_hf_call_state(btif_hf_cb[idx].call_setup_state),
                      dump_hf_call_state(call_setup_state));
-    memset(&ag_res, 0, sizeof(tBTA_AG_RES_DATA));
-
     switch (call_setup_state) {
       case BTHF_CALL_STATE_IDLE: {
         switch (btif_hf_cb[idx].call_setup_state) {
@@ -1387,8 +1363,6 @@ static bt_status_t phone_state_change(int num_active, int num_held,
     }
   }
 
-  memset(&ag_res, 0, sizeof(tBTA_AG_RES_DATA));
-
   /* per the errata 2043, call=1 implies atleast one call is in progress
    *(active/held)
    ** https://www.bluetooth.org/errata/errata_view.cfm?errata_id=2043
@@ -1451,8 +1425,8 @@ update_call_states:
  * Returns          bt_status_t
  *
  ******************************************************************************/
-bool btif_hf_is_call_idle(void) {
-  if (bt_hf_callbacks == NULL) return true;
+bool btif_hf_is_call_idle() {
+  if (bt_hf_callbacks == nullptr) return true;
 
   for (int i = 0; i < btif_max_hf_clients; ++i) {
     if ((btif_hf_cb[i].call_setup_state != BTHF_CALL_STATE_IDLE) ||
@@ -1465,28 +1439,6 @@ bool btif_hf_is_call_idle(void) {
 
 /*******************************************************************************
  *
- * Function         btif_hf_call_terminated_recently
- *
- * Description      Checks if a call has been terminated
- *
- * Returns          bt_status_t
- *
- ******************************************************************************/
-bool btif_hf_call_terminated_recently() {
-  struct timespec now;
-
-  clock_gettime(CLOCK_MONOTONIC, &now);
-  if (now.tv_sec <
-      btif_hf_cb[0].call_end_timestamp.tv_sec + BTIF_HF_CALL_END_TIMEOUT) {
-    return true;
-  } else {
-    btif_hf_cb[0].call_end_timestamp.tv_sec = 0;
-    return false;
-  }
-}
-
-/*******************************************************************************
- *
  * Function         cleanup
  *
  * Description      Closes the HF interface
@@ -1494,7 +1446,7 @@ bool btif_hf_call_terminated_recently() {
  * Returns          bt_status_t
  *
  ******************************************************************************/
-static void cleanup(void) {
+static void cleanup() {
   BTIF_TRACE_EVENT("%s", __func__);
 
   btif_queue_cleanup(UUID_SERVCLASS_AG_HANDSFREE);
@@ -1504,7 +1456,7 @@ static void cleanup(void) {
 #else
     btif_disable_service(BTA_HSP_SERVICE_ID);
 #endif
-    bt_hf_callbacks = NULL;
+    bt_hf_callbacks = nullptr;
   }
 }
 
index a830f91..203eeaf 100644 (file)
@@ -347,7 +347,6 @@ static btrc_ctrl_callbacks_t* bt_rc_ctrl_callbacks = NULL;
 /*****************************************************************************
  *  Externs
  *****************************************************************************/
-extern bool btif_hf_call_terminated_recently();
 extern bool check_cod(const RawAddress* remote_bdaddr, uint32_t cod);
 
 /*****************************************************************************