diff --git a/common/include/device_manager_ipc_interface_code.h b/common/include/device_manager_ipc_interface_code.h index 418684851ef4e18d1ffd2b47eeff7818525a521e..e0219102a3994706fb67dbe8bb90e0a28ac374db 100644 --- a/common/include/device_manager_ipc_interface_code.h +++ b/common/include/device_manager_ipc_interface_code.h @@ -122,6 +122,17 @@ enum DMIpcCmdInterfaceCode { CHECK_SINK_ACCESS_CONTROL, CHECK_SRC_SAME_ACCOUNT, CHECK_SINK_SAME_ACCOUNT, + START_SERVICE_DISCOVERING, + STOP_SERVICE_DISCOVERING, + NOTIFY_SERVICE_FOUND, + NOTIFY_SERVICE_DISCOVERY_RESULT, + BIND_SERVICE_TARGET, + UNBIND_SERVICE_TARGET, + REGISTER_SERVICE_INFO, + UNREGISTER_SERVICE_INFO, + START_PUBLISH_SERVICE, + STOP_PUBLISH_SERVICE, + SERVICE_PUBLISH_RESULT, // Add ipc msg here IPC_MSG_BUTT }; diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 403201b60ebb3d88a6d184c3cb898e40ebc1c1ab..1a4a526b90728d87d50cc2519e08ecf975f14e84 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -172,6 +172,7 @@ DM_EXPORT extern const char* APP_USER_DATA; DM_EXPORT extern const char* BUNDLE_INFO; DM_EXPORT extern const char* TITLE; DM_EXPORT extern const char* DM_BUSINESS_ID; +DM_EXPORT extern const char* PARAM_KEY_IS_SERVICE_BIND; // screen state enum ScreenState { @@ -190,6 +191,7 @@ const int32_t DEVICE_NAME_MAX_BYTES = 100; DM_EXPORT extern const char* ACL_IS_LNN_ACL_KEY; DM_EXPORT extern const char* ACL_IS_LNN_ACL_VAL_TRUE; DM_EXPORT extern const char* ACL_IS_LNN_ACL_VAL_FALSE; +DM_EXPORT extern const char* SERVICE_ID_KEY; extern const char* DM_VERSION_5_0_1; extern const char* DM_VERSION_5_0_2; diff --git a/common/include/ipc/model/ipc_notify_device_state_req.h b/common/include/ipc/model/ipc_notify_device_state_req.h index 26d2f59ead3845b723759210607823487af0c123..161ea9a5c3be8701cd468de535b868c69612bdc1 100644 --- a/common/include/ipc/model/ipc_notify_device_state_req.h +++ b/common/include/ipc/model/ipc_notify_device_state_req.h @@ -80,10 +80,21 @@ public: dmDeviceBasicInfo_ = dmDeviceBasicInfo; } + void SetServiceIds(const std::vector &serviceIds) + { + serviceIds_ = serviceIds; + } + + const std::vector &GetServiceIds() const + { + return serviceIds_; + } + private: int32_t deviceState_ { 0 }; DmDeviceInfo dmDeviceInfo_; DmDeviceBasicInfo dmDeviceBasicInfo_; + std::vector serviceIds_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/common/include/ipc/model/ipc_notify_service_discover_result_req.h b/common/include/ipc/model/ipc_notify_service_discover_result_req.h new file mode 100644 index 0000000000000000000000000000000000000000..c7d70355f224e87d017c952b79db2220ed7b47ed --- /dev/null +++ b/common/include/ipc/model/ipc_notify_service_discover_result_req.h @@ -0,0 +1,53 @@ +/* + * 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_NOTIFY_SERVICE_DISCOVER_RESULT_REQ_H +#define OHOS_DM_IPC_NOTIFY_SERVICE_DISCOVER_RESULT_REQ_H + +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcNotifyServiceDiscoverResultReq : public IpcReq { + DECLARE_IPC_MODEL(IpcNotifyServiceDiscoverResultReq); + +public: + int32_t GetDiscServiceId() const + { + return discServiceId_; + } + + void SetDiscServiceId(int32_t discServiceId) + { + discServiceId_ = discServiceId; + } + + int32_t GetResult() const + { + return result_; + } + + void SetResult(int32_t result) + { + result_ = result; + } + +private: + int32_t discServiceId_ { 0 }; + int32_t result_ { 0 }; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_NOTIFY_SERVICE_DISCOVER_RESULT_REQ_H diff --git a/common/include/ipc/model/ipc_notify_service_found_req.h b/common/include/ipc/model/ipc_notify_service_found_req.h new file mode 100644 index 0000000000000000000000000000000000000000..527ad1aec675dae29238b5f04c881817d8382e8a --- /dev/null +++ b/common/include/ipc/model/ipc_notify_service_found_req.h @@ -0,0 +1,53 @@ +/* + * 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_NOTIFY_SERVICE_FOUND_REQ_H +#define OHOS_DM_IPC_NOTIFY_SERVICE_FOUND_REQ_H + +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcNotifyServiceFoundReq : public IpcReq { + DECLARE_IPC_MODEL(IpcNotifyServiceFoundReq); + +public: + int32_t GetDiscServiceId() const + { + return discServiceId_; + } + + void SetDiscServiceId(int32_t discServiceId) + { + discServiceId_ = discServiceId; + } + + const DiscoveryServiceInfo &GetDiscServiceInfo() const + { + return discServiceInfo_; + } + + void SetDiscServiceInfo(const DiscoveryServiceInfo &discServiceInfo) + { + discServiceInfo_ = discServiceInfo; + } + +private: + int32_t discServiceId_ { 0 }; + DiscoveryServiceInfo discServiceInfo_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_NOTIFY_SERVICE_FOUND_REQ_H diff --git a/common/include/ipc/model/ipc_publish_service_info_rsp.h b/common/include/ipc/model/ipc_publish_service_info_rsp.h new file mode 100644 index 0000000000000000000000000000000000000000..3f2ee10549fe21bcefa2bb6cf7661ff01e59e4be --- /dev/null +++ b/common/include/ipc/model/ipc_publish_service_info_rsp.h @@ -0,0 +1,53 @@ +/* + * 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_PUBLISH_SERVICE_INFO_RSP_H +#define OHOS_DM_IPC_PUBLISH_SERVICE_INFO_RSP_H + +#include "ipc_rsp.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcPublishServiceInfoRsp : public IpcRsp { + DECLARE_IPC_MODEL(IpcPublishServiceInfoRsp); + +public: + int32_t GetRegServiceId() const + { + return regServiceId_; + } + + void SetRegServiceId(const int32_t ®ServiceId) + { + regServiceId_ = regServiceId; + } + + int64_t GetServiceId() const + { + return serviceId_; + } + + void SetServiceId(const int64_t &serviceId) + { + serviceId_ = serviceId; + } + +private: + int32_t regServiceId_; + int64_t serviceId_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_PUBLISH_SERVICE_INFO_RSP_H \ No newline at end of file diff --git a/common/include/ipc/model/ipc_register_service_info_new_req.h b/common/include/ipc/model/ipc_register_service_info_new_req.h new file mode 100644 index 0000000000000000000000000000000000000000..d2d4f940ff46dd8e3e8c3569154aff0f3cbb2c34 --- /dev/null +++ b/common/include/ipc/model/ipc_register_service_info_new_req.h @@ -0,0 +1,53 @@ +/* + * 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_REGISTER_SERVICE_INFO_NEW_REQ_H +#define OHOS_DM_IPC_REGISTER_SERVICE_INFO_NEW_REQ_H + +#include "dm_device_info.h" +#include "ipc_req.h" +namespace OHOS { +namespace DistributedHardware { +class IpcRegisterServiceInfoNewReq : public IpcReq { + DECLARE_IPC_MODEL(IpcRegisterServiceInfoNewReq); + +public: + ServiceRegInfo GetServiceRegInfo() const + { + return serviceRegInfo_; + } + + void SetServiceRegInfo(const ServiceRegInfo& serviceRegInfo) + { + serviceRegInfo_ = serviceRegInfo; + } + + int32_t GetRegServiceId() const + { + return regServiceId_; + } + + void SetRegServiceId(int32_t regServiceId) + { + regServiceId_ = regServiceId; + } + +private: + ServiceRegInfo serviceRegInfo_; + int64_t regServiceId_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_REGISTER_SERVICE_INFO_NEW_REQ_H \ No newline at end of file diff --git a/common/include/ipc/model/ipc_service_publish_result_req.h b/common/include/ipc/model/ipc_service_publish_result_req.h new file mode 100644 index 0000000000000000000000000000000000000000..e752d114bf6abc1c3056212e72b182ca4d7fa10a --- /dev/null +++ b/common/include/ipc/model/ipc_service_publish_result_req.h @@ -0,0 +1,54 @@ +/* + * 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_SERVICE_PUBLISH_RESULT_REQ_H +#define OHOS_DM_IPC_SERVICE_PUBLISH_RESULT_REQ_H + +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcServicePublishResultReq : public IpcReq { + DECLARE_IPC_MODEL(IpcServicePublishResultReq); + +public: + + int64_t GetServiceId() const + { + return serviceId_; + } + + void SetServiceId(int64_t serviceId) + { + serviceId_ = serviceId; + } + + int32_t GetResult() const + { + return result_; + } + + void SetResult(int32_t result) + { + result_ = result; + } + +private: + int64_t serviceId_ = 0; + int32_t result_ = 0; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_SERVICE_PUBLISH_RESULT_REQ_H diff --git a/common/include/ipc/model/ipc_start_publish_service_req.h b/common/include/ipc/model/ipc_start_publish_service_req.h new file mode 100644 index 0000000000000000000000000000000000000000..0a9c380eba0d5be144ff25319e28f03ab9a9fe63 --- /dev/null +++ b/common/include/ipc/model/ipc_start_publish_service_req.h @@ -0,0 +1,55 @@ +/* + * 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_START_PUBLISH_SERVICE_REQ_H +#define OHOS_DM_IPC_START_PUBLISH_SERVICE_REQ_H + +#include "dm_subscribe_info.h" +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { + +class IpcStartPublishServiceReq : public IpcReq { + DECLARE_IPC_MODEL(IpcStartPublishServiceReq); + +public: + PublishServiceParam GetPublishServiceParam() + { + return publishServiceParam_; + } + + void SetPublishServiceParam(const PublishServiceParam& publishServiceParam) + { + publishServiceParam_ = publishServiceParam; + } + + int64_t GetServiceId() + { + return serviceId_; + } + + void SetServiceId(const int64_t& serviceId) + { + serviceId_ = serviceId; + } + +private: + int64_t serviceId_; + PublishServiceParam publishServiceParam_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_START_PUBLISH_SERVICE_REQ_H \ No newline at end of file diff --git a/common/include/ipc/model/ipc_start_service_discovery_req.h b/common/include/ipc/model/ipc_start_service_discovery_req.h new file mode 100644 index 0000000000000000000000000000000000000000..3ebb8931063f70257544f2533f13f23c7a45d7d8 --- /dev/null +++ b/common/include/ipc/model/ipc_start_service_discovery_req.h @@ -0,0 +1,42 @@ +/* + * 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_START_SERVICE_DISCOVERY_REQ_H +#define OHOS_DM_IPC_START_SERVICE_DISCOVERY_REQ_H + +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcStartServiceDiscoveryReq : public IpcReq { + DECLARE_IPC_MODEL(IpcStartServiceDiscoveryReq); + +public: + DiscoveryServiceParam GetDiscParam() const + { + return discParam_; + } + + void SetDiscParam(const DiscoveryServiceParam &discParam) + { + discParam_ = discParam; + } + +private: + DiscoveryServiceParam discParam_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_START_SERVICE_DISCOVERY_REQ_H \ No newline at end of file diff --git a/common/include/ipc/model/ipc_stop_publish_service_req.h b/common/include/ipc/model/ipc_stop_publish_service_req.h new file mode 100644 index 0000000000000000000000000000000000000000..1ebda8dc8baa1fc5bb360a9689730a9161aa2800 --- /dev/null +++ b/common/include/ipc/model/ipc_stop_publish_service_req.h @@ -0,0 +1,42 @@ +/* + * 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_STOP_PUBLISH_SERVICE_REQ_H +#define OHOS_DM_IPC_STOP_PUBLISH_SERVICE_REQ_H + +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcStopPublishServiceReq : public IpcReq { + DECLARE_IPC_MODEL(IpcStopPublishServiceReq); + +public: + int64_t GetServiceId() + { + return serviceId_; + } + + void SetServiceId(const int64_t& serviceId) + { + serviceId_ = serviceId; + } + +private: + int64_t serviceId_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_STOP_PUBLISH_SERVICE_REQ_H \ No newline at end of file diff --git a/common/include/ipc/model/ipc_unbind_service_target_req.h b/common/include/ipc/model/ipc_unbind_service_target_req.h new file mode 100644 index 0000000000000000000000000000000000000000..7167da8530a012ed28f45b46a9f1622bb2230af0 --- /dev/null +++ b/common/include/ipc/model/ipc_unbind_service_target_req.h @@ -0,0 +1,42 @@ +/* + * 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_UNBIND_SERVICE_TARGET_REQ_H +#define OHOS_DM_IPC_UNBIND_SERVICE_TARGET_REQ_H + +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcUnBindServiceTargetReq : public IpcReq { + DECLARE_IPC_MODEL(IpcUnBindServiceTargetReq); + +public: + int64_t GetServiceId() const + { + return serviceId_; + } + + void SetServiceId(int64_t serviceId) + { + serviceId_ = serviceId; + } + +private: + int64_t serviceId_ = 0; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_UNBIND_SERVICE_TARGET_REQ_H diff --git a/common/include/ipc/model/ipc_unregister_service_info_req.h b/common/include/ipc/model/ipc_unregister_service_info_req.h new file mode 100644 index 0000000000000000000000000000000000000000..96d57e53d5569922b107a8115588d0b815e3c5eb --- /dev/null +++ b/common/include/ipc/model/ipc_unregister_service_info_req.h @@ -0,0 +1,43 @@ +/* + * 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_UNREGISTER_SERVICE_INFO_REQ_H +#define OHOS_DM_IPC_UNREGISTER_SERVICE_INFO_REQ_H + +#include "dm_device_info.h" +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcUnRegisterServiceInfoReq : public IpcReq { + DECLARE_IPC_MODEL(IpcUnRegisterServiceInfoReq); + +public: + int32_t GetRegServiceId() const + { + return regServiceId_; + } + + void SetRegServiceId(int32_t regServiceId) + { + regServiceId_ = regServiceId; + } + +private: + int32_t regServiceId_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_UNREGISTER_SERVICE_INFO_REQ_H \ No newline at end of file diff --git a/common/include/ipc/standard/ipc_model_codec.h b/common/include/ipc/standard/ipc_model_codec.h index e06af83a94477da5100f2039832ccb033d070f7d..7bf1e7f1f34258b7c78b2ce2039d1888bbf77344 100644 --- a/common/include/ipc/standard/ipc_model_codec.h +++ b/common/include/ipc/standard/ipc_model_codec.h @@ -56,6 +56,16 @@ public: static bool DecodeNetworkIdQueryFilter(MessageParcel &parcel, NetworkIdQueryFilter &queryFilter); static bool EncodeStringVector(const std::vector &vec, MessageParcel &parcel); static bool DecodeStringVector(MessageParcel &parcel, std::vector &vec); + static bool EncodeSrvDiscParam(const DiscoveryServiceParam ¶m, MessageParcel &parcel); + static bool DecodeSrvDiscParam(MessageParcel &parcel, DiscoveryServiceParam ¶m); + static bool EncodeSrvDiscServiceInfo(const DiscoveryServiceInfo &serviceInfo, MessageParcel &parcel); + static bool DecodeSrvDiscServiceInfo(MessageParcel &parcel, DiscoveryServiceInfo &serviceInfo); + static bool EncodeServiceIds(const std::vector &serviceIds, MessageParcel &parcel); + static void DecodeServiceIds(std::vector &serviceIds, MessageParcel &parcel); + static bool EncodeServiceRegInfo(const ServiceRegInfo &serRegInfo, MessageParcel &parcel); + static bool DecodeServiceRegInfo(MessageParcel &parcel, ServiceRegInfo &serRegInfo); + static bool EncodePublishServiceParam(const PublishServiceParam &publishServiceParam, MessageParcel &parcel); + static bool DecodePublishServiceParam(MessageParcel &parcel, PublishServiceParam &publishServiceParam); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/common/src/dm_anonymous.cpp b/common/src/dm_anonymous.cpp index 43a0ecfed58b75fd2d1ae7fbe42ed2c032afe5d0..b083472b1ffa4277f5c13252ed86cc10b5ac9be2 100644 --- a/common/src/dm_anonymous.cpp +++ b/common/src/dm_anonymous.cpp @@ -225,7 +225,8 @@ void ParseMapFromJsonString(const std::string &jsonStr, std::map MAP_ERROR_CODE = { @@ -198,5 +199,6 @@ const int32_t DM_OH_OSTYPE = 10; const char* PEER_UDID = "peer_udid"; const char* PEER_OSTYPE = "peer_ostype"; const char* TIME_STAMP = "time_stamp"; +const char* SERVICE_ID_KEY = "serviceId"; } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/common/src/ipc/standard/ipc_model_codec.cpp b/common/src/ipc/standard/ipc_model_codec.cpp index d5376c7d5d630073c9c73e3d231d2a1c53d9f8b8..4ab96f3ade1198a427d4425f6d09d2709ba4e29f 100644 --- a/common/src/ipc/standard/ipc_model_codec.cpp +++ b/common/src/ipc/standard/ipc_model_codec.cpp @@ -76,6 +76,7 @@ bool IpcModelCodec::EncodePeerTargetId(const PeerTargetId &targetId, MessageParc bRet = (bRet && parcel.WriteString(targetId.bleMac)); bRet = (bRet && parcel.WriteString(targetId.wifiIp)); bRet = (bRet && parcel.WriteUint16(targetId.wifiPort)); + bRet = (bRet && parcel.WriteInt64(targetId.serviceId)); return bRet; } @@ -86,6 +87,7 @@ void IpcModelCodec::DecodePeerTargetId(MessageParcel &parcel, PeerTargetId &targ targetId.bleMac = parcel.ReadString(); targetId.wifiIp = parcel.ReadString(); targetId.wifiPort = parcel.ReadUint16(); + targetId.serviceId = parcel.ReadInt64(); } bool IpcModelCodec::EncodeDmAccessCaller(const DmAccessCaller &caller, MessageParcel &parcel) @@ -324,6 +326,34 @@ bool IpcModelCodec::EncodeDmDeviceIconInfo(const DmDeviceIconInfo &deviceIconInf return bRet; } +bool IpcModelCodec::EncodeServiceIds(const std::vector &serviceIds, MessageParcel &parcel) +{ + int32_t size = serviceIds.size(); + if (!parcel.WriteInt32(size)) { + return false; + } + for (const auto &id : serviceIds) { + if (!parcel.WriteInt64(id)) { + return false; + } + } + return true; +} + +void IpcModelCodec::DecodeServiceIds(std::vector &serviceIds, MessageParcel &parcel) +{ + const int32_t MAX_SERVICE_IDS_SIZE = 1024; + int32_t size = parcel.ReadInt32(); + if (size > MAX_SERVICE_IDS_SIZE) { + LOGE("DecodeServiceIds: size %d", size); + return; + } + serviceIds.resize(size); + for (int32_t i = 0; i < size; ++i) { + serviceIds[i] = parcel.ReadInt64(); + } +} + void IpcModelCodec::DecodeDmDeviceIconInfoFilterOptions(MessageParcel &parcel, DmDeviceIconInfoFilterOptions &filterOptions) { @@ -497,6 +527,112 @@ bool IpcModelCodec::DecodeStringVector(MessageParcel &parcel, std::vector(freq); + int32_t medium = 0; + READ_HELPER_RET(parcel, Int32, medium, false); + param.medium = static_cast(medium); + int32_t mode = 0; + READ_HELPER_RET(parcel, Int32, mode, false); + param.mode = static_cast(mode); + return true; +} + +bool IpcModelCodec::EncodeSrvDiscServiceInfo(const DiscoveryServiceInfo &serviceInfo, MessageParcel &parcel) +{ + bool bRet = true; + bRet = (bRet && parcel.WriteString(serviceInfo.pkgName)); + bRet = (bRet && parcel.WriteInt64(serviceInfo.serviceInfo.serviceId)); + bRet = (bRet && parcel.WriteString(serviceInfo.serviceInfo.serviceType)); + bRet = (bRet && parcel.WriteString(serviceInfo.serviceInfo.serviceName)); + bRet = (bRet && parcel.WriteString(serviceInfo.serviceInfo.serviceDisplayName)); + return bRet; +} + +bool IpcModelCodec::DecodeSrvDiscServiceInfo(MessageParcel &parcel, DiscoveryServiceInfo &serviceInfo) +{ + READ_HELPER_RET(parcel, String, serviceInfo.pkgName, false); + READ_HELPER_RET(parcel, Int64, serviceInfo.serviceInfo.serviceId, false); + READ_HELPER_RET(parcel, String, serviceInfo.serviceInfo.serviceType, false); + READ_HELPER_RET(parcel, String, serviceInfo.serviceInfo.serviceName, false); + READ_HELPER_RET(parcel, String, serviceInfo.serviceInfo.serviceDisplayName, false); + return true; +} //LCOV_EXCL_STOP + +bool IpcModelCodec::EncodeServiceRegInfo(const ServiceRegInfo &serRegInfo, MessageParcel &parcel) +{ + bool bRet = true; + bRet = (bRet && parcel.WriteInt64(serRegInfo.serviceInfo.serviceId)); + bRet = (bRet && parcel.WriteString(serRegInfo.serviceInfo.serviceType)); + bRet = (bRet && parcel.WriteString(serRegInfo.serviceInfo.serviceName)); + bRet = (bRet && parcel.WriteString(serRegInfo.serviceInfo.serviceDisplayName)); + bRet = (bRet && parcel.WriteString(serRegInfo.customData)); + bRet = (bRet && parcel.WriteUint32(serRegInfo.dataLen)); + return bRet; +} + +bool IpcModelCodec::DecodeServiceRegInfo(MessageParcel &parcel, ServiceRegInfo &serRegInfo) +{ + READ_HELPER_RET(parcel, Int64, serRegInfo.serviceInfo.serviceId, false); + READ_HELPER_RET(parcel, String, serRegInfo.serviceInfo.serviceType, false); + READ_HELPER_RET(parcel, String, serRegInfo.serviceInfo.serviceName, false); + READ_HELPER_RET(parcel, String, serRegInfo.serviceInfo.serviceDisplayName, false); + READ_HELPER_RET(parcel, String, serRegInfo.customData, false); + READ_HELPER_RET(parcel, Uint32, serRegInfo.dataLen, false); + return true; +} + +bool IpcModelCodec::EncodePublishServiceParam(const PublishServiceParam &publishServiceParam, MessageParcel &parcel) +{ + bool bRet = true; + bRet = (bRet && parcel.WriteInt64(publishServiceParam.serviceInfo.serviceId)); + bRet = (bRet && parcel.WriteString(publishServiceParam.serviceInfo.serviceType)); + bRet = (bRet && parcel.WriteString(publishServiceParam.serviceInfo.serviceName)); + bRet = (bRet && parcel.WriteString(publishServiceParam.serviceInfo.serviceDisplayName)); + bRet = (bRet && parcel.WriteInt32(publishServiceParam.regServiceId)); + bRet = (bRet && parcel.WriteInt32(static_cast(publishServiceParam.discoverMode))); + bRet = (bRet && parcel.WriteInt32(static_cast(publishServiceParam.media))); + bRet = (bRet && parcel.WriteInt32(static_cast(publishServiceParam.freq))); + return bRet; +} + +bool IpcModelCodec::DecodePublishServiceParam(MessageParcel &parcel, PublishServiceParam &publishServiceParam) +{ + READ_HELPER_RET(parcel, Int64, publishServiceParam.serviceInfo.serviceId, false); + READ_HELPER_RET(parcel, String, publishServiceParam.serviceInfo.serviceType, false); + READ_HELPER_RET(parcel, String, publishServiceParam.serviceInfo.serviceName, false); + READ_HELPER_RET(parcel, String, publishServiceParam.serviceInfo.serviceDisplayName, false); + READ_HELPER_RET(parcel, Int32, publishServiceParam.regServiceId, false); + int32_t discoverMode = static_cast(DMSrvDiscoveryMode::SERVICE_PUBLISH_MODE_ACTIVE); + READ_HELPER_RET(parcel, Int32, discoverMode, false); + publishServiceParam.discoverMode = static_cast(discoverMode); + int32_t media = static_cast(DMSrvMediumType::SERVICE_MEDIUM_TYPE_AUTO); + READ_HELPER_RET(parcel, Int32, media, false); + publishServiceParam.media = static_cast(media); + int32_t freq = static_cast(DmExchangeFreq::DM_LOW); + READ_HELPER_RET(parcel, Int32, freq, false); + publishServiceParam.freq = static_cast(freq); + return true; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 1cd88b8d18450b361fb14c73bd5aa10d7078d5c5..5e94c6c841d01f81f0c69da8502d0f12416fb119 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -229,6 +229,12 @@ public: int32_t tokenId, const std::string &localUdid); DM_EXPORT DmOfflineParam HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId, const std::string &localUdid, int32_t peerTokenId); + DM_EXPORT int32_t GetServiceInfoProfileByServiceId(int64_t serviceId, ServiceInfoProfile &serviceInfoProfile); + DM_EXPORT int32_t PutServiceInfoProfile(const ServiceInfoProfile &serviceInfoProfile); + DM_EXPORT int32_t DeleteServiceInfoProfile(int32_t regServiceId, int32_t userId); + DM_EXPORT void GetRemoteTokenIds(const std::string &localUdid, const std::string &udid, + std::vector &remoteTokenIds); + DM_EXPORT int32_t GetServiceInfoByTokenId(int64_t tokenId, ServiceInfoProfile &serviceInfo); DM_EXPORT std::vector GetAllAccessControlProfile(); DM_EXPORT std::vector GetAllAclIncludeLnnAcl(); @@ -332,6 +338,7 @@ public: const std::vector &backGroundUserIds); DM_EXPORT bool IsAllowAuthAlways(const std::string &localUdid, int32_t userId, const std::string &peerUdid, const std::string &pkgName, int64_t tokenId); + int32_t GetAuthOnceUdids(std::unordered_set &udidSet); private: int32_t HandleDmAuthForm(DistributedDeviceProfile::AccessControlProfile profiles, DmDiscoveryInfo discoveryInfo); diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 49ec04f9f2578136af67d0279e13b68250aadf2e..b7a6091b9f34fc6091732e9f9933257db62de560 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -2327,6 +2327,65 @@ DmOfflineParam DeviceProfileConnector::HandleServiceUnBindEvent(int32_t remoteUs return offlineParam; } +DM_EXPORT int32_t DeviceProfileConnector::GetServiceInfoProfileByServiceId(int64_t serviceId, + ServiceInfoProfile &serviceInfoProfile) +{ + LOGI("GetServiceInfoProfileByServiceId start"); + ServiceInfoProfileNew serviceInfoProfileDp; + int32_t ret = DistributedDeviceProfileClient::GetInstance().GetServiceInfoProfileByServiceId( + serviceId, serviceInfoProfileDp); + if (ret != DM_OK) { + LOGE("GetServiceInfoProfileByServiceId failed, result: %{public}d", ret); + return ret; + } + serviceInfoProfile.regServiceId = serviceInfoProfileDp.GetRegServiceId(); + serviceInfoProfile.deviceId = serviceInfoProfileDp.GetDeviceId(); + serviceInfoProfile.userId = serviceInfoProfileDp.GetUserId(); + serviceInfoProfile.tokenId = serviceInfoProfileDp.GetTokenId(); + serviceInfoProfile.publishState = serviceInfoProfileDp.GetSerPubState(); + serviceInfoProfile.serviceId = serviceInfoProfileDp.GetServiceId(); + serviceInfoProfile.serviceType = serviceInfoProfileDp.GetServiceType(); + serviceInfoProfile.serviceName = serviceInfoProfileDp.GetServiceName(); + serviceInfoProfile.serviceDisplayName = serviceInfoProfileDp.GetServiceDisplayName(); + LOGI("GetServiceInfoProfileByServiceId success"); + return DM_OK; +} + +DM_EXPORT int32_t DeviceProfileConnector::PutServiceInfoProfile(const ServiceInfoProfile &serviceInfoProfile) +{ + LOGI("PutServiceInfoProfile start"); + ServiceInfoProfileNew serviceInfoProfileDp; + serviceInfoProfileDp.SetRegServiceId(serviceInfoProfile.regServiceId); + serviceInfoProfileDp.SetDeviceId(serviceInfoProfile.deviceId); + serviceInfoProfileDp.SetUserId(serviceInfoProfile.userId); + serviceInfoProfileDp.SetTokenId(serviceInfoProfile.tokenId); + serviceInfoProfileDp.SetSerPubState(serviceInfoProfile.publishState); + serviceInfoProfileDp.SetServiceId(serviceInfoProfile.serviceId); + serviceInfoProfileDp.SetServiceType(serviceInfoProfile.serviceType); + serviceInfoProfileDp.SetServiceName(serviceInfoProfile.serviceName); + serviceInfoProfileDp.SetServiceDisplayName(serviceInfoProfile.serviceDisplayName); + int32_t ret = DistributedDeviceProfileClient::GetInstance().PutServiceInfoProfile(serviceInfoProfileDp); + if (ret != DM_OK) { + LOGE("PutServiceInfoProfile failed, result: %{public}d", ret); + return ret; + } + LOGI("PutServiceInfoProfile success"); + return DM_OK; +} + +DM_EXPORT int32_t DeviceProfileConnector::DeleteServiceInfoProfile(int32_t regServiceId, int32_t userId) +{ + LOGI("DeleteServiceInfoProfile start"); + int32_t ret = DistributedDeviceProfileClient::GetInstance().DeleteServiceInfoProfile( + regServiceId, userId); + if (ret != DM_OK) { + LOGE("DeleteServiceInfoProfile failed, result: %{public}d", ret); + return ret; + } + LOGI("DeleteServiceInfoProfile success"); + return DM_OK; +} + //LCOV_EXCL_START DM_EXPORT std::vector DeviceProfileConnector::GetAllAccessControlProfile() { @@ -3484,6 +3543,54 @@ DM_EXPORT void DeviceProfileConnector::DeleteHoDevice(const std::string &peerUdi } } +DM_EXPORT void DeviceProfileConnector::GetRemoteTokenIds(const std::string &localUdid, + const std::string &udid, std::vector &remoteTokenIds) +{ + if (udid.empty() || localUdid.empty() || localUdid == udid) { + LOGE("GetRemoteTokenIds udid error."); + return; + } + int32_t userId = MultipleUserConnector::GetCurrentAccountUserID(); + std::vector profiles = GetAclProfileByDeviceIdAndUserId(localUdid, userId); + uint64_t peerToken = 0; + for (auto &item : profiles) { + if (item.GetStatus() != ACTIVE) { + continue; + } + if (item.GetAccessee().GetAccesseeDeviceId() == localUdid && + item.GetAccesser().GetAccesserDeviceId() == udid) { + peerToken = static_cast(item.GetAccesser().GetAccesserTokenId()); + remoteTokenIds.push_back(peerToken); + } + if (item.GetAccessee().GetAccesseeDeviceId()== udid && + item.GetAccesser().GetAccesserDeviceId() == localUdid) { + peerToken = static_cast(item.GetAccessee().GetAccesseeTokenId()); + remoteTokenIds.push_back(peerToken); + } + } +} + +DM_EXPORT int32_t DeviceProfileConnector::GetServiceInfoByTokenId(int64_t tokenId, + ServiceInfoProfile &serviceInfo) +{ + DistributedDeviceProfile::ServiceInfoProfileNew dpServiceInfo; + auto ret = DistributedDeviceProfileClient::GetInstance().GetServiceInfoProfileByTokenId(tokenId, dpServiceInfo); + if (ret != 0) { + LOGE("GetServiceInfoByTokenId GetServiceInfoProfileByTokenId failed."); + return ret; + } + serviceInfo.regServiceId = dpServiceInfo.GetRegServiceId(); + serviceInfo.deviceId = dpServiceInfo.GetDeviceId(); + serviceInfo.userId = dpServiceInfo.GetUserId(); + serviceInfo.tokenId = dpServiceInfo.GetTokenId(); + serviceInfo.publishState = dpServiceInfo.GetSerPubState(); + serviceInfo.serviceId = dpServiceInfo.GetServiceId(); + serviceInfo.serviceType = dpServiceInfo.GetServiceType(); + serviceInfo.serviceName = dpServiceInfo.GetServiceName(); + serviceInfo.serviceDisplayName = dpServiceInfo.GetServiceDisplayName(); + return DM_OK; +} + bool DeviceProfileConnector::CheckExtWhiteList(const std::string &pkgName) { LOGI("start pkgName %{public}s.", pkgName.c_str()); diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_callback.h b/interfaces/inner_kits/native_cpp/include/device_manager_callback.h index e403436809b85a6d2069e2e947ba7a8559dc6e39..8cd0563dc7e4c49e548dcbc7db21302f52513cca 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_callback.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_callback.h @@ -179,6 +179,32 @@ public: } virtual void OnCredentialAuthStatus(const std::string &deviceList, uint16_t deviceTypeId, int32_t errcode) = 0; }; + +class ServiceDiscoveryCallback { +public: + virtual ~ServiceDiscoveryCallback() + { + } + virtual void OnServiceFound(const DiscoveryServiceInfo &service) = 0; + virtual void OnServiceDiscoveryResult(int32_t resReason) = 0; +}; + +class ServiceInfoStateCallback { +public: + virtual ~ServiceInfoStateCallback() + { + } + virtual void OnServiceOnline(int64_t serviceId) = 0; + virtual void OnServiceOffline(int64_t serviceId) = 0; +}; + +class ServicePublishCallback { +public: + virtual ~ServicePublishCallback() + { + } + virtual void OnServicePublishResult(int64_t serviceId, int32_t reason) = 0; +}; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_CALLBACK_H 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 b7704d94df412168e0e12abc80305242450246e6..0e4d753a2e831153fed570c3e3b0d8b6da08f7ac 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -20,6 +20,7 @@ #include #include "dm_app_image_info.h" +#include "dm_subscribe_info.h" #define DM_MAX_DEVICE_ID_LEN (97) #define DM_MAX_DEVICE_NAME_LEN (129) @@ -292,11 +293,16 @@ typedef struct PeerTargetId { * wlan ip port. */ uint16_t wifiPort = 0; + /** + * service id. + */ + int64_t serviceId; 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 +312,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; @@ -470,6 +478,72 @@ typedef struct DMAclQuadInfo { std::string peerUdid; int32_t peerUserId; } DMAclQuadInfo; + +typedef struct ServiceInfo { + int64_t serviceId = 0; + std::string serviceType; + std::string serviceName; + std::string serviceDisplayName; +} ServiceInfo; + +typedef enum DMSrvDiscoveryMode { + SERVICE_PUBLISH_MODE_PASSIVE = 0x15, + SERVICE_PUBLISH_MODE_ACTIVE = 0x25 +} DMSrvDiscoveryMode; + +typedef enum DMSrvMediumType { + SERVICE_MEDIUM_TYPE_AUTO = 0, + SERVICE_MEDIUM_TYPE_BLE, + SERVICE_MEDIUM_TYPE_BLE_TRIGGER, + SERVICE_MEDIUM_TYPE_MDNS, + SERVICE_MEDIUM_TYPE_BUTT, +} DMSrvMediumType; + +typedef struct DiscoveryServiceParam { + std::string serviceName; + std::string serviceType; + int32_t discoveryServiceId = 0; + DmExchangeFreq freq; + DMSrvMediumType medium; + DMSrvDiscoveryMode mode; +} DiscoveryServiceParam; + +typedef struct DiscoveryServiceInfo { + ServiceInfo serviceInfo; + std::string pkgName; +} DiscoveryServiceInfo; + +typedef struct ServiceInfoProfile { + int32_t regServiceId = 0; + std::string deviceId; + int32_t userId = 0; + int64_t tokenId = 0; + int8_t publishState = 0; + int64_t serviceId = 0; + std::string serviceType; + std::string serviceName; + std::string serviceDisplayName; +} ServiceInfoProfile; + +typedef struct ServiceRegInfo { + ServiceInfo serviceInfo; + std::string customData; + uint32_t dataLen = 0; +} ServiceRegInfo; + +typedef struct PublishServiceParam { + ServiceInfo serviceInfo; + DMSrvDiscoveryMode discoverMode; + int32_t regServiceId = 0; + DMSrvMediumType media; + DmExchangeFreq freq; +} PublishServiceParam; + +typedef struct ServiceBindlocalInfo { + std::string localUdid; + int32_t userId = 0; + uint32_t tokenId = 0; +} ServiceBindLocalInfo; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_DEVICE_INFO_H \ No newline at end of file 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 cb4bb85bc260c8e3638704898fe98dfe3c505d4a..3038801e2b325081fed162407e24c7c26b9b95b0 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 @@ -107,6 +107,12 @@ public: 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; + virtual int32_t StartServiceDiscovery(const ProcessInfo &processInfo, const DiscoveryServiceParam &discParam) = 0; + virtual int32_t StopServiceDiscovery(int32_t discServiceId) = 0; + virtual int32_t OpenAuthSessionWithPara(int64_t serviceId) = 0; + virtual int32_t StartPublishService(const ProcessInfo &processInfo, + const PublishServiceParam &publishServiceParam) = 0; + virtual int32_t StopPublishService(int64_t serviceId) = 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 4f738fc7cac35b6dbc1356a306d56fc22437940e..ba6468dcfe03000ac0feed3e88628f073d3a210e 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 @@ -113,6 +113,12 @@ public: virtual void HandleScreenLockEvent(bool isLock) = 0; virtual int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) = 0; virtual void HandleUserSwitchEvent(int32_t currentUserId, int32_t beforeUserId) = 0; + virtual int32_t StartServiceDiscovery(const ProcessInfo &processInfo, const DiscoveryServiceParam &discParam) = 0; + virtual int32_t StopServiceDiscovery(int32_t discServiceId) = 0; + virtual int32_t OpenAuthSessionWithPara(int64_t serviceId) = 0; + virtual int32_t StartPublishService(const ProcessInfo &processInfo, + const PublishServiceParam &publishServiceParam) = 0; + virtual int32_t StopPublishService(int64_t serviceId) = 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 336c5b631bd1e523058e86a725f72225b2997688..fecaa011c1fed44632c8f7901e364a46344f12ac 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 @@ -174,9 +174,16 @@ public: virtual void OnSetRemoteDeviceNameResult(const ProcessInfo &processInfo, const std::string &deviceId, const std::string &deviceName, int32_t code) = 0; virtual void SetExistPkgName(const std::set &pkgNameSet) = 0; + virtual void OnServiceFound(const ProcessInfo &processInfo, int32_t discServiceId, + const DiscoveryServiceInfo &discServiceInfo) = 0; + virtual void OnServiceDiscoveryResult(const ProcessInfo &processInfo, int32_t discServiceId, int32_t reason) = 0; virtual std::string GetLocalDisplayDeviceName() = 0; virtual int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) = 0; + virtual int32_t OpenAuthSessionWithPara(int64_t serviceId) = 0; + virtual void OnDeviceStateChange(const ProcessInfo &processInfo, const DmDeviceState &state, + const DmDeviceInfo &info, const std::vector &serviceIds) = 0; + virtual void OnServicePublishResult(const ProcessInfo &processInfo, int64_t serviceId, int32_t publishResult) = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h b/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h index 39a229cc8fa23bb023351d03ab785b694637c7ab..fc3da670d5fcae4ee82e763fd8558091ab7ef23f 100644 --- a/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h +++ b/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h @@ -57,6 +57,7 @@ public: void UnRegisterCredentialCallback(const std::string &pkgName); void RegisterBindCallback(const std::string &pkgName, const PeerTargetId &targetId, std::shared_ptr callback); + void UnRegisterBindCallback(const std::string &pkgName, const PeerTargetId &targetId); void RegisterUnbindCallback(const std::string &pkgName, const PeerTargetId &targetId, std::shared_ptr callback); void OnBindResult(const std::string &pkgName, const PeerTargetId &targetId, int32_t result, int32_t status, @@ -87,6 +88,13 @@ public: std::shared_ptr callback); void OnSetRemoteDeviceNameResult(const std::string &pkgName, const std::string &deviceId, int32_t code); void UnRegisterPinHolderCallback(const std::string &pkgName); + void RegisterServiceDiscoveryCallback(int32_t discoveryServiceId, + std::shared_ptr callback); + void UnRegisterServiceDiscoveryCallback(int32_t discoveryServiceId); + int32_t RegisterServiceStateCallback(const std::string &key, std::shared_ptr callback); + int32_t UnRegisterServiceStateCallback(const std::string &key); + void RegisterServicePublishCallback(int64_t serviceId, std::shared_ptr callback); + void UnRegisterServicePublishCallback(int64_t serviceId); public: static void DeviceInfoOnline(const DmDeviceInfo &deviceInfo, std::shared_ptr tempCbk); @@ -103,6 +111,8 @@ public: std::shared_ptr tempCbk); static void DeviceTrustChange(const std::string &udid, const std::string &uuid, DmAuthForm authForm, std::shared_ptr tempCbk); + static void ServiceInfoOnline( + std::vector, int64_t>> callbackInfo); public: void OnRemoteDied(); void OnDeviceOnline(const std::string &pkgName, const DmDeviceInfo &deviceInfo); @@ -139,6 +149,10 @@ public: std::string content); std::shared_ptr GetDiscoveryCallback(const std::string &pkgName, uint16_t subscribeId); void GetCallBack(std::map> &callbackMap); + void OnServiceFound(int32_t discoveryServiceId, const DiscoveryServiceInfo &service); + void OnServiceDiscoveryResult(int32_t discoveryServiceId, int32_t resReason); + void OnServiceOnline(const std::vector &serviceIds); + void OnServicePublishResult(int64_t serviceId, int32_t publishResult); private: #if !defined(__LITEOS_M__) @@ -166,6 +180,9 @@ private: std::map> setLocalDeviceNameCallback_; std::map>> setRemoteDeviceNameCallback_; + std::map> serviceDiscoveryCallbacks_; + std::map> serviceStateCallback_; + std::map> servicePublishCallback_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp index 907efd2984775652335f81fb84458d28406fce53..6cc6d01eb8729237c6614a79672c6dcb69c628ff 100644 --- a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp +++ b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp @@ -36,6 +36,7 @@ constexpr const char* DEVICE_OFFLINE = "deviceOffline"; constexpr const char* DEVICEINFO_CHANGE = "deviceInfoChange"; constexpr const char* DEVICE_READY = "deviceReady"; constexpr const char* DEVICE_TRUST_CHANGE = "deviceTrustChange"; +constexpr const char* SERVICE_ONLINE = "serviceOnLine"; #endif const uint16_t DM_INVALID_FLAG_ID = 0; void DeviceManagerNotify::RegisterDeathRecipientCallback(const std::string &pkgName, @@ -717,6 +718,10 @@ void DeviceManagerNotify::RegisterBindCallback(const std::string &pkgName, const return; } std::lock_guard autoLock(bindLock_); + if (bindCallback_.size() >= MAX_CONTAINER_SIZE) { + LOGE("bindCallback_ map size is more than max size"); + return; + } if (bindCallback_.count(pkgName) == 0) { CHECK_SIZE_VOID(bindCallback_); bindCallback_[pkgName] = std::map>(); @@ -724,6 +729,21 @@ void DeviceManagerNotify::RegisterBindCallback(const std::string &pkgName, const bindCallback_[pkgName][targetId] = callback; } +void DeviceManagerNotify::UnRegisterBindCallback(const std::string &pkgName, const PeerTargetId &targetId) +{ + if (pkgName.empty()) { + LOGE("Invalid parameter, pkgName is empty."); + return; + } + std::lock_guard autoLock(lock_); + if (bindCallback_.count(pkgName) > 0) { + bindCallback_[pkgName].erase(targetId); + if (bindCallback_[pkgName].empty()) { + bindCallback_.erase(pkgName); + } + } +} + void DeviceManagerNotify::RegisterUnbindCallback(const std::string &pkgName, const PeerTargetId &targetId, std::shared_ptr callback) { @@ -733,6 +753,10 @@ void DeviceManagerNotify::RegisterUnbindCallback(const std::string &pkgName, con return; } std::lock_guard autoLock(lock_); + if (unbindCallback_.size() >= MAX_CONTAINER_SIZE) { + LOGE("unbindCallback_ map size is more than max size"); + return; + } if (unbindCallback_.count(pkgName) == 0) { CHECK_SIZE_VOID(unbindCallback_); unbindCallback_[pkgName] = std::map>(); @@ -1450,5 +1474,198 @@ void DeviceManagerNotify::UnRegisterPinHolderCallback(const std::string &pkgName std::lock_guard autoLock(lock_); pinHolderCallback_.erase(pkgName); } + +void DeviceManagerNotify::RegisterServiceDiscoveryCallback(int32_t discoveryServiceId, + std::shared_ptr callback) +{ + if (callback == nullptr) { + LOGE("Invalid parameter, pkgName is empty."); + return; + } + std::lock_guard autolock(lock_); + if (serviceDiscoveryCallbacks_.size() >= MAX_CONTAINER_SIZE) { + LOGE("serviceDiscoveryCallbacks_ map size is more than max size"); + return; + } + serviceDiscoveryCallbacks_[discoveryServiceId] = callback; +} + +void DeviceManagerNotify::UnRegisterServiceDiscoveryCallback(int32_t discoveryServiceId) +{ + std::lock_guard autolock(lock_); + if (serviceDiscoveryCallbacks_.count(discoveryServiceId) == 0) { + LOGE("error,Service Discovery not register."); + return; + } + serviceDiscoveryCallbacks_.erase(discoveryServiceId); +} + +void DeviceManagerNotify::OnServiceFound(int32_t discoveryServiceId, const DiscoveryServiceInfo &service) +{ + std::shared_ptr tempCbk; + std::lock_guard autolock(lock_); + auto iter = serviceDiscoveryCallbacks_.find(discoveryServiceId); + if (iter == serviceDiscoveryCallbacks_.end()) { + LOGE("error, callback not register for discoveryServiceId %{public}s", + GetAnonyInt32(discoveryServiceId).c_str()); + return; + } + tempCbk = iter->second; + if (tempCbk == nullptr) { + LOGE("OnServiceFound error, registered service discovery callback is nullptr."); + return; + } + LOGD("Complete with serviceInfo"); + tempCbk->OnServiceFound(service); +} + +void DeviceManagerNotify::OnServiceDiscoveryResult(int32_t discoveryServiceId, int32_t resReason) +{ + std::shared_ptr tempCbk; + std::lock_guard autolock(lock_); + auto iter = serviceDiscoveryCallbacks_.find(discoveryServiceId); + if (iter == serviceDiscoveryCallbacks_.end()) { + LOGE("error, callback not register for discoveryServiceId %{public}s", + GetAnonyInt32(discoveryServiceId).c_str()); + return; + } + tempCbk = iter->second; + if (tempCbk == nullptr) { + LOGE("OnServiceDiscoveryResult error, registered service discovery callback is nullptr."); + return; + } + LOGD("Complete with result"); + tempCbk->OnServiceDiscoveryResult(resReason); +} + +void DeviceManagerNotify::OnServiceOnline(const std::vector &serviceIds) +{ + if (serviceIds.empty()) { + LOGE("Invalid parameter, serviceIds is empty."); + return; + } + LOGI("In, serviceIds size: %{public}zu", serviceIds.size()); + std::string key = ""; + std::vector, int64_t>> callbackInfo; + std::lock_guard autoLock(lock_); + for (const auto &item : serviceIds) { + key = std::to_string(item); + auto iter = serviceStateCallback_.find(key); + if (iter == serviceStateCallback_.end()) { + continue; + } + callbackInfo.push_back( + std::pair, int64_t>(iter->second, item)); + } + if (callbackInfo.empty()) { + return; + } + +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + ffrt::submit([=]() { ServiceInfoOnline(callbackInfo); }); +#else + std::thread serviceOnline([=]() { ServiceInfoOnline(callbackInfo);}); + int32_t ret = pthread_setname_np(serviceOnline.native_handle(), SERVICE_ONLINE); + if (ret != DM_OK) { + LOGE("DeviceManagerNotify serviceOnline setname failed."); + } + serviceOnline.detach(); +#endif +} + +void DeviceManagerNotify::ServiceInfoOnline( + std::vector, int64_t>> callbackInfo) +{ + for (auto &iter : callbackInfo) { + if (iter.first == nullptr) { + continue; + } + iter.first->OnServiceOnline(iter.second); + } +} + +int32_t DeviceManagerNotify::RegisterServiceStateCallback(const std::string &key, + std::shared_ptr callback) +{ + LOGI("DeviceManagerNotify::RegisterServiceStateCallback key = %{public}s", GetAnonyString(key).c_str()); + if (key.empty() || callback == nullptr) { + LOGE("Invalid parameter."); + return ERR_DM_INPUT_PARA_INVALID; + } + std::lock_guard autolock(lock_); + if (serviceStateCallback_.size() >= MAX_CONTAINER_SIZE) { + LOGE("serviceStateCallback_ map size is more than max size"); + return ERR_DM_FAILED; + } + serviceStateCallback_[key] = callback; + return DM_OK; +} + +int32_t DeviceManagerNotify::UnRegisterServiceStateCallback(const std::string &key) +{ + LOGI("DeviceManagerNotify::UnRegisterServiceStateCallback key = %{public}s", GetAnonyString(key).c_str()); + std::lock_guard autolock(lock_); + if (key.empty() || serviceStateCallback_.find(key) == serviceStateCallback_.end()) { + LOGE("Invalid parameter."); + return ERR_DM_INPUT_PARA_INVALID; + } + serviceStateCallback_.erase(key); + return DM_OK; +} + +void DeviceManagerNotify::RegisterServicePublishCallback(int64_t serviceId, + std::shared_ptr callback) +{ + LOGI("RegisterPublishCallback start"); + if (callback == nullptr) { + LOGE("Invalid parameter, callback is nullptr."); + return; + } + std::lock_guard autoLock(lock_); + if (servicePublishCallback_.size() >= MAX_CONTAINER_SIZE) { + LOGE("servicePublishCallback_ map size is more than max size"); + return; + } + servicePublishCallback_[serviceId] = callback; + LOGI("RegisterPublishCallback success"); +} + +void DeviceManagerNotify::UnRegisterServicePublishCallback(int64_t serviceId) +{ + LOGI("UnRegisterServicePublishCallback start"); + if (serviceId == 0) { + LOGE("UnRegisterServicePublishCallback error: Invalid parameter, serviceId is 0."); + return; + } + std::lock_guard autoLock(lock_); + servicePublishCallback_.erase(serviceId); + LOGI("UnRegisterServicePublishCallback success"); +} + +void DeviceManagerNotify::OnServicePublishResult(int64_t serviceId, int32_t publishResult) +{ + LOGI("OnServicePublishResult start, serviceId: %{public}s, publishResult: %{public}d", + GetAnonyString(std::to_string(serviceId)).c_str(), publishResult); + std::shared_ptr tempCbk; + { + std::lock_guard autoLock(lock_); + auto iter = servicePublishCallback_.find(serviceId); + if (iter == servicePublishCallback_.end()) { + LOGE("OnServicePublishResult error, callback not registered for serviceId"); + return; + } + tempCbk = iter->second; + if (publishResult != DM_OK) { + servicePublishCallback_.erase(serviceId); + LOGI("OnServicePublishResult: Removed callback for serviceId"); + } + } + if (tempCbk == nullptr) { + LOGE("OnServicePublishResult error, registered callback is nullptr"); + return; + } + tempCbk->OnServicePublishResult(serviceId, publishResult); + LOGI("OnServicePublishResult end"); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/include/authentication_v2/auth_manager.h b/services/implementation/include/authentication_v2/auth_manager.h index 604c5ea7e54b981e0faf3bbddd3d895d85040d8e..dff744ce241a678299278cff08398b976bc7f13b 100644 --- a/services/implementation/include/authentication_v2/auth_manager.h +++ b/services/implementation/include/authentication_v2/auth_manager.h @@ -154,6 +154,7 @@ private: void GetBindCallerInfo(); int32_t GetBindLevel(int32_t bindLevel); void GetIsNeedJoinLnnParam(const std::map &bindParam); + void ParseServiceInfo(const JsonObject &jsonObject); void GetConnDelayCloseTime(const std::string &extra); }; diff --git a/services/implementation/include/authentication_v2/dm_auth_context.h b/services/implementation/include/authentication_v2/dm_auth_context.h index 4bb875565c97ec79afae064737bdb30235449cd7..95271a5eacb1871cd18bb668fbf394bf907aab5d 100644 --- a/services/implementation/include/authentication_v2/dm_auth_context.h +++ b/services/implementation/include/authentication_v2/dm_auth_context.h @@ -276,6 +276,7 @@ struct DmAuthContext { std::multimap proxy; // Multimap where the key is the accessor and the value is the accesssee bool isNeedJoinLnn{true}; bool IsProxyBind{false}; + bool isServiceBind{false}; bool IsCallingProxyAsSubject{true}; bool IsNeedSetProxy{false}; bool isNeedAuthenticate{true}; // apply for skip authenticate diff --git a/services/implementation/src/authentication_v2/auth_manager.cpp b/services/implementation/src/authentication_v2/auth_manager.cpp index 786210c80e6768160413d1596241b1e66c2162c3..8b55301e73ec0a3d21c595e3b664ab59bbd61990 100644 --- a/services/implementation/src/authentication_v2/auth_manager.cpp +++ b/services/implementation/src/authentication_v2/auth_manager.cpp @@ -483,9 +483,19 @@ void AuthManager::ParseJsonObject(const JsonObject &jsonObject) } ParseHmlInfoInJsonObject(jsonObject); ParseProxyJsonObject(jsonObject); + ParseServiceInfo(jsonObject); return; } +void AuthManager::ParseServiceInfo(const JsonObject &jsonObject) +{ + if (context_ == nullptr || jsonObject.IsDiscarded() || !IsString(jsonObject, PARAM_KEY_IS_SERVICE_BIND) || + jsonObject[PARAM_KEY_IS_SERVICE_BIND].Get() != DM_VAL_TRUE) { + return; + } + context_->isServiceBind = true; +} + void AuthManager::ParseUltrasonicSide(const JsonObject &jsonObject) { if (jsonObject[TAG_ULTRASONIC_SIDE].IsString()) { @@ -586,6 +596,15 @@ void AuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, return; } ParseJsonObject(jsonObject); + if (context_->isServiceBind) { + if (IsNumberString(deviceId)) { + context_->accessee.serviceId = std::stoll(deviceId); + context_->accesser.serviceId = std::stoll(deviceId); + } else { + LOGE("OpenAuthSession failed"); + return; + } + } context_->accesser.accountId = MultipleUserConnector::GetOhosAccountIdByUserId(context_->accesser.userId); // compatible for old version diff --git a/services/implementation/src/authentication_v2/dm_auth_state.cpp b/services/implementation/src/authentication_v2/dm_auth_state.cpp index 5d5698a4d7c11c18c0e6b6d9b0d767bf056e6892..52c00c3d07761813c93b62fd230c21001ed8ba10 100644 --- a/services/implementation/src/authentication_v2/dm_auth_state.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_state.cpp @@ -986,7 +986,7 @@ void DmAuthState::JoinLnn(std::shared_ptr context) LOGI("The remote device is offline."); isForceJoin = true; } - if (context->connSessionType == CONN_SESSION_TYPE_HML) { + if (context->connSessionType == CONN_SESSION_TYPE_HML || context->isServiceBind) { context->softbusConnector->JoinLnnByHml(context->sessionId, context->accesser.transmitSessionKeyId, context->accessee.transmitSessionKeyId, isForceJoin); } else { diff --git a/services/service/include/device_manager_service_listener.h b/services/service/include/device_manager_service_listener.h index 8eaf51139f5595f2fd6ef65046e06d3e2b20114e..7c7a229214a727af1470c6c7859d08669d0ad6b1 100644 --- a/services/service/include/device_manager_service_listener.h +++ b/services/service/include/device_manager_service_listener.h @@ -90,9 +90,16 @@ public: void OnSetRemoteDeviceNameResult(const ProcessInfo &processInfo, const std::string &deviceId, const std::string &deviceName, int32_t code) override; void SetExistPkgName(const std::set &pkgNameSet) override; + void OnServiceFound(const ProcessInfo &processInfo, int32_t discServiceId, + const DiscoveryServiceInfo &discServiceInfo) override; + void OnServiceDiscoveryResult(const ProcessInfo &processInfo, int32_t discServiceId, int32_t reason) override; + void OnDeviceStateChange(const ProcessInfo &processInfo, const DmDeviceState &state, + const DmDeviceInfo &info, const std::vector &serviceIds) override; std::string GetLocalDisplayDeviceName() override; int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) override; + int32_t OpenAuthSessionWithPara(int64_t serviceId) override; + void OnServicePublishResult(const ProcessInfo &processInfo, int64_t serviceId, int32_t publishResult) override; private: void ConvertDeviceInfoToDeviceBasicInfo(const std::string &pkgName, @@ -127,6 +134,17 @@ private: void ProcessAppOffline(const std::vector &procInfoVec, const ProcessInfo &processInfo, const DmDeviceState &state, const DmDeviceInfo &info, const DmDeviceBasicInfo &deviceBasicInfo); void RemoveNotExistProcess(); + void ProcessDeviceStateChange(const ProcessInfo &processInfo, const DmDeviceState &state, const DmDeviceInfo &info, + const DmDeviceBasicInfo &deviceBasicInfo, const std::vector &serviceIds); + void ProcessAppStateChange(const ProcessInfo &processInfo, const DmDeviceState &state, + const DmDeviceInfo &info, const DmDeviceBasicInfo &deviceBasicInfo, + const std::vector &serviceIds); + void ProcessDeviceOnline(const std::vector &procinfoVec, const ProcessInfo &processInfo, + const DmDeviceState &state, const DmDeviceInfo &info, const DmDeviceBasicInfo &deviceBasicInfo, + const std::vector &serviceIds); + void ProcessAppOnline(const std::vector &procInfoVec, const ProcessInfo &processInfo, + const DmDeviceState &state, const DmDeviceInfo &info, const DmDeviceBasicInfo &deviceBasicInfo, + const std::vector &serviceIds); private: #if !defined(__LITEOS_M__) IpcServerListener ipcServerListener_; diff --git a/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index f917117d4aa2a5fed7ead810c8b06ea515126196..05beed68684620e90c9a35f7374ed0adb67658c0 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -39,8 +39,11 @@ #include "ipc_notify_get_device_profile_info_list_req.h" #include "ipc_notify_pin_holder_event_req.h" #include "ipc_notify_publish_result_req.h" +#include "ipc_notify_service_discover_result_req.h" +#include "ipc_notify_service_found_req.h" #include "ipc_notify_set_local_device_name_req.h" #include "ipc_notify_set_remote_device_name_req.h" +#include "ipc_service_publish_result_req.h" #include "ipc_server_stub.h" #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #include "datetime_ex.h" @@ -1033,6 +1036,101 @@ void DeviceManagerServiceListener::SetExistPkgName(const std::set & } } +void DeviceManagerServiceListener::ProcessDeviceStateChange(const ProcessInfo &processInfo, const DmDeviceState &state, + const DmDeviceInfo &info, const DmDeviceBasicInfo &deviceBasicInfo, const std::vector &serviceIds) +{ + std::vector processInfoVec = GetNotifyProcessInfoByUserId(processInfo.userId, + DmCommonNotifyEvent::REG_DEVICE_STATE); + std::vector hpProcessInfoVec; + std::vector lpProcessInfoVec; + for (const auto &it : processInfoVec) { + if (highPriorityPkgNameSet_.find(it.pkgName) != highPriorityPkgNameSet_.end()) { + hpProcessInfoVec.push_back(it); + } else { + lpProcessInfoVec.push_back(it); + } + } + ProcessDeviceOnline(hpProcessInfoVec, processInfo, state, info, deviceBasicInfo, serviceIds); + ProcessDeviceOnline(lpProcessInfoVec, processInfo, state, info, deviceBasicInfo, serviceIds); +} + +void DeviceManagerServiceListener::ProcessAppStateChange(const ProcessInfo &processInfo, const DmDeviceState &state, + const DmDeviceInfo &info, const DmDeviceBasicInfo &deviceBasicInfo, + const std::vector &serviceIds) +{ + std::vector processInfoVec = GetWhiteListSAProcessInfo(DmCommonNotifyEvent::REG_DEVICE_STATE); + ProcessInfo bindProcessInfo = DealBindProcessInfo(processInfo); + processInfoVec.push_back(bindProcessInfo); + std::vector allProcessInfos = ipcServerListener_.GetAllProcessInfo(); + ProcessAppOnline(processInfoVec, processInfo, state, info, deviceBasicInfo, serviceIds); +} + +void DeviceManagerServiceListener::OnDeviceStateChange(const ProcessInfo &processInfo, const DmDeviceState &state, + const DmDeviceInfo &info, const std::vector &serviceIds) +{ + LOGI("OnDeviceStateChange, state = %{public}d", state); + DmDeviceBasicInfo deviceBasicInfo; + ConvertDeviceInfoToDeviceBasicInfo(processInfo.pkgName, info, deviceBasicInfo); + if (processInfo.pkgName == std::string(DM_PKG_NAME)) { + ProcessDeviceStateChange(processInfo, state, info, deviceBasicInfo, serviceIds); + } else { + ProcessAppStateChange(processInfo, state, info, deviceBasicInfo, serviceIds); + } +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + KVAdapterManager::GetInstance().DeleteAgedEntry(); +#endif +} + +void DeviceManagerServiceListener::ProcessDeviceOnline(const std::vector &procInfoVec, + const ProcessInfo &processInfo, const DmDeviceState &state, const DmDeviceInfo &info, + const DmDeviceBasicInfo &deviceBasicInfo, const std::vector &serviceIds) +{ + LOGI("state %{public}d, udidhash %{public}s.", static_cast(state), + GetAnonyString(info.deviceId).c_str()); + for (const auto &it : procInfoVec) { + std::shared_ptr pReq = std::make_shared(); + std::shared_ptr pRsp = std::make_shared(); + pReq->SetServiceIds(serviceIds); + std::string notifyPkgName = it.pkgName + "#" + std::to_string(it.userId) + "#" + std::string(info.deviceId); + DmDeviceState notifyState = state; + { + std::lock_guard autoLock(alreadyNotifyPkgNameLock_); + if (alreadyOnlinePkgName_.find(notifyPkgName) != alreadyOnlinePkgName_.end()) { + notifyState = DmDeviceState::DEVICE_INFO_CHANGED; + } else { + alreadyOnlinePkgName_[notifyPkgName] = info; + } + } + SetDeviceInfo(pReq, it, notifyState, info, deviceBasicInfo); + ipcServerListener_.SendRequest(SERVER_DEVICE_STATE_NOTIFY, pReq, pRsp); + } +} + +void DeviceManagerServiceListener::ProcessAppOnline(const std::vector &procInfoVec, + const ProcessInfo &processInfo, const DmDeviceState &state, const DmDeviceInfo &info, + const DmDeviceBasicInfo &deviceBasicInfo, const std::vector &serviceIds) +{ + LOGI("state %{public}d, udidhash %{public}s.", static_cast(state), + GetAnonyString(info.deviceId).c_str()); + for (const auto &it : procInfoVec) { + std::shared_ptr pReq = std::make_shared(); + std::shared_ptr pRsp = std::make_shared(); + pReq->SetServiceIds(serviceIds); + std::string notifyPkgName = it.pkgName + "#" + std::to_string(it.userId) + "#" + std::string(info.deviceId); + DmDeviceState notifyState = state; + { + std::lock_guard autoLock(alreadyNotifyPkgNameLock_); + if (alreadyOnlinePkgName_.find(notifyPkgName) != alreadyOnlinePkgName_.end()) { + notifyState = DmDeviceState::DEVICE_INFO_CHANGED; + } else { + alreadyOnlinePkgName_[notifyPkgName] = info; + } + } + SetDeviceInfo(pReq, it, notifyState, info, deviceBasicInfo); + ipcServerListener_.SendRequest(SERVER_DEVICE_STATE_NOTIFY, pReq, pRsp); + } +} + std::string DeviceManagerServiceListener::GetLocalDisplayDeviceName() { #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) @@ -1053,5 +1151,45 @@ int32_t DeviceManagerServiceListener::OpenAuthSessionWithPara(const std::string return ERR_DM_UNSUPPORTED_METHOD; #endif } + +int32_t DeviceManagerServiceListener::OpenAuthSessionWithPara(int64_t serviceId) +{ + return ERR_DM_UNSUPPORTED_METHOD; +} + +void DeviceManagerServiceListener::OnServiceFound(const ProcessInfo &processInfo, int32_t discServiceId, + const DiscoveryServiceInfo &discServiceInfo) +{ + std::shared_ptr pReq = std::make_shared(); + std::shared_ptr pRsp = std::make_shared(); + pReq->SetProcessInfo(processInfo); + pReq->SetDiscServiceId(discServiceId); + pReq->SetDiscServiceInfo(discServiceInfo); + ipcServerListener_.SendRequest(NOTIFY_SERVICE_FOUND, pReq, pRsp); +} + +void DeviceManagerServiceListener::OnServiceDiscoveryResult(const ProcessInfo &processInfo, int32_t discServiceId, + int32_t reason) +{ + std::shared_ptr pReq = std::make_shared(); + std::shared_ptr pRsp = std::make_shared(); + pReq->SetProcessInfo(processInfo); + pReq->SetDiscServiceId(discServiceId); + pReq->SetResult(reason); + ipcServerListener_.SendRequest(NOTIFY_SERVICE_DISCOVERY_RESULT, pReq, pRsp); +} + +void DeviceManagerServiceListener::OnServicePublishResult(const ProcessInfo &processInfo, + int64_t serviceId, int32_t publishResult) +{ + LOGI("OnServicePublishResult start"); + std::shared_ptr pReq = std::make_shared(); + std::shared_ptr pRsp = std::make_shared(); + pReq->SetServiceId(serviceId); + pReq->SetResult(publishResult); + pReq->SetPkgName(processInfo.pkgName); + pReq->SetProcessInfo(processInfo); + ipcServerListener_.SendRequest(SERVICE_PUBLISH_RESULT, pReq, pRsp); +} } // 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 5994cd534cf43aee3fab52c30993411124244ca9..49a04ae6d687e678d8ea7ceca7cc512a773a1c5c 100644 --- a/services/service/src/ipc/standard/ipc_server_stub.cpp +++ b/services/service/src/ipc/standard/ipc_server_stub.cpp @@ -51,7 +51,7 @@ SERVER_DEVICE_DISCOVERY, SERVER_PUBLISH_FINISH, SERVER_AUTH_RESULT, SERVER_DEVIC 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 }; +GET_DEVICE_ICON_INFO_RESULT, SET_LOCAL_DEVICE_NAME_RESULT, SET_REMOTE_DEVICE_NAME_RESULT, SERVICE_PUBLISH_RESULT }; } DM_IMPLEMENT_SINGLE_INSTANCE(IpcServerStub); diff --git a/test/unittest/UTTest_dm_pin_holder.h b/test/unittest/UTTest_dm_pin_holder.h index 4dfb660f8392378ea8602484e6d805220f6f3f99..b4dba923cedbc5d7b2b1d4177a3cdeb37943471f 100644 --- a/test/unittest/UTTest_dm_pin_holder.h +++ b/test/unittest/UTTest_dm_pin_holder.h @@ -273,6 +273,42 @@ public: (void)isEnable160m; return 0; } + virtual void OnServiceFound(const ProcessInfo &processInfo, int32_t discServiceId, + const DiscoveryServiceInfo &discServiceInfo) + { + (void)processInfo; + (void)discServiceId; + (void)discServiceInfo; + } + + virtual void OnServiceDiscoveryResult(const ProcessInfo &processInfo, int32_t discServiceId, int32_t reason) + { + (void)processInfo; + (void)discServiceId; + (void)reason; + } + + virtual int32_t OpenAuthSessionWithPara(int64_t serviceId) + { + (void)serviceId; + return 0; + } + + virtual void OnDeviceStateChange(const ProcessInfo &processInfo, const DmDeviceState &state, + const DmDeviceInfo &info, const std::vector &serviceIds) + { + (void)processInfo; + (void)state; + (void)info; + (void)serviceIds; + } + + virtual void OnServicePublishResult(const ProcessInfo &processInfo, int64_t serviceId, int32_t publishResult) + { + (void)processInfo; + (void)serviceId; + (void)publishResult; + } }; } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/BUILD.gn b/utils/BUILD.gn index c4d1ba8fe5106a23dc36a67e65a175e117e5a6a1..6e644b74c0714c4cde9f98b66d8e8e2802db0852 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -167,6 +167,7 @@ if (defined(ohos_lite)) { "openssl:libcrypto_shared", "os_account:os_account_innerkits", "samgr:samgr_proxy", + "init:libbegetutil", ] public_external_deps = [ @@ -246,6 +247,7 @@ if (defined(ohos_lite)) { "openssl:libcrypto_shared", "os_account:os_account_innerkits", "samgr:samgr_proxy", + "init:libbegetutil", ] public_external_deps = [ diff --git a/utils/include/appInfo/standard/app_manager.h b/utils/include/appInfo/standard/app_manager.h index e03124661d8da3a55db0e92e5bddc159d4d739c5..23775941a8ee901b100e0739344d1885ca08222c 100644 --- a/utils/include/appInfo/standard/app_manager.h +++ b/utils/include/appInfo/standard/app_manager.h @@ -23,7 +23,7 @@ #include "bundle_mgr_interface.h" #include "bundle_mgr_proxy.h" #include "event_handler.h" - +#include "dm_device_info.h" #include "dm_single_instance.h" namespace OHOS { @@ -46,6 +46,7 @@ public: DM_EXPORT int32_t GetBundleNameForSelf(std::string &bundleName); DM_EXPORT int32_t GetBundleNameByTokenId(int64_t tokenId, std::string &bundleName); DM_EXPORT int32_t GetTokenIdByBundleName(int32_t userId, std::string &bundleName, int64_t &tokenId); + ServiceInfoProfile CreateServiceInfoProfile(const PublishServiceParam &publishServiceParam, const int32_t &userId); private: bool GetBundleManagerProxy(sptr &bundleManager); std::mutex appIdMapLock_; diff --git a/utils/src/appInfo/standard/app_manager.cpp b/utils/src/appInfo/standard/app_manager.cpp index 17eaf947f6a1652c7601dfd7a2ecc1a9ab1b0f33..7ef0a6cd5691a7559fca8f07f7119167e1bbf108 100644 --- a/utils/src/appInfo/standard/app_manager.cpp +++ b/utils/src/appInfo/standard/app_manager.cpp @@ -21,6 +21,7 @@ #include "ipc_skeleton.h" #include "iservice_registry.h" #include "os_account_manager.h" +#include "parameter.h" #include "system_ability_definition.h" #include "tokenid_kit.h" @@ -34,6 +35,8 @@ namespace OHOS { namespace DistributedHardware { namespace { const uint32_t MAX_CONTAINER_SIZE = 1000; +constexpr int32_t SERVICE_PUBLISHED_STATE = 1; +constexpr int32_t DEVICE_UUID_LENGTH = 65; } DM_IMPLEMENT_SINGLE_INSTANCE(AppManager); @@ -337,5 +340,23 @@ int32_t AppManager::GetBundleNameForSelf(std::string &bundleName) bundleName = bundleInfo.name; return DM_OK; } + +ServiceInfoProfile AppManager::CreateServiceInfoProfile(const PublishServiceParam &publishServiceParam, + const int32_t &userId) +{ + char localDeviceId[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); + ServiceInfoProfile serviceInfoProfile; + serviceInfoProfile.regServiceId = publishServiceParam.regServiceId; + serviceInfoProfile.deviceId = localDeviceId; + serviceInfoProfile.userId = userId; + serviceInfoProfile.tokenId = IPCSkeleton::GetCallingTokenID(); + serviceInfoProfile.publishState = SERVICE_PUBLISHED_STATE; + serviceInfoProfile.serviceId = publishServiceParam.serviceInfo.serviceId; + serviceInfoProfile.serviceType = publishServiceParam.serviceInfo.serviceType; + serviceInfoProfile.serviceName = publishServiceParam.serviceInfo.serviceName; + serviceInfoProfile.serviceDisplayName = publishServiceParam.serviceInfo.serviceDisplayName; + return serviceInfoProfile; +} } // namespace DistributedHardware } // namespace OHOS