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

Commit 2bd36b71 authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Automerger Merge Worker
Browse files

Merge "LE Audio State Machine and Native Interface boilerplate" am: a09be1c8

Original change: https://android-review.googlesource.com/c/platform/system/bt/+/1515334

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I209a7e7355f6a996fbed2cf39a8ed71742c43704
parents 69c6baef a09be1c8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ cc_library_static {
        "src/btif_hf_client.cc",
        "src/btif_hh.cc",
        "src/btif_hd.cc",
        "src/btif_le_audio.cc",
        "src/btif_pan.cc",
        "src/btif_profile_queue.cc",
        "src/btif_rc.cc",
+7 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
#include <hardware/bt_hearing_aid.h>
#include <hardware/bt_hf_client.h>
#include <hardware/bt_hh.h>
#include <hardware/bt_le_audio.h>
#include <hardware/bt_pan.h>
#include <hardware/bt_rc.h>
#include <hardware/bt_sdp.h>
@@ -78,6 +79,7 @@
#include "stack_manager.h"

using bluetooth::hearing_aid::HearingAidInterface;
using bluetooth::le_audio::LeAudioClientInterface;

/*******************************************************************************
 *  Static variables
@@ -119,6 +121,8 @@ extern const btrc_ctrl_interface_t* btif_rc_ctrl_get_interface();
extern const btsdp_interface_t* btif_sdp_get_interface();
/*Hearing Aid client*/
extern HearingAidInterface* btif_hearing_aid_get_interface();
/* LeAudio testi client */
extern LeAudioClientInterface* btif_le_audio_get_interface();

/*******************************************************************************
 *  Functions
@@ -435,6 +439,9 @@ static const void* get_profile_interface(const char* profile_id) {
    return NULL;
  }

  if (is_profile(profile_id, BT_PROFILE_LE_AUDIO_ID))
    return btif_le_audio_get_interface();

  return NULL;
}

+102 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 HIMSA II K/S - www.himsa.com. Represented by EHIMA -
 * www.ehima.com
 *
 * 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.
 */

#include <hardware/bluetooth.h>
#include <vector>

#include "btif_common.h"
#include "btif_storage.h"
#include "hardware/bt_le_audio.h"
#include "stack/include/btu.h"

#include <hardware/bt_le_audio.h>

using base::Bind;
using base::Unretained;
using bluetooth::le_audio::ConnectionState;

using bluetooth::le_audio::GroupStatus;
using bluetooth::le_audio::LeAudioClientCallbacks;
using bluetooth::le_audio::LeAudioClientInterface;

namespace {
class LeAudioClientInterfaceImpl;
std::unique_ptr<LeAudioClientInterface> lEAudioInstance;

class LeAudioClientInterfaceImpl : public LeAudioClientInterface,
                                   public LeAudioClientCallbacks {
  ~LeAudioClientInterfaceImpl() = default;

  void OnConnectionState(ConnectionState state,
                         const RawAddress& address) override {
    do_in_jni_thread(FROM_HERE, Bind(&LeAudioClientCallbacks::OnConnectionState,
                                     Unretained(callbacks), state, address));
  }

  void OnGroupStatus(uint8_t group_id, GroupStatus group_status,
                     uint8_t group_flags) override {
    do_in_jni_thread(FROM_HERE, Bind(&LeAudioClientCallbacks::OnGroupStatus,
                                     Unretained(callbacks), group_id,
                                     group_status, group_flags));
  }

  void OnSetMemberAvailable(const RawAddress& address,
                            uint8_t group_id) override {
    do_in_jni_thread(FROM_HERE,
                     Bind(&LeAudioClientCallbacks::OnSetMemberAvailable,
                          Unretained(callbacks), address, group_id));
  }

  void OnAudioConf(const RawAddress& addr, uint8_t direction, uint8_t group_id,
                   uint32_t snk_audio_location,
                   uint32_t src_audio_location) override {
    do_in_jni_thread(
        FROM_HERE,
        Bind(&LeAudioClientCallbacks::OnAudioConf, Unretained(callbacks), addr,
             direction, group_id, snk_audio_location, src_audio_location));
  }

  void Initialize(LeAudioClientCallbacks* callbacks) override {
    this->callbacks = callbacks;
  }

  void Cleanup(void) override {}

  void Connect(const RawAddress& address) override {}

  void Disconnect(const RawAddress& address) override {}

  void GroupStream(const uint8_t group_id,
                   const uint16_t content_type) override {}

  void GroupSuspend(const uint8_t group_id) override {}

  void GroupStop(const uint8_t group_id) override {}

 private:
  LeAudioClientCallbacks* callbacks;
};

} /* namespace */

LeAudioClientInterface* btif_le_audio_get_interface() {
  if (!lEAudioInstance) {
    lEAudioInstance.reset(new LeAudioClientInterfaceImpl());
  }

  return lEAudioInstance.get();
}
+1 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@
#define BT_PROFILE_AV_RC_ID "avrcp"
#define BT_PROFILE_AV_RC_CTRL_ID "avrcp_ctrl"
#define BT_PROFILE_HEARING_AID_ID "hearing_aid"
#define BT_PROFILE_LE_AUDIO_ID "le_audio"
#define BT_KEYSTORE_ID "bluetooth_keystore"
#define BT_ACTIVITY_ATTRIBUTION_ID "activity_attribution"

+94 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 HIMSA II K/S - www.himsa.com. Represented by EHIMA -
 * www.ehima.com
 *
 * 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.
 */

#pragma once

#include <array>
#include <optional>

#include "raw_address.h"

namespace bluetooth {
namespace le_audio {

enum class ConnectionState {
  DISCONNECTED = 0,
  CONNECTING,
  CONNECTED,
  DISCONNECTING
};

enum class GroupStatus {
  IDLE = 0,
  STREAMING,
  SUSPENDED,
  RECONFIGURED,
  DESTROYED,
};

class LeAudioClientCallbacks {
 public:
  virtual ~LeAudioClientCallbacks() = default;

  /** Callback for profile connection state change */
  virtual void OnConnectionState(ConnectionState state,
                                 const RawAddress& address) = 0;

  /* Callback with group status update */
  virtual void OnGroupStatus(uint8_t group_id, GroupStatus group_status,
                             uint8_t group_flags) = 0;

  /* Callback for newly recognized or reconfigured existing le audio device */
  virtual void OnAudioConf(const RawAddress& addr, uint8_t direction,
                           uint8_t group_id, uint32_t snk_audio_location,
                           uint32_t src_audio_location) = 0;

  /* Callback for available set member  */
  virtual void OnSetMemberAvailable(const RawAddress& address,
                                    uint8_t group_id) = 0;
};

class LeAudioClientInterface {
 public:
  virtual ~LeAudioClientInterface() = default;

  /* Register the LeAudio callbacks */
  virtual void Initialize(LeAudioClientCallbacks* callbacks) = 0;

  /** Connect to LEAudio */
  virtual void Connect(const RawAddress& address) = 0;

  /** Disconnect from LEAudio */
  virtual void Disconnect(const RawAddress& address) = 0;

  /* Cleanup the LeAudio */
  virtual void Cleanup(void) = 0;

  /* Request to stream audio */
  virtual void GroupStream(uint8_t group_id, uint16_t content_type) = 0;

  /* Request to suspend audio */
  virtual void GroupSuspend(uint8_t group_id) = 0;

  /* Request to stop streaming audio */
  virtual void GroupStop(uint8_t group_id) = 0;
};

static constexpr uint8_t INSTANCE_ID_UNDEFINED = 0xFF;

} /* namespace le_audio */
} /* namespace bluetooth */