diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 901a30b7a175676d860b062641e2db95cb6cc5d4..660e0309d96ff3b67bc7b98c16aaa9cade5cb6d8 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -172,6 +172,12 @@ DM_EXPORT extern const char* APP_USER_DATA; DM_EXPORT extern const char* BUNDLE_INFO; DM_EXPORT extern const char* DM_BUSINESS_ID; +DM_EXPORT extern const char* TAG_SERVICE_BIND; +DM_EXPORT extern const char* TAG_SERVICE_INFO; +DM_EXPORT extern const char* TAG_SERVICE_INFO_NUM; +DM_EXPORT extern const char* IS_BIND_SERVICE; +DM_EXPORT extern const char* SERVICE_ID; + // screen state enum ScreenState { DM_SCREEN_UNKNOWN = -1, diff --git a/common/src/dm_constants.cpp b/common/src/dm_constants.cpp index 5a2632e9dbc5bc6bd26f6ef8e506d5769b2e6c95..6b71487b70888287d929642e20e2fe043b3e4db5 100644 --- a/common/src/dm_constants.cpp +++ b/common/src/dm_constants.cpp @@ -162,6 +162,12 @@ const char* APP_USER_DATA = "appUserData"; const char* BUNDLE_INFO = "bundleInfo"; const char* DM_BUSINESS_ID = "business_id"; +const char* TAG_SERVICE_BIND = "SERVICE_BIND"; +const char* TAG_SERVICE_INFO = "SERVICE_INFO"; +const char* TAG_SERVICE_INFO_NUM = "SERVICE_INFO_NUM"; +const char* IS_BIND_SERVICE = "isBindService"; +const char* SERVICE_ID = "serviceId"; + // errCode map const std::map MAP_ERROR_CODE = { { ERR_DM_TIME_OUT, 96929745 }, { ERR_DM_UNSUPPORTED_AUTH_TYPE, 96929760 }, { ERR_DM_AUTH_BUSINESS_BUSY, 96929761 }, diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index fdc2551374811df93c68ced3a4e255485e045b0e..9cb9aa7be2a960ca8c4f29f8f4d068db3bbdd420 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -262,6 +262,18 @@ public: DM_EXPORT void HandleDeviceUnBind(int32_t bindType, const std::string &peerUdid, const std::string &localUdid, int32_t localUserId, const std::string &localAccountId); + DM_EXPORT int32_t GetAllServiceInfoProfileList(std::vector &dmServiceInfoProfiles); + DM_EXPORT int32_t GetServiceInfoProfileListByTokenId(const DmServiceInfoUniqueKey &key, + std::vector &serviceInfos); + DM_EXPORT int32_t GetServiceInfoProfileListByDeviceId(const std::string &deviceId, + std::vector &serviceInfos); + DM_EXPORT int32_t DeleteServiceInfoProfile(const DmServiceInfoUniqueKey& key); + DM_EXPORT void GetLocalTokenIdByDeviceIdAndUserId(std::string localUdid, std::string udid, + std::map &tokenToKey); + DM_EXPORT int32_t GetServiceInfoByTokenId(DmServiceInfoUniqueKey key, + std::vector &serviceInfos); + + DM_EXPORT int32_t DeleteSessionKey(int32_t userId, int32_t sessionKeyId); DM_EXPORT int32_t GetSessionKey(int32_t userId, int32_t sessionKeyId, std::vector &sessionKeyArray); @@ -427,6 +439,11 @@ private: const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid); bool CheckExtWhiteList(const std::string &bundleName); + + // void TransferDpToDmServiceInfoProfile(const DmServiceInfoProfile &dmServiceInfoProfile, + // DistributedDeviceProfile::ServiceInfoProfile &dpServiceInfoProfile); + // void TransferDpToDmServiceInfoProfile(const DistributedDeviceProfile::ServiceInfoProfile &dpServiceInfoProfile, + // DMServiceInfoProfile &dmServiceInfoProfile); }; extern "C" IDeviceProfileConnector *CreateDpConnectorInstance(); diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 702edb00f681de79a3ce277ee1880a32e711af9e..7bf6da64a19d8feb71adf1608e791e30a83471e7 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -592,6 +592,56 @@ void DeviceProfileConnector::FilterNeedDeleteACLInfos( } } +// void DeviceProfileConnector::TransferDpToDmServiceInfoProfile(const DmServiceInfoProfile &dmServiceInfoProfile, +// DistributedDeviceProfile::ServiceInfoProfile &dpServiceInfoProfile) +// { +// dpServiceInfoProfile.SetDeviceId(dmServiceInfoProfile.deviceId); +// dpServiceInfoProfile.SetuserId(dmServiceInfoProfile.userId); +// dpServiceInfoProfile.SetNetworkId(dmServiceInfoProfile.networkId); +// dpServiceInfoProfile.SetTokenId(dmServiceInfoProfile.tokenId); +// dpServiceInfoProfile.SetServiceId(dmServiceInfoProfile.serviceRegInfo.serviceInfo.serviceId); +// dpServiceInfoProfile.SetServiceName(dmServiceInfoProfile.serviceRegInfo.serviceInfo.serviceName); +// dpServiceInfoProfile.SetServiceDisplayName(dmServiceInfoProfile.serviceRegInfo.serviceInfo.serviceDisplayName); +// dpServiceInfoProfile.SetCustomData(dmServiceInfoProfile.serviceRegInfo.serviceInfo.customData); +// dpServiceInfoProfile.SetCustomDataLen(dmServiceInfoProfile.serviceRegInfo.serviceInfo.dataLen); +// dpServiceInfoProfile.SetBundleName(dmServiceInfoProfile.serviceRegInfo.serviceInfo.bundleName); +// dpServiceInfoProfile.SetModuleName (dmServiceInfoProfile.serviceRegInfo.serviceInfo.moduleName); +// dpServiceInfoProfile.SetAbilityName(dmServiceInfoProfile.sserviceRegInfo.serviceInfo.abilityName); +// dpServiceInfoProfile.SetAuthBoxType(dmServiceInfoProfile.serviceRegInfo.authBoxType); +// dpServiceInfoProfile.SetAuthType(dmServiceInfoProfile.serviceRegInfo.authType); +// dpServiceInfoProfile.SetPinExchangeType (dmServiceInfoProfile.serviceRegInfo.pinExchangeType); +// dpServiceInfoProfile.SetPinCode(dmServiceInfoProfile.serviceRegInfo.pinCode); +// dpServiceInfoProfile.SetDescription(dmServiceInfoProfile.serviceRegInfo.description); +// dpServiceInfoProfile.SetServiceDicoveryScope(dmServiceInfoProfile.serviceRegInfo.serviceDiscoveryScope); +// dpServiceInfoProfile.SetExtraInfo(dmServiceInfoProfile.extraInfo); +// } + +// void DeviceProfileConnector::TransferDpToDmServiceInfoProfile( +// const DistributedDeviceProfile::ServiceInfoProfile &dpServiceInfoProfile, +// DMServiceInfoProfile &dmServiceInfoProfile) +// { +// dmServiceInfoProfile.deviceId = dpServiceInfoProfile.GetDeviceId(); +// dmServiceInfoProfile.userId = dpServiceInfoProfile.GetUserId(); +// dmServiceInfoProfile.networkId = dpServiceInfoProfile.GetNetworkId(); +// dmServiceInfoProfile.tokenId = dpServiceInfoProfile.GetTokenId(); +// dmServiceInfoProfile.serviceRegInfo.serviceInfo.serviceId = dpServiceInfoProfile.GetServiceId(); +// dmServiceInfoProfile.serviceRegInfo.serviceInfo.serviceType = dpServiceInfoProfile.GetServiceType(); +// dmServiceInfoProfile.serviceRegInfo.serviceInfo.serviceName = dpServiceInfoProfile.GetServiceName(); +// dmServiceInfoProfile.serviceRegInfo.serviceInfo.serviceDisplayName = dpServiceInfoProfile.GetServiceDisplayName(); +// dmServiceInfoProfile.serviceRegInfo.serviceInfo.customData = dpServiceInfoProfile.GetCustomData(); +// dmServiceInfoProfile.serviceRegInfo.serviceInfo.dataLen = dpServiceInfoProfile.GetCustomDataLen(); +// dmServiceInfoProfile.serviceRegInfo.serviceInfo.bundleName = dpServiceInfoProfile.GetBundleName(); +// dmServiceInfoProfile.serviceRegInfo.serviceInfo.moduleName = dpServiceInfoProfile.GetModuleName(); +// dmServiceInfoProfile.serviceRegInfo.serviceInfo.abilityName = dpServiceInfoProfile.GetAbilityName(); +// dmServiceInfoProfile.serviceRegInfo.authBoxType = dpServiceInfoProfile.GetAuthBoxType(); +// dmServiceInfoProfile.serviceReginfo.authType = dpServiceInfoProfile.GetAuthType(); +// dmServiceInfoProfile.serviceRegInfo.pinExchangeType= dpServiceInfoProfile.GetPinExchangeType(); +// dmServiceInfoProfile.serviceRegInfo.pinCode = dpServiceInfoProfile.GetPinCode(); +// dmServiceInfoProfile.serviceRegInfo.description = dpServiceInfoProfile.GetDescription(); +// dmServiceInfoProfile.serviceRegInfo.serviceDiscoveryScope = dpServiceInfoProfile.GetServieDicoveryScope(); +// dmServiceInfoProfile.extraInfo = dpServiceInfoProfile.GetExtraInfo(); +// } + DM_EXPORT std::vector DeviceProfileConnector::GetAccessControlProfile() { std::vector profiles; @@ -2712,6 +2762,136 @@ DM_EXPORT void DeviceProfileConnector::HandleDeviceUnBind(int32_t bindType, } } +DM_EXPORT int32_t DeviceProfileConnector::GetAllServiceInfoProfileList(std::vector &dmServiceInfoProfiles) +{ + // std::vector dpServiceInfoProfiles; + // int32_t ret = DistributedDeviceProfileClient::Getinstance().GetAllServiceInfoProfileList(dmServiceInfoProfiles); + // if (ret != DM_OK) { + // LOGE("failed: %{public}d",ret); + // return ret; + // } + // for (const auto &dpProfile : dpServiceInfoProfiles){ + // DmServiceInfoProfile dmProfile; + // TransferDpToDmServiceInfoProfile(dpProfile,dmProfile); + // dmServiceInfoProfiles.emplace_back(dmProfile); + // } + return DM_OK; +} + +DM_EXPORT int32_t DeviceProfileConnector::GetServiceInfoProfileListByTokenId(const DmServiceInfoUniqueKey &key, + std::vector &serviceInfos) +{ + ServiceInfoUniqueKey dpKey; + dpKey.SetTokenId(key.tokenId); + dpKey.SetDeviceId(key.deviceId); + dpKey.SetUserId(key.userId); + std::vector dpServiceInfos; + int32_t ret = DistributedDeviceProfileClient::GetInstance().GetServiceInfoProfileListByTokenId(dpKey, + dpServiceInfos); + if (ret != DM_OK) { + LOGE("failed: %{public}d",ret); + return ret; + } + for (auto dpServiceInfoProfile : dpServiceInfos) { + DmServiceInfoProfile dmServiceInfoProfile; + //TransferDpToDmServiceInfoProfile(dpServiceInfoProfile,dmServiceInfoProfile); + serviceInfos.push_back(dmServiceInfoProfile); + } + return DM_OK; +} + +int32_t DeviceProfileConnector::GetServiceInfoProfileListByDeviceId(const std::string &deviceId, + std::vector &serviceInfos) +{ + std::vector serviceInfoProfiles; + + if (GetAllServiceInfoProfileList(serviceInfoProfiles)) { + return ERR_DM_FAILED; + } + if (serviceInfoProfiles.empty()) { + LOGE("GetServiceInfosByTokenId failed, serviceInfoProfiles is empty."); + return ERR_DM_FAILED; + } + for (auto const &item : serviceInfoProfiles) { + if (item.deviceId == deviceId) { + serviceInfos.push_back(item.serviceRegInfo.serviceInfo); + } + } + return DM_OK; +} + +int32_t DeviceProfileConnector::DeleteServiceInfoProfile(const DmServiceInfoUniqueKey& key) +{ + DistributedDeviceProfile::ServiceInfoUniqueKey dpKey; + dpKey.SetDeviceId(key.deviceId); + dpKey.SetServiceId(key.serviceId); + dpKey.SetTokenId(key.tokenId); + dpKey.SetUserId(key.userId); + int32_t ret = DistributedDeviceProfileClient::GetInstance().DeleteServiceInfoProfile(dpKey); + if (ret != DM_OK) { + LOGE("failed: %{public}d", ret); + return ret; + } + return DM_OK; +} + +void DeviceProfileConnector::GetLocalTokenIdByDeviceIdAndUserId(std::string localUdid, std::string udid, + std::map &tokenToKey) +{ + int32_t userId = MultipleUserConnector::GetCurrentAccountUserID(); + std::vector profiles = GetAclProfileByDeviceIdAndUserId(localUdid, userId); + + uint64_t localToken; + uint64_t peerToken; + DmServiceInfoUniqueKey key = { 0 }; + key.deviceId = udid; + for (auto &item : profiles){ + if (item.GetStatus()!= ACTIVE) { + continue; + } + if (item.GetAccessee().GetAccesseeDeviceId() == localUdid && + item.GetAccesser().GetAccesserDeviceId() == udid) { + localToken = static_cast(item.GetAccessee().GetAccesseeTokenId()); + peerToken = static_cast(item.GetAccesser().GetAccesserTokenId()); + key.tokenId = std::to_string(peerToken); + key.userId = item.GetAccesser().GetAccesserUserId(); + } + if (item.GetAccessee().GetAccesseeDeviceId() == udid && + item.GetAccesser().GetAccesserDeviceId() == localUdid) { + peerToken = static_cast(item.GetAccessee().GetAccesseeTokenId()); + localToken = static_cast(item.GetAccesser().GetAccesserTokenId()); + key.tokenId = std::to_string(peerToken); + key.userId = item.GetAccessee().GetAccesseeUserId(); + } + tokenToKey.insert(std::pair(std::to_string(localToken), key)); + } +} + +DM_EXPORT int32_t DeviceProfileConnector::GetServiceInfoByTokenId(DmServiceInfoUniqueKey key, + std::vector &serviceInfos) +{ + std::vector infos; + DistributedDeviceProfile::ServiceInfoUniqueKey keyIndex(key.deviceId, key.userId, key.tokenId, -1); + auto ret = DistributedDeviceProfileClient::GetInstance().GetServiceInfoProfileListByTokenId(keyIndex, infos); + if (ret != 0) { + return ret; + } + DmServiceInfo serviceInfo; + for (auto info : infos) { + serviceInfo.serviceId = info.GetServiceId(); + serviceInfo.serviceType = info.GetServiceType(); + serviceInfo.serviceName = info.GetServiceName(); + serviceInfo.serviceDisplayName = info.GetServiceDisplayName(); + serviceInfo.customData = info.GetCustomData(); + serviceInfo.customDataLen = info.GetCustomDataLen(); + serviceInfo.bundleName = info.GetBundleName(); + serviceInfo.moduleName = info.GetModuleName(); + serviceInfo.abilityName = info.GetAbilityName(); + serviceInfos.push_back(serviceInfo); + } + return DM_OK; +} + DM_EXPORT int32_t DeviceProfileConnector::SubscribeDeviceProfileInited( sptr dpInitedCallback) { 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 67c3a32aec0a6114bef43e50c0ce4ad577cbf7eb..d624a2675e82c64b7b44e0a3f8c5f61941132daa 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -30,6 +30,80 @@ namespace OHOS { namespace DistributedHardware { + +typedef struct DmServiceInfo { + int64_t serviceId = 0; + std::string serviceType; + std::string serviceName; + std::string serviceDisplayName; + std::string customData; + uint32_t customDataLen = 0; + std::string bundleName; + std::string moduleName; + std::string abilityName; + //std::string extraInfo; +} DmServiceInfo; + +typedef struct ServiceRegInfo { + DmServiceInfo serviceInfo; + int32_t authBoxType = 0; + int32_t authType = 0; + int32_t pinExchangeType = 0; + std::string pinCode; + std::string description; + std::string serviceDiscoveryScope; +} ServiceRegInfo; + +typedef struct DmServiceInfoUniqueKey { + std::string deviceId; + int32_t userId = 0; + std::string tokenId; + int64_t serviceId = 0; +} DmServiceInfoUniqueKey; + +typedef struct DmServiceInfoProfile { + ServiceRegInfo serviceRegInfo; + std::string deviceId; + int32_t userId = 0; + std::string networkId; + std::string tokenId; + std::string extraInfo; +} DmServiceInfoProfile; + +typedef struct ServiceBindLocalInfo { + std::string localUdid; + int32_t userId = 0; + uint32_t tokenId = 0; +} ServiceBindLocalInfo; + +typedef struct DmServiceAddress{ + std::string bleMac; + uint32_t actionId = 0; +} DmServiceAddress; + +typedef struct DmServiceInfoDeviceProfile{ + std::string deviceId; + int32_t userId = 0; + std::string networkId; + std::string tokenId; + int64_t serviceId = 0; + std::string serviceType; + std::string serviceName; + std::string serviceDisplayName; + std::string customData; + int32_t customDataLen = 0; + 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 serviceDicoveryScope; + std::string extraInfo; +} DmServiceInfoDeviceProfile; + /** * @brief Device manager event notify. */ @@ -192,6 +266,9 @@ typedef struct DmDeviceInfo { * include json keys: "CONN_ADDR_TYPE", "BR_MAC_", "BLE_MAC", "WIFI_IP", "WIFI_PORT", "CUSTOM_DATA" */ std::string extraData; + + //std::vector serviceInfos; + std::map> tokenToServiceInfos; } DmDeviceInfo; /** @@ -292,11 +369,17 @@ typedef struct PeerTargetId { * wlan ip port. */ uint16_t wifiPort = 0; + /** + * service id. + */ + int64_t serviceId = 0; + bool operator==(const PeerTargetId &other) const { return (deviceId == other.deviceId) && (brMac == other.brMac) && - (bleMac == other.bleMac) && (wifiIp == other.wifiIp) && (wifiPort == other.wifiPort); + (bleMac == other.bleMac) && (wifiIp == other.wifiIp) && (wifiPort == other.wifiPort) && + (serviceId == other.serviceId); } bool operator<(const PeerTargetId &other) const @@ -306,7 +389,9 @@ typedef struct PeerTargetId { (deviceId == other.deviceId && brMac == other.brMac && bleMac < other.bleMac) || (deviceId == other.deviceId && brMac == other.brMac && bleMac == other.bleMac && wifiIp < other.wifiIp) || (deviceId == other.deviceId && brMac == other.brMac && bleMac == other.bleMac && wifiIp == other.wifiIp && - wifiPort < other.wifiPort); + wifiPort < other.wifiPort) || + (deviceId == other.deviceId && brMac == other.brMac && bleMac == other.bleMac && wifiIp == other.wifiIp && + wifiPort == other.wifiPort && serviceId < other.serviceId); } } PeerTargetId; diff --git a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h index b93d073e433fb89e043b45a94d39dd81b9cbc3ab..cb4bb85bc260c8e3638704898fe98dfe3c505d4a 100644 --- a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h +++ b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h @@ -106,6 +106,7 @@ public: virtual void OnSessionOpened(int32_t sessionId, int32_t sessionSide, int32_t result) = 0; virtual void OnSessionClosed(const int32_t sessionId) = 0; virtual void OnBytesReceived(const int32_t sessionId, const std::string message) = 0; + virtual int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) = 0; }; using CreateDMServiceImplExtFuncPtr = IDMServiceImplExt *(*)(void); diff --git a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext_resident.h b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext_resident.h index 0b957825216fc0e4fea898150b6d52d067605322..3211cd8c21acaed7229ee2b3ba55294d850b3c64 100644 --- a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext_resident.h +++ b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext_resident.h @@ -111,6 +111,7 @@ public: virtual int32_t RestoreLocalDeviceName() = 0; virtual void ClearCacheWhenLogout(int32_t userId, const std::string &oldAccountId) = 0; virtual void HandleScreenLockEvent(bool isLock) = 0; + virtual int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) = 0; }; using CreateDMServiceExtResidentFuncPtr = IDMServiceImplExtResident *(*)(void); diff --git a/interfaces/inner_kits/native_cpp/include/idevice_manager_service_listener.h b/interfaces/inner_kits/native_cpp/include/idevice_manager_service_listener.h index cc7a97ace4b57eab431d620b932ad2e60bc430e5..336c5b631bd1e523058e86a725f72225b2997688 100644 --- a/interfaces/inner_kits/native_cpp/include/idevice_manager_service_listener.h +++ b/interfaces/inner_kits/native_cpp/include/idevice_manager_service_listener.h @@ -176,6 +176,7 @@ public: virtual void SetExistPkgName(const std::set &pkgNameSet) = 0; virtual std::string GetLocalDisplayDeviceName() = 0; + virtual int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index 633b02b6b4baa9ea0b3dbf807bff94168efc9b96..2eb015b6cdba0c84f6eab4d9e98b36cf28105ac7 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -207,7 +207,7 @@ napi_value CreateBusinessError(napi_env env, int32_t errCode, bool isAsync = tru return error; } -void DeleteUvWork(uv_work_t *work) +void DeleteUvWork(uv_work_t *&work) { if (work == nullptr) { return; @@ -217,7 +217,7 @@ void DeleteUvWork(uv_work_t *work) LOGI("delete work!"); } -void DeleteDmNapiStateJsCallbackPtr(DmNapiStateJsCallback *pJsCallbackPtr) +void DeleteDmNapiStateJsCallbackPtr(DmNapiStateJsCallback *&pJsCallbackPtr) { if (pJsCallbackPtr == nullptr) { return; @@ -227,7 +227,7 @@ void DeleteDmNapiStateJsCallbackPtr(DmNapiStateJsCallback *pJsCallbackPtr) LOGI("delete DmNapiStateJsCallback callbackPtr!"); } -void DeleteAsyncCallbackInfo(DeviceInfoListAsyncCallbackInfo *pAsynCallbackInfo) +void DeleteAsyncCallbackInfo(DeviceInfoListAsyncCallbackInfo *&pAsynCallbackInfo) { if (pAsynCallbackInfo == nullptr) { return; diff --git a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp index 005d39c8af4c7f3d0108af28d51788c29f7b842b..2aa78c1ab4f9de5c2bbabfbc4e20d61cdf2e8158 100644 --- a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp @@ -86,7 +86,7 @@ std::mutex g_authCallbackMapMutex; std::mutex g_bindCallbackMapMutex; std::mutex g_dmUiCallbackMapMutex; -void DeleteUvWork(uv_work_t *work) +void DeleteUvWork(uv_work_t *&work) { if (work == nullptr) { return; @@ -96,7 +96,7 @@ void DeleteUvWork(uv_work_t *work) LOGI("delete work!"); } -void DeleteDmNapiStatusJsCallbackPtr(DmNapiStatusJsCallback *pJsCallbackPtr) +void DeleteDmNapiStatusJsCallbackPtr(DmNapiStatusJsCallback *&pJsCallbackPtr) { if (pJsCallbackPtr == nullptr) { return; @@ -106,7 +106,7 @@ void DeleteDmNapiStatusJsCallbackPtr(DmNapiStatusJsCallback *pJsCallbackPtr) LOGI("delete DmNapiStatusJsCallback callbackPtr!"); } -void DeleteAsyncCallbackInfo(DeviceBasicInfoListAsyncCallbackInfo *pAsynCallbackInfo) +void DeleteAsyncCallbackInfo(DeviceBasicInfoListAsyncCallbackInfo *&pAsynCallbackInfo) { if (pAsynCallbackInfo == nullptr) { return; diff --git a/services/implementation/include/authentication_v2/dm_auth_context.h b/services/implementation/include/authentication_v2/dm_auth_context.h index f4308c85632a16e02e86564d00c942787fe9cc7e..4d9d52f1c5635d4fb4360b1c321594f1a28aefec 100644 --- a/services/implementation/include/authentication_v2/dm_auth_context.h +++ b/services/implementation/include/authentication_v2/dm_auth_context.h @@ -182,6 +182,7 @@ struct DmAccess { std::string pkgName; // store pkgName set by client std::string language; int64_t serviceId; // Reserved field, to be used in HM 6.0 + std::vector serviceInfos; std::string accesserHapSignature; int32_t bindLevel; int32_t lnnBindType; diff --git a/services/implementation/include/authentication_v2/dm_auth_message_processor.h b/services/implementation/include/authentication_v2/dm_auth_message_processor.h index 5192992bde31ffe817560ce771a8f50b76e43029..ba71a8cd2c103683bb707d3127ee0300db104642 100644 --- a/services/implementation/include/authentication_v2/dm_auth_message_processor.h +++ b/services/implementation/include/authentication_v2/dm_auth_message_processor.h @@ -232,6 +232,9 @@ private: // Parse the authentication start message int32_t ParseAuthStartMessage(const JsonObject &jsonObject, std::shared_ptr context); + void ParseSrcServiceInfoToContext(const JsonObject &serviceJson, std::shared_ptr context); + void ParseSinkServiceInfoToContext(const JsonObject &serviceJson, std::shared_ptr context); + // Parse the 80 message int32_t ParseNegotiateMessage(const JsonObject &jsonObject, std::shared_ptr context); int32_t ParseProxyNegotiateMessage(const JsonObject &jsonObject, std::shared_ptr context); diff --git a/services/implementation/include/authentication_v2/dm_auth_state.h b/services/implementation/include/authentication_v2/dm_auth_state.h index 8e948a6664f720607f6611b07713de1093c77010..b2a5cc3a72817d8745bb951414d592d72bbc18d2 100644 --- a/services/implementation/include/authentication_v2/dm_auth_state.h +++ b/services/implementation/include/authentication_v2/dm_auth_state.h @@ -175,6 +175,11 @@ public: static void DeleteAclAndSk(std::shared_ptr context, const DistributedDeviceProfile::AccessControlProfile &profile); void GetPeerDeviceId(std::shared_ptr context, std::string &peerDeviceId); + + int32_t GetSrcServiceInfoParam(std::vector &serviceInfoProfiles, + std::shared_ptr context); + int32_t GetSinkServiceInfoParam(std::vector &serviceInfoProfiles, + std::shared_ptr context); protected: bool NeedReqUserConfirm(std::shared_ptr context); bool NeedAgreeAcl(std::shared_ptr context); diff --git a/services/implementation/include/dependency/softbus/softbus_session.h b/services/implementation/include/dependency/softbus/softbus_session.h index b3dfc2840c51d70cb62f9858279d96ad30b329d8..aaa548f361113f91bb2f8223f50c04a06673634d 100644 --- a/services/implementation/include/dependency/softbus/softbus_session.h +++ b/services/implementation/include/dependency/softbus/softbus_session.h @@ -59,13 +59,6 @@ public: */ int32_t OpenAuthSession(const std::string &deviceId); - /** - * @tc.name: SoftbusSession::OpenAuthSessionWithPara - * @tc.desc: Open HML AuthSession of the Softbus Session - * @tc.type: FUNC - */ - int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m); - /** * @tc.name: SoftbusSession::CloseAuthSession * @tc.desc: Close AuthSession of the Softbus Session diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index ded639356c1946ed37091e086b3d162a42049f2e..60f51ac5c5fbb4c002aa89d88b9a37292d12b74d 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -868,10 +868,11 @@ int32_t DmAuthManager::EstablishAuthChannel(const std::string &deviceId) int32_t sessionId = 0; if (IsHmlSessionType()) { CHECK_NULL_RETURN(authRequestContext_, ERR_DM_FAILED); + CHECK_NULL_RETURN(listener_, ERR_DM_FAILED); LOGI("hmlActionId %{public}d, hmlReleaseTime %{public}d, hmlEnable160M %{public}d", authRequestContext_->hmlActionId, authRequestContext_->closeSessionDelaySeconds, authRequestContext_->hmlEnable160M); - sessionId = softbusConnector_->GetSoftbusSession()->OpenAuthSessionWithPara(deviceId, + sessionId = listener_->OpenAuthSessionWithPara(deviceId, authRequestContext_->hmlActionId, authRequestContext_->hmlEnable160M); } else { sessionId = softbusConnector_->GetSoftbusSession()->OpenAuthSession(deviceId); diff --git a/services/implementation/src/authentication_v2/auth_stages/auth_credential.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_credential.cpp index 4bada104f53d5f96a04388633dd50e492d6e1abe..8212df269f23832a3a07e9cf65324bb30b059b28 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_credential.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_credential.cpp @@ -568,6 +568,12 @@ int32_t AuthSrcCredentialExchangeState::Action(std::shared_ptr co return ret; } + std::vector serviceInfoProfiles; + ret = GetSrcServiceInfoParam(serviceInfoProfiles, context); + if (ret != DM_OK) { + LOGE("AuthManager::GetAuthParam GetSrcServiceInfoParam failed."); + } + std::string message = context->authMessageProcessor->CreateMessage(MSG_TYPE_REQ_CREDENTIAL_EXCHANGE, context); LOGI("AuthSrcCredentialExchangeState::Action() leave."); return context->softbusConnector->GetSoftbusSession()->SendData(context->sessionId, message); @@ -590,6 +596,13 @@ int32_t AuthSinkCredentialExchangeState::Action(std::shared_ptr c return ret; } + // Generate service information + std::vector serviceInfoProfiles; + ret = GetSinkServiceInfoParam(serviceInfoProfiles, context); + if (ret != DM_OK) { + LOGE("AuthSinkNegotiateStateMachine::GetAuthParam GetSinkServiceInfoParam failed."); + } + // First authentication lnn cred if (context->accessee.isGenerateLnnCredential && context->accessee.bindLevel != USER) { // Generate credentials and public key diff --git a/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp b/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp index 3ff2a9174a405c2004b31873995be1922bb0852b..ee0d3e50ac1a4a9798a272b1371b906926c91756 100644 --- a/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp @@ -76,6 +76,21 @@ const char* TAG_TOKEN_ID = "tokenId"; const char* TAG_NETWORKID_ID = "networkId"; const char* TAG_ISSUER = "issuer"; +//service info related +const char* TAG_SERVICE_INFOS = "serviceInfos"; +const char* TAG_SERVICE_ID = "serviceId"; +const char* TAG_SERVICE_TYPE = "serviceType"; +const char* TAG_SERVICE_NAME = "serviceName"; +const char* TAG_SERVICE_DISPLAY_NAME = "serviceDisplayName"; +const char* TAG_CUSTOM_DATA = "customData"; +const char* TAG_CUSTOM_DATA_LEN = "customDataLen"; +//const char* TAG_BUNDLE_NAME = "bundleName"; +const char* TAG_MODULE_NAME = "moduleName"; +const char* TAG_ABILIY_NAME = "abilityName"; +const char* TAG_DESCRIPTION = "description"; +const char* TAG_SERVICE_DICCOVERY_SCOPE = "serviceDiscoveryScope"; +const char* TAG_EXTRA_INFO = "extraInfo"; + const char* TAG_DEVICE_VERSION = "deviceVersion"; const char* TAG_DEVICE_NAME = "deviceName"; const char* TAG_DEVICE_ID_HASH = "deviceIdHash"; @@ -89,7 +104,6 @@ const char* TAG_STATE = "state"; const char* TAG_REASON = "reason"; const char* TAG_PEER_USER_ID = "peerUserId"; const char* TAG_PEER_DISPLAY_ID = "peerDisplayId"; -const char* TAG_EXTRA_INFO = "extraInfo"; const char* TAG_ACL_TYPE_LIST = "aclTypeList"; const char* TAG_CERT_TYPE_LIST = "certTypeList"; @@ -653,11 +667,15 @@ int32_t DmAuthMessageProcessor::ParseMessageReqCredExchange(const JsonObject &js LOGE("DmAuthMessageProcessor::ParseMessageReqCredExchange, MSG_TYPE_REQ_CREDENTIAL_EXCHANGE message error."); return ERR_DM_FAILED; } + ParseSrcServiceInfoToContext(jsonData, context); + context->accesser.transmitPublicKey = jsonData[TAG_TRANSMIT_PUBLIC_KEY].Get(); context->accesser.deviceId = jsonData[TAG_DEVICE_ID].Get(); context->accesser.userId = jsonData[TAG_PEER_USER_SPACE_ID].Get(); context->accesser.tokenId = jsonData[TAG_TOKEN_ID].Get(); ParseProxyCredExchangeToSync(context, jsonData); + context->accesser.networkId = jsonData[TAG_NETWORKID_ID].Get(); + //这里需要put DP数据库 context->authStateMachine->TransitionTo(std::make_shared()); return DM_OK; } @@ -699,11 +717,16 @@ int32_t DmAuthMessageProcessor::ParseMessageRspCredExchange(const JsonObject &js "message error."); return ERR_DM_FAILED; } + + ParseSinkServiceInfoToContext(jsonData, context); + context->accessee.transmitPublicKey = jsonData[TAG_TRANSMIT_PUBLIC_KEY].Get(); context->accessee.deviceId = jsonData[TAG_DEVICE_ID].Get(); context->accessee.userId = jsonData[TAG_PEER_USER_SPACE_ID].Get(); context->accessee.tokenId = jsonData[TAG_TOKEN_ID].Get(); ParseProxyCredExchangeToSync(context, jsonData); + context->accessee.networkId = jsonData[TAG_NETWORKID_ID].Get(); + //这里需要 put DP数据库 context->authStateMachine->TransitionTo(std::make_shared()); return DM_OK; } @@ -901,6 +924,25 @@ int32_t DmAuthMessageProcessor::CreateMessageReqCredExchange(std::shared_ptraccesser.userId; jsonData[TAG_TOKEN_ID] = context->accesser.tokenId; CreateProxyCredExchangeMessage(context, jsonData); + jsonData[TAG_NETWORKID_ID] = context->accesser.networkId; + + //create service infos + JsonObject serviceInfosJson(JsonCreateType::JSON_CREATE_TYPE_ARRAY); + for (auto item : context->accesser.serviceInfos) { + JsonObject childServiceJson(JsonCreateType::JSON_CREATE_TYPE_OBJECT); + childServiceJson[TAG_SERVICE_ID] = item.serviceId; + childServiceJson[TAG_SERVICE_TYPE] = item.serviceType; + childServiceJson[TAG_SERVICE_NAME] = item.serviceName; + childServiceJson[TAG_SERVICE_DISPLAY_NAME] = item.serviceDisplayName; + childServiceJson[TAG_CUSTOM_DATA] = item.customData; + childServiceJson[TAG_CUSTOM_DATA_LEN] = item.customDataLen; + childServiceJson[TAG_BUNDLE_NAME] = item.bundleName; + childServiceJson[TAG_MODULE_NAME] = item.moduleName; + childServiceJson[TAG_ABILIY_NAME] = item.abilityName; + serviceInfosJson.PushBack(childServiceJson); + } + jsonData[TAG_SERVICE_INFOS] = serviceInfosJson.Dump(); + std::string plainText = jsonData.Dump(); std::string cipherText; int32_t ret = cryptoMgr_->EncryptMessage(plainText, cipherText); @@ -926,6 +968,25 @@ int32_t DmAuthMessageProcessor::CreateMessageRspCredExchange(std::shared_ptraccessee.userId; jsonData[TAG_TOKEN_ID] = context->accessee.tokenId; CreateProxyCredExchangeMessage(context, jsonData); + jsonData[TAG_NETWORKID_ID] = context->accessee.networkId; + + //create service infos + JsonObject serviceInfosJson(JsonCreateType::JSON_CREATE_TYPE_ARRAY); + for (auto item : context->accessee.serviceInfos) { + JsonObject childServiceJson(JsonCreateType::JSON_CREATE_TYPE_OBJECT); + childServiceJson[TAG_SERVICE_ID] = item.serviceId; + childServiceJson[TAG_SERVICE_TYPE] = item.serviceType; + childServiceJson[TAG_SERVICE_NAME] = item.serviceName; + childServiceJson[TAG_SERVICE_DISPLAY_NAME] = item.serviceDisplayName; + childServiceJson[TAG_CUSTOM_DATA] = item.customData; + childServiceJson[TAG_CUSTOM_DATA_LEN] = item.customDataLen; + childServiceJson[TAG_BUNDLE_NAME] = item.bundleName; + childServiceJson[TAG_MODULE_NAME] = item.moduleName; + childServiceJson[TAG_ABILIY_NAME] = item.abilityName; + serviceInfosJson.PushBack(childServiceJson); + } + jsonObject[TAG_SERVICE_INFOS] = serviceInfosJson.Dump(); + std::string plainText = jsonData.Dump(); std::string cipherText; LOGI("plainText=%{public}s", GetAnonyJsonString(plainText).c_str()); @@ -1255,6 +1316,97 @@ int32_t DmAuthMessageProcessor::CheckLogicalSessionId(const JsonObject &jsonObje return DM_OK; } +void DmAuthMessageProcessor::ParseSrcServiceInfoToContext(const JsonObject &serviceJson, + std::shared_ptr context) +{ + if (context == nullptr || !serviceJson.Contains(TAG_SERVICE_INFOS)) { + LOGE("DmAuthMessageProcessor::ParseSrcServiceInfoToContext context is null or TAG_SERVICE_INFOS not found"); + return; + } + + if (serviceJson.Contains(TAG_SERVICE_INFOS) && serviceJson[TAG_SERVICE_INFOS].IsString()) { + JsonObject serviceinfos(JsonCreateType::JSON_CREATE_TYPE_ARRAY); + serviceinfos.Parse(serviceJson[TAG_SERVICE_INFOS].Get()); + std::vector serviceVec = serviceinfos.Items(); + for (auto item : serviceVec) { + DmServiceInfo serviceInfo; + if (item.Contains(TAG_SERVICE_ID) && item[TAG_SERVICE_ID].IsString()) { + serviceInfo.serviceId = item[TAG_SERVICE_ID].Get(); + } + if (item.Contains(TAG_SERVICE_TYPE) && item[TAG_SERVICE_TYPE].IsString()) { + serviceInfo.serviceType = item[TAG_SERVICE_TYPE].Get(); + } + if (item.Contains(TAG_SERVICE_NAME) && item[TAG_SERVICE_NAME].IsString()) { + serviceInfo.serviceName = item[TAG_SERVICE_NAME].Get(); + } + if (item.Contains(TAG_SERVICE_DISPLAY_NAME) && item[TAG_SERVICE_DISPLAY_NAME].IsString()) { + serviceInfo.serviceDisplayName = item[TAG_SERVICE_DISPLAY_NAME].Get(); + } + if (item.Contains(TAG_CUSTOM_DATA) && item[TAG_CUSTOM_DATA].IsString()) { + serviceInfo.customData = item[TAG_CUSTOM_DATA].Get(); + } + if (item.Contains(TAG_CUSTOM_DATA_LEN) && item[TAG_CUSTOM_DATA_LEN].IsNumberInteger()) { + serviceInfo.customDataLen = item[TAG_CUSTOM_DATA_LEN].Get(); + } + if (item.Contains(TAG_BUNDLE_NAME) && item[TAG_BUNDLE_NAME].IsString()) { + serviceInfo.bundleName = item[TAG_BUNDLE_NAME].Get(); + } + if (item.Contains(TAG_MODULE_NAME) && item[TAG_MODULE_NAME].IsString()) { + serviceInfo.moduleName = item[TAG_MODULE_NAME].Get(); + } + if (item.Contains(TAG_ABILIY_NAME) && item[TAG_ABILIY_NAME].IsString()) { + serviceInfo.abilityName = item[TAG_ABILIY_NAME].Get(); + } + context->accesser.serviceInfos.push_back(serviceInfo); + } + } +} + +void DmAuthMessageProcessor::ParseSinkServiceInfoToContext(const JsonObject &serviceJson, + std::shared_ptr context) +{ + if ((context == nullptr) || (!serviceJson.Contains(TAG_SERVICE_INFOS))) { + LOGE("DmAuthMessageProcessor::ParseSinkServiceInfoToContext context is null or TAG_SERVICE_INFOS not found"); + return; + } + if (serviceJson[TAG_SERVICE_INFOS].IsString()) { + JsonObject serviceinfos(JsonCreateType::JSON_CREATE_TYPE_ARRAY); + serviceinfos.Parse(serviceJson[TAG_SERVICE_INFOS].Get()); + std::vector serviceVec = serviceinfos.Items(); + for (auto item : serviceVec) { + DmServiceInfo serviceInfo; + if (item.Contains(TAG_SERVICE_ID) && item[TAG_SERVICE_ID].IsString()) { + serviceInfo.serviceId = item[TAG_SERVICE_ID].Get(); + } + if (item.Contains(TAG_SERVICE_TYPE) && item[TAG_SERVICE_TYPE].IsString()) { + serviceInfo.serviceType = item[TAG_SERVICE_TYPE].Get(); + } + if (item.Contains(TAG_SERVICE_NAME) && item[TAG_SERVICE_NAME].IsString()) { + serviceInfo.serviceName = item[TAG_SERVICE_NAME].Get(); + } + if (item.Contains(TAG_SERVICE_DISPLAY_NAME) && item[TAG_SERVICE_DISPLAY_NAME].IsString()) { + serviceInfo.serviceDisplayName = item[TAG_SERVICE_DISPLAY_NAME].Get(); + } + if (item.Contains(TAG_CUSTOM_DATA) && item[TAG_CUSTOM_DATA].IsString()) { + serviceInfo.customData = item[TAG_CUSTOM_DATA].Get(); + } + if (item.Contains(TAG_CUSTOM_DATA_LEN) && item[TAG_CUSTOM_DATA_LEN].IsNumberInteger()) { + serviceInfo.customDataLen = item[TAG_CUSTOM_DATA_LEN].Get(); + } + if (item.Contains(TAG_BUNDLE_NAME) && item[TAG_BUNDLE_NAME].IsString()) { + serviceInfo.bundleName = item[TAG_BUNDLE_NAME].Get(); + } + if (item.Contains(TAG_MODULE_NAME) && item[TAG_MODULE_NAME].IsString()) { + serviceInfo.moduleName = item[TAG_MODULE_NAME].Get(); + } + if (item.Contains(TAG_ABILIY_NAME) && item[TAG_ABILIY_NAME].IsString()) { + serviceInfo.abilityName = item[TAG_ABILIY_NAME].Get(); + } + context->accessee.serviceInfos.push_back(serviceInfo); + } + } +} + int32_t DmAuthMessageProcessor::ParseNegotiateMessage( const JsonObject &jsonObject, std::shared_ptr context) { diff --git a/services/implementation/src/authentication_v2/dm_auth_state.cpp b/services/implementation/src/authentication_v2/dm_auth_state.cpp index 9a0952c9cc4e44280e30b0020ce6c475e36674a6..e47c7c3e322071ee922005932e7546bc73950b39 100644 --- a/services/implementation/src/authentication_v2/dm_auth_state.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_state.cpp @@ -580,6 +580,54 @@ void DmAuthState::DeleteAcl(std::shared_ptr context, DeviceProfileConnector::GetInstance().DeleteAccessControlById(profile.GetAccessControlId()); } +int32_t DmAuthState::GetSrcServiceInfoParam(std::vector &serviceInfoProfiles, std::shared_ptr context) +{ + if (DeviceProfileConnector::GetInstance().GetAllServiceInfoProfileList(serviceInfoProfiles)) { + return ERR_DM_FAILED; + } + if (serviceInfoProfiles.empty()) { + LOGE("GetSrcServiceInfoParam failed, serviceInfoProfiles is empty."); + return ERR_DM_FAILED; + } + std::string tokenId; + for (auto const &item : serviceInfoProfiles) { + if (item.serviceRegInfo.serviceInfo.serviceId == context->peerTargetId.serviceId) { + tokenId = item.tokenId; + break; + } + } + for (auto const &item : serviceInfoProfiles) { + if (item.tokenId == tokenId) { + context->accesser.serviceInfos.push_back(item.serviceRegInfo.serviceInfo); + } + } + return DM_OK; +} + +int32_t DmAuthState::GetSinkServiceInfoParam(std::vector &serviceInfoProfiles, std::shared_ptr context) +{ + if (DeviceProfileConnector::GetInstance().GetAllServiceInfoProfileList(serviceInfoProfiles)) { + return ERR_DM_FAILED; + } + if (serviceInfoProfiles.empty()) { + LOGE("GetSinkServiceInfoParam failed, serviceInfoProfiles is empty."); + return ERR_DM_FAILED; + } + std::string tokenId; + for (auto const &item : serviceInfoProfiles) { + if (item.serviceRegInfo.serviceInfo.serviceId == context->peerTargetId.serviceId) { + tokenId = item.tokenId; + break; + } + } + for (auto const &item : serviceInfoProfiles) { + if (item.tokenId == tokenId) { + context->accessee.serviceInfos.push_back(item.serviceRegInfo.serviceInfo); + } + } + return DM_OK; +} + void DmAuthState::SetProcessInfo(std::shared_ptr context) { CHECK_NULL_VOID(context); diff --git a/services/implementation/src/dependency/softbus/softbus_session.cpp b/services/implementation/src/dependency/softbus/softbus_session.cpp index 056eb40442acffaca75ff0bc67d5ff22945fa10f..1563f8b861969b505a82fda35348ba07a38436ca 100644 --- a/services/implementation/src/dependency/softbus/softbus_session.cpp +++ b/services/implementation/src/dependency/softbus/softbus_session.cpp @@ -23,9 +23,6 @@ #include "json_object.h" #include "softbus_connector.h" #include "softbus_error_code.h" -#ifndef DEVICE_MANAGER_COMMON_FLAG -#include "session_ex.h" -#endif namespace OHOS { namespace DistributedHardware { @@ -75,29 +72,6 @@ int32_t SoftbusSession::OpenAuthSession(const std::string &deviceId) return sessionId; } -int32_t SoftbusSession::OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) -{ -#ifdef DEVICE_MANAGER_COMMON_FLAG - LOGE("[SOFTBUS] OpenAuthSessionWithPara no implement"); - return SOFTBUS_NOT_IMPLEMENT; -#else - DmTraceStart(std::string(DM_HITRACE_AUTH_TO_OPPEN_SESSION)); - LinkPara para; - para.type = PARA_ACTION; - para.action.actionId = static_cast(actionId); - para.enable160M = isEnable160m; - para.accountInfo = false; - int32_t sessionId = ::OpenAuthSessionWithPara(DM_SESSION_NAME, ¶); - if (sessionId < 0) { - LOGE("[SOFTBUS]open session error, sessionId: %{public}d.", sessionId); - return sessionId; - } - DmTraceEnd(); - LOGI("OpenAuthSessionWithPara success. sessionId: %{public}d.", sessionId); - return sessionId; -#endif -} - int32_t SoftbusSession::CloseAuthSession(int32_t sessionId) { LOGI("CloseAuthSession."); diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 370064b1d36348465034a97f40f2f3a0748b74a6..36dccf96aa6b107eb30ad7218818dec8efd90ffd 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -1529,8 +1529,8 @@ int DeviceManagerServiceImpl::OpenAuthSession(const std::string& deviceId, return ret; } LOGI("hmlActionId %{public}d, hmlEnable160M %{public}d", hmlActionId, hmlEnable160M); - return softbusConnector_->GetSoftbusSession()->OpenAuthSessionWithPara(deviceId, - hmlActionId, hmlEnable160M); + CHECK_NULL_RETURN(listener_, ERR_DM_FAILED); + return listener_->OpenAuthSessionWithPara(deviceId, hmlActionId, hmlEnable160M); } else { return softbusConnector_->GetSoftbusSession()->OpenAuthSession(deviceId); } diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 4ac7e9d87f34f931df4aa5fd97f63cb3fc2e163c..1f570c46862574e8c18c071634b66074c1213b60 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -185,11 +185,12 @@ public: int32_t StopAdvertising(const std::string &pkgName, const std::map &advertiseParam); - int32_t BindTarget(const std::string &pkgName, const PeerTargetId &targetId, - const std::map &bindParam); - - int32_t UnbindTarget(const std::string &pkgName, const PeerTargetId &targetId, - const std::map &unbindParam); + int32_t BindTarget(const std::string &pkgName, PeerTargetId &targetId, + std::map &bindParam); + int32_t UnbindTarget(const std::string &pkgName, PeerTargetId &targetId, + std::map &unbindParam); + + void ServiceInfoBindParmamHandle(PeerTargetId &targetId, std::map &bindParam); int32_t DpAclAdd(const std::string &udid); @@ -258,6 +259,7 @@ public: int32_t GetDeviceNetworkIdList(const std::string &pkgName, const NetworkIdQueryFilter &queryFilter, std::vector &networkIds); void ProcessSyncAccountLogout(const std::string &accountId, const std::string &peerUdid, int32_t userId); + int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m); int32_t UnRegisterPinHolderCallback(const std::string &pkgName); void ProcessReceiveRspAppUninstall(const std::string &remoteUdid); void ProcessReceiveRspAppUnbind(const std::string &remoteUdid); @@ -269,6 +271,22 @@ public: bool CheckSinkAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee); bool CheckSrcIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee); bool CheckSinkIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee); + + int32_t GetOnlineServiceList(const std::map &filterOptions, + std::vector &serviceList); + int32_t GetTrustedServiceList(const std::map &filterOptions, + std::vector &serviceList); + int32_t GetServiceInfoByServiceId(const int64_t &serviceId, DmServiceInfo &dmServiceInfo); + + int32_t GetCallerServiceInfo(std::vector &serviceInfos); + + int32_t GetServiceInfosByTokenId(const int64_t &tokenId, + std::vector &serviceInfos); + +private: + int32_t GetServiceBindLocalInfo(ServiceBindLocalInfo &localInfo); + bool CheckIsDeviceOnline(const std::vector &onlineDeviceList, const std::string &peerUdid); + int32_t GetServiceInfoProfileByServiceId(const int64_t &serviceId, DmServiceInfoProfile &dmServiceInfoProfile); private: bool IsDMServiceImplReady(); bool IsDMImplSoLoaded(); diff --git a/services/service/include/device_manager_service_listener.h b/services/service/include/device_manager_service_listener.h index c6b9128b6d27389805d67f6422ed776f0485286b..216835016a96327f3e1961ba1e80cab2facb1e72 100644 --- a/services/service/include/device_manager_service_listener.h +++ b/services/service/include/device_manager_service_listener.h @@ -92,6 +92,7 @@ public: void SetExistPkgName(const std::set &pkgNameSet) override; std::string GetLocalDisplayDeviceName() override; + int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) override; private: void ConvertDeviceInfoToDeviceBasicInfo(const std::string &pkgName, diff --git a/services/service/include/softbus/softbus_listener.h b/services/service/include/softbus/softbus_listener.h index cc50ac399e009f56b5d86be94caba9115cead54e..405f015727464dad2e5108b51e97e9bc45f3bcce 100644 --- a/services/service/include/softbus/softbus_listener.h +++ b/services/service/include/softbus/softbus_listener.h @@ -132,6 +132,8 @@ public: std::vector &deviceList); int32_t GetUdidFromDp(const std::string &udidHash, std::string &udid); static void GetActionId(const std::string &deviceId, int32_t &actionId); + + int32_t GetPeerServiceAddress(int64_t serviceId, DmServiceAddress &addr); private: static int32_t FillDeviceInfo(const DeviceInfo &device, DmDeviceInfo &dmDevice); static void ParseConnAddrInfo(const ConnectionAddr *addrInfo, JsonObject &jsonObj); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index f8eb37b841c3b75c633d9719d114151344a2e93b..d5f45606034a8c2de73343c9fe4ef0990f22daac 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1701,8 +1701,8 @@ int32_t DeviceManagerService::StopAdvertising(const std::string &pkgName, return advertiseMgr_->StopAdvertising(pkgName, publishId); } -int32_t DeviceManagerService::BindTarget(const std::string &pkgName, const PeerTargetId &targetId, - const std::map &bindParam) +int32_t DeviceManagerService::BindTarget(const std::string &pkgName, PeerTargetId &targetId, + std::map &bindParam) { if (!PermissionManager::GetInstance().CheckNewPermission()) { LOGE("The caller does not have permission to call"); @@ -1713,6 +1713,7 @@ int32_t DeviceManagerService::BindTarget(const std::string &pkgName, const PeerT LOGE("Invalid parameter, pkgName is empty."); return ERR_DM_INPUT_PARA_INVALID; } + ServiceInfoBindParmamHandle(targetId, bindParam); if (bindParam.find(PARAM_KEY_META_TYPE) == bindParam.end()) { if (!IsDMServiceImplReady()) { LOGE("BindTarget failed, DMServiceImpl instance not init or init failed."); @@ -1745,8 +1746,8 @@ int32_t DeviceManagerService::BindTarget(const std::string &pkgName, const PeerT return dmServiceImplExtResident_->BindTargetExt(pkgName, targetId, bindParam); } -int32_t DeviceManagerService::UnbindTarget(const std::string &pkgName, const PeerTargetId &targetId, - const std::map &unbindParam) +int32_t DeviceManagerService::UnbindTarget(const std::string &pkgName, PeerTargetId &targetId, + std::map &unbindParam) { if (!PermissionManager::GetInstance().CheckNewPermission()) { LOGE("The caller does not have permission to call"); @@ -1769,6 +1770,37 @@ int32_t DeviceManagerService::UnbindTarget(const std::string &pkgName, const Pee LOGE("The caller does not have permission to call"); return ERR_DM_NO_PERMISSION; } + + if (targetId.serviceId != 0) { + unbindParam[IS_BIND_SERVICE] = "true"; + unbindParam[SERVICE_ID] = std::to_string(targetId.serviceId); + DmServiceAddress addr; + softbusListener_->GetPeerServiceAddress(targetId.serviceId, addr); + targetId.bleMac = addr.bleMac; + } + std::vector serviceInfoProfiles; + std::string tokenId; + if (DeviceProfileConnector::GetInstance().GetAllServiceInfoProfileList(serviceInfoProfiles)) { + return ERR_DM_FAILED; + } + int32_t i; + for (i = 0; i < serviceInfoProfiles.size(); i++) { + if (serviceInfoProfiles[i].serviceRegInfo.serviceInfo.serviceId == targetId.serviceId) { + tokenId = serviceInfoProfiles[i].tokenId; + break; + } + } + DmServiceInfoUniqueKey serviceInfoUniqueKey; + serviceInfoUniqueKey.tokenId = tokenId; + for (i = 0; i < serviceInfoProfiles.size(); i++) { + if (serviceInfoProfiles[i].tokenId == tokenId) { + serviceInfoUniqueKey.deviceId = serviceInfoProfiles[i].deviceId; + serviceInfoUniqueKey.serviceId = serviceInfoProfiles[i].serviceRegInfo.serviceInfo.serviceId; + serviceInfoUniqueKey.userId = serviceInfoProfiles[i].userId; + //UnRegisterServiceInfo(serviceInfoUniqueKey); + } + } + std::string realDeviceId = targetId.deviceId; #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) std::string udidHashTemp = ""; @@ -1785,6 +1817,29 @@ int32_t DeviceManagerService::UnbindTarget(const std::string &pkgName, const Pee return dmServiceImplExtResident_->UnbindTargetExt(pkgName, targetId, unbindParamWithUdid); } +void DeviceManagerService::ServiceInfoBindParmamHandle(PeerTargetId &targetId, + std::map &bindParam) +{ + if (targetId.serviceId != 0) { + DmServiceAddress addr; + if (softbusListener_->GetPeerServiceAddress(targetId.serviceId, addr) == DM_OK) { + bindParam[SERVICE_ID] = std::to_string(targetId.serviceId); + bindParam[IS_BIND_SERVICE] = "ture"; + targetId.bleMac = addr.bleMac; + } + else { + DmServiceInfoProfile serviceInfoProfile; + if (GetServiceInfoProfileByServiceId(targetId.serviceId, serviceInfoProfile) == DM_OK) { + std::string udid = ""; + SoftbusListener::GetUdidByNetworkId(serviceInfoProfile.networkId.c_str(), udid); + } + } + } + else { + LOGE("DeviceManagerService::BindTarget serviceId is 0, not a service bind."); + } +} + #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) bool DeviceManagerService::InitDPLocalServiceInfo(const DMLocalServiceInfo &serviceInfo, DistributedDeviceProfile::LocalServiceInfo &dpLocalServiceInfo) @@ -4301,6 +4356,15 @@ void DeviceManagerService::ProcessSyncAccountLogout(const std::string &accountId dmServiceImpl_->HandleAccountLogoutEvent(userId, accountId, peerUdid); } +int32_t DeviceManagerService::OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) +{ + if (!IsDMServiceAdapterResidentLoad()) { + LOGE("failed, adapter instance not init or init failed."); + return ERR_DM_UNSUPPORTED_METHOD; + } + return dmServiceImplExtResident_->OpenAuthSessionWithPara(deviceId, actionId, isEnable160m); +} + int32_t DeviceManagerService::UnRegisterPinHolderCallback(const std::string &pkgName) { if (!PermissionManager::GetInstance().CheckPermission()) { @@ -4477,5 +4541,220 @@ void DeviceManagerService::HandleAccountLogoutEventCallback(const std::string &c MultipleUserConnector::GetCurrentDMAccountInfo()); } #endif +int32_t DeviceManagerService::GetOnlineServiceList(const std::map &filterOptions, + std::vector &serviceList) +{ + LOGI("DeviceManagerService::GetOnlineServiceList Start"); + ServiceBindLocalInfo localInfo; + int32_t ret = GetServiceBindLocalInfo(localInfo); + if (ret != DM_OK) { + return ret; + } + std::vector allTrustDeviceProfiles; + //std::vector allTrustDeviceProfiles = + // DeviceProfileConnector::GetInstance().GetAccessControProfileByUserId(localInfo.userId); + std::vector onlineDeviceList; + CHECK_NULL_RETURN(softbusListener_, ERR_DM_POINT_NULL); + ret = softbusListener_->GetTrustedDeviceList(onlineDeviceList); + if (ret != DM_OK) { + LOGE("GetTrustedDeviceList failed"); + return ret; + } + for (auto &profile : allTrustDeviceProfiles) { + DistributedDeviceProfile::Accesser accesser = profile.GetAccesser(); + DistributedDeviceProfile::Accessee accessee = profile.GetAccessee(); + std::string peerUdid = ""; + std::string peerTokenId = ""; + int32_t peerUserId = -1; + if (accesser.GetAccesserDeviceId() == localInfo.localUdid && + accesser.GetAccesserTokenId() == localInfo.tokenId) { + peerUdid = accessee.GetAccesseeDeviceId(); + peerTokenId = accessee.GetAccesseeTokenId(); + peerUserId = accessee.GetAccesseeUserId(); + } else if (accessee.GetAccesseeDeviceId() == localInfo.localUdid && accessee.GetAccesseeTokenId()== localInfo.tokenId) { + peerUdid = accesser.GetAccesserDeviceId(); + peerTokenId = accesser.GetAccesserTokenId(); + peerUserId = accesser.GetAccesserUserId(); + } + if (!CheckIsDeviceOnline(onlineDeviceList, peerUdid)) { + LOGE("DeviceManagerService::GetOnlineServiceList Device Is Offline"); + continue; + } + DmServiceInfoUniqueKey key; + key.tokenId = peerTokenId; + key.deviceId = peerUdid; + key.userId = peerUserId; + std::vector serviceInfoProfiles; + //DeviceProfileConnector::GetInstance().GetServiceInfoProfileListByTokenId(key, serviceInfoProfiles); + for (auto serviceInfoProfile : serviceInfoProfiles) { + serviceList.emplace_back(serviceInfoProfile.serviceRegInfo.serviceInfo); + } + } + return DM_OK; +} + +int32_t DeviceManagerService::GetTrustedServiceList(const std::map &filterOptions, + std::vector &serviceList) +{ + LOGI("DeviceManagerService::GetTrustedServiceList Start"); + ServiceBindLocalInfo localInfo; + int32_t ret = GetServiceBindLocalInfo(localInfo); + if (ret != DM_OK) { + return ret; + } + std::vector allTrustDeviceProfiles = + DeviceProfileConnector::GetInstance().GetAccessControlProfileByUserId(localInfo.userId); + + for (auto &profile : allTrustDeviceProfiles) { + DistributedDeviceProfile::Accesser accesser = profile.GetAccesser(); + DistributedDeviceProfile::Accessee accessee = profile.GetAccessee(); + std::string peerUdid = ""; + std::string peerTokenId = ""; + int32_t peerUserId = -1; + if (accesser.GetAccesserDeviceId() == localInfo.localUdid && + accesser.GetAccesserTokenId() == localInfo.tokenId) { + peerUdid = accessee.GetAccesseeDeviceId(); + peerTokenId = accessee.GetAccesseeTokenId(); + peerUserId = accessee.GetAccesseeUserId(); + } else if (accessee.GetAccesseeDeviceId() == localInfo.localUdid && + accessee.GetAccesseeTokenId() == localInfo.tokenId) { + peerUdid = accesser.GetAccesserDeviceId(); + peerTokenId = accesser.GetAccesserTokenId(); + peerUserId = accesser.GetAccesserUserId(); + } + DmServiceInfoUniqueKey key; + key.tokenId = peerTokenId; + key.deviceId = peerUdid; + key.userId = peerUserId; + std::vector serviceInfoProfiles; + //DeviceProfileConnector::Getinstance().GetServiceInfoProfileListByTokenId(key, serviceInfoProfiles); + for (auto serviceInfoProfile : serviceInfoProfiles) { + serviceList.emplace_back(serviceInfoProfile.serviceRegInfo.serviceInfo); + } + } + return DM_OK; +} + +int32_t DeviceManagerService::GetServiceInfoByServiceId(const int64_t &serviceId, DmServiceInfo &dmServiceInfo) +{ + LOGI("DeviceManagerService::GetServiceInfoByServiceId Start"); + ServiceBindLocalInfo localInfo; + int32_t ret = GetServiceBindLocalInfo(localInfo); + if (ret != DM_OK) { + return ret; + } + DmServiceInfoUniqueKey serviceInfoUniqueKey; + serviceInfoUniqueKey.serviceId = serviceId; + serviceInfoUniqueKey.tokenId = std::to_string(localInfo.tokenId); + serviceInfoUniqueKey.userId = localInfo.userId; + serviceInfoUniqueKey.deviceId = localInfo.localUdid; + // LOGI("SQW GetServiceInfoByServiceId key serviceid=%{public}ld, tokenid=%{public}s, userid= + // %{public}d, deviceid=%{public}s", + // serviceInfoUniqueKey.serviceId, serviceInfoUniqueKey.tokenId.c_str(), serviceInfoUniqu + // eKey.userId, + // serviceInfoUniqueKey.deviceId.c_str()); + DmServiceInfoProfile dmServiceInfoProfile; + //ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileByUniqueKey(serviceInfoUniqueKey, + // dmServiceInfoProfile); + // LOGI("SQW GetServiceInfoByServiceId ret=%{public}d, ser"viceId=%{public}ld, service name=%{ + // public}s", + // ret, dmServiceInfoProfile.serviceRegInfo.servicelInfo.serviceId, dmServiceInfoProfile. + // erviceRegInfo.serviceInfo.serviceName.c_str()); + if (ret != DM_OK) { + return ret; + } + dmServiceInfo = dmServiceInfoProfile.serviceRegInfo.serviceInfo; + return DM_OK; +} + +int32_t DeviceManagerService::GetServiceInfoProfileByServiceId(const int64_t &serviceId, + DmServiceInfoProfile &dmServiceInfoProfile) +{ + LOGI("DeviceManagerService::GetServiceInfoProfileByServiceId Start"); + ServiceBindLocalInfo localInfo; + int32_t ret = GetServiceBindLocalInfo(localInfo); + if (ret != DM_OK) { + return ret; + } + DmServiceInfoUniqueKey serviceInfoUniqueKey; + serviceInfoUniqueKey.serviceId = serviceId; + serviceInfoUniqueKey.tokenId = std::to_string(localInfo.tokenId); + serviceInfoUniqueKey.userId = localInfo.userId; + serviceInfoUniqueKey.deviceId = localInfo.localUdid; + + //ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileByUniqueKey(serviceInfoUniqueKey, + // dmServiceInfoProfile); + if (ret != DM_OK) { + return ret; + } + return DM_OK; +} + +int32_t DeviceManagerService::GetCallerServiceInfo(std::vector &serviceInfos) +{ + LOGI("DeviceManagerService::GetCallerServiceInfo Start"); + std::vector serviceInfoProfiles; + + int64_t tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); + + if (DeviceProfileConnector::GetInstance().GetAllServiceInfoProfileList(serviceInfoProfiles)) { + return ERR_DM_FAILED; + } + if (serviceInfoProfiles.empty()) { + LOGE("GetServiceInfosByTokenId failed, serviceInfoProfiles is empty."); + return ERR_DM_FAILED; + } + for (auto const &item : serviceInfoProfiles) { + if (item.tokenId == std::to_string(tokenId)) { + serviceInfos.push_back(item.serviceRegInfo.serviceInfo); + } + } + return DM_OK; +} + +int32_t DeviceManagerService::GetServiceBindLocalInfo(ServiceBindLocalInfo &localInfo) +{ + DmDeviceInfo localDeviceInfo; + int32_t ret = GetLocalDeviceInfo(localDeviceInfo); + if (ret != DM_OK) { + LOGE("GetLocalDeviceInfo failed"); + return ret; + } + localInfo.localUdid = localDeviceInfo.deviceId; + localInfo.tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); + MultipleUserConnector::GetCallerUserId(localInfo.userId); + + return DM_OK; +} + +int32_t DeviceManagerService::GetServiceInfosByTokenId(const int64_t &tokenId, + std::vector &serviceInfos) +{ + std::vector serviceInfoProfiles; + + if (DeviceProfileConnector::GetInstance().GetAllServiceInfoProfileList(serviceInfoProfiles)) { + return ERR_DM_FAILED; + } + if (serviceInfoProfiles.empty()) { + LOGE("GetServiceInfosByTokenId failed, serviceInfoProfiles is empty."); + return ERR_DM_FAILED; + } + for (auto const &item : serviceInfoProfiles) { + if (item.tokenId == std::to_string(tokenId)) { + serviceInfos.push_back(item.serviceRegInfo.serviceInfo); + } + } + return DM_OK; +} + +bool DeviceManagerService::CheckIsDeviceOnline(const std::vector &onlineDeviceList, const std::string &peerUdid) +{ + for (auto deviceInfo : onlineDeviceList) { + if (deviceInfo.deviceId == peerUdid) { + return true; + } + } + return false; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index 7bf14c146627fbc118e152d31e4f6f073774712f..bc47a6a81fc2c3d3908b7aa811a1d160a185c12a 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -45,6 +45,7 @@ #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #include "datetime_ex.h" #include "device_name_manager.h" +#include "device_manager_service.h" #include "kv_adapter_manager.h" #include "multiple_user_connector.h" #endif @@ -1041,5 +1042,15 @@ std::string DeviceManagerServiceListener::GetLocalDisplayDeviceName() return ""; #endif } + +int32_t DeviceManagerServiceListener::OpenAuthSessionWithPara(const std::string &deviceId, + int32_t actionId, bool isEnable160m) +{ +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + return DeviceManagerService::GetInstance().OpenAuthSessionWithPara(deviceId, actionId, isEnable160m); +#else + return ERR_DM_UNSUPPORTED_METHOD; +#endif +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/ipc/standard/ipc_server_stub.cpp b/services/service/src/ipc/standard/ipc_server_stub.cpp index c85383af7292f05e11704bbdbc510063dd097d6b..a971dd983848abdd1948a9a7f4b2eb46528979a0 100644 --- a/services/service/src/ipc/standard/ipc_server_stub.cpp +++ b/services/service/src/ipc/standard/ipc_server_stub.cpp @@ -16,6 +16,7 @@ #include "ipc_server_stub.h" #include +#include #include "ipc_cmd_register.h" #include "ipc_skeleton.h" @@ -44,6 +45,15 @@ namespace OHOS { namespace DistributedHardware { +namespace { +const std::unordered_set CLIENT_CODE { SERVER_DEVICE_STATE_NOTIFY, SERVER_DEVICE_FOUND, BIND_TARGET_RESULT, +SERVER_DEVICE_DISCOVERY, SERVER_PUBLISH_FINISH, SERVER_AUTH_RESULT, SERVER_DEVICE_FA_NOTIFY, SERVER_CREDENTIAL_RESULT, +SERVER_CREATE_PIN_HOLDER, SERVER_DESTROY_PIN_HOLDER, SERVER_CREATE_PIN_HOLDER_RESULT, SERVER_DESTROY_PIN_HOLDER_RESULT, +SERVER_ON_PIN_HOLDER_EVENT, UNBIND_TARGET_RESULT, REMOTE_DEVICE_TRUST_CHANGE, SERVER_DEVICE_SCREEN_STATE_NOTIFY, +SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, SINK_BIND_TARGET_RESULT, GET_DEVICE_PROFILE_INFO_LIST_RESULT, +GET_DEVICE_ICON_INFO_RESULT, SET_LOCAL_DEVICE_NAME_RESULT, SET_REMOTE_DEVICE_NAME_RESULT }; +} + DM_IMPLEMENT_SINGLE_INSTANCE(IpcServerStub); const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&IpcServerStub::GetInstance()); @@ -242,6 +252,9 @@ void IpcServerStub::OnStop() int32_t IpcServerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { + if (CLIENT_CODE.find(code) != CLIENT_CODE.end()) { + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } auto remoteDescriptor = data.ReadInterfaceToken(); if (GetDescriptor() != remoteDescriptor) { LOGI("ReadInterfaceToken fail!"); diff --git a/services/service/src/softbus/softbus_listener.cpp b/services/service/src/softbus/softbus_listener.cpp index 565f8a932716f499f95b81c1a7a6dac8d7b7d041..2a7cf45739ae40675d02c8e410c05317080acae6 100644 --- a/services/service/src/softbus/softbus_listener.cpp +++ b/services/service/src/softbus/softbus_listener.cpp @@ -1507,5 +1507,19 @@ int32_t SoftbusListener::PutOstypeData(const std::string &peerUdid, int32_t osTy return KVAdapterManager::GetInstance().PutOstypeData(peerUdid, osTypeStr); } #endif +int32_t SoftbusListener::GetPeerServiceAddress(int64_t serviceId, DmServiceAddress &addr) +{ + std::string serviceIdStr = std::to_string(serviceId); + + // DistributedDeviceProfile::ServiceAddress addrinfo; + // int32_t ret = ::GetPeerServiceAddress(serviceIdStr.c_str(),&addrinfo); + // if(ret != DM_OK) { + // LOGE("[SOFTBUS]GetPeerServiceAddress failed,ret %{public}d.",ret); + // return ret; + // } + // addr.bleMac=addrinfo.ble.bleMac; + // addr.actionid = addrinfo.action.actionId; + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.cpp b/test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.cpp index 0b1103234ecf676347497848a63548f495a5cae1..f0420974898654c0eea5def335499b521e1bf8af 100644 --- a/test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.cpp +++ b/test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.cpp @@ -32,6 +32,7 @@ void AuthAclFuzzTest(const uint8_t* data, size_t size) FuzzedDataProvider fdp(data, size); int32_t sessionId = fdp.ConsumeIntegral(); std::string result = fdp.ConsumeRandomLengthString(); + std::string peerDeviceId = fdp.ConsumeRandomLengthString(); std::shared_ptr authSink = std::make_shared(); std::shared_ptr authSrc = std::make_shared(); @@ -45,6 +46,9 @@ void AuthAclFuzzTest(const uint8_t* data, size_t size) context->accesser.isCommonFlag = false; authSink->VerifyCertificate(context); authSink->VerifyCertificate(nullptr); + context->IsProxyBind = true; + authSink->DerivativeSessionKey(context); + authSrc->GetPeerDeviceId(context, peerDeviceId); } } } diff --git a/test/servicesfuzztest/authconfirm_fuzzer/auth_confirm_fuzzer.cpp b/test/servicesfuzztest/authconfirm_fuzzer/auth_confirm_fuzzer.cpp index a60faf0ed9999f644ab3acc1e801c26f6401c299..0571eab22bc6bee124427ffb26094c68ae37a4fb 100644 --- a/test/servicesfuzztest/authconfirm_fuzzer/auth_confirm_fuzzer.cpp +++ b/test/servicesfuzztest/authconfirm_fuzzer/auth_confirm_fuzzer.cpp @@ -165,6 +165,7 @@ void AuthConfirmFuzzTestNext(JsonObject &jsonObject, FuzzedDataProvider &fdp) authSrcConfirmState_->GetIdenticalCredentialInfo(context_, jsonObject); authSrcConfirmState_->GetShareCredentialInfo(context_, jsonObject); authSrcConfirmState_->GetP2PCredentialInfo(context_, jsonObject); + authSinkConfirmState_->CreateProxyData(context_, jsonObject); authSinkConfirmState_->NegotiateCredential(context_, jsonObject); authSinkConfirmState_->NegotiateAcl(context_, jsonObject); authSinkNegotiateStateMachine_->GetIdenticalCredentialInfo(context_, jsonObject); @@ -200,6 +201,9 @@ void AuthConfirmFuzzTestThird(FuzzedDataProvider &fdp) { std::string businessId = fdp.ConsumeRandomLengthString(); std::string businessValue = fdp.ConsumeRandomLengthString(); + std::string authorizeInfo = fdp.ConsumeRandomLengthString(); + std::vector deleteCredInfo; + DistributedDeviceProfile::AccessControlProfile acl; authSinkNegotiateStateMachine_->IsAntiDisturbanceMode(businessId); authSinkNegotiateStateMachine_->IsAntiDisturbanceMode(""); authSinkNegotiateStateMachine_->ParseAndCheckAntiDisturbanceMode(businessId, businessValue); @@ -216,6 +220,18 @@ void AuthConfirmFuzzTestThird(FuzzedDataProvider &fdp) authSrcPinNegotiateStartState_->ProcessCredAuth(context_); int32_t credType = fdp.ConsumeIntegral(); authSrcPinNegotiateStartState_->GetCredIdByCredType(context_, credType); + context_->IsProxyBind = true; + authSrcConfirmState_->NegotiateProxyCredential(context_); + authSrcConfirmState_->NegotiateProxyAcl(context_); + authSrcConfirmState_->ResetBindLevel(context_); + authSinkConfirmState_->GetBundleLabel(context_); + authSinkConfirmState_->NegotiateProxyAcl(context_); + authSinkConfirmState_->ProcessUserAuthorize(context_); + authSinkConfirmState_->ProcessServerAuthorize(context_); + authSinkConfirmState_->NegotiateProxyCredential(context_); + authSrcConfirmState_->GetSrcProxyCredTypeForP2P(context_, deleteCredInfo); + authSinkConfirmState_->ProcessUserOption(context_, authorizeInfo); + authSrcConfirmState_->GetSrcProxyAclInfoForP2P(context_, acl); } void AuthConfirmFuzzTest(const uint8_t* data, size_t size) diff --git a/test/softbusfuzztest/softbussession_fuzzer/softbus_session_fuzzer.cpp b/test/softbusfuzztest/softbussession_fuzzer/softbus_session_fuzzer.cpp index 57c6d3e99c45218d9e475a2915c86e998c0eb081..9df6f8cdc50bfc013fe330e613e6b8d09cabff27 100644 --- a/test/softbusfuzztest/softbussession_fuzzer/softbus_session_fuzzer.cpp +++ b/test/softbusfuzztest/softbussession_fuzzer/softbus_session_fuzzer.cpp @@ -75,8 +75,6 @@ void SoftBusSessionFuzzTest(const uint8_t* data, size_t size) softbusSession->SendHeartbeatData(sessionId, str); softbusSession->OnSessionClosed(result); softbusSession->UnRegisterSessionCallback(); - bool isEnable = fdp.ConsumeBool(); - softbusSession->OpenAuthSessionWithPara(str, sessionId, isEnable); } } } diff --git a/test/unittest/UTTest_device_manager_service.cpp b/test/unittest/UTTest_device_manager_service.cpp index 1a5576f521497d19d721e7aa41e8c624c536ca99..731169b4f2cf3c13400e9e8792ab0f73cb5b9b8d 100644 --- a/test/unittest/UTTest_device_manager_service.cpp +++ b/test/unittest/UTTest_device_manager_service.cpp @@ -2493,6 +2493,15 @@ HWTEST_F(DeviceManagerServiceTest, GetEncryptedUuidByNetworkId_004, testing::ext EXPECT_EQ(ret, DM_OK); } +HWTEST_F(DeviceManagerServiceTest, OpenAuthSessionWithPara_001, testing::ext::TestSize.Level1) +{ + const std::string deviceId = "OpenAuthSessionWithPara"; + int32_t actionId = 0; + bool isEnable160m = false; + int32_t ret = DeviceManagerService::GetInstance().OpenAuthSessionWithPara(deviceId, actionId, isEnable160m); + EXPECT_NE(ret, DM_OK); +} + #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) HWTEST_F(DeviceManagerServiceTest, ConvertUdidHashToAnoyDeviceId_001, testing::ext::TestSize.Level1) { diff --git a/test/unittest/UTTest_device_manager_service_listener.cpp b/test/unittest/UTTest_device_manager_service_listener.cpp index 84d1bc6ff9172f4668697f297214e4d284a7b684..ff761bb5399e6cb47271deaaf5f4f7e0d605c6eb 100644 --- a/test/unittest/UTTest_device_manager_service_listener.cpp +++ b/test/unittest/UTTest_device_manager_service_listener.cpp @@ -1093,6 +1093,16 @@ HWTEST_F(DeviceManagerServiceListenerTest, GetLocalDisplayDeviceName_001, testin displayDeviceName = listener_->GetLocalDisplayDeviceName(); EXPECT_FALSE(displayDeviceName.empty()); } + +HWTEST_F(DeviceManagerServiceListenerTest, OpenAuthSessionWithPara_001, testing::ext::TestSize.Level1) +{ + const std::string deviceId = "OpenAuthSessionWithPara"; + int32_t actionId = 0; + bool isEnable160m = false; + std::shared_ptr listener_ = std::make_shared(); + int32_t ret = listener_->OpenAuthSessionWithPara(deviceId, actionId, isEnable160m); + EXPECT_NE(ret, DM_OK); +} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_dm_pin_holder.h b/test/unittest/UTTest_dm_pin_holder.h index 7d38ad3cee4fbfade509da3d3fe937a2277b3e39..4dfb660f8392378ea8602484e6d805220f6f3f99 100644 --- a/test/unittest/UTTest_dm_pin_holder.h +++ b/test/unittest/UTTest_dm_pin_holder.h @@ -265,6 +265,14 @@ public: { (void)pkgNameSet; } + + virtual int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) + { + (void)deviceId; + (void)actionId; + (void)isEnable160m; + return 0; + } }; } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_ipc_server_stub.cpp b/test/unittest/UTTest_ipc_server_stub.cpp index 67f91bd307d257e4801efb489f0035e909361e68..adc33ab53c1bb534285886645528d21208a98aec 100644 --- a/test/unittest/UTTest_ipc_server_stub.cpp +++ b/test/unittest/UTTest_ipc_server_stub.cpp @@ -159,8 +159,8 @@ HWTEST_F(IpcServerStubTest, OnRemoteRequest_002, testing::ext::TestSize.Level0) int ret = 0; // 2. Call IpcServerStub OnRemoteRequest with param ret = IpcServerStub::GetInstance().OnRemoteRequest(code, data, reply, option); - // 3. check ret not ERR_DM_IPC_READ_FAILED - ASSERT_EQ(ret, ERR_DM_IPC_READ_FAILED); + // 3. check ret not DM_OK + ASSERT_NE(ret, DM_OK); } /** diff --git a/test/unittest/mock/softbus_session_mock.cpp b/test/unittest/mock/softbus_session_mock.cpp index c85d7045d13a77be7fea3621d4830ec6912454da..331e0e2cbf58b2a546b64340caadf437006e2967 100644 --- a/test/unittest/mock/softbus_session_mock.cpp +++ b/test/unittest/mock/softbus_session_mock.cpp @@ -30,11 +30,6 @@ int32_t SoftbusSession::SendData(int32_t sessionId, std::string &message) return DmSoftbusSession::dmSoftbusSession->SendData(sessionId, message); } -int32_t SoftbusSession::OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) -{ - return DmSoftbusSession::dmSoftbusSession->OpenAuthSessionWithPara(deviceId, actionId, isEnable160m); -} - int32_t SoftbusSession::OpenAuthSession(const std::string &deviceId) { return DmSoftbusSession::dmSoftbusSession->OpenAuthSession(deviceId); diff --git a/test/unittest/mock/softbus_session_mock.h b/test/unittest/mock/softbus_session_mock.h index 9f386d18388b8c01da00ab872a8e5fad15852dd3..bdb1ad0f52d1db87ee431265bebe491599a1e0f6 100644 --- a/test/unittest/mock/softbus_session_mock.h +++ b/test/unittest/mock/softbus_session_mock.h @@ -28,7 +28,6 @@ public: public: virtual int32_t GetPeerDeviceId(int32_t sessionId, std::string &peerDevId) = 0; virtual int32_t SendData(int32_t sessionId, std::string &message) = 0; - virtual int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) = 0; virtual int32_t OpenAuthSession(const std::string &deviceId) = 0; public: @@ -39,7 +38,6 @@ class SoftbusSessionMock : public DmSoftbusSession { public: MOCK_METHOD(int32_t, GetPeerDeviceId, (int32_t, std::string &)); MOCK_METHOD(int32_t, SendData, (int32_t, std::string &)); - MOCK_METHOD(int32_t, OpenAuthSessionWithPara, (const std::string &, int32_t, bool)); MOCK_METHOD(int32_t, OpenAuthSession, (const std::string &)); }; }