1 /******************************************************************************
2  *
3  *  Copyright 2022 The Android Open Source Project
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 
19 #pragma once
20 
21 #include <bluetooth/uuid.h>
22 #include <hardware/bluetooth.h>
23 
24 #include <vector>
25 
26 #include "types/ble_address_with_type.h"
27 #include "types/raw_address.h"
28 
29 /*******************************************************************************
30  *  Functions
31  ******************************************************************************/
32 
33 /*******************************************************************************
34  *
35  * Function         btif_storage_add_hid_device_info
36  *
37  * Description      BTIF storage API - Adds the hid information of bonded hid
38  *                  devices-to NVRAM
39  *
40  * Returns          BT_STATUS_SUCCESS if the store was successful,
41  *                  BT_STATUS_FAIL otherwise
42  *
43  ******************************************************************************/
44 
45 bt_status_t btif_storage_add_hid_device_info(
46     const tAclLinkSpec& link_spec, uint16_t attr_mask, uint8_t sub_class,
47     uint8_t app_id, uint16_t vendor_id, uint16_t product_id, uint16_t version,
48     uint8_t ctry_code, uint16_t ssr_max_latency, uint16_t ssr_min_tout,
49     uint16_t dl_len, uint8_t* dsc_list);
50 
51 /*******************************************************************************
52  *
53  * Function         btif_storage_load_bonded_hid_info
54  *
55  * Description      BTIF storage API - Loads hid info for all the bonded devices
56  *                  from NVRAM and adds those devices  to the BTA_HH.
57  *
58  * Returns          BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise
59  *
60  ******************************************************************************/
61 bt_status_t btif_storage_load_bonded_hid_info(void);
62 
63 /*******************************************************************************
64  *
65  * Function         btif_storage_remove_hid_info
66  *
67  * Description      BTIF storage API - Deletes the bonded hid device info from
68  *                  NVRAM
69  *
70  * Returns          BT_STATUS_SUCCESS if the deletion was successful,
71  *                  BT_STATUS_FAIL otherwise
72  *
73  ******************************************************************************/
74 bt_status_t btif_storage_remove_hid_info(const tAclLinkSpec& link_spec);
75 
76 /** Returns all bonded LE hid devices + their address types. */
77 std::vector<std::pair<RawAddress, uint8_t>> btif_storage_get_le_hid_devices(
78     void);
79 
80 /** Returns all bonded Classic HID devices capable of waking the system from
81  * system suspend (i.e. Keyboards and Pointing devices).
82  */
83 std::vector<RawAddress> btif_storage_get_wake_capable_classic_hid_devices(void);
84 
85 /** Loads information about bonded hearing aid devices */
86 void btif_storage_load_bonded_hearing_aids();
87 
88 /** Deletes the bonded hearing aid device info from NVRAM */
89 void btif_storage_remove_hearing_aid(const RawAddress& address);
90 
91 /** Set/Unset the hearing aid device HEARING_AID_IS_ACCEPTLISTED flag. */
92 void btif_storage_set_hearing_aid_acceptlist(const RawAddress& address,
93                                              bool add_to_acceptlist);
94 
95 /** Get the hearing aid device properties. */
96 bool btif_storage_get_hearing_aid_prop(
97     const RawAddress& address, uint8_t* capabilities, uint64_t* hi_sync_id,
98     uint16_t* render_delay, uint16_t* preparation_delay, uint16_t* codecs);
99 
100 /** Store Le Audio device autoconnect flag */
101 void btif_storage_set_leaudio_autoconnect(const RawAddress& addr,
102                                           bool autoconnect);
103 
104 /** Store PACs information */
105 void btif_storage_leaudio_update_pacs_bin(const RawAddress& addr);
106 
107 /** Store ASEs information */
108 void btif_storage_leaudio_update_ase_bin(const RawAddress& addr);
109 
110 /** Store Handles information */
111 void btif_storage_leaudio_update_handles_bin(const RawAddress& addr);
112 
113 /** Store Le Audio device audio locations */
114 void btif_storage_set_leaudio_audio_location(const RawAddress& addr,
115                                              uint32_t sink_location,
116                                              uint32_t source_location);
117 
118 /** Store Le Audio device context types */
119 void btif_storage_set_leaudio_supported_context_types(
120     const RawAddress& addr, uint16_t sink_supported_context_type,
121     uint16_t source_supported_context_type);
122 
123 /** Remove Le Audio device service data */
124 void btif_storage_leaudio_clear_service_data(const RawAddress& address);
125 
126 /** Remove Le Audio device from the storage */
127 void btif_storage_remove_leaudio(const RawAddress& address);
128 
129 /** Load bonded Le Audio devices */
130 void btif_storage_load_bonded_leaudio(void);
131 
132 /** Loads information about bonded HAS devices */
133 void btif_storage_load_bonded_leaudio_has_devices(void);
134 
135 /** Deletes the bonded HAS device info from NVRAM */
136 void btif_storage_remove_leaudio_has(const RawAddress& address);
137 
138 /** Set/Unset the HAS device acceptlist flag. */
139 void btif_storage_set_leaudio_has_acceptlist(const RawAddress& address,
140                                              bool add_to_acceptlist);
141 
142 void btif_storage_add_groups(const RawAddress& addr);
143 void btif_storage_load_bonded_groups(void);
144 void btif_storage_remove_groups(const RawAddress& address);
145 
146 void btif_storage_set_csis_autoconnect(const RawAddress& addr,
147                                        bool autoconnect);
148 void btif_storage_update_csis_info(const RawAddress& addr);
149 void btif_storage_load_bonded_csis_devices();
150 void btif_storage_remove_csis_device(const RawAddress& address);
151 
152 void btif_storage_load_bonded_volume_control_devices(void);
153 /*******************************************************************************
154  * Function         btif_storage_load_hidd
155  *
156  * Description      Loads hidd bonded device and "plugs" it into hidd
157  *
158  * Returns          BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise
159  *
160  ******************************************************************************/
161 bt_status_t btif_storage_load_hidd(void);
162 
163 /*******************************************************************************
164  *
165  * Function         btif_storage_set_hidd
166  *
167  * Description      Stores hidd bonded device info in nvram.
168  *
169  * Returns          BT_STATUS_SUCCESS
170  *
171  ******************************************************************************/
172 
173 bt_status_t btif_storage_set_hidd(const RawAddress& remote_bd_addr);
174 
175 /*******************************************************************************
176  *
177  * Function         btif_storage_remove_hidd
178  *
179  * Description      Removes hidd bonded device info from nvram
180  *
181  * Returns          BT_STATUS_SUCCESS
182  *
183  ******************************************************************************/
184 
185 bt_status_t btif_storage_remove_hidd(RawAddress* remote_bd_addr);
186 
187 /*******************************************************************************
188  *
189  *Function : btif_storage_set_pce_profile_version
190  *
191  * Description :
192  *    This function store remote PCE profile version in config file
193  *
194  ******************************************************************************/
195 
196 void btif_storage_set_pce_profile_version(const RawAddress& remote_bd_addr,
197                                           uint16_t peer_pce_version);
198 
199 /*******************************************************************************
200  *
201  * Function        btif_storage_is_pce_version_102
202  *
203  * Description     checks if remote supports PBAP 1.2
204  *
205  * Returns         true/false depending on remote PBAP version support found in
206  *file.
207  *
208  ******************************************************************************/
209 
210 bool btif_storage_is_pce_version_102(const RawAddress& remote_bd_addr);
211