From 4c8c0bd85f68210ce36dd2ea0e4e6893687c9fec Mon Sep 17 00:00:00 2001 From: caochao Date: Mon, 21 Feb 2022 18:43:17 -0800 Subject: [PATCH 01/11] The sane process cannot ipc communication rectification Signed-off-by: cao_liu_chao --- .../devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp b/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp index dc2d74a92..ff7e3a148 100644 --- a/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp +++ b/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp @@ -104,9 +104,9 @@ int32_t IpcServerStub::SendCmd(int32_t cmdCode, std::shared_ptr req, std int32_t ret = IpcCmdRegister::GetInstance().OnIpcCmd(cmdCode, data, reply); if (ret == DM_IPC_NOT_REGISTER_FUNC) { LOGW("unsupport code: %d", cmdCode); - return IpcCmdRegister::GetInstance().ReadResponse(cmdCode, reply, rsp); + return IPCObjectStub::OnRemoteRequest(cmdCode, data, reply, option); } - return ret; + return IpcCmdRegister::GetInstance().ReadResponse(cmdCode, reply, rsp); } ServiceRunningState IpcServerStub::QueryServiceState() const -- Gitee From ec74a38020185e556ae057df46591cc65e4f81bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=92=B2=E8=BE=89?= Date: Tue, 22 Feb 2022 02:59:23 +0000 Subject: [PATCH 02/11] =?UTF-8?q?=E6=9B=B4=E6=96=B0readme=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: puhui --- README_zh.md | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/README_zh.md b/README_zh.md index ad0f988a2..5df737b47 100644 --- a/README_zh.md +++ b/README_zh.md @@ -103,29 +103,19 @@ foundation/distributedhardware/devicemanager | release(): void; | 释放DeviceManager实例 | +- 系统能力接口: -- 开放能力接口: + 提供可信设备列表获取、可信设备状态监听、周边设备发现、设备认证等相关接口,该部分作为系统能力接口,仅供系统应用调用。 - 提供可信设备列表获取、可信设备状态监听等接口能力,所有应用均可进行接口调用。 + 开始设备发现、停止发现设备接口要配对使用,使用同一个subscribeId。 -| 原型 | 描述 | -| ------- | ---------- | +| 原型 | 描述 | +| ------------------------------------------------------------ | -------------------- | | getTrustedDeviceListSync(): Array; | 获取信任设备列表 | | on(type: 'deviceStateChange', callback: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void; | 设备状态变更回调 | | off(type: 'deviceStateChange', callback?: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void; | 取消设备状态变更回调 | | on(type: 'serviceDie', callback: () => void): void; | 服务错误回调 | | off(type: 'serviceDie', callback?: () => void): void; | 取消服务错误回调 | - - - -- 系统能力接口: - - 提供周边设备发现、设备认证等相关接口,该部分作为系统能力接口,仅供系统应用调用。 - - 开始设备发现、停止发现设备接口要配对使用,使用同一个subscribeId。 - -| 原型 | 描述 | -| ------------------------------------------------------------ | -------------------- | | startDeviceDiscovery(subscribeInfo: SubscribeInfo): void; | 开始设备发现 | | stopDeviceDiscovery(subscribeId: number): void; | 停止发现设备 | | authenticateDevice(deviceInfo: DeviceInfo, authparam: AuthParam, callback: AsyncCallback<{deviceId: string, pinTone ?: number}>): void; | 设备认证接口 | @@ -153,6 +143,9 @@ dmClass.off('deviceStateChange') // 查询可信设备列表 var array = dmClass.getTrustedDeviceListSync(); +// 获取本地设备信息 +var localDeviceInfo = dmClass.getLocalDeviceInfoSync(); + // 开始设备发现(发现周边不可信设备) var subscribeId = 0; dmClass.on('deviceFound', (data) => { @@ -187,16 +180,15 @@ var deviceInfo ={ deviceType: 0 }; let extraInfo = { - "targetPkgName": 'xxxxxxxx', // FA流转目标设备包名 + "appIcon": new Uint8Array(), // app图标,可选参数,可不填 + "appThumbnail": new Uint8Array(), // app缩略图,可选参数,可不填 "appName": "xxxxxxxx", // 对端设备应用名称 "appDescription": "xxxxxxxx", // app描述 "business": '0', - "displayOwner": 0 + "displayOwner": 0, } let authParam = { "authType": 1, - "appIcon": new Uint8Array(), // app图标,可选参数,可不填 - "appThumbnail": new Uint8Array(), // app缩略图,可选参数,可不填 "extraInfo": extraInfo } dmClass.authenticateDevice(this.deviceInfo, authParam, (err, data) => { @@ -209,6 +201,9 @@ dmClass.authenticateDevice(this.deviceInfo, authParam, (err, data) => { console.info(TAG + "authenticateDevice result:" + JSON.stringify(data)); token = data.pinToken; }); + +// 设备取消认证 +dmClass.unAuthenticateDevice(this.deviceInfo); ``` ## 系统弹框FA @@ -239,5 +234,4 @@ dmClass.authenticateDevice(this.deviceInfo, authParam, (err, data) => { [**interface_sdk-js**](https://gitee.com/openharmony/interface_sdk-js/) [**applications_hap**](https://gitee.com/openharmony/applications_hap) -**device_manager** - +**device_manager** \ No newline at end of file -- Gitee From 80ebdb83d9530fde1eec5e29197bfe7563db2d55 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Wed, 23 Feb 2022 11:53:36 +0800 Subject: [PATCH 03/11] =?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 04/11] =?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 05/11] =?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 06/11] =?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 07/11] =?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 08/11] =?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 From aeb4aa24799346bc98d43b9e2872eab33aa1b276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cyour?= Date: Thu, 24 Feb 2022 19:04:14 -0800 Subject: [PATCH 09/11] device_ready_status bug Signed-off-by: pang-wenbin2 --- ext/profile/include/device_profile_adapter.h | 3 ++- ext/profile/src/device_profile_adapter.cpp | 4 ++-- .../src/devicestate/dm_device_state_manager.cpp | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ext/profile/include/device_profile_adapter.h b/ext/profile/include/device_profile_adapter.h index 3703a619a..5425bc1de 100644 --- a/ext/profile/include/device_profile_adapter.h +++ b/ext/profile/include/device_profile_adapter.h @@ -24,7 +24,8 @@ namespace OHOS { namespace DistributedHardware { -class DeviceProfileAdapter : public IProfileAdapter, public IProfileConnectorCallback { +class DeviceProfileAdapter : public IProfileAdapter, public IProfileConnectorCallback, + public std::enable_shared_from_this { public: DeviceProfileAdapter(); ~DeviceProfileAdapter(); diff --git a/ext/profile/src/device_profile_adapter.cpp b/ext/profile/src/device_profile_adapter.cpp index 5d6165a01..b036406eb 100644 --- a/ext/profile/src/device_profile_adapter.cpp +++ b/ext/profile/src/device_profile_adapter.cpp @@ -36,13 +36,13 @@ int32_t DeviceProfileAdapter::RegisterProfileListener(const std::string &pkgName { LOGI("DeviceProfileAdapter::RegisterProfileListener"); deviceProfileAdapterCallback_ = callback; - profileConnector_->RegisterProfileCallback(pkgName, deviceId, std::shared_ptr(this)); + profileConnector_->RegisterProfileCallback(pkgName, deviceId, shared_from_this()); return DM_OK; } int32_t DeviceProfileAdapter::UnRegisterProfileListener(const std::string &pkgName) { - LOGI("DeviceProfileAdapter::RegisterProfileListener"); + LOGI("DeviceProfileAdapter::UnRegisterProfileListener"); deviceProfileAdapterCallback_ = nullptr; profileConnector_->UnRegisterProfileCallback(pkgName); return DM_OK; diff --git a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp index 98ba3c7f2..56c0d9e6a 100644 --- a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp +++ b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp @@ -70,6 +70,7 @@ void DmDeviceStateManager::OnDeviceOnline(const std::string &pkgName, const DmDe remoteDeviceInfos_[uuid] = saveInfo; LOGI("RegisterProfileListener in, deviceId = %s, deviceUdid = %s, uuid = %s", info.deviceId, deviceUdid.c_str(), uuid.c_str()); + profileAdapter->RegisterProfileListener(pkgName, deviceUdid, shared_from_this()); LOGI("RegisterProfileListener out"); } } @@ -87,6 +88,7 @@ void DmDeviceStateManager::OnDeviceOffline(const std::string &pkgName, const DmD if (profileAdapter == nullptr) { LOGE("OnDeviceOffline profile adapter is null"); } else { + profileAdapter->UnRegisterProfileListener(pkgName); std::string uuid; SoftbusConnector::GetUuidByNetworkId(info.deviceId, uuid); auto iter = remoteDeviceInfos_.find(std::string(info.deviceId)); -- Gitee From 8a40754f57a321ed5465c81b0d5d37690376c9f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cyour?= Date: Thu, 24 Feb 2022 19:38:30 -0800 Subject: [PATCH 10/11] modify code_regular Signed-off-by: pang-wenbin2 --- .../src/devicestate/dm_device_state_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp index 56c0d9e6a..696a84b67 100644 --- a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp +++ b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp @@ -70,7 +70,7 @@ void DmDeviceStateManager::OnDeviceOnline(const std::string &pkgName, const DmDe remoteDeviceInfos_[uuid] = saveInfo; LOGI("RegisterProfileListener in, deviceId = %s, deviceUdid = %s, uuid = %s", info.deviceId, deviceUdid.c_str(), uuid.c_str()); - profileAdapter->RegisterProfileListener(pkgName, deviceUdid, shared_from_this()); + profileAdapter->RegisterProfileListener(pkgName, deviceUdid, shared_from_this()); LOGI("RegisterProfileListener out"); } } @@ -88,7 +88,7 @@ void DmDeviceStateManager::OnDeviceOffline(const std::string &pkgName, const DmD if (profileAdapter == nullptr) { LOGE("OnDeviceOffline profile adapter is null"); } else { - profileAdapter->UnRegisterProfileListener(pkgName); + profileAdapter->UnRegisterProfileListener(pkgName); std::string uuid; SoftbusConnector::GetUuidByNetworkId(info.deviceId, uuid); auto iter = remoteDeviceInfos_.find(std::string(info.deviceId)); -- Gitee From 2785b1efdfa703248354d80e336013e407390e8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cyour?= Date: Thu, 24 Feb 2022 19:53:41 -0800 Subject: [PATCH 11/11] modify code_regular_2 Signed-off-by: pang-wenbin2 --- .../src/devicestate/dm_device_state_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp index 696a84b67..3750ae545 100644 --- a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp +++ b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp @@ -88,7 +88,7 @@ void DmDeviceStateManager::OnDeviceOffline(const std::string &pkgName, const DmD if (profileAdapter == nullptr) { LOGE("OnDeviceOffline profile adapter is null"); } else { - profileAdapter->UnRegisterProfileListener(pkgName); + profileAdapter->UnRegisterProfileListener(pkgName); std::string uuid; SoftbusConnector::GetUuidByNetworkId(info.deviceId, uuid); auto iter = remoteDeviceInfos_.find(std::string(info.deviceId)); -- Gitee