From 17010e7b08dcc1ca55a543222becb8aed6bee9a6 Mon Sep 17 00:00:00 2001 From: yangwei_814916 Date: Tue, 25 Jun 2024 09:48:13 +0800 Subject: [PATCH 1/4] =?UTF-8?q?630=E5=AE=89=E5=85=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangwei_814916 --- .../device_manager_ipc_interface_code.h | 2 + .../ipc/model/ipc_check_access_control.h | 53 +++++++++ .../src/deviceprofile_connector.cpp | 2 +- .../native_cpp/include/device_manager.h | 2 + .../native_cpp/include/device_manager_impl.h | 2 + .../native_cpp/include/dm_device_info.h | 13 +++ .../native_cpp/src/device_manager_impl.cpp | 40 +++++++ .../src/ipc/lite/ipc_cmd_parser.cpp | 71 +++++++++++ .../src/ipc/standard/ipc_cmd_parser.cpp | 71 +++++++++++ .../devicestate/dm_device_state_manager.h | 1 + .../devicestate/dm_device_state_manager.cpp | 45 ++++--- .../service/include/device_manager_service.h | 3 + .../include/ipc/standard/ipc_server_stub.h | 2 - .../permission/lite/permission_manager.h | 2 + .../permission/standard/permission_manager.h | 3 +- .../service/src/device_manager_service.cpp | 32 ++++- .../src/device_manager_service_listener.cpp | 110 ++++++++++++------ .../service/src/ipc/lite/ipc_cmd_parser.cpp | 42 +++++++ .../src/ipc/standard/ipc_cmd_parser.cpp | 42 +++++++ .../src/ipc/standard/ipc_server_stub.cpp | 10 -- .../permission/lite/permission_manager.cpp | 11 ++ .../standard/permission_manager.cpp | 32 +++-- 22 files changed, 512 insertions(+), 79 deletions(-) create mode 100644 common/include/ipc/model/ipc_check_access_control.h diff --git a/common/include/device_manager_ipc_interface_code.h b/common/include/device_manager_ipc_interface_code.h index d03176ae7..7e9234d10 100644 --- a/common/include/device_manager_ipc_interface_code.h +++ b/common/include/device_manager_ipc_interface_code.h @@ -88,6 +88,8 @@ enum DMIpcCmdInterfaceCode { IS_SAME_ACCOUNT, CHECK_API_PERMISSION, CHECK_RELATED_DEVICE, + CHECK_ACCESS_CONTROL, + CHECK_SAME_ACCOUNT, // Add ipc msg here IPC_MSG_BUTT }; diff --git a/common/include/ipc/model/ipc_check_access_control.h b/common/include/ipc/model/ipc_check_access_control.h new file mode 100644 index 000000000..ac88b02e0 --- /dev/null +++ b/common/include/ipc/model/ipc_check_access_control.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 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_IPC_CHECK_ACCESS_CONTROL_H +#define OHOS_DM_IPC_CHECK_ACCESS_CONTROL_H + +#include "dm_device_info.h" +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcCheckAcl : public IpcReq { + DECLARE_IPC_MODEL(IpcCheckAcl); + +public: + const DmAccessCaller &GetAccessCaller() const + { + return caller_; + } + + void SetAccessCaller(const DmAccessCaller &caller) + { + caller_ = caller; + } + + const DmAccessCallee &GetAccessCallee() const + { + return callee_; + } + + void SetAccessCallee(const DmAccessCallee &callee) + { + callee_ = callee; + } +private: + DmAccessCaller caller_; + DmAccessCallee callee_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_CHECK_ACCESS_CONTROL_H diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 757d51e10..ca743bb13 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -694,7 +694,7 @@ bool DeviceProfileConnector::IsTrustDevice(AccessControlProfile profile, const s return true; } if (profile.GetBindType() == DM_POINT_TO_POINT || profile.GetBindType() == DM_ACROSS_ACCOUNT) { - if (profile.GetBindLevel() == DEVICE) { // 设备级 + if (profile.GetBindLevel() == DEVICE || profile.GetBindLevel() == SERVICE) { // 设备级 LOGI("The udid %{public}s is device bind.", GetAnonyString(udid).c_str()); return true; } diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h index 611963695..b17847a28 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager.h @@ -611,6 +611,8 @@ public: virtual int32_t GetDeviceSecurityLevel(const std::string &pkgName, const std::string &networkId, int32_t &securityLevel) = 0; virtual bool IsSameAccount(const std::string &netWorkId) = 0; + virtual bool CheckAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee) = 0; + virtual bool CheckIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee) = 0; }; } // namespace DistributedHardware } // namespace OHOS 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 628833f8d..276a09434 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -382,6 +382,8 @@ public: virtual bool CheckRelatedDevice(const std::string &udid, const std::string &bundleName) override; virtual bool IsSameAccount(const std::string &netWorkId) override; + virtual bool CheckAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee) override; + virtual bool CheckIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee) override; private: DeviceManagerImpl() = default; ~DeviceManagerImpl() = default; diff --git a/interfaces/inner_kits/native_cpp/include/dm_device_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_info.h index d914e462d..192e3a61e 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -340,6 +340,19 @@ const std::string DEVICE_TYPE_WIFICAMERA_STRING = "WiFiCamera"; const std::string DEVICE_TYPE_PC_STRING = "PC"; const std::string DEVICE_TYPE_SMART_DISPLAY_STRING = "SMART_DISPLAY"; const std::string DEVICE_TYPE_2IN1_STRING = "2IN1"; + +typedef struct DmAccessCaller { + std::string accountId; + std::string pkgName; + int32_t userId; + uint64_t tokenId; +} DmAccessCaller; + +typedef struct DmAccessCallee { + std::string networkId; + std::string peerId; +} DmAccessCallee; + } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_DEVICE_INFO_H 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 fc8e7e495..23155e245 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -29,6 +29,7 @@ #include "ipc_authenticate_device_req.h" #include "ipc_bind_device_req.h" #include "ipc_bind_target_req.h" +#include "ipc_check_access_control.h" #include "ipc_check_related_device_req.h" #include "ipc_common_param_req.h" #include "ipc_create_pin_holder_req.h" @@ -2110,5 +2111,44 @@ bool DeviceManagerImpl::IsSameAccount(const std::string &netWorkId) return true; } +bool DeviceManagerImpl::CheckAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee) +{ + LOGI("DeviceManagerImpl::CheckAccessControl"); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetAccessCaller(caller); + req->SetAccessCallee(callee); + int32_t ret = ipcClientProxy_->SendRequest(CHECK_ACCESS_CONTROL, req, rsp); + if (ret != DM_OK) { + LOGE("CheckAccessControl Send Request failed ret: %{public}d", ret); + return false; + } + ret = rsp->GetErrCode(); + if (ret != DM_OK) { + LOGE("CheckAccessControl Failed with ret: %{public}d", ret); + return false; + } + return true; +} + +bool DeviceManagerImpl::CheckIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee) +{ + LOGI("DeviceManagerImpl::CheckIsSameAccount"); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetAccessCaller(caller); + req->SetAccessCallee(callee); + int32_t ret = ipcClientProxy_->SendRequest(CHECK_SAME_ACCOUNT, req, rsp); + if (ret != DM_OK) { + LOGE("CheckIsSameAccount Send Request failed ret: %{public}d", ret); + return false; + } + ret = rsp->GetErrCode(); + if (ret != DM_OK) { + LOGE("CheckIsSameAccount Failed with ret: %{public}d", ret); + return false; + } + return true; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp index 248628c0d..ce9fff7db 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp @@ -22,6 +22,7 @@ #include "dm_subscribe_info.h" #include "ipc_cmd_register.h" #include "ipc_def.h" +#include "ipc_check_access_control.h" #include "ipc_get_device_info_rsp.h" #include "ipc_get_info_by_network_req.h" #include "ipc_get_local_device_info_rsp.h" @@ -66,6 +67,24 @@ int32_t SetRspErrCode(IpcIo &reply, std::shared_ptr pBaseRsp) return DM_OK; } +bool EncodeDmAccessCaller(const DmAccessCaller &caller, MessageParcel &parcel) +{ + bool bRet = true; + bRet = (bRet && parcel.WriteString(caller.accountId)); + bRet = (bRet && parcel.WriteString(caller.pkgName)); + bRet = (bRet && parcel.WriteInt32(caller.userId)); + bRet = (bRet && parcel.WriteUint64(caller.tokenId)); + return bRet; +} + +bool EncodeDmAccessCallee(const DmAccessCallee &callee, MessageParcel &parcel) +{ + bool bRet = true; + bRet = (bRet && parcel.WriteString(callee.networkId)); + bRet = (bRet && parcel.WriteString(callee.peerId)); + return bRet; +} + ON_IPC_SET_REQUEST(REGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr pBaseReq, IpcIo &request, uint8_t *buffer, size_t buffLen) { @@ -370,5 +389,57 @@ ON_IPC_CMD(SERVER_DISCOVER_FINISH, IpcIo &reply) DeviceManagerNotify::GetInstance().OnDiscoveryFailed(pkgName, subscribeId, failedReason); } } + +ON_IPC_SET_REQUEST(CHECK_ACCESS_CONTROL, std::shared_ptr pBaseReq, MessageParcel &data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + DmAccessCaller caller = pReq->GetAccessCaller(); + DmAccessCallee callee = pReq->GetAccessCallee(); + if (!EncodeDmAccessCaller(caller, data)) { + LOGE("write caller failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + if (!EncodeDmAccessCallee(callee, data)) { + LOGE("write caller failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(CHECK_ACCESS_CONTROL, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + if (pBaseRsp == nullptr) { + LOGE("pBaseRsp is null"); + return ERR_DM_FAILED; + } + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} + +ON_IPC_SET_REQUEST(CHECK_SAME_ACCOUNT, std::shared_ptr pBaseReq, MessageParcel &data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + DmAccessCaller caller = pReq->GetAccessCaller(); + DmAccessCallee callee = pReq->GetAccessCallee(); + if (!EncodeDmAccessCaller(caller, data)) { + LOGE("write caller failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + if (!EncodeDmAccessCallee(callee, data)) { + LOGE("write caller failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(CHECK_SAME_ACCOUNT, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + if (pBaseRsp == nullptr) { + LOGE("pBaseRsp is null"); + return ERR_DM_FAILED; + } + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp index a434ebdde..4c1b042a3 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp @@ -23,6 +23,7 @@ #include "ipc_authenticate_device_req.h" #include "ipc_bind_device_req.h" #include "ipc_bind_target_req.h" +#include "ipc_check_access_control.h" #include "ipc_check_related_device_req.h" #include "ipc_cmd_register.h" #include "ipc_common_param_req.h" @@ -117,6 +118,24 @@ void DecodePeerTargetId(MessageParcel &parcel, PeerTargetId &targetId) targetId.wifiPort = parcel.ReadUint16(); } +bool EncodeDmAccessCaller(const DmAccessCaller &caller, MessageParcel &parcel) +{ + bool bRet = true; + bRet = (bRet && parcel.WriteString(caller.accountId)); + bRet = (bRet && parcel.WriteString(caller.pkgName)); + bRet = (bRet && parcel.WriteInt32(caller.userId)); + bRet = (bRet && parcel.WriteUint64(caller.tokenId)); + return bRet; +} + +bool EncodeDmAccessCallee(const DmAccessCallee &callee, MessageParcel &parcel) +{ + bool bRet = true; + bRet = (bRet && parcel.WriteString(callee.networkId)); + bRet = (bRet && parcel.WriteString(callee.peerId)); + return bRet; +} + ON_IPC_SET_REQUEST(REGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr pBaseReq, MessageParcel &data) { std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); @@ -1531,5 +1550,57 @@ ON_IPC_READ_RESPONSE(CHECK_RELATED_DEVICE, MessageParcel &reply, std::shared_ptr pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } + +ON_IPC_SET_REQUEST(CHECK_ACCESS_CONTROL, std::shared_ptr pBaseReq, MessageParcel &data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + DmAccessCaller caller = pReq->GetAccessCaller(); + DmAccessCallee callee = pReq->GetAccessCallee(); + if (!EncodeDmAccessCaller(caller, data)) { + LOGE("write caller failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + if (!EncodeDmAccessCallee(callee, data)) { + LOGE("write caller failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(CHECK_ACCESS_CONTROL, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + if (pBaseRsp == nullptr) { + LOGE("pBaseRsp is null"); + return ERR_DM_FAILED; + } + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} + +ON_IPC_SET_REQUEST(CHECK_SAME_ACCOUNT, std::shared_ptr pBaseReq, MessageParcel &data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + DmAccessCaller caller = pReq->GetAccessCaller(); + DmAccessCallee callee = pReq->GetAccessCallee(); + if (!EncodeDmAccessCaller(caller, data)) { + LOGE("write caller failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + if (!EncodeDmAccessCallee(callee, data)) { + LOGE("write caller failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(CHECK_SAME_ACCOUNT, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + if (pBaseRsp == nullptr) { + LOGE("pBaseRsp is null"); + return ERR_DM_FAILED; + } + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/implementation/include/devicestate/dm_device_state_manager.h b/services/implementation/include/devicestate/dm_device_state_manager.h index f71a89213..da77e0dfe 100644 --- a/services/implementation/include/devicestate/dm_device_state_manager.h +++ b/services/implementation/include/devicestate/dm_device_state_manager.h @@ -107,6 +107,7 @@ private: #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) int32_t DeleteGroupByDP(const std::string &deviceId); #endif + void ProcessDeviceStateChange(const DmDeviceState devState, const DmDeviceInfo &devInfo); private: std::mutex timerMapMutex_; diff --git a/services/implementation/src/devicestate/dm_device_state_manager.cpp b/services/implementation/src/devicestate/dm_device_state_manager.cpp index db124b71a..120554656 100644 --- a/services/implementation/src/devicestate/dm_device_state_manager.cpp +++ b/services/implementation/src/devicestate/dm_device_state_manager.cpp @@ -108,14 +108,7 @@ void DmDeviceStateManager::OnDeviceOnline(std::string deviceId, int32_t authForm stateDeviceInfos_[deviceId] = devInfo; } } - std::vector pkgName = softbusConnector_->GetPkgName(); - if (pkgName.size() == 0) { - listener_->OnDeviceStateChange(std::string(DM_PKG_NAME), DEVICE_STATE_ONLINE, devInfo); - } else { - for (auto item : pkgName) { - listener_->OnDeviceStateChange(item, DEVICE_STATE_ONLINE, devInfo); - } - } + ProcessDeviceStateChange(DEVICE_STATE_ONLINE, devInfo); softbusConnector_->ClearPkgName(); } @@ -131,14 +124,7 @@ void DmDeviceStateManager::OnDeviceOffline(std::string deviceId) } devInfo = stateDeviceInfos_[deviceId]; } - std::vector pkgName = softbusConnector_->GetPkgName(); - if (pkgName.size() == 0) { - listener_->OnDeviceStateChange(std::string(DM_PKG_NAME), DEVICE_STATE_OFFLINE, devInfo); - } else { - for (auto item : pkgName) { - listener_->OnDeviceStateChange(item, DEVICE_STATE_OFFLINE, devInfo); - } - } + ProcessDeviceStateChange(DEVICE_STATE_OFFLINE, devInfo); softbusConnector_->ClearPkgName(); } @@ -149,9 +135,10 @@ void DmDeviceStateManager::HandleDeviceStatusChange(DmDeviceState devState, DmDe switch (devState) { case DEVICE_STATE_ONLINE: RegisterOffLineTimer(devInfo); - SaveOnlineDeviceInfo(devInfo); devInfo.authForm = GetAuthForm(devInfo.networkId); + SaveOnlineDeviceInfo(devInfo); DmDistributedHardwareLoad::GetInstance().LoadDistributedHardwareFwk(); + ProcessDeviceStateChange(devState, devInfo); break; case DEVICE_STATE_OFFLINE: StartOffLineTimer(devInfo); @@ -161,9 +148,13 @@ void DmDeviceStateManager::HandleDeviceStatusChange(DmDeviceState devState, DmDe softbusConnector_->GetUdidByNetworkId(devInfo.networkId, udid); softbusConnector_->EraseUdidFromMap(udid); } + ProcessDeviceStateChange(devState, devInfo); + softbusConnector_->ClearPkgName(); break; case DEVICE_INFO_CHANGED: ChangeDeviceInfo(devInfo); + ProcessDeviceStateChange(devState, devInfo); + softbusConnector_->ClearPkgName(); break; default: LOGE("HandleDeviceStatusChange error, unknown device state = %{public}d", devState); @@ -186,6 +177,22 @@ void DmDeviceStateManager::HandleDeviceStatusChange(DmDeviceState devState, DmDe } } +void DmDeviceStateManager::ProcessDeviceStateChange(const DmDeviceState devState, const DmDeviceInfo &devInfo) +{ + if (softbusConnector_ == nullptr || listener_ == nullptr) { + LOGE("ProcessDeviceStateChange failed, callback_ptr is null."); + return; + } + std::vector pkgName = softbusConnector_->GetPkgName(); + if (pkgName.size() == 0) { + listener_->OnDeviceStateChange(std::string(DM_PKG_NAME), devState, devInfo); + } else { + for (auto item : pkgName) { + listener_->OnDeviceStateChange(item, devState, devInfo); + } + } +} + void DmDeviceStateManager::OnDbReady(const std::string &pkgName, const std::string &uuid) { if (pkgName.empty() || uuid.empty()) { @@ -205,8 +212,8 @@ void DmDeviceStateManager::OnDbReady(const std::string &pkgName, const std::stri saveInfo = iter->second; } if (listener_ != nullptr) { - DmDeviceState state = DEVICE_INFO_READY; - listener_->OnDeviceStateChange(pkgName, state, saveInfo); + ProcessDeviceStateChange(DEVICE_INFO_READY, devInfo); + softbusConnector_->ClearPkgName(); } } diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index c211bc34b..17932838d 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -191,6 +191,9 @@ public: int32_t CheckRelatedDevice(const std::string &udid, const std::string &bundleName); int32_t InitAccountInfo(); int32_t InitScreenLockEvent(); + bool CheckAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee); + bool CheckIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee); + private: bool IsDMServiceImplReady(); bool IsDMServiceAdapterLoad(); diff --git a/services/service/include/ipc/standard/ipc_server_stub.h b/services/service/include/ipc/standard/ipc_server_stub.h index a023b29d1..83f0af0d6 100644 --- a/services/service/include/ipc/standard/ipc_server_stub.h +++ b/services/service/include/ipc/standard/ipc_server_stub.h @@ -148,7 +148,6 @@ public: * @tc.type: FUNC */ void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; - std::set GetSaPkgname(); private: IpcServerStub(); @@ -161,7 +160,6 @@ private: mutable std::mutex listenerLock_; std::map> appRecipient_; std::map> dmListener_; - std::set saSet_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/include/permission/lite/permission_manager.h b/services/service/include/permission/lite/permission_manager.h index ae3d179e8..2fae6ef0c 100644 --- a/services/service/include/permission/lite/permission_manager.h +++ b/services/service/include/permission/lite/permission_manager.h @@ -17,6 +17,7 @@ #define OHOS_DM_PERMISSION_LITE_PERMISSION_MANAGER_H #include +#include #include "single_instance.h" namespace OHOS { @@ -32,6 +33,7 @@ public: bool CheckProcessNameValidOnAuthCode(const std::string &processName); bool CheckProcessNameValidOnPinHolder(const std::string &processName); bool CheckSA(void); + std::unordered_set GetSystemSA(); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/include/permission/standard/permission_manager.h b/services/service/include/permission/standard/permission_manager.h index a27ce71fd..0c02960c5 100644 --- a/services/service/include/permission/standard/permission_manager.h +++ b/services/service/include/permission/standard/permission_manager.h @@ -18,7 +18,7 @@ #include #include - +#include #include "single_instance.h" namespace OHOS { @@ -34,6 +34,7 @@ public: bool CheckProcessNameValidOnAuthCode(const std::string &processName); bool CheckProcessNameValidOnPinHolder(const std::string &processName); bool CheckSA(void); + std::unordered_set GetSystemSA(); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index a57c802cb..39621bc9c 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -172,7 +172,7 @@ int32_t DeviceManagerService::GetTrustedDeviceList(const std::string &pkgName, c } if (onlineDeviceList.size() > 0 && IsDMServiceImplReady()) { std::unordered_map> udidMap; - if (PermissionManager::GetInstance().CheckSA()) { + if (PermissionManager::GetInstance().CheckSystemSA(pkgName)) { udidMap = dmServiceImpl_->GetAppTrustDeviceIdList(std::string(ALL_PKGNAME)); } else { udidMap = dmServiceImpl_->GetAppTrustDeviceIdList(pkgName); @@ -1373,6 +1373,36 @@ int32_t DeviceManagerService::CheckRelatedDevice(const std::string &udid, const return dmServiceImpl_->CheckRelatedDevice(udid, bundleName); } +bool DeviceManagerService::CheckAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee) +{ + if (!PermissionManager::GetInstance().CheckPermission()) { + LOGE("The caller: %{public}s does not have permission to call CheckRelatedDevice.", caller.pkgName.c_str()); + return ERR_DM_NO_PERMISSION; + } + if (!IsDMServiceImplReady()) { + LOGE("CheckAccessControl failed, instance not init or init failed."); + return ERR_DM_NOT_INIT; + } + std::string udid = ""; + SoftbusListener::GetUdidByNetworkId(callee.networkId.c_str(), udid); + return dmServiceImpl_->CheckRelatedDevice(udid, caller.pkgName); +} + +bool DeviceManagerService::CheckIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee) +{ + if (!PermissionManager::GetInstance().CheckPermission()) { + LOGE("The caller: %{public}s does not have permission to call CheckRelatedDevice.", caller.pkgName.c_str()); + return ERR_DM_NO_PERMISSION; + } + if (!IsDMServiceImplReady()) { + LOGE("CheckIsSameAccount failed, instance not init or init failed."); + return ERR_DM_NOT_INIT; + } + std::string udid = ""; + SoftbusListener::GetUdidByNetworkId(callee.networkId.c_str(), udid); + return dmServiceImpl_->IsSameAccount(udid); +} + int32_t DeviceManagerService::InitAccountInfo() { #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) diff --git a/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index c456fc86b..dece00f67 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -32,6 +32,7 @@ #include "ipc_notify_pin_holder_event_req.h" #include "ipc_notify_publish_result_req.h" #include "ipc_server_stub.h" +#include "permission_manager.h" namespace OHOS { namespace DistributedHardware { @@ -41,7 +42,7 @@ std::map DeviceManagerServiceListener::dmListenerMap_ std::map> DeviceManagerServiceListener::udidHashMap_ = {}; std::mutex DeviceManagerServiceListener::alreadyOnlineSetLock_; std::unordered_set DeviceManagerServiceListener::alreadyOnlineSet_ = {}; - +const int32_t ALREADY_ONLINE_NUMS = 3; void DeviceManagerServiceListener::ConvertDeviceInfoToDeviceBasicInfo(const std::string &pkgName, const DmDeviceInfo &info, DmDeviceBasicInfo &deviceBasicInfo) { @@ -73,56 +74,95 @@ void DeviceManagerServiceListener::SetDeviceInfo(std::shared_ptrSetDeviceBasicInfo(deviceBasicInfo); } -void DeviceManagerServiceListener::OnDeviceStateChange(const std::string &pkgName, const DmDeviceState &state, - const DmDeviceInfo &info) +void DeviceManagerServiceListener::ProcessDeviceStateChange(const DmDeviceState &state, const DmDeviceInfo &info, + const DmDeviceBasicInfo &deviceBasicInfo) { - LOGI("OnDeviceStateChange, state = %{public}d", state); + LOGI("DeviceManagerServiceListener::ProcessDeviceStateChange"); std::shared_ptr pReq = std::make_shared(); std::shared_ptr pRsp = std::make_shared(); - DmDeviceBasicInfo deviceBasicInfo; - ConvertDeviceInfoToDeviceBasicInfo(pkgName, info, deviceBasicInfo); - if (pkgName == std::string(DM_PKG_NAME)) { - std::vector PkgNameVec = ipcServerListener_.GetAllPkgName(); - if (state == DEVICE_STATE_OFFLINE) { - { - std::lock_guard autoLock(alreadyOnlineSetLock_); - alreadyOnlineSet_.clear(); + std::vector PkgNameVec = ipcServerListener_.GetAllPkgName(); + if (state == DEVICE_STATE_OFFLINE) { + { + std::lock_guard autoLock(alreadyOnlineSetLock_); + alreadyOnlineSet_.clear(); + } + } + for (const auto &it : PkgNameVec) { + std::string notifyKey = it + "_" + info.deviceId; + DmDeviceState notifyState = state; + { + std::lock_guard autoLock(alreadyOnlineSetLock_); + if (state == DEVICE_STATE_ONLINE && alreadyOnlineSet_.find(notifyKey) != alreadyOnlineSet_.end()) { + notifyState = DmDeviceState::DEVICE_INFO_CHANGED; + } else if (state == DEVICE_STATE_ONLINE) { + alreadyOnlineSet_.insert(notifyKey); } } - for (const auto &it : PkgNameVec) { + SetDeviceInfo(pReq, it, notifyState, info, deviceBasicInfo); + ipcServerListener_.SendRequest(SERVER_DEVICE_STATE_NOTIFY, pReq, pRsp); + } +} + +void DeviceManagerServiceListener::ProcessAppStateChange(const std::string &pkgName, const DmDeviceState &state, + const DmDeviceInfo &info, const DmDeviceBasicInfo &deviceBasicInfo) +{ + LOGI("DeviceManagerServiceListener::ProcessAppStateChange"); + std::shared_ptr pReq = std::make_shared(); + std::shared_ptr pRsp = std::make_shared(); + std::unordered_set notifyPkgnames = PermissionManager::GetInstance().GetSystemSA(); + notifyPkgnames.insert(pkgName); + if (state == DEVICE_STATE_ONLINE) { + for (const auto &it : notifyPkgnames) { std::string notifyKey = it + "_" + info.deviceId; - DmDeviceState notifyState = state; { std::lock_guard autoLock(alreadyOnlineSetLock_); - if (state == DEVICE_STATE_ONLINE && alreadyOnlineSet_.find(notifyKey) != alreadyOnlineSet_.end()) { - notifyState = DmDeviceState::DEVICE_INFO_CHANGED; - } else if (state == DEVICE_STATE_ONLINE) { - alreadyOnlineSet_.insert(notifyKey); + if (alreadyOnlineSet_.find(notifyKey) != alreadyOnlineSet_.end()) { + continue; } + alreadyOnlineSet_.insert(notifyKey); } - SetDeviceInfo(pReq, it, notifyState, info, deviceBasicInfo); + SetDeviceInfo(pReq, it, state, info, deviceBasicInfo); ipcServerListener_.SendRequest(SERVER_DEVICE_STATE_NOTIFY, pReq, pRsp); } - } else { - std::string notifyKey = pkgName + "_" + info.deviceId; - { - std::lock_guard autoLock(alreadyOnlineSetLock_); - if (state == DEVICE_STATE_ONLINE) { - alreadyOnlineSet_.insert(notifyKey); - } else if (state == DEVICE_STATE_OFFLINE) { - alreadyOnlineSet_.erase(notifyKey); + } + if (state == DEVICE_STATE_OFFLINE) { + if (alreadyOnlineSet_.size() == ALREADY_ONLINE_NUMS) { + { + std::lock_guard autoLock(alreadyOnlineSetLock_); + alreadyOnlineSet_.clear(); } + for (const auto &it : notifyPkgnames) { + SetDeviceInfo(pReq, it, state, info, deviceBasicInfo); + ipcServerListener_.SendRequest(SERVER_DEVICE_STATE_NOTIFY, pReq, pRsp); + } + } else { + std::string notifyKey = pkgName + "_" + info.deviceId; + { + std::lock_guard autoLock(alreadyOnlineSetLock_); + if (alreadyOnlineSet_.find(notifyKey) != alreadyOnlineSet_.end()) { + alreadyOnlineSet_.erase(notifyKey); + } + } + SetDeviceInfo(pReq, pkgName, state, info, deviceBasicInfo); + ipcServerListener_.SendRequest(SERVER_DEVICE_STATE_NOTIFY, pReq, pRsp); } + } + if (state == DEVICE_INFO_READY) { SetDeviceInfo(pReq, pkgName, state, info, deviceBasicInfo); ipcServerListener_.SendRequest(SERVER_DEVICE_STATE_NOTIFY, pReq, pRsp); - #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) - std::set set = IpcServerStub::GetInstance().GetSaPkgname(); - for (const auto &item : set) { - LOGI("Notify SA pkgname %s", item.c_str()); - SetDeviceInfo(pReq, item, state, info, deviceBasicInfo); - ipcServerListener_.SendRequest(SERVER_DEVICE_STATE_NOTIFY, pReq, pRsp); - } - #endif + } +} + +void DeviceManagerServiceListener::OnDeviceStateChange(const std::string &pkgName, const DmDeviceState &state, + const DmDeviceInfo &info) +{ + LOGI("OnDeviceStateChange, state = %{public}d", state); + DmDeviceBasicInfo deviceBasicInfo; + ConvertDeviceInfoToDeviceBasicInfo(pkgName, info, deviceBasicInfo); + if (pkgName == std::string(DM_PKG_NAME)) { + ProcessDeviceStateChange(state, info, deviceBasicInfo); + } else { + ProcessAppStateChange(pkgName, state, info, deviceBasicInfo); } } diff --git a/services/service/src/ipc/lite/ipc_cmd_parser.cpp b/services/service/src/ipc/lite/ipc_cmd_parser.cpp index 9154339c2..85dd8d3b6 100644 --- a/services/service/src/ipc/lite/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/lite/ipc_cmd_parser.cpp @@ -56,6 +56,20 @@ bool EncodeDmDeviceInfo(const DmDeviceInfo &devInfo, IpcIo &reply) return bRet; } +void DecodeDmAccessCaller(MessageParcel &parcel, DmAccessCaller &caller) +{ + caller.accountId = parcel.ReadString(); + caller.pkgName = parcel.ReadString(); + caller.userId = parcel.ReadInt32(); + caller.tokenId = parcel.ReadUint64(); +} + +void DecodeDmAccessCallee(MessageParcel &parcel, const DmAccessCallee &callee) +{ + callee.networkId = parcel.ReadString(); + callee.peerId = parcel.ReadString(); +} + ON_IPC_SET_REQUEST(SERVER_DEVICE_STATE_NOTIFY, std::shared_ptr pBaseReq, IpcIo &request, uint8_t *buffer, size_t buffLen) { @@ -258,5 +272,33 @@ ON_IPC_SERVER_CMD(DELETE_CREDENTIAL, IpcIo &req, IpcIo &reply) WriteString(&reply, outParamStr.c_str()); } } + +ON_IPC_CMD(CHECK_ACCESS_CONTROL, MessageParcel &data, MessageParcel &reply) +{ + DmAccessCaller caller; + DmAccessCallee callee; + DecodeDmAccessCaller(data, caller); + DecodeDmAccessCallee(data, callee); + int32_t result = DeviceManagerService::GetInstance().CheckAccessControl(caller, callee); + if (!reply.WriteInt32(result)) { + LOGE("write result failed."); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_CMD(CHECK_SAME_ACCOUNT, MessageParcel &data, MessageParcel &reply) +{ + DmAccessCaller caller; + DmAccessCallee callee; + DecodeDmAccessCaller(data, caller); + DecodeDmAccessCallee(data, callee); + int32_t result = DeviceManagerService::GetInstance().CheckIsSameAccount(caller, callee); + if (!reply.WriteInt32(result)) { + LOGE("write result failed."); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 812eb7f84..09cd036c2 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -94,6 +94,20 @@ void DecodePeerTargetId(MessageParcel &parcel, PeerTargetId &targetId) targetId.wifiPort = parcel.ReadUint16(); } +void DecodeDmAccessCaller(MessageParcel &parcel, DmAccessCaller &caller) +{ + caller.accountId = parcel.ReadString(); + caller.pkgName = parcel.ReadString(); + caller.userId = parcel.ReadInt32(); + caller.tokenId = parcel.ReadUint64(); +} + +void DecodeDmAccessCallee(MessageParcel &parcel, const DmAccessCallee &callee) +{ + callee.networkId = parcel.ReadString(); + callee.peerId = parcel.ReadString(); +} + ON_IPC_SET_REQUEST(SERVER_DEVICE_STATE_NOTIFY, std::shared_ptr pBaseReq, MessageParcel &data) { if (pBaseReq == nullptr) { @@ -1387,5 +1401,33 @@ ON_IPC_CMD(CHECK_RELATED_DEVICE, MessageParcel &data, MessageParcel &reply) } return DM_OK; } + +ON_IPC_CMD(CHECK_ACCESS_CONTROL, MessageParcel &data, MessageParcel &reply) +{ + DmAccessCaller caller; + DmAccessCallee callee; + DecodeDmAccessCaller(data, caller); + DecodeDmAccessCallee(data, callee); + int32_t result = DeviceManagerService::GetInstance().CheckAccessControl(caller, callee); + if (!reply.WriteInt32(result)) { + LOGE("write result failed."); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_CMD(CHECK_SAME_ACCOUNT, MessageParcel &data, MessageParcel &reply) +{ + DmAccessCaller caller; + DmAccessCallee callee; + DecodeDmAccessCaller(data, caller); + DecodeDmAccessCallee(data, callee); + int32_t result = DeviceManagerService::GetInstance().CheckIsSameAccount(caller, callee); + if (!reply.WriteInt32(result)) { + LOGE("write result failed."); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/service/src/ipc/standard/ipc_server_stub.cpp b/services/service/src/ipc/standard/ipc_server_stub.cpp index 6ae72f36e..434499851 100644 --- a/services/service/src/ipc/standard/ipc_server_stub.cpp +++ b/services/service/src/ipc/standard/ipc_server_stub.cpp @@ -187,10 +187,6 @@ int32_t IpcServerStub::RegisterDeviceManagerListener(std::string &pkgName, sptr< } dmListener_[pkgName] = listener; appRecipient_[pkgName] = appRecipient; - if (PermissionManager::GetInstance().CheckSA()) { - LOGI("RegisterDeviceManagerListener pkgname %{public}s is SA", pkgName.c_str()); - saSet_.insert(pkgName); - } LOGI("RegisterDeviceManagerListener: Register listener complete."); return DM_OK; } @@ -219,7 +215,6 @@ int32_t IpcServerStub::UnRegisterDeviceManagerListener(std::string &pkgName) listener->AsObject()->RemoveDeathRecipient(appRecipient); appRecipient_.erase(pkgName); dmListener_.erase(pkgName); - saSet_.erase(pkgName); return DM_OK; } @@ -304,10 +299,5 @@ void AppDeathRecipient::OnRemoteDied(const wptr &remote) LOGI("AppDeathRecipient: OnRemoteDied for %{public}s", pkgName.c_str()); IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(pkgName); } - -std::set IpcServerStub::GetSaPkgname() -{ - return saSet_; -} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/permission/lite/permission_manager.cpp b/services/service/src/permission/lite/permission_manager.cpp index 4c277db42..4752e3c3c 100644 --- a/services/service/src/permission/lite/permission_manager.cpp +++ b/services/service/src/permission/lite/permission_manager.cpp @@ -58,5 +58,16 @@ bool PermissionManager::CheckSA(void) { return true; } + +bool PermissionManager::CheckSystemSA(const std::string &pkgName) +{ + (void)pkgName; + return true; +} + +std::unordered_set PermissionManager::GetSystemSA() +{ + return std::unordered_set{}; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/permission/standard/permission_manager.cpp b/services/service/src/permission/standard/permission_manager.cpp index 0411d4885..d61a2c157 100644 --- a/services/service/src/permission/standard/permission_manager.cpp +++ b/services/service/src/permission/standard/permission_manager.cpp @@ -49,6 +49,12 @@ constexpr const static char g_authCodeWhiteList[AUTH_CODE_WHITE_LIST_NUM][PKG_NA constexpr const static char g_pinHolderWhiteList[PIN_HOLDER_WHITE_LIST_NUM][PKG_NAME_SIZE_MAX] = { "CollaborationFwk", }; + +#define SYSTEM_SA_WHITE_LIST_NUM (2) +constexpr const static char systemSaWhiteList[SYSTEM_SA_WHITE_LIST_NUM][PKG_NAME_SIZE_MAX] = { + "Samgr_Networking", + "ohos.distributeddata.service", +}; } bool PermissionManager::CheckPermission(void) @@ -189,21 +195,27 @@ bool PermissionManager::CheckProcessNameValidOnPinHolder(const std::string &proc return false; } -bool PermissionManager::CheckSA(void) +bool PermissionManager::CheckSystemSA(const std::string &pkgName) { - AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID(); - if (tokenCaller == 0) { - LOGE("CheckSA GetCallingTokenID error."); - return false; + LOGI("PermissionManager::CheckSystemSA"); + for (uint16_t index = 0; index < SYSTEM_SA_WHITE_LIST_NUM; ++index) { + std::string tmp(systemSaWhiteList[index]); + if (pkgName == tmp) { + return true; + } } - LOGI("CheckSA::tokenCaller ID == %{public}s", GetAnonyInt32(tokenCaller).c_str()); + return false; +} - ATokenTypeEnum tokenTypeFlag = AccessTokenKit::GetTokenTypeFlag(tokenCaller); - if (tokenTypeFlag == ATokenTypeEnum::TOKEN_NATIVE) { - return true; +std::unordered_set PermissionManager::GetSystemSA() +{ + std::unordered_set systemSA; + for (uint16_t index = 0; index < SYSTEM_SA_WHITE_LIST_NUM; ++index) { + std::string tmp(systemSaWhiteList[index]); + systemSA.insert(tmp); } LOGE("TokenCaller is not SA."); - return false; + return systemSA; } } // namespace DistributedHardware } // namespace OHOS -- Gitee From d3cfd30f554ae504eaad8eaef768a317939fcec8 Mon Sep 17 00:00:00 2001 From: yangwei_814916 Date: Tue, 25 Jun 2024 18:09:04 +0800 Subject: [PATCH 2/4] =?UTF-8?q?630=E5=AE=89=E5=85=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangwei_814916 --- .../native_cpp/include/dm_device_info.h | 3 +- .../src/ipc/lite/ipc_cmd_parser.cpp | 70 ------------------- .../devicestate/dm_device_state_manager.cpp | 2 +- .../include/device_manager_service_listener.h | 4 ++ .../permission/lite/permission_manager.h | 2 +- .../permission/standard/permission_manager.h | 2 +- .../service/src/ipc/lite/ipc_cmd_parser.cpp | 42 ----------- .../src/ipc/standard/ipc_cmd_parser.cpp | 2 +- .../permission/lite/permission_manager.cpp | 5 -- 9 files changed, 9 insertions(+), 123 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/include/dm_device_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_info.h index 192e3a61e..bb6d53fad 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -352,7 +352,6 @@ typedef struct DmAccessCallee { std::string networkId; std::string peerId; } DmAccessCallee; - } // namespace DistributedHardware } // namespace OHOS -#endif // OHOS_DM_DEVICE_INFO_H +#endif // OHOS_DM_DEVICE_INFO_H \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp index ce9fff7db..49291720e 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp @@ -67,24 +67,6 @@ int32_t SetRspErrCode(IpcIo &reply, std::shared_ptr pBaseRsp) return DM_OK; } -bool EncodeDmAccessCaller(const DmAccessCaller &caller, MessageParcel &parcel) -{ - bool bRet = true; - bRet = (bRet && parcel.WriteString(caller.accountId)); - bRet = (bRet && parcel.WriteString(caller.pkgName)); - bRet = (bRet && parcel.WriteInt32(caller.userId)); - bRet = (bRet && parcel.WriteUint64(caller.tokenId)); - return bRet; -} - -bool EncodeDmAccessCallee(const DmAccessCallee &callee, MessageParcel &parcel) -{ - bool bRet = true; - bRet = (bRet && parcel.WriteString(callee.networkId)); - bRet = (bRet && parcel.WriteString(callee.peerId)); - return bRet; -} - ON_IPC_SET_REQUEST(REGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr pBaseReq, IpcIo &request, uint8_t *buffer, size_t buffLen) { @@ -389,57 +371,5 @@ ON_IPC_CMD(SERVER_DISCOVER_FINISH, IpcIo &reply) DeviceManagerNotify::GetInstance().OnDiscoveryFailed(pkgName, subscribeId, failedReason); } } - -ON_IPC_SET_REQUEST(CHECK_ACCESS_CONTROL, std::shared_ptr pBaseReq, MessageParcel &data) -{ - std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - DmAccessCaller caller = pReq->GetAccessCaller(); - DmAccessCallee callee = pReq->GetAccessCallee(); - if (!EncodeDmAccessCaller(caller, data)) { - LOGE("write caller failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!EncodeDmAccessCallee(callee, data)) { - LOGE("write caller failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(CHECK_ACCESS_CONTROL, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - -ON_IPC_SET_REQUEST(CHECK_SAME_ACCOUNT, std::shared_ptr pBaseReq, MessageParcel &data) -{ - std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - DmAccessCaller caller = pReq->GetAccessCaller(); - DmAccessCallee callee = pReq->GetAccessCallee(); - if (!EncodeDmAccessCaller(caller, data)) { - LOGE("write caller failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!EncodeDmAccessCallee(callee, data)) { - LOGE("write caller failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(CHECK_SAME_ACCOUNT, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/src/devicestate/dm_device_state_manager.cpp b/services/implementation/src/devicestate/dm_device_state_manager.cpp index 120554656..5325904b4 100644 --- a/services/implementation/src/devicestate/dm_device_state_manager.cpp +++ b/services/implementation/src/devicestate/dm_device_state_manager.cpp @@ -212,7 +212,7 @@ void DmDeviceStateManager::OnDbReady(const std::string &pkgName, const std::stri saveInfo = iter->second; } if (listener_ != nullptr) { - ProcessDeviceStateChange(DEVICE_INFO_READY, devInfo); + ProcessDeviceStateChange(DEVICE_INFO_READY, saveInfo); softbusConnector_->ClearPkgName(); } } diff --git a/services/service/include/device_manager_service_listener.h b/services/service/include/device_manager_service_listener.h index 0b6145dbc..d2c190c5a 100644 --- a/services/service/include/device_manager_service_listener.h +++ b/services/service/include/device_manager_service_listener.h @@ -82,6 +82,10 @@ private: const DmDeviceInfo &info, DmDeviceBasicInfo &deviceBasicInfo); void SetDeviceInfo(std::shared_ptr pReq, const std::string &pkgName, const DmDeviceState &state, const DmDeviceInfo &deviceInfo, const DmDeviceBasicInfo &deviceBasicInfo); + void ProcessDeviceStateChange(const DmDeviceState &state, const DmDeviceInfo &info, + const DmDeviceBasicInfo &deviceBasicInfo); + void ProcessAppStateChange(const std::string &pkgName, const DmDeviceState &state, + const DmDeviceInfo &info, const DmDeviceBasicInfo &deviceBasicInfo); private: #if !defined(__LITEOS_M__) IpcServerListener ipcServerListener_; diff --git a/services/service/include/permission/lite/permission_manager.h b/services/service/include/permission/lite/permission_manager.h index 2fae6ef0c..7ed977a94 100644 --- a/services/service/include/permission/lite/permission_manager.h +++ b/services/service/include/permission/lite/permission_manager.h @@ -32,7 +32,7 @@ public: int32_t GetCallerProcessName(std::string &processName); bool CheckProcessNameValidOnAuthCode(const std::string &processName); bool CheckProcessNameValidOnPinHolder(const std::string &processName); - bool CheckSA(void); + bool CheckSystemSA(const std::string &pkgName); std::unordered_set GetSystemSA(); }; } // namespace DistributedHardware diff --git a/services/service/include/permission/standard/permission_manager.h b/services/service/include/permission/standard/permission_manager.h index 0c02960c5..7978b30d3 100644 --- a/services/service/include/permission/standard/permission_manager.h +++ b/services/service/include/permission/standard/permission_manager.h @@ -33,7 +33,7 @@ public: int32_t GetCallerProcessName(std::string &processName); bool CheckProcessNameValidOnAuthCode(const std::string &processName); bool CheckProcessNameValidOnPinHolder(const std::string &processName); - bool CheckSA(void); + bool CheckSystemSA(const std::string &pkgName); std::unordered_set GetSystemSA(); }; } // namespace DistributedHardware diff --git a/services/service/src/ipc/lite/ipc_cmd_parser.cpp b/services/service/src/ipc/lite/ipc_cmd_parser.cpp index 85dd8d3b6..9154339c2 100644 --- a/services/service/src/ipc/lite/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/lite/ipc_cmd_parser.cpp @@ -56,20 +56,6 @@ bool EncodeDmDeviceInfo(const DmDeviceInfo &devInfo, IpcIo &reply) return bRet; } -void DecodeDmAccessCaller(MessageParcel &parcel, DmAccessCaller &caller) -{ - caller.accountId = parcel.ReadString(); - caller.pkgName = parcel.ReadString(); - caller.userId = parcel.ReadInt32(); - caller.tokenId = parcel.ReadUint64(); -} - -void DecodeDmAccessCallee(MessageParcel &parcel, const DmAccessCallee &callee) -{ - callee.networkId = parcel.ReadString(); - callee.peerId = parcel.ReadString(); -} - ON_IPC_SET_REQUEST(SERVER_DEVICE_STATE_NOTIFY, std::shared_ptr pBaseReq, IpcIo &request, uint8_t *buffer, size_t buffLen) { @@ -272,33 +258,5 @@ ON_IPC_SERVER_CMD(DELETE_CREDENTIAL, IpcIo &req, IpcIo &reply) WriteString(&reply, outParamStr.c_str()); } } - -ON_IPC_CMD(CHECK_ACCESS_CONTROL, MessageParcel &data, MessageParcel &reply) -{ - DmAccessCaller caller; - DmAccessCallee callee; - DecodeDmAccessCaller(data, caller); - DecodeDmAccessCallee(data, callee); - int32_t result = DeviceManagerService::GetInstance().CheckAccessControl(caller, callee); - if (!reply.WriteInt32(result)) { - LOGE("write result failed."); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_CMD(CHECK_SAME_ACCOUNT, MessageParcel &data, MessageParcel &reply) -{ - DmAccessCaller caller; - DmAccessCallee callee; - DecodeDmAccessCaller(data, caller); - DecodeDmAccessCallee(data, callee); - int32_t result = DeviceManagerService::GetInstance().CheckIsSameAccount(caller, callee); - if (!reply.WriteInt32(result)) { - LOGE("write result failed."); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 09cd036c2..e7748f1a8 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -102,7 +102,7 @@ void DecodeDmAccessCaller(MessageParcel &parcel, DmAccessCaller &caller) caller.tokenId = parcel.ReadUint64(); } -void DecodeDmAccessCallee(MessageParcel &parcel, const DmAccessCallee &callee) +void DecodeDmAccessCallee(MessageParcel &parcel, DmAccessCallee &callee) { callee.networkId = parcel.ReadString(); callee.peerId = parcel.ReadString(); diff --git a/services/service/src/permission/lite/permission_manager.cpp b/services/service/src/permission/lite/permission_manager.cpp index 4752e3c3c..49c9478af 100644 --- a/services/service/src/permission/lite/permission_manager.cpp +++ b/services/service/src/permission/lite/permission_manager.cpp @@ -54,11 +54,6 @@ bool PermissionManager::CheckProcessNameValidOnPinHolder(const std::string &proc return true; } -bool PermissionManager::CheckSA(void) -{ - return true; -} - bool PermissionManager::CheckSystemSA(const std::string &pkgName) { (void)pkgName; -- Gitee From 85b83e336b451bcbc94797c1c72e81ac75a43621 Mon Sep 17 00:00:00 2001 From: yangwei_814916 Date: Tue, 25 Jun 2024 21:42:10 +0800 Subject: [PATCH 3/4] =?UTF-8?q?630=E5=AE=89=E5=85=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangwei_814916 --- .../native_cpp/src/ipc/lite/ipc_cmd_parser.cpp | 1 - .../src/devicestate/dm_device_state_manager.cpp | 16 +--------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp index 49291720e..248628c0d 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp @@ -22,7 +22,6 @@ #include "dm_subscribe_info.h" #include "ipc_cmd_register.h" #include "ipc_def.h" -#include "ipc_check_access_control.h" #include "ipc_get_device_info_rsp.h" #include "ipc_get_info_by_network_req.h" #include "ipc_get_local_device_info_rsp.h" diff --git a/services/implementation/src/devicestate/dm_device_state_manager.cpp b/services/implementation/src/devicestate/dm_device_state_manager.cpp index 5325904b4..c371ea5fc 100644 --- a/services/implementation/src/devicestate/dm_device_state_manager.cpp +++ b/services/implementation/src/devicestate/dm_device_state_manager.cpp @@ -139,6 +139,7 @@ void DmDeviceStateManager::HandleDeviceStatusChange(DmDeviceState devState, DmDe SaveOnlineDeviceInfo(devInfo); DmDistributedHardwareLoad::GetInstance().LoadDistributedHardwareFwk(); ProcessDeviceStateChange(devState, devInfo); + softbusConnector_->ClearPkgName(); break; case DEVICE_STATE_OFFLINE: StartOffLineTimer(devInfo); @@ -160,21 +161,6 @@ void DmDeviceStateManager::HandleDeviceStatusChange(DmDeviceState devState, DmDe LOGE("HandleDeviceStatusChange error, unknown device state = %{public}d", devState); break; } - if (listener_ == nullptr) { - LOGE("HandleDeviceStatusChange failed, device manager client listener is null."); - return; - } - if (softbusConnector_ != nullptr) { - std::vector pkgName = softbusConnector_->GetPkgName(); - if (pkgName.size() == 0) { - listener_->OnDeviceStateChange(std::string(DM_PKG_NAME), devState, devInfo); - } else { - for (auto item : pkgName) { - listener_->OnDeviceStateChange(item, devState, devInfo); - } - } - softbusConnector_->ClearPkgName(); - } } void DmDeviceStateManager::ProcessDeviceStateChange(const DmDeviceState devState, const DmDeviceInfo &devInfo) -- Gitee From 47b8081ae6bcdbf8efeae2adaccb573fec41d072 Mon Sep 17 00:00:00 2001 From: yangwei_814916 Date: Tue, 25 Jun 2024 21:43:58 +0800 Subject: [PATCH 4/4] =?UTF-8?q?630=E5=AE=89=E5=85=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangwei_814916 --- .../src/devicestate/dm_device_state_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/implementation/src/devicestate/dm_device_state_manager.cpp b/services/implementation/src/devicestate/dm_device_state_manager.cpp index c371ea5fc..2e61ed098 100644 --- a/services/implementation/src/devicestate/dm_device_state_manager.cpp +++ b/services/implementation/src/devicestate/dm_device_state_manager.cpp @@ -198,8 +198,8 @@ void DmDeviceStateManager::OnDbReady(const std::string &pkgName, const std::stri saveInfo = iter->second; } if (listener_ != nullptr) { - ProcessDeviceStateChange(DEVICE_INFO_READY, saveInfo); - softbusConnector_->ClearPkgName(); + DmDeviceState state = DEVICE_INFO_READY; + listener_->OnDeviceStateChange(pkgName, state, saveInfo); } } -- Gitee