1 /****************************************************************************** 2 * 3 * Copyright (C) 2014 Google, Inc. 4 * Copyright (C) 2018 The Linux Foundation 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at: 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 ******************************************************************************/ 19 20 #pragma once 21 22 #include "osi/include/config.h" 23 #include "osi/include/osi.h" 24 25 #define PROPERTY_ENABLE_LOGGING \ 26 "persist.bluetooth.device_iot_config.enablelogging" 27 #define PROPERTY_FACTORY_RESET "persist.bluetooth.factoryreset" 28 29 #define INFO_SECTION "Info" 30 #define VERSION_KEY "Version" 31 #define FILE_CREATED_TIMESTAMP "TimeCreated" 32 #define FILE_MODIFIED_TIMESTAMP "TimeModified" 33 #define TIME_STRING_LENGTH sizeof("YYYY-MM-DD HH:MM:SS") 34 static const char* TIME_STRING_FORMAT = "%Y-%m-%d %H:%M:%S"; 35 36 #ifndef DEVICES_MAX_NUM_IN_IOT_INFO_FILE 37 #define DEVICES_MAX_NUM_IN_IOT_INFO_FILE 40 38 #endif 39 #define DEVICES_NUM_MARGIN 5 40 41 #if (DEVICES_MAX_NUM_IN_IOT_INFO_FILE < DEVICES_NUM_MARGIN) 42 #undef DEVICES_MAX_NUM_IN_IOT_INFO_FILE 43 #define DEVICES_MAX_NUM_IN_IOT_INFO_FILE DEVICES_NUM_MARGIN 44 #endif 45 46 #define DEVICE_IOT_INFO_CURRENT_VERSION 1 47 #define DEVICE_IOT_INFO_FIRST_VERSION 1 48 49 #define IOT_CONFIG_FLUSH_EVT 0 50 #define IOT_CONFIG_SAVE_TIMER_FIRED_EVT 1 51 52 #ifdef __ANDROID__ 53 static const char* IOT_CONFIG_FILE_PATH = 54 "/data/misc/bluedroid/bt_remote_dev_info.conf"; 55 static const char* IOT_CONFIG_BACKUP_PATH = 56 "/data/misc/bluedroid/bt_remote_dev_info.bak"; 57 #else // !__ANDROID__ 58 static const char* IOT_CONFIG_FILE_PATH = "bt_remote_dev_info.conf"; 59 static const char* IOT_CONFIG_BACKUP_PATH = "bt_remote_dev_info.bak"; 60 #endif // __ANDROID__ 61 static const uint64_t CONFIG_SETTLE_PERIOD_MS = 12000; 62 63 enum ConfigSource { NOT_LOADED, ORIGINAL, BACKUP, NEW_FILE, RESET }; 64 65 #define CHECK_LOGGING_ENABLED(return_value) \ 66 do { \ 67 if (!bluetooth::common::InitFlags::IsDeviceIotConfigLoggingEnabled()) \ 68 return (return_value); \ 69 } while (0) 70 71 struct config_t; 72 struct future_t; 73 74 typedef bool (*compare_func)(const entry_t& first, const entry_t& second); 75 76 // config_lock is used by the callee in the following methods 77 future_t* device_iot_config_module_init(void); 78 future_t* device_iot_config_module_start_up(void); 79 future_t* device_iot_config_module_shut_down(void); 80 future_t* device_iot_config_module_clean_up(void); 81 void device_iot_config_write(uint16_t event, char* p_param); 82 83 // config_lock is used by the caller of the following methods 84 void device_iot_config_sections_sort_by_entry_key(config_t& config, 85 compare_func comp); 86 bool device_iot_config_has_key_value(const std::string& section, 87 const std::string& key, 88 const std::string& value_str); 89 void device_iot_config_save_async(void); 90 int device_iot_config_get_device_num(const config_t& config); 91 void device_iot_config_restrict_device_num(config_t& config); 92 bool device_iot_config_compare_key(const entry_t& first, const entry_t& second); 93 void device_iot_config_timer_save_cb(UNUSED_ATTR void* data); 94 void device_iot_config_set_modified_time(); 95 bool device_iot_config_is_factory_reset(void); 96 void device_iot_config_delete_files(void); 97