1 /* 2 * Copyright (c) 2025 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 #include "bluetooth_state_adapter.h" 17 18 #include "mc_connect_manager.h" 19 #include "mechbody_controller_log.h" 20 21 namespace OHOS { 22 namespace MechBodyController { 23 namespace { 24 const std::string TAG = "BluetoothStateAdapter"; 25 } 26 GetInstance()27BluetoothStateAdapter& BluetoothStateAdapter::GetInstance() 28 { 29 static auto instance = new BluetoothStateAdapter(); 30 return *instance; 31 } 32 IsBluetoothActive()33bool BluetoothStateAdapter::IsBluetoothActive() 34 { 35 HILOGI("current BT state cache is: %{public}s; BLE state cache is: %{public}s", isBTActive_ ? "true" : "false", 36 isBLEActive_ ? "true" : "false"); 37 return isBTActive_.load() || isBLEActive_.load(); 38 } 39 UpdateBTState(bool isBTActive)40void BluetoothStateAdapter::UpdateBTState(bool isBTActive) 41 { 42 HILOGI("update BT state: %{public}s", isBTActive ? "true" : "false"); 43 isBTActive_.store(isBTActive); 44 MechConnectManager::GetInstance().UpdateBleStatus(isBTActive_.load() || isBLEActive_.load()); 45 } 46 UpdateBLEState(bool isBLEActive)47void BluetoothStateAdapter::UpdateBLEState(bool isBLEActive) 48 { 49 HILOGI("update BLE state: %{public}s", isBLEActive ? "true" : "false"); 50 isBLEActive_.store(isBLEActive); 51 MechConnectManager::GetInstance().UpdateBleStatus(isBLEActive_.load()); 52 } 53 } // namespace MechBodyController 54 } // namespace OHOS 55