• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef AUDIO_BLUETOOTH_MANAGERI_H
17 #define AUDIO_BLUETOOTH_MANAGERI_H
18 
19 #include "bluetooth_a2dp_src.h"
20 #include "bluetooth_a2dp_codec.h"
21 #include "bluetooth_hfp_ag.h"
22 #include "idevice_status_observer.h"
23 
24 namespace OHOS {
25 namespace Bluetooth {
26 
27 int32_t RegisterDeviceObserver(AudioStandard::IDeviceStatusObserver &observer);
28 void UnregisterDeviceObserver();
29 
30 // Audio bluetooth a2dp feature support
31 class AudioA2dpListener : public A2dpSourceObserver {
32 public:
33     AudioA2dpListener() = default;
34     virtual ~AudioA2dpListener() = default;
35 
36     virtual void OnConnectionStateChanged(const BluetoothRemoteDevice &device, int state);
37     virtual void OnConfigurationChanged(const BluetoothRemoteDevice &device, const A2dpCodecInfo &info, int error);
38     virtual void OnPlayingStatusChanged(const BluetoothRemoteDevice &device, int playingState, int error);
39 
40 private:
41     BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(AudioA2dpListener);
42 };
43 
44 class AudioA2dpManager {
45 public:
46     AudioA2dpManager() = default;
47     virtual ~AudioA2dpManager() = default;
48     static void RegisterBluetoothA2dpListener();
49     static void UnregisterBluetoothA2dpListener();
50     static void ConnectBluetoothA2dpSink();
51     static void DisconnectBluetoothA2dpSink();
SetConnectionState(int state)52     static void SetConnectionState(int state)
53     {
54         connectionState_ = state;
55     }
GetConnectionState()56     static int GetConnectionState()
57     {
58         return connectionState_;
59     }
SetBluetoothSinkLoaded(bool isLoaded)60     static void SetBluetoothSinkLoaded(bool isLoaded)
61     {
62         bluetoothSinkLoaded_ = isLoaded;
63     }
GetBluetoothSinkLoaded()64     static bool GetBluetoothSinkLoaded()
65     {
66         return bluetoothSinkLoaded_;
67     }
SetBluetoothRemoteDevice(BluetoothRemoteDevice device)68     static void SetBluetoothRemoteDevice(BluetoothRemoteDevice device)
69     {
70         bluetoothRemoteDevice_ = device;
71     }
GetBluetoothRemoteDevice()72     static BluetoothRemoteDevice GetBluetoothRemoteDevice()
73     {
74         return bluetoothRemoteDevice_;
75     }
76 
77 private:
78     static A2dpSource *a2dpInstance_;
79     static AudioA2dpListener a2dpListener_;
80     static int connectionState_;
81     static bool bluetoothSinkLoaded_;
82     static BluetoothRemoteDevice bluetoothRemoteDevice_;
83 };
84 
85 // Audio bluetooth sco feature support
86 class AudioHfpListener : public HandsFreeAudioGatewayObserver {
87 public:
88     AudioHfpListener() = default;
89     virtual ~AudioHfpListener() = default;
90 
91     void OnScoStateChanged(const BluetoothRemoteDevice &device, int state);
OnConnectionStateChanged(const BluetoothRemoteDevice & device,int state)92     void OnConnectionStateChanged(const BluetoothRemoteDevice &device, int state) {}
OnActiveDeviceChanged(const BluetoothRemoteDevice & device)93     void OnActiveDeviceChanged(const BluetoothRemoteDevice &device) {}
OnHfEnhancedDriverSafetyChanged(const BluetoothRemoteDevice & device,int indValue)94     void OnHfEnhancedDriverSafetyChanged(const BluetoothRemoteDevice &device, int indValue) {}
95 
96 private:
97     BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(AudioHfpListener);
98 };
99 
100 class AudioHfpManager {
101 public:
102     AudioHfpManager() = default;
103     virtual ~AudioHfpManager() = default;
104     static void RegisterBluetoothScoListener();
105     static void UnregisterBluetoothScoListener();
106 
107 private:
108     static HandsFreeAudioGateway *hfpInstance_;
109     static AudioHfpListener hfpListener_;
110 };
111 }
112 }
113 #endif  // AUDIO_BLUETOOTH_MANAGERI_H
114