diff --git a/common/BUILD.gn b/common/BUILD.gn index dc264caf350f5629f6bbb7b029abcc8de82d891e..9f148dde9bdc9c24fb657cdf29cc71f8bba6b210 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -13,8 +13,57 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") +import("//build/config/components/idl_tool/idl.gni") import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni") +idl_gen_interface("dp_business_callback_interfaces") { + sources = [ + "IBusinessCallback.idl", + ] + log_domainid = "0xD004400" + log_tag = "Distributed_Device_Profile" +} + +config("business_callback_interfaces_ipc_config"){ + include_dirs = [ + ".", + "${target_gen_dir}/", + ] +} + +ohos_source_set("business_callback_interfaces_ipc") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + + output_values = get_target_outputs(":dp_business_callback_interfaces") + sources = [] + sources += filter_include(output_values, [ "*.cpp" ]) + public_configs = [ + ":business_callback_interfaces_ipc_config" + ] + include_dirs = [ + "${device_profile_common}/include/constants", + "${device_profile_common}/include/interfaces", + "${device_profile_common}/include/utils", + ] + deps = [ ":dp_business_callback_interfaces",] + external_deps = [ + "cJSON:cjson", + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + part_name = "device_info_manager" + subsystem_name = "deviceprofile" +} + config("distributed_device_profile_common_config") { visibility = [ ":*" ] include_dirs = [ @@ -55,8 +104,6 @@ ohos_shared_library("distributed_device_profile_common") { "src/interfaces/access_control_profile.cpp", "src/interfaces/accessee.cpp", "src/interfaces/accesser.cpp", - "src/interfaces/business_callback_proxy.cpp", - "src/interfaces/business_callback_stub.cpp", "src/interfaces/business_event.cpp", "src/interfaces/characteristic_profile.cpp", "src/interfaces/device_icon_info.cpp", @@ -88,9 +135,12 @@ ohos_shared_library("distributed_device_profile_common") { "src/utils/profile_utils.cpp", ] - deps = [] + deps = [":business_callback_interfaces_ipc"] - public_configs = [ ":distributed_device_profile_common_config" ] + public_configs = [ + ":business_callback_interfaces_ipc_config", + ":distributed_device_profile_common_config" + ] external_deps = [ "access_token:libaccesstoken_sdk", diff --git a/common/include/interfaces/i_business_callback.h b/common/IBusinessCallback.idl similarity index 51% rename from common/include/interfaces/i_business_callback.h rename to common/IBusinessCallback.idl index ea089df42f21ddc3744f3974252797c15ea66ee4..5cb746d7934f72ac3fcc8145ddf47ed92976adaa 100644 --- a/common/include/interfaces/i_business_callback.h +++ b/common/IBusinessCallback.idl @@ -13,23 +13,7 @@ * limitations under the License. */ -#ifndef OHOS_DP_IBUSINESS_CALLBACK_H -#define OHOS_DP_IBUSINESS_CALLBACK_H - -#include "business_event.h" -#include "iremote_broker.h" - -namespace OHOS { -namespace DistributedDeviceProfile { - -class IBusinessCallback : public OHOS::IRemoteBroker { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DeviceProfile.IBusinessCallback"); - IBusinessCallback() = default; - virtual ~IBusinessCallback() = default; - - virtual int32_t OnBusinessEvent(const BusinessEvent& event) = 0; -}; -} // namespace DistributedDeviceProfile -} // namespace OHOS -#endif // OHOS_DP_IBUSINESS_CALLBACK_H \ No newline at end of file +sequenceable BusinessEvent..OHOS.DistributedDeviceProfile.BusinessEventExt; +interface OHOS.DistributedDeviceProfile.IBusinessCallback { + void OnBusinessEvent([in] BusinessEventExt event); +} \ No newline at end of file diff --git a/common/include/interfaces/business_callback_proxy.h b/common/include/interfaces/business_callback_proxy.h deleted file mode 100644 index 0168860c1a545dc5dafcdfd95fe9efd5af696ac4..0000000000000000000000000000000000000000 --- a/common/include/interfaces/business_callback_proxy.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -* Copyright (c) 2025 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef OHOS_DP_BUSINESS_CALLBACK_PROXY_H -#define OHOS_DP_BUSINESS_CALLBACK_PROXY_H - -#include - -#include "distributed_device_profile_enums.h" -#include "i_business_callback.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "refbase.h" - -namespace OHOS { -namespace DistributedDeviceProfile { -class BusinessCallbackProxy : public IRemoteProxy { -public: - explicit BusinessCallbackProxy(const sptr& impl) - : IRemoteProxy(impl) {} - ~BusinessCallbackProxy() = default; - - int32_t OnBusinessEvent(const BusinessEvent& event) override; - -private: - static inline BrokerDelegator delegator_; -}; -} // namespace DistributedDeviceProfile -} // namespace OHOS -#endif // OHOS_DP_BUSINESS_CALLBACK_PROXY_H diff --git a/common/include/interfaces/business_callback_stub.h b/common/include/interfaces/business_callback_stub.h deleted file mode 100644 index 99aeac17ddbd1c955e9f27e78b58197c0d385b2e..0000000000000000000000000000000000000000 --- a/common/include/interfaces/business_callback_stub.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -* Copyright (c) 2025 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef OHOS_BUSINESS_CALLBACK_STUB_H -#define OHOS_BUSINESS_CALLBACK_STUB_H - -#include - -#include "distributed_device_profile_enums.h" -#include "distributed_device_profile_errors.h" -#include "i_business_callback.h" -#include "iremote_stub.h" -#include "message_parcel.h" -#include "refbase.h" - -namespace OHOS { -namespace DistributedDeviceProfile { -class BusinessCallbackStub : public IRemoteStub { -public: - BusinessCallbackStub(); - ~BusinessCallbackStub(); - - virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, - MessageOption& option) override; - -private: - int32_t OnBusinessEventInner(MessageParcel& data, MessageParcel& reply); -}; -} // namespace DistributedDeviceProfile -} // namespace OHOS -#endif // OHOS_BUSINESS_CALLBCK_STUB_H diff --git a/common/include/interfaces/business_event.h b/common/include/interfaces/business_event.h index e15f5be1b34c2ffe4c6969c72c2c0418fe8bb254..9c430b4210fe9995e6d61c30a3e88087ff60b35f 100644 --- a/common/include/interfaces/business_event.h +++ b/common/include/interfaces/business_event.h @@ -21,6 +21,7 @@ #include "distributed_device_profile_constants.h" #include "dp_parcel.h" +#include "parcel.h" namespace OHOS { namespace DistributedDeviceProfile { @@ -40,6 +41,26 @@ public: bool UnMarshalling(MessageParcel& parcel) override; std::string dump() const override; +private: + std::string businessKey_ = ""; + std::string businessValue_ = ""; +}; + +class BusinessEventExt : public Parcelable { +public: + BusinessEventExt(const std::string& businessKey, const std::string& businessValue) + : businessKey_(businessKey), businessValue_(businessValue) {}; + + BusinessEventExt(); + ~BusinessEventExt(); + + std::string GetBusinessKey() const; + void SetBusinessKey(const std::string& businessKey); + std::string GetBusinessValue() const; + void SetBusinessValue(const std::string& businessValue); + bool Marshalling(Parcel &parcel) const override; + static BusinessEventExt *Unmarshalling(Parcel &parcel); + private: std::string businessKey_ = ""; std::string businessValue_ = ""; @@ -47,4 +68,4 @@ private: } // namespace DistributedDeviceProfile } // namespace OHOS #endif //OHOS_DP_BUSINESS_EVENT_H - \ No newline at end of file + diff --git a/common/include/interfaces/i_distributed_device_profile.h b/common/include/interfaces/i_distributed_device_profile.h index 567de016050e17e164ebd01baac31196e07ddc0e..413c643c081fd45f04fa222ef7d78d8077aad56b 100644 --- a/common/include/interfaces/i_distributed_device_profile.h +++ b/common/include/interfaces/i_distributed_device_profile.h @@ -28,7 +28,6 @@ #include "device_profile_filter_options.h" #include "dp_subscribe_info.h" #include "dp_sync_options.h" -#include "i_business_callback.h" #include "i_sync_completed_callback.h" #include "product_info.h" #include "service_info_profile.h" @@ -37,6 +36,7 @@ #include "trust_device_profile.h" #include "trusted_device_info.h" #include "local_service_info.h" +#include "business_event.h" namespace OHOS { namespace DistributedDeviceProfile { diff --git a/common/src/interfaces/business_callback_proxy.cpp b/common/src/interfaces/business_callback_proxy.cpp deleted file mode 100644 index a0bbad31b652154a47a372d98f5f2cd15d9629a4..0000000000000000000000000000000000000000 --- a/common/src/interfaces/business_callback_proxy.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* -* Copyright (c) 2025 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "business_callback_proxy.h" -#include "distributed_device_profile_errors.h" -#include "i_distributed_device_profile.h" -#include "macro_utils.h" -#include "message_parcel.h" - -namespace OHOS { -namespace DistributedDeviceProfile { -namespace { - const std::string TAG = "BusinessCallbackProxy"; -} - -int32_t BusinessCallbackProxy::OnBusinessEvent(const BusinessEvent& event) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - if (!data.WriteInterfaceToken(IBusinessCallback::GetDescriptor())) { - HILOGE("write descriptor failed"); - return ERR_FLATTEN_OBJECT; - } - if (!event.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::ON_BUSINESS_EVENT), data, reply); - return DP_SUCCESS; -} -} // namespace DistributedDeviceProfile -} // namespace OHOS - diff --git a/common/src/interfaces/business_callback_stub.cpp b/common/src/interfaces/business_callback_stub.cpp deleted file mode 100644 index e22f51fb9783d54868d3be9c9936105ab1cf1df2..0000000000000000000000000000000000000000 --- a/common/src/interfaces/business_callback_stub.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* -* Copyright (c) 2025 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "business_callback_stub.h" -#include "distributed_device_profile_log.h" -#include "ipc_utils.h" -#include "message_parcel.h" - -namespace OHOS { -namespace DistributedDeviceProfile { -namespace { - const std::string TAG = "BusinessdCallbackStub"; -} - -BusinessCallbackStub::BusinessCallbackStub() -{ - HILOGI("constructor!"); -} - -BusinessCallbackStub::~BusinessCallbackStub() -{ - HILOGI("destruct!"); -} - -int32_t BusinessCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel& data, - MessageParcel& reply, MessageOption& option) -{ - HILOGI("code = %{public}u", code); - std::u16string descriptor = BusinessCallbackStub::GetDescriptor(); - std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - HILOGE("Check descriptor failed"); - return DP_INTERFACE_CHECK_FAILED; - } - if (code != static_cast(DPInterfaceCode::ON_BUSINESS_EVENT)) { - HILOGW("Unknown request code, code = %{public}u", code); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - return OnBusinessEventInner(data, reply); -} - -int32_t BusinessCallbackStub::OnBusinessEventInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - BusinessEvent businessEvent; - if (!businessEvent.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = OnBusinessEvent(businessEvent); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} -} // namespace DistributedDeviceProfile -} // namespace OHOS diff --git a/common/src/interfaces/business_event.cpp b/common/src/interfaces/business_event.cpp index f2ec12a43e430084ff732909f64a5916a379c913..910ae694fde802814b31780f55d1eb143db4e028 100644 --- a/common/src/interfaces/business_event.cpp +++ b/common/src/interfaces/business_event.cpp @@ -87,6 +87,52 @@ std::string BusinessEvent::dump() const cJSON_free(jsonChars); return jsonStr; } + +BusinessEventExt::BusinessEventExt() +{ +} + +BusinessEventExt::~BusinessEventExt() +{ +} + +std::string BusinessEventExt::GetBusinessKey() const +{ + return businessKey_; +} + +void BusinessEventExt::SetBusinessKey(const std::string& businessKey) +{ + businessKey_ = businessKey; +} + +std::string BusinessEventExt::GetBusinessValue() const +{ + return businessValue_; +} + +void BusinessEventExt::SetBusinessValue(const std::string& businessValue) +{ + businessValue_ = businessValue; +} + +bool BusinessEventExt::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER(parcel, String, businessKey_); + WRITE_HELPER(parcel, String, businessValue_); + return true; +} + +BusinessEventExt *BusinessEventExt::Unmarshalling(Parcel& parcel) +{ + BusinessEventExt* obj = new (std::nothrow) BusinessEventExt(); + if (!obj) { + return nullptr; + } + obj->businessKey_ = parcel.ReadString(); + obj->businessValue_ = parcel.ReadString(); + return obj; +} } // namespace DistributedDeviceProfile } // namespace OHOS - \ No newline at end of file + diff --git a/interfaces/innerkits/core/BUILD.gn b/interfaces/innerkits/core/BUILD.gn index 95a346e3e5f84d7191123cdada091e75d367e670..0625c28657dfa15d0c3caf498dbe842d6c3f3921 100644 --- a/interfaces/innerkits/core/BUILD.gn +++ b/interfaces/innerkits/core/BUILD.gn @@ -59,9 +59,13 @@ ohos_shared_library("distributed_device_profile_sdk") { "src/distributed_device_profile_proxy.cpp", ] - public_configs = [ ":distributed_device_profile_sdk_config" ] + public_configs = [ + ":distributed_device_profile_sdk_config", + "${device_profile_common}:business_callback_interfaces_ipc_config" + ] deps = [ + "${device_profile_common}:business_callback_interfaces_ipc", "${device_profile_common}:distributed_device_profile_common", "${device_profile_path}/radar:device_profile_radar", ] diff --git a/interfaces/innerkits/core/include/distributed_device_profile_client.h b/interfaces/innerkits/core/include/distributed_device_profile_client.h index 7f27d01f5f010033c51596609f807dead79cb7c2..cb1f6f869f9673813538a16d9a8af64b184bdf5e 100644 --- a/interfaces/innerkits/core/include/distributed_device_profile_client.h +++ b/interfaces/innerkits/core/include/distributed_device_profile_client.h @@ -34,7 +34,7 @@ #include "single_instance.h" #include "dp_subscribe_info.h" #include "distributed_device_profile_constants.h" -#include "i_business_callback.h" +#include "ibusiness_callback.h" #include "sync_completed_callback_stub.h" #include "system_ability_status_change_stub.h" #include "profile_change_listener_stub.h" diff --git a/interfaces/innerkits/core/include/distributed_device_profile_proxy.h b/interfaces/innerkits/core/include/distributed_device_profile_proxy.h index 4af626628008450d4e48658cd049fc112dea3667..d9e96ee3268e7734972af85c4bc7b3cbac62b0f5 100644 --- a/interfaces/innerkits/core/include/distributed_device_profile_proxy.h +++ b/interfaces/innerkits/core/include/distributed_device_profile_proxy.h @@ -28,7 +28,6 @@ #include "refbase.h" #include "distributed_device_profile_enums.h" #include "distributed_device_profile_errors.h" -#include "i_business_callback.h" #include "ipc_utils.h" #include "profile_change_listener_stub.h" diff --git a/services/core/src/distributed_device_profile_service_new.cpp b/services/core/src/distributed_device_profile_service_new.cpp index a20cd256d4b0aa3fd469277e2a3744b8fd8654e3..5e2b5f5db52076970aed1a361fb8ec9478cb7196 100644 --- a/services/core/src/distributed_device_profile_service_new.cpp +++ b/services/core/src/distributed_device_profile_service_new.cpp @@ -34,6 +34,7 @@ #include "device_profile_manager.h" #include "dp_radar_helper.h" #include "event_handler_factory.h" +#include "ibusiness_callback.h" #include "i_pincode_invalid_callback.h" #include "local_service_info_manager.h" #include "multi_user_manager.h" @@ -1476,7 +1477,8 @@ int32_t DistributedDeviceProfileServiceNew::NotifyBusinessEvent(const BusinessEv HILOGE("OnBusinessEvent task callbackProxy is nullptr"); return; } - callbackProxy->OnBusinessEvent(event); + BusinessEventExt eventExt(event.GetBusinessKey(), event.GetBusinessValue()); + callbackProxy->OnBusinessEvent(eventExt); }; auto handler = EventHandlerFactory::GetInstance().GetEventHandler(); HILOGI("notify"); diff --git a/services/core/test/unittest/distributed_device_profile_client_kv_test.cpp b/services/core/test/unittest/distributed_device_profile_client_kv_test.cpp index 24402b77bbcee1b415e4e157098302250194a328..847afe29ccc9087e503e402560f76be70df2ed57 100644 --- a/services/core/test/unittest/distributed_device_profile_client_kv_test.cpp +++ b/services/core/test/unittest/distributed_device_profile_client_kv_test.cpp @@ -166,7 +166,7 @@ public: ~BusinessCallback() { } - int32_t OnBusinessEvent(const BusinessEvent &event) + int32_t OnBusinessEvent(const BusinessEventExt &event) { (void)event; return DP_SUCCESS;