1 /*
2  * Copyright 2020 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 "storage/classic_device.h"
18 
19 #include <algorithm>
20 
21 #include "common/strings.h"
22 
23 namespace bluetooth {
24 namespace storage {
25 
26 const std::unordered_set<std::string_view> ClassicDevice::kLinkKeyProperties = {"LinkKey"};
27 
ClassicDevice(ConfigCache * config,ConfigCache * memory_only_config,std::string section)28 ClassicDevice::ClassicDevice(ConfigCache* config, ConfigCache* memory_only_config, std::string section)
29     : config_(config), memory_only_config_(memory_only_config), section_(std::move(section)) {}
30 
Parent()31 Device ClassicDevice::Parent() {
32   return Device(config_, memory_only_config_, section_);
33 }
34 
ToLogString() const35 std::string ClassicDevice::ToLogString() const {
36   return section_;
37 }
38 
GetAddress() const39 hci::Address ClassicDevice::GetAddress() const {
40   // section name of a classic device is its MAC address
41   auto addr = hci::Address::FromString(section_);
42   ASSERT(addr.has_value());
43   return std::move(addr.value());
44 }
45 
IsPaired() const46 bool ClassicDevice::IsPaired() const {
47   // This first check is here only to speed up the checking process
48   if (!config_->IsPersistentSection(section_)) {
49     return false;
50   }
51   return config_->HasAtLeastOneMatchingPropertiesInSection(section_, kLinkKeyProperties);
52 }
53 
54 }  // namespace storage
55 }  // namespace bluetooth