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

Commit 93a5acca authored by Jack He's avatar Jack He Committed by android-build-merger
Browse files

Merge "eSCO: Limit number of retries after mSBC connection failure"

am: 557f161b

Change-Id: I57bdffaac640741e62078fd2fe206c22ca8f3144
parents e39ee0b5 557f161b
Loading
Loading
Loading
Loading
+0 −1
Original line number Original line Diff line number Diff line
@@ -258,7 +258,6 @@ typedef struct {
  uint8_t roam_ind;         /* CIEV roam indicator value */
  uint8_t roam_ind;         /* CIEV roam indicator value */
  uint8_t battchg_ind;      /* CIEV battery charge indicator value */
  uint8_t battchg_ind;      /* CIEV battery charge indicator value */
  uint8_t callheld_ind;     /* CIEV call held indicator value */
  uint8_t callheld_ind;     /* CIEV call held indicator value */
  bool retry_with_sco_only; /* indicator to try with SCO only when eSCO fails */
  uint32_t bia_masked_out;  /* indicators HF does not want us to send */
  uint32_t bia_masked_out;  /* indicators HF does not want us to send */
  alarm_t* collision_timer;
  alarm_t* collision_timer;
  alarm_t* ring_timer;
  alarm_t* ring_timer;
+1 −0
Original line number Original line Diff line number Diff line
@@ -260,6 +260,7 @@ static tBTA_AG_SCB* bta_ag_scb_alloc(void) {
      p_scb->in_use = true;
      p_scb->in_use = true;
      p_scb->sco_idx = BTM_INVALID_SCO_INDEX;
      p_scb->sco_idx = BTM_INVALID_SCO_INDEX;
      p_scb->codec_updated = false;
      p_scb->codec_updated = false;
      p_scb->codec_fallback = false;
      p_scb->peer_codecs = BTA_AG_CODEC_CVSD;
      p_scb->peer_codecs = BTA_AG_CODEC_CVSD;
      p_scb->sco_codec = BTA_AG_CODEC_CVSD;
      p_scb->sco_codec = BTA_AG_CODEC_CVSD;
      /* set up timers */
      /* set up timers */
+29 −65
Original line number Original line Diff line number Diff line
@@ -177,14 +177,20 @@ static void bta_ag_sco_disc_cback(uint16_t sco_idx) {
        bta_ag_cb.sco.p_curr_scb->state = BTA_AG_SCO_CODEC_ST;
        bta_ag_cb.sco.p_curr_scb->state = BTA_AG_SCO_CODEC_ST;
        if (bta_ag_cb.sco.p_curr_scb->codec_msbc_settings ==
        if (bta_ag_cb.sco.p_curr_scb->codec_msbc_settings ==
            BTA_AG_SCO_MSBC_SETTINGS_T2) {
            BTA_AG_SCO_MSBC_SETTINGS_T2) {
          APPL_TRACE_DEBUG("%s: Fallback to mSBC T1 settings", __func__);
          APPL_TRACE_WARNING(
              "%s: eSCO/SCO failed to open, falling back to mSBC T1 settings",
              __func__);
          bta_ag_cb.sco.p_curr_scb->codec_msbc_settings =
          bta_ag_cb.sco.p_curr_scb->codec_msbc_settings =
              BTA_AG_SCO_MSBC_SETTINGS_T1;
              BTA_AG_SCO_MSBC_SETTINGS_T1;
        } else {
        } else {
          APPL_TRACE_DEBUG("%s: Fallback to CVSD", __func__);
          APPL_TRACE_WARNING(
              "%s: eSCO/SCO failed to open, falling back to CVSD", __func__);
          bta_ag_cb.sco.p_curr_scb->codec_fallback = true;
          bta_ag_cb.sco.p_curr_scb->codec_fallback = true;
        }
        }
      }
      }
    } else if (bta_ag_sco_is_opening(bta_ag_cb.sco.p_curr_scb)) {
      APPL_TRACE_ERROR("%s: eSCO/SCO failed to open, no more fall back",
                       __func__);
    }
    }


    bta_ag_cb.sco.p_curr_scb->inuse_codec = BTA_AG_CODEC_NONE;
    bta_ag_cb.sco.p_curr_scb->inuse_codec = BTA_AG_CODEC_NONE;
@@ -354,6 +360,11 @@ static void bta_ag_cback_sco(tBTA_AG_SCB* p_scb, uint8_t event) {
 *
 *
 ******************************************************************************/
 ******************************************************************************/
static void bta_ag_create_sco(tBTA_AG_SCB* p_scb, bool is_orig) {
static void bta_ag_create_sco(tBTA_AG_SCB* p_scb, bool is_orig) {
  APPL_TRACE_DEBUG(
      "%s: BEFORE codec_updated=%d, codec_fallback=%d, "
      "sco_codec=%d, peer_codec=%d, msbc_settings=%d",
      __func__, p_scb->codec_updated, p_scb->codec_fallback, p_scb->sco_codec,
      p_scb->peer_codecs, p_scb->codec_msbc_settings);
  tBTA_AG_PEER_CODEC esco_codec = BTA_AG_CODEC_CVSD;
  tBTA_AG_PEER_CODEC esco_codec = BTA_AG_CODEC_CVSD;


  /* Make sure this SCO handle is not already in use */
  /* Make sure this SCO handle is not already in use */
@@ -363,18 +374,15 @@ static void bta_ag_create_sco(tBTA_AG_SCB* p_scb, bool is_orig) {
    return;
    return;
  }
  }


  APPL_TRACE_DEBUG("%s: Using enhanced SCO setup command %d", __func__,
  if ((p_scb->sco_codec == BTA_AG_CODEC_MSBC) && !p_scb->codec_fallback)
                   controller_get_interface()
                       ->supports_enhanced_setup_synchronous_connection());

  if ((p_scb->sco_codec == BTA_AG_CODEC_MSBC) && !p_scb->codec_fallback &&
      !p_scb->retry_with_sco_only)
    esco_codec = BTA_AG_CODEC_MSBC;
    esco_codec = BTA_AG_CODEC_MSBC;


  if (p_scb->codec_fallback) {
  if (p_scb->codec_fallback) {
    p_scb->codec_fallback = false;
    p_scb->codec_fallback = false;
    /* Force AG to send +BCS for the next audio connection. */
    /* Force AG to send +BCS for the next audio connection. */
    p_scb->codec_updated = true;
    p_scb->codec_updated = true;
    /* Reset mSBC settings to T2 for the next audio connection */
    p_scb->codec_msbc_settings = BTA_AG_SCO_MSBC_SETTINGS_T2;
  }
  }


  esco_codec_t codec_index = ESCO_CODEC_CVSD;
  esco_codec_t codec_index = ESCO_CODEC_CVSD;
@@ -406,32 +414,9 @@ static void bta_ag_create_sco(tBTA_AG_SCB* p_scb, bool is_orig) {
  /* If initiating, setup parameters to start SCO/eSCO connection */
  /* If initiating, setup parameters to start SCO/eSCO connection */
  if (is_orig) {
  if (is_orig) {
    bta_ag_cb.sco.is_local = true;
    bta_ag_cb.sco.is_local = true;
    /* Attempt to use eSCO if remote host supports HFP >= 1.5 */
    /* Set eSCO Mode */
    /* HSP does not prohibit eSCO, but no official support, CVSD only */
    if (p_scb->conn_service == BTA_AG_HFP &&
        p_scb->peer_version >= HFP_VERSION_1_5 && !p_scb->retry_with_sco_only) {
    BTM_SetEScoMode(&params);
    BTM_SetEScoMode(&params);
      /* If eSCO or EDR eSCO, retry with SCO only in case of failure */
      if ((params.packet_types & BTM_ESCO_LINK_ONLY_MASK) ||
          !((params.packet_types &
             ~(BTM_ESCO_LINK_ONLY_MASK | BTM_SCO_LINK_ONLY_MASK)) ^
            BTA_AG_NO_EDR_ESCO)) {
        /* However, do not retry with SCO when using mSBC */
        if (esco_codec != BTA_AG_CODEC_MSBC) {
          p_scb->retry_with_sco_only = true;
        }
        APPL_TRACE_API("%s: eSCO supported, retry_with_sco_only=%d", __func__,
                       p_scb->retry_with_sco_only);
      }
    } else {
      APPL_TRACE_API("%s: eSCO not supported, retry_with_sco_only=%d", __func__,
                     p_scb->retry_with_sco_only);
      p_scb->retry_with_sco_only = false;
      BTM_SetEScoMode(&params);
    }

    bta_ag_cb.sco.p_curr_scb = p_scb;
    bta_ag_cb.sco.p_curr_scb = p_scb;

    /* save the current codec as sco_codec can be updated while SCO is open. */
    /* save the current codec as sco_codec can be updated while SCO is open. */
    p_scb->inuse_codec = esco_codec;
    p_scb->inuse_codec = esco_codec;


@@ -443,7 +428,6 @@ static void bta_ag_create_sco(tBTA_AG_SCB* p_scb, bool is_orig) {
  } else {
  } else {
    /* Not initiating, go to listen mode */
    /* Not initiating, go to listen mode */
    uint8_t* p_bd_addr = NULL;
    uint8_t* p_bd_addr = NULL;
    p_scb->retry_with_sco_only = false;
    p_bd_addr = p_scb->peer_addr;
    p_bd_addr = p_scb->peer_addr;


    tBTM_STATUS status =
    tBTM_STATUS status =
@@ -456,6 +440,11 @@ static void bta_ag_create_sco(tBTA_AG_SCB* p_scb, bool is_orig) {
                   __func__, is_orig, p_scb->sco_idx, status,
                   __func__, is_orig, p_scb->sco_idx, status,
                   params.packet_types);
                   params.packet_types);
  }
  }
  APPL_TRACE_DEBUG(
      "%s: AFTER codec_updated=%d, codec_fallback=%d, "
      "sco_codec=%d, peer_codec=%d, msbc_settings=%d",
      __func__, p_scb->codec_updated, p_scb->codec_fallback, p_scb->sco_codec,
      p_scb->peer_codecs, p_scb->codec_msbc_settings);
}
}


/*******************************************************************************
/*******************************************************************************
@@ -528,25 +517,6 @@ static void bta_ag_create_pending_sco(tBTA_AG_SCB* p_scb, bool is_local) {
  }
  }
}
}


/*******************************************************************************
 *
 * Function         bta_ag_attempt_msbc_safe_settings
 *
 * Description    Checks if ESCO connection needs to be attempted using mSBC
 *                T1(safe) settings
 *
 *
 * Returns          true if T1 settings has to be used, false otherwise
 *
 ******************************************************************************/
bool bta_ag_attempt_msbc_safe_settings(tBTA_AG_SCB* p_scb) {
  if (p_scb->svc_conn && p_scb->sco_codec == BTM_SCO_CODEC_MSBC &&
      p_scb->codec_msbc_settings == BTA_AG_SCO_MSBC_SETTINGS_T1)
    return true;
  else
    return false;
}

/*******************************************************************************
/*******************************************************************************
 *
 *
 * Function         bta_ag_codec_negotiation_timer_cback
 * Function         bta_ag_codec_negotiation_timer_cback
@@ -1296,7 +1266,6 @@ void bta_ag_sco_conn_open(tBTA_AG_SCB* p_scb,
  /* call app callback */
  /* call app callback */
  bta_ag_cback_sco(p_scb, BTA_AG_AUDIO_OPEN_EVT);
  bta_ag_cback_sco(p_scb, BTA_AG_AUDIO_OPEN_EVT);


  p_scb->retry_with_sco_only = false;
  /* reset to mSBC T2 settings as the preferred */
  /* reset to mSBC T2 settings as the preferred */
  p_scb->codec_msbc_settings = BTA_AG_SCO_MSBC_SETTINGS_T2;
  p_scb->codec_msbc_settings = BTA_AG_SCO_MSBC_SETTINGS_T2;
}
}
@@ -1318,17 +1287,13 @@ void bta_ag_sco_conn_close(tBTA_AG_SCB* p_scb,
  p_scb->sco_idx = BTM_INVALID_SCO_INDEX;
  p_scb->sco_idx = BTM_INVALID_SCO_INDEX;


  /* codec_fallback is set when AG is initiator and connection failed for mSBC.
  /* codec_fallback is set when AG is initiator and connection failed for mSBC.
   */
   * OR if codec is msbc and T2 settings failed, then retry Safe T1 settings */
  /* OR if codec is msbc and T2 settings failed, then retry Safe T1 settings */
  if (p_scb->svc_conn &&
  if ((p_scb->codec_fallback && p_scb->svc_conn) ||
      (p_scb->codec_fallback ||
      bta_ag_attempt_msbc_safe_settings(p_scb)) {
       (p_scb->sco_codec == BTM_SCO_CODEC_MSBC &&
        p_scb->codec_msbc_settings == BTA_AG_SCO_MSBC_SETTINGS_T1))) {
    bta_ag_sco_event(p_scb, BTA_AG_SCO_REOPEN_E);
    bta_ag_sco_event(p_scb, BTA_AG_SCO_REOPEN_E);
  } else if (p_scb->retry_with_sco_only && p_scb->svc_conn) {
  } else {
    /* retry_with_sco_only is set when AG is initiator and connection failed for
     * eSCO */
    bta_ag_create_sco(p_scb, true);
  }
  else {
    /* Indicate if the closing of audio is because of transfer */
    /* Indicate if the closing of audio is because of transfer */
    bta_ag_sco_event(p_scb, BTA_AG_SCO_CONN_CLOSE_E);
    bta_ag_sco_event(p_scb, BTA_AG_SCO_CONN_CLOSE_E);


@@ -1346,7 +1311,6 @@ void bta_ag_sco_conn_close(tBTA_AG_SCB* p_scb,
    bta_ag_cback_sco(p_scb, BTA_AG_AUDIO_CLOSE_EVT);
    bta_ag_cback_sco(p_scb, BTA_AG_AUDIO_CLOSE_EVT);
    p_scb->codec_msbc_settings = BTA_AG_SCO_MSBC_SETTINGS_T2;
    p_scb->codec_msbc_settings = BTA_AG_SCO_MSBC_SETTINGS_T2;
  }
  }
  p_scb->retry_with_sco_only = false;
}
}


/*******************************************************************************
/*******************************************************************************
+0 −1
Original line number Original line Diff line number Diff line
@@ -174,7 +174,6 @@ typedef struct {
  uint16_t sco_idx;                       /* SCO handle */
  uint16_t sco_idx;                       /* SCO handle */
  uint8_t sco_state;                      /* SCO state variable */
  uint8_t sco_state;                      /* SCO state variable */
  bool sco_close_rfc; /* true if also close RFCOMM after SCO */
  bool sco_close_rfc; /* true if also close RFCOMM after SCO */
  bool retry_with_sco_only;
  tBTM_SCO_CODEC_TYPE negotiated_codec; /* negotiated codec */
  tBTM_SCO_CODEC_TYPE negotiated_codec; /* negotiated codec */
  bool svc_conn;      /* set to true when service level connection is up */
  bool svc_conn;      /* set to true when service level connection is up */
  bool send_at_reply; /* set to true to notify framework about AT results */
  bool send_at_reply; /* set to true to notify framework about AT results */
+9 −39
Original line number Original line Diff line number Diff line
@@ -236,30 +236,9 @@ static void bta_hf_client_sco_create(tBTA_HF_CLIENT_CB* client_cb,


  /* if initiating set current scb and peer bd addr */
  /* if initiating set current scb and peer bd addr */
  if (is_orig) {
  if (is_orig) {
    /* Attempt to use eSCO if remote host supports HFP >= 1.5 */
    if (client_cb->peer_version >= HFP_VERSION_1_5 &&
        !client_cb->retry_with_sco_only) {
    BTM_SetEScoMode(&params);
    BTM_SetEScoMode(&params);
      /* If ESCO or EDR ESCO, retry with SCO only in case of failure */
      if ((params.packet_types & BTM_ESCO_LINK_ONLY_MASK) ||
          !((params.packet_types &
             ~(BTM_ESCO_LINK_ONLY_MASK | BTM_SCO_LINK_ONLY_MASK)) ^
            BTA_HF_CLIENT_NO_EDR_ESCO)) {
        client_cb->retry_with_sco_only = true;
        APPL_TRACE_API("Setting retry_with_sco_only to true");
      }
    } else {
      if (client_cb->retry_with_sco_only)
        APPL_TRACE_API("retrying with SCO only");
      client_cb->retry_with_sco_only = false;

      BTM_SetEScoMode(&params);
    }

    /* tell sys to stop av if any */
    /* tell sys to stop av if any */
    bta_sys_sco_use(BTA_ID_HS, 1, client_cb->peer_addr);
    bta_sys_sco_use(BTA_ID_HS, 1, client_cb->peer_addr);
  } else {
    client_cb->retry_with_sco_only = false;
  }
  }


  p_bd_addr = client_cb->peer_addr;
  p_bd_addr = client_cb->peer_addr;
@@ -583,8 +562,6 @@ void bta_hf_client_sco_conn_open(tBTA_HF_CLIENT_DATA* p_data) {
  } else {
  } else {
    bta_hf_client_cback_sco(client_cb, BTA_HF_CLIENT_AUDIO_OPEN_EVT);
    bta_hf_client_cback_sco(client_cb, BTA_HF_CLIENT_AUDIO_OPEN_EVT);
  }
  }

  client_cb->retry_with_sco_only = false;
}
}


/*******************************************************************************
/*******************************************************************************
@@ -611,11 +588,6 @@ void bta_hf_client_sco_conn_close(tBTA_HF_CLIENT_DATA* p_data) {
  /* clear current scb */
  /* clear current scb */
  client_cb->sco_idx = BTM_INVALID_SCO_INDEX;
  client_cb->sco_idx = BTM_INVALID_SCO_INDEX;


  /* retry_with_sco_only, will be set only when initiator
  ** and HFClient is first trying to establish an eSCO connection */
  if (client_cb->retry_with_sco_only && client_cb->svc_conn) {
    bta_hf_client_sco_create(client_cb, true);
  } else {
  bta_hf_client_sco_event(client_cb, BTA_HF_CLIENT_SCO_CONN_CLOSE_E);
  bta_hf_client_sco_event(client_cb, BTA_HF_CLIENT_SCO_CONN_CLOSE_E);


  bta_sys_sco_close(BTA_ID_HS, 1, client_cb->peer_addr);
  bta_sys_sco_close(BTA_ID_HS, 1, client_cb->peer_addr);
@@ -630,8 +602,6 @@ void bta_hf_client_sco_conn_close(tBTA_HF_CLIENT_DATA* p_data) {
    bta_hf_client_rfc_do_close(p_data);
    bta_hf_client_rfc_do_close(p_data);
  }
  }
}
}
  client_cb->retry_with_sco_only = false;
}


/*******************************************************************************
/*******************************************************************************
 *
 *