• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_listener.h"
17 
18 #include "bluetooth_state_adapter.h"
19 #include "mechbody_controller_log.h"
20 
21 namespace OHOS {
22 namespace MechBodyController {
23 namespace {
24     const std::string TAG = "BluetoothStateListener";
25 }
26 
InitBluetoothState()27 void BluetoothStateListener::InitBluetoothState()
28 {
29     Bluetooth::BluetoothState bluetoothState = Bluetooth::BluetoothHost::GetDefaultHost().GetBluetoothState();
30     HILOGI("query bluetooth state is: %{public}d", static_cast<int>(bluetoothState));
31     if (bluetoothState == Bluetooth::BluetoothState::STATE_ON) {
32         BluetoothStateAdapter::GetInstance().UpdateBTState(true);
33         BluetoothStateAdapter::GetInstance().UpdateBLEState(true);
34     } else if (bluetoothState == Bluetooth::BluetoothState::STATE_BLE_ON) {
35         BluetoothStateAdapter::GetInstance().UpdateBTState(false);
36         BluetoothStateAdapter::GetInstance().UpdateBLEState(true);
37     }
38 }
39 
OnStateChanged(const int transport,const int status)40 void BluetoothStateListener::OnStateChanged(const int transport, const int status)
41 {
42     HILOGI("Bluetooth state changed, transport: %{public}d, state: %{public}d", transport, status);
43     if (transport == static_cast<int>(Bluetooth::BTTransport::ADAPTER_BREDR)) {
44         BluetoothStateAdapter::GetInstance().UpdateBTState(status == Bluetooth::BTStateID::STATE_TURN_ON);
45     }
46 
47     if (transport == static_cast<int>(Bluetooth::BTTransport::ADAPTER_BLE)) {
48         BluetoothStateAdapter::GetInstance().UpdateBLEState(status == Bluetooth::BTStateID::STATE_TURN_ON);
49     }
50 }
51 
52 } // namespace MechBodyController
53 } // namespace OHOS
54