1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef BLE_PROPERTIES_H 17 #define BLE_PROPERTIES_H 18 19 #include <mutex> 20 #include <string> 21 #include <vector> 22 23 #include "base_observer_list.h" 24 #include "ble_config.h" 25 #include "ble_defs.h" 26 #include "interface_adapter_ble.h" 27 28 namespace OHOS { 29 namespace bluetooth { 30 /** 31 * @BleProperties to save and get classic properties. 32 */ 33 class BleProperties { 34 public: 35 /** 36 * @brief Constructor. 37 */ 38 BleProperties(BleProperties &) = delete; 39 40 /** 41 * @brief Constructor. 42 */ 43 BleProperties &operator=(const BleProperties &) = delete; 44 45 /** 46 * @brief Get ble Properties instance. 47 * 48 * @return @c advertiser instance. 49 */ 50 static BleProperties &GetInstance(); 51 52 bool SetLocalAddress(const std::string &addr) const; 53 int GetUTF8StringLength(const char firstByte) const; 54 int GetValidUTF8StringLength(const std::string& name) const; 55 bool SetLocalName(const std::string &name) const; 56 int SetBondableMode(const int mode) const; 57 bool SetIoCapability(const int ioCapability) const; 58 59 int GetBondableMode() const; 60 int GetIoCapability() const; 61 static int GetAppearance(); 62 std::string GetLocalAddress() const; 63 std::string GetLocalName() const; 64 std::string GetPasskey() const; 65 66 bool LoadBleConfigInfo() const; 67 bool ConfigBleProperties() const; 68 static bool SetBleRoles(uint8_t roles); 69 static int GetBleRoles(); 70 71 static bool SetPasskey(const std::string &passkey); 72 static bool SetBleModel1Level(int level); 73 static bool SetBleModel2Level(int level); 74 static bool SetBleSecurity(bool security); 75 static bool SetBleScanMode(int scanmode); 76 77 bool SaveDefaultValues() const; 78 bool GetAddrFromController() const; 79 80 void RegisterBleAdapterObserver(BaseObserverList<IAdapterBleObserver> &observer) const; 81 void DeregisterBleAdapterObserver(IAdapterBleObserver &observer) const; 82 83 private: 84 enum { 85 UTF8_INVALID_BYTE_LENGTH, 86 UTF8_SINGLE_BYTE_LENGTH, 87 UTF8_DOUBLE_BYTE_LENGTH, 88 UTF8_TRIPLE_BYTE_LENGTH, 89 UTF8_QUADRUPLE_BYTE_LENGTH 90 }; 91 92 BleProperties(); 93 ~BleProperties(); 94 95 void ReadBleHostInfo() const; 96 bool UpdateConfig(int type) const; 97 DECLARE_IMPL(); 98 }; 99 } // namespace bluetooth 100 } // namespace OHOS 101 102 #endif // BLE_PROPERTIES_H 103