From 37c2365a18603c1ff4df2800b3da33a6f980699e Mon Sep 17 00:00:00 2001 From: zhengzhuolan Date: Tue, 11 Mar 2025 11:31:46 +0800 Subject: [PATCH] SwingCallBack_0311A Signed-off-by: zhengzhuolan --- frameworks/ans/BUILD.gn | 75 ++++++++++++++++++- .../ISwingCallBack.idl} | 70 +++++------------ frameworks/core/include/ans_notification.h | 6 +- ...k_interface.h => swing_callback_service.h} | 39 +++++----- frameworks/core/include/swing_callback_stub.h | 64 ---------------- frameworks/core/src/ans_notification.cpp | 10 +-- ...k_proxy.cpp => swing_callback_service.cpp} | 57 ++++---------- .../core/src/listener/swing_callback_stub.cpp | 58 -------------- .../swing_callback_test.cpp | 14 ++-- .../include/reminder_swing_decision_center.h | 4 +- .../src/reminder_swing_decision_center.cpp | 10 ++- .../mock/include/mock_swing_callback_stub.h | 6 +- .../mock/mock_swing_callback_stub.cpp | 5 +- 13 files changed, 151 insertions(+), 267 deletions(-) rename frameworks/{core/include/swing_callback_proxy.h => ans/ISwingCallBack.idl} (31%) rename frameworks/core/include/{swing_callback_interface.h => swing_callback_service.h} (44%) delete mode 100644 frameworks/core/include/swing_callback_stub.h rename frameworks/core/src/listener/{swing_callback_proxy.cpp => swing_callback_service.cpp} (36%) delete mode 100644 frameworks/core/src/listener/swing_callback_stub.cpp diff --git a/frameworks/ans/BUILD.gn b/frameworks/ans/BUILD.gn index 3883d2f55..8a2b26503 100644 --- a/frameworks/ans/BUILD.gn +++ b/frameworks/ans/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2024 Huawei Device Co., Ltd. +# Copyright (c) 2021-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 @@ -12,7 +12,15 @@ # limitations under the License. import("//base/notification/distributed_notification_service/notification.gni") -import("//build/ohos.gni") +import("//build/config/components/idl_tool/idl.gni") + +idl_gen_interface("swing_call_back_interface") { + sources = [ "ISwingCallBack.idl" ] + log_domainid = "0xD001203" + log_tag = "Ans" + subsystem_name = "notification" + part_name = "distributed_notification_service" +} group("ans_client") { deps = [ ":ans_innerkits" ] @@ -26,11 +34,65 @@ config("ans_innerkits_public_config") { "${interfaces_path}/kits/native", "${core_path}/common/include", "${core_path}/include", + "${target_gen_dir}", "//third_party/json/single_include", ] configs = [ "${multimedia_path}/interfaces/innerkits:image_external_config" ] } +config("swing_call_back_config") { + visibility = [ "./../../*" ] + + include_dirs = [ + "${inner_api_path}", + "${interfaces_path}/kits/native", + "${core_path}/common/include", + "${core_path}/include", + "${target_gen_dir}", + ] + configs = [ "${multimedia_path}/interfaces/innerkits:image_external_config" ] +} + +ohos_source_set("swing_call_back_proxy") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + public_configs = [ ":swing_call_back_config" ] + output_values = get_target_outputs(":swing_call_back_interface") + sources = filter_include(output_values, [ "*_proxy.cpp" ]) + deps = [ ":swing_call_back_interface" ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] + subsystem_name = "notification" + part_name = "distributed_notification_service" +} + +ohos_source_set("swing_call_back_stub") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + public_configs = [ ":swing_call_back_config" ] + output_values = get_target_outputs(":swing_call_back_interface") + sources = filter_include(output_values, [ "*_stub.cpp" ]) + deps = [ ":swing_call_back_interface" ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] + subsystem_name = "notification" + part_name = "distributed_notification_service" +} + ohos_shared_library("ans_innerkits") { sanitize = { integer_overflow = true @@ -58,8 +120,7 @@ ohos_shared_library("ans_innerkits") { "${core_path}/src/listener/ans_subscriber_local_live_view_stub.cpp", "${core_path}/src/listener/ans_subscriber_proxy.cpp", "${core_path}/src/listener/ans_subscriber_stub.cpp", - "${core_path}/src/listener/swing_callback_proxy.cpp", - "${core_path}/src/listener/swing_callback_stub.cpp", + "${core_path}/src/listener/swing_callback_service.cpp", "${core_path}/src/manager/ans_manager_death_recipient.cpp", "${core_path}/src/manager/ans_manager_proxy.cpp", "${core_path}/src/manager/ans_manager_proxy_bundle.cpp", @@ -120,6 +181,8 @@ ohos_shared_library("ans_innerkits") { defines = [] + deps = [] + external_deps = [ "ability_base:want", "ability_base:zuri", @@ -153,6 +216,10 @@ ohos_shared_library("ans_innerkits") { if (notification_smart_reminder_supported) { defines += [ "NOTIFICATION_SMART_REMINDER_SUPPORTED" ] + deps += [ + ":swing_call_back_proxy", + ":swing_call_back_stub", + ] } if (distributed_notification_service_feature_privileged_message) { diff --git a/frameworks/core/include/swing_callback_proxy.h b/frameworks/ans/ISwingCallBack.idl similarity index 31% rename from frameworks/core/include/swing_callback_proxy.h rename to frameworks/ans/ISwingCallBack.idl index 2f0016e60..216ebe1db 100644 --- a/frameworks/core/include/swing_callback_proxy.h +++ b/frameworks/ans/ISwingCallBack.idl @@ -1,52 +1,18 @@ -/* - * Copyright (c) 2024 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 BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_SWING_CALLBACK_PROXY_H -#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_SWING_CALLBACK_PROXY_H -#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED - -#include "distributed_notification_service_ipc_interface_code.h" -#include "swing_callback_interface.h" -#include "iremote_proxy.h" - -namespace OHOS { -namespace Notification { -/** - * @class SwingCallBackProxy - * SwingCallBack proxy. - */ -class SwingCallBackProxy : public IRemoteProxy { -public: - explicit SwingCallBackProxy(const sptr &impl) : IRemoteProxy(impl) - {} - - virtual ~SwingCallBackProxy() - {} - - /** - * OnUpdateStatus, update status. - * - * @param isEnable enable swing. - * @param triggerMode trigger mode. - * @return Returns true success, false fail. - */ - int32_t OnUpdateStatus(bool isEnable, int triggerMode) override; - -private: - static inline BrokerDelegator delegator_; -}; -} // namespace Notification -} // namespace OHOS -#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_SWING_CALLBACK_PROXY_H -#endif \ No newline at end of file +/* + * 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. + */ + +interface OHOS.Notification.ISwingCallBack { + int OnUpdateStatus([in] boolean isEnable, [in] int triggerMode); +} \ No newline at end of file diff --git a/frameworks/core/include/ans_notification.h b/frameworks/core/include/ans_notification.h index cae37a5b4..48a55e544 100644 --- a/frameworks/core/include/ans_notification.h +++ b/frameworks/core/include/ans_notification.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -26,7 +26,7 @@ #include "notification_local_live_view_subscriber.h" #include "want_params.h" #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED -#include "swing_callback_stub.h" +#include "swing_callback_service.h" #endif namespace OHOS { @@ -1316,7 +1316,7 @@ private: std::mutex subscriberMutex_; std::map, sptr> subscribers_; #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED - sptr swingCallBackStub_; + sptr swingCallBackService_; #endif }; } // namespace Notification diff --git a/frameworks/core/include/swing_callback_interface.h b/frameworks/core/include/swing_callback_service.h similarity index 44% rename from frameworks/core/include/swing_callback_interface.h rename to frameworks/core/include/swing_callback_service.h index 7483a9f62..ebd2f2834 100644 --- a/frameworks/core/include/swing_callback_interface.h +++ b/frameworks/core/include/swing_callback_service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * 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 @@ -12,29 +12,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_SWING_CALLBACK_INTERFACE_H -#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_SWING_CALLBACK_INTERFACE_H -#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED -#include "iremote_broker.h" +#ifndef NOTIFICATION_SWING_CALLBACK_SERVICE_H +#define NOTIFICATION_SWING_CALLBACK_SERVICE_H +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED +#include "swing_call_back_stub.h" namespace OHOS { namespace Notification { -/** - * @class ISwingCallBack - */ -class ISwingCallBack : public OHOS::IRemoteBroker { +class SwingCallBackService : public SwingCallBackStub, + public std::enable_shared_from_this{ public: - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Notification.SwingCallBack"); + SwingCallBackService(std::function swingCallback); + SwingCallBackService(); + ~SwingCallBackService() = default; + + ErrCode OnUpdateStatus(bool isEnable, int32_t triggerMode, int32_t& funcResult) override; - /** - * OnUpdateStatus - * - * @param isEnable, triggerMode param. - * @return Returns update status result. - */ - virtual int32_t OnUpdateStatus(bool isEnable, int triggerMode) = 0; +private: + std::function swingCallback_; }; -} // namespace Notification -} // namespace OHOS -#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_SWING_CALLBACK_INTERFACE_H -#endif \ No newline at end of file +} // namespace Notification +} // namespace OHOS +#endif // NOTIFICATION_SMART_REMINDER_SUPPORTED +#endif // NOTIFICATION_SWING_CALLBACK_SERVICE_H \ No newline at end of file diff --git a/frameworks/core/include/swing_callback_stub.h b/frameworks/core/include/swing_callback_stub.h deleted file mode 100644 index a67b1c85d..000000000 --- a/frameworks/core/include/swing_callback_stub.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2024 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 BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_SWING_CALLBACK_STUB_H -#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_SWING_CALLBACK_STUB_H -#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED - -#include -#include - -#include "distributed_notification_service_ipc_interface_code.h" -#include "swing_callback_interface.h" -#include "swing_callback_stub.h" - -namespace OHOS { -namespace Notification { -/** - * @class SwingCallBackStub - * SwingCallBack Stub. - */ -class SwingCallBackStub : public IRemoteStub { -public: - SwingCallBackStub(std::function swingCallback); - SwingCallBackStub(); - virtual ~SwingCallBackStub(); - - /** - * OnUpdateStatus, update status. - * - * @param isEnable enable swing. - * @param triggerMode trigger mode. - * @return Returns true success, false fail. - */ - int32_t OnUpdateStatus(bool isEnable, int triggerMode) override; - - /** - * OnUpdateStatus, update status. - * - * @param isEnable enable swing. - * @param triggerMode trigger mode. - * @return Returns true success, false fail. - */ - int OnRemoteRequest( - uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - std::function swingCallback_; - DISALLOW_COPY_AND_MOVE(SwingCallBackStub); -}; -} // namespace Notification -} // namespace OHOS -#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_SWING_CALLBACK_STUB_H -#endif \ No newline at end of file diff --git a/frameworks/core/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index b41c439b2..62596e422 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -2013,12 +2013,12 @@ ErrCode AnsNotification::RegisterSwingCallback(const std::functionRegisterSwingCallback(swingCallBackStub_->AsObject()); + return proxy->RegisterSwingCallback(swingCallBackService_->AsObject()); } #endif diff --git a/frameworks/core/src/listener/swing_callback_proxy.cpp b/frameworks/core/src/listener/swing_callback_service.cpp similarity index 36% rename from frameworks/core/src/listener/swing_callback_proxy.cpp rename to frameworks/core/src/listener/swing_callback_service.cpp index 74032aedf..ff60f354d 100644 --- a/frameworks/core/src/listener/swing_callback_proxy.cpp +++ b/frameworks/core/src/listener/swing_callback_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * 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 @@ -12,51 +12,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED -#include "swing_callback_proxy.h" +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED +#include "swing_callback_service.h" #include "ans_log_wrapper.h" -#include "event_handler.h" -#include "ipc_types.h" -#include "message_parcel.h" -#include "singleton.h" -#include "ans_inner_errors.h" - namespace OHOS { namespace Notification { -int32_t SwingCallBackProxy::OnUpdateStatus(bool isEnable, int triggerMode) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(SwingCallBackProxy::GetDescriptor())) { - ANS_LOGE("Write interface token failed."); - return false; - } - - if (!data.WriteInt8(static_cast(isEnable))) { - ANS_LOGE("Connect done element error."); - return false; - } - if (!data.WriteInt32(static_cast(triggerMode))) { - ANS_LOGE("Connect done element error."); - return false; - } - - auto remote = Remote(); - if (remote == nullptr) { - ANS_LOGE("Get Remote fail."); - return false; - } - int error = remote->SendRequest(static_cast(NotificationInterfaceCode::ON_UPDATE_STATUS), - data, reply, option); - if (error != NO_ERROR) { - ANS_LOGE("Connect done fail, error: %{public}d", error); - return false; +SwingCallBackService::SwingCallBackService(std::function swingCallback) : swingCallback_(swingCallback) +{} +ErrCode SwingCallBackService::OnUpdateStatus(bool isEnable, int32_t triggerMode, int32_t& funcResult) +{ + if (swingCallback_) { + ANS_LOGI("swingCallback(isEnable: %{public}d, triggerMode: %{public}d)", isEnable, triggerMode); + swingCallback_(isEnable, triggerMode); + return NO_ERROR; } - return reply.ReadInt32(); -} -} + return ERR_UNKNOWN_OBJECT; } -#endif \ No newline at end of file +} // namespace Notification +} // namespace OHOS +#endif // NOTIFICATION_SMART_REMINDER_SUPPORTED \ No newline at end of file diff --git a/frameworks/core/src/listener/swing_callback_stub.cpp b/frameworks/core/src/listener/swing_callback_stub.cpp deleted file mode 100644 index af7bb2cc3..000000000 --- a/frameworks/core/src/listener/swing_callback_stub.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2024 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. - */ -#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED -#include "swing_callback_stub.h" - -#include "ans_log_wrapper.h" -#include "event_handler.h" -#include "ipc_types.h" -#include "message_parcel.h" -#include "singleton.h" -#include "ans_inner_errors.h" - -namespace OHOS { -namespace Notification { -SwingCallBackStub::SwingCallBackStub() {} -SwingCallBackStub::SwingCallBackStub(std::function swingCallback) : swingCallback_(swingCallback) {} -SwingCallBackStub::~SwingCallBackStub() {} -int32_t SwingCallBackStub::OnUpdateStatus(bool isEnable, int triggerMode) -{ - return ERR_OK; -} -int SwingCallBackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - ANS_LOGD("called."); - if (data.ReadInterfaceToken() != GetDescriptor()) { - ANS_LOGE("local descriptor is not equal to remote"); - return ERR_INVALID_STATE; - } - switch (code) { - case static_cast(NotificationInterfaceCode::ON_UPDATE_STATUS): { - bool isEnable = static_cast(data.ReadInt8()); - int triggerMode = static_cast(data.ReadInt32()); - if (swingCallback_) { - ANS_LOGI("swingCallback(isEnable: %{public}d, triggerMode: %{public}d)", isEnable, triggerMode); - swingCallback_(isEnable, triggerMode); - return NO_ERROR; - } - return ERR_UNKNOWN_OBJECT; - } - default: - return ERR_INVALID_STATE; - } -} -} -} -#endif \ No newline at end of file diff --git a/frameworks/core/test/unittest/swing_callback_test/swing_callback_test.cpp b/frameworks/core/test/unittest/swing_callback_test/swing_callback_test.cpp index 3c7b08cd1..6a476305d 100644 --- a/frameworks/core/test/unittest/swing_callback_test/swing_callback_test.cpp +++ b/frameworks/core/test/unittest/swing_callback_test/swing_callback_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-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 @@ -19,8 +19,8 @@ #include "message_option.h" #include "message_parcel.h" #include "parcel.h" -#include "swing_callback_proxy.h" -#include "swing_callback_stub.h" +#include "swing_call_back_proxy.h" +#include "swing_call_back_stub.h" using namespace testing::ext; namespace OHOS { @@ -43,9 +43,9 @@ HWTEST_F(SwingCallBackTest, SwingCallBackProxyTest_00100, Function | SmallTest | { sptr impl; SwingCallBackProxy swingCallBackProxy(impl); - - int ret = swingCallBackProxy.OnUpdateStatus(true, 0); - EXPECT_EQ(ret, false); + int32_t funcResult = -1; + int ret = swingCallBackProxy.OnUpdateStatus(true, 0, funcResult); + EXPECT_EQ(ret, ERR_INVALID_DATA); } /** @@ -60,7 +60,7 @@ HWTEST_F(SwingCallBackTest, SwingCallBackStubTest_00100, Function | SmallTest | MessageParcel reply; MessageOption option = {MessageOption::TF_SYNC}; - SwingCallBackStub swingCallBackStub = SwingCallBackStub( + SwingCallBackStub swingCallBackStub = SwingCallBackService( std::bind(&SwingCallBackTest::OnUpdateStatus, this, std::placeholders::_1, std::placeholders::_2)); data.WriteInterfaceToken(swingCallBackStub.GetDescriptor()); int ret = swingCallBackStub.OnRemoteRequest(code, data, reply, option); diff --git a/services/ans/include/reminder_swing_decision_center.h b/services/ans/include/reminder_swing_decision_center.h index acd468324..ad62cab73 100644 --- a/services/ans/include/reminder_swing_decision_center.h +++ b/services/ans/include/reminder_swing_decision_center.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-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 @@ -28,7 +28,7 @@ #include "common_event_support.h" #include "nlohmann/json.hpp" #include "notification_config_parse.h" -#include "swing_callback_proxy.h" +#include "swing_call_back_proxy.h" #include "system_event_subscriber.h" namespace OHOS { diff --git a/services/ans/src/reminder_swing_decision_center.cpp b/services/ans/src/reminder_swing_decision_center.cpp index a7c446d2b..2355e344d 100644 --- a/services/ans/src/reminder_swing_decision_center.cpp +++ b/services/ans/src/reminder_swing_decision_center.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -131,7 +131,8 @@ void ReminderSwingDecisionCenter::DisableSwingStatus() return; } ANS_LOGD("DisableSwingStatus"); - swingCallback_->OnUpdateStatus(false, NONE_UNLOCK_TRIGGER); + int32_t funcResult = -1; + swingCallback_->OnUpdateStatus(false, NONE_UNLOCK_TRIGGER, funcResult); } void ReminderSwingDecisionCenter::SwingExecuteDecision(bool isScreenUnlockTrigger) @@ -167,11 +168,12 @@ void ReminderSwingDecisionCenter::SwingExecuteDecision(bool isScreenUnlockTrigge } int triggerMode = isScreenUnlockTrigger ? UNLOCK_TRIGGER : NONE_UNLOCK_TRIGGER; + int32_t funcResult = -1; bool isSwingCrossDeviceStatusStatified = IsStatifySwingCrossDeviceStatus(); if (isScreenUnlock_ && isSwingCrossDeviceStatusStatified) { if (!isSwingExecuting_) { isSwingExecuting_ = true; - swingCallback_->OnUpdateStatus(true, triggerMode); + swingCallback_->OnUpdateStatus(true, triggerMode, funcResult); ANS_LOGI("swing OnUpdateStatus enable triggerMode %{public}d", triggerMode); } else { ANS_LOGD("isSwingExecuting_ %{public}d", isSwingExecuting_); @@ -179,7 +181,7 @@ void ReminderSwingDecisionCenter::SwingExecuteDecision(bool isScreenUnlockTrigge } else { if (isSwingExecuting_) { isSwingExecuting_ = false; - swingCallback_->OnUpdateStatus(false, triggerMode); + swingCallback_->OnUpdateStatus(false, triggerMode, funcResult); ANS_LOGI("swing OnUpdateStatus disable triggerMode %{public}d", triggerMode); } else { ANS_LOGD("isScreenUnlock_ %{public}d isSwingCrossDeviceStatusStatified %{public}d ", diff --git a/services/ans/test/unittest/mock/include/mock_swing_callback_stub.h b/services/ans/test/unittest/mock/include/mock_swing_callback_stub.h index 7bfd08533..312b508e2 100644 --- a/services/ans/test/unittest/mock/include/mock_swing_callback_stub.h +++ b/services/ans/test/unittest/mock/include/mock_swing_callback_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-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 @@ -19,14 +19,14 @@ #include #include -#include "swing_callback_interface.h" +#include "iswing_call_back.h" namespace OHOS { class MockSwingCallBackStub : public IRemoteStub { public: MockSwingCallBackStub(); virtual ~MockSwingCallBackStub(); - virtual int32_t OnUpdateStatus(bool isEnable, int triggerMode) override; + virtual ErrCode OnUpdateStatus(bool isEnable, int32_t triggerMode, int32_t& funcResult) override; }; } // namespace OHOS #endif // ANS_MOCK_SWING_CALL_BACK_STUB_H diff --git a/services/ans/test/unittest/mock/mock_swing_callback_stub.cpp b/services/ans/test/unittest/mock/mock_swing_callback_stub.cpp index ccd224675..82bb8e11c 100644 --- a/services/ans/test/unittest/mock/mock_swing_callback_stub.cpp +++ b/services/ans/test/unittest/mock/mock_swing_callback_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-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 @@ -18,8 +18,9 @@ namespace OHOS { MockSwingCallBackStub::MockSwingCallBackStub() {} MockSwingCallBackStub::~MockSwingCallBackStub() {} -int32_t MockSwingCallBackStub::OnUpdateStatus(bool isEnable, int triggerMode) +ErrCode MockSwingCallBackStub::OnUpdateStatus(bool isEnable, int32_t triggerMode, int32_t& funcResult) { + funcResult = 0; return 0; } } // namespace OHOS -- Gitee