1 /*
2  * Copyright 2019 HIMSA II K/S - www.himsa.com. Represented by EHIMA -
3  * www.ehima.com
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <hardware/bluetooth.h>
19 #include <vector>
20 
21 #include "btif_common.h"
22 #include "btif_storage.h"
23 #include "hardware/bt_le_audio.h"
24 #include "stack/include/btu.h"
25 
26 #include <hardware/bt_le_audio.h>
27 
28 using base::Bind;
29 using base::Unretained;
30 using bluetooth::le_audio::ConnectionState;
31 
32 using bluetooth::le_audio::GroupStatus;
33 using bluetooth::le_audio::LeAudioClientCallbacks;
34 using bluetooth::le_audio::LeAudioClientInterface;
35 
36 namespace {
37 class LeAudioClientInterfaceImpl;
38 std::unique_ptr<LeAudioClientInterface> lEAudioInstance;
39 
40 class LeAudioClientInterfaceImpl : public LeAudioClientInterface,
41                                    public LeAudioClientCallbacks {
42   ~LeAudioClientInterfaceImpl() = default;
43 
OnConnectionState(ConnectionState state,const RawAddress & address)44   void OnConnectionState(ConnectionState state,
45                          const RawAddress& address) override {
46     do_in_jni_thread(FROM_HERE, Bind(&LeAudioClientCallbacks::OnConnectionState,
47                                      Unretained(callbacks), state, address));
48   }
49 
OnGroupStatus(uint8_t group_id,GroupStatus group_status,uint8_t group_flags)50   void OnGroupStatus(uint8_t group_id, GroupStatus group_status,
51                      uint8_t group_flags) override {
52     do_in_jni_thread(FROM_HERE, Bind(&LeAudioClientCallbacks::OnGroupStatus,
53                                      Unretained(callbacks), group_id,
54                                      group_status, group_flags));
55   }
56 
OnSetMemberAvailable(const RawAddress & address,uint8_t group_id)57   void OnSetMemberAvailable(const RawAddress& address,
58                             uint8_t group_id) override {
59     do_in_jni_thread(FROM_HERE,
60                      Bind(&LeAudioClientCallbacks::OnSetMemberAvailable,
61                           Unretained(callbacks), address, group_id));
62   }
63 
OnAudioConf(const RawAddress & addr,uint8_t direction,uint8_t group_id,uint32_t snk_audio_location,uint32_t src_audio_location)64   void OnAudioConf(const RawAddress& addr, uint8_t direction, uint8_t group_id,
65                    uint32_t snk_audio_location,
66                    uint32_t src_audio_location) override {
67     do_in_jni_thread(
68         FROM_HERE,
69         Bind(&LeAudioClientCallbacks::OnAudioConf, Unretained(callbacks), addr,
70              direction, group_id, snk_audio_location, src_audio_location));
71   }
72 
Initialize(LeAudioClientCallbacks * callbacks)73   void Initialize(LeAudioClientCallbacks* callbacks) override {
74     this->callbacks = callbacks;
75   }
76 
Cleanup(void)77   void Cleanup(void) override {}
78 
Connect(const RawAddress & address)79   void Connect(const RawAddress& address) override {}
80 
Disconnect(const RawAddress & address)81   void Disconnect(const RawAddress& address) override {}
82 
GroupStream(const uint8_t group_id,const uint16_t content_type)83   void GroupStream(const uint8_t group_id,
84                    const uint16_t content_type) override {}
85 
GroupSuspend(const uint8_t group_id)86   void GroupSuspend(const uint8_t group_id) override {}
87 
GroupStop(const uint8_t group_id)88   void GroupStop(const uint8_t group_id) override {}
89 
90  private:
91   LeAudioClientCallbacks* callbacks;
92 };
93 
94 } /* namespace */
95 
btif_le_audio_get_interface()96 LeAudioClientInterface* btif_le_audio_get_interface() {
97   if (!lEAudioInstance) {
98     lEAudioInstance.reset(new LeAudioClientInterfaceImpl());
99   }
100 
101   return lEAudioInstance.get();
102 }
103