From 9861631dc85519733ae44a8b659d6551bf3f1238 Mon Sep 17 00:00:00 2001 From: lee Date: Fri, 1 Dec 2023 15:49:47 +0800 Subject: [PATCH 1/2] add EDM prohibit bluetooth feature Signed-off-by: lee --- bundle.json | 1 + frameworks/inner/BUILD.gn | 1 + frameworks/inner/common/bluetooth_errorcode.h | 1 + frameworks/inner/common/bluetooth_log.h | 2 +- frameworks/inner/ipc/common/log.h | 2 +- .../inner/src/bluetooth_ble_advertiser.cpp | 1 - .../src/bluetooth_ble_central_manager.cpp | 1 - .../inner/src/bluetooth_gatt_client.cpp | 1 - frameworks/inner/src/bluetooth_hfp_ag.cpp | 1 - frameworks/inner/src/bluetooth_host.cpp | 337 +++++------------- frameworks/inner/src/bluetooth_pan.cpp | 1 - frameworks/inner/src/bluetooth_utils.cpp | 1 - .../src/ble/napi_bluetooth_gatt_server.cpp | 1 - .../napi/src/common/napi_bluetooth_error.cpp | 1 + .../napi/src/common/napi_bluetooth_utils.cpp | 1 - .../js/napi/src/hfp/napi_bluetooth_hfp_ag.cpp | 1 - .../napi/src/hid/napi_bluetooth_hid_host.cpp | 1 - .../js/napi/src/pan/napi_bluetooth_pan.cpp | 1 - .../inner_api/include/bluetooth_errorcode.h | 62 ---- interfaces/inner_api/include/bluetooth_host.h | 8 + 20 files changed, 107 insertions(+), 319 deletions(-) delete mode 100644 interfaces/inner_api/include/bluetooth_errorcode.h diff --git a/bundle.json b/bundle.json index b7685473..e754626e 100644 --- a/bundle.json +++ b/bundle.json @@ -60,6 +60,7 @@ "hilog", "hisysevent", "hitrace", + "init", "ipc", "libuv", "napi", diff --git a/frameworks/inner/BUILD.gn b/frameworks/inner/BUILD.gn index 52a514d1..5bbd1dfe 100644 --- a/frameworks/inner/BUILD.gn +++ b/frameworks/inner/BUILD.gn @@ -137,6 +137,7 @@ ohos_shared_library("btframework") { "c_utils:utils", "hilog:libhilog", "hisysevent:libhisysevent", + "init:libbegetutil", "ipc:ipc_core", "samgr:samgr_proxy", ] diff --git a/frameworks/inner/common/bluetooth_errorcode.h b/frameworks/inner/common/bluetooth_errorcode.h index 550da01e..1e2fd91e 100644 --- a/frameworks/inner/common/bluetooth_errorcode.h +++ b/frameworks/inner/common/bluetooth_errorcode.h @@ -24,6 +24,7 @@ enum BtErrCode { // Common error codes BT_ERR_PERMISSION_FAILED = 201, BT_ERR_SYSTEM_PERMISSION_FAILED = 202, + BT_ERR_PROHIBITED_BY_EDM = 203, BT_ERR_INVALID_PARAM = 401, BT_ERR_API_NOT_SUPPORT = 801, diff --git a/frameworks/inner/common/bluetooth_log.h b/frameworks/inner/common/bluetooth_log.h index a974c7db..68c4a2c1 100644 --- a/frameworks/inner/common/bluetooth_log.h +++ b/frameworks/inner/common/bluetooth_log.h @@ -91,7 +91,7 @@ static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = {LOG_CORE, BT_LOG_DOMAI #define CHECK_AND_RETURN_LOG_RET(cond, ret, fmt, ...) \ do { \ if (!(cond)) { \ - HILOGE(fmt " ret(%{public}s)", ##__VA_ARGS__, #ret); \ + HILOGE(fmt, ##__VA_ARGS__); \ return ret; \ } \ } while (0) diff --git a/frameworks/inner/ipc/common/log.h b/frameworks/inner/ipc/common/log.h index cb43df78..c2d4167a 100644 --- a/frameworks/inner/ipc/common/log.h +++ b/frameworks/inner/ipc/common/log.h @@ -137,7 +137,7 @@ #define CHECK_AND_RETURN_LOG_RET(cond, ret, fmt, ...) \ do { \ if (!(cond)) { \ - HILOGE(fmt " ret(%{public}s)", ##__VA_ARGS__, #ret); \ + HILOGE(fmt, ##__VA_ARGS__); \ return ret; \ } \ } while (0) diff --git a/frameworks/inner/src/bluetooth_ble_advertiser.cpp b/frameworks/inner/src/bluetooth_ble_advertiser.cpp index 8937538e..59b9cda9 100644 --- a/frameworks/inner/src/bluetooth_ble_advertiser.cpp +++ b/frameworks/inner/src/bluetooth_ble_advertiser.cpp @@ -16,7 +16,6 @@ #include "bluetooth_ble_advertise_callback_stub.h" #include "bluetooth_def.h" -#include "bluetooth_errorcode.h" #include "bluetooth_host.h" #include "bluetooth_log.h" #include "bluetooth_observer_map.h" diff --git a/frameworks/inner/src/bluetooth_ble_central_manager.cpp b/frameworks/inner/src/bluetooth_ble_central_manager.cpp index e23780db..5362d5ca 100644 --- a/frameworks/inner/src/bluetooth_ble_central_manager.cpp +++ b/frameworks/inner/src/bluetooth_ble_central_manager.cpp @@ -15,7 +15,6 @@ #include "bluetooth_ble_central_manager.h" #include "bluetooth_ble_central_manager_callback_stub.h" #include "bluetooth_def.h" -#include "bluetooth_errorcode.h" #include "bluetooth_host.h" #include "bluetooth_log.h" #include "bluetooth_observer_list.h" diff --git a/frameworks/inner/src/bluetooth_gatt_client.cpp b/frameworks/inner/src/bluetooth_gatt_client.cpp index d021cbe2..4ee6a6c1 100644 --- a/frameworks/inner/src/bluetooth_gatt_client.cpp +++ b/frameworks/inner/src/bluetooth_gatt_client.cpp @@ -17,7 +17,6 @@ #include #include -#include "bluetooth_errorcode.h" #include "bluetooth_def.h" #include "bluetooth_gatt_client.h" #include "bluetooth_gatt_client_proxy.h" diff --git a/frameworks/inner/src/bluetooth_hfp_ag.cpp b/frameworks/inner/src/bluetooth_hfp_ag.cpp index 3dc6e823..73f9eeb6 100644 --- a/frameworks/inner/src/bluetooth_hfp_ag.cpp +++ b/frameworks/inner/src/bluetooth_hfp_ag.cpp @@ -16,7 +16,6 @@ #include "bluetooth_hfp_ag.h" #include #include "bluetooth_device.h" -#include "bluetooth_errorcode.h" #include "bluetooth_host.h" #include "bluetooth_load_system_ability.h" #include "bluetooth_log.h" diff --git a/frameworks/inner/src/bluetooth_host.cpp b/frameworks/inner/src/bluetooth_host.cpp index ea12d9f7..541be3ae 100644 --- a/frameworks/inner/src/bluetooth_host.cpp +++ b/frameworks/inner/src/bluetooth_host.cpp @@ -27,8 +27,8 @@ #include "bluetooth_observer_list.h" #include "bluetooth_remote_device_observer_stub.h" #include "iservice_registry.h" +#include "parameter.h" #include "system_ability_definition.h" -#include "bluetooth_errorcode.h" namespace OHOS { namespace Bluetooth { @@ -507,7 +507,7 @@ void BluetoothHost::Init() void BluetoothHost::Uinit() { - HILOGE("enter BluetoothHost Uinit"); + HILOGI("enter BluetoothHost Uinit"); if (!pimpl) { HILOGE("fails: no pimpl"); return; @@ -525,31 +525,22 @@ void BluetoothHost::Uinit() int BluetoothHost::CountEnableTimes(bool enable) { HILOGD("enter"); - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return BT_ERR_INTERNAL_ERROR; - } - + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, BT_ERR_INTERNAL_ERROR, "pimpl or proxy_ is nullptr"); return pimpl->proxy_->CountEnableTimes(enable); } + int BluetoothHost::EnableBt() { HILOGD("enter"); - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return BT_ERR_INTERNAL_ERROR; - } - + CHECK_AND_RETURN_LOG_RET(!IsBtProhibitedByEdm(), BT_ERR_PROHIBITED_BY_EDM, "bluetooth is prohibited"); + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, BT_ERR_INTERNAL_ERROR, "pimpl or proxy is null"); return pimpl->proxy_->EnableBt(); } int BluetoothHost::DisableBt() { HILOGD("enter"); - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return BT_ERR_INTERNAL_ERROR; - } + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, BT_ERR_INTERNAL_ERROR, "pimpl or proxy_ is nullptr"); CountEnableTimes(false); return pimpl->proxy_->DisableBt(); } @@ -557,15 +548,8 @@ int BluetoothHost::DisableBt() int BluetoothHost::GetBtState() const { HILOGD("enter"); - if (!IS_BT_ENABLED()) { - HILOGE("bluetooth is off."); - return BTStateID::STATE_TURN_OFF; - } - - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return BTStateID::STATE_TURN_OFF; - } + CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BTStateID::STATE_TURN_OFF, "bluetooth is off."); + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, BT_ERR_INTERNAL_ERROR, "pimpl or proxy_ is nullptr"); int state = BTStateID::STATE_TURN_OFF; pimpl->proxy_->GetBtState(state); @@ -576,17 +560,10 @@ int BluetoothHost::GetBtState() const int BluetoothHost::GetBtState(int &state) const { HILOGD("enter"); - state = BTStateID::STATE_TURN_OFF; - if (!IS_BT_ENABLED()) { - HILOGE("bluetooth is off."); - return BT_NO_ERROR; - } - - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return BT_ERR_INVALID_STATE; - } + CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_NO_ERROR, "bluetooth is off."); + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, BT_ERR_INVALID_STATE, "pimpl or proxy_ is nullptr"); + state = BTStateID::STATE_TURN_OFF; int ret = pimpl->proxy_->GetBtState(state); HILOGI("state: %{public}d", state); return ret; @@ -595,24 +572,16 @@ int BluetoothHost::GetBtState(int &state) const bool BluetoothHost::BluetoothFactoryReset() { HILOGD("enter"); - if (!IS_BT_ENABLED()) { - HILOGE("bluetooth is off."); - return false; - } - - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return false; - } + CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), false, "bluetooth is off."); + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, false, "pimpl or proxy_ is nullptr"); return pimpl->proxy_->BluetoothFactoryReset(); } bool BluetoothHost::IsValidBluetoothAddr(const std::string &addr) { - if (addr.empty() || addr.length() != ADDRESS_LENGTH) { - return false; - } + CHECK_AND_RETURN_LOG_RET(addr.length() == ADDRESS_LENGTH, false, "invalid address len."); + for (int i = 0; i < ADDRESS_LENGTH; i++) { char c = addr[i]; switch (i % ADDRESS_SEPARATOR_UNIT) { @@ -641,11 +610,12 @@ BluetoothRemoteDevice BluetoothHost::GetRemoteDevice(const std::string &addr, in int BluetoothHost::EnableBle() { - HILOGD("enter"); - if (!pimpl || !pimpl->LoadBluetoothHostService()) { - HILOGE("pimpl or bluetooth host is nullptr"); - return BT_ERR_INTERNAL_ERROR; - } + HILOGI("enter"); + CHECK_AND_RETURN_LOG_RET(!IsBtProhibitedByEdm(), BT_ERR_PROHIBITED_BY_EDM, "bluetooth is prohibited"); + + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->LoadBluetoothHostService(), BT_ERR_INTERNAL_ERROR, + "pimpl or proxy is null"); + CountEnableTimes(true); return pimpl->proxy_->EnableBle(); } @@ -653,29 +623,21 @@ int BluetoothHost::EnableBle() int BluetoothHost::DisableBle() { HILOGD("enter"); - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return BT_ERR_INTERNAL_ERROR; - } + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, BT_ERR_INTERNAL_ERROR, "pimpl or proxy_ is nullptr"); + return pimpl->proxy_->DisableBle(); } bool BluetoothHost::IsBrEnabled() const { - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return false; - } + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, false, "pimpl or proxy_ is nullptr"); return pimpl->proxy_->IsBrEnabled(); } bool BluetoothHost::IsBleEnabled() const { - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return false; - } + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, false, "pimpl or proxy_ is nullptr"); return pimpl->proxy_->IsBleEnabled(); } @@ -683,10 +645,7 @@ bool BluetoothHost::IsBleEnabled() const std::string BluetoothHost::GetLocalAddress() const { HILOGD("enter"); - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return std::string(); - } + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, std::string(), "pimpl or proxy_ is nullptr"); return pimpl->proxy_->GetLocalAddress(); } @@ -695,10 +654,7 @@ std::vector BluetoothHost::GetProfileList() const { HILOGD("enter"); std::vector profileList; - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return profileList; - } + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, profileList, "pimpl or proxy_ is nullptr"); profileList = pimpl->proxy_->GetProfileList(); return profileList; @@ -707,10 +663,7 @@ std::vector BluetoothHost::GetProfileList() const int BluetoothHost::GetMaxNumConnectedAudioDevices() const { HILOGD("enter"); - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return INVALID_VALUE; - } + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, INVALID_VALUE, "pimpl or proxy_ is nullptr"); return pimpl->proxy_->GetMaxNumConnectedAudioDevices(); } @@ -719,15 +672,8 @@ int BluetoothHost::GetBtConnectionState() const { HILOGD("enter"); int state = static_cast(BTConnectState::DISCONNECTED); - if (!IS_BT_ENABLED()) { - HILOGE("bluetooth is off."); - return state; - } - - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return state; - } + CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), state, "bluetooth is off."); + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, state, "pimpl or proxy_ is nullptr"); pimpl->proxy_->GetBtConnectionState(state); HILOGI("state: %{public}d", state); @@ -737,17 +683,10 @@ int BluetoothHost::GetBtConnectionState() const int BluetoothHost::GetBtConnectionState(int &state) const { HILOGD("enter"); - state = static_cast(BTConnectState::DISCONNECTED); - if (!IS_BT_ENABLED()) { - HILOGE("bluetooth is off."); - return BT_ERR_INVALID_STATE; - } - - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return BT_ERR_UNAVAILABLE_PROXY; - } + CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, BT_ERR_UNAVAILABLE_PROXY, "pimpl or proxy_ is nullptr"); + state = static_cast(BTConnectState::DISCONNECTED); int ret = pimpl->proxy_->GetBtConnectionState(state); HILOGI("state: %{public}d", state); return ret; @@ -756,27 +695,17 @@ int BluetoothHost::GetBtConnectionState(int &state) const int BluetoothHost::GetBtProfileConnState(uint32_t profileId, int &state) const { HILOGI("enter, profileId: %{public}d", profileId); - state = static_cast(BTConnectState::DISCONNECTED); - if (!IS_BT_ENABLED()) { - HILOGE("bluetooth is off."); - return BT_ERR_INVALID_STATE; - } - - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return BT_ERR_UNAVAILABLE_PROXY; - } + CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, BT_ERR_UNAVAILABLE_PROXY, "pimpl or proxy_ is nullptr"); + state = static_cast(BTConnectState::DISCONNECTED); return pimpl->proxy_->GetBtProfileConnState(profileId, state); } void BluetoothHost::GetLocalSupportedUuids(std::vector &uuids) { HILOGD("enter"); - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return; - } + CHECK_AND_RETURN_LOG(pimpl && pimpl->proxy_, "pimpl or proxy_ is nullptr"); std::vector stringUuids; pimpl->proxy_->GetLocalSupportedUuids(stringUuids); @@ -799,10 +728,7 @@ void BluetoothHost::Stop() BluetoothDeviceClass BluetoothHost::GetLocalDeviceClass() const { HILOGD("enter"); - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return BluetoothDeviceClass(0); - } + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, BluetoothDeviceClass(0), "pimpl or proxy_ is nullptr"); int LocalDeviceClass = pimpl->proxy_->GetLocalDeviceClass(); return BluetoothDeviceClass(LocalDeviceClass); @@ -811,10 +737,7 @@ BluetoothDeviceClass BluetoothHost::GetLocalDeviceClass() const bool BluetoothHost::SetLocalDeviceClass(const BluetoothDeviceClass &deviceClass) { HILOGD("enter"); - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return false; - } + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, false, "pimpl or proxy_ is nullptr"); int cod = deviceClass.GetClassOfDevice(); return pimpl->proxy_->SetLocalDeviceClass(cod); @@ -823,10 +746,7 @@ bool BluetoothHost::SetLocalDeviceClass(const BluetoothDeviceClass &deviceClass) std::string BluetoothHost::GetLocalName() const { HILOGD("enter"); - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return std::string(); - } + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, std::string(), "pimpl or proxy_ is nullptr"); std::string name = INVALID_NAME; pimpl->proxy_->GetLocalName(name); @@ -836,10 +756,7 @@ std::string BluetoothHost::GetLocalName() const int BluetoothHost::GetLocalName(std::string &name) const { HILOGD("enter"); - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return BT_ERR_UNAVAILABLE_PROXY; - } + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, BT_ERR_UNAVAILABLE_PROXY, "pimpl or proxy_ is nullptr"); return pimpl->proxy_->GetLocalName(name); } @@ -847,14 +764,8 @@ int BluetoothHost::GetLocalName(std::string &name) const int BluetoothHost::SetLocalName(const std::string &name) { HILOGD("enter"); - if (!IS_BT_ENABLED()) { - HILOGE("bluetooth is off."); - return BT_ERR_INVALID_STATE; - } - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return BT_ERR_UNAVAILABLE_PROXY; - } + CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, BT_ERR_UNAVAILABLE_PROXY, "pimpl or proxy_ is nullptr"); return pimpl->proxy_->SetLocalName(name); } @@ -862,15 +773,8 @@ int BluetoothHost::SetLocalName(const std::string &name) int BluetoothHost::GetBtScanMode(int32_t &scanMode) const { HILOGD("enter"); - if (!IS_BT_ENABLED()) { - HILOGE("bluetooth is off."); - return BT_ERR_INVALID_STATE; - } - - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return BT_ERR_UNAVAILABLE_PROXY; - } + CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, BT_ERR_UNAVAILABLE_PROXY, "pimpl or proxy_ is nullptr"); return pimpl->proxy_->GetBtScanMode(scanMode); } @@ -878,15 +782,8 @@ int BluetoothHost::GetBtScanMode(int32_t &scanMode) const int BluetoothHost::SetBtScanMode(int mode, int duration) { HILOGI("enter, mode: %{public}d, duration: %{public}d", mode, duration); - if (!IS_BT_ENABLED()) { - HILOGE("bluetooth is off."); - return BT_ERR_INVALID_STATE; - } - - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return BT_ERR_UNAVAILABLE_PROXY; - } + CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, BT_ERR_UNAVAILABLE_PROXY, "pimpl or proxy_ is nullptr"); return pimpl->proxy_->SetBtScanMode(mode, duration); } @@ -894,10 +791,7 @@ int BluetoothHost::SetBtScanMode(int mode, int duration) int BluetoothHost::GetBondableMode(int transport) const { HILOGI("enter, transport: %{public}d", transport); - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return INVALID_VALUE; - } + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, INVALID_VALUE, "pimpl or proxy_ is nullptr"); return pimpl->proxy_->GetBondableMode(transport); } @@ -905,10 +799,7 @@ int BluetoothHost::GetBondableMode(int transport) const bool BluetoothHost::SetBondableMode(int transport, int mode) { HILOGI("enter, transport: %{public}d, mode: %{public}d", transport, mode); - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return false; - } + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, false, "pimpl or proxy_ is nullptr"); return pimpl->proxy_->SetBondableMode(transport, mode); } @@ -916,15 +807,8 @@ bool BluetoothHost::SetBondableMode(int transport, int mode) int BluetoothHost::StartBtDiscovery() { HILOGD("enter"); - if (!IS_BT_ENABLED()) { - HILOGE("bluetooth is off."); - return BT_ERR_INVALID_STATE; - } - - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return BT_ERR_UNAVAILABLE_PROXY; - } + CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, BT_ERR_UNAVAILABLE_PROXY, "pimpl or proxy_ is nullptr"); return pimpl->proxy_->StartBtDiscovery(); } @@ -932,15 +816,8 @@ int BluetoothHost::StartBtDiscovery() int BluetoothHost::CancelBtDiscovery() { HILOGD("enter"); - if (!IS_BT_ENABLED()) { - HILOGE("bluetooth is off."); - return BT_ERR_INVALID_STATE; - } - - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return BT_ERR_UNAVAILABLE_PROXY; - } + CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, BT_ERR_UNAVAILABLE_PROXY, "pimpl or proxy_ is nullptr"); return pimpl->proxy_->CancelBtDiscovery(); } @@ -948,15 +825,8 @@ int BluetoothHost::CancelBtDiscovery() int32_t BluetoothHost::IsBtDiscovering(bool &isDiscovering, int transport) const { HILOGI("enter, transport: %{public}d", transport); - if (!IS_BT_ENABLED()) { - HILOGE("bluetooth is off."); - return BT_ERR_INVALID_STATE; - } - - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return BT_ERR_INVALID_STATE; - } + CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, BT_ERR_UNAVAILABLE_PROXY, "pimpl or proxy_ is nullptr"); return pimpl->proxy_->IsBtDiscovering(isDiscovering, transport); } @@ -964,15 +834,8 @@ int32_t BluetoothHost::IsBtDiscovering(bool &isDiscovering, int transport) const long BluetoothHost::GetBtDiscoveryEndMillis() const { HILOGD("enter"); - if (!IS_BT_ENABLED()) { - HILOGE("bluetooth is off."); - return 0; - } - - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return 0; - } + CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), 0, "bluetooth is off."); + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, 0, "pimpl or proxy_ is nullptr"); return pimpl->proxy_->GetBtDiscoveryEndMillis(); } @@ -980,14 +843,8 @@ long BluetoothHost::GetBtDiscoveryEndMillis() const int32_t BluetoothHost::GetPairedDevices(int transport, std::vector &pairedDevices) const { HILOGI("enter, transport: %{public}d", transport); - if (!IS_BT_ENABLED()) { - HILOGE("bluetooth is off."); - return BT_ERR_INVALID_STATE; - } - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return BT_ERR_UNAVAILABLE_PROXY; - } + CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, BT_ERR_UNAVAILABLE_PROXY, "pimpl or proxy_ is nullptr"); std::vector pairedAddr; int32_t ret = pimpl->proxy_->GetPairedDevices(pairedAddr); @@ -1002,15 +859,8 @@ int32_t BluetoothHost::GetPairedDevices(int transport, std::vectorproxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return BT_ERR_UNAVAILABLE_PROXY; - } + CHECK_AND_RETURN_LOG_RET(device.IsValidBluetoothRemoteDevice(), BT_ERR_INTERNAL_ERROR, "Invalid remote device."); + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, BT_ERR_UNAVAILABLE_PROXY, "pimpl or proxy_ is nullptr"); sptr rawAddrSptr = new BluetoothRawAddress(device.GetDeviceAddr()); return pimpl->proxy_->RemovePair(device.GetTransportType(), rawAddrSptr); @@ -1019,10 +869,7 @@ int32_t BluetoothHost::RemovePair(const BluetoothRemoteDevice &device) bool BluetoothHost::RemoveAllPairs() { HILOGD("enter"); - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return false; - } + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, false, "pimpl or proxy_ is nullptr"); return pimpl->proxy_->RemoveAllPairs(); } @@ -1043,57 +890,39 @@ void BluetoothHost::DeregisterRemoteDeviceObserver(std::shared_ptrproxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return INVALID_VALUE; - } + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, INVALID_VALUE, "pimpl or proxy_ is nullptr"); return pimpl->proxy_->GetBleMaxAdvertisingDataLength(); } void BluetoothHost::LoadSystemAbilitySuccess(const sptr &remoteObject) { - if (!pimpl) { - HILOGE("fails: no pimpl"); - return; - } + CHECK_AND_RETURN_LOG(pimpl, "pimpl is null."); + pimpl->LoadSystemAbilitySuccess(remoteObject); } void BluetoothHost::LoadSystemAbilityFail() { - if (!pimpl) { - HILOGE("fails: no pimpl"); - return; - } + CHECK_AND_RETURN_LOG(pimpl, "pimpl is null."); + pimpl->LoadSystemAbilityFail(); } int32_t BluetoothHost::GetLocalProfileUuids(std::vector &uuids) { - if (!IS_BT_ENABLED()) { - HILOGE("bluetooth is off."); - return BT_ERR_INTERNAL_ERROR; - } - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return BT_ERR_UNAVAILABLE_PROXY; - } + CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INTERNAL_ERROR, "bluetooth is off."); + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, BT_ERR_UNAVAILABLE_PROXY, "pimpl or proxy_ is nullptr"); + return pimpl->proxy_->GetLocalProfileUuids(uuids); } int BluetoothHost::SetFastScan(bool isEnable) { HILOGI("enter, isEnable: %{public}d", isEnable); - if (!IS_BT_ENABLED()) { - HILOGE("bluetooth is off."); - return BT_ERR_INVALID_STATE; - } + CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); + CHECK_AND_RETURN_LOG_RET(pimpl && pimpl->proxy_, BT_ERR_UNAVAILABLE_PROXY, "pimpl or proxy_ is nullptr"); - if (!pimpl || !pimpl->proxy_) { - HILOGE("pimpl or bluetooth host is nullptr"); - return BT_ERR_UNAVAILABLE_PROXY; - } return pimpl->proxy_->SetFastScan(isEnable); } @@ -1119,5 +948,25 @@ int BluetoothHost::DisconnectAllowedProfiles(const std::string &remoteAddr) cons CHECK_AND_RETURN_LOG_RET((pimpl && pimpl->proxy_), BT_ERR_UNAVAILABLE_PROXY, "pimpl or bluetooth host is nullptr"); return pimpl->proxy_->DisconnectAllowedProfiles(remoteAddr); } + +bool BluetoothHost::IsBtProhibitedByEdm(void) +{ + constexpr const char* BLUETOOTH_EDM_KEY = "persist.edm.prohibit_bluetooth"; + constexpr const uint32_t PARAM_TRUE_LEN = 4; // "true" 4bytes + constexpr const uint32_t PARAM_FALSE_LEN = 5; // "false" 5bytes + constexpr const char* PARAM_TRUE = "true"; + constexpr const char* PARAM_FALSE = "false"; + + char result[PARAM_FALSE_LEN + 1] = {0}; + // Returns the number of bytes of the system parameter if the operation is successful. + int len = GetParameter(BLUETOOTH_EDM_KEY, PARAM_FALSE, result, PARAM_FALSE_LEN + 1); + CHECK_AND_RETURN_LOG_RET(len == PARAM_FALSE_LEN || len == PARAM_TRUE_LEN, false, "GetParameter len is invalid."); + HILOGI("prohibit_bluetooth = %{public}s", result); + if (strncmp(result, PARAM_TRUE, PARAM_TRUE_LEN) == 0) { + HILOGW("Bluetooth is prohibited by EDM. You won't be able to turn on bluetooth !"); + return true; + } + return false; +} } // namespace Bluetooth } // namespace OHOS diff --git a/frameworks/inner/src/bluetooth_pan.cpp b/frameworks/inner/src/bluetooth_pan.cpp index 6571282e..e4aec807 100644 --- a/frameworks/inner/src/bluetooth_pan.cpp +++ b/frameworks/inner/src/bluetooth_pan.cpp @@ -14,7 +14,6 @@ */ #include "bluetooth_pan.h" -#include "bluetooth_errorcode.h" #include "bluetooth_host.h" #include "bluetooth_load_system_ability.h" #include "bluetooth_log.h" diff --git a/frameworks/inner/src/bluetooth_utils.cpp b/frameworks/inner/src/bluetooth_utils.cpp index d0748e12..e9d292de 100644 --- a/frameworks/inner/src/bluetooth_utils.cpp +++ b/frameworks/inner/src/bluetooth_utils.cpp @@ -18,7 +18,6 @@ #include #include "securec.h" #include "__config" -#include "bluetooth_errorcode.h" #include "bluetooth_def.h" #include "bluetooth_host_proxy.h" #include "bluetooth_log.h" diff --git a/frameworks/js/napi/src/ble/napi_bluetooth_gatt_server.cpp b/frameworks/js/napi/src/ble/napi_bluetooth_gatt_server.cpp index 011b5bca..f5ec8ada 100644 --- a/frameworks/js/napi/src/ble/napi_bluetooth_gatt_server.cpp +++ b/frameworks/js/napi/src/ble/napi_bluetooth_gatt_server.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ #include "napi_bluetooth_gatt_server.h" -#include "bluetooth_errorcode.h" #include "bluetooth_gatt_service.h" #include "bluetooth_host.h" #include "bluetooth_log.h" diff --git a/frameworks/js/napi/src/common/napi_bluetooth_error.cpp b/frameworks/js/napi/src/common/napi_bluetooth_error.cpp index 0875c0ed..95994da9 100644 --- a/frameworks/js/napi/src/common/napi_bluetooth_error.cpp +++ b/frameworks/js/napi/src/common/napi_bluetooth_error.cpp @@ -32,6 +32,7 @@ static std::map napiErrMsgMap { { BtErrCode::BT_ERR_IPC_TRANS_FAILED, "trans exception." }, { BtErrCode::BT_ERR_PERMISSION_FAILED, "Permission denied." }, { BtErrCode::BT_ERR_SYSTEM_PERMISSION_FAILED, "Non-system applications are not allowed to use system APIs."}, + { BtErrCode::BT_ERR_PROHIBITED_BY_EDM, "Bluetooth is prohibited by EDM."}, { BtErrCode::BT_ERR_INVALID_PARAM, "Invalid parameter." }, { BtErrCode::BT_ERR_API_NOT_SUPPORT, "Capability is not supported." }, { BtErrCode::BT_ERR_GATT_READ_NOT_PERMITTED, "Gatt read forbiden." }, diff --git a/frameworks/js/napi/src/common/napi_bluetooth_utils.cpp b/frameworks/js/napi/src/common/napi_bluetooth_utils.cpp index b29ab7a8..11157c91 100644 --- a/frameworks/js/napi/src/common/napi_bluetooth_utils.cpp +++ b/frameworks/js/napi/src/common/napi_bluetooth_utils.cpp @@ -17,7 +17,6 @@ #include #include #include -#include "bluetooth_errorcode.h" #include "bluetooth_log.h" #include "bluetooth_utils.h" #include "napi/native_api.h" diff --git a/frameworks/js/napi/src/hfp/napi_bluetooth_hfp_ag.cpp b/frameworks/js/napi/src/hfp/napi_bluetooth_hfp_ag.cpp index 58d856e7..67942791 100644 --- a/frameworks/js/napi/src/hfp/napi_bluetooth_hfp_ag.cpp +++ b/frameworks/js/napi/src/hfp/napi_bluetooth_hfp_ag.cpp @@ -14,7 +14,6 @@ */ #include "bluetooth_hfp_ag.h" -#include "bluetooth_errorcode.h" #include "bluetooth_utils.h" #include "napi_async_work.h" #include "napi_bluetooth_error.h" diff --git a/frameworks/js/napi/src/hid/napi_bluetooth_hid_host.cpp b/frameworks/js/napi/src/hid/napi_bluetooth_hid_host.cpp index fdc2fd5c..17f116ac 100644 --- a/frameworks/js/napi/src/hid/napi_bluetooth_hid_host.cpp +++ b/frameworks/js/napi/src/hid/napi_bluetooth_hid_host.cpp @@ -15,7 +15,6 @@ #include "bluetooth_hid_host.h" -#include "bluetooth_errorcode.h" #include "bluetooth_log.h" #include "bluetooth_utils.h" #include "napi_async_work.h" diff --git a/frameworks/js/napi/src/pan/napi_bluetooth_pan.cpp b/frameworks/js/napi/src/pan/napi_bluetooth_pan.cpp index 8b79cc28..bc45b4a3 100644 --- a/frameworks/js/napi/src/pan/napi_bluetooth_pan.cpp +++ b/frameworks/js/napi/src/pan/napi_bluetooth_pan.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ -#include "bluetooth_errorcode.h" #include "bluetooth_log.h" #include "bluetooth_pan.h" #include "bluetooth_utils.h" diff --git a/interfaces/inner_api/include/bluetooth_errorcode.h b/interfaces/inner_api/include/bluetooth_errorcode.h deleted file mode 100644 index 463605be..00000000 --- a/interfaces/inner_api/include/bluetooth_errorcode.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2022-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BLUETOOTH_ERRORCODE_H -#define BLUETOOTH_ERRORCODE_H - -namespace OHOS { -namespace Bluetooth { - -/* Bluetooth errcode defines */ -enum BtErrCode { - // Common error codes - BT_ERR_PERMISSION_FAILED = 201, - BT_ERR_SYSTEM_PERMISSION_FAILED = 202, - BT_ERR_INVALID_PARAM = 401, - BT_ERR_API_NOT_SUPPORT = 801, - - // Customized error codes - BT_NO_ERROR = 0, - - BT_ERR_BASE_SYSCAP = 2900000, - BT_ERR_SERVICE_DISCONNECTED = BT_ERR_BASE_SYSCAP + 1, - BT_ERR_UNBONDED_DEVICE = BT_ERR_BASE_SYSCAP + 2, - BT_ERR_INVALID_STATE = BT_ERR_BASE_SYSCAP + 3, - BT_ERR_PROFILE_DISABLED = BT_ERR_BASE_SYSCAP + 4, - BT_ERR_DEVICE_DISCONNECTED = BT_ERR_BASE_SYSCAP + 5, - BT_ERR_MAX_CONNECTION = BT_ERR_BASE_SYSCAP + 6, - BT_ERR_UNAVAILABLE_PROXY = BT_ERR_BASE_SYSCAP + 8, - - BT_ERR_INTERNAL_ERROR = BT_ERR_BASE_SYSCAP + 99, - BT_ERR_IPC_TRANS_FAILED = BT_ERR_BASE_SYSCAP + 100, - - BT_ERR_GATT_READ_NOT_PERMITTED = BT_ERR_BASE_SYSCAP + 1000, - BT_ERR_GATT_WRITE_NOT_PERMITTED = BT_ERR_BASE_SYSCAP + 1001, - BT_ERR_GATT_MAX_SERVER = BT_ERR_BASE_SYSCAP + 1002, - - BT_ERR_SPP_SERVER_STATE = BT_ERR_BASE_SYSCAP + 1050, - BT_ERR_SPP_BUSY = BT_ERR_BASE_SYSCAP + 1051, - BT_ERR_SPP_DEVICE_NOT_FOUND = BT_ERR_BASE_SYSCAP + 1052, - BT_ERR_SPP_IO = BT_ERR_BASE_SYSCAP + 1054, - - // will deprected - NO_ERROR = BT_NO_ERROR, - ERROR = BT_ERR_INTERNAL_ERROR, - ERR_INVALID_STATE = BT_ERR_INVALID_STATE, -}; -} // namespace Bluetooth -} // namespace OHOS - -#endif // BLUETOOTH_ERRORCODE_H \ No newline at end of file diff --git a/interfaces/inner_api/include/bluetooth_host.h b/interfaces/inner_api/include/bluetooth_host.h index ea009b0e..46050d16 100644 --- a/interfaces/inner_api/include/bluetooth_host.h +++ b/interfaces/inner_api/include/bluetooth_host.h @@ -693,6 +693,14 @@ private: int CountEnableTimes(bool enable); + /** + * @brief Check whether bluetooth is prohibited by EDM. + * + * @return Returns true if bluetooth is prohibited, returns false otherwise. + * @since 11 + */ + bool IsBtProhibitedByEdm(void); + BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(BluetoothHost); BLUETOOTH_DECLARE_IMPL(); }; -- Gitee From ec656e9e98cda3bab2a7d139308a3a94d15c1af2 Mon Sep 17 00:00:00 2001 From: lee Date: Thu, 7 Dec 2023 17:13:01 +0800 Subject: [PATCH 2/2] Add EDM prohibit bluetooth feature Signed-off-by: lee --- frameworks/inner/src/bluetooth_host.cpp | 81 ++++++++++++------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/frameworks/inner/src/bluetooth_host.cpp b/frameworks/inner/src/bluetooth_host.cpp index ce7cf496..aabc2ead 100644 --- a/frameworks/inner/src/bluetooth_host.cpp +++ b/frameworks/inner/src/bluetooth_host.cpp @@ -308,7 +308,7 @@ BluetoothHost::impl::impl() profileRegisterId = DelayedSingleton::GetInstance()->RegisterFunc(BLUETOOTH_HOST, [this](sptr remote) { sptr proxy = iface_cast(remote); - CHECK_AND_RETURN_LOG(proxy != nullptr, "failed: no proxy"); + CHECK_AND_RETURN_LOG(proxy != nullptr, "proxy is nullptr"); proxy->RegisterObserver(observerImp_); proxy->RegisterBleAdapterObserver(bleObserverImp_); proxy->RegisterRemoteDeviceObserver(remoteObserverImp_); @@ -321,7 +321,7 @@ BluetoothHost::impl::~impl() HILOGI("starts"); DelayedSingleton::GetInstance()->DeregisterFunc(profileRegisterId); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG(proxy != nullptr, "failed: no proxy"); + CHECK_AND_RETURN_LOG(proxy != nullptr, "proxy is nullptr"); proxy->DeregisterObserver(observerImp_); proxy->DeregisterBleAdapterObserver(bleObserverImp_); proxy->DeregisterRemoteDeviceObserver(remoteObserverImp_); @@ -390,7 +390,7 @@ void BluetoothHost::impl::SyncRandomAddrToService(void) return; } sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG(proxy != nullptr, "failed: no proxy"); + CHECK_AND_RETURN_LOG(proxy != nullptr, "proxy is nullptr"); proxy->SyncRandomAddress(stagingRealAddr_, stagingRandomAddr_); stagingRealAddr_ = ""; stagingRandomAddr_ = ""; @@ -431,7 +431,7 @@ int BluetoothHost::CountEnableTimes(bool enable) { HILOGD("enter"); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INTERNAL_ERROR, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INTERNAL_ERROR, "proxy is nullptr"); return proxy->CountEnableTimes(enable); } @@ -441,7 +441,7 @@ int BluetoothHost::EnableBt() HILOGD("enter"); CHECK_AND_RETURN_LOG_RET(!IsBtProhibitedByEdm(), BT_ERR_PROHIBITED_BY_EDM, "bluetooth is prohibited"); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INTERNAL_ERROR, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INTERNAL_ERROR, "proxy is nullptr"); return proxy->EnableBt(); } @@ -450,7 +450,7 @@ int BluetoothHost::DisableBt() { HILOGD("enter"); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INTERNAL_ERROR, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INTERNAL_ERROR, "proxy is nullptr"); CountEnableTimes(false); return proxy->DisableBt(); @@ -462,7 +462,7 @@ int BluetoothHost::GetBtState() const CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BTStateID::STATE_TURN_OFF, "bluetooth is off."); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BTStateID::STATE_TURN_OFF, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BTStateID::STATE_TURN_OFF, "proxy is nullptr"); int state = BTStateID::STATE_TURN_OFF; proxy->GetBtState(state); @@ -477,7 +477,7 @@ int BluetoothHost::GetBtState(int &state) const CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_NO_ERROR, "bluetooth is off."); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INVALID_STATE, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INVALID_STATE, "proxy is nullptr"); int ret = proxy->GetBtState(state); HILOGI("state: %{public}d", state); @@ -490,7 +490,7 @@ bool BluetoothHost::BluetoothFactoryReset() CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), false, "bluetooth is off."); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, false, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, false, "proxy is nullptr"); return proxy->BluetoothFactoryReset(); } @@ -533,7 +533,7 @@ int BluetoothHost::EnableBle() "pimpl is null or load bluetooth service failed."); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INTERNAL_ERROR, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INTERNAL_ERROR, "proxy is nullptr"); CountEnableTimes(true); return proxy->EnableBle(); @@ -543,7 +543,7 @@ int BluetoothHost::DisableBle() { HILOGD("enter"); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INTERNAL_ERROR, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INTERNAL_ERROR, "proxy is nullptr"); return proxy->DisableBle(); } @@ -551,7 +551,7 @@ int BluetoothHost::DisableBle() bool BluetoothHost::IsBrEnabled() const { sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, false, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, false, "proxy is nullptr"); return proxy->IsBrEnabled(); } @@ -559,7 +559,7 @@ bool BluetoothHost::IsBrEnabled() const bool BluetoothHost::IsBleEnabled() const { sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, false, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, false, "proxy is nullptr"); return proxy->IsBleEnabled(); } @@ -568,7 +568,7 @@ std::string BluetoothHost::GetLocalAddress() const { HILOGD("enter"); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, std::string(), "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, std::string(), "proxy is nullptr"); return proxy->GetLocalAddress(); } @@ -578,7 +578,7 @@ std::vector BluetoothHost::GetProfileList() const HILOGD("enter"); std::vector profileList; sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, profileList, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, profileList, "proxy is nullptr"); profileList = proxy->GetProfileList(); return profileList; @@ -588,7 +588,7 @@ int BluetoothHost::GetMaxNumConnectedAudioDevices() const { HILOGD("enter"); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, INVALID_VALUE, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, INVALID_VALUE, "proxy is nullptr"); return proxy->GetMaxNumConnectedAudioDevices(); } @@ -600,7 +600,7 @@ int BluetoothHost::GetBtConnectionState() const CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), state, "bluetooth is off."); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, state, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, state, "proxy is nullptr"); proxy->GetBtConnectionState(state); HILOGI("state: %{public}d", state); @@ -614,7 +614,7 @@ int BluetoothHost::GetBtConnectionState(int &state) const CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "proxy is nullptr"); int ret = proxy->GetBtConnectionState(state); HILOGI("state: %{public}d", state); @@ -628,7 +628,7 @@ int BluetoothHost::GetBtProfileConnState(uint32_t profileId, int &state) const CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "proxy is nullptr"); return proxy->GetBtProfileConnState(profileId, state); } @@ -637,7 +637,7 @@ void BluetoothHost::GetLocalSupportedUuids(std::vector &uuids) { HILOGD("enter"); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG(proxy != nullptr, "failed: no proxy"); + CHECK_AND_RETURN_LOG(proxy != nullptr, "proxy is nullptr"); std::vector stringUuids; proxy->GetLocalSupportedUuids(stringUuids); @@ -662,7 +662,7 @@ BluetoothDeviceClass BluetoothHost::GetLocalDeviceClass() const { HILOGD("enter"); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BluetoothDeviceClass(0), "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BluetoothDeviceClass(0), "proxy is nullptr"); int LocalDeviceClass = proxy->GetLocalDeviceClass(); return BluetoothDeviceClass(LocalDeviceClass); @@ -672,7 +672,7 @@ bool BluetoothHost::SetLocalDeviceClass(const BluetoothDeviceClass &deviceClass) { HILOGD("enter"); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, false, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, false, "proxy is nullptr"); int cod = deviceClass.GetClassOfDevice(); return proxy->SetLocalDeviceClass(cod); @@ -682,7 +682,7 @@ std::string BluetoothHost::GetLocalName() const { HILOGD("enter"); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, std::string(), "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, std::string(), "proxy is nullptr"); std::string name = INVALID_NAME; proxy->GetLocalName(name); @@ -693,7 +693,7 @@ int BluetoothHost::GetLocalName(std::string &name) const { HILOGD("enter"); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "proxy is nullptr"); return proxy->GetLocalName(name); } @@ -704,7 +704,7 @@ int BluetoothHost::SetLocalName(const std::string &name) CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "proxy is nullptr"); return proxy->SetLocalName(name); } @@ -715,7 +715,7 @@ int BluetoothHost::GetBtScanMode(int32_t &scanMode) const CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "proxy is nullptr"); return proxy->GetBtScanMode(scanMode); } @@ -726,7 +726,7 @@ int BluetoothHost::SetBtScanMode(int mode, int duration) CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "proxy is nullptr"); return proxy->SetBtScanMode(mode, duration); } @@ -735,7 +735,7 @@ int BluetoothHost::GetBondableMode(int transport) const { HILOGI("transport: %{public}d", transport); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, INVALID_VALUE, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, INVALID_VALUE, "proxy is nullptr"); return proxy->GetBondableMode(transport); } @@ -744,7 +744,7 @@ bool BluetoothHost::SetBondableMode(int transport, int mode) { HILOGI("transport: %{public}d, mode: %{public}d", transport, mode); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, false, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, false, "proxy is nullptr"); return proxy->SetBondableMode(transport, mode); } @@ -755,7 +755,7 @@ int BluetoothHost::StartBtDiscovery() CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "proxy is nullptr"); return proxy->StartBtDiscovery(); } @@ -766,7 +766,7 @@ int BluetoothHost::CancelBtDiscovery() CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "proxy is nullptr"); return proxy->CancelBtDiscovery(); } @@ -777,7 +777,7 @@ int32_t BluetoothHost::IsBtDiscovering(bool &isDiscovering, int transport) const CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INVALID_STATE, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INVALID_STATE, "proxy is nullptr"); return proxy->IsBtDiscovering(isDiscovering, transport); } @@ -788,7 +788,7 @@ long BluetoothHost::GetBtDiscoveryEndMillis() const CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), 0, "bluetooth is off."); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, 0, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, 0, "proxy is nullptr"); return proxy->GetBtDiscoveryEndMillis(); } @@ -799,7 +799,7 @@ int32_t BluetoothHost::GetPairedDevices(int transport, std::vector proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "proxy is nullptr"); std::vector pairedAddr; int32_t ret = proxy->GetPairedDevices(pairedAddr); @@ -817,7 +817,7 @@ int32_t BluetoothHost::RemovePair(const BluetoothRemoteDevice &device) CHECK_AND_RETURN_LOG_RET(device.IsValidBluetoothRemoteDevice(), BT_ERR_INTERNAL_ERROR, "Invalid remote device."); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "proxy is nullptr"); sptr rawAddrSptr = new BluetoothRawAddress(device.GetDeviceAddr()); return proxy->RemovePair(device.GetTransportType(), rawAddrSptr); @@ -827,7 +827,7 @@ bool BluetoothHost::RemoveAllPairs() { HILOGD("enter"); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, false, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, false, "proxy is nullptr"); return proxy->RemoveAllPairs(); } @@ -851,7 +851,7 @@ void BluetoothHost::DeregisterRemoteDeviceObserver(std::shared_ptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, INVALID_VALUE, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, INVALID_VALUE, "proxy is nullptr"); return proxy->GetBleMaxAdvertisingDataLength(); } @@ -875,7 +875,7 @@ int32_t BluetoothHost::GetLocalProfileUuids(std::vector &uuids) CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INTERNAL_ERROR, "bluetooth is off."); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "proxy is nullptr"); return proxy->GetLocalProfileUuids(uuids); } @@ -886,7 +886,7 @@ int BluetoothHost::SetFastScan(bool isEnable) CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); - CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "failed: no proxy"); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "proxy is nullptr"); return proxy->SetFastScan(isEnable); } @@ -932,9 +932,8 @@ bool BluetoothHost::IsBtProhibitedByEdm(void) int len = GetParameter(BLUETOOTH_EDM_KEY, PARAM_FALSE, result, PARAM_FALSE_LEN + 1); CHECK_AND_RETURN_LOG_RET(len == PARAM_FALSE_LEN || len == PARAM_TRUE_LEN, false, "GetParameter len is invalid."); - HILOGI("prohibit_bluetooth = %{public}s", result); if (strncmp(result, PARAM_TRUE, PARAM_TRUE_LEN) == 0) { - HILOGW("Bluetooth is prohibited by EDM. You won't be able to turn on bluetooth !"); + HILOGW("bluetooth is prohibited by EDM. You won't be able to turn on bluetooth !"); return true; } return false; -- Gitee