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/system_properties.h"
18 
19 #include <mutex>  // NOLINT
20 #include <string>
21 #include <unordered_map>
22 
23 namespace bluetooth {
24 namespace os {
25 
26 namespace {
27 std::mutex properties_mutex;
28 
29 // Properties set along with some default values for Floss.
30 std::unordered_map<std::string, std::string> properties = {
31         {"bluetooth.profile.avrcp.target.enabled", "true"},
32         {"bluetooth.gd.start_timeout", "12000"},
33         {"bluetooth.gd.stop_timeout", "12000"},
34         /* HCI Reset timeout: 10s + Default cleanup timeout: 1s = 11s */
35         {"bluetooth.cleanup_timeout", "11000"}};
36 }  // namespace
37 
GetSystemProperty(const std::string & property)38 std::optional<std::string> GetSystemProperty(const std::string& property) {
39   std::lock_guard<std::mutex> lock(properties_mutex);
40   auto iter = properties.find(property);
41   if (iter == properties.end()) {
42     return std::nullopt;
43   }
44   return iter->second;
45 }
46 
SetSystemProperty(const std::string & property,const std::string & value)47 bool SetSystemProperty(const std::string& property, const std::string& value) {
48   std::lock_guard<std::mutex> lock(properties_mutex);
49   properties.insert_or_assign(property, value);
50   return true;
51 }
52 
ClearSystemPropertiesForHost()53 bool ClearSystemPropertiesForHost() {
54   std::lock_guard<std::mutex> lock(properties_mutex);
55   properties.clear();
56   return true;
57 }
58 
IsRootCanalEnabled()59 bool IsRootCanalEnabled() { return false; }
60 
GetAndroidVendorReleaseVersion()61 int GetAndroidVendorReleaseVersion() { return 0; }
62 
63 }  // namespace os
64 }  // namespace bluetooth
65