From 80ebdb83d9530fde1eec5e29197bfe7563db2d55 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Wed, 23 Feb 2022 11:53:36 +0800 Subject: [PATCH 1/6] =?UTF-8?q?AccessToken=E6=9D=83=E9=99=90=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- interfaces/inner_kits/native_cpp/BUILD.gn | 8 -- .../native_cpp/include/device_manager_impl.h | 2 - .../native_cpp/src/device_manager_impl.cpp | 101 ------------------ services/devicemanagerservice/BUILD.gn | 1 + .../include/device_manager_service.h | 2 + .../src/device_manager_service.cpp | 43 ++++++++ utils/BUILD.gn | 12 ++- .../permission/lite/permission_token.h | 31 ++++++ .../permission/standard/permission_token.h | 31 ++++++ .../src/permission/lite/permission_token.cpp | 28 +++++ .../permission/standard/permission_token.cpp | 85 +++++++++++++++ 11 files changed, 232 insertions(+), 112 deletions(-) create mode 100644 utils/include/permission/lite/permission_token.h create mode 100644 utils/include/permission/standard/permission_token.h create mode 100644 utils/src/permission/lite/permission_token.cpp create mode 100644 utils/src/permission/standard/permission_token.cpp diff --git a/interfaces/inner_kits/native_cpp/BUILD.gn b/interfaces/inner_kits/native_cpp/BUILD.gn index 99011143a..353ca9f45 100644 --- a/interfaces/inner_kits/native_cpp/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/BUILD.gn @@ -63,14 +63,6 @@ if (defined(ohos_lite)) { "utils_base:utils", ] - if (support_jsapi) { - deps += [ "//foundation/aafwk/standard/interfaces/innerkits/want:want" ] - external_deps += [ - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - ] - defines += [ "SUPPORT_CALLING_ABILITY" ] - } subsystem_name = "distributedhardware" diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h index 46d8c3222..5b439ae65 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -64,8 +64,6 @@ private: DeviceManagerImpl(DeviceManagerImpl &&) = delete; DeviceManagerImpl &operator=(DeviceManagerImpl &&) = delete; -private: - bool isSystemAppCalling(void); private: std::shared_ptr ipcClientProxy_ = diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index 811a6d7f4..1d82859b4 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -15,16 +15,6 @@ #include "device_manager_impl.h" -#ifdef SUPPORT_CALLING_ABILITY -#include "bundle_constants.h" -#include "bundle_info.h" -#include "bundle_mgr_client.h" -#include "bundle_mgr_interface.h" -#endif -#include "if_system_ability_manager.h" -#include "iservice_registry.h" -#include "system_ability_definition.h" - #include "device_manager_notify.h" #include "dm_constants.h" #include "dm_log.h" @@ -45,47 +35,9 @@ #include "ipc_verify_authenticate_req.h" #include "securec.h" -#ifdef SUPPORT_CALLING_ABILITY -using namespace OHOS::AppExecFwk; -using namespace OHOS::AppExecFwk::Constants; -#endif namespace OHOS { namespace DistributedHardware { -bool DeviceManagerImpl::isSystemAppCalling(void) -{ -#ifdef SUPPORT_CALLING_ABILITY - int32_t uid = IPCSkeleton::GetCallingUid(); - if (uid < 0) { - LOGI("app caller uid is: %d,", uid); - return false; - } - - sptr systemAbilityManager = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (systemAbilityManager == nullptr) { - LOGE("failed to get system ability mgr."); - return true; - } - sptr remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); - if (remoteObject == nullptr) { - LOGE("failed to get bundle manager proxy."); - return true; - } - - LOGI("get bundle manager proxy success."); - sptr iBundleMgr = iface_cast(remoteObject); - if (iBundleMgr == nullptr) { - LOGI("iBundleMgr is nullptr, caller may be a process"); - return true; - } - - return iBundleMgr->CheckIsSystemAppByUid(uid); -#else - // Minimum system only native services will call - return true; -#endif -} DeviceManagerImpl &DeviceManagerImpl::GetInstance() { @@ -96,11 +48,6 @@ DeviceManagerImpl &DeviceManagerImpl::GetInstance() int32_t DeviceManagerImpl::InitDeviceManager(const std::string &pkgName, std::shared_ptr dmInitCallback) { LOGI("DeviceManager::InitDeviceManager start, pkgName: %s", pkgName.c_str()); - if (!isSystemAppCalling()) { - LOGI("the caller is not a system app"); - return DM_NOT_SYSTEM_APP; - } - if (pkgName.empty() || dmInitCallback == nullptr) { LOGE("InitDeviceManager error: Invalid parameter"); return DM_INVALID_VALUE; @@ -120,11 +67,6 @@ int32_t DeviceManagerImpl::InitDeviceManager(const std::string &pkgName, std::sh int32_t DeviceManagerImpl::UnInitDeviceManager(const std::string &pkgName) { LOGI("DeviceManager::UnInitDeviceManager start, pkgName: %s", pkgName.c_str()); - if (!isSystemAppCalling()) { - LOGI("the caller is not a system app"); - return DM_NOT_SYSTEM_APP; - } - if (pkgName.empty()) { LOGE("UnInitDeviceManager error: Invalid parameter"); return DM_INVALID_VALUE; @@ -145,11 +87,6 @@ int32_t DeviceManagerImpl::GetTrustedDeviceList(const std::string &pkgName, cons std::vector &deviceList) { LOGI("DeviceManager::GetTrustedDeviceList start, pkgName: %s", pkgName.c_str()); - if (!isSystemAppCalling()) { - LOGI("the caller is not a system app"); - return DM_NOT_SYSTEM_APP; - } - if (pkgName.empty()) { LOGE("GetTrustedDeviceList error: Invalid para"); return DM_INVALID_VALUE; @@ -179,11 +116,6 @@ int32_t DeviceManagerImpl::GetTrustedDeviceList(const std::string &pkgName, cons int32_t DeviceManagerImpl::GetLocalDeviceInfo(const std::string &pkgName, DmDeviceInfo &info) { LOGI("DeviceManager::GetLocalDeviceInfo start, pkgName: %s", pkgName.c_str()); - if (!isSystemAppCalling()) { - LOGI("the caller is not a system app"); - return DM_NOT_SYSTEM_APP; - } - std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); req->SetPkgName(pkgName); @@ -208,11 +140,6 @@ int32_t DeviceManagerImpl::RegisterDevStateCallback(const std::string &pkgName, std::shared_ptr callback) { LOGI("DeviceManager::RegisterDevStateCallback start, pkgName: %s", pkgName.c_str()); - if (!isSystemAppCalling()) { - LOGI("the caller is not a system app"); - return DM_NOT_SYSTEM_APP; - } - if (pkgName.empty() || callback == nullptr) { LOGE("RegisterDevStateCallback error: Invalid para"); return DM_INVALID_VALUE; @@ -226,11 +153,6 @@ int32_t DeviceManagerImpl::RegisterDevStateCallback(const std::string &pkgName, int32_t DeviceManagerImpl::UnRegisterDevStateCallback(const std::string &pkgName) { LOGI("DeviceManager::UnRegisterDevStateCallback start, pkgName: %s", pkgName.c_str()); - if (!isSystemAppCalling()) { - LOGI("the caller is not a system app"); - return DM_NOT_SYSTEM_APP; - } - if (pkgName.empty()) { LOGE("UnRegisterDevStateCallback error: Invalid para"); return DM_INVALID_VALUE; @@ -245,11 +167,6 @@ int32_t DeviceManagerImpl::StartDeviceDiscovery(const std::string &pkgName, cons const std::string &extra, std::shared_ptr callback) { LOGI("DeviceManager::StartDeviceDiscovery start, pkgName: %s", pkgName.c_str()); - if (!isSystemAppCalling()) { - LOGI("the caller is not a system app"); - return DM_NOT_SYSTEM_APP; - } - if (pkgName.empty() || callback == nullptr) { LOGE("StartDeviceDiscovery error: Invalid para"); return DM_INVALID_VALUE; @@ -282,11 +199,6 @@ int32_t DeviceManagerImpl::StartDeviceDiscovery(const std::string &pkgName, cons int32_t DeviceManagerImpl::StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId) { LOGI("DeviceManager::StopDeviceDiscovery start , pkgName: %s", pkgName.c_str()); - if (!isSystemAppCalling()) { - LOGI("the caller is not a system app"); - return DM_NOT_SYSTEM_APP; - } - if (pkgName.empty()) { LOGE("StopDeviceDiscovery error: Invalid para"); return DM_INVALID_VALUE; @@ -319,11 +231,6 @@ int32_t DeviceManagerImpl::AuthenticateDevice(const std::string &pkgName, int32_ std::shared_ptr callback) { LOGI("DeviceManager::AuthenticateDevice start , pkgName: %s", pkgName.c_str()); - if (!isSystemAppCalling()) { - LOGI("the caller is not a system app"); - return DM_NOT_SYSTEM_APP; - } - if (pkgName.empty()) { LOGE("AuthenticateDevice error: Invalid para"); return DM_INVALID_VALUE; @@ -356,10 +263,6 @@ int32_t DeviceManagerImpl::AuthenticateDevice(const std::string &pkgName, int32_ int32_t DeviceManagerImpl::UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId) { LOGI("DeviceManager::UnAuthenticateDevice start , pkgName: %s, deviceId: %s", pkgName.c_str(), deviceId.c_str()); - if (!isSystemAppCalling()) { - LOGI("the caller is not a system app"); - return DM_NOT_SYSTEM_APP; - } if (deviceId.empty()) { LOGE("UnAuthenticateDevice error: Invalid para"); @@ -417,10 +320,6 @@ int32_t DeviceManagerImpl::VerifyAuthentication(const std::string &pkgName, cons std::shared_ptr callback) { LOGI("DeviceManager::VerifyAuthentication start, pkgName: %s", pkgName.c_str()); - if (!isSystemAppCalling()) { - LOGI("the caller is not a system app"); - return DM_NOT_SYSTEM_APP; - } if (pkgName.empty()) { LOGE("VerifyAuthentication error: Invalid para"); return DM_INVALID_VALUE; diff --git a/services/devicemanagerservice/BUILD.gn b/services/devicemanagerservice/BUILD.gn index cde4b3193..12ddf9c64 100644 --- a/services/devicemanagerservice/BUILD.gn +++ b/services/devicemanagerservice/BUILD.gn @@ -49,6 +49,7 @@ if (defined(ohos_lite)) { "${common_path}/include", "${common_path}/include/ipc", "${common_path}/include/ipc/model", + "${utils_path}/include/permission/standard", "//base/security/deviceauth/interfaces/innerkits", "//third_party/json/include", "//base/account/os_account/interfaces/innerkits/osaccount/native/include", diff --git a/services/devicemanagerservice/include/device_manager_service.h b/services/devicemanagerservice/include/device_manager_service.h index aedfc875d..0a72b3c22 100644 --- a/services/devicemanagerservice/include/device_manager_service.h +++ b/services/devicemanagerservice/include/device_manager_service.h @@ -27,6 +27,7 @@ #include "dm_discovery_manager.h" #include "single_instance.h" #include "softbus_connector.h" +#include "permission_token.h" namespace OHOS { namespace DistributedHardware { @@ -60,6 +61,7 @@ private: std::shared_ptr listener_; std::shared_ptr abilityMgr_; std::shared_ptr hiChainConnector_; + std::shared_ptr permissionToken_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/src/device_manager_service.cpp b/services/devicemanagerservice/src/device_manager_service.cpp index 8a02d7265..7551044d3 100644 --- a/services/devicemanagerservice/src/device_manager_service.cpp +++ b/services/devicemanagerservice/src/device_manager_service.cpp @@ -44,10 +44,25 @@ DeviceManagerService::~DeviceManagerService() int32_t DeviceManagerService::Init() { + LOGI("Enter DeviceManagerService::isSystemAppCalling 111111"); if (intFlag_) { LOGE("Init failed, singleton cannot be initialized multiple times"); return DM_INT_MULTIPLE; } + + if (permissionToken_ == nullptr) { + permissionToken_ = std::make_shared(); + if (permissionToken_ == nullptr) { + LOGE("Init failed, permissionToken_ apply for failure"); + return DM_MAKE_SHARED_FAIL; + } + } + + if (!permissionToken_->isSystemAppCalling()) { + LOGI("the caller is not a system app"); + return DM_NOT_SYSTEM_APP; + } + if (softbusConnector_ == nullptr) { softbusConnector_ = std::make_shared(); if (softbusConnector_ == nullptr) { @@ -122,6 +137,10 @@ int32_t DeviceManagerService::Init() int32_t DeviceManagerService::GetTrustedDeviceList(const std::string &pkgName, const std::string &extra, std::vector &deviceList) { + if (!permissionToken_->isSystemAppCalling()) { + LOGI("the caller is not a system app"); + return DM_NOT_SYSTEM_APP; + } if (!intFlag_) { LOGE("GetTrustedDeviceList failed, singleton not init or init fail"); return DM_NOT_INIT; @@ -135,6 +154,10 @@ int32_t DeviceManagerService::GetTrustedDeviceList(const std::string &pkgName, c int32_t DeviceManagerService::GetLocalDeviceInfo(DmDeviceInfo &info) { + if (!permissionToken_->isSystemAppCalling()) { + LOGI("the caller is not a system app"); + return DM_NOT_SYSTEM_APP; + } if (!intFlag_) { LOGE("GetLocalDeviceInfo failed, singleton not init or init fail"); return DM_NOT_INIT; @@ -177,6 +200,10 @@ int32_t DeviceManagerService::GetUuidByNetworkId(const std::string &pkgName, con int32_t DeviceManagerService::StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo, const std::string &extra) { + if (!permissionToken_->isSystemAppCalling()) { + LOGI("the caller is not a system app"); + return DM_NOT_SYSTEM_APP; + } if (!intFlag_) { LOGE("StartDeviceDiscovery failed, singleton not init or init fail"); return DM_NOT_INIT; @@ -190,6 +217,10 @@ int32_t DeviceManagerService::StartDeviceDiscovery(const std::string &pkgName, c int32_t DeviceManagerService::StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId) { + if (!permissionToken_->isSystemAppCalling()) { + LOGI("the caller is not a system app"); + return DM_NOT_SYSTEM_APP; + } if (!intFlag_) { LOGE("StopDeviceDiscovery failed, singleton not init or init fail"); return DM_NOT_INIT; @@ -204,6 +235,10 @@ int32_t DeviceManagerService::StopDeviceDiscovery(const std::string &pkgName, ui int32_t DeviceManagerService::AuthenticateDevice(const std::string &pkgName, int32_t authType, const std::string &deviceId, const std::string &extra) { + if (!permissionToken_->isSystemAppCalling()) { + LOGI("the caller is not a system app"); + return DM_NOT_SYSTEM_APP; + } if (!intFlag_) { LOGE("AuthenticateDevice failed, singleton not init or init fail"); return DM_NOT_INIT; @@ -221,6 +256,10 @@ int32_t DeviceManagerService::AuthenticateDevice(const std::string &pkgName, int int32_t DeviceManagerService::UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId) { + if (!permissionToken_->isSystemAppCalling()) { + LOGI("the caller is not a system app"); + return DM_NOT_SYSTEM_APP; + } if (!intFlag_) { LOGE("UnAuthenticateDevice failed, singleton not init or init fail"); return DM_NOT_INIT; @@ -238,6 +277,10 @@ int32_t DeviceManagerService::UnAuthenticateDevice(const std::string &pkgName, c int32_t DeviceManagerService::VerifyAuthentication(const std::string &authParam) { + if (!permissionToken_->isSystemAppCalling()) { + LOGI("the caller is not a system app"); + return DM_NOT_SYSTEM_APP; + } if (!intFlag_) { LOGE("VerifyAuthentication failed, singleton not init or init fail"); return DM_NOT_INIT; diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 7080341e1..c85ead095 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -30,6 +30,7 @@ if (defined(ohos_lite)) { "${common_path}/include", "${common_path}/include/ipc", "${common_path}/include/ipc/model", + "include/permission/standard", ] } @@ -39,6 +40,7 @@ if (defined(ohos_lite)) { "src/dm_log.cpp", "src/dm_random.cpp", "src/ipc/standard/ipc_cmd_register.cpp", + "src/permission/standard/permission_token.cpp", ] public_configs = [ ":devicemanagerutils_config" ] @@ -49,12 +51,20 @@ if (defined(ohos_lite)) { "LOG_DOMAIN=0xD004100", ] - deps = [ "//third_party/mbedtls:mbedtls_shared" ] + deps = [ + "//third_party/mbedtls:mbedtls_shared", + "//foundation/aafwk/standard/interfaces/innerkits/want:want", + ] external_deps = [ "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "utils_base:utils", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "access_token:libaccesstoken_sdk", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", ] subsystem_name = "distributedhardware" diff --git a/utils/include/permission/lite/permission_token.h b/utils/include/permission/lite/permission_token.h new file mode 100644 index 000000000..0a8e9720d --- /dev/null +++ b/utils/include/permission/lite/permission_token.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2021 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 OHOS_DM_PERMISSION_TOKEN_H +#define OHOS_DM_PERMISSION_TOKEN_H + +namespace OHOS { +namespace DistributedHardware { +class PermissionToken { +public: + PermissionToken() = default; + virtual ~PermissionToken() = default; + +public: + bool isSystemAppCalling(void); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_PERMISSION_TOKEN_H diff --git a/utils/include/permission/standard/permission_token.h b/utils/include/permission/standard/permission_token.h new file mode 100644 index 000000000..0a8e9720d --- /dev/null +++ b/utils/include/permission/standard/permission_token.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2021 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 OHOS_DM_PERMISSION_TOKEN_H +#define OHOS_DM_PERMISSION_TOKEN_H + +namespace OHOS { +namespace DistributedHardware { +class PermissionToken { +public: + PermissionToken() = default; + virtual ~PermissionToken() = default; + +public: + bool isSystemAppCalling(void); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_PERMISSION_TOKEN_H diff --git a/utils/src/permission/lite/permission_token.cpp b/utils/src/permission/lite/permission_token.cpp new file mode 100644 index 000000000..47d77ab8e --- /dev/null +++ b/utils/src/permission/lite/permission_token.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2021 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. + */ + +#include "permission_token.h" + + +namespace OHOS { +namespace DistributedHardware { + +bool PermissionToken::isSystemAppCalling(void) +{ + return true; +} + +} // namespace DistributedHardware +} // namespace OHOS diff --git a/utils/src/permission/standard/permission_token.cpp b/utils/src/permission/standard/permission_token.cpp new file mode 100644 index 000000000..5fb4a6160 --- /dev/null +++ b/utils/src/permission/standard/permission_token.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2021 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. + */ + +#include "permission_token.h" + +#include "bundle_constants.h" +#include "bundle_info.h" +#include "bundle_mgr_client.h" +#include "bundle_mgr_interface.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" +#include "ipc_skeleton.h" +#include "access_token.h" +#include "hap_token_info.h" +#include "native_token_info.h" +#include "accesstoken_kit.h" +#include "dm_log.h" + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::Constants; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { +namespace DistributedHardware { +bool PermissionToken::isSystemAppCalling(void) +{ + LOGI("Enter DeviceManagerService::isSystemAppCalling 111111"); + AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID(); + if (tokenCaller == 0) { + LOGI("DeviceManagerService::tokenCaller == 0"); + return false; + } + LOGI("DeviceManagerService::tokenCaller ID == %d", tokenCaller); + + ATokenTypeEnum tokenTypeFlag = AccessTokenKit::GetTokenTypeFlag(tokenCaller); + if (tokenTypeFlag == ATokenTypeEnum::TOKEN_HAP) { + int32_t uid = IPCSkeleton::GetCallingUid(); + if (uid < 0) { + LOGI("app caller uid is: %d,", uid); + return false; + } + + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (systemAbilityManager == nullptr) { + LOGE("failed to get system ability mgr."); + return true; + } + sptr remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + if (remoteObject == nullptr) { + LOGE("failed to get bundle manager proxy."); + return true; + } + + LOGI("get bundle manager proxy success."); + sptr iBundleMgr = iface_cast(remoteObject); + if (iBundleMgr == nullptr) { + LOGI("iBundleMgr is nullptr, caller may be a process"); + return true; + } + LOGI("DeviceManagerService::tokenTypeFlag is hap process"); + return iBundleMgr->CheckIsSystemAppByUid(uid); + } else if (tokenTypeFlag == ATokenTypeEnum::TOKEN_NATIVE) { + LOGI("DeviceManagerService::tokenTypeFlag is native process"); + return true; + } else { + LOGI("DeviceManagerService::invalid tokenTypeFlag"); + return false; + } +} +} // namespace DistributedHardware +} // namespace OHOS -- Gitee From 7a60ea0dc763356744eccefaceab317903b0fdcc Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Wed, 23 Feb 2022 14:13:13 +0800 Subject: [PATCH 2/6] =?UTF-8?q?AccessToken=E6=9D=83=E9=99=90=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- interfaces/inner_kits/native_cpp/include/device_manager_impl.h | 1 - interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp | 3 --- utils/src/permission/lite/permission_token.cpp | 3 --- 3 files changed, 7 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h index 5b439ae65..1e38d7dbd 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -64,7 +64,6 @@ private: DeviceManagerImpl(DeviceManagerImpl &&) = delete; DeviceManagerImpl &operator=(DeviceManagerImpl &&) = delete; - private: std::shared_ptr ipcClientProxy_ = std::make_shared(std::make_shared()); diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index 1d82859b4..452c1704a 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -14,7 +14,6 @@ */ #include "device_manager_impl.h" - #include "device_manager_notify.h" #include "dm_constants.h" #include "dm_log.h" @@ -35,10 +34,8 @@ #include "ipc_verify_authenticate_req.h" #include "securec.h" - namespace OHOS { namespace DistributedHardware { - DeviceManagerImpl &DeviceManagerImpl::GetInstance() { static DeviceManagerImpl instance; diff --git a/utils/src/permission/lite/permission_token.cpp b/utils/src/permission/lite/permission_token.cpp index 47d77ab8e..f540bcf63 100644 --- a/utils/src/permission/lite/permission_token.cpp +++ b/utils/src/permission/lite/permission_token.cpp @@ -15,14 +15,11 @@ #include "permission_token.h" - namespace OHOS { namespace DistributedHardware { - bool PermissionToken::isSystemAppCalling(void) { return true; } - } // namespace DistributedHardware } // namespace OHOS -- Gitee From 8c9f56399d2e9d3072ce1856cf6cfefe510cc1d1 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Wed, 23 Feb 2022 14:14:20 +0800 Subject: [PATCH 3/6] =?UTF-8?q?AccessToken=E6=9D=83=E9=99=90=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- interfaces/inner_kits/native_cpp/BUILD.gn | 1 - 1 file changed, 1 deletion(-) diff --git a/interfaces/inner_kits/native_cpp/BUILD.gn b/interfaces/inner_kits/native_cpp/BUILD.gn index 353ca9f45..a842f4b22 100644 --- a/interfaces/inner_kits/native_cpp/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/BUILD.gn @@ -63,7 +63,6 @@ if (defined(ohos_lite)) { "utils_base:utils", ] - subsystem_name = "distributedhardware" part_name = "device_manager_base" -- Gitee From d72af995a6b4d810ce0919d93e492ea5bcc40560 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Wed, 23 Feb 2022 16:28:23 +0800 Subject: [PATCH 4/6] =?UTF-8?q?AccessToken=E6=9D=83=E9=99=90=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- utils/BUILD.gn | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/utils/BUILD.gn b/utils/BUILD.gn index c85ead095..274b6e46b 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -51,20 +51,20 @@ if (defined(ohos_lite)) { "LOG_DOMAIN=0xD004100", ] - deps = [ - "//third_party/mbedtls:mbedtls_shared", + deps = [ "//foundation/aafwk/standard/interfaces/innerkits/want:want", + "//third_party/mbedtls:mbedtls_shared", ] external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "utils_base:utils", + "access_token:libaccesstoken_sdk", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "access_token:libaccesstoken_sdk", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", + "utils_base:utils", ] subsystem_name = "distributedhardware" -- Gitee From b2c30ae17d93c01a148c1ca1f2fb012ab7b183dc Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Thu, 24 Feb 2022 11:46:51 +0800 Subject: [PATCH 5/6] =?UTF-8?q?AccessToken=E6=9D=83=E9=99=90=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=20codex?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- common/include/dm_constants.h | 2 +- .../include/device_manager_service.h | 2 - .../src/device_manager_service.cpp | 58 ++++++++----------- utils/BUILD.gn | 2 +- ...ermission_token.h => permission_manager.h} | 12 ++-- ...ermission_token.h => permission_manager.h} | 12 ++-- ...ssion_token.cpp => permission_manager.cpp} | 8 ++- ...ssion_token.cpp => permission_manager.cpp} | 20 ++++--- 8 files changed, 55 insertions(+), 61 deletions(-) rename utils/include/permission/lite/{permission_token.h => permission_manager.h} (80%) rename utils/include/permission/standard/{permission_token.h => permission_manager.h} (80%) rename utils/src/permission/lite/{permission_token.cpp => permission_manager.cpp} (80%) rename utils/src/permission/standard/{permission_token.cpp => permission_manager.cpp} (82%) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 1206f3909..184e2e1fc 100644 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -52,7 +52,7 @@ enum { DM_UNINIT_FAILED, DM_POINT_NULL, DM_INPUT_PARA_EMPTY, - DM_NOT_SYSTEM_APP, + DM_NO_PERMISSION, DM_INVALID_VALUE, DM_FLATTEN_OBJECT, DM_MALLOC_ERROR, diff --git a/services/devicemanagerservice/include/device_manager_service.h b/services/devicemanagerservice/include/device_manager_service.h index 0a72b3c22..aedfc875d 100644 --- a/services/devicemanagerservice/include/device_manager_service.h +++ b/services/devicemanagerservice/include/device_manager_service.h @@ -27,7 +27,6 @@ #include "dm_discovery_manager.h" #include "single_instance.h" #include "softbus_connector.h" -#include "permission_token.h" namespace OHOS { namespace DistributedHardware { @@ -61,7 +60,6 @@ private: std::shared_ptr listener_; std::shared_ptr abilityMgr_; std::shared_ptr hiChainConnector_; - std::shared_ptr permissionToken_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/src/device_manager_service.cpp b/services/devicemanagerservice/src/device_manager_service.cpp index 7551044d3..7c4ae6e50 100644 --- a/services/devicemanagerservice/src/device_manager_service.cpp +++ b/services/devicemanagerservice/src/device_manager_service.cpp @@ -24,6 +24,7 @@ #include "dm_device_info_manager.h" #include "dm_log.h" #include "multiple_user_connector.h" +#include "permission_manager.h" using namespace OHOS::EventFwk; @@ -44,23 +45,14 @@ DeviceManagerService::~DeviceManagerService() int32_t DeviceManagerService::Init() { - LOGI("Enter DeviceManagerService::isSystemAppCalling 111111"); if (intFlag_) { LOGE("Init failed, singleton cannot be initialized multiple times"); return DM_INT_MULTIPLE; } - if (permissionToken_ == nullptr) { - permissionToken_ = std::make_shared(); - if (permissionToken_ == nullptr) { - LOGE("Init failed, permissionToken_ apply for failure"); - return DM_MAKE_SHARED_FAIL; - } - } - - if (!permissionToken_->isSystemAppCalling()) { - LOGI("the caller is not a system app"); - return DM_NOT_SYSTEM_APP; + if (!PermissionManager::GetInstance().checkPermission()) { + LOGI("The caller does not have permission to call"); + return DM_NO_PERMISSION; } if (softbusConnector_ == nullptr) { @@ -137,9 +129,9 @@ int32_t DeviceManagerService::Init() int32_t DeviceManagerService::GetTrustedDeviceList(const std::string &pkgName, const std::string &extra, std::vector &deviceList) { - if (!permissionToken_->isSystemAppCalling()) { - LOGI("the caller is not a system app"); - return DM_NOT_SYSTEM_APP; + if (!PermissionManager::GetInstance().checkPermission()) { + LOGI("The caller does not have permission to call"); + return DM_NO_PERMISSION; } if (!intFlag_) { LOGE("GetTrustedDeviceList failed, singleton not init or init fail"); @@ -154,9 +146,9 @@ int32_t DeviceManagerService::GetTrustedDeviceList(const std::string &pkgName, c int32_t DeviceManagerService::GetLocalDeviceInfo(DmDeviceInfo &info) { - if (!permissionToken_->isSystemAppCalling()) { - LOGI("the caller is not a system app"); - return DM_NOT_SYSTEM_APP; + if (!PermissionManager::GetInstance().checkPermission()) { + LOGI("The caller does not have permission to call"); + return DM_NO_PERMISSION; } if (!intFlag_) { LOGE("GetLocalDeviceInfo failed, singleton not init or init fail"); @@ -200,9 +192,9 @@ int32_t DeviceManagerService::GetUuidByNetworkId(const std::string &pkgName, con int32_t DeviceManagerService::StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo, const std::string &extra) { - if (!permissionToken_->isSystemAppCalling()) { - LOGI("the caller is not a system app"); - return DM_NOT_SYSTEM_APP; + if (!PermissionManager::GetInstance().checkPermission()) { + LOGI("The caller does not have permission to call"); + return DM_NO_PERMISSION; } if (!intFlag_) { LOGE("StartDeviceDiscovery failed, singleton not init or init fail"); @@ -217,9 +209,9 @@ int32_t DeviceManagerService::StartDeviceDiscovery(const std::string &pkgName, c int32_t DeviceManagerService::StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId) { - if (!permissionToken_->isSystemAppCalling()) { - LOGI("the caller is not a system app"); - return DM_NOT_SYSTEM_APP; + if (!PermissionManager::GetInstance().checkPermission()) { + LOGI("The caller does not have permission to call"); + return DM_NO_PERMISSION; } if (!intFlag_) { LOGE("StopDeviceDiscovery failed, singleton not init or init fail"); @@ -235,9 +227,9 @@ int32_t DeviceManagerService::StopDeviceDiscovery(const std::string &pkgName, ui int32_t DeviceManagerService::AuthenticateDevice(const std::string &pkgName, int32_t authType, const std::string &deviceId, const std::string &extra) { - if (!permissionToken_->isSystemAppCalling()) { - LOGI("the caller is not a system app"); - return DM_NOT_SYSTEM_APP; + if (!PermissionManager::GetInstance().checkPermission()) { + LOGI("The caller does not have permission to call"); + return DM_NO_PERMISSION; } if (!intFlag_) { LOGE("AuthenticateDevice failed, singleton not init or init fail"); @@ -256,9 +248,9 @@ int32_t DeviceManagerService::AuthenticateDevice(const std::string &pkgName, int int32_t DeviceManagerService::UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId) { - if (!permissionToken_->isSystemAppCalling()) { - LOGI("the caller is not a system app"); - return DM_NOT_SYSTEM_APP; + if (!PermissionManager::GetInstance().checkPermission()) { + LOGI("The caller does not have permission to call"); + return DM_NO_PERMISSION; } if (!intFlag_) { LOGE("UnAuthenticateDevice failed, singleton not init or init fail"); @@ -277,9 +269,9 @@ int32_t DeviceManagerService::UnAuthenticateDevice(const std::string &pkgName, c int32_t DeviceManagerService::VerifyAuthentication(const std::string &authParam) { - if (!permissionToken_->isSystemAppCalling()) { - LOGI("the caller is not a system app"); - return DM_NOT_SYSTEM_APP; + if (!PermissionManager::GetInstance().checkPermission()) { + LOGI("The caller does not have permission to call"); + return DM_NO_PERMISSION; } if (!intFlag_) { LOGE("VerifyAuthentication failed, singleton not init or init fail"); diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 274b6e46b..ed13a0b4e 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -40,7 +40,7 @@ if (defined(ohos_lite)) { "src/dm_log.cpp", "src/dm_random.cpp", "src/ipc/standard/ipc_cmd_register.cpp", - "src/permission/standard/permission_token.cpp", + "src/permission/standard/permission_manager.cpp", ] public_configs = [ ":devicemanagerutils_config" ] diff --git a/utils/include/permission/lite/permission_token.h b/utils/include/permission/lite/permission_manager.h similarity index 80% rename from utils/include/permission/lite/permission_token.h rename to utils/include/permission/lite/permission_manager.h index 0a8e9720d..3ae6074ba 100644 --- a/utils/include/permission/lite/permission_token.h +++ b/utils/include/permission/lite/permission_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 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 @@ -16,15 +16,15 @@ #ifndef OHOS_DM_PERMISSION_TOKEN_H #define OHOS_DM_PERMISSION_TOKEN_H +#include "single_instance.h" + namespace OHOS { namespace DistributedHardware { -class PermissionToken { -public: - PermissionToken() = default; - virtual ~PermissionToken() = default; +class PermissionManager { + DECLARE_SINGLE_INSTANCE(PermissionManager); public: - bool isSystemAppCalling(void); + bool checkPermission(void); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/include/permission/standard/permission_token.h b/utils/include/permission/standard/permission_manager.h similarity index 80% rename from utils/include/permission/standard/permission_token.h rename to utils/include/permission/standard/permission_manager.h index 0a8e9720d..3ae6074ba 100644 --- a/utils/include/permission/standard/permission_token.h +++ b/utils/include/permission/standard/permission_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 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 @@ -16,15 +16,15 @@ #ifndef OHOS_DM_PERMISSION_TOKEN_H #define OHOS_DM_PERMISSION_TOKEN_H +#include "single_instance.h" + namespace OHOS { namespace DistributedHardware { -class PermissionToken { -public: - PermissionToken() = default; - virtual ~PermissionToken() = default; +class PermissionManager { + DECLARE_SINGLE_INSTANCE(PermissionManager); public: - bool isSystemAppCalling(void); + bool checkPermission(void); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/src/permission/lite/permission_token.cpp b/utils/src/permission/lite/permission_manager.cpp similarity index 80% rename from utils/src/permission/lite/permission_token.cpp rename to utils/src/permission/lite/permission_manager.cpp index f540bcf63..0d76c792a 100644 --- a/utils/src/permission/lite/permission_token.cpp +++ b/utils/src/permission/lite/permission_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 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 @@ -13,11 +13,13 @@ * limitations under the License. */ -#include "permission_token.h" +#include "permission_manager.h" namespace OHOS { namespace DistributedHardware { -bool PermissionToken::isSystemAppCalling(void) +IMPLEMENT_SINGLE_INSTANCE(PermissionManager); + +bool PermissionManager::checkPermission(void) { return true; } diff --git a/utils/src/permission/standard/permission_token.cpp b/utils/src/permission/standard/permission_manager.cpp similarity index 82% rename from utils/src/permission/standard/permission_token.cpp rename to utils/src/permission/standard/permission_manager.cpp index 5fb4a6160..4f73444f6 100644 --- a/utils/src/permission/standard/permission_token.cpp +++ b/utils/src/permission/standard/permission_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 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 @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "permission_token.h" +#include "permission_manager.h" #include "bundle_constants.h" #include "bundle_info.h" @@ -35,15 +35,17 @@ using namespace OHOS::Security::AccessToken; namespace OHOS { namespace DistributedHardware { -bool PermissionToken::isSystemAppCalling(void) +IMPLEMENT_SINGLE_INSTANCE(PermissionManager); + +bool PermissionManager::checkPermission(void) { - LOGI("Enter DeviceManagerService::isSystemAppCalling 111111"); + LOGI("Enter PermissionManager::checkPermission"); AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID(); if (tokenCaller == 0) { - LOGI("DeviceManagerService::tokenCaller == 0"); + LOGI("PermissionManager::tokenCaller == 0"); return false; } - LOGI("DeviceManagerService::tokenCaller ID == %d", tokenCaller); + LOGI("PermissionManager::tokenCaller ID == %d", tokenCaller); ATokenTypeEnum tokenTypeFlag = AccessTokenKit::GetTokenTypeFlag(tokenCaller); if (tokenTypeFlag == ATokenTypeEnum::TOKEN_HAP) { @@ -71,13 +73,13 @@ bool PermissionToken::isSystemAppCalling(void) LOGI("iBundleMgr is nullptr, caller may be a process"); return true; } - LOGI("DeviceManagerService::tokenTypeFlag is hap process"); + LOGI("PermissionManager::tokenTypeFlag is hap process"); return iBundleMgr->CheckIsSystemAppByUid(uid); } else if (tokenTypeFlag == ATokenTypeEnum::TOKEN_NATIVE) { - LOGI("DeviceManagerService::tokenTypeFlag is native process"); + LOGI("PermissionManager::tokenTypeFlag is native process"); return true; } else { - LOGI("DeviceManagerService::invalid tokenTypeFlag"); + LOGI("PermissionManager::invalid tokenTypeFlag"); return false; } } -- Gitee From 4f2f683811bb1df2ab7f0d9421a1f3fa26ff8357 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Thu, 24 Feb 2022 16:10:21 +0800 Subject: [PATCH 6/6] =?UTF-8?q?AccessToken=E6=9D=83=E9=99=90=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- .../src/device_manager_service.cpp | 16 ++++++++-------- .../include/permission/lite/permission_manager.h | 8 ++++---- .../permission/standard/permission_manager.h | 8 ++++---- utils/src/permission/lite/permission_manager.cpp | 2 +- .../permission/standard/permission_manager.cpp | 4 ++-- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/services/devicemanagerservice/src/device_manager_service.cpp b/services/devicemanagerservice/src/device_manager_service.cpp index 7c4ae6e50..fe343b583 100644 --- a/services/devicemanagerservice/src/device_manager_service.cpp +++ b/services/devicemanagerservice/src/device_manager_service.cpp @@ -50,7 +50,7 @@ int32_t DeviceManagerService::Init() return DM_INT_MULTIPLE; } - if (!PermissionManager::GetInstance().checkPermission()) { + if (!PermissionManager::GetInstance().CheckPermission()) { LOGI("The caller does not have permission to call"); return DM_NO_PERMISSION; } @@ -129,7 +129,7 @@ int32_t DeviceManagerService::Init() int32_t DeviceManagerService::GetTrustedDeviceList(const std::string &pkgName, const std::string &extra, std::vector &deviceList) { - if (!PermissionManager::GetInstance().checkPermission()) { + if (!PermissionManager::GetInstance().CheckPermission()) { LOGI("The caller does not have permission to call"); return DM_NO_PERMISSION; } @@ -146,7 +146,7 @@ int32_t DeviceManagerService::GetTrustedDeviceList(const std::string &pkgName, c int32_t DeviceManagerService::GetLocalDeviceInfo(DmDeviceInfo &info) { - if (!PermissionManager::GetInstance().checkPermission()) { + if (!PermissionManager::GetInstance().CheckPermission()) { LOGI("The caller does not have permission to call"); return DM_NO_PERMISSION; } @@ -192,7 +192,7 @@ int32_t DeviceManagerService::GetUuidByNetworkId(const std::string &pkgName, con int32_t DeviceManagerService::StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo, const std::string &extra) { - if (!PermissionManager::GetInstance().checkPermission()) { + if (!PermissionManager::GetInstance().CheckPermission()) { LOGI("The caller does not have permission to call"); return DM_NO_PERMISSION; } @@ -209,7 +209,7 @@ int32_t DeviceManagerService::StartDeviceDiscovery(const std::string &pkgName, c int32_t DeviceManagerService::StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId) { - if (!PermissionManager::GetInstance().checkPermission()) { + if (!PermissionManager::GetInstance().CheckPermission()) { LOGI("The caller does not have permission to call"); return DM_NO_PERMISSION; } @@ -227,7 +227,7 @@ int32_t DeviceManagerService::StopDeviceDiscovery(const std::string &pkgName, ui int32_t DeviceManagerService::AuthenticateDevice(const std::string &pkgName, int32_t authType, const std::string &deviceId, const std::string &extra) { - if (!PermissionManager::GetInstance().checkPermission()) { + if (!PermissionManager::GetInstance().CheckPermission()) { LOGI("The caller does not have permission to call"); return DM_NO_PERMISSION; } @@ -248,7 +248,7 @@ int32_t DeviceManagerService::AuthenticateDevice(const std::string &pkgName, int int32_t DeviceManagerService::UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId) { - if (!PermissionManager::GetInstance().checkPermission()) { + if (!PermissionManager::GetInstance().CheckPermission()) { LOGI("The caller does not have permission to call"); return DM_NO_PERMISSION; } @@ -269,7 +269,7 @@ int32_t DeviceManagerService::UnAuthenticateDevice(const std::string &pkgName, c int32_t DeviceManagerService::VerifyAuthentication(const std::string &authParam) { - if (!PermissionManager::GetInstance().checkPermission()) { + if (!PermissionManager::GetInstance().CheckPermission()) { LOGI("The caller does not have permission to call"); return DM_NO_PERMISSION; } diff --git a/utils/include/permission/lite/permission_manager.h b/utils/include/permission/lite/permission_manager.h index 3ae6074ba..fa0b93756 100644 --- a/utils/include/permission/lite/permission_manager.h +++ b/utils/include/permission/lite/permission_manager.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_DM_PERMISSION_TOKEN_H -#define OHOS_DM_PERMISSION_TOKEN_H +#ifndef OHOS_DM_PERMISSION_MANAGER_H +#define OHOS_DM_PERMISSION_MANAGER_H #include "single_instance.h" @@ -24,8 +24,8 @@ class PermissionManager { DECLARE_SINGLE_INSTANCE(PermissionManager); public: - bool checkPermission(void); + bool CheckPermission(void); }; } // namespace DistributedHardware } // namespace OHOS -#endif // OHOS_DM_PERMISSION_TOKEN_H +#endif // OHOS_DM_PERMISSION_MANAGER_H diff --git a/utils/include/permission/standard/permission_manager.h b/utils/include/permission/standard/permission_manager.h index 3ae6074ba..fa0b93756 100644 --- a/utils/include/permission/standard/permission_manager.h +++ b/utils/include/permission/standard/permission_manager.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_DM_PERMISSION_TOKEN_H -#define OHOS_DM_PERMISSION_TOKEN_H +#ifndef OHOS_DM_PERMISSION_MANAGER_H +#define OHOS_DM_PERMISSION_MANAGER_H #include "single_instance.h" @@ -24,8 +24,8 @@ class PermissionManager { DECLARE_SINGLE_INSTANCE(PermissionManager); public: - bool checkPermission(void); + bool CheckPermission(void); }; } // namespace DistributedHardware } // namespace OHOS -#endif // OHOS_DM_PERMISSION_TOKEN_H +#endif // OHOS_DM_PERMISSION_MANAGER_H diff --git a/utils/src/permission/lite/permission_manager.cpp b/utils/src/permission/lite/permission_manager.cpp index 0d76c792a..356a13131 100644 --- a/utils/src/permission/lite/permission_manager.cpp +++ b/utils/src/permission/lite/permission_manager.cpp @@ -19,7 +19,7 @@ namespace OHOS { namespace DistributedHardware { IMPLEMENT_SINGLE_INSTANCE(PermissionManager); -bool PermissionManager::checkPermission(void) +bool PermissionManager::CheckPermission(void) { return true; } diff --git a/utils/src/permission/standard/permission_manager.cpp b/utils/src/permission/standard/permission_manager.cpp index 4f73444f6..82a0ad7af 100644 --- a/utils/src/permission/standard/permission_manager.cpp +++ b/utils/src/permission/standard/permission_manager.cpp @@ -37,9 +37,9 @@ namespace OHOS { namespace DistributedHardware { IMPLEMENT_SINGLE_INSTANCE(PermissionManager); -bool PermissionManager::checkPermission(void) +bool PermissionManager::CheckPermission(void) { - LOGI("Enter PermissionManager::checkPermission"); + LOGI("Enter PermissionManager::CheckPermission"); AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID(); if (tokenCaller == 0) { LOGI("PermissionManager::tokenCaller == 0"); -- Gitee