OSDN Git Service

Add support for inband ringing feature
authorJack He <siyuanh@google.com>
Fri, 3 Feb 2017 01:42:40 +0000 (17:42 -0800)
committerAndre Eisenbach <eisenbach@google.com>
Mon, 10 Apr 2017 19:50:39 +0000 (19:50 +0000)
* Change HFP init API so that the HFP feature bit field depends on
  whether in-band ringing is supported on the device
* Feature disabled by default unless system property enables it

Bug: 19171297
Test: mm -j 40, HFP regression test, testplans/82144
Change-Id: Ib8ba28ac6e70eb23b2a2ad11c5805793911a4e43

bta/ag/bta_ag_cmd.cc
btif/src/btif_hf.cc

index 405712b..d9033e1 100644 (file)
@@ -1316,15 +1316,14 @@ void bta_ag_hsp_result(tBTA_AG_SCB* p_scb, tBTA_AG_API_RESULT* p_result) {
       if (bta_ag_sco_is_open(p_scb) || !bta_ag_inband_enabled(p_scb) ||
           (p_scb->features & BTA_AG_FEAT_NOSCO)) {
         bta_ag_send_ring(p_scb, (tBTA_AG_DATA*)p_result);
-      }
-      /* else open sco, send ring after sco opened */
-      else {
+      } else {
+        /* else open sco, send ring after sco opened */
         /* HSPv1.2: AG shall not send RING if using in-band ring tone. */
-        if (p_scb->hsp_version >= HSP_VERSION_1_2)
+        if (p_scb->hsp_version >= HSP_VERSION_1_2) {
           p_scb->post_sco = BTA_AG_POST_SCO_NONE;
-        else
+        } else {
           p_scb->post_sco = BTA_AG_POST_SCO_RING;
-
+        }
         bta_ag_sco_open(p_scb, (tBTA_AG_DATA*)p_result);
       }
       break;
@@ -1337,12 +1336,14 @@ void bta_ag_hsp_result(tBTA_AG_SCB* p_scb, tBTA_AG_API_RESULT* p_result) {
       }
 
       if (!(p_scb->features & BTA_AG_FEAT_NOSCO)) {
-        /* if audio connected to this scb open sco */
-        if (p_result->data.audio_handle == bta_ag_scb_to_idx(p_scb)) {
+        /* if audio connected to this scb AND sco is not opened, open sco */
+        if (p_result->data.audio_handle == bta_ag_scb_to_idx(p_scb) &&
+            !bta_ag_sco_is_open(p_scb)) {
           bta_ag_sco_open(p_scb, (tBTA_AG_DATA*)p_result);
         }
         /* else if no audio at call close sco */
-        else if (p_result->data.audio_handle == BTA_AG_HANDLE_NONE) {
+        else if (p_result->data.audio_handle == BTA_AG_HANDLE_NONE &&
+                 bta_ag_sco_is_open(p_scb)) {
           bta_ag_sco_close(p_scb, (tBTA_AG_DATA*)p_result);
         }
       }
@@ -1435,9 +1436,8 @@ void bta_ag_hfp_result(tBTA_AG_SCB* p_scb, tBTA_AG_API_RESULT* p_result) {
         if (bta_ag_sco_is_open(p_scb) || !bta_ag_inband_enabled(p_scb) ||
             (p_scb->features & BTA_AG_FEAT_NOSCO)) {
           bta_ag_send_ring(p_scb, (tBTA_AG_DATA*)p_result);
-        }
-        /* else open sco, send ring after sco opened */
-        else {
+        } else {
+          /* else open sco, send ring after sco opened */
           p_scb->post_sco = BTA_AG_POST_SCO_RING;
           bta_ag_sco_open(p_scb, (tBTA_AG_DATA*)p_result);
         }
@@ -1453,7 +1453,8 @@ void bta_ag_hfp_result(tBTA_AG_SCB* p_scb, tBTA_AG_API_RESULT* p_result) {
       bta_ag_send_call_inds(p_scb, p_result->result);
 
       if (!(p_scb->features & BTA_AG_FEAT_NOSCO)) {
-        if (p_result->data.audio_handle == bta_ag_scb_to_idx(p_scb)) {
+        if (p_result->data.audio_handle == bta_ag_scb_to_idx(p_scb) &&
+            !bta_ag_sco_is_open(p_scb)) {
           bta_ag_sco_open(p_scb, (tBTA_AG_DATA*)p_result);
         } else if ((p_result->data.audio_handle == BTA_AG_HANDLE_NONE) &&
                    bta_ag_sco_is_open(p_scb)) {
index c92a479..6006d6e 100644 (file)
@@ -41,6 +41,7 @@
 #include "btif_hf.h"
 #include "btif_profile_queue.h"
 #include "btif_util.h"
+#include "osi/include/properties.h"
 
 /*******************************************************************************
  *  Constants & Macros
@@ -84,6 +85,9 @@
 #endif
 #endif
 
+/* 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)
@@ -671,6 +675,17 @@ static void btif_in_hf_generic_evt(uint16_t event, char* p_param) {
   }
 }
 
+static bool inband_ringing_property_enabled() {
+  char inband_ringing_flag[PROPERTY_VALUE_MAX] = {0};
+  osi_property_get("persist.bluetooth.enableinbandringing", inband_ringing_flag,
+                   "false");
+  if (strncmp(inband_ringing_flag, "true", 4) == 0) {
+    BTIF_TRACE_DEBUG("%s: In-band ringing enabled by property", __func__);
+    return true;
+  }
+  return false;
+}
+
 /*******************************************************************************
  *
  * Function         btif_hf_init
@@ -680,10 +695,20 @@ static void btif_in_hf_generic_evt(uint16_t event, char* p_param) {
  * Returns         bt_status_t
  *
  ******************************************************************************/
-static bt_status_t init(bthf_callbacks_t* callbacks, int max_hf_clients) {
+static bt_status_t init(bthf_callbacks_t* callbacks, int max_hf_clients,
+                        bool inband_ringing_supported) {
+  bool inband_ringing_property_enable = inband_ringing_property_enabled();
+  if (inband_ringing_supported && inband_ringing_property_enable) {
+    btif_hf_features |= BTA_AG_FEAT_INBAND;
+  } else {
+    btif_hf_features &= ~BTA_AG_FEAT_INBAND;
+  }
   btif_max_hf_clients = max_hf_clients;
-  BTIF_TRACE_DEBUG("%s - max_hf_clients=%d", __func__, btif_max_hf_clients);
-
+  BTIF_TRACE_DEBUG(
+      "%s: btif_hf_features=%zu, max_hf_clients=%d, "
+      "inband_ringing=[supported=%d, enabled=%d]",
+      __func__, btif_hf_features, btif_max_hf_clients, inband_ringing_supported,
+      inband_ringing_property_enable);
   bt_hf_callbacks = callbacks;
   memset(&btif_hf_cb, 0, sizeof(btif_hf_cb));
 
@@ -1331,10 +1356,11 @@ static bt_status_t phone_state_change(int num_active, int num_held,
       } break;
 
       case BTHF_CALL_STATE_INCOMING:
-        if (num_active || num_held)
+        if (num_active || num_held) {
           res = BTA_AG_CALL_WAIT_RES;
-        else
+        } else {
           res = BTA_AG_IN_CALL_RES;
+        }
         if (number) {
           int xx = 0;
           if ((type == BTHF_CALL_ADDRTYPE_INTERNATIONAL) && (*number != '+'))
@@ -1560,7 +1586,7 @@ bt_status_t btif_hf_execute_service(bool b_enable) {
     /* Enable and register with BTA-AG */
     BTA_AgEnable(BTA_AG_PARSE, bte_hf_evt);
     for (i = 0; i < btif_max_hf_clients; i++) {
-      BTA_AgRegister(BTIF_HF_SERVICES, BTIF_HF_SECURITY, BTIF_HF_FEATURES,
+      BTA_AgRegister(BTIF_HF_SERVICES, BTIF_HF_SECURITY, btif_hf_features,
                      p_service_names, bthf_hf_id[i]);
     }
   } else {