1 /*
2  * Copyright 2021 HIMSA II K/S - www.himsa.com.
3  * Represented by EHIMA - 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 #pragma once
18 
19 #include <gmock/gmock.h>
20 
21 #include "include/hardware/bluetooth.h"
22 #include "types/raw_address.h"
23 
24 namespace bluetooth {
25 namespace storage {
26 
27 class BtifStorageInterface {
28 public:
29   virtual void AddLeaudioAutoconnect(RawAddress const& addr, bool autoconnect) = 0;
30   virtual void LeAudioUpdatePacs(RawAddress const& addr) = 0;
31   virtual void LeAudioUpdateAses(RawAddress const& addr) = 0;
32   virtual void LeAudioUpdateHandles(RawAddress const& addr) = 0;
33   virtual void SetLeAudioLocations(RawAddress const& addr, uint32_t sink_location,
34                                    uint32_t source_location) = 0;
35   virtual void SetLeAudioContexts(RawAddress const& addr, uint16_t sink_context,
36                                   uint16_t source_context) = 0;
37   virtual void ClearLeAudioServiceData(RawAddress const& addr) = 0;
38   virtual void RemoveLeaudio(RawAddress const& addr) = 0;
39   virtual void AddLeaudioHasDevice(const RawAddress& address, std::vector<uint8_t> presets_bin,
40                                    uint8_t features, uint8_t active_preset) = 0;
41   virtual void SetLeaudioHasPresets(const RawAddress& address,
42                                     std::vector<uint8_t> presets_bin) = 0;
43   virtual bool GetLeaudioHasFeatures(const RawAddress& address, uint8_t& features) = 0;
44   virtual void SetLeaudioHasFeatures(const RawAddress& address, uint8_t features) = 0;
45   virtual void SetLeaudioHasActivePreset(const RawAddress& address, uint8_t active_preset) = 0;
46   virtual bool GetLeaudioHasPresets(const RawAddress& address, std::vector<uint8_t>& presets_bin,
47                                     uint8_t& active_preset) = 0;
48   virtual void RemoveLeaudioHas(const RawAddress& address) = 0;
49   virtual bt_status_t GetRemoteDeviceProperty(const RawAddress* address,
50                                               bt_property_t* property) = 0;
51 
52   virtual ~BtifStorageInterface() = default;
53 };
54 
55 class MockBtifStorageInterface : public BtifStorageInterface {
56 public:
57   MOCK_METHOD((void), AddLeaudioAutoconnect, (RawAddress const& addr, bool autoconnect),
58               (override));
59   MOCK_METHOD((void), LeAudioUpdatePacs, (RawAddress const& addr), (override));
60   MOCK_METHOD((void), LeAudioUpdateAses, (RawAddress const& addr), (override));
61   MOCK_METHOD((void), LeAudioUpdateHandles, (RawAddress const& addr), (override));
62   MOCK_METHOD((void), SetLeAudioLocations,
63               (RawAddress const& addr, uint32_t sink_location, uint32_t source_location),
64               (override));
65   MOCK_METHOD((void), SetLeAudioContexts,
66               (RawAddress const& addr, uint16_t sink_context, uint16_t source_context), (override));
67   MOCK_METHOD((void), ClearLeAudioServiceData, (RawAddress const& addr), (override));
68   MOCK_METHOD((void), RemoveLeaudio, (RawAddress const& addr), (override));
69   MOCK_METHOD((void), AddLeaudioHasDevice,
70               (const RawAddress& address, std::vector<uint8_t> presets_bin, uint8_t features,
71                uint8_t active_preset),
72               (override));
73   MOCK_METHOD((bool), GetLeaudioHasPresets,
74               (const RawAddress& address, std::vector<uint8_t>& presets_bin,
75                uint8_t& active_preset),
76               (override));
77   MOCK_METHOD((void), SetLeaudioHasPresets,
78               (const RawAddress& address, std::vector<uint8_t> presets_bin), (override));
79   MOCK_METHOD((bool), GetLeaudioHasFeatures, (const RawAddress& address, uint8_t& features),
80               (override));
81   MOCK_METHOD((void), SetLeaudioHasFeatures, (const RawAddress& address, uint8_t features),
82               (override));
83   MOCK_METHOD((void), SetLeaudioHasActivePreset, (const RawAddress& address, uint8_t active_preset),
84               (override));
85   MOCK_METHOD((void), RemoveLeaudioHas, (const RawAddress& address), (override));
86   MOCK_METHOD((bt_status_t), GetRemoteDeviceProperty,
87               (const RawAddress* address, bt_property_t* property), (override));
88 };
89 
90 /**
91  * Set the {@link MockBifStorageInterface} for testing
92  *
93  * @param mock_btif_storage_interface pointer to mock btm security
94  * internal interface, could be null
95  */
96 void SetMockBtifStorageInterface(MockBtifStorageInterface* mock_btif_storage_interface);
97 
98 }  // namespace storage
99 }  // namespace bluetooth
100