From 5445314f029d42dee0d4110e7517b4046ba56c66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=B7?= Date: Thu, 11 Sep 2025 16:00:18 +0800 Subject: [PATCH 01/14] add service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- .../device_manager_ipc_interface_code.h | 11 + common/include/dm_constants.h | 2 + .../ipc/model/ipc_notify_device_state_req.h | 11 + .../ipc_notify_service_discover_result_req.h | 53 +++++ .../ipc/model/ipc_notify_service_found_req.h | 53 +++++ .../ipc/model/ipc_publish_service_info_rsp.h | 53 +++++ .../model/ipc_register_service_info_new_req.h | 53 +++++ .../model/ipc_service_publish_result_req.h | 54 +++++ .../ipc/model/ipc_start_publish_service_req.h | 55 +++++ .../model/ipc_start_service_discovery_req.h | 42 ++++ .../ipc/model/ipc_stop_publish_service_req.h | 42 ++++ .../ipc/model/ipc_unbind_service_target_req.h | 42 ++++ .../model/ipc_unregister_service_info_req.h | 43 ++++ common/include/ipc/standard/ipc_model_codec.h | 10 + common/src/dm_anonymous.cpp | 3 +- common/src/dm_constants.cpp | 2 + common/src/ipc/standard/ipc_model_codec.cpp | 136 ++++++++++++ .../include/deviceprofile_connector.h | 7 + .../src/deviceprofile_connector.cpp | 105 +++++++++ .../include/device_manager_callback.h | 26 +++ .../native_cpp/include/device_manager_impl.h | 1 - .../native_cpp/include/dm_device_info.h | 78 ++++++- .../include/i_dm_service_impl_ext.h | 6 + .../include/i_dm_service_impl_ext_resident.h | 6 + .../idevice_manager_service_listener.h | 7 + .../include/notify/device_manager_notify.h | 17 ++ .../native_cpp/src/device_manager_impl.cpp | 7 + .../src/notify/device_manager_notify.cpp | 201 ++++++++++++++++++ .../include/authentication_v2/auth_manager.h | 1 + .../authentication_v2/dm_auth_context.h | 1 + .../include/device_manager_service_impl.h | 4 + .../src/authentication_v2/auth_manager.cpp | 19 ++ .../dm_auth_message_processor.cpp | 12 -- .../src/authentication_v2/dm_auth_state.cpp | 2 +- .../devicestate/dm_device_state_manager.cpp | 1 - .../service/include/device_manager_service.h | 17 ++ .../include/device_manager_service_listener.h | 18 ++ .../src/device_manager_service_listener.cpp | 142 +++++++++++++ .../src/ipc/standard/ipc_server_stub.cpp | 2 +- utils/BUILD.gn | 2 + utils/include/appInfo/standard/app_manager.h | 3 +- utils/src/appInfo/standard/app_manager.cpp | 22 +- 42 files changed, 1351 insertions(+), 21 deletions(-) create mode 100644 common/include/ipc/model/ipc_notify_service_discover_result_req.h create mode 100644 common/include/ipc/model/ipc_notify_service_found_req.h create mode 100644 common/include/ipc/model/ipc_publish_service_info_rsp.h create mode 100644 common/include/ipc/model/ipc_register_service_info_new_req.h create mode 100644 common/include/ipc/model/ipc_service_publish_result_req.h create mode 100644 common/include/ipc/model/ipc_start_publish_service_req.h create mode 100644 common/include/ipc/model/ipc_start_service_discovery_req.h create mode 100644 common/include/ipc/model/ipc_stop_publish_service_req.h create mode 100644 common/include/ipc/model/ipc_unbind_service_target_req.h create mode 100644 common/include/ipc/model/ipc_unregister_service_info_req.h diff --git a/common/include/device_manager_ipc_interface_code.h b/common/include/device_manager_ipc_interface_code.h index 418684851..e0219102a 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 403201b60..1a4a526b9 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 26d2f59ea..161ea9a5c 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 000000000..c7d70355f --- /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 000000000..527ad1aec --- /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 000000000..3f2ee1054 --- /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 000000000..d2d4f940f --- /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 000000000..e752d114b --- /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 000000000..0a9c380eb --- /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 000000000..3ebb89310 --- /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 000000000..1ebda8dc8 --- /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 000000000..7167da853 --- /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 000000000..96d57e53d --- /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 e06af83a9..7bf1e7f1f 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 43a0ecfed..b083472b1 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 d5376c7d5..4ab96f3ad 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 1cd88b8d1..ffb86fcc6 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, bool isMultiUser, 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 49ec04f9f..9f34f887d 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -2327,6 +2327,67 @@ 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, bool isMultiUser, + int32_t userId) +{ + void(isMultiUser); + 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 +3545,50 @@ 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) +{ + 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 e40343680..8cd0563dc 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/device_manager_impl.h b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h index 863626aef..f72675337 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -439,7 +439,6 @@ public: virtual bool CheckSinkAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee) override; virtual bool CheckSrcIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee) override; virtual bool CheckSinkIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee) override; - private: DeviceManagerImpl() = default; ~DeviceManagerImpl() = default; diff --git a/interfaces/inner_kits/native_cpp/include/dm_device_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_info.h index b7704d94d..5cff684a8 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; + 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; + DmExchangeFreq freq; + DMSrvMediumType medium; + DMSrvDiscoveryMode mode; +} DiscoveryServiceParam; + +typedef struct DiscoveryServiceInfo { + ServiceInfo serviceInfo; + std::string pkgName; +} DiscoveryServiceInfo; + +typedef struct ServiceInfoProfile { + int32_t regServiceId; + std::string deviceId; + int32_t userId; + int64_t tokenId; + int8_t publishState; + int64_t serviceId; + std::string serviceType; + std::string serviceName; + std::string serviceDisplayName; +} ServiceInfoProfile; + +typedef struct ServiceRegInfo { + ServiceInfo serviceInfo; + std::string customData; + uint32_t dataLen; +} ServiceRegInfo; + +typedef struct PublishServiceParam { + ServiceInfo serviceInfo; + DMSrvDiscoveryMode discoverMode; + int32_t regServiceId; + DMSrvMediumType media; + DmExchangeFreq freq; +} PublishServiceParam; + +typedef struct ServiceBindlocalInfo { + std::string localUdid; + int32_t userId; + uint32_t tokenId; +} 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 cb4bb85bc..0e0a20660 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(const 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 4f738fc7c..ec351ea34 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(const 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 336c5b631..fecaa011c 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 39a229cc8..fc3da670d 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/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index 23aa74e64..96234824e 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -56,17 +56,24 @@ #include "ipc_permission_req.h" #include "ipc_publish_req.h" #include "ipc_put_device_profile_info_list_req.h" +#include "ipc_publish_service_info_rsp.h" #include "ipc_register_serviceinfo_req.h" +#include "ipc_register_service_info_new_req.h" #include "ipc_set_credential_req.h" #include "ipc_set_credential_rsp.h" #include "ipc_set_local_device_name_req.h" #include "ipc_set_remote_device_name_req.h" #include "ipc_set_useroperation_req.h" #include "ipc_skeleton.h" +#include "ipc_start_service_discovery_req.h" #include "ipc_sync_callback_req.h" +#include "ipc_start_publish_service_req.h" +#include "ipc_stop_publish_service_req.h" #include "ipc_unauthenticate_device_req.h" #include "ipc_unbind_device_req.h" +#include "ipc_unbind_service_target_req.h" #include "ipc_unpublish_req.h" +#include "ipc_unregister_service_info_req.h" #include "securec.h" #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #include "ipc_model_codec.h" 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 907efd298..1740bb430 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, @@ -724,6 +725,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) { @@ -1450,5 +1466,190 @@ 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_); + 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_); + 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 02deef3fe..58f16d19a 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); }; class AuthSrcManager : public AuthManager { diff --git a/services/implementation/include/authentication_v2/dm_auth_context.h b/services/implementation/include/authentication_v2/dm_auth_context.h index 4bb875565..95271a5ea 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/include/device_manager_service_impl.h b/services/implementation/include/device_manager_service_impl.h index 13759a00d..532d0ca22 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -205,6 +205,9 @@ public: const DmAccessCallee &callee, const std::string &sinkUdid); void DeleteHoDevice(const std::string &peerUdid, const std::vector &foreGroundUserIds, const std::vector &backGroundUserIds); + int32_t BindServiceTarget(const std::string &pkgName, const PeerTargetId &targetId, + const std::map &bindParam); + int32_t UnbindServiceTarget(const std::string &pkgName, int64_t serviceId); void InitTaskOfDelTimeOutAcl(const std::string &deviceUdid, const std::string &deviceUdidHash); private: int32_t PraseNotifyEventJson(const std::string &event, JsonObject &jsonObject); @@ -304,6 +307,7 @@ private: const std::string &deviceId, int32_t reason, uint64_t tokenId); void GetBundleName(const DMAclQuadInfo &info, std::set &pkgNameSet); void DeleteSessionKey(int32_t userId, const DistributedDeviceProfile::AccessControlProfile &profile); + int32_t DeleteAclExtraDataServiceId(int64_t serviceId); private: std::mutex authMgrMtx_; std::shared_ptr authMgr_; // Old protocol only diff --git a/services/implementation/src/authentication_v2/auth_manager.cpp b/services/implementation/src/authentication_v2/auth_manager.cpp index a6ddbde19..470d19512 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_message_processor.cpp b/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp index 43f367ea3..2e87ccf93 100644 --- a/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp @@ -2007,7 +2007,6 @@ int32_t DmAuthMessageProcessor::EncryptSyncMessage(std::shared_ptraccesser.isCommonFlag; syncMsgJson[TAG_DM_CERT_CHAIN] = context->accesser.cert; - CreateProxyAccessMessage(context, syncMsgJson); - std::string syncMsg = syncMsgJson.Dump(); - std::string compressMsg = CompressSyncMsg(syncMsg); - if (compressMsg.empty()) { - LOGE("DmAuthMessageProcessor::EncryptSyncMessage compress failed"); - return ERR_DM_FAILED; - } - JsonObject plainJson; - plainJson[TAG_COMPRESS_ORI_LEN] = syncMsg.size(); - plainJson[TAG_COMPRESS] = Base64Encode(compressMsg); - return cryptoMgr_->EncryptMessage(plainJson.Dump(), encSyncMsg); } int32_t DmAuthMessageProcessor::CreateProxyAccessMessage(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 5d5698a4d..52c00c3d0 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/implementation/src/devicestate/dm_device_state_manager.cpp b/services/implementation/src/devicestate/dm_device_state_manager.cpp index 7e0db378b..6adaa2c94 100644 --- a/services/implementation/src/devicestate/dm_device_state_manager.cpp +++ b/services/implementation/src/devicestate/dm_device_state_manager.cpp @@ -178,7 +178,6 @@ void DmDeviceStateManager::ProcessDeviceStateChange(const DmDeviceState devState for (const auto &item : processInfoVec) { if (!item.pkgName.empty()) { LOGI("ProcessDeviceStateChange, pkgName = %{public}s", item.pkgName.c_str()); - listener_->OnDeviceStateChange(item, devState, devInfo); } } } diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index b285a2d70..cdeaf2919 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -264,6 +264,7 @@ public: 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 OpenAuthSessionWithPara(int64_t serviceId); int32_t UnRegisterPinHolderCallback(const std::string &pkgName); void ProcessReceiveRspAppUninstall(const std::string &remoteUdid); void ProcessReceiveRspAppUnbind(const std::string &remoteUdid); @@ -275,6 +276,16 @@ 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 StartServiceDiscovery(const std::string &pkgName, const DiscoveryServiceParam &discParam); + int32_t StopServiceDiscovery(const std::string &pkgName, int32_t discServiceId); + int32_t BindServiceTarget(const std::string &pkgName, const PeerTargetId &targetId, + const std::map &bindParam); + int32_t UnbindServiceTarget(const std::string &pkgName, int64_t serviceId); + int32_t RegisterServiceInfo(const ServiceRegInfo &serviceRegInfo, int32_t ®ServiceId); + int32_t UnRegisterServiceInfo(int32_t regServiceId); + int32_t StartPublishService(const std::string &pkgName, + PublishServiceParam &publishServiceParam, int64_t &serviceId); + int32_t StopPublishService(int64_t serviceId); private: bool IsDMServiceImplReady(); bool IsDMImplSoLoaded(); @@ -418,6 +429,12 @@ private: void GetLocalUserIdFromDataBase(std::vector &foregroundUsers, std::vector &backgroundUsers); void PutLocalUserIdToDataBase(const std::vector &foregroundUsers, const std::vector &backgroundUsers); + int32_t UpdateServiceInfo(int64_t serviceId); + int32_t GenerateServiceId(int64_t &serviceId); + int32_t GetServiceBindLocalInfo(ServiceBindLocalInfo &localInfo); + int32_t ConvertServiceInfoProfileByRegInfo(const ServiceRegInfo &serviceRegInfo, + ServiceInfoProfile &serviceInfoProfile); + int32_t GenerateRegServiceId(int32_t ®ServiceId); private: bool isImplsoLoaded_ = false; diff --git a/services/service/include/device_manager_service_listener.h b/services/service/include/device_manager_service_listener.h index 8eaf51139..7c7a22921 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 f917117d4..fa235c5f9 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,49 @@ int32_t DeviceManagerServiceListener::OpenAuthSessionWithPara(const std::string return ERR_DM_UNSUPPORTED_METHOD; #endif } + +int32_t DeviceManagerServiceListener::OpenAuthSessionWithPara(int64_t serviceId) +{ +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + return DeviceManagerService::GetInstance().OpenAuthSessionWithPara(serviceId); +#else + return ERR_DM_UNSUPPORTED_METHOD; +#endif +} + +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 5994cd534..49a04ae6d 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/utils/BUILD.gn b/utils/BUILD.gn index c4d1ba8fe..6e644b74c 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 e03124661..23775941a 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 17eaf947f..19278a6a9 100644 --- a/utils/src/appInfo/standard/app_manager.cpp +++ b/utils/src/appInfo/standard/app_manager.cpp @@ -27,13 +27,15 @@ #include "dm_anonymous.h" #include "dm_error_type.h" #include "dm_log.h" - +#include "parameter.h" using namespace OHOS::Security::AccessToken; 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 +339,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 -- Gitee From d2dd1d44ec01064b142d5ff5e69e4f7286d9b193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=B7?= Date: Thu, 11 Sep 2025 16:14:04 +0800 Subject: [PATCH 02/14] add service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- .../inner_kits/native_cpp/src/device_manager_impl.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index 96234824e..23aa74e64 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -56,24 +56,17 @@ #include "ipc_permission_req.h" #include "ipc_publish_req.h" #include "ipc_put_device_profile_info_list_req.h" -#include "ipc_publish_service_info_rsp.h" #include "ipc_register_serviceinfo_req.h" -#include "ipc_register_service_info_new_req.h" #include "ipc_set_credential_req.h" #include "ipc_set_credential_rsp.h" #include "ipc_set_local_device_name_req.h" #include "ipc_set_remote_device_name_req.h" #include "ipc_set_useroperation_req.h" #include "ipc_skeleton.h" -#include "ipc_start_service_discovery_req.h" #include "ipc_sync_callback_req.h" -#include "ipc_start_publish_service_req.h" -#include "ipc_stop_publish_service_req.h" #include "ipc_unauthenticate_device_req.h" #include "ipc_unbind_device_req.h" -#include "ipc_unbind_service_target_req.h" #include "ipc_unpublish_req.h" -#include "ipc_unregister_service_info_req.h" #include "securec.h" #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #include "ipc_model_codec.h" -- Gitee From ff288d0e1e1205e7c0d5947e86f16501d6746d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=B7?= Date: Thu, 11 Sep 2025 16:17:21 +0800 Subject: [PATCH 03/14] add service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- .../authentication_v2/dm_auth_message_processor.cpp | 11 +++++++++++ .../src/devicestate/dm_device_state_manager.cpp | 1 + 2 files changed, 12 insertions(+) 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 2e87ccf93..f98426272 100644 --- a/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp @@ -2041,6 +2041,17 @@ int32_t DmAuthMessageProcessor::EncryptSyncMessage(std::shared_ptraccesser.isCommonFlag; syncMsgJson[TAG_DM_CERT_CHAIN] = context->accesser.cert; + CreateProxyAccessMessage(context, syncMsgJson); + std::string syncMsg = syncMsgJson.Dump(); + std::string compressMsg = CompressSyncMsg(syncMsg); + if (compressMsg.empty()) { + LOGE("DmAuthMessageProcessor::EncryptSyncMessage compress failed"); + return ERR_DM_FAILED; + } + JsonObject plainJson; + plainJson[TAG_COMPRESS_ORI_LEN] = syncMsg.size(); + plainJson[TAG_COMPRESS] = Base64Encode(compressMsg); + return cryptoMgr_->EncryptMessage(plainJson.Dump(), encSyncMsg); } int32_t DmAuthMessageProcessor::CreateProxyAccessMessage(std::shared_ptr &context, diff --git a/services/implementation/src/devicestate/dm_device_state_manager.cpp b/services/implementation/src/devicestate/dm_device_state_manager.cpp index 6adaa2c94..7e0db378b 100644 --- a/services/implementation/src/devicestate/dm_device_state_manager.cpp +++ b/services/implementation/src/devicestate/dm_device_state_manager.cpp @@ -178,6 +178,7 @@ void DmDeviceStateManager::ProcessDeviceStateChange(const DmDeviceState devState for (const auto &item : processInfoVec) { if (!item.pkgName.empty()) { LOGI("ProcessDeviceStateChange, pkgName = %{public}s", item.pkgName.c_str()); + listener_->OnDeviceStateChange(item, devState, devInfo); } } } -- Gitee From 073893053f089d0831440936d84c4a6886af1153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=B7?= Date: Thu, 11 Sep 2025 16:18:11 +0800 Subject: [PATCH 04/14] add service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- utils/src/appInfo/standard/app_manager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/src/appInfo/standard/app_manager.cpp b/utils/src/appInfo/standard/app_manager.cpp index 19278a6a9..01bd4ca3b 100644 --- a/utils/src/appInfo/standard/app_manager.cpp +++ b/utils/src/appInfo/standard/app_manager.cpp @@ -23,11 +23,12 @@ #include "os_account_manager.h" #include "system_ability_definition.h" #include "tokenid_kit.h" +#include "parameter.h" #include "dm_anonymous.h" #include "dm_error_type.h" #include "dm_log.h" -#include "parameter.h" + using namespace OHOS::Security::AccessToken; namespace OHOS { -- Gitee From f0ad8ec402644da9c10bf91a21064eee6ff3e52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=B7?= Date: Thu, 11 Sep 2025 16:22:14 +0800 Subject: [PATCH 05/14] add service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- .../include/device_manager_service_impl.h | 4 ---- services/service/include/device_manager_service.h | 11 ----------- 2 files changed, 15 deletions(-) diff --git a/services/implementation/include/device_manager_service_impl.h b/services/implementation/include/device_manager_service_impl.h index 532d0ca22..13759a00d 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -205,9 +205,6 @@ public: const DmAccessCallee &callee, const std::string &sinkUdid); void DeleteHoDevice(const std::string &peerUdid, const std::vector &foreGroundUserIds, const std::vector &backGroundUserIds); - int32_t BindServiceTarget(const std::string &pkgName, const PeerTargetId &targetId, - const std::map &bindParam); - int32_t UnbindServiceTarget(const std::string &pkgName, int64_t serviceId); void InitTaskOfDelTimeOutAcl(const std::string &deviceUdid, const std::string &deviceUdidHash); private: int32_t PraseNotifyEventJson(const std::string &event, JsonObject &jsonObject); @@ -307,7 +304,6 @@ private: const std::string &deviceId, int32_t reason, uint64_t tokenId); void GetBundleName(const DMAclQuadInfo &info, std::set &pkgNameSet); void DeleteSessionKey(int32_t userId, const DistributedDeviceProfile::AccessControlProfile &profile); - int32_t DeleteAclExtraDataServiceId(int64_t serviceId); private: std::mutex authMgrMtx_; std::shared_ptr authMgr_; // Old protocol only diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index cdeaf2919..d570f2e59 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -264,7 +264,6 @@ public: 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 OpenAuthSessionWithPara(int64_t serviceId); int32_t UnRegisterPinHolderCallback(const std::string &pkgName); void ProcessReceiveRspAppUninstall(const std::string &remoteUdid); void ProcessReceiveRspAppUnbind(const std::string &remoteUdid); @@ -276,16 +275,6 @@ 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 StartServiceDiscovery(const std::string &pkgName, const DiscoveryServiceParam &discParam); - int32_t StopServiceDiscovery(const std::string &pkgName, int32_t discServiceId); - int32_t BindServiceTarget(const std::string &pkgName, const PeerTargetId &targetId, - const std::map &bindParam); - int32_t UnbindServiceTarget(const std::string &pkgName, int64_t serviceId); - int32_t RegisterServiceInfo(const ServiceRegInfo &serviceRegInfo, int32_t ®ServiceId); - int32_t UnRegisterServiceInfo(int32_t regServiceId); - int32_t StartPublishService(const std::string &pkgName, - PublishServiceParam &publishServiceParam, int64_t &serviceId); - int32_t StopPublishService(int64_t serviceId); private: bool IsDMServiceImplReady(); bool IsDMImplSoLoaded(); -- Gitee From 045bcba2f31220208a8a5aa62dae651d308af6c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=B7?= Date: Thu, 11 Sep 2025 16:25:05 +0800 Subject: [PATCH 06/14] add service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- .../inner_kits/native_cpp/include/device_manager_impl.h | 1 + .../src/authentication_v2/dm_auth_message_processor.cpp | 1 + services/service/include/device_manager_service.h | 6 ------ utils/src/appInfo/standard/app_manager.cpp | 2 +- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h index f72675337..863626aef 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -439,6 +439,7 @@ public: virtual bool CheckSinkAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee) override; virtual bool CheckSrcIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee) override; virtual bool CheckSinkIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee) override; + private: DeviceManagerImpl() = default; ~DeviceManagerImpl() = default; 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 f98426272..f9cd8437d 100644 --- a/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp @@ -2007,6 +2007,7 @@ int32_t DmAuthMessageProcessor::EncryptSyncMessage(std::shared_ptr &foregroundUsers, std::vector &backgroundUsers); void PutLocalUserIdToDataBase(const std::vector &foregroundUsers, const std::vector &backgroundUsers); - int32_t UpdateServiceInfo(int64_t serviceId); - int32_t GenerateServiceId(int64_t &serviceId); - int32_t GetServiceBindLocalInfo(ServiceBindLocalInfo &localInfo); - int32_t ConvertServiceInfoProfileByRegInfo(const ServiceRegInfo &serviceRegInfo, - ServiceInfoProfile &serviceInfoProfile); - int32_t GenerateRegServiceId(int32_t ®ServiceId); private: bool isImplsoLoaded_ = false; diff --git a/utils/src/appInfo/standard/app_manager.cpp b/utils/src/appInfo/standard/app_manager.cpp index 01bd4ca3b..7ef0a6cd5 100644 --- a/utils/src/appInfo/standard/app_manager.cpp +++ b/utils/src/appInfo/standard/app_manager.cpp @@ -21,9 +21,9 @@ #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" -#include "parameter.h" #include "dm_anonymous.h" #include "dm_error_type.h" -- Gitee From c502b04a4f63c8bccbb9b57d8e4c7fc20e50471e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=B7?= Date: Thu, 11 Sep 2025 17:15:21 +0800 Subject: [PATCH 07/14] add service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- commondependency/include/deviceprofile_connector.h | 2 +- commondependency/src/deviceprofile_connector.cpp | 8 +++++--- .../inner_kits/native_cpp/include/i_dm_service_impl_ext.h | 2 +- .../native_cpp/include/i_dm_service_impl_ext_resident.h | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index ffb86fcc6..5e94c6c84 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -231,7 +231,7 @@ public: 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, bool isMultiUser, int32_t userId); + 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); diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 9f34f887d..2be11e389 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -2373,10 +2373,8 @@ DM_EXPORT int32_t DeviceProfileConnector::PutServiceInfoProfile(const ServiceInf return DM_OK; } -DM_EXPORT int32_t DeviceProfileConnector::DeleteServiceInfoProfile(int32_t regServiceId, bool isMultiUser, - int32_t userId) +DM_EXPORT int32_t DeviceProfileConnector::DeleteServiceInfoProfile(int32_t regServiceId, int32_t userId) { - void(isMultiUser); LOGI("DeleteServiceInfoProfile start"); int32_t ret = DistributedDeviceProfileClient::GetInstance().DeleteServiceInfoProfile( regServiceId, userId); @@ -3548,6 +3546,10 @@ 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; 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 0e0a20660..3038801e2 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 @@ -109,7 +109,7 @@ public: 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(const int64_t serviceId) = 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; 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 ec351ea34..ba6468dcf 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 @@ -115,7 +115,7 @@ public: 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(const int64_t serviceId) = 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; -- Gitee From 06270aff65da7be308c99cf4324bb6b1934f5edb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=B7?= Date: Thu, 11 Sep 2025 17:39:34 +0800 Subject: [PATCH 08/14] add service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- .../src/authentication_v2/dm_auth_message_processor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f9cd8437d..43f367ea3 100644 --- a/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp @@ -2007,7 +2007,7 @@ int32_t DmAuthMessageProcessor::EncryptSyncMessage(std::shared_ptr Date: Thu, 11 Sep 2025 17:55:51 +0800 Subject: [PATCH 09/14] add service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- services/service/src/device_manager_service_listener.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index fa235c5f9..cb4895091 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -1154,11 +1154,7 @@ int32_t DeviceManagerServiceListener::OpenAuthSessionWithPara(const std::string int32_t DeviceManagerServiceListener::OpenAuthSessionWithPara(int64_t serviceId) { -#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) - return DeviceManagerService::GetInstance().OpenAuthSessionWithPara(serviceId); -#else return ERR_DM_UNSUPPORTED_METHOD; -#endif } void DeviceManagerServiceListener::OnServiceFound(const ProcessInfo &processInfo, int32_t discServiceId, -- Gitee From 7a3da5a16d5dd6899718811357f3776809da69f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=B7?= Date: Thu, 11 Sep 2025 18:59:24 +0800 Subject: [PATCH 10/14] add service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- test/unittest/UTTest_dm_pin_holder.h | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/unittest/UTTest_dm_pin_holder.h b/test/unittest/UTTest_dm_pin_holder.h index 4dfb660f8..b4dba923c 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 -- Gitee From 23df60395797564690811ad5bb23cbe1c21a2c46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=B7?= Date: Thu, 11 Sep 2025 19:02:10 +0800 Subject: [PATCH 11/14] add service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- services/service/src/device_manager_service_listener.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index cb4895091..05beed686 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -1086,7 +1086,7 @@ void DeviceManagerServiceListener::ProcessDeviceOnline(const std::vector &serviceIds) { LOGI("state %{public}d, udidhash %{public}s.", static_cast(state), - GetAnonyString(info.deviceId).c_str()); + GetAnonyString(info.deviceId).c_str()); for (const auto &it : procInfoVec) { std::shared_ptr pReq = std::make_shared(); std::shared_ptr pRsp = std::make_shared(); -- Gitee From 9a8f3ca7fd3b1b43e6995f489a61f9f0db14fe75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=B7?= Date: Thu, 11 Sep 2025 19:24:32 +0800 Subject: [PATCH 12/14] add service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- commondependency/src/deviceprofile_connector.cpp | 2 +- .../inner_kits/native_cpp/src/notify/device_manager_notify.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 2be11e389..b7a6091b9 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -3554,7 +3554,7 @@ DM_EXPORT void DeviceProfileConnector::GetRemoteTokenIds(const std::string &loca std::vector profiles = GetAclProfileByDeviceIdAndUserId(localUdid, userId); uint64_t peerToken = 0; for (auto &item : profiles) { - if(item.GetStatus() != ACTIVE) { + if (item.GetStatus() != ACTIVE) { continue; } if (item.GetAccessee().GetAccesseeDeviceId() == localUdid && 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 1740bb430..136ccb0b9 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 @@ -1554,7 +1554,7 @@ void DeviceManagerNotify::OnServiceOnline(const std::vector &serviceIds #else std::thread serviceOnline([=]() { ServiceInfoOnline(callbackInfo);}); int32_t ret = pthread_setname_np(serviceOnline.native_handle(), SERVICE_ONLINE); - if(ret != DM_OK) { + if (ret != DM_OK) { LOGE("DeviceManagerNotify serviceOnline setname failed."); } serviceOnline.detach(); -- Gitee From 12fc804073aebda445f62f777eac08d2801a1988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=B7?= Date: Fri, 12 Sep 2025 10:01:09 +0800 Subject: [PATCH 13/14] add service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- .../native_cpp/include/dm_device_info.h | 22 +++++++++---------- .../src/notify/device_manager_notify.cpp | 16 ++++++++++++++ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/include/dm_device_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_info.h index 5cff684a8..0e4d753a2 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -480,7 +480,7 @@ typedef struct DMAclQuadInfo { } DMAclQuadInfo; typedef struct ServiceInfo { - int64_t serviceId; + int64_t serviceId = 0; std::string serviceType; std::string serviceName; std::string serviceDisplayName; @@ -502,7 +502,7 @@ typedef enum DMSrvMediumType { typedef struct DiscoveryServiceParam { std::string serviceName; std::string serviceType; - int32_t discoveryServiceId; + int32_t discoveryServiceId = 0; DmExchangeFreq freq; DMSrvMediumType medium; DMSrvDiscoveryMode mode; @@ -514,12 +514,12 @@ typedef struct DiscoveryServiceInfo { } DiscoveryServiceInfo; typedef struct ServiceInfoProfile { - int32_t regServiceId; + int32_t regServiceId = 0; std::string deviceId; - int32_t userId; - int64_t tokenId; - int8_t publishState; - int64_t serviceId; + 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; @@ -528,21 +528,21 @@ typedef struct ServiceInfoProfile { typedef struct ServiceRegInfo { ServiceInfo serviceInfo; std::string customData; - uint32_t dataLen; + uint32_t dataLen = 0; } ServiceRegInfo; typedef struct PublishServiceParam { ServiceInfo serviceInfo; DMSrvDiscoveryMode discoverMode; - int32_t regServiceId; + int32_t regServiceId = 0; DMSrvMediumType media; DmExchangeFreq freq; } PublishServiceParam; typedef struct ServiceBindlocalInfo { std::string localUdid; - int32_t userId; - uint32_t tokenId; + int32_t userId = 0; + uint32_t tokenId = 0; } ServiceBindLocalInfo; } // 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 136ccb0b9..6cc6d01eb 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 @@ -718,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>(); @@ -749,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>(); @@ -1475,6 +1483,10 @@ void DeviceManagerNotify::RegisterServiceDiscoveryCallback(int32_t discoveryServ 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; } @@ -1581,6 +1593,10 @@ int32_t DeviceManagerNotify::RegisterServiceStateCallback(const std::string &key 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; } -- Gitee From 507e0f46ba54b01441b3643be2c009590a947c3a Mon Sep 17 00:00:00 2001 From: 18392818341 <15571958+meo123456@user.noreply.gitee.com> Date: Fri, 12 Sep 2025 14:06:50 +0800 Subject: [PATCH 14/14] fix code Signed-off-by: 18392818341 <15571958+meo123456@user.noreply.gitee.com> --- .../ipc/model/ipc_publish_service_info_rsp.h | 4 +-- .../model/ipc_register_service_info_new_req.h | 2 +- .../ipc/model/ipc_start_publish_service_req.h | 6 ++--- .../ipc/model/ipc_stop_publish_service_req.h | 4 +-- .../model/ipc_unregister_service_info_req.h | 2 +- common/src/dm_constants.cpp | 2 +- .../native_cpp/include/dm_device_info.h | 26 +++++++------------ .../src/notify/device_manager_notify.cpp | 7 +++-- .../src/authentication_v2/auth_manager.cpp | 2 +- 9 files changed, 24 insertions(+), 31 deletions(-) diff --git a/common/include/ipc/model/ipc_publish_service_info_rsp.h b/common/include/ipc/model/ipc_publish_service_info_rsp.h index 3f2ee1054..79569a957 100644 --- a/common/include/ipc/model/ipc_publish_service_info_rsp.h +++ b/common/include/ipc/model/ipc_publish_service_info_rsp.h @@ -45,8 +45,8 @@ public: } private: - int32_t regServiceId_; - int64_t serviceId_; + int32_t regServiceId_ = 0; + int64_t serviceId_ = 0; }; } // namespace DistributedHardware } // namespace OHOS 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 index d2d4f940f..93a97f948 100644 --- a/common/include/ipc/model/ipc_register_service_info_new_req.h +++ b/common/include/ipc/model/ipc_register_service_info_new_req.h @@ -46,7 +46,7 @@ public: private: ServiceRegInfo serviceRegInfo_; - int64_t regServiceId_; + int32_t regServiceId_ = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/common/include/ipc/model/ipc_start_publish_service_req.h b/common/include/ipc/model/ipc_start_publish_service_req.h index 0a9c380eb..6ef0d4f8a 100644 --- a/common/include/ipc/model/ipc_start_publish_service_req.h +++ b/common/include/ipc/model/ipc_start_publish_service_req.h @@ -31,7 +31,7 @@ public: return publishServiceParam_; } - void SetPublishServiceParam(const PublishServiceParam& publishServiceParam) + void SetPublishServiceParam(const PublishServiceParam &publishServiceParam) { publishServiceParam_ = publishServiceParam; } @@ -41,13 +41,13 @@ public: return serviceId_; } - void SetServiceId(const int64_t& serviceId) + void SetServiceId(int64_t serviceId) { serviceId_ = serviceId; } private: - int64_t serviceId_; + int64_t serviceId_ = 0; PublishServiceParam publishServiceParam_; }; } // namespace DistributedHardware diff --git a/common/include/ipc/model/ipc_stop_publish_service_req.h b/common/include/ipc/model/ipc_stop_publish_service_req.h index 1ebda8dc8..4612c0d3d 100644 --- a/common/include/ipc/model/ipc_stop_publish_service_req.h +++ b/common/include/ipc/model/ipc_stop_publish_service_req.h @@ -29,13 +29,13 @@ public: return serviceId_; } - void SetServiceId(const int64_t& serviceId) + void SetServiceId(int64_t serviceId) { serviceId_ = serviceId; } private: - int64_t serviceId_; + int64_t serviceId_ = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/common/include/ipc/model/ipc_unregister_service_info_req.h b/common/include/ipc/model/ipc_unregister_service_info_req.h index 96d57e53d..d6712dc98 100644 --- a/common/include/ipc/model/ipc_unregister_service_info_req.h +++ b/common/include/ipc/model/ipc_unregister_service_info_req.h @@ -36,7 +36,7 @@ public: } private: - int32_t regServiceId_; + int32_t regServiceId_ = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/common/src/dm_constants.cpp b/common/src/dm_constants.cpp index 2b4cce08d..44c580fa5 100644 --- a/common/src/dm_constants.cpp +++ b/common/src/dm_constants.cpp @@ -174,7 +174,7 @@ const std::map MAP_ERROR_CODE = { }; // wise device -const uint32_t MAX_CONTAINER_SIZE = 1000; +const uint32_t MAX_CONTAINER_SIZE = 10000; const int32_t MAX_DEVICE_PROFILE_SIZE = 500; const char* ACL_IS_LNN_ACL_KEY = "IsLnnAcl"; const char* ACL_IS_LNN_ACL_VAL_TRUE = "true"; 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 5cff684a8..5a334b42c 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -296,7 +296,7 @@ typedef struct PeerTargetId { /** * service id. */ - int64_t serviceId; + int64_t serviceId = 0; bool operator==(const PeerTargetId &other) const { @@ -480,7 +480,7 @@ typedef struct DMAclQuadInfo { } DMAclQuadInfo; typedef struct ServiceInfo { - int64_t serviceId; + int64_t serviceId = 0; std::string serviceType; std::string serviceName; std::string serviceDisplayName; @@ -502,7 +502,7 @@ typedef enum DMSrvMediumType { typedef struct DiscoveryServiceParam { std::string serviceName; std::string serviceType; - int32_t discoveryServiceId; + int32_t discoveryServiceId = 0; DmExchangeFreq freq; DMSrvMediumType medium; DMSrvDiscoveryMode mode; @@ -514,12 +514,12 @@ typedef struct DiscoveryServiceInfo { } DiscoveryServiceInfo; typedef struct ServiceInfoProfile { - int32_t regServiceId; + int32_t regServiceId = 0; std::string deviceId; - int32_t userId; - int64_t tokenId; - int8_t publishState; - int64_t serviceId; + 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; @@ -528,22 +528,16 @@ typedef struct ServiceInfoProfile { typedef struct ServiceRegInfo { ServiceInfo serviceInfo; std::string customData; - uint32_t dataLen; + uint32_t dataLen = 0; } ServiceRegInfo; typedef struct PublishServiceParam { ServiceInfo serviceInfo; DMSrvDiscoveryMode discoverMode; - int32_t regServiceId; + int32_t regServiceId = 0; DMSrvMediumType media; DmExchangeFreq freq; } PublishServiceParam; - -typedef struct ServiceBindlocalInfo { - std::string localUdid; - int32_t userId; - uint32_t tokenId; -} 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/src/notify/device_manager_notify.cpp b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp index 136ccb0b9..28c345d32 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 @@ -1475,6 +1475,7 @@ void DeviceManagerNotify::RegisterServiceDiscoveryCallback(int32_t discoveryServ return; } std::lock_guard autolock(lock_); + CHECK_SIZE_VOID(serviceDiscoveryCallbacks_); serviceDiscoveryCallbacks_[discoveryServiceId] = callback; } @@ -1581,6 +1582,7 @@ int32_t DeviceManagerNotify::RegisterServiceStateCallback(const std::string &key return ERR_DM_INPUT_PARA_INVALID; } std::lock_guard autolock(lock_); + CHECK_SIZE_RETURN(serviceStateCallback_, ERR_DM_CALLBACK_REGISTER_FAILED); serviceStateCallback_[key] = callback; return DM_OK; } @@ -1606,10 +1608,7 @@ void DeviceManagerNotify::RegisterServicePublishCallback(int64_t serviceId, return; } std::lock_guard autoLock(lock_); - if (servicePublishCallback_.size() >= MAX_CONTAINER_SIZE) { - LOGE("servicePublishCallback_ map size is more than max size"); - return; - } + CHECK_SIZE_VOID(servicePublishCallback_); servicePublishCallback_[serviceId] = callback; LOGI("RegisterPublishCallback success"); } diff --git a/services/implementation/src/authentication_v2/auth_manager.cpp b/services/implementation/src/authentication_v2/auth_manager.cpp index 470d19512..c72fcede7 100644 --- a/services/implementation/src/authentication_v2/auth_manager.cpp +++ b/services/implementation/src/authentication_v2/auth_manager.cpp @@ -598,7 +598,7 @@ void AuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, ParseJsonObject(jsonObject); if (context_->isServiceBind) { if (IsNumberString(deviceId)) { - context_->accessee.serviceId = std::stoll(deviceId); + context_->accessee.serviceId = std::stoll(deviceId); // service bind device id is service id context_->accesser.serviceId = std::stoll(deviceId); } else { LOGE("OpenAuthSession failed"); -- Gitee