From 197b7966b519f0f3ee2c987f8b8694d060787469 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Wed, 5 Mar 2025 09:22:03 +0800 Subject: [PATCH 1/2] time optimize for quick mirrow Signed-off-by: zhuzhihui7 Change-Id: I109b61562d8975fd50f66f3f59e78039666eeadf --- .../include/deviceprofile_connector.h | 6 +- .../src/deviceprofile_connector.cpp | 16 ++--- .../include/authentication/dm_auth_manager.h | 6 ++ .../authentication/auth_message_processor.cpp | 6 +- .../src/authentication/dm_auth_manager.cpp | 60 +++++++++++++++++-- .../UTTest_dm_auth_manager_first.cpp | 7 ++- .../mock/deviceprofile_connector_mock.cpp | 4 +- .../mock/deviceprofile_connector_mock.h | 4 +- 8 files changed, 84 insertions(+), 25 deletions(-) diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 30869a252..1547a55da 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -184,9 +184,9 @@ public: DistributedDeviceProfile::ServiceInfoProfile &serviceInfoProfile); int32_t GetServiceInfoProfileListByTokenId(const DistributedDeviceProfile::ServiceInfoUniqueKey &key, std::vector &serviceInfoProfiles); - int32_t GetServiceInfoProfileListByBundleName(const DistributedDeviceProfile::ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles); - int32_t PutSessionKey(const uint8_t* sessionKey, uint32_t length, int32_t& sessionKeyId); + int32_t GetServiceInfoProfileListByBundleName(const DistributedDeviceProfile::ServiceInfoUniqueKey &key, + std::vector &serviceInfoProfiles); + int32_t PutSessionKey(const std::vector &sessionKeyArray, int32_t &sessionKeyId); private: int32_t HandleDmAuthForm(DistributedDeviceProfile::AccessControlProfile profiles, DmDiscoveryInfo discoveryInfo); diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 63207c775..75fefdc03 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -1807,8 +1807,8 @@ int32_t DeviceProfileConnector::GetServiceInfoProfileListByTokenId( } int32_t DeviceProfileConnector::GetServiceInfoProfileListByBundleName( - const DistributedDeviceProfile::ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) + const DistributedDeviceProfile::ServiceInfoUniqueKey &key, + std::vector &serviceInfoProfiles) { int32_t ret = DistributedDeviceProfileClient::GetInstance().GetServiceInfoProfileListByBundleName( key, serviceInfoProfiles); @@ -1819,19 +1819,13 @@ int32_t DeviceProfileConnector::GetServiceInfoProfileListByBundleName( return DM_OK; } -int32_t DeviceProfileConnector::PutSessionKey( - const uint8_t* sessionKey, uint32_t length, int32_t& sessionKeyId) +int32_t DeviceProfileConnector::PutSessionKey(const std::vector &sessionKeyArray, int32_t &sessionKeyId) { - if (sessionKey == nullptr) { - LOGE("sessionKey nullptr"); - return ERR_DM_FAILED; - } - if (length > MAX_SESSION_KEY_LENGTH) { - LOGE("SessionKey too long, len: %{public}d", length); + if (sessionKeyArray.empty() || sessionKeyArray.size() > MAX_SESSION_KEY_LENGTH) { + LOGE("SessionKey size invalid"); return ERR_DM_FAILED; } uint32_t userId = static_cast(MultipleUserConnector::GetCurrentAccountUserID()); - std::vector sessionKeyArray(sessionKey, sessionKey + length); int32_t ret = DistributedDeviceProfileClient::GetInstance().PutSessionKey(userId, sessionKeyArray, sessionKeyId); if (ret != DM_OK) { LOGE("failed: %{public}d", ret); diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 662d9df67..0bb4f2ef2 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -484,6 +484,7 @@ public: static bool IsPinCodeValid(const std::string strpin); static bool IsPinCodeValid(int32_t numpin); bool IsImportedAuthCodeValid(); + bool IsSrc(); private: bool IsHmlSessionType(); @@ -536,6 +537,7 @@ public: void AuthDeviceError(int64_t requestId, int32_t errorCode); void GetRemoteDeviceId(std::string &deviceId); void AuthDeviceSessionKey(int64_t requestId, const uint8_t *sessionKey, uint32_t sessionKeyLen); + int32_t GetSessionKeyIdSync(int64_t requestId); void OnAuthDeviceDataReceived(const int32_t sessionId, const std::string message); void OnScreenLocked(); void HandleDeviceNotTrust(const std::string &udid); @@ -551,6 +553,7 @@ private: const std::string &extra); void ParseJsonObject(nlohmann::json jsonObject); void ParseHmlInfoInJsonObject(nlohmann::json jsonObject); + void PutSessionKeyAsync(int64_t requestId, std::vector hash); int32_t DeleteAcl(const std::string &pkgName, const std::string &localUdid, const std::string &remoteUdid, int32_t bindLevel, const std::string &extra); void ProcessAuthRequestExt(const int32_t &sessionId); @@ -625,6 +628,9 @@ private: DistributedDeviceProfile::ServiceInfoProfile serviceInfoProfile_; bool pincodeDialogEverShown_ = false; std::string bundleName_ = ""; + std::mutex sessionKeyIdMutex_; + std::condition_variable sessionKeyIdCondition_; + std::map> sessionKeyIdAsyncResult_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index a42c941dc..34dd05292 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -230,7 +230,11 @@ void AuthMessageProcessor::CreatePublicKeyMessageExt(nlohmann::json &json) return; } else { nlohmann::json jsonTemp; - jsonTemp[TAG_SESSIONKEY_ID] = authResponseContext_->localSessionKeyId; + auto sptr = authMgr_.lock(); + if (sptr != nullptr && !sptr->IsSrc()) { + authResponseContext_->localSessionKeyId = sptr->GetSessionKeyIdSync(authResponseContext_->requestId); + jsonTemp[TAG_SESSIONKEY_ID] = authResponseContext_->localSessionKeyId; + } jsonTemp[TAG_PUBLICKEY] = authResponseContext_->publicKey; std::string strTemp = SafetyDump(jsonTemp); std::string encryptStr = ""; diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 531c2f4e7..89a67e221 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -82,6 +82,7 @@ const int32_t AUTH_DEVICE_TIMEOUT = 10; const int32_t SESSION_HEARTBEAT_TIMEOUT = 50; const int32_t ALREADY_BIND = 1; const int32_t STRTOLL_BASE_10 = 10; +const int32_t MAX_PUT_SESSIONKEY_TIMEOUT = 100; //ms constexpr const char* AUTHENTICATE_TIMEOUT_TASK = "deviceManagerTimer:authenticate"; constexpr const char* NEGOTIATE_TIMEOUT_TASK = "deviceManagerTimer:negotiate"; @@ -1471,6 +1472,8 @@ void DmAuthManager::AuthenticateFinish() std::lock_guard lock(srcReqMsgLock_); srcReqMsg_ = ""; isNeedProcCachedSrcReqMsg_ = false; + std::lock_guard guard(sessionKeyIdMutex_); + sessionKeyIdAsyncResult_.clear(); } pincodeDialogEverShown_ = false; serviceInfoProfile_ = {}; @@ -2187,6 +2190,15 @@ bool DmAuthManager::IsImportedAuthCodeValid() return false; } +bool DmAuthManager::IsSrc() +{ + if (authRequestState_ != nullptr) { + return true; + } else { + return false; + } +} + bool DmAuthManager::IsAuthTypeSupported(const int32_t &authType) { if (authenticationMap_.find(authType) == authenticationMap_.end()) { @@ -2493,13 +2505,52 @@ void DmAuthManager::AuthDeviceSessionKey(int64_t requestId, const uint8_t *sessi } } authResponseContext_->localSessionKeyId = 0; + { + std::lock_guard guard(sessionKeyIdMutex_); + sessionKeyIdAsyncResult_.clear(); + sessionKeyIdAsyncResult_[requestId] = std::optional(); + } unsigned char hash[SHA256_DIGEST_LENGTH] = { 0 }; Crypto::DmGenerateStrHash(sessionKey, sessionKeyLen, hash, SHA256_DIGEST_LENGTH, 0); - int32_t sessionKeyId = 0; - int32_t ret = DeviceProfileConnector::GetInstance().PutSessionKey(hash, SHA256_DIGEST_LENGTH, sessionKeyId); - if (ret == DM_OK && sessionKeyId > 0) { - authResponseContext_->localSessionKeyId = sessionKeyId; + std::vector hashVector(hash, hash + SHA256_DIGEST_LENGTH); + std::shared_ptr sharePtrThis = shared_from_this(); + auto asyncTaskFunc = [sharePtrThis, requestId, hashVector]() { + sharePtrThis->PutSessionKeyAsync(requestId, hashVector); + }; + ffrt::submit(asyncTaskFunc, ffrt::task_attr().delay(0)); +} + +void DmAuthManager::PutSessionKeyAsync(int64_t requestId, std::vector hash) +{ + { + std::lock_guard guard(sessionKeyIdMutex_); + int32_t sessionKeyId = 0; + int32_t ret = DeviceProfileConnector::GetInstance().PutSessionKey(hash, sessionKeyId); + if (ret != DM_OK) { + LOGI("PutSessionKey failed."); + sessionKeyId = 0; + } + sessionKeyIdAsyncResult_[requestId] = sessionKeyId; + } + sessionKeyIdCondition_.notify_one(); +} + +int32_t DmAuthManager::GetSessionKeyIdSync(int64_t requestId) +{ + std::unique_lock guard(sessionKeyIdMutex_); + if (sessionKeyIdAsyncResult_.find(requestId) == sessionKeyIdAsyncResult_.end()) { + LOGW("GetSessionKeyIdSync failed, not find by requestId"); + return 0; + } + if (sessionKeyIdAsyncResult_[requestId].has_value()) { + LOGI("GetSessionKeyIdSync, already ready"); + return sessionKeyIdAsyncResult_[requestId].value(); } + LOGI("GetSessionKeyIdSync need wait"); + sessionKeyIdCondition_.wait_for(guard, std::chrono::milliseconds(MAX_PUT_SESSIONKEY_TIMEOUT)); + int32_t keyid = sessionKeyIdAsyncResult_[requestId].value_or(0); + LOGI("GetSessionKeyIdSync exit"); + return keyid; } void DmAuthManager::GetRemoteDeviceId(std::string &deviceId) @@ -3253,6 +3304,7 @@ void DmAuthManager::JoinLnn(const std::string &deviceId, bool isForceJoin) CHECK_NULL_VOID(authResponseContext_); CHECK_NULL_VOID(softbusConnector_); if (IsHmlSessionType()) { + authResponseContext_->localSessionKeyId = GetSessionKeyIdSync(authResponseContext_->requestId); softbusConnector_->JoinLnnByHml(authRequestContext_->sessionId, authResponseContext_->localSessionKeyId, authResponseContext_->remoteSessionKeyId); return; diff --git a/test/commonunittest/UTTest_dm_auth_manager_first.cpp b/test/commonunittest/UTTest_dm_auth_manager_first.cpp index 1b8f73341..eb246dde7 100644 --- a/test/commonunittest/UTTest_dm_auth_manager_first.cpp +++ b/test/commonunittest/UTTest_dm_auth_manager_first.cpp @@ -1010,6 +1010,7 @@ HWTEST_F(DmAuthManagerTest, AuthDeviceError005, testing::ext::TestSize.Level0) authManager_->AuthDeviceError(requestId, errorCode); authManager_->AuthDeviceSessionKey(requestId, nullptr, sessionKeyLen); ASSERT_EQ(authManager_->isAuthDevice_, false); + authManager_->GetSessionKeyIdSync(requestId); } HWTEST_F(DmAuthManagerTest, AuthDeviceError006, testing::ext::TestSize.Level0) @@ -1033,6 +1034,7 @@ HWTEST_F(DmAuthManagerTest, AuthDeviceSessionKey001, testing::ext::TestSize.Leve uint32_t sessionKeyLen = 0; authManager_->AuthDeviceSessionKey(requestId, sessionKey, sessionKeyLen); ASSERT_EQ(authManager_->isAuthDevice_, false); + authManager_->GetSessionKeyIdSync(requestId); } HWTEST_F(DmAuthManagerTest, GetRemoteDeviceId001, testing::ext::TestSize.Level0) @@ -2060,9 +2062,10 @@ HWTEST_F(DmAuthManagerTest, CheckNeedShowAuthInfoDialog_001, testing::ext::TestS authManager_->authResponseContext_->requestId = 1; authManager_->authMessageProcessor_ = std::make_shared(authManager_); EXPECT_CALL(*cryptoMgrMock_, SaveSessionKey(_, _)).WillOnce(Return(DM_OK)); - EXPECT_CALL(*deviceProfileConnectorMock_, PutSessionKey(_, _, _)) - .WillOnce(DoAll(SetArgReferee<2>(1), Return(DM_OK))); + EXPECT_CALL(*deviceProfileConnectorMock_, PutSessionKey(_, _)) + .WillOnce(DoAll(SetArgReferee<1>(1), Return(DM_OK))); authManager_->AuthDeviceSessionKey(requestId, sessionKey, sessionKeyLen); + authManager_->GetSessionKeyIdSync(requestId); } HWTEST_F(DmAuthManagerTest, IsPinCodeValid_001, testing::ext::TestSize.Level0) diff --git a/test/unittest/mock/deviceprofile_connector_mock.cpp b/test/unittest/mock/deviceprofile_connector_mock.cpp index 15a6be1e2..be3dd7f8d 100644 --- a/test/unittest/mock/deviceprofile_connector_mock.cpp +++ b/test/unittest/mock/deviceprofile_connector_mock.cpp @@ -126,9 +126,9 @@ int32_t DeviceProfileConnector::GetServiceInfoProfileListByBundleName( serviceInfoProfiles); } -int32_t DeviceProfileConnector::PutSessionKey(const uint8_t* sessionKey, uint32_t length, int32_t& sessionKeyId) +int32_t DeviceProfileConnector::PutSessionKey(const std::vector &sessionKeyArray, int32_t &sessionKeyId) { - return DmDeviceProfileConnector::dmDeviceProfileConnector->PutSessionKey(sessionKey, length, sessionKeyId); + return DmDeviceProfileConnector::dmDeviceProfileConnector->PutSessionKey(sessionKeyArray, sessionKeyId); } } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/deviceprofile_connector_mock.h b/test/unittest/mock/deviceprofile_connector_mock.h index f6096c8b3..fc11aeb8d 100644 --- a/test/unittest/mock/deviceprofile_connector_mock.h +++ b/test/unittest/mock/deviceprofile_connector_mock.h @@ -56,7 +56,7 @@ public: virtual int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId) = 0; virtual int32_t GetServiceInfoProfileListByBundleName(const DistributedDeviceProfile::ServiceInfoUniqueKey& key, std::vector& serviceInfoProfiles) = 0; - virtual int32_t PutSessionKey(const uint8_t* sessionKey, uint32_t length, int32_t& sessionKeyId) = 0; + virtual int32_t PutSessionKey(const std::vector &sessionKeyArray, int32_t &sessionKeyId) = 0; public: static inline std::shared_ptr dmDeviceProfileConnector = nullptr; }; @@ -87,7 +87,7 @@ public: MOCK_METHOD(int32_t, CheckDeviceInfoPermission, (const std::string &, const std::string &)); MOCK_METHOD(int32_t, GetServiceInfoProfileListByBundleName, (const DistributedDeviceProfile::ServiceInfoUniqueKey&, (std::vector&))); - MOCK_METHOD(int32_t, PutSessionKey, (const uint8_t*, uint32_t, int32_t&)); + MOCK_METHOD(int32_t, PutSessionKey, (const std::vector &, int32_t&)); }; } } -- Gitee From 267594b59beadbb2b2571dd3ced64fbf86c15e75 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 6 Mar 2025 20:02:51 +0800 Subject: [PATCH 2/2] serviceinfo to localserviceinfo Signed-off-by: zhuzhihui7 Change-Id: I1d696a318680f1dbee57cb83f411f0111be36385 --- .../device_manager_ipc_interface_code.h | 10 +- .../include/ipc/model/ipc_common_param_req.h | 10 +- .../include/ipc/model/ipc_gen_serviceid_rsp.h | 43 ---- ...d_rsp.h => ipc_get_localserviceinfo_rsp.h} | 16 +- .../model/ipc_get_serviceinfo_bycaller_rsp.h | 45 ---- .../ipc/model/ipc_register_serviceinfo_req.h | 6 +- common/include/ipc/standard/ipc_model_codec.h | 8 +- common/src/ipc/standard/ipc_model_codec.cpp | 38 +--- .../include/deviceprofile_connector.h | 17 +- .../src/deviceprofile_connector.cpp | 51 +---- .../native_cpp/include/device_manager.h | 11 +- .../native_cpp/include/device_manager_impl.h | 11 +- .../native_cpp/include/dm_device_info.h | 19 +- .../native_cpp/src/device_manager_impl.cpp | 76 ++----- .../src/ipc/standard/ipc_cmd_parser.cpp | 112 +++------- .../authentication/auth_message_processor.h | 1 - .../include/authentication/dm_auth_manager.h | 8 +- .../authentication/auth_message_processor.cpp | 11 - .../src/authentication/dm_auth_manager.cpp | 87 +++----- .../service/include/device_manager_service.h | 24 +- .../service/src/device_manager_service.cpp | 206 ++++-------------- .../src/ipc/standard/ipc_cmd_parser.cpp | 68 ++---- .../UTTest_dm_auth_manager_first.cpp | 60 +++-- .../UTTest_auth_message_processor.cpp | 1 - .../unittest/UTTest_ipc_cmd_parser_client.cpp | 192 +++------------- .../mock/deviceprofile_connector_mock.cpp | 9 +- .../mock/deviceprofile_connector_mock.h | 8 +- 27 files changed, 308 insertions(+), 840 deletions(-) delete mode 100644 common/include/ipc/model/ipc_gen_serviceid_rsp.h rename common/include/ipc/model/{ipc_get_serviceinfo_byid_rsp.h => ipc_get_localserviceinfo_rsp.h} (68%) delete mode 100644 common/include/ipc/model/ipc_get_serviceinfo_bycaller_rsp.h diff --git a/common/include/device_manager_ipc_interface_code.h b/common/include/device_manager_ipc_interface_code.h index cf417f0b0..2b30d3064 100644 --- a/common/include/device_manager_ipc_interface_code.h +++ b/common/include/device_manager_ipc_interface_code.h @@ -109,12 +109,10 @@ enum DMIpcCmdInterfaceCode { SET_LOCAL_DEVICE_NAME, SET_LOCAL_DEVICE_NAME_RESULT, GET_ALL_TRUST_DEVICE_LIST, - GEN_SERVICEID, - REG_SERVICE_INFO, - UNREG_SERVICE_INFO, - UPDATE_SERVICE_INFO, - GET_SERVICEINFO_BYID, - GET_SERVICEINFOS_CALLER, + REG_LOCALSERVICE_INFO, + UNREG_LOCALSERVICE_INFO, + UPDATE_LOCALSERVICE_INFO, + GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE, // Add ipc msg here IPC_MSG_BUTT }; diff --git a/common/include/ipc/model/ipc_common_param_req.h b/common/include/ipc/model/ipc_common_param_req.h index 135a23040..139f74d9b 100644 --- a/common/include/ipc/model/ipc_common_param_req.h +++ b/common/include/ipc/model/ipc_common_param_req.h @@ -64,19 +64,19 @@ public: secondParam_ = secondParam; } - int64_t GetInt64Param() const + int64_t GetInt32Param() const { - return int64Param_; + return int32Param_; } - void SetInt64Param(int64_t param) + void SetInt32Param(int64_t param) { - int64Param_ = param; + int32Param_ = param; } private: std::string firstParam_; std::string secondParam_; - int64_t int64Param_ = 0; + int64_t int32Param_ = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/common/include/ipc/model/ipc_gen_serviceid_rsp.h b/common/include/ipc/model/ipc_gen_serviceid_rsp.h deleted file mode 100644 index 74840316c..000000000 --- a/common/include/ipc/model/ipc_gen_serviceid_rsp.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2025 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_GEN_SERVICEID_RSP_H -#define OHOS_DM_IPC_GEN_SERVICEID_RSP_H - -#include "ipc_rsp.h" -#include "dm_device_info.h" - -namespace OHOS { -namespace DistributedHardware { -class IpcGenServiceIdRsp : public IpcRsp { - DECLARE_IPC_MODEL(IpcGenServiceIdRsp); - -public: - int64_t GetServiceId() const - { - return serviceId_; - } - - void SetServiceId(const int64_t &serviceId) - { - serviceId_ = serviceId; - } - -private: - int64_t serviceId_ = 0; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DM_IPC_GEN_SERVICEID_RSP_H diff --git a/common/include/ipc/model/ipc_get_serviceinfo_byid_rsp.h b/common/include/ipc/model/ipc_get_localserviceinfo_rsp.h similarity index 68% rename from common/include/ipc/model/ipc_get_serviceinfo_byid_rsp.h rename to common/include/ipc/model/ipc_get_localserviceinfo_rsp.h index cd3cd1396..98a8137c7 100644 --- a/common/include/ipc/model/ipc_get_serviceinfo_byid_rsp.h +++ b/common/include/ipc/model/ipc_get_localserviceinfo_rsp.h @@ -13,30 +13,30 @@ * limitations under the License. */ -#ifndef OHOS_DM_IPC_GET_SERVICEINFO_BYID_RSP_H -#define OHOS_DM_IPC_GET_SERVICEINFO_BYID_RSP_H +#ifndef OHOS_DM_IPC_GET_LOCALSERVICEINFO_RSP_H +#define OHOS_DM_IPC_GET_LOCALSERVICEINFO_RSP_H #include "ipc_req.h" #include "dm_device_info.h" namespace OHOS { namespace DistributedHardware { -class IpcGetServiceInfoByIdRsp : public IpcRsp { - DECLARE_IPC_MODEL(IpcGetServiceInfoByIdRsp); +class IpcGetLocalServiceInfoRsp : public IpcRsp { + DECLARE_IPC_MODEL(IpcGetLocalServiceInfoRsp); public: - const DMServiceInfo &GetServiceInfo() const + const DMLocalServiceInfo &GetLocalServiceInfo() const { return serviceInfo_; } - void SetServiceInfo(const DMServiceInfo &info) + void SetLocalServiceInfo(const DMLocalServiceInfo &info) { serviceInfo_ = info; } private: - DMServiceInfo serviceInfo_; + DMLocalServiceInfo serviceInfo_; }; } // namespace DistributedHardware } // namespace OHOS -#endif // OHOS_DM_IPC_GET_SERVICEINFO_BYID_RSP_H +#endif // OHOS_DM_IPC_GET_LOCALSERVICEINFO_RSP_H diff --git a/common/include/ipc/model/ipc_get_serviceinfo_bycaller_rsp.h b/common/include/ipc/model/ipc_get_serviceinfo_bycaller_rsp.h deleted file mode 100644 index c0090a8a1..000000000 --- a/common/include/ipc/model/ipc_get_serviceinfo_bycaller_rsp.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2025 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_GET_SERVICEINFO_BYCALLER_RSP_H -#define OHOS_DM_IPC_GET_SERVICEINFO_BYCALLER_RSP_H - -#include - -#include "dm_device_info.h" -#include "ipc_req.h" - -namespace OHOS { -namespace DistributedHardware { -class IpcGetServiceInfoByCallerRsp : public IpcRsp { - DECLARE_IPC_MODEL(IpcGetServiceInfoByCallerRsp); - -public: - const std::vector& GetServiceInfos() const - { - return serviceInfos_; - } - - void SetServiceInfos(const std::vector &infos) - { - serviceInfos_ = infos; - } - -private: - std::vector serviceInfos_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DM_IPC_GET_SERVICEINFO_BYCALLER_RSP_H diff --git a/common/include/ipc/model/ipc_register_serviceinfo_req.h b/common/include/ipc/model/ipc_register_serviceinfo_req.h index 02c68202a..d9308dc57 100644 --- a/common/include/ipc/model/ipc_register_serviceinfo_req.h +++ b/common/include/ipc/model/ipc_register_serviceinfo_req.h @@ -25,17 +25,17 @@ class IpcRegServiceInfoReq : public IpcReq { DECLARE_IPC_MODEL(IpcRegServiceInfoReq); public: - const DMServiceInfo &GetServiceInfo() const + const DMLocalServiceInfo &GetLocalServiceInfo() const { return serviceInfo_; } - void SetServiceInfo(const DMServiceInfo &info) + void SetLocalServiceInfo(const DMLocalServiceInfo &info) { serviceInfo_ = info; } private: - DMServiceInfo serviceInfo_; + DMLocalServiceInfo serviceInfo_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/common/include/ipc/standard/ipc_model_codec.h b/common/include/ipc/standard/ipc_model_codec.h index e608b4701..bbda493c4 100644 --- a/common/include/ipc/standard/ipc_model_codec.h +++ b/common/include/ipc/standard/ipc_model_codec.h @@ -50,10 +50,10 @@ public: static bool EncodeDmDeviceIconInfoFilterOptions(const DmDeviceIconInfoFilterOptions &filterOptions, MessageParcel &parcel); static void DecodeDmDeviceInfo(MessageParcel &parcel, DmDeviceInfo &devInfo); - static bool EncodeServiceInfo(const DMServiceInfo &serviceInfo, MessageParcel &parcel); - static bool EncodeServiceInfos(const std::vector &serviceInfos, MessageParcel &parcel); - static bool DecodeServiceInfo(MessageParcel &parcel, DMServiceInfo &serviceInfo); - static bool DecodeServiceInfos(MessageParcel &parcel, std::vector &serviceInfos); + static bool EncodeLocalServiceInfo(const DMLocalServiceInfo &serviceInfo, MessageParcel &parcel); + static bool EncodeLocalServiceInfos(const std::vector &serviceInfos, MessageParcel &parcel); + static bool DecodeLocalServiceInfo(MessageParcel &parcel, DMLocalServiceInfo &serviceInfo); + static bool DecodeLocalServiceInfos(MessageParcel &parcel, std::vector &serviceInfos); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/common/src/ipc/standard/ipc_model_codec.cpp b/common/src/ipc/standard/ipc_model_codec.cpp index 63024824f..d9597e00b 100644 --- a/common/src/ipc/standard/ipc_model_codec.cpp +++ b/common/src/ipc/standard/ipc_model_codec.cpp @@ -369,27 +369,20 @@ void IpcModelCodec::DecodeDmDeviceInfo(MessageParcel &parcel, DmDeviceInfo &devI devInfo.extraData = parcel.ReadString(); } -bool IpcModelCodec::EncodeServiceInfo(const DMServiceInfo &serviceInfo, MessageParcel &parcel) +bool IpcModelCodec::EncodeLocalServiceInfo(const DMLocalServiceInfo &serviceInfo, MessageParcel &parcel) { bool bRet = true; - bRet = (bRet && parcel.WriteInt64(serviceInfo.serviceId)); - bRet = (bRet && parcel.WriteString(serviceInfo.serviceType)); - bRet = (bRet && parcel.WriteString(serviceInfo.serviceName)); - bRet = (bRet && parcel.WriteString(serviceInfo.serviceDisplayName)); - bRet = (bRet && parcel.WriteString(serviceInfo.customData)); bRet = (bRet && parcel.WriteString(serviceInfo.bundleName)); - bRet = (bRet && parcel.WriteString(serviceInfo.moduleName)); - bRet = (bRet && parcel.WriteString(serviceInfo.abilityName)); bRet = (bRet && parcel.WriteInt32(serviceInfo.authBoxType)); bRet = (bRet && parcel.WriteInt32(serviceInfo.authType)); bRet = (bRet && parcel.WriteInt32(serviceInfo.pinExchangeType)); bRet = (bRet && parcel.WriteString(serviceInfo.pinCode)); bRet = (bRet && parcel.WriteString(serviceInfo.description)); - bRet = (bRet && parcel.WriteString(serviceInfo.serviceDiscoveryScope)); + bRet = (bRet && parcel.WriteString(serviceInfo.extraInfo)); return bRet; } -bool IpcModelCodec::EncodeServiceInfos(const std::vector &serviceInfos, MessageParcel &parcel) +bool IpcModelCodec::EncodeLocalServiceInfos(const std::vector &serviceInfos, MessageParcel &parcel) { uint32_t num = static_cast(serviceInfos.size()); if (!parcel.WriteUint32(num)) { @@ -398,45 +391,38 @@ bool IpcModelCodec::EncodeServiceInfos(const std::vector &service } bool bRet = true; for (uint32_t k = 0; k < num; k++) { - DMServiceInfo serviceInfo = serviceInfos[k]; - bRet = EncodeServiceInfo(serviceInfo, parcel); + DMLocalServiceInfo serviceInfo = serviceInfos[k]; + bRet = EncodeLocalServiceInfo(serviceInfo, parcel); if (!bRet) { - LOGE("EncodeServiceInfo failed"); + LOGE("EncodeLocalServiceInfo failed"); break; } } return bRet; } -bool IpcModelCodec::DecodeServiceInfo(MessageParcel &parcel, DMServiceInfo &serviceInfo) +bool IpcModelCodec::DecodeLocalServiceInfo(MessageParcel &parcel, DMLocalServiceInfo &serviceInfo) { - READ_HELPER_RET(parcel, Int64, serviceInfo.serviceId, false); - READ_HELPER_RET(parcel, String, serviceInfo.serviceType, false); - READ_HELPER_RET(parcel, String, serviceInfo.serviceName, false); - READ_HELPER_RET(parcel, String, serviceInfo.serviceDisplayName, false); - READ_HELPER_RET(parcel, String, serviceInfo.customData, false); READ_HELPER_RET(parcel, String, serviceInfo.bundleName, false); - READ_HELPER_RET(parcel, String, serviceInfo.moduleName, false); - READ_HELPER_RET(parcel, String, serviceInfo.abilityName, false); READ_HELPER_RET(parcel, Int32, serviceInfo.authBoxType, false); READ_HELPER_RET(parcel, Int32, serviceInfo.authType, false); READ_HELPER_RET(parcel, Int32, serviceInfo.pinExchangeType, false); READ_HELPER_RET(parcel, String, serviceInfo.pinCode, false); READ_HELPER_RET(parcel, String, serviceInfo.description, false); - READ_HELPER_RET(parcel, String, serviceInfo.serviceDiscoveryScope, false); + READ_HELPER_RET(parcel, String, serviceInfo.extraInfo, false); return true; } -bool IpcModelCodec::DecodeServiceInfos(MessageParcel &parcel, std::vector &serviceInfos) +bool IpcModelCodec::DecodeLocalServiceInfos(MessageParcel &parcel, std::vector &serviceInfos) { uint32_t num = 0; READ_HELPER_RET(parcel, Uint32, num, false); bool bRet = true; for (uint32_t k = 0; k < num; k++) { - DMServiceInfo serviceInfo; - bRet = DecodeServiceInfo(parcel, serviceInfo); + DMLocalServiceInfo serviceInfo; + bRet = DecodeLocalServiceInfo(parcel, serviceInfo); if (!bRet) { - LOGE("DecodeServiceInfo failed"); + LOGE("DecodeLocalServiceInfo failed"); break; } serviceInfos.emplace_back(serviceInfo); diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 1547a55da..911b57ec8 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -21,8 +21,7 @@ #include "dm_device_info.h" #include "dm_single_instance.h" #include "i_dp_inited_callback.h" -#include "service_info_profile.h" -#include "service_info_unique_key.h" +#include "local_service_info.h" #include "trusted_device_info.h" enum AllowAuthType { @@ -177,15 +176,11 @@ public: int32_t PutAllTrustedDevices(const std::vector &deviceInfos); int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId); int32_t UpdateAclDeviceName(const std::string &udid, const std::string &newDeviceName); - int32_t PutServiceInfoProfile(const DistributedDeviceProfile::ServiceInfoProfile &serviceInfoProfile); - int32_t DeleteServiceInfoProfile(const DistributedDeviceProfile::ServiceInfoUniqueKey &key); - int32_t UpdateServiceInfoProfile(const DistributedDeviceProfile::ServiceInfoProfile &serviceInfoProfile); - int32_t GetServiceInfoProfileByUniqueKey(const DistributedDeviceProfile::ServiceInfoUniqueKey &key, - DistributedDeviceProfile::ServiceInfoProfile &serviceInfoProfile); - int32_t GetServiceInfoProfileListByTokenId(const DistributedDeviceProfile::ServiceInfoUniqueKey &key, - std::vector &serviceInfoProfiles); - int32_t GetServiceInfoProfileListByBundleName(const DistributedDeviceProfile::ServiceInfoUniqueKey &key, - std::vector &serviceInfoProfiles); + int32_t PutLocalServiceInfo(const DistributedDeviceProfile::LocalServiceInfo &localServiceInfo); + int32_t DeleteLocalServiceInfo(const std::string &bundleName, int32_t pinExchangeType); + int32_t UpdateLocalServiceInfo(const DistributedDeviceProfile::LocalServiceInfo &localServiceInfo); + int32_t GetLocalServiceInfoByBundleNameAndPinExchangeType(const std::string &bundleName, + int32_t pinExchangeType, DistributedDeviceProfile::LocalServiceInfo &localServiceInfo); int32_t PutSessionKey(const std::vector &sessionKeyArray, int32_t &sessionKeyId); private: diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 75fefdc03..3142f0efe 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -1748,10 +1748,10 @@ int32_t DeviceProfileConnector::UpdateAclDeviceName(const std::string &udid, con return ERR_DM_FAILED; } -int32_t DeviceProfileConnector::PutServiceInfoProfile( - const DistributedDeviceProfile::ServiceInfoProfile &serviceInfoProfile) +int32_t DeviceProfileConnector::PutLocalServiceInfo( + const DistributedDeviceProfile::LocalServiceInfo &localServiceInfo) { - int32_t ret = DistributedDeviceProfileClient::GetInstance().PutServiceInfoProfile(serviceInfoProfile); + int32_t ret = DistributedDeviceProfileClient::GetInstance().PutLocalServiceInfo(localServiceInfo); if (ret != DM_OK) { LOGE("failed: %{public}d", ret); return ret; @@ -1759,9 +1759,9 @@ int32_t DeviceProfileConnector::PutServiceInfoProfile( return DM_OK; } -int32_t DeviceProfileConnector::DeleteServiceInfoProfile(const DistributedDeviceProfile::ServiceInfoUniqueKey &key) +int32_t DeviceProfileConnector::DeleteLocalServiceInfo(const std::string &bundleName, int32_t pinExchangeType) { - int32_t ret = DistributedDeviceProfileClient::GetInstance().DeleteServiceInfoProfile(key); + int32_t ret = DistributedDeviceProfileClient::GetInstance().DeleteLocalServiceInfo(bundleName, pinExchangeType); if (ret != DM_OK) { LOGE("failed: %{public}d", ret); return ret; @@ -1769,10 +1769,10 @@ int32_t DeviceProfileConnector::DeleteServiceInfoProfile(const DistributedDevice return DM_OK; } -int32_t DeviceProfileConnector::UpdateServiceInfoProfile( - const DistributedDeviceProfile::ServiceInfoProfile &serviceInfoProfile) +int32_t DeviceProfileConnector::UpdateLocalServiceInfo( + const DistributedDeviceProfile::LocalServiceInfo &localServiceInfo) { - int32_t ret = DistributedDeviceProfileClient::GetInstance().UpdateServiceInfoProfile(serviceInfoProfile); + int32_t ret = DistributedDeviceProfileClient::GetInstance().UpdateLocalServiceInfo(localServiceInfo); if (ret != DM_OK) { LOGE("failed: %{public}d", ret); return ret; @@ -1780,38 +1780,11 @@ int32_t DeviceProfileConnector::UpdateServiceInfoProfile( return DM_OK; } -int32_t DeviceProfileConnector::GetServiceInfoProfileByUniqueKey( - const DistributedDeviceProfile::ServiceInfoUniqueKey &key, - DistributedDeviceProfile::ServiceInfoProfile &serviceInfoProfile) +int32_t DeviceProfileConnector::GetLocalServiceInfoByBundleNameAndPinExchangeType(const std::string &bundleName, + int32_t pinExchangeType, DistributedDeviceProfile::LocalServiceInfo &localServiceInfo) { - int32_t ret = DistributedDeviceProfileClient::GetInstance().GetServiceInfoProfileByUniqueKey( - key, serviceInfoProfile); - if (ret != DM_OK) { - LOGE("failed: %{public}d", ret); - return ret; - } - return DM_OK; -} - -int32_t DeviceProfileConnector::GetServiceInfoProfileListByTokenId( - const DistributedDeviceProfile::ServiceInfoUniqueKey &key, - std::vector &serviceInfoProfiles) -{ - int32_t ret = DistributedDeviceProfileClient::GetInstance().GetServiceInfoProfileListByTokenId( - key, serviceInfoProfiles); - if (ret != DM_OK) { - LOGE("failed: %{public}d", ret); - return ret; - } - return DM_OK; -} - -int32_t DeviceProfileConnector::GetServiceInfoProfileListByBundleName( - const DistributedDeviceProfile::ServiceInfoUniqueKey &key, - std::vector &serviceInfoProfiles) -{ - int32_t ret = DistributedDeviceProfileClient::GetInstance().GetServiceInfoProfileListByBundleName( - key, serviceInfoProfiles); + int32_t ret = DistributedDeviceProfileClient::GetInstance().GetLocalServiceInfoByBundleAndPinType(bundleName, + pinExchangeType, localServiceInfo); if (ret != DM_OK) { LOGE("failed: %{public}d", ret); return ret; diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h index cdb13a58f..54b34081c 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager.h @@ -647,12 +647,11 @@ public: const std::vector &deviceProfileInfoList) = 0; virtual int32_t GetLocalDisplayDeviceName(const std::string &pkgName, int32_t maxNameLength, std::string &displayName) = 0; - virtual int32_t GenerateServiceId(int64_t &serviceId) = 0; - virtual int32_t RegisterServiceInfo(const DMServiceInfo &info) = 0; - virtual int32_t UnRegisterServiceInfo(int64_t serviceId) = 0; - virtual int32_t UpdateServiceInfo(const DMServiceInfo &info) = 0; - virtual int32_t GetServiceInfoByServiceId(int64_t serviceId, DMServiceInfo &info) = 0; - virtual int32_t GetCallerServiceInfos(std::vector &serviceInfos) = 0; + virtual int32_t RegisterLocalServiceInfo(const DMLocalServiceInfo &info) = 0; + virtual int32_t UnRegisterLocalServiceInfo(const std::string &bundleName, int32_t pinExchangeType) = 0; + virtual int32_t UpdateLocalServiceInfo(const DMLocalServiceInfo &info) = 0; + virtual int32_t GetLocalServiceInfoByBundleNameAndPinExchangeType(const std::string &bundleName, + int32_t pinExchangeType, DMLocalServiceInfo &info) = 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 38004d941..485ea6e27 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -420,12 +420,11 @@ public: const std::vector &deviceProfileInfoList) override; virtual int32_t GetLocalDisplayDeviceName(const std::string &pkgName, int32_t maxNameLength, std::string &displayName) override; - virtual int32_t GenerateServiceId(int64_t &serviceId) override; - virtual int32_t RegisterServiceInfo(const DMServiceInfo &info) override; - virtual int32_t UnRegisterServiceInfo(int64_t serviceId) override; - virtual int32_t UpdateServiceInfo(const DMServiceInfo &info) override; - virtual int32_t GetServiceInfoByServiceId(int64_t serviceId, DMServiceInfo &info) override; - virtual int32_t GetCallerServiceInfos(std::vector &serviceInfos) override; + virtual int32_t RegisterLocalServiceInfo(const DMLocalServiceInfo &info) override; + virtual int32_t UnRegisterLocalServiceInfo(const std::string &bundleName, int32_t pinExchangeType) override; + virtual int32_t UpdateLocalServiceInfo(const DMLocalServiceInfo &info) override; + virtual int32_t GetLocalServiceInfoByBundleNameAndPinExchangeType(const std::string &bundleName, + int32_t pinExchangeType, DMLocalServiceInfo &info) override; private: 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 5e2887109..8a13dfc19 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -419,40 +419,33 @@ typedef struct DmNotifyKey { } } DmNotifyKey; -enum class DMServiceInfoAuthType : int32_t { +enum class DMLocalServiceInfoAuthType : int32_t { TRUST_ONETIME = 0, TRUST_ALWAYS = 6, CANCEL = 1 }; -enum class DMServiceInfoPinExchangeType : int32_t { +enum class DMLocalServiceInfoPinExchangeType : int32_t { PINBOX = 1, ULTRASOUND = 2, FROMDP = 3 }; -enum class DMServiceInfoAuthBoxType : int32_t { +enum class DMLocalServiceInfoAuthBoxType : int32_t { STATE3 = 1, SKIP_CONFIRM = 2, TWO_IN1 = 3 }; -typedef struct DMServiceInfo { - int64_t serviceId = 0; - std::string serviceType; - std::string serviceName; - std::string serviceDisplayName; - std::string customData; +typedef struct DMLocalServiceInfo { std::string bundleName; - std::string moduleName; - std::string abilityName; int32_t authBoxType = 0; int32_t authType = 0; int32_t pinExchangeType = 0; std::string pinCode; std::string description; - std::string serviceDiscoveryScope; -} DMServiceInfo; + std::string extraInfo; +} DMLocalServiceInfo; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_DEVICE_INFO_H \ No newline at end of file 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 a1d0d4fc8..6c0d3e70a 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -34,7 +34,6 @@ #include "ipc_destroy_pin_holder_req.h" #include "ipc_export_auth_code_rsp.h" #include "ipc_generate_encrypted_uuid_req.h" -#include "ipc_gen_serviceid_rsp.h" #include "ipc_get_anony_local_udid_rsp.h" #include "ipc_get_device_icon_info_req.h" #include "ipc_get_device_info_rsp.h" @@ -46,8 +45,7 @@ #include "ipc_get_local_device_info_rsp.h" #include "ipc_get_local_display_device_name_req.h" #include "ipc_get_local_display_device_name_rsp.h" -#include "ipc_get_serviceinfo_bycaller_rsp.h" -#include "ipc_get_serviceinfo_byid_rsp.h" +#include "ipc_get_localserviceinfo_rsp.h" #include "ipc_get_trustdevice_req.h" #include "ipc_get_trustdevice_rsp.h" #include "ipc_import_auth_code_req.h" @@ -2735,33 +2733,13 @@ int32_t DeviceManagerImpl::GetLocalDisplayDeviceName(const std::string &pkgName, return DM_OK; } -int32_t DeviceManagerImpl::GenerateServiceId(int64_t &serviceId) -{ - LOGI("Start"); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - int32_t ret = ipcClientProxy_->SendRequest(GEN_SERVICEID, req, rsp); - if (ret != DM_OK) { - LOGE("Send Request failed ret: %{public}d", ret); - return ERR_DM_IPC_SEND_REQUEST_FAILED; - } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("Failed with ret %{public}d", ret); - return ret; - } - serviceId = rsp->GetServiceId(); - LOGI("Completed, serviceId %{public}" PRId64, serviceId); - return DM_OK; -} - -int32_t DeviceManagerImpl::RegisterServiceInfo(const DMServiceInfo &info) +int32_t DeviceManagerImpl::RegisterLocalServiceInfo(const DMLocalServiceInfo &info) { LOGI("Start"); std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); - req->SetServiceInfo(info); - int32_t ret = ipcClientProxy_->SendRequest(REG_SERVICE_INFO, req, rsp); + req->SetLocalServiceInfo(info); + int32_t ret = ipcClientProxy_->SendRequest(REG_LOCALSERVICE_INFO, req, rsp); if (ret != DM_OK) { LOGE("Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; @@ -2775,13 +2753,14 @@ int32_t DeviceManagerImpl::RegisterServiceInfo(const DMServiceInfo &info) return DM_OK; } -int32_t DeviceManagerImpl::UnRegisterServiceInfo(int64_t serviceId) +int32_t DeviceManagerImpl::UnRegisterLocalServiceInfo(const std::string &bundleName, int32_t pinExchangeType) { LOGI("Start"); std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); - req->SetInt64Param(serviceId); - int32_t ret = ipcClientProxy_->SendRequest(UNREG_SERVICE_INFO, req, rsp); + req->SetFirstParam(bundleName); + req->SetInt32Param(pinExchangeType); + int32_t ret = ipcClientProxy_->SendRequest(UNREG_LOCALSERVICE_INFO, req, rsp); if (ret != DM_OK) { LOGE("Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; @@ -2795,13 +2774,13 @@ int32_t DeviceManagerImpl::UnRegisterServiceInfo(int64_t serviceId) return DM_OK; } -int32_t DeviceManagerImpl::UpdateServiceInfo(const DMServiceInfo &info) +int32_t DeviceManagerImpl::UpdateLocalServiceInfo(const DMLocalServiceInfo &info) { LOGI("Start"); std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); - req->SetServiceInfo(info); - int32_t ret = ipcClientProxy_->SendRequest(UPDATE_SERVICE_INFO, req, rsp); + req->SetLocalServiceInfo(info); + int32_t ret = ipcClientProxy_->SendRequest(UPDATE_LOCALSERVICE_INFO, req, rsp); if (ret != DM_OK) { LOGE("Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; @@ -2815,13 +2794,14 @@ int32_t DeviceManagerImpl::UpdateServiceInfo(const DMServiceInfo &info) return DM_OK; } -int32_t DeviceManagerImpl::GetServiceInfoByServiceId(int64_t serviceId, DMServiceInfo &info) +int32_t DeviceManagerImpl::GetLocalServiceInfoByBundleNameAndPinExchangeType( + const std::string &bundleName, int32_t pinExchangeType, DMLocalServiceInfo &info) { - LOGI("Start GetServiceInfoByServiceId, %{public}" PRId64, serviceId); std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetInt64Param(serviceId); - int32_t ret = ipcClientProxy_->SendRequest(GET_SERVICEINFO_BYID, req, rsp); + std::shared_ptr rsp = std::make_shared(); + req->SetFirstParam(bundleName); + req->SetInt32Param(pinExchangeType); + int32_t ret = ipcClientProxy_->SendRequest(GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE, req, rsp); if (ret != DM_OK) { LOGE("Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; @@ -2831,29 +2811,9 @@ int32_t DeviceManagerImpl::GetServiceInfoByServiceId(int64_t serviceId, DMServic LOGE("Failed with ret %{public}d", ret); return ret; } - info = rsp->GetServiceInfo(); + info = rsp->GetLocalServiceInfo(); LOGI("Completed"); return DM_OK; } - -int32_t DeviceManagerImpl::GetCallerServiceInfos(std::vector &serviceInfos) -{ - LOGI("Start"); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - int32_t ret = ipcClientProxy_->SendRequest(GET_SERVICEINFOS_CALLER, req, rsp); - if (ret != DM_OK) { - LOGE("Send Request failed ret: %{public}d", ret); - return ERR_DM_IPC_SEND_REQUEST_FAILED; - } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("Failed with ret %{public}d", ret); - return ret; - } - serviceInfos = rsp->GetServiceInfos(); - LOGI("Completed, serviceInfos size %{public}zu", serviceInfos.size()); - return DM_OK; -} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file 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 5709b6e4a..9e95dd811 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 @@ -32,7 +32,6 @@ #include "ipc_def.h" #include "ipc_export_auth_code_rsp.h" #include "ipc_generate_encrypted_uuid_req.h" -#include "ipc_gen_serviceid_rsp.h" #include "ipc_get_anony_local_udid_rsp.h" #include "ipc_get_device_icon_info_req.h" #include "ipc_get_device_info_rsp.h" @@ -45,8 +44,7 @@ #include "ipc_get_local_device_info_rsp.h" #include "ipc_get_local_display_device_name_req.h" #include "ipc_get_local_display_device_name_rsp.h" -#include "ipc_get_serviceinfo_byid_rsp.h" -#include "ipc_get_serviceinfo_bycaller_rsp.h" +#include "ipc_get_localserviceinfo_rsp.h" #include "ipc_get_trustdevice_req.h" #include "ipc_get_trustdevice_rsp.h" #include "ipc_import_auth_code_req.h" @@ -1855,45 +1853,22 @@ ON_IPC_READ_RESPONSE(GET_LOCAL_DISPLAY_DEVICE_NAME, MessageParcel &reply, std::s return DM_OK; } -ON_IPC_SET_REQUEST(GEN_SERVICEID, std::shared_ptr pBaseReq, MessageParcel &data) -{ - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - return ERR_DM_FAILED; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(GEN_SERVICEID, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); - if (pRsp == nullptr) { - LOGE("pRsp is null"); - return ERR_DM_FAILED; - } - pRsp->SetErrCode(reply.ReadInt32()); - if (pRsp->GetErrCode() == DM_OK) { - pRsp->SetServiceId(reply.ReadInt64()); - } - return DM_OK; -} - -ON_IPC_SET_REQUEST(REG_SERVICE_INFO, std::shared_ptr pBaseReq, MessageParcel &data) +ON_IPC_SET_REQUEST(REG_LOCALSERVICE_INFO, std::shared_ptr pBaseReq, MessageParcel &data) { if (pBaseReq == nullptr) { LOGE("pBaseReq is null"); return ERR_DM_FAILED; } std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - const DMServiceInfo& info = pReq->GetServiceInfo(); - if (!IpcModelCodec::EncodeServiceInfo(info, data)) { - LOGE("EncodeServiceInfo failed"); + const DMLocalServiceInfo& info = pReq->GetLocalServiceInfo(); + if (!IpcModelCodec::EncodeLocalServiceInfo(info, data)) { + LOGE("EncodeLocalServiceInfo failed"); return ERR_DM_IPC_WRITE_FAILED; } return DM_OK; } -ON_IPC_READ_RESPONSE(REG_SERVICE_INFO, MessageParcel &reply, std::shared_ptr pBaseRsp) +ON_IPC_READ_RESPONSE(REG_LOCALSERVICE_INFO, MessageParcel &reply, std::shared_ptr pBaseRsp) { if (pBaseRsp == nullptr) { LOGE("pBaseRsp is null"); @@ -1903,21 +1878,25 @@ ON_IPC_READ_RESPONSE(REG_SERVICE_INFO, MessageParcel &reply, std::shared_ptr pBaseReq, MessageParcel &data) +ON_IPC_SET_REQUEST(UNREG_LOCALSERVICE_INFO, std::shared_ptr pBaseReq, MessageParcel &data) { if (pBaseReq == nullptr) { LOGE("pBaseReq is null"); return ERR_DM_FAILED; } std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - int64_t serviceId = pReq->GetInt64Param(); - if (!data.WriteInt64(serviceId)) { + std::string bundleName = pReq->GetFirstParam(); + int64_t pinExchangeType = pReq->GetInt32Param(); + if (!data.WriteString(bundleName)) { + return ERR_DM_IPC_WRITE_FAILED; + } + if (!data.WriteInt32(pinExchangeType)) { return ERR_DM_IPC_WRITE_FAILED; } return DM_OK; } -ON_IPC_READ_RESPONSE(UNREG_SERVICE_INFO, MessageParcel &reply, std::shared_ptr pBaseRsp) +ON_IPC_READ_RESPONSE(UNREG_LOCALSERVICE_INFO, MessageParcel &reply, std::shared_ptr pBaseRsp) { if (pBaseRsp == nullptr) { LOGE("pBaseRsp is null"); @@ -1927,22 +1906,22 @@ ON_IPC_READ_RESPONSE(UNREG_SERVICE_INFO, MessageParcel &reply, std::shared_ptr pBaseReq, MessageParcel &data) +ON_IPC_SET_REQUEST(UPDATE_LOCALSERVICE_INFO, std::shared_ptr pBaseReq, MessageParcel &data) { if (pBaseReq == nullptr) { LOGE("pBaseReq is null"); return ERR_DM_FAILED; } std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - const DMServiceInfo& info = pReq->GetServiceInfo(); - if (!IpcModelCodec::EncodeServiceInfo(info, data)) { - LOGE("EncodeServiceInfo failed"); + const DMLocalServiceInfo& info = pReq->GetLocalServiceInfo(); + if (!IpcModelCodec::EncodeLocalServiceInfo(info, data)) { + LOGE("EncodeLocalServiceInfo failed"); return ERR_DM_IPC_WRITE_FAILED; } return DM_OK; } -ON_IPC_READ_RESPONSE(UPDATE_SERVICE_INFO, MessageParcel &reply, std::shared_ptr pBaseRsp) +ON_IPC_READ_RESPONSE(UPDATE_LOCALSERVICE_INFO, MessageParcel &reply, std::shared_ptr pBaseRsp) { if (pBaseRsp == nullptr) { LOGE("pBaseRsp is null"); @@ -1952,50 +1931,27 @@ ON_IPC_READ_RESPONSE(UPDATE_SERVICE_INFO, MessageParcel &reply, std::shared_ptr< return DM_OK; } -ON_IPC_SET_REQUEST(GET_SERVICEINFO_BYID, std::shared_ptr pBaseReq, MessageParcel &data) +ON_IPC_SET_REQUEST(GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE, std::shared_ptr pBaseReq, + MessageParcel &data) { if (pBaseReq == nullptr) { LOGE("pBaseReq is null"); return ERR_DM_FAILED; } std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - int64_t serviceId = pReq->GetInt64Param(); - if (!data.WriteInt64(serviceId)) { + std::string bundleName = pReq->GetFirstParam(); + int32_t pinExchangeType = pReq->GetInt32Param(); + if (!data.WriteString(bundleName)) { return ERR_DM_IPC_WRITE_FAILED; } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(GET_SERVICEINFO_BYID, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } - pBaseRsp->SetErrCode(reply.ReadInt32()); - if (pBaseRsp->GetErrCode() == DM_OK) { - std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); - DMServiceInfo info; - bool ret = IpcModelCodec::DecodeServiceInfo(reply, info); - if (!ret) { - LOGE("DecodeServiceInfo failed"); - pBaseRsp->SetErrCode(ERR_DM_IPC_READ_FAILED); - } - pRsp->SetServiceInfo(info); - } - return DM_OK; -} - -ON_IPC_SET_REQUEST(GET_SERVICEINFOS_CALLER, std::shared_ptr pBaseReq, MessageParcel &data) -{ - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - return ERR_DM_FAILED; + if (!data.WriteInt32(pinExchangeType)) { + return ERR_DM_IPC_WRITE_FAILED; } return DM_OK; } -ON_IPC_READ_RESPONSE(GET_SERVICEINFOS_CALLER, MessageParcel &reply, std::shared_ptr pBaseRsp) +ON_IPC_READ_RESPONSE(GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE, MessageParcel &reply, + std::shared_ptr pBaseRsp) { if (pBaseRsp == nullptr) { LOGE("pBaseRsp is null"); @@ -2003,15 +1959,15 @@ ON_IPC_READ_RESPONSE(GET_SERVICEINFOS_CALLER, MessageParcel &reply, std::shared_ } pBaseRsp->SetErrCode(reply.ReadInt32()); if (pBaseRsp->GetErrCode() == DM_OK) { - std::shared_ptr pRsp = - std::static_pointer_cast(pBaseRsp); - std::vector infos; - bool ret = IpcModelCodec::DecodeServiceInfos(reply, infos); + std::shared_ptr pRsp = + std::static_pointer_cast(pBaseRsp); + DMLocalServiceInfo info; + bool ret = IpcModelCodec::DecodeLocalServiceInfo(reply, info); if (!ret) { - LOGE("DecodeServiceInfo failed"); + LOGE("DecodeLocalServiceInfo failed"); pBaseRsp->SetErrCode(ERR_DM_IPC_READ_FAILED); } - pRsp->SetServiceInfos(infos); + pRsp->SetLocalServiceInfo(info); } return DM_OK; } diff --git a/services/implementation/include/authentication/auth_message_processor.h b/services/implementation/include/authentication/auth_message_processor.h index 9b5e864fc..1f766dd68 100644 --- a/services/implementation/include/authentication/auth_message_processor.h +++ b/services/implementation/include/authentication/auth_message_processor.h @@ -43,7 +43,6 @@ extern const char* TAG_INDEX; extern const char* TAG_SLICE_NUM; extern const char* TAG_IS_AUTH_CODE_READY; extern const char* TAG_IS_SHOW_DIALOG; -extern const char* TAG_SRC_PINCODE_IMPORTED; extern const char* TAG_TOKEN; extern const char* TAG_CRYPTO_NAME; extern const char* TAG_CRYPTO_VERSION; diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 0bb4f2ef2..f73367c7a 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -197,7 +197,6 @@ typedef struct DmAuthResponseContext { std::string edition; int32_t localBindLevel; std::string remoteDeviceName; - bool isSrcPincodeImported = false; int32_t localSessionKeyId = 0; int32_t remoteSessionKeyId = 0; } DmAuthResponseContext; @@ -489,12 +488,11 @@ public: private: bool IsHmlSessionType(); bool CanUsePincodeFromDp(); - void InitServiceInfoUniqueKey(DistributedDeviceProfile::ServiceInfoUniqueKey &key); bool IsServiceInfoAuthTypeValid(int32_t authType); bool IsServiceInfoAuthBoxTypeValid(int32_t authBoxType); bool IsServiceInfoPinExchangeTypeValid(int32_t pinExchangeType); - bool IsServiceInfoProfileValid(const DistributedDeviceProfile::ServiceInfoProfile &profile); - void GetServiceInfoProfile(); + bool IsLocalServiceInfoValid(const DistributedDeviceProfile::LocalServiceInfo &localServiceInfo); + void GetLocalServiceInfoInDp(); bool CheckNeedShowAuthInfoDialog(int32_t errorCode); void UpdateInputPincodeDialog(int32_t errorCode); void JoinLnn(const std::string &deviceId, bool isForceJoin = false); @@ -625,7 +623,7 @@ private: bool isNeedProcCachedSrcReqMsg_ = false; std::string srcReqMsg_ = ""; int32_t authenticationType_ = USER_OPERATION_TYPE_ALLOW_AUTH; - DistributedDeviceProfile::ServiceInfoProfile serviceInfoProfile_; + DistributedDeviceProfile::LocalServiceInfo serviceInfoProfile_; bool pincodeDialogEverShown_ = false; std::string bundleName_ = ""; std::mutex sessionKeyIdMutex_; diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index 34dd05292..b0a52f004 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -38,7 +38,6 @@ const char* TAG_INDEX = "INDEX"; const char* TAG_SLICE_NUM = "SLICE"; const char* TAG_IS_AUTH_CODE_READY = "IS_AUTH_CODE_READY"; const char* TAG_IS_SHOW_DIALOG = "IS_SHOW_DIALOG"; -const char* TAG_SRC_PINCODE_IMPORTED = "TAG_SRC_PINCODE_IMPORTED"; const char* TAG_TOKEN = "TOKEN"; const char* TAG_CRYPTO_NAME = "CRYPTONAME"; const char* TAG_CRYPTO_VERSION = "CRYPTOVERSION"; @@ -286,13 +285,6 @@ void AuthMessageProcessor::CreateNegotiateMessage(nlohmann::json &json) json[TAG_HOST_PKGLABEL] = authResponseContext_->hostPkgLabel; json[TAG_EDITION] = authResponseContext_->edition; json[TAG_REMOTE_DEVICE_NAME] = authResponseContext_->remoteDeviceName; - if (authRequestContext_->authType != AUTH_TYPE_IMPORT_AUTH_CODE && IsPincodeImported()) { - LOGI("TAG_SRC_PINCODE_IMPORTED set"); - json[TAG_SRC_PINCODE_IMPORTED] = true; - } else { - LOGI("TAG_SRC_PINCODE_IMPORTED not set"); - json[TAG_SRC_PINCODE_IMPORTED] = false; - } } void AuthMessageProcessor::CreateRespNegotiateMessage(nlohmann::json &json) @@ -685,9 +677,6 @@ void AuthMessageProcessor::ParseNegotiateMessage(const nlohmann::json &json) authResponseContext_->remoteDeviceName = json[TAG_REMOTE_DEVICE_NAME].get(); } ParsePkgNegotiateMessage(json); - if (IsBool(json, TAG_SRC_PINCODE_IMPORTED)) { - authResponseContext_->isSrcPincodeImported = json[TAG_SRC_PINCODE_IMPORTED].get(); - } } void AuthMessageProcessor::ParseRespNegotiateMessage(const nlohmann::json &json) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 89a67e221..db51aa8d2 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -136,6 +136,7 @@ DmAuthManager::DmAuthManager(std::shared_ptr softbusConnector, authUiStateMgr_ = std::make_shared(listener_); authenticationMap_[AUTH_TYPE_IMPORT_AUTH_CODE] = nullptr; authenticationMap_[AUTH_TYPE_CRE] = nullptr; + authenticationMap_[AUTH_TYPE_NFC] = nullptr; dmVersion_ = DM_VERSION_5_0_5; } @@ -181,7 +182,7 @@ int32_t DmAuthManager::CheckAuthParamVaild(const std::string &pkgName, int32_t a return ERR_DM_AUTH_BUSINESS_BUSY; } - if ((authType == AUTH_TYPE_IMPORT_AUTH_CODE) && (!IsAuthCodeReady(pkgName))) { + if ((authType == AUTH_TYPE_IMPORT_AUTH_CODE || authType == AUTH_TYPE_NFC) && (!IsAuthCodeReady(pkgName))) { LOGE("Auth code not exist."); listener_->OnAuthResult(processInfo_, peerTargetId_.deviceId, "", STATUS_DM_AUTH_DEFAULT, ERR_DM_INPUT_PARA_INVALID); @@ -1567,30 +1568,16 @@ bool DmAuthManager::IsPinCodeValid(int32_t numpin) bool DmAuthManager::CanUsePincodeFromDp() { CHECK_NULL_RETURN(authResponseContext_, false); - return (authResponseContext_->authType != AUTH_TYPE_IMPORT_AUTH_CODE && - authResponseContext_->isSrcPincodeImported && + return (authResponseContext_->authType == AUTH_TYPE_NFC && IsPinCodeValid(serviceInfoProfile_.GetPinCode()) && - serviceInfoProfile_.GetPinExchangeType() == (int32_t)DMServiceInfoPinExchangeType::FROMDP); -} - -void DmAuthManager::InitServiceInfoUniqueKey(DistributedDeviceProfile::ServiceInfoUniqueKey &key) -{ - CHECK_NULL_VOID(authResponseContext_); - char localDeviceId[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - key.SetDeviceId(std::string(localDeviceId)); - key.SetBundleName(authResponseContext_->hostPkgName); - int32_t userId = MultipleUserConnector::GetFirstForegroundUserId(); - key.SetUserId(userId); - LOGI("localDeviceId %{public}s, bundleName %{public}s", - GetAnonyString(std::string(localDeviceId)).c_str(), GetAnonyString(authResponseContext_->hostPkgName).c_str()); + serviceInfoProfile_.GetPinExchangeType() == (int32_t)DMLocalServiceInfoPinExchangeType::FROMDP); } bool DmAuthManager::IsServiceInfoAuthTypeValid(int32_t authType) { - if (authType != (int32_t)DMServiceInfoAuthType::TRUST_ONETIME && - authType != (int32_t)DMServiceInfoAuthType::TRUST_ALWAYS && - authType != (int32_t)DMServiceInfoAuthType::CANCEL) { + if (authType != (int32_t)DMLocalServiceInfoAuthType::TRUST_ONETIME && + authType != (int32_t)DMLocalServiceInfoAuthType::TRUST_ALWAYS && + authType != (int32_t)DMLocalServiceInfoAuthType::CANCEL) { return false; } return true; @@ -1598,8 +1585,8 @@ bool DmAuthManager::IsServiceInfoAuthTypeValid(int32_t authType) bool DmAuthManager::IsServiceInfoAuthBoxTypeValid(int32_t authBoxType) { - if (authBoxType != (int32_t)DMServiceInfoAuthBoxType::STATE3 && - authBoxType != (int32_t)DMServiceInfoAuthBoxType::SKIP_CONFIRM) { + if (authBoxType != (int32_t)DMLocalServiceInfoAuthBoxType::STATE3 && + authBoxType != (int32_t)DMLocalServiceInfoAuthBoxType::SKIP_CONFIRM) { return false; } return true; @@ -1607,29 +1594,29 @@ bool DmAuthManager::IsServiceInfoAuthBoxTypeValid(int32_t authBoxType) bool DmAuthManager::IsServiceInfoPinExchangeTypeValid(int32_t pinExchangeType) { - if (pinExchangeType != (int32_t)DMServiceInfoPinExchangeType::PINBOX && - pinExchangeType != (int32_t)DMServiceInfoPinExchangeType::FROMDP && - pinExchangeType != (int32_t)DMServiceInfoPinExchangeType::ULTRASOUND) { + if (pinExchangeType != (int32_t)DMLocalServiceInfoPinExchangeType::PINBOX && + pinExchangeType != (int32_t)DMLocalServiceInfoPinExchangeType::FROMDP && + pinExchangeType != (int32_t)DMLocalServiceInfoPinExchangeType::ULTRASOUND) { return false; } return true; } -bool DmAuthManager::IsServiceInfoProfileValid(const DistributedDeviceProfile::ServiceInfoProfile &profile) +bool DmAuthManager::IsLocalServiceInfoValid(const DistributedDeviceProfile::LocalServiceInfo &localServiceInfo) { - if (!IsServiceInfoAuthTypeValid(profile.GetAuthType())) { - LOGE("AuthType not valid, %{public}d", profile.GetAuthType()); + if (!IsServiceInfoAuthTypeValid(localServiceInfo.GetAuthType())) { + LOGE("AuthType not valid, %{public}d", localServiceInfo.GetAuthType()); return false; } - if (!IsServiceInfoAuthBoxTypeValid(profile.GetAuthBoxType())) { - LOGE("AuthBoxType not valid, %{public}d", profile.GetAuthBoxType()); + if (!IsServiceInfoAuthBoxTypeValid(localServiceInfo.GetAuthBoxType())) { + LOGE("AuthBoxType not valid, %{public}d", localServiceInfo.GetAuthBoxType()); return false; } - if (!IsServiceInfoPinExchangeTypeValid(profile.GetPinExchangeType())) { - LOGE("PinExchangeType not valid, %{public}d", profile.GetPinExchangeType()); + if (!IsServiceInfoPinExchangeTypeValid(localServiceInfo.GetPinExchangeType())) { + LOGE("PinExchangeType not valid, %{public}d", localServiceInfo.GetPinExchangeType()); return false; } - if (!IsPinCodeValid(profile.GetPinCode())) { + if (!IsPinCodeValid(localServiceInfo.GetPinCode())) { LOGE("pincode not valid"); return false; } @@ -1716,7 +1703,7 @@ void DmAuthManager::ShowConfigDialog() return; } if (CanUsePincodeFromDp() && - serviceInfoProfile_.GetAuthBoxType() == (int32_t)DMServiceInfoAuthBoxType::SKIP_CONFIRM) { + serviceInfoProfile_.GetAuthBoxType() == (int32_t)DMLocalServiceInfoAuthBoxType::SKIP_CONFIRM) { LOGI("no need confirm dialog"); StartAuthProcess(serviceInfoProfile_.GetAuthType()); return; @@ -2650,8 +2637,8 @@ void DmAuthManager::ProcRespNegotiateExt(const int32_t &sessionId) std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_NEGOTIATE); softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); - if (authResponseContext_->isSrcPincodeImported) { - GetServiceInfoProfile(); + if (authResponseContext_->authType == AUTH_TYPE_NFC) { + GetLocalServiceInfoInDp(); } } @@ -3247,26 +3234,22 @@ void DmAuthManager::ProcessReqPublicKey() } } -void DmAuthManager::GetServiceInfoProfile() +void DmAuthManager::GetLocalServiceInfoInDp() { - DistributedDeviceProfile::ServiceInfoUniqueKey key; - InitServiceInfoUniqueKey(key); - std::vector profiles; - int32_t result = DeviceProfileConnector::GetInstance().GetServiceInfoProfileListByBundleName(key, profiles); + DistributedDeviceProfile::LocalServiceInfo localServiceInfo; + int32_t result = DeviceProfileConnector::GetInstance().GetLocalServiceInfoByBundleNameAndPinExchangeType( + authResponseContext_->hostPkgName, (int32_t)DMLocalServiceInfoPinExchangeType::FROMDP, localServiceInfo); if (result != DM_OK) { return; } - for (auto &item : profiles) { - if (IsServiceInfoProfileValid(item)) { - serviceInfoProfile_ = item; - LOGI("authBoxType %{public}d, authType %{public}d, pinExchangeType %{public}d", - serviceInfoProfile_.GetAuthBoxType(), serviceInfoProfile_.GetAuthType(), - serviceInfoProfile_.GetPinExchangeType()); - auto updateProfile = serviceInfoProfile_; - updateProfile.SetPinCode("######"); - DeviceProfileConnector::GetInstance().UpdateServiceInfoProfile(updateProfile); - break; - } + if (IsLocalServiceInfoValid(localServiceInfo)) { + serviceInfoProfile_ = localServiceInfo; + LOGI("authBoxType %{public}d, authType %{public}d, pinExchangeType %{public}d", + serviceInfoProfile_.GetAuthBoxType(), serviceInfoProfile_.GetAuthType(), + serviceInfoProfile_.GetPinExchangeType()); + auto updateProfile = serviceInfoProfile_; + updateProfile.SetPinCode("######"); + DeviceProfileConnector::GetInstance().UpdateLocalServiceInfo(updateProfile); } } diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index e889bef4d..d02fff16b 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -36,7 +36,7 @@ #include "dm_package_common_event.h" #include "dm_screen_common_event.h" #include "relationship_sync_mgr.h" -#include "service_info_profile.h" +#include "local_service_info.h" #if defined(SUPPORT_BLUETOOTH) || defined(SUPPORT_WIFI) #include "dm_publish_common_event.h" #endif // SUPPORT_BLUETOOTH SUPPORT_WIFI @@ -221,11 +221,11 @@ public: int32_t GetLocalDisplayDeviceName(const std::string &pkgName, int32_t maxNameLength, std::string &displayName); std::vector GetDeviceNamePrefixs(); int64_t GenerateSerivceId(); - int32_t RegisterServiceInfo(const DMServiceInfo &serviceInfo); - int32_t UnRegisterServiceInfo(int64_t serviceId); - int32_t UpdateServiceInfo(const DMServiceInfo &serviceInfo); - int32_t GetServiceInfoById(int64_t serviceId, DMServiceInfo &serviceInfo); - int32_t GetCallerServiceInfos(std::vector &serviceInfos); + int32_t RegisterLocalServiceInfo(const DMLocalServiceInfo &serviceInfo); + int32_t UnRegisterLocalServiceInfo(const std::string &bundleName, int32_t pinExchangeType); + int32_t UpdateLocalServiceInfo(const DMLocalServiceInfo &serviceInfo); + int32_t GetLocalServiceInfoByBundleNameAndPinExchangeType(const std::string &bundleName, int32_t pinExchangeType, + DMLocalServiceInfo &serviceInfo); void ClearPulishIdCache(const std::string &pkgName); private: @@ -299,12 +299,12 @@ private: int32_t SendUserIdsByWifi(const std::string &networkId, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); void HandleUserSwitchTimeout(int32_t curUserId, int32_t preUserId, const std::string &udid); - bool InitServiceInfoProfile(const DMServiceInfo &serviceInfo, - DistributedDeviceProfile::ServiceInfoProfile &profile); - void InitServiceInfo(const DistributedDeviceProfile::ServiceInfoProfile &profile, DMServiceInfo &serviceInfo); - void InitServiceInfos(const std::vector &profiles, - std::vector &serviceInfos); - bool InitServiceInfoUniqueKey(DistributedDeviceProfile::ServiceInfoUniqueKey &key); + bool InitDPLocalServiceInfo(const DMLocalServiceInfo &serviceInfo, + DistributedDeviceProfile::LocalServiceInfo &dpLocalServiceItem); + void InitServiceInfo(const DistributedDeviceProfile::LocalServiceInfo &dpLocalServiceItem, + DMLocalServiceInfo &serviceInfo); + void InitServiceInfos(const std::vector &dpLocalServiceItems, + std::vector &serviceInfos); #if defined(SUPPORT_BLUETOOTH) || defined(SUPPORT_WIFI) void SubscribePublishCommonEvent(); void QueryDependsSwitchState(); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index c52a19685..d56a433fb 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -766,7 +766,7 @@ int32_t DeviceManagerService::UnBindDevice(const std::string &pkgName, const std LOGE("UnAuthenticateDevice failed, Acl not contain the bindLevel %{public}d.", bindLevel); return ERR_DM_FAILED; } - uint64_t peerTokenId = dmServiceImpl_->GetTokenIdByNameAndDeviceId(extra, udid); + [[maybe_unused]] uint64_t peerTokenId = dmServiceImpl_->GetTokenIdByNameAndDeviceId(extra, udid); if (dmServiceImpl_->UnBindDevice(pkgName, udid, bindLevel, extra) != DM_OK) { LOGE("dmServiceImpl_ UnBindDevice failed."); return ERR_DM_FAILED; @@ -1519,191 +1519,94 @@ int32_t DeviceManagerService::UnbindTarget(const std::string &pkgName, const Pee } #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) -bool DeviceManagerService::InitServiceInfoProfile(const DMServiceInfo &serviceInfo, - DistributedDeviceProfile::ServiceInfoProfile &profile) -{ - DmDeviceInfo devInfo; - int32_t ret = GetLocalDeviceInfo(devInfo); - if (ret != DM_OK) { - LOGE("GetLocalDeviceInfo failed"); - return false; - } - char localDeviceId[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - profile.SetDeviceId(std::string(localDeviceId)); - profile.SetNetworkId(devInfo.networkId); - profile.SetUserId(MultipleUserConnector::GetFirstForegroundUserId()); - profile.SetTokenId(std::to_string(IPCSkeleton::GetCallingTokenID())); - profile.SetServiceId(serviceInfo.serviceId); - profile.SetServiceType(serviceInfo.serviceType); - profile.SetServiceName(serviceInfo.serviceName); - profile.SetServiceDisplayName(serviceInfo.serviceDisplayName); - profile.SetCustomData(serviceInfo.customData); - profile.SetCustomDataLen(serviceInfo.customData.size()); - profile.SetBundleName(serviceInfo.bundleName); - profile.SetModuleName(serviceInfo.moduleName); - profile.SetAbilityName(serviceInfo.abilityName); - profile.SetAuthBoxType(serviceInfo.authBoxType); - profile.SetAuthType(serviceInfo.authType); - profile.SetPinExchangeType(serviceInfo.pinExchangeType); - profile.SetPinCode(serviceInfo.pinCode); - profile.SetDescription(serviceInfo.description); - profile.SetServiceDicoveryScope(serviceInfo.serviceDiscoveryScope); +bool DeviceManagerService::InitDPLocalServiceInfo(const DMLocalServiceInfo &serviceInfo, + DistributedDeviceProfile::LocalServiceInfo &dpLocalServiceInfo) +{ + dpLocalServiceInfo.SetBundleName(serviceInfo.bundleName); + dpLocalServiceInfo.SetAuthBoxType(serviceInfo.authBoxType); + dpLocalServiceInfo.SetAuthType(serviceInfo.authType); + dpLocalServiceInfo.SetPinExchangeType(serviceInfo.pinExchangeType); + dpLocalServiceInfo.SetPinCode(serviceInfo.pinCode); + dpLocalServiceInfo.SetDescription(serviceInfo.description); + dpLocalServiceInfo.SetExtraInfo(serviceInfo.extraInfo); return true; } -void DeviceManagerService::InitServiceInfo(const DistributedDeviceProfile::ServiceInfoProfile &profile, - DMServiceInfo &serviceInfo) +void DeviceManagerService::InitServiceInfo(const DistributedDeviceProfile::LocalServiceInfo &dpLocalServiceInfo, + DMLocalServiceInfo &serviceInfo) { - serviceInfo.serviceId = profile.GetServiceId(); - serviceInfo.serviceType = profile.GetServiceType(); - serviceInfo.serviceName = profile.GetServiceName(); - serviceInfo.serviceDisplayName = profile.GetServiceDisplayName(); - serviceInfo.customData = profile.GetCustomData(); - serviceInfo.bundleName = profile.GetBundleName(); - serviceInfo.moduleName = profile.GetModuleName(); - serviceInfo.abilityName = profile.GetAbilityName(); - serviceInfo.authBoxType = profile.GetAuthBoxType(); - serviceInfo.authType = profile.GetAuthType(); - serviceInfo.pinExchangeType = profile.GetPinExchangeType(); - serviceInfo.pinCode = profile.GetPinCode(); - serviceInfo.description = profile.GetDescription(); - serviceInfo.serviceDiscoveryScope = profile.GetServiceDicoveryScope(); + serviceInfo.bundleName = dpLocalServiceInfo.GetBundleName(); + serviceInfo.authBoxType = dpLocalServiceInfo.GetAuthBoxType(); + serviceInfo.authType = dpLocalServiceInfo.GetAuthType(); + serviceInfo.pinExchangeType = dpLocalServiceInfo.GetPinExchangeType(); + serviceInfo.pinCode = dpLocalServiceInfo.GetPinCode(); + serviceInfo.description = dpLocalServiceInfo.GetDescription(); + serviceInfo.extraInfo = dpLocalServiceInfo.GetExtraInfo(); } -void DeviceManagerService::InitServiceInfos(const std::vector &profiles, - std::vector &serviceInfos) +void DeviceManagerService::InitServiceInfos( + const std::vector &dpLocalServiceInfos, + std::vector &serviceInfos) { - for (const auto &profileItem : profiles) { - DMServiceInfo infoItem; - InitServiceInfo(profileItem, infoItem); + for (const auto &dpInfoItem : dpLocalServiceInfos) { + DMLocalServiceInfo infoItem; + InitServiceInfo(dpInfoItem, infoItem); serviceInfos.emplace_back(infoItem); } } - -bool DeviceManagerService::InitServiceInfoUniqueKey(DistributedDeviceProfile::ServiceInfoUniqueKey &key) -{ - char localDeviceId[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - key.SetDeviceId(std::string(localDeviceId)); - key.SetUserId(MultipleUserConnector::GetFirstForegroundUserId()); - key.SetTokenId(std::to_string(IPCSkeleton::GetCallingTokenID())); - return true; -} -#endif - -int64_t DeviceManagerService::GenerateSerivceId() -{ -#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) - DmDeviceInfo devInfo; - int32_t ret = GetLocalDeviceInfo(devInfo); - if (ret != DM_OK) { - LOGE("GetLocalDeviceInfo failed"); - return 0; - } - std::string udid = devInfo.deviceId; - if (udid.empty()) { - LOGE("udid empty"); - return 0; - } - int64_t tokenId = IPCSkeleton::GetCallingTokenID(); - const uint32_t dataLength = sizeof(int64_t) + sizeof(int64_t) + udid.length(); - std::unique_ptr data = std::make_unique(dataLength); - int64_t randomSeed = GenRandLongLong(0, std::numeric_limits::max()); - unsigned char* dataPtr = data.get(); - *((int64_t*)dataPtr) = randomSeed; - dataPtr += sizeof(int64_t); - *((int64_t*)dataPtr) = tokenId; - dataPtr += sizeof(int64_t); - if (memcpy_s(dataPtr, udid.length(), udid.c_str(), udid.length()) != EOK) { - LOGE("memcpy udid failed"); - return 0; - } - unsigned char hash[SHA256_DIGEST_LENGTH] = {0}; - Crypto::DmGenerateStrHash(data.get(), dataLength, hash, SHA256_DIGEST_LENGTH, 0); - if (memset_s(data.get(), dataLength, 0, dataLength) != EOK) { - LOGW("memset_s failed."); - } - int64_t serviceId = 0; - if (memcpy_s(&serviceId, sizeof(int64_t), hash, sizeof(int64_t)) != EOK) { - serviceId = 0; - LOGE("memcpy serviceId failed"); - } - serviceId = std::abs(serviceId); - LOGI("GenerateSeivceId %{public}" PRId64, serviceId); - return serviceId; -#else - return ERR_DM_FAILED; #endif -} -int32_t DeviceManagerService::RegisterServiceInfo(const DMServiceInfo &serviceInfo) +int32_t DeviceManagerService::RegisterLocalServiceInfo(const DMLocalServiceInfo &serviceInfo) { #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) - LOGI("start, serviceId %{public}" PRId64, serviceInfo.serviceId); - DistributedDeviceProfile::ServiceInfoProfile profile; - bool success = InitServiceInfoProfile(serviceInfo, profile); + DistributedDeviceProfile::LocalServiceInfo dpLocalServiceInfo; + bool success = InitDPLocalServiceInfo(serviceInfo, dpLocalServiceInfo); if (!success) { - LOGE("InitServiceInfoProfile failed"); + LOGE("InitDPLocalServiceInfo failed"); return ERR_DM_FAILED; } - return DeviceProfileConnector::GetInstance().PutServiceInfoProfile(profile); + return DeviceProfileConnector::GetInstance().PutLocalServiceInfo(dpLocalServiceInfo); #else (void)serviceInfo; return ERR_DM_FAILED; #endif } -int32_t DeviceManagerService::UnRegisterServiceInfo(int64_t serviceId) +int32_t DeviceManagerService::UnRegisterLocalServiceInfo(const std::string &bundleName, int32_t pinExchangeType) { #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) - LOGI("start, serviceId %{public}" PRId64, serviceId); - DistributedDeviceProfile::ServiceInfoUniqueKey key; - bool result = InitServiceInfoUniqueKey(key); - if (!result) { - LOGE("InitServiceInfoUniqueKey failed"); - return ERR_DM_FAILED; - } - key.SetServiceId(serviceId); - return DeviceProfileConnector::GetInstance().DeleteServiceInfoProfile(key); + return DeviceProfileConnector::GetInstance().DeleteLocalServiceInfo(bundleName, pinExchangeType); #else (void)serviceId; return ERR_DM_FAILED; #endif } -int32_t DeviceManagerService::UpdateServiceInfo(const DMServiceInfo &serviceInfo) +int32_t DeviceManagerService::UpdateLocalServiceInfo(const DMLocalServiceInfo &serviceInfo) { #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) - LOGI("start, serviceId %{public}" PRId64, serviceInfo.serviceId); - DistributedDeviceProfile::ServiceInfoProfile profile; - bool success = InitServiceInfoProfile(serviceInfo, profile); + DistributedDeviceProfile::LocalServiceInfo dpLocalServiceInfo; + bool success = InitDPLocalServiceInfo(serviceInfo, dpLocalServiceInfo); if (!success) { - LOGE("InitServiceInfoProfile failed"); + LOGE("InitDPLocalServiceInfo failed"); return ERR_DM_FAILED; } - return DeviceProfileConnector::GetInstance().UpdateServiceInfoProfile(profile); + return DeviceProfileConnector::GetInstance().UpdateLocalServiceInfo(dpLocalServiceInfo); #else (void)serviceInfo; return ERR_DM_FAILED; #endif } -int32_t DeviceManagerService::GetServiceInfoById(int64_t serviceId, DMServiceInfo &serviceInfo) +int32_t DeviceManagerService::GetLocalServiceInfoByBundleNameAndPinExchangeType(const std::string &bundleName, + int32_t pinExchangeType, DMLocalServiceInfo &serviceInfo) { #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) - LOGI("start, serviceId %{public}" PRId64, serviceId); - DistributedDeviceProfile::ServiceInfoUniqueKey key; - bool result = InitServiceInfoUniqueKey(key); - if (!result) { - LOGE("InitServiceInfoUniqueKey failed"); - return ERR_DM_FAILED; - } - key.SetServiceId(serviceId); - DistributedDeviceProfile::ServiceInfoProfile profile; - int32_t ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileByUniqueKey(key, profile); + DistributedDeviceProfile::LocalServiceInfo dpLocalServiceInfo; + int32_t ret = DeviceProfileConnector::GetInstance().GetLocalServiceInfoByBundleNameAndPinExchangeType(bundleName, + pinExchangeType, dpLocalServiceInfo); if (ret == DM_OK) { - InitServiceInfo(profile, serviceInfo); + InitServiceInfo(dpLocalServiceInfo, serviceInfo); } return ret; #else @@ -1713,27 +1616,6 @@ int32_t DeviceManagerService::GetServiceInfoById(int64_t serviceId, DMServiceInf #endif } -int32_t DeviceManagerService::GetCallerServiceInfos(std::vector &serviceInfos) -{ -#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) - DistributedDeviceProfile::ServiceInfoUniqueKey key; - bool result = InitServiceInfoUniqueKey(key); - if (!result) { - LOGE("InitServiceInfoUniqueKey failed"); - return ERR_DM_FAILED; - } - std::vector profiles; - int32_t ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileListByTokenId(key, profiles); - if (ret == DM_OK) { - InitServiceInfos(profiles, serviceInfos); - } - return ret; -#else - (void)serviceInfos; - return ERR_DM_FAILED; -#endif -} - int32_t DeviceManagerService::RegisterPinHolderCallback(const std::string &pkgName) { if (!PermissionManager::GetInstance().CheckPermission()) { diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 8bebe20f3..3c9894d78 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -1734,40 +1734,11 @@ ON_IPC_CMD(GET_LOCAL_DISPLAY_DEVICE_NAME, MessageParcel &data, MessageParcel &re return DM_OK; } -ON_IPC_CMD(GEN_SERVICEID, MessageParcel &data, MessageParcel &reply) +ON_IPC_CMD(REG_LOCALSERVICE_INFO, MessageParcel &data, MessageParcel &reply) { - int64_t serviceId = DeviceManagerService::GetInstance().GenerateSerivceId(); - int32_t result = DM_OK; - if (serviceId == 0) { - result = ERR_DM_FAILED; - } - if (!reply.WriteInt32(result)) { - LOGE("write result failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!reply.WriteInt64(serviceId)) { - LOGE("write result failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_CMD(REG_SERVICE_INFO, MessageParcel &data, MessageParcel &reply) -{ - DMServiceInfo serviceInfo; - IpcModelCodec::DecodeServiceInfo(data, serviceInfo); - int32_t result = DeviceManagerService::GetInstance().RegisterServiceInfo(serviceInfo); - if (!reply.WriteInt32(result)) { - LOGE("write result failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_CMD(UNREG_SERVICE_INFO, MessageParcel &data, MessageParcel &reply) -{ - int64_t serviceId = data.ReadInt64(); - int32_t result = DeviceManagerService::GetInstance().UnRegisterServiceInfo(serviceId); + DMLocalServiceInfo serviceInfo; + IpcModelCodec::DecodeLocalServiceInfo(data, serviceInfo); + int32_t result = DeviceManagerService::GetInstance().RegisterLocalServiceInfo(serviceInfo); if (!reply.WriteInt32(result)) { LOGE("write result failed"); return ERR_DM_IPC_WRITE_FAILED; @@ -1775,11 +1746,11 @@ ON_IPC_CMD(UNREG_SERVICE_INFO, MessageParcel &data, MessageParcel &reply) return DM_OK; } -ON_IPC_CMD(UPDATE_SERVICE_INFO, MessageParcel &data, MessageParcel &reply) +ON_IPC_CMD(UNREG_LOCALSERVICE_INFO, MessageParcel &data, MessageParcel &reply) { - DMServiceInfo serviceInfo; - IpcModelCodec::DecodeServiceInfo(data, serviceInfo); - int32_t result = DeviceManagerService::GetInstance().UpdateServiceInfo(serviceInfo); + std::string bundleName = data.ReadString(); + int32_t pinExchangeType = data.ReadInt32(); + int32_t result = DeviceManagerService::GetInstance().UnRegisterLocalServiceInfo(bundleName, pinExchangeType); if (!reply.WriteInt32(result)) { LOGE("write result failed"); return ERR_DM_IPC_WRITE_FAILED; @@ -1787,31 +1758,30 @@ ON_IPC_CMD(UPDATE_SERVICE_INFO, MessageParcel &data, MessageParcel &reply) return DM_OK; } -ON_IPC_CMD(GET_SERVICEINFO_BYID, MessageParcel &data, MessageParcel &reply) +ON_IPC_CMD(UPDATE_LOCALSERVICE_INFO, MessageParcel &data, MessageParcel &reply) { - int64_t serviceId = data.ReadInt64(); - DMServiceInfo serviceInfo; - int32_t result = DeviceManagerService::GetInstance().GetServiceInfoById(serviceId, serviceInfo); + DMLocalServiceInfo serviceInfo; + IpcModelCodec::DecodeLocalServiceInfo(data, serviceInfo); + int32_t result = DeviceManagerService::GetInstance().UpdateLocalServiceInfo(serviceInfo); if (!reply.WriteInt32(result)) { LOGE("write result failed"); return ERR_DM_IPC_WRITE_FAILED; } - if (result == DM_OK && !IpcModelCodec::EncodeServiceInfo(serviceInfo, reply)) { - LOGE("write result failed"); - return ERR_DM_IPC_WRITE_FAILED; - } return DM_OK; } -ON_IPC_CMD(GET_SERVICEINFOS_CALLER, MessageParcel &data, MessageParcel &reply) +ON_IPC_CMD(GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE, MessageParcel &data, MessageParcel &reply) { - std::vector serviceInfos; - int32_t result = DeviceManagerService::GetInstance().GetCallerServiceInfos(serviceInfos); + std::string bundleName = data.ReadString(); + int64_t pinExchangeType = data.ReadInt32(); + DMLocalServiceInfo serviceInfo; + int32_t result = DeviceManagerService::GetInstance().GetLocalServiceInfoByBundleNameAndPinExchangeType( + bundleName, pinExchangeType, serviceInfo); if (!reply.WriteInt32(result)) { LOGE("write result failed"); return ERR_DM_IPC_WRITE_FAILED; } - if (result == DM_OK && !IpcModelCodec::EncodeServiceInfos(serviceInfos, reply)) { + if (result == DM_OK && !IpcModelCodec::EncodeLocalServiceInfo(serviceInfo, reply)) { LOGE("write result failed"); return ERR_DM_IPC_WRITE_FAILED; } diff --git a/test/commonunittest/UTTest_dm_auth_manager_first.cpp b/test/commonunittest/UTTest_dm_auth_manager_first.cpp index eb246dde7..450babef2 100644 --- a/test/commonunittest/UTTest_dm_auth_manager_first.cpp +++ b/test/commonunittest/UTTest_dm_auth_manager_first.cpp @@ -2030,9 +2030,9 @@ HWTEST_F(DmAuthManagerTest, CheckNeedShowAuthInfoDialog_001, testing::ext::TestS int32_t errorCode = ERR_DM_HICHAIN_PROOFMISMATCH; authManager_->pincodeDialogEverShown_ = false; authManager_->authResponseContext_->authType = AUTH_TYPE_NFC; - authManager_->authResponseContext_->isSrcPincodeImported = true; authManager_->serviceInfoProfile_.SetPinCode(std::to_string(PINCODE)); - authManager_->serviceInfoProfile_.SetPinExchangeType(static_cast(DMServiceInfoPinExchangeType::FROMDP)); + authManager_->serviceInfoProfile_.SetPinExchangeType( + static_cast(DMLocalServiceInfoPinExchangeType::FROMDP)); bool ret = authManager_->CheckNeedShowAuthInfoDialog(errorCode); ASSERT_TRUE(ret); @@ -2040,20 +2040,18 @@ HWTEST_F(DmAuthManagerTest, CheckNeedShowAuthInfoDialog_001, testing::ext::TestS ret = authManager_->CheckNeedShowAuthInfoDialog(errorCode); ASSERT_FALSE(ret); - EXPECT_CALL(*deviceProfileConnectorMock_, GetServiceInfoProfileListByBundleName(_, _)) + EXPECT_CALL(*deviceProfileConnectorMock_, GetLocalServiceInfoByBundleNameAndPinExchangeType(_, _, _)) .WillOnce(Return(ERR_DM_FAILED)); - authManager_->GetServiceInfoProfile(); - - std::vector profiles; - DistributedDeviceProfile::ServiceInfoProfile serviceInfoProfile; - serviceInfoProfile.SetAuthType(static_cast(DMServiceInfoAuthType::TRUST_ONETIME)); - serviceInfoProfile.SetAuthBoxType(static_cast(DMServiceInfoAuthBoxType::STATE3)); - serviceInfoProfile.SetPinExchangeType(static_cast(DMServiceInfoPinExchangeType::FROMDP)); - serviceInfoProfile.SetPinCode(std::to_string(PINCODE)); - profiles.push_back(serviceInfoProfile); - EXPECT_CALL(*deviceProfileConnectorMock_, GetServiceInfoProfileListByBundleName(_, _)) - .WillOnce(DoAll(SetArgReferee<1>(profiles), Return(DM_OK))); - authManager_->GetServiceInfoProfile(); + authManager_->GetLocalServiceInfoInDp(); + + DistributedDeviceProfile::LocalServiceInfo localServiceInfo; + localServiceInfo.SetAuthType(static_cast(DMLocalServiceInfoAuthType::TRUST_ONETIME)); + localServiceInfo.SetAuthBoxType(static_cast(DMLocalServiceInfoAuthBoxType::STATE3)); + localServiceInfo.SetPinExchangeType(static_cast(DMLocalServiceInfoPinExchangeType::FROMDP)); + localServiceInfo.SetPinCode(std::to_string(PINCODE)); + EXPECT_CALL(*deviceProfileConnectorMock_, GetLocalServiceInfoByBundleNameAndPinExchangeType(_, _, _)) + .WillOnce(DoAll(Return(DM_OK))); + authManager_->GetLocalServiceInfoInDp(); int64_t requestId = 1; uint8_t arrayPtr[] = {1, 2, 3, 4}; @@ -2074,23 +2072,23 @@ HWTEST_F(DmAuthManagerTest, IsPinCodeValid_001, testing::ext::TestSize.Level0) authManager_->ShowConfigDialog(); authManager_->authResponseContext_ = std::make_shared(); - authManager_->serviceInfoProfile_.SetAuthBoxType(static_cast(DMServiceInfoAuthBoxType::SKIP_CONFIRM)); + authManager_->serviceInfoProfile_.SetAuthBoxType( + static_cast(DMLocalServiceInfoAuthBoxType::SKIP_CONFIRM)); authManager_->authResponseContext_->authType = AUTH_TYPE_NFC; - authManager_->authResponseContext_->isSrcPincodeImported = true; authManager_->serviceInfoProfile_.SetPinCode(std::to_string(PINCODE)); - authManager_->serviceInfoProfile_.SetPinExchangeType(static_cast(DMServiceInfoPinExchangeType::FROMDP)); + authManager_->serviceInfoProfile_.SetPinExchangeType( + static_cast(DMLocalServiceInfoPinExchangeType::FROMDP)); authManager_->ShowConfigDialog(); authManager_->authResponseContext_->isShowDialog = false; - authManager_->serviceInfoProfile_.SetPinExchangeType(static_cast(DMServiceInfoPinExchangeType::PINBOX)); + authManager_->serviceInfoProfile_.SetPinExchangeType( + static_cast(DMLocalServiceInfoPinExchangeType::PINBOX)); authManager_->ShowConfigDialog(); authManager_->authResponseContext_->isShowDialog = true; authManager_->ShowConfigDialog(); - DistributedDeviceProfile::ServiceInfoUniqueKey key; - authManager_->InitServiceInfoUniqueKey(key); ASSERT_FALSE(authManager_->IsPinCodeValid(MIN_PIN_CODE_VALUE)); ASSERT_FALSE(authManager_->IsPinCodeValid(MAX_PIN_CODE_VALUE)); ASSERT_TRUE(authManager_->IsPinCodeValid(PINCODE)); @@ -2122,26 +2120,26 @@ HWTEST_F(DmAuthManagerTest, IsServiceInfoPinExchangeTypeValid_001, testing::ext: ASSERT_FALSE(authManager_->IsServiceInfoPinExchangeTypeValid(pinExchangeType)); } -HWTEST_F(DmAuthManagerTest, IsServiceInfoProfileValid_001, testing::ext::TestSize.Level0) +HWTEST_F(DmAuthManagerTest, IsLocalServiceInfoValid_001, testing::ext::TestSize.Level0) { - DistributedDeviceProfile::ServiceInfoProfile profile; + DistributedDeviceProfile::LocalServiceInfo profile; profile.SetAuthType(2); - ASSERT_FALSE(authManager_->IsServiceInfoProfileValid(profile)); + ASSERT_FALSE(authManager_->IsLocalServiceInfoValid(profile)); - profile.SetAuthType(static_cast(DMServiceInfoAuthType::TRUST_ONETIME)); + profile.SetAuthType(static_cast(DMLocalServiceInfoAuthType::TRUST_ONETIME)); profile.SetAuthBoxType(3); - ASSERT_FALSE(authManager_->IsServiceInfoProfileValid(profile)); + ASSERT_FALSE(authManager_->IsLocalServiceInfoValid(profile)); - profile.SetAuthBoxType(static_cast(DMServiceInfoAuthBoxType::STATE3)); + profile.SetAuthBoxType(static_cast(DMLocalServiceInfoAuthBoxType::STATE3)); profile.SetPinExchangeType(4); - ASSERT_FALSE(authManager_->IsServiceInfoProfileValid(profile)); + ASSERT_FALSE(authManager_->IsLocalServiceInfoValid(profile)); - profile.SetPinExchangeType(static_cast(DMServiceInfoPinExchangeType::FROMDP)); + profile.SetPinExchangeType(static_cast(DMLocalServiceInfoPinExchangeType::FROMDP)); profile.SetPinCode(""); - ASSERT_FALSE(authManager_->IsServiceInfoProfileValid(profile)); + ASSERT_FALSE(authManager_->IsLocalServiceInfoValid(profile)); profile.SetPinCode(std::to_string(PINCODE)); - ASSERT_TRUE(authManager_->IsServiceInfoProfileValid(profile)); + ASSERT_TRUE(authManager_->IsLocalServiceInfoValid(profile)); } HWTEST_F(DmAuthManagerTest, EstablishAuthChannel_003, testing::ext::TestSize.Level0) diff --git a/test/unittest/UTTest_auth_message_processor.cpp b/test/unittest/UTTest_auth_message_processor.cpp index 64265e764..f6ce05c6a 100644 --- a/test/unittest/UTTest_auth_message_processor.cpp +++ b/test/unittest/UTTest_auth_message_processor.cpp @@ -880,7 +880,6 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_006, testing::ext::Test jsonObj[TAG_BUNDLE_NAME] = "bundleName"; jsonObj[TAG_PEER_BUNDLE_NAME] = "peerbundleName"; jsonObj[TAG_REMOTE_DEVICE_NAME] = "remoteDeviceName"; - jsonObj[TAG_SRC_PINCODE_IMPORTED] = false; authMessageProcessor->SetResponseContext(authResponseContext); authMessageProcessor->ParseNegotiateMessage(jsonObj); ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext); diff --git a/test/unittest/UTTest_ipc_cmd_parser_client.cpp b/test/unittest/UTTest_ipc_cmd_parser_client.cpp index 6b52ab63a..34e24b1e9 100644 --- a/test/unittest/UTTest_ipc_cmd_parser_client.cpp +++ b/test/unittest/UTTest_ipc_cmd_parser_client.cpp @@ -26,13 +26,11 @@ #include "ipc_create_pin_holder_req.h" #include "ipc_register_listener_req.h" #include "ipc_generate_encrypted_uuid_req.h" -#include "ipc_gen_serviceid_rsp.h" #include "ipc_get_device_screen_status_req.h" #include "ipc_get_device_screen_status_rsp.h" #include "ipc_get_info_by_network_req.h" #include "ipc_get_info_by_network_rsp.h" -#include "ipc_get_serviceinfo_byid_rsp.h" -#include "ipc_get_serviceinfo_bycaller_rsp.h" +#include "ipc_get_localserviceinfo_rsp.h" #include "ipc_get_trustdevice_req.h" #include "ipc_model_codec.h" #include "ipc_publish_req.h" @@ -335,80 +333,53 @@ HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_034, testing::ext::TestSize.Le ASSERT_EQ(TestReadResponseRspNull(cmdCode), ERR_DM_FAILED); } -HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_080, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = GEN_SERVICEID; - ASSERT_EQ(TestReadResponseRspNull(cmdCode), ERR_DM_FAILED); -} - HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_081, testing::ext::TestSize.Level0) { - int32_t cmdCode = REG_SERVICE_INFO; + int32_t cmdCode = REG_LOCALSERVICE_INFO; ASSERT_EQ(TestReadResponseRspNull(cmdCode), ERR_DM_FAILED); } HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_082, testing::ext::TestSize.Level0) { - int32_t cmdCode = UNREG_SERVICE_INFO; + int32_t cmdCode = UNREG_LOCALSERVICE_INFO; ASSERT_EQ(TestReadResponseRspNull(cmdCode), ERR_DM_FAILED); } HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_083, testing::ext::TestSize.Level0) { - int32_t cmdCode = UPDATE_SERVICE_INFO; + int32_t cmdCode = UPDATE_LOCALSERVICE_INFO; ASSERT_EQ(TestReadResponseRspNull(cmdCode), ERR_DM_FAILED); } HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_084, testing::ext::TestSize.Level0) { - int32_t cmdCode = GET_SERVICEINFO_BYID; - ASSERT_EQ(TestReadResponseRspNull(cmdCode), ERR_DM_FAILED); -} - -HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_085, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = GET_SERVICEINFOS_CALLER; + int32_t cmdCode = GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE; ASSERT_EQ(TestReadResponseRspNull(cmdCode), ERR_DM_FAILED); } -HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_086, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = GEN_SERVICEID; - MessageParcel reply; - std::shared_ptr rsp = std::make_shared(); - int32_t retCode = 0; - reply.WriteInt32(retCode); - int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; - ReadResponseFunc ptr = GetResponseFunc(cmdCode); - if (ptr) { - ret = ptr(reply, rsp); - } - ASSERT_EQ(ret, DM_OK); -} - HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_087, testing::ext::TestSize.Level0) { - int32_t cmdCode = REG_SERVICE_INFO; + int32_t cmdCode = REG_LOCALSERVICE_INFO; ASSERT_EQ(TestReadResponseRspNotNull(cmdCode), DM_OK); } HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_088, testing::ext::TestSize.Level0) { - int32_t cmdCode = UNREG_SERVICE_INFO; + int32_t cmdCode = UNREG_LOCALSERVICE_INFO; ASSERT_EQ(TestReadResponseRspNotNull(cmdCode), DM_OK); } HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_089, testing::ext::TestSize.Level0) { - int32_t cmdCode = UPDATE_SERVICE_INFO; + int32_t cmdCode = UPDATE_LOCALSERVICE_INFO; ASSERT_EQ(TestReadResponseRspNotNull(cmdCode), DM_OK); } HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_090, testing::ext::TestSize.Level0) { - int32_t cmdCode = GET_SERVICEINFO_BYID; + int32_t cmdCode = GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE; MessageParcel reply; - std::shared_ptr rsp = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); int32_t retCode = 0; reply.WriteInt32(retCode); int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; @@ -421,77 +392,15 @@ HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_090, testing::ext::TestSize.Le MessageParcel reply2; reply2.WriteInt32(DM_OK); - DMServiceInfo info; - info.abilityName = "debug"; - ASSERT_TRUE(IpcModelCodec::EncodeServiceInfo(info, reply2)); + DMLocalServiceInfo info; + info.bundleName = "debug"; + ASSERT_TRUE(IpcModelCodec::EncodeLocalServiceInfo(info, reply2)); if (ptr) { ret = ptr(reply2, rsp); } ASSERT_EQ(ret, DM_OK); ASSERT_EQ(rsp->GetErrCode(), DM_OK); - ASSERT_TRUE(rsp->GetServiceInfo().abilityName == "debug"); -} - -HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_091, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = GET_SERVICEINFOS_CALLER; - MessageParcel reply; - std::shared_ptr rsp = std::make_shared(); - int32_t retCode = 0; - reply.WriteInt32(retCode); - int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; - ReadResponseFunc ptr = GetResponseFunc(cmdCode); - if (ptr) { - ret = ptr(reply, rsp); - } - ASSERT_EQ(ret, DM_OK); - ASSERT_EQ(rsp->GetErrCode(), ERR_DM_IPC_READ_FAILED); - - MessageParcel reply2; - reply2.WriteInt32(DM_OK); - std::vector infos; - DMServiceInfo info1; - info1.abilityName = "debug0"; - DMServiceInfo info2; - info2.abilityName = "debug1"; - infos.emplace_back(info1); - infos.emplace_back(info2); - ASSERT_TRUE(IpcModelCodec::EncodeServiceInfos(infos, reply2)); - if (ptr) { - ret = ptr(reply2, rsp); - } - ASSERT_EQ(ret, DM_OK); - ASSERT_EQ(rsp->GetErrCode(), DM_OK); - std::vector infos2 = rsp->GetServiceInfos(); - ASSERT_EQ(infos2.size(), infos.size()); - ASSERT_TRUE(infos2[0].abilityName == "debug0"); - ASSERT_TRUE(infos2[1].abilityName == "debug1"); -} - -HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_092, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = GET_SERVICEINFOS_CALLER; - ReadResponseFunc ptr = GetResponseFunc(cmdCode); - MessageParcel reply; - std::shared_ptr rsp = std::make_shared(); - reply.WriteInt32(DM_OK); - std::vector infos; - for (int k = 0; k < NUM_200; k++) { - DMServiceInfo info; - info.abilityName = std::string("debug") + std::to_string(k); - infos.emplace_back(info); - } - ASSERT_TRUE(IpcModelCodec::EncodeServiceInfos(infos, reply)); - int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; - if (ptr) { - ret = ptr(reply, rsp); - } - ASSERT_EQ(ret, DM_OK); - ASSERT_EQ(rsp->GetErrCode(), DM_OK); - std::vector infos2 = rsp->GetServiceInfos(); - ASSERT_EQ(infos2.size(), infos.size()); - ASSERT_TRUE(infos2[0].abilityName == "debug0"); - ASSERT_TRUE(infos2[1].abilityName == "debug1"); + ASSERT_TRUE(rsp->GetLocalServiceInfo().bundleName == "debug"); } HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_002, testing::ext::TestSize.Level0) @@ -736,26 +645,13 @@ HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_015, testing::ext::TestSize.L ASSERT_EQ(DM_OK, ret); } -HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_030, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = GEN_SERVICEID; - MessageParcel data; - std::shared_ptr req = std::make_shared(); - int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; - SetIpcRequestFunc ptr = GetIpcRequestFunc(cmdCode); - if (ptr) { - ret = ptr(req, data); - } - ASSERT_EQ(DM_OK, ret); -} - HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_031, testing::ext::TestSize.Level0) { - int32_t cmdCode = REG_SERVICE_INFO; - DMServiceInfo serviceInfo; + int32_t cmdCode = REG_LOCALSERVICE_INFO; + DMLocalServiceInfo serviceInfo; MessageParcel data; std::shared_ptr req = std::make_shared(); - req->SetServiceInfo(serviceInfo); + req->SetLocalServiceInfo(serviceInfo); int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; SetIpcRequestFunc ptr = GetIpcRequestFunc(cmdCode); @@ -767,11 +663,12 @@ HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_031, testing::ext::TestSize.L HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_032, testing::ext::TestSize.Level0) { - int32_t cmdCode = UNREG_SERVICE_INFO; - DMServiceInfo serviceInfo; + int32_t cmdCode = UNREG_LOCALSERVICE_INFO; + DMLocalServiceInfo serviceInfo; MessageParcel data; std::shared_ptr req = std::make_shared(); - req->SetInt64Param(100); + req->SetFirstParam(std::string("testbundle")); + req->SetInt32Param(100); int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; SetIpcRequestFunc ptr = GetIpcRequestFunc(cmdCode); @@ -783,11 +680,11 @@ HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_032, testing::ext::TestSize.L HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_033, testing::ext::TestSize.Level0) { - int32_t cmdCode = UPDATE_SERVICE_INFO; - DMServiceInfo serviceInfo; + int32_t cmdCode = UPDATE_LOCALSERVICE_INFO; + DMLocalServiceInfo serviceInfo; MessageParcel data; std::shared_ptr req = std::make_shared(); - req->SetServiceInfo(serviceInfo); + req->SetLocalServiceInfo(serviceInfo); int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; SetIpcRequestFunc ptr = GetIpcRequestFunc(cmdCode); @@ -799,25 +696,12 @@ HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_033, testing::ext::TestSize.L HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_034, testing::ext::TestSize.Level0) { - int32_t cmdCode = GET_SERVICEINFO_BYID; - DMServiceInfo serviceInfo; + int32_t cmdCode = GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE; + DMLocalServiceInfo serviceInfo; MessageParcel data; std::shared_ptr req = std::make_shared(); - req->SetInt64Param(100); - int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; - SetIpcRequestFunc ptr = GetIpcRequestFunc(cmdCode); - if (ptr) { - ret = ptr(req, data); - } - ASSERT_EQ(DM_OK, ret); -} - -HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_035, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = GET_SERVICEINFOS_CALLER; - DMServiceInfo serviceInfo; - MessageParcel data; - std::shared_ptr req = std::make_shared(); + req->SetFirstParam(std::string("testbundle")); + req->SetInt32Param(100); int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; SetIpcRequestFunc ptr = GetIpcRequestFunc(cmdCode); if (ptr) { @@ -1416,12 +1300,10 @@ HWTEST_F(IpcCmdParserClientTest, TEST_IPC_REQUEST_NULL_002, testing::ext::TestSi HWTEST_F(IpcCmdParserClientTest, TEST_IPC_REQUEST_NULL_003, testing::ext::TestSize.Level2) { - EXPECT_EQ(TestIpcRequestNull(GEN_SERVICEID), ERR_DM_FAILED); - EXPECT_EQ(TestIpcRequestNull(REG_SERVICE_INFO), ERR_DM_FAILED); - EXPECT_EQ(TestIpcRequestNull(UNREG_SERVICE_INFO), ERR_DM_FAILED); - EXPECT_EQ(TestIpcRequestNull(UPDATE_SERVICE_INFO), ERR_DM_FAILED); - EXPECT_EQ(TestIpcRequestNull(GET_SERVICEINFO_BYID), ERR_DM_FAILED); - EXPECT_EQ(TestIpcRequestNull(GET_SERVICEINFOS_CALLER), ERR_DM_FAILED); + EXPECT_EQ(TestIpcRequestNull(REG_LOCALSERVICE_INFO), ERR_DM_FAILED); + EXPECT_EQ(TestIpcRequestNull(UNREG_LOCALSERVICE_INFO), ERR_DM_FAILED); + EXPECT_EQ(TestIpcRequestNull(UPDATE_LOCALSERVICE_INFO), ERR_DM_FAILED); + EXPECT_EQ(TestIpcRequestNull(GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE), ERR_DM_FAILED); } HWTEST_F(IpcCmdParserClientTest, TEST_READ_RESPONSE_NULL_001, testing::ext::TestSize.Level2) @@ -1470,12 +1352,10 @@ HWTEST_F(IpcCmdParserClientTest, TEST_READ_RESPONSE_NULL_001, testing::ext::Test HWTEST_F(IpcCmdParserClientTest, TEST_READ_RESPONSE_NULL_002, testing::ext::TestSize.Level2) { - EXPECT_EQ(TestReadResponseRspNull(GEN_SERVICEID), ERR_DM_FAILED); - EXPECT_EQ(TestReadResponseRspNull(REG_SERVICE_INFO), ERR_DM_FAILED); - EXPECT_EQ(TestReadResponseRspNull(UNREG_SERVICE_INFO), ERR_DM_FAILED); - EXPECT_EQ(TestReadResponseRspNull(UPDATE_SERVICE_INFO), ERR_DM_FAILED); - EXPECT_EQ(TestReadResponseRspNull(GET_SERVICEINFO_BYID), ERR_DM_FAILED); - EXPECT_EQ(TestReadResponseRspNull(GET_SERVICEINFOS_CALLER), ERR_DM_FAILED); + EXPECT_EQ(TestReadResponseRspNull(REG_LOCALSERVICE_INFO), ERR_DM_FAILED); + EXPECT_EQ(TestReadResponseRspNull(UNREG_LOCALSERVICE_INFO), ERR_DM_FAILED); + EXPECT_EQ(TestReadResponseRspNull(UPDATE_LOCALSERVICE_INFO), ERR_DM_FAILED); + EXPECT_EQ(TestReadResponseRspNull(GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE), ERR_DM_FAILED); } } // namespace } // namespace DistributedHardware diff --git a/test/unittest/mock/deviceprofile_connector_mock.cpp b/test/unittest/mock/deviceprofile_connector_mock.cpp index be3dd7f8d..a0b920118 100644 --- a/test/unittest/mock/deviceprofile_connector_mock.cpp +++ b/test/unittest/mock/deviceprofile_connector_mock.cpp @@ -118,12 +118,11 @@ int32_t DeviceProfileConnector::CheckDeviceInfoPermission(const std::string &loc return DmDeviceProfileConnector::dmDeviceProfileConnector->CheckDeviceInfoPermission(localUdid, peerDeviceId); } -int32_t DeviceProfileConnector::GetServiceInfoProfileListByBundleName( - const DistributedDeviceProfile::ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) +int32_t DeviceProfileConnector::GetLocalServiceInfoByBundleNameAndPinExchangeType( + const std::string& bundleName, int32_t pinExchangeType, DistributedDeviceProfile::LocalServiceInfo &serviceInfo) { - return DmDeviceProfileConnector::dmDeviceProfileConnector->GetServiceInfoProfileListByBundleName(key, - serviceInfoProfiles); + return DmDeviceProfileConnector::dmDeviceProfileConnector->GetLocalServiceInfoByBundleNameAndPinExchangeType( + bundleName, pinExchangeType, serviceInfo); } int32_t DeviceProfileConnector::PutSessionKey(const std::vector &sessionKeyArray, int32_t &sessionKeyId) diff --git a/test/unittest/mock/deviceprofile_connector_mock.h b/test/unittest/mock/deviceprofile_connector_mock.h index fc11aeb8d..209e54309 100644 --- a/test/unittest/mock/deviceprofile_connector_mock.h +++ b/test/unittest/mock/deviceprofile_connector_mock.h @@ -54,8 +54,8 @@ public: virtual std::unordered_map GetAppTrustDeviceList(const std::string &pkgName, const std::string &deviceId) = 0; virtual int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId) = 0; - virtual int32_t GetServiceInfoProfileListByBundleName(const DistributedDeviceProfile::ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) = 0; + virtual int32_t GetLocalServiceInfoByBundleNameAndPinExchangeType(const std::string& bundleName, + int32_t pinExchangeType, DistributedDeviceProfile::LocalServiceInfo &serviceInfo) = 0; virtual int32_t PutSessionKey(const std::vector &sessionKeyArray, int32_t &sessionKeyId) = 0; public: static inline std::shared_ptr dmDeviceProfileConnector = nullptr; @@ -85,8 +85,8 @@ public: MOCK_METHOD((std::unordered_map), GetAppTrustDeviceList, (const std::string &, const std::string &)); MOCK_METHOD(int32_t, CheckDeviceInfoPermission, (const std::string &, const std::string &)); - MOCK_METHOD(int32_t, GetServiceInfoProfileListByBundleName, (const DistributedDeviceProfile::ServiceInfoUniqueKey&, - (std::vector&))); + MOCK_METHOD(int32_t, GetLocalServiceInfoByBundleNameAndPinExchangeType, (const std::string&, int32_t, + DistributedDeviceProfile::LocalServiceInfo &serviceInfo)); MOCK_METHOD(int32_t, PutSessionKey, (const std::vector &, int32_t&)); }; } -- Gitee