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/le_device.h"
18 
19 namespace bluetooth {
20 namespace storage {
21 
22 namespace {
23 const std::string kLeIdentityAddressKey = "LeIdentityAddr";
24 // TODO(siyuanh): check if we still need these keys in GD
25 // const std::string kLePencKey = "LE_KEY_PENC";
26 // const std::string kLePidKey = "LE_KEY_PENC";
27 // const std::string kLePsrkKey = "LE_KEY_PENC";
28 // const std::string kLeLencKey = "LE_KEY_PENC";
29 // const std::string kLeLcsrkKey = "LE_KEY_PENC";
30 // const std::string kLeLidKey = "LE_KEY_PENC";
31 }  // namespace
32 
33 const std::unordered_set<std::string_view> LeDevice::kLinkKeyProperties = {
34     "LE_KEY_PENC", "LE_KEY_PID", "LE_KEY_PCSRK", "LE_KEY_LENC", "LE_KEY_LCSRK"};
35 
LeDevice(ConfigCache * config,ConfigCache * memory_only_config,std::string section)36 LeDevice::LeDevice(ConfigCache* config, ConfigCache* memory_only_config, std::string section)
37     : config_(config), memory_only_config_(memory_only_config), section_(std::move(section)) {}
38 
Parent()39 Device LeDevice::Parent() {
40   return Device(config_, memory_only_config_, section_);
41 }
42 
ToLogString() const43 std::string LeDevice::ToLogString() const {
44   return section_;
45 }
46 
IsPaired() const47 bool LeDevice::IsPaired() const {
48   // This first check is here only to speed up the checking process
49   if (!config_->IsPersistentSection(section_)) {
50     return false;
51   }
52   return config_->HasAtLeastOneMatchingPropertiesInSection(section_, kLinkKeyProperties);
53 }
54 
55 }  // namespace storage
56 }  // namespace bluetooth