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,
29 std::string section)
30 : config_(config), memory_only_config_(memory_only_config), section_(std::move(section)) {}
31
Parent()32 Device ClassicDevice::Parent() { return Device(config_, memory_only_config_, section_); }
33
ToLogString() const34 std::string ClassicDevice::ToLogString() const { return section_; }
35
GetAddress() const36 hci::Address ClassicDevice::GetAddress() const {
37 // section name of a classic device is its MAC address
38 auto addr = hci::Address::FromString(section_);
39 log::assert_that(addr.has_value(), "assert failed: addr.has_value()");
40 return std::move(addr.value());
41 }
42
IsPaired() const43 bool ClassicDevice::IsPaired() const {
44 // This first check is here only to speed up the checking process
45 if (!config_->IsPersistentSection(section_)) {
46 return false;
47 }
48 return config_->HasAtLeastOneMatchingPropertiesInSection(section_, kLinkKeyProperties);
49 }
50
51 } // namespace storage
52 } // namespace bluetooth
53