1 /* 2 * Copyright 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "os/parameter_provider.h" 18 19 #include <private/android_filesystem_config.h> 20 #include <unistd.h> 21 22 #include <mutex> 23 #include <string> 24 25 namespace bluetooth { 26 namespace os { 27 28 namespace { 29 std::mutex parameter_mutex; 30 std::string config_file_path; 31 std::string snoop_log_file_path; 32 std::string snooz_log_file_path; 33 bluetooth_keystore::BluetoothKeystoreInterface* bt_keystore_interface = nullptr; 34 bool is_common_criteria_mode = false; 35 int common_criteria_config_compare_result = 0b11; 36 } // namespace 37 38 // On Android we always write a single default location ConfigFilePath()39std::string ParameterProvider::ConfigFilePath() { 40 { 41 std::lock_guard<std::mutex> lock(parameter_mutex); 42 if (!config_file_path.empty()) { 43 return config_file_path; 44 } 45 } 46 return "/data/misc/bluedroid/bt_config.conf"; 47 } 48 OverrideConfigFilePath(const std::string & path)49void ParameterProvider::OverrideConfigFilePath(const std::string& path) { 50 std::lock_guard<std::mutex> lock(parameter_mutex); 51 config_file_path = path; 52 } 53 SnoopLogFilePath()54std::string ParameterProvider::SnoopLogFilePath() { 55 { 56 std::lock_guard<std::mutex> lock(parameter_mutex); 57 if (!snoop_log_file_path.empty()) { 58 return snoop_log_file_path; 59 } 60 } 61 return "/data/misc/bluetooth/logs/btsnoop_hci.log"; 62 } 63 OverrideSnoopLogFilePath(const std::string & path)64void ParameterProvider::OverrideSnoopLogFilePath(const std::string& path) { 65 std::lock_guard<std::mutex> lock(parameter_mutex); 66 snoop_log_file_path = path; 67 } 68 69 // Return the path to the default snooz log file location SnoozLogFilePath()70std::string ParameterProvider::SnoozLogFilePath() { 71 { 72 std::lock_guard<std::mutex> lock(parameter_mutex); 73 if (!snooz_log_file_path.empty()) { 74 return snooz_log_file_path; 75 } 76 } 77 return "/data/misc/bluetooth/logs/btsnooz_hci.log"; 78 } 79 OverrideSnoozLogFilePath(const std::string & path)80void ParameterProvider::OverrideSnoozLogFilePath(const std::string& path) { 81 std::lock_guard<std::mutex> lock(parameter_mutex); 82 snooz_log_file_path = path; 83 } 84 85 // Android doesn't have a need for the sysprops module SyspropsFilePath()86std::string ParameterProvider::SyspropsFilePath() { 87 return ""; 88 } 89 GetBtKeystoreInterface()90bluetooth_keystore::BluetoothKeystoreInterface* ParameterProvider::GetBtKeystoreInterface() { 91 std::lock_guard<std::mutex> lock(parameter_mutex); 92 return bt_keystore_interface; 93 } 94 SetBtKeystoreInterface(bluetooth_keystore::BluetoothKeystoreInterface * bt_keystore)95void ParameterProvider::SetBtKeystoreInterface(bluetooth_keystore::BluetoothKeystoreInterface* bt_keystore) { 96 std::lock_guard<std::mutex> lock(parameter_mutex); 97 bt_keystore_interface = bt_keystore; 98 } 99 IsCommonCriteriaMode()100bool ParameterProvider::IsCommonCriteriaMode() { 101 std::lock_guard<std::mutex> lock(parameter_mutex); 102 return (getuid() == AID_BLUETOOTH) && is_common_criteria_mode; 103 } 104 SetCommonCriteriaMode(bool enable)105void ParameterProvider::SetCommonCriteriaMode(bool enable) { 106 std::lock_guard<std::mutex> lock(parameter_mutex); 107 is_common_criteria_mode = enable; 108 } 109 GetCommonCriteriaConfigCompareResult()110int ParameterProvider::GetCommonCriteriaConfigCompareResult() { 111 std::lock_guard<std::mutex> lock(parameter_mutex); 112 return common_criteria_config_compare_result; 113 } 114 SetCommonCriteriaConfigCompareResult(int result)115void ParameterProvider::SetCommonCriteriaConfigCompareResult(int result) { 116 std::lock_guard<std::mutex> lock(parameter_mutex); 117 common_criteria_config_compare_result = result; 118 } 119 120 } // namespace os 121 } // namespace bluetooth