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

Commit 6ebe7717 authored by Jack He's avatar Jack He
Browse files

HFP: Add APIs for set and get active device (3/3)

* Add set active device APIs to set active device from Java layer
* Set active device to the first connected device if no one set it
  before
* Clear active device on RFCOMM disconnection if active device is the
  one getting disconnected
* Currently, the active device value is not used in any functional code

Bug: 68951996
Test: runtest -j40 bluetooth
Change-Id: Id0c00e89178b0f963ed8642e72c7010160dd1d68
parent ae3fc182
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -56,4 +56,6 @@ interface IBluetoothHeadset {
    oneway void phoneStateChanged(int numActive, int numHeld, int callState, String number, int type);
    void clccResponse(int index, int direction, int status, int mode, boolean mpty,
                      String number, int type);
    boolean setActiveDevice(in BluetoothDevice device);
    BluetoothDevice getActiveDevice();
}
+9 −1
Original line number Diff line number Diff line
@@ -406,6 +406,10 @@ void bta_ag_rfc_close(tBTA_AG_SCB* p_scb, UNUSED_ATTR tBTA_AG_DATA* p_data) {
  /* call close call-out */
  bta_ag_co_data_close(close.hdr.handle);

  if (bta_ag_get_active_device() == p_scb->peer_addr) {
    bta_clear_active_device();
  }

  /* call close cback */
  (*bta_ag_cb.p_cback)(BTA_AG_CLOSE_EVT, (tBTA_AG*)&close);

@@ -764,7 +768,11 @@ void bta_ag_svc_conn_open(tBTA_AG_SCB* p_scb,
        (p_scb->callsetup_ind != BTA_AG_CALLSETUP_NONE)) {
      bta_sys_sco_use(BTA_ID_AG, p_scb->app_id, p_scb->peer_addr);
    }

    if (bta_ag_get_active_device().IsEmpty()) {
      tBTA_AG_DATA data = {};
      data.api_set_active_device.active_device_addr = p_scb->peer_addr;
      bta_ag_api_set_active_device(&data);
    }
    (*bta_ag_cb.p_cback)(BTA_AG_CONN_EVT, (tBTA_AG*)&evt);
  }
}
+11 −0
Original line number Diff line number Diff line
@@ -286,3 +286,14 @@ void BTA_AgSetScoAllowed(bool value) {

  bta_sys_sendmsg(p_buf);
}

void BTA_AgSetActiveDevice(const RawAddress& active_device_addr) {
  tBTA_AG_API_SET_ACTIVE_DEVICE* p_buf =
      (tBTA_AG_API_SET_ACTIVE_DEVICE*)osi_malloc(
          sizeof(tBTA_AG_API_SET_ACTIVE_DEVICE));

  p_buf->hdr.event = BTA_AG_API_SET_ACTIVE_DEVICE_EVT;
  p_buf->active_device_addr = active_device_addr;

  bta_sys_sendmsg(p_buf);
}
+11 −1
Original line number Diff line number Diff line
@@ -92,7 +92,8 @@ enum {
  /* these events are handled outside of the state machine */
  BTA_AG_API_ENABLE_EVT,
  BTA_AG_API_DISABLE_EVT,
  BTA_AG_API_SET_SCO_ALLOWED_EVT
  BTA_AG_API_SET_SCO_ALLOWED_EVT,
  BTA_AG_API_SET_ACTIVE_DEVICE_EVT
};

/* Actions to perform after a SCO event */
@@ -170,6 +171,11 @@ typedef struct {
  bool value;
} tBTA_AG_API_SET_SCO_ALLOWED;

typedef struct {
  BT_HDR hdr;
  RawAddress active_device_addr;
} tBTA_AG_API_SET_ACTIVE_DEVICE;

/* data type for BTA_AG_DISC_RESULT_EVT */
typedef struct {
  BT_HDR hdr;
@@ -197,6 +203,7 @@ typedef union {
  tBTA_AG_API_RESULT api_result;
  tBTA_AG_API_SETCODEC api_setcodec;
  tBTA_AG_API_SET_SCO_ALLOWED api_set_sco_allowed;
  tBTA_AG_API_SET_ACTIVE_DEVICE api_set_active_device;
  tBTA_AG_DISC_RESULT disc_result;
  tBTA_AG_RFC rfc;
  tBTA_AG_CI_RX_WRITE ci_rx_write;
@@ -395,5 +402,8 @@ extern void bta_ag_ci_sco_data(tBTA_AG_SCB* p_scb, tBTA_AG_DATA* p_data);
extern void bta_ag_ci_rx_data(tBTA_AG_SCB* p_scb, tBTA_AG_DATA* p_data);
extern void bta_ag_rcvd_slc_ready(tBTA_AG_SCB* p_scb, tBTA_AG_DATA* p_data);
extern void bta_ag_set_sco_allowed(tBTA_AG_DATA* p_data);
extern const RawAddress& bta_ag_get_active_device();
extern void bta_clear_active_device();
extern void bta_ag_api_set_active_device(tBTA_AG_DATA* p_data);

#endif /* BTA_AG_INT_H */
+4 −0
Original line number Diff line number Diff line
@@ -793,6 +793,10 @@ bool bta_ag_hdl_event(BT_HDR* p_msg) {
      bta_ag_set_sco_allowed((tBTA_AG_DATA*)p_msg);
      break;

    case BTA_AG_API_SET_ACTIVE_DEVICE_EVT:
      bta_ag_api_set_active_device((tBTA_AG_DATA*)p_msg);
      break;

    /* all others reference scb by handle */
    default:
      p_scb = bta_ag_scb_by_idx(p_msg->layer_specific);
Loading