195489c19Sopenharmony_ci/* 295489c19Sopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd. 395489c19Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 495489c19Sopenharmony_ci * you may not use this file except in compliance with the License. 595489c19Sopenharmony_ci * You may obtain a copy of the License at 695489c19Sopenharmony_ci * 795489c19Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 895489c19Sopenharmony_ci * 995489c19Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1095489c19Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1195489c19Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1295489c19Sopenharmony_ci * See the License for the specific language governing permissions and 1395489c19Sopenharmony_ci * limitations under the License. 1495489c19Sopenharmony_ci */ 1595489c19Sopenharmony_ci 1695489c19Sopenharmony_ci#include "oh_bluetooth.h" 1795489c19Sopenharmony_ci 1895489c19Sopenharmony_ci#include "bluetooth_log.h" 1995489c19Sopenharmony_ci#include "bluetooth_host.h" 2095489c19Sopenharmony_ci 2195489c19Sopenharmony_ci#ifdef __cplusplus 2295489c19Sopenharmony_ciextern "C" { 2395489c19Sopenharmony_ci#endif 2495489c19Sopenharmony_ci 2595489c19Sopenharmony_cinamespace OHOS { 2695489c19Sopenharmony_cinamespace Bluetooth { 2795489c19Sopenharmony_ci 2895489c19Sopenharmony_ciBluetooth_ResultCode OH_Bluetooth_GetBluetoothSwitchState(Bluetooth_SwitchState *state) 2995489c19Sopenharmony_ci{ 3095489c19Sopenharmony_ci if (!state) { 3195489c19Sopenharmony_ci HILOGE("invalid param"); 3295489c19Sopenharmony_ci return Bluetooth_ResultCode::BLUETOOTH_INVALID_PARAM; 3395489c19Sopenharmony_ci } 3495489c19Sopenharmony_ci BluetoothHost *host = &BluetoothHost::GetDefaultHost(); 3595489c19Sopenharmony_ci int32_t btState = BTStateID::STATE_TURN_OFF; 3695489c19Sopenharmony_ci host->GetBtState(btState); 3795489c19Sopenharmony_ci 3895489c19Sopenharmony_ci Bluetooth_SwitchState status = Bluetooth_SwitchState::BLUETOOTH_STATE_OFF; 3995489c19Sopenharmony_ci switch (btState) { 4095489c19Sopenharmony_ci case BTStateID::STATE_TURNING_ON: 4195489c19Sopenharmony_ci status = Bluetooth_SwitchState::BLUETOOTH_STATE_TURNING_ON; 4295489c19Sopenharmony_ci break; 4395489c19Sopenharmony_ci case BTStateID::STATE_TURN_ON: 4495489c19Sopenharmony_ci status = Bluetooth_SwitchState::BLUETOOTH_STATE_ON; 4595489c19Sopenharmony_ci break; 4695489c19Sopenharmony_ci case BTStateID::STATE_TURNING_OFF: 4795489c19Sopenharmony_ci status = Bluetooth_SwitchState::BLUETOOTH_STATE_TURNING_OFF; 4895489c19Sopenharmony_ci break; 4995489c19Sopenharmony_ci case BTStateID::STATE_TURN_OFF: 5095489c19Sopenharmony_ci status = Bluetooth_SwitchState::BLUETOOTH_STATE_OFF; 5195489c19Sopenharmony_ci break; 5295489c19Sopenharmony_ci default: 5395489c19Sopenharmony_ci HILOGE("get state failed"); 5495489c19Sopenharmony_ci break; 5595489c19Sopenharmony_ci } 5695489c19Sopenharmony_ci 5795489c19Sopenharmony_ci bool enableBle = host->IsBleEnabled(); 5895489c19Sopenharmony_ci if (enableBle && (btState == BTStateID::STATE_TURN_OFF)) { 5995489c19Sopenharmony_ci status = Bluetooth_SwitchState::BLUETOOTH_STATE_BLE_ON; 6095489c19Sopenharmony_ci } else if (!enableBle && (btState == BTStateID::STATE_TURN_OFF)) { 6195489c19Sopenharmony_ci status = Bluetooth_SwitchState::BLUETOOTH_STATE_OFF; 6295489c19Sopenharmony_ci } 6395489c19Sopenharmony_ci *state = status; 6495489c19Sopenharmony_ci return Bluetooth_ResultCode::BLUETOOTH_SUCCESS; 6595489c19Sopenharmony_ci} 6695489c19Sopenharmony_ci 6795489c19Sopenharmony_ci} // namespace Bluetooth 6895489c19Sopenharmony_ci} // namespace OHOS 6995489c19Sopenharmony_ci 7095489c19Sopenharmony_ci#ifdef __cplusplus 7195489c19Sopenharmony_ci} 7295489c19Sopenharmony_ci#endif 73