From cad95c72a6d6169798d392cfb06a6a5747c0b8fe Mon Sep 17 00:00:00 2001 From: dongqingran Date: Sat, 14 Dec 2024 14:10:12 +0800 Subject: [PATCH] refactor slot manager Signed-off-by: dongqingran --- frameworks/ans/BUILD.gn | 2 - frameworks/core/test/unittest/BUILD.gn | 1 - .../unittest/ans_manager_stub_test/BUILD.gn | 48 - services/ans/BUILD.gn | 13 +- .../include/advanced_notification_service.h | 19 +- .../ans/include/slot_manager/slot_manager.h | 96 + services/ans/src/ans_manager_stub.cpp | 2498 +++++++++++++++++ services/ans/src/ans_manager_stub_invalid.cpp | 633 +++++ services/ans/src/slot_manager/AddSlots.cpp | 110 + .../setNotificationEnableSlot.cpp | 205 ++ .../ans/src/slot_manager/slot_manager.cpp | 117 + services/ans/test/unittest/BUILD.gn | 1 + .../test/unittest}/ans_manager_stub_test.cpp | 0 .../ansmanagerstubannexthree_fuzzer/BUILD.gn | 1 + .../ansmanagerstubannextwo_fuzzer/BUILD.gn | 1 + tools/test/unittest/dump/BUILD.gn | 1 + 16 files changed, 3686 insertions(+), 60 deletions(-) delete mode 100644 frameworks/core/test/unittest/ans_manager_stub_test/BUILD.gn create mode 100644 services/ans/include/slot_manager/slot_manager.h create mode 100644 services/ans/src/ans_manager_stub.cpp create mode 100644 services/ans/src/ans_manager_stub_invalid.cpp create mode 100644 services/ans/src/slot_manager/AddSlots.cpp create mode 100644 services/ans/src/slot_manager/setNotificationEnableSlot.cpp create mode 100644 services/ans/src/slot_manager/slot_manager.cpp rename {frameworks/core/test/unittest/ans_manager_stub_test => services/ans/test/unittest}/ans_manager_stub_test.cpp (100%) diff --git a/frameworks/ans/BUILD.gn b/frameworks/ans/BUILD.gn index f194290d4..455653a4d 100644 --- a/frameworks/ans/BUILD.gn +++ b/frameworks/ans/BUILD.gn @@ -66,8 +66,6 @@ ohos_shared_library("ans_innerkits") { "${core_path}/src/manager/ans_manager_proxy_slot.cpp", "${core_path}/src/manager/ans_manager_proxy_subscribe.cpp", "${core_path}/src/manager/ans_manager_proxy_utils.cpp", - "${core_path}/src/manager/ans_manager_stub.cpp", - "${core_path}/src/manager/ans_manager_stub_invalid.cpp", "${frameworks_module_ans_path}/src/ans_dialog_host_client.cpp", "${frameworks_module_ans_path}/src/badge_number_callback_data.cpp", "${frameworks_module_ans_path}/src/enabled_notification_callback_data.cpp", diff --git a/frameworks/core/test/unittest/BUILD.gn b/frameworks/core/test/unittest/BUILD.gn index 94550b16b..f8305fd0d 100644 --- a/frameworks/core/test/unittest/BUILD.gn +++ b/frameworks/core/test/unittest/BUILD.gn @@ -18,7 +18,6 @@ group("unittest") { deps += [ "ans_image_util_test:unittest", "ans_manager_proxy_test:unittest", - "ans_manager_stub_test:unittest", "ans_notification_annex_test:unittest", "ans_notification_branch_test:unittest", "ans_notification_test:unittest", diff --git a/frameworks/core/test/unittest/ans_manager_stub_test/BUILD.gn b/frameworks/core/test/unittest/ans_manager_stub_test/BUILD.gn deleted file mode 100644 index 5f739a86c..000000000 --- a/frameworks/core/test/unittest/ans_manager_stub_test/BUILD.gn +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright (c) 2022-2023 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. - -import("//base/notification/distributed_notification_service/notification.gni") -import("//build/ohos.gni") -import("//build/test.gni") - -module_output_path = "${component_name}/unittest" - -ohos_unittest("ans_manager_stub_test") { - module_out_path = module_output_path - include_dirs = [ "${core_path}/include" ] - - sources = [ "ans_manager_stub_test.cpp" ] - - deps = [ "${frameworks_module_ans_path}:ans_innerkits" ] - - external_deps = [ - "ability_base:want", - "ability_base:zuri", - "ability_runtime:wantagent_innerkits", - "c_utils:utils", - "hilog:libhilog", - "image_framework:image_native", - "ipc:ipc_single", - "relational_store:native_rdb", - ] - - subsystem_name = "${subsystem_name}" - part_name = "${component_name}" -} - -group("unittest") { - testonly = true - deps = [] - - deps += [ ":ans_manager_stub_test" ] -} diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index 4a65f0ce1..96cbd4469 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -47,7 +47,10 @@ ohos_source_set("ans_service_sources") { "-fdata-sections", ] - include_dirs = [ "${services_path}/ans/include" ] + include_dirs = [ + "${services_path}/ans/include", + "${services_path}/ans/include/slot_manager", + ] defines = [] @@ -71,6 +74,8 @@ ohos_source_set("ans_service_sources") { "src/advanced_notification_slot_service.cpp", "src/advanced_notification_subscriber_service.cpp", "src/advanced_notification_utils.cpp", + "src/ans_manager_stub.cpp", + "src/ans_manager_stub_invalid.cpp", "src/bundle_manager_helper.cpp", "src/clone/notification_clone_bundle_info.cpp", "src/clone/notification_clone_bundle_service.cpp", @@ -107,6 +112,12 @@ ohos_source_set("ans_service_sources") { "src/telephony_extension_wrapper.cpp", ] + sources += [ + "src/slot_manager/AddSlots.cpp", + "src/slot_manager/setNotificationEnableSlot.cpp", + "src/slot_manager/slot_manager.cpp", + ] + deps = [ "${frameworks_module_ans_path}:ans_innerkits", "${frameworks_module_reminder_path}:reminder_innerkits", diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 061ba3b3e..904ca7b93 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1106,6 +1106,9 @@ public: void UpdateCloneBundleInfo(const NotificationCloneBundleInfo cloneBundleInfo); void TryStartReminderAgentService(); + + static sptr GenerateBundleOption(); + static sptr GenerateValidBundleOption(const sptr &bundleOption); protected: /** * @brief Query whether there is a agent relationship between the two apps. @@ -1116,6 +1119,13 @@ protected: */ bool IsAgentRelationship(const std::string &agentBundleName, const std::string &sourceBundleName); +public: + bool CheckApiCompatibility(const sptr &bundleOption); + ErrCode SetDefaultNotificationEnabled( + const sptr &bundleOption, bool enabled); + ErrCode RemoveNotificationBySlot(const sptr &bundleOption, + const sptr &slot, const int reason); + bool PublishSlotChangeCommonEvent(const sptr &bundleOption); private: struct RecentInfo { std::list> list; @@ -1176,12 +1186,8 @@ private: const std::shared_ptr &first, const std::shared_ptr &second); ErrCode FlowControl(const std::shared_ptr &record, const int32_t callingUid); ErrCode PublishInNotificationList(const std::shared_ptr &record); - ErrCode RemoveNotificationBySlot(const sptr &bundleOption, - const sptr &slot, const int reason); sptr GenerateSortingMap(); - static sptr GenerateBundleOption(); - static sptr GenerateValidBundleOption(const sptr &bundleOption); std::string TimeToString(int64_t time); int64_t GetNowSysTime(); @@ -1202,7 +1208,7 @@ private: ErrCode PrepareContinuousTaskNotificationRequest(const sptr &request, const int32_t &uid); void TriggerRemoveWantAgent(const sptr &request); - bool CheckApiCompatibility(const sptr &bundleOption); + ErrCode IsAllowedNotifySelf(const sptr &bundleOption, bool &allowed); ErrCode SetNotificationRemindType(sptr notification, bool isLocal); @@ -1232,7 +1238,6 @@ private: ErrCode GetHasPoppedDialog(const sptr bundleOption, bool &hasPopped); static ErrCode GetAppTargetBundle(const sptr &bundleOption, sptr &targetBundle); - bool PublishSlotChangeCommonEvent(const sptr &bundleOption); void ReportInfoToResourceSchedule(const int32_t userId, const std::string &bundleName); int Dump(int fd, const std::vector &args) override; void GetDumpInfo(const std::vector &args, std::string &result); @@ -1266,8 +1271,6 @@ private: void SendNotificationsOnCanceled(std::vector> ¬ifications, const sptr ¬ificationMap, int32_t deleteReason); void SetAgentNotification(sptr& notificationRequest, std::string& bundleName); - ErrCode SetDefaultNotificationEnabled( - const sptr &bundleOption, bool enabled); static bool GetBundleInfoByNotificationBundleOption( const sptr &bundleOption, AppExecFwk::BundleInfo &bundleInfo); diff --git a/services/ans/include/slot_manager/slot_manager.h b/services/ans/include/slot_manager/slot_manager.h new file mode 100644 index 000000000..bd82903bc --- /dev/null +++ b/services/ans/include/slot_manager/slot_manager.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2021-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_ANS_SERVICES_ANS_INCLUDE_SLOT_MANAGER_H +#define BASE_NOTIFICATION_ANS_SERVICES_ANS_INCLUDE_SLOT_MANAGER_H + +#include +#include + +#include "ans_manager_interface.h" +#include "ans_subscriber_local_live_view_interface.h" +#include "distributed_notification_service_ipc_interface_code.h" +#include "iremote_stub.h" +#include "singleton.h" + +namespace OHOS { +namespace Notification { +class SlotManager { +public: + DECLARE_DELAYED_SINGLETON(SlotManager); +public: + static const uint32_t DEFAULT_SLOT_FLAGS = 59; // 0b111011 + /** + * @brief Handle remote request. + * + * @param data Indicates the input parcel. + * @param reply Indicates the output parcel. + * @param option Indicates the message option. + * @return Returns ERR_OK on success, others on failure. + */ + int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); +private: + ErrCode AddSlots(MessageParcel &data, MessageParcel &reply); + ErrCode AddSlotsSyncQue(const std::vector> &slots, sptr bundleOption); + ErrCode AddSlotsInner(const std::vector> &slots, sptr bundleOption); + + ErrCode SetEnabledForBundleSlot(MessageParcel &data, MessageParcel &reply); + ErrCode SetEnabledForBundleSlotSyncQue( + const sptr &bundleOption, + const sptr &bundle, + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl); + ErrCode SetEnabledForBundleSlotInner( + const sptr &bundleOption, + const sptr &bundle, + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl); +private: + int32_t CheckInterfacePermission(uint32_t code); + void GenerateSlotReminderMode(const sptr &slot, const sptr &bundle, + bool isSpecifiedSlot = false, uint32_t defaultSlotFlags = DEFAULT_SLOT_FLAGS); + void SendEnableNotificationSlotHiSysEvent( + const sptr &bundleOption, const NotificationConstant::SlotType &slotType, + bool enabled, ErrCode errCode); + ErrCode AddSlotThenPublishEvent( + const sptr &slot, + const sptr &bundle, + bool enabled, bool isForceControl); + + template + bool ReadParcelableVector(std::vector> &parcelableInfos, MessageParcel &data) + { + int32_t infoSize = 0; + if (!data.ReadInt32(infoSize)) { + ANS_LOGE("Failed to read Parcelable size."); + return false; + } + + parcelableInfos.clear(); + infoSize = (infoSize < MAX_PARCELABLE_VECTOR_NUM) ? infoSize : MAX_PARCELABLE_VECTOR_NUM; + for (int32_t index = 0; index < infoSize; index++) { + sptr info = data.ReadStrongParcelable(); + if (info == nullptr) { + ANS_LOGE("Failed to read Parcelable infos."); + return false; + } + parcelableInfos.emplace_back(info); + } + + return true; + } +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_ANS_SERVICES_ANS_INCLUDE_SLOT_MANAGER_H diff --git a/services/ans/src/ans_manager_stub.cpp b/services/ans/src/ans_manager_stub.cpp new file mode 100644 index 000000000..352dd0dcc --- /dev/null +++ b/services/ans/src/ans_manager_stub.cpp @@ -0,0 +1,2498 @@ +/* + * Copyright (c) 2021-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. + */ + +#include "ans_manager_stub.h" +#include "ans_const_define.h" +#include "ans_inner_errors.h" +#include "ans_log_wrapper.h" +#include "ans_subscriber_local_live_view_interface.h" +#include "message_option.h" +#include "message_parcel.h" +#include "notification_bundle_option.h" +#include "notification_button_option.h" +#include "parcel.h" +#include "reminder_request_alarm.h" +#include "reminder_request_calendar.h" +#include "reminder_request_timer.h" +#include "slot_manager.h" + +namespace OHOS { +namespace Notification { +AnsManagerStub::AnsManagerStub() {} + +AnsManagerStub::~AnsManagerStub() {} + +int32_t AnsManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &flags) +{ + std::u16string descriptor = AnsManagerStub::GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (descriptor != remoteDescriptor) { + ANS_LOGE("[OnRemoteRequest] fail: invalid interface token!"); + return OBJECT_NULL; + } + ErrCode result = NO_ERROR; + switch (code) { + case static_cast(NotificationInterfaceCode::PUBLISH_NOTIFICATION): { + result = HandlePublish(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::PUBLISH_NOTIFICATION_INDIRECTPROXY): { + result = HandlePublishNotificationForIndirectProxy(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::CANCEL_NOTIFICATION): { + result = HandleCancel(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::CANCEL_ALL_NOTIFICATIONS): { + result = HandleCancelAll(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::CANCEL_AS_BUNDLE_OPTION): { + result = HandleCancelAsBundleOption(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::CANCEL_AS_BUNDLE_AND_USER): { + result = HandleCancelAsBundleAndUser(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::CANCEL_AS_BUNDLE): { + result = HandleCancelAsBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::ADD_SLOT_BY_TYPE): { + result = HandleAddSlotByType(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::ADD_SLOTS): + case static_cast(NotificationInterfaceCode::SET_ENABLED_FOR_BUNDLE_SLOT): { + result = DelayedSingleton::GetInstance()->OnRemoteRequest(code, data, reply); + break; + } + case static_cast(NotificationInterfaceCode::REMOVE_SLOT_BY_TYPE): { + result = HandleRemoveSlotByType(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::REMOVE_ALL_SLOTS): { + result = HandleRemoveAllSlots(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_SLOT_BY_TYPE): { + result = HandleGetSlotByType(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_SLOTS): { + result = HandleGetSlots(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_SLOT_NUM_AS_BUNDLE): { + result = HandleGetSlotNumAsBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_ACTIVE_NOTIFICATIONS): { + result = HandleGetActiveNotifications(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_ACTIVE_NOTIFICATION_NUMS): { + result = HandleGetActiveNotificationNums(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_ALL_ACTIVE_NOTIFICATIONS): { + result = HandleGetAllActiveNotifications(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_SPECIAL_ACTIVE_NOTIFICATIONS): { + result = HandleGetSpecialActiveNotifications(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_ACTIVE_NOTIFICATION_BY_FILTER): { + result = HandleGetActiveNotificationByFilter(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::CAN_PUBLISH_AS_BUNDLE): { + result = HandleCanPublishAsBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::PUBLISH_AS_BUNDLE): { + result = HandlePublishAsBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_NOTIFICATION_BADGE_NUM): { + result = HandleSetNotificationBadgeNum(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_BUNDLE_IMPORTANCE): { + result = HandleGetBundleImportance(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::IS_NOTIFICATION_POLICY_ACCESS_GRANTED): { + result = HandleIsNotificationPolicyAccessGranted(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::REMOVE_NOTIFICATION): { + result = HandleRemoveNotification(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::REMOVE_ALL_NOTIFICATIONS): { + result = HandleRemoveAllNotifications(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::REMOVE_NOTIFICATIONS_BY_KEYS): { + result = HandleRemoveNotifications(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::DELETE_NOTIFICATION): { + result = HandleDelete(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::DELETE_NOTIFICATION_BY_BUNDLE): { + result = HandleDeleteByBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::DELETE_ALL_NOTIFICATIONS): { + result = HandleDeleteAll(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_SLOTS_BY_BUNDLE): { + result = HandleGetSlotsByBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::UPDATE_SLOTS): { + result = HandleUpdateSlots(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::REQUEST_ENABLE_NOTIFICATION): { + result = HandleRequestEnableNotification(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_BUNDLE): { + result = HandleSetNotificationsEnabledForBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_ALL_BUNDLE): { + result = HandleSetNotificationsEnabledForAllBundles(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_SPECIAL_BUNDLE): { + result = HandleSetNotificationsEnabledForSpecialBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_SHOW_BADGE_ENABLED_FOR_BUNDLE): { + result = HandleSetShowBadgeEnabledForBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_SHOW_BADGE_ENABLED_FOR_BUNDLE): { + result = HandleGetShowBadgeEnabledForBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_SHOW_BADGE_ENABLED): { + result = HandleGetShowBadgeEnabled(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SUBSCRIBE_NOTIFICATION): { + result = HandleSubscribe(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::UNSUBSCRIBE_NOTIFICATION): { + result = HandleUnsubscribe(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::IS_ALLOWED_NOTIFY): { + result = HandleIsAllowedNotify(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::IS_ALLOWED_NOTIFY_SELF): { + result = HandleIsAllowedNotifySelf(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::CAN_POP_ENABLE_NOTIFICATION_DIALOG): { + result = HandleCanPopEnableNotificationDialog(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::REMOVE_ENABLE_NOTIFICATION_DIALOG): { + result = HandleRemoveEnableNotificationDialog(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::IS_SPECIAL_BUNDLE_ALLOWED_NOTIFY): { + result = HandleIsSpecialBundleAllowedNotify(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_DO_NOT_DISTURB_DATE): { + result = HandleSetDoNotDisturbDate(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_DO_NOT_DISTURB_DATE): { + result = HandleGetDoNotDisturbDate(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::DOES_SUPPORT_DO_NOT_DISTURB_MODE): { + result = HandleDoesSupportDoNotDisturbMode(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::IS_NEED_SILENT_IN_DO_NOT_DISTURB_MODE): { + result = HandleIsNeedSilentInDoNotDisturbMode(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::CANCEL_GROUP): { + result = HandleCancelGroup(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::REMOVE_GROUP_BY_BUNDLE): { + result = HandleRemoveGroupByBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::IS_DISTRIBUTED_ENABLED): { + result = HandleIsDistributedEnabled(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::ENABLE_DISTRIBUTED): { + result = HandleEnableDistributed(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::ENABLE_DISTRIBUTED_BY_BUNDLE): { + result = HandleEnableDistributedByBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::ENABLE_DISTRIBUTED_SELF): { + result = HandleEnableDistributedSelf(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::IS_DISTRIBUTED_ENABLED_BY_BUNDLE): { + result = HandleIsDistributedEnableByBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_DEVICE_REMIND_TYPE): { + result = HandleGetDeviceRemindType(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SHELL_DUMP): { + result = HandleShellDump(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::PUBLISH_CONTINUOUS_TASK_NOTIFICATION): { + result = HandlePublishContinuousTaskNotification(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::CANCEL_CONTINUOUS_TASK_NOTIFICATION): { + result = HandleCancelContinuousTaskNotification(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::IS_SUPPORT_TEMPLATE): { + result = HandleIsSupportTemplate(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::IS_SPECIAL_USER_ALLOWED_NOTIFY): { + result = HandleIsSpecialUserAllowedNotifyByUser(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_BY_USER): { + result = HandleSetNotificationsEnabledByUser(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::DELETE_ALL_NOTIFICATIONS_BY_USER): { + result = HandleDeleteAllByUser(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_DO_NOT_DISTURB_DATE_BY_USER): { + result = HandleSetDoNotDisturbDateByUser(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_DO_NOT_DISTURB_DATE_BY_USER): { + result = HandleGetDoNotDisturbDateByUser(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_ENABLED_FOR_BUNDLE_SLOT): { + result = HandleGetEnabledForBundleSlot(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_ENABLED_FOR_BUNDLE_SLOT_SELF): { + result = HandleGetEnabledForBundleSlotSelf(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_DISTRIBUTED_ENABLED_BY_BUNDLE): { + result = HandleSetDistributedEnabledByBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_DISTRIBUTED_ENABLED_BY_BUNDLE): { + result = HandleIsDistributedEnabledByBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_SMART_REMINDER_ENABLED): { + result = HandleSetSmartReminderEnabled(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_SMART_REMINDER_ENABLED): { + result = HandleIsSmartReminderEnabled(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_SYNC_NOTIFICATION_ENABLED_WITHOUT_APP): { + result = HandleDistributedSetEnabledWithoutApp(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_SYNC_NOTIFICATION_ENABLED_WITHOUT_APP): { + result = HandleDistributedGetEnabledWithoutApp(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_BADGE_NUMBER): { + result = HandleSetBadgeNumber(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_BADGE_NUMBER_BY_BUNDLE): { + result = HandleSetBadgeNumberByBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_ALL_NOTIFICATION_ENABLE_STATUS): { + result = HandleGetAllNotificationEnableStatus(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::REGISTER_PUSH_CALLBACK): { + result = HandleRegisterPushCallback(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::UNREGISTER_PUSH_CALLBACK): { + result = HandleUnregisterPushCallback(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SUBSCRIBE_LOCAL_LIVE_VIEW_NOTIFICATION): { + result = HandleSubscribeLocalLiveView(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::TRIGGER_LOCAL_LIVE_VIEW_NOTIFICATION): { + result = HandleTriggerLocalLiveView(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SUBSCRIBE_NOTIFICATION_SELF): { + result = HandleSubscribeSelf(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_SLOTFLAGS_BY_BUNDLE): { + result = HandleSetSlotFlagsAsBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_SLOTFLAGS_BY_BUNDLE): { + result = HandleGetSlotFlagsAsBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_NOTIFICATION_AGENT_RELATIONSHIP): { + result = HandleSetAdditionConfig(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::CANCEL_AS_BUNDLE_WITH_AGENT): { + result = HandleCancelAsBundleWithAgent(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::GET_SLOT_BY_BUNDLE): { + result = HandleGetSlotByBundle(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::ADD_DO_NOTDISTURB_PROFILES): { + result = HandleAddDoNotDisturbProfiles(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::REMOVE_DO_NOT_DISTURB_PROFILES): { + result = HandleRemoveDoNotDisturbProfiles(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_TARGET_DEVICE_STATUS): { + result = HandleSetTargetDeviceStatus(data, reply); + break; + } +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED + case static_cast(NotificationInterfaceCode::REGISTER_SWING_CALLBACK): { + result = HandleRegisterSwingCallback(data, reply); + break; + } +#endif + case static_cast(NotificationInterfaceCode::GET_DONOTDISTURB_PROFILE): { + result = HandleGetDoNotDisturbProfile(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::UPDATE_NOTIFICATION_TIMER): { + result = HandleUpdateNotificationTimerByUid(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::ALLOW_USE_REMINDER): { + result = HandleAllowUseReminder(data, reply); + break; + } + default: { + ANS_LOGE("[OnRemoteRequest] fail: unknown code!"); + return IPCObjectStub::OnRemoteRequest(code, data, reply, flags); + } + } + if (SUCCEEDED(result)) { + return NO_ERROR; + } + + ANS_LOGE("[OnRemoteRequest] fail: Failed to call interface %{public}u, err:%{public}d", code, result); + return result; +} + +ErrCode AnsManagerStub::HandlePublish(MessageParcel &data, MessageParcel &reply) +{ + std::string label; + if (!data.ReadString(label)) { + ANS_LOGE("[HandlePublish] fail: read label failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr notification = data.ReadParcelable(); + if (!notification) { + ANS_LOGE("[HandlePublish] fail: notification ReadParcelable failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = Publish(label, notification); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandlePublish] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandlePublishNotificationForIndirectProxy(MessageParcel &data, MessageParcel &reply) +{ + sptr notification = data.ReadParcelable(); + if (!notification) { + ANS_LOGE("[HandlePublishNotificationForIndirectProxy] fail: notification ReadParcelable failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = PublishNotificationForIndirectProxy(notification); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandlePublishNotificationForIndirectProxy] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleCancel(MessageParcel &data, MessageParcel &reply) +{ + int32_t notificationId = 0; + if (!data.ReadInt32(notificationId)) { + ANS_LOGE("[HandleCancel] fail: read notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::string label; + if (!data.ReadString(label)) { + ANS_LOGE("[HandleCancel] fail: read label failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::string appInstanceKey; + if (!data.ReadString(appInstanceKey)) { + ANS_LOGE("[HandleCancel] fail: read InstanceKey failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = Cancel(notificationId, label, appInstanceKey); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleCancel] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleCancelAll(MessageParcel &data, MessageParcel &reply) +{ + std::string appInstanceKey; + if (!data.ReadString(appInstanceKey)) { + ANS_LOGE("[HandleCancelAll] fail: read instanceKey failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = CancelAll(appInstanceKey); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleCancelAll] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleCancelAsBundleOption(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleCancelAsBundle] fail: read BundleOption failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + int32_t notificationId = 0; + if (!data.ReadInt32(notificationId)) { + ANS_LOGE("[HandleCancelAsBundle] fail: read notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + ErrCode result = CancelAsBundle(bundleOption, notificationId); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleCancelAsBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleCancelAsBundle(MessageParcel &data, MessageParcel &reply) +{ + int32_t notificationId = 0; + if (!data.ReadInt32(notificationId)) { + ANS_LOGE("[HandleCancelAsBundle] fail: read notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::string representativeBundle; + if (!data.ReadString(representativeBundle)) { + ANS_LOGE("[HandleCancelAsBundle] fail: read representativeBundle failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t userId = 0; + if (!data.ReadInt32(userId)) { + ANS_LOGE("[HandleCancelAsBundle] fail: read userId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = CancelAsBundle(notificationId, representativeBundle, userId); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleCancelAsBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleCancelAsBundleAndUser(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleCancelAsBundle] fail: read BundleOption failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + int32_t notificationId = 0; + if (!data.ReadInt32(notificationId)) { + ANS_LOGE("[HandleCancelAsBundle] fail: read notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t userId = 0; + if (!data.ReadInt32(userId)) { + ANS_LOGE("[HandleCancelAsBundle] fail: read userId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + ErrCode result = CancelAsBundle(bundleOption, notificationId, userId); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleCancelAsBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleAddSlotByType(MessageParcel &data, MessageParcel &reply) +{ + NotificationConstant::SlotType slotType = static_cast(data.ReadInt32()); + ErrCode result = AddSlotByType(slotType); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleAddSlotByType] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleAddSlots(MessageParcel &data, MessageParcel &reply) +{ + std::vector> slots; + if (!ReadParcelableVector(slots, data)) { + ANS_LOGE("[HandleAddSlots] fail: read slotsSize failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + ErrCode result = AddSlots(slots); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleAddSlots] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleRemoveSlotByType(MessageParcel &data, MessageParcel &reply) +{ + NotificationConstant::SlotType slotType = static_cast(data.ReadInt32()); + + ErrCode result = RemoveSlotByType(slotType); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleRemoveSlotByType] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleRemoveAllSlots(MessageParcel &data, MessageParcel &reply) +{ + ErrCode result = RemoveAllSlots(); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleRemoveAllSlots] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetSlots(MessageParcel &data, MessageParcel &reply) +{ + std::vector> slots; + ErrCode result = GetSlots(slots); + if (!WriteParcelableVector(slots, reply, result)) { + ANS_LOGE("[HandleGetSlots] fail: write slots failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetSlotByType(MessageParcel &data, MessageParcel &reply) +{ + NotificationConstant::SlotType slotType = static_cast(data.ReadInt32()); + + sptr slot = nullptr; + ErrCode result = GetSlotByType(slotType, slot); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetSlotByType] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteParcelable(slot)) { + ANS_LOGE("[HandleGetSlotByType] fail: write slot failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetSlotNumAsBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleGetSlotNumAsBundle] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + uint64_t num = 0; + ErrCode result = GetSlotNumAsBundle(bundleOption, num); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetSlotNumAsBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteUint64(num)) { + ANS_LOGE("[HandleGetSlotNumAsBundle] fail: write enabled failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetSlotFlagsAsBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleSetSlotFlagsAsBundle] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t slotFlags = 0; + if (!data.ReadInt32(slotFlags)) { + ANS_LOGE("[HandleSetSlotFlagsAsBundle] fail: read notification failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetSlotFlagsAsBundle(bundleOption, slotFlags); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetSlotFlagsAsBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetSlotFlagsAsBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleGetSlotFlagsAsBundle] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + uint32_t slotFlags = 0; + ErrCode result = GetSlotFlagsAsBundle(bundleOption, slotFlags); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetSlotFlagsAsBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteUint32(slotFlags)) { + ANS_LOGE("[HandleGetSlotFlagsAsBundle] fail: write enabled failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetActiveNotifications(MessageParcel &data, MessageParcel &reply) +{ + std::string appInstanceKey; + if (!data.ReadString(appInstanceKey)) { + ANS_LOGE("[HandleGetActiveNotifications] fail: read instanceKey failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + std::vector> notifications; + ErrCode result = GetActiveNotifications(notifications, appInstanceKey); + if (!WriteParcelableVector(notifications, reply, result)) { + ANS_LOGE("[HandleGetActiveNotifications] fail: write notifications failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetActiveNotificationNums(MessageParcel &data, MessageParcel &reply) +{ + uint64_t num = 0; + ErrCode result = GetActiveNotificationNums(num); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetActiveNotificationNums] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteUint64(num)) { + ANS_LOGE("[HandleGetActiveNotificationNums] fail: write num failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetAllActiveNotifications(MessageParcel &data, MessageParcel &reply) +{ + std::vector> notifications; + ErrCode result = GetAllActiveNotifications(notifications); + + if (!reply.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { + return ERR_ANS_PARCELABLE_FAILED; + } + if (!WriteParcelableVector(notifications, reply, result)) { + ANS_LOGE("[HandleGetAllActiveNotifications] fail: write notifications failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetSpecialActiveNotifications(MessageParcel &data, MessageParcel &reply) +{ + std::vector key; + if (!data.ReadStringVector(&key)) { + ANS_LOGE("[HandleGetSpecialActiveNotifications] fail: read key failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::vector> notifications; + ErrCode result = GetSpecialActiveNotifications(key, notifications); + if (!WriteParcelableVector(notifications, reply, result)) { + ANS_LOGE("[HandleGetSpecialActiveNotifications] fail: write notifications failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetActiveNotificationByFilter(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: read bundleOption failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t notificationId = 0; + if (!data.ReadInt32(notificationId)) { + ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: read notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::string label; + if (!data.ReadString(label)) { + ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: read label failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::vector extraInfoKeys; + if (!data.ReadStringVector(&extraInfoKeys)) { + ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: read extraInfoKeys failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr request; + ErrCode result = GetActiveNotificationByFilter(bundleOption, notificationId, label, extraInfoKeys, request); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteParcelable(request)) { + ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: get extra info by filter failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + +ErrCode AnsManagerStub::HandleCanPublishAsBundle(MessageParcel &data, MessageParcel &reply) +{ + std::string representativeBundle; + if (!data.ReadString(representativeBundle)) { + ANS_LOGE("[HandleCanPublishAsBundle] fail: read representativeBundle failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool canPublish = false; + ErrCode result = CanPublishAsBundle(representativeBundle, canPublish); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleCanPublishAsBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(canPublish)) { + ANS_LOGE("[HandleCanPublishAsBundle] fail: write canPublish failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandlePublishAsBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr notification = data.ReadParcelable(); + if (!notification) { + ANS_LOGE("[HandlePublishAsBundle] fail: read notification failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::string representativeBundle; + if (!data.ReadString(representativeBundle)) { + ANS_LOGE("[HandlePublishAsBundle] fail: read representativeBundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = PublishAsBundle(notification, representativeBundle); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandlePublishAsBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetNotificationBadgeNum(MessageParcel &data, MessageParcel &reply) +{ + int32_t num = 0; + if (!data.ReadInt32(num)) { + ANS_LOGE("[HandleSetNotificationBadgeNum] fail: read notification failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetNotificationBadgeNum(num); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetNotificationBadgeNum] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetBundleImportance(MessageParcel &data, MessageParcel &reply) +{ + int32_t importance = 0; + ErrCode result = GetBundleImportance(importance); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetBundleImportance] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteInt32(importance)) { + ANS_LOGE("[HandleGetBundleImportance] fail: write importance failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetDoNotDisturbDate(MessageParcel &data, MessageParcel &reply) +{ + sptr date = data.ReadParcelable(); + if (date == nullptr) { + ANS_LOGE("[HandleSetDoNotDisturbDate] fail: read date failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetDoNotDisturbDate(date); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetDoNotDisturbDate] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetDoNotDisturbDate(MessageParcel &data, MessageParcel &reply) +{ + sptr date = nullptr; + + ErrCode result = GetDoNotDisturbDate(date); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetDoNotDisturbDate] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (result == ERR_OK) { + if (!reply.WriteParcelable(date)) { + ANS_LOGE("[HandleSetDoNotDisturbDate] fail: write date failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleDoesSupportDoNotDisturbMode(MessageParcel &data, MessageParcel &reply) +{ + bool support = false; + + ErrCode result = DoesSupportDoNotDisturbMode(support); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleDoesSupportDoNotDisturbMode] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(support)) { + ANS_LOGE("[HandleDoesSupportDoNotDisturbMode] fail: write doesSupport failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleIsNeedSilentInDoNotDisturbMode(MessageParcel &data, MessageParcel &reply) +{ + std::string phoneNumber; + if (!data.ReadString(phoneNumber)) { + ANS_LOGE("[HandleIsNeedSilentInDoNotDisturbMode] fail: read phoneNumber failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t callerType = 0; + if (!data.ReadInt32(callerType)) { + ANS_LOGE("[HandleIsNeedSilentInDoNotDisturbMode] fail: read callerType failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = IsNeedSilentInDoNotDisturbMode(phoneNumber, callerType); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleIsNeedSilentInDoNotDisturbMode] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandlePublishContinuousTaskNotification(MessageParcel &data, MessageParcel &reply) +{ + sptr request = data.ReadParcelable(); + if (!request) { + ANS_LOGE("[HandlePublishContinuousTaskNotification] fail: notification ReadParcelable failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = PublishContinuousTaskNotification(request); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandlePublishContinuousTaskNotification] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleCancelContinuousTaskNotification(MessageParcel &data, MessageParcel &reply) +{ + std::string label; + if (!data.ReadString(label)) { + ANS_LOGE("[HandleCancelContinuousTaskNotification] fail: read label failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t notificationId = 0; + if (!data.ReadInt32(notificationId)) { + ANS_LOGE("[HandleCancelContinuousTaskNotification] fail: read notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = CancelContinuousTaskNotification(label, notificationId); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleCancelContinuousTaskNotification] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleIsNotificationPolicyAccessGranted(MessageParcel &data, MessageParcel &reply) +{ + bool granted = false; + ErrCode result = HasNotificationPolicyAccessPermission(granted); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleIsNotificationPolicyAccessGranted] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(granted)) { + ANS_LOGE("[HandleIsNotificationPolicyAccessGranted] fail: write granted failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleTriggerLocalLiveView(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleTriggerLocalLiveView] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t notificationId = 0; + if (!data.ReadInt32(notificationId)) { + ANS_LOGE("[HandleTriggerLocalLiveView] fail: read notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr buttonOption = data.ReadStrongParcelable(); + if (buttonOption == nullptr) { + ANS_LOGE("[HandleTriggerLocalLiveView] fail: read button failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = TriggerLocalLiveView(bundleOption, notificationId, buttonOption); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleTriggerLocalLiveView] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleRemoveNotification(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleRemoveNotification] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t notificationId = 0; + if (!data.ReadInt32(notificationId)) { + ANS_LOGE("[HandleRemoveNotification] fail: read notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::string label; + if (!data.ReadString(label)) { + ANS_LOGE("[HandleRemoveNotification] fail: read label failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t removeReason = 0; + if (!data.ReadInt32(removeReason)) { + ANS_LOGE("[HandleRemoveNotification] fail: read removeReason failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = RemoveNotification(bundleOption, notificationId, label, removeReason); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleRemoveNotification] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleRemoveAllNotifications(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleRemoveAllNotifications] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = RemoveAllNotifications(bundleOption); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleRemoveAllNotifications] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleRemoveNotifications(MessageParcel &data, MessageParcel &reply) +{ + int32_t keysSize = 0; + if (!data.ReadInt32(keysSize)) { + ANS_LOGE("read keys size failed."); + return false; + } + + std::vector keys; + if (!data.ReadStringVector(&keys)) { + ANS_LOGE("read keys failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t removeReason = 0; + if (!data.ReadInt32(removeReason)) { + ANS_LOGE("read removeReason failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = RemoveNotifications(keys, removeReason); + if (!reply.WriteInt32(result)) { + ANS_LOGE("write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + + +ErrCode AnsManagerStub::HandleDelete(MessageParcel &data, MessageParcel &reply) +{ + std::string key; + if (!data.ReadString(key)) { + ANS_LOGE("[HandleDelete] fail: read key failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t removeReason = 0; + if (!data.ReadInt32(removeReason)) { + ANS_LOGE("[HandleDelete] fail: read removeReason failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = Delete(key, removeReason); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleDelete] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleDeleteByBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleDeleteByBundle] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = DeleteByBundle(bundleOption); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleDeleteByBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleDeleteAll(MessageParcel &data, MessageParcel &reply) +{ + ErrCode result = DeleteAll(); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleDeleteAll] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetSlotsByBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleGetSlotsByBundle] fail: read bundleOption failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::vector> slots; + ErrCode result = GetSlotsByBundle(bundleOption, slots); + if (!WriteParcelableVector(slots, reply, result)) { + ANS_LOGE("[HandleGetSlotsByBundle] fail: write slots failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetSlotByBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleGetSlotByBundle] fail: read bundleOption failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + NotificationConstant::SlotType slotType = static_cast(data.ReadInt32()); + + sptr slot = nullptr; + ErrCode result = GetSlotByBundle(bundleOption, slotType, slot); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetSlotByBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteParcelable(slot)) { + ANS_LOGE("[HandleGetSlotByBundle] fail: write slot failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleUpdateSlots(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleUpdateSlots] fail: read bundleOption failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::vector> slots; + if (!ReadParcelableVector(slots, data)) { + ANS_LOGE("[HandleUpdateSlots] fail: read slots failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = UpdateSlots(bundleOption, slots); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleUpdateSlots] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleRequestEnableNotification(MessageParcel &data, MessageParcel &reply) +{ + ANS_LOGD("enter"); + std::string deviceId; + if (!data.ReadString(deviceId)) { + ANS_LOGE("[HandleRequestEnableNotification] fail: read deviceId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr callback = data.ReadRemoteObject(); + if (callback == nullptr) { + ANS_LOGE("[HandleRequestEnableNotification] fail: read callback failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool hasCallerToken = false; + if (!data.ReadBool(hasCallerToken)) { + ANS_LOGE("fail: read hasCallerToken failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr callerToken = nullptr; + if (hasCallerToken) { + callerToken = data.ReadRemoteObject(); + } + + ErrCode result = RequestEnableNotification(deviceId, iface_cast(callback), callerToken); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleRequestEnableNotification] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetNotificationsEnabledForBundle(MessageParcel &data, MessageParcel &reply) +{ + std::string deviceId; + if (!data.ReadString(deviceId)) { + ANS_LOGE("[HandleSetNotificationsEnabledForBundle] fail: read deviceId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleSetNotificationsEnabledForBundle] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetNotificationsEnabledForBundle(deviceId, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetNotificationsEnabledForBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetNotificationsEnabledForAllBundles(MessageParcel &data, MessageParcel &reply) +{ + std::string deviceId; + if (!data.ReadString(deviceId)) { + ANS_LOGE("[HandleSetNotificationsEnabledForAllBundles] fail: read deviceId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleSetNotificationsEnabledForAllBundles] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetNotificationsEnabledForAllBundles(deviceId, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetNotificationsEnabledForAllBundles] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetNotificationsEnabledForSpecialBundle(MessageParcel &data, MessageParcel &reply) +{ + std::string deviceId; + if (!data.ReadString(deviceId)) { + ANS_LOGE("[HandleSetNotificationsEnabledForSpecialBundle] fail: read deviceId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleSetNotificationsEnabledForSpecialBundle] fail: read bundleOption failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleSetNotificationsEnabledForSpecialBundle] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetNotificationsEnabledForSpecialBundle(deviceId, bundleOption, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetNotificationsEnabledForSpecialBundle] fail: write result failed, ErrCode=%{public}d", + result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetShowBadgeEnabledForBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleSetShowBadgeEnabledForBundle] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleSetShowBadgeEnabledForBundle] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetShowBadgeEnabledForBundle(bundleOption, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetShowBadgeEnabledForBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetShowBadgeEnabledForBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleGetShowBadgeEnabledForBundle] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + ErrCode result = GetShowBadgeEnabledForBundle(bundleOption, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetShowBadgeEnabledForBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(enabled)) { + ANS_LOGE("[HandleGetShowBadgeEnabledForBundle] fail: write enabled failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetShowBadgeEnabled(MessageParcel &data, MessageParcel &reply) +{ + bool enabled = false; + ErrCode result = GetShowBadgeEnabled(enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetShowBadgeEnabled] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(enabled)) { + ANS_LOGE("[HandleGetShowBadgeEnabled] fail: write enabled failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSubscribe(MessageParcel &data, MessageParcel &reply) +{ + sptr subscriber = data.ReadRemoteObject(); + if (subscriber == nullptr) { + ANS_LOGE("[HandleSubscribe] fail: read subscriber failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool subcribeInfo = false; + if (!data.ReadBool(subcribeInfo)) { + ANS_LOGE("[HandleSubscribe] fail: read isSubcribeInfo failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr info = nullptr; + if (subcribeInfo) { + info = data.ReadParcelable(); + if (info == nullptr) { + ANS_LOGE("[HandleSubscribe] fail: read info failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + } + + ErrCode result = Subscribe(iface_cast(subscriber), info); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSubscribe] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSubscribeSelf(MessageParcel &data, MessageParcel &reply) +{ + sptr subscriber = data.ReadRemoteObject(); + if (subscriber == nullptr) { + ANS_LOGE("[HandleSubscribeSelf] fail: read subscriber failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SubscribeSelf(iface_cast(subscriber)); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSubscribeSelf] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSubscribeLocalLiveView(MessageParcel &data, MessageParcel &reply) +{ + sptr subscriber = data.ReadRemoteObject(); + if (subscriber == nullptr) { + ANS_LOGE("[HandleSubscribeLocalLiveView] fail: read subscriber failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool subcribeInfo = false; + if (!data.ReadBool(subcribeInfo)) { + ANS_LOGE("[HandleSubscribeLocalLiveView] fail: read isSubcribeInfo failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr info = nullptr; + if (subcribeInfo) { + info = data.ReadParcelable(); + if (info == nullptr) { + ANS_LOGE("[HandleSubscribeLocalLiveView] fail: read info failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + } + + bool isNative = false; + if (!data.ReadBool(isNative)) { + ANS_LOGE("[HandleSubscribeLocalLiveView] fail: read isNative failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = + SubscribeLocalLiveView(iface_cast(subscriber), info, isNative); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSubscribeLocalLiveView] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleUnsubscribe(MessageParcel &data, MessageParcel &reply) +{ + sptr subscriber = data.ReadRemoteObject(); + if (subscriber == nullptr) { + ANS_LOGE("[HandleUnsubscribe] fail: read subscriber failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool subcribeInfo = false; + if (!data.ReadBool(subcribeInfo)) { + ANS_LOGE("[HandleUnsubscribe] fail: read isSubcribeInfo failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr info = nullptr; + if (subcribeInfo) { + info = data.ReadParcelable(); + if (info == nullptr) { + ANS_LOGE("[HandleUnsubscribe] fail: read info failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + } + + ErrCode result = Unsubscribe(iface_cast(subscriber), info); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleUnsubscribe] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleIsAllowedNotify(MessageParcel &data, MessageParcel &reply) +{ + bool allowed = false; + ErrCode result = IsAllowedNotify(allowed); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleIsAllowedNotify] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(allowed)) { + ANS_LOGE("[HandleIsAllowedNotify] fail: write allowed failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleIsAllowedNotifySelf(MessageParcel &data, MessageParcel &reply) +{ + bool allowed = false; + ErrCode result = IsAllowedNotifySelf(allowed); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleIsAllowedNotifySelf] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(allowed)) { + ANS_LOGE("[HandleIsAllowedNotifySelf] fail: write allowed failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleCanPopEnableNotificationDialog(MessageParcel &data, MessageParcel &reply) +{ + sptr callback = data.ReadRemoteObject(); + if (callback == nullptr) { + ANS_LOGE("[HandleCanPopEnableNotificationDialog] fail: read callback failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + bool canPop = false; + std::string bundleName; + ErrCode result = CanPopEnableNotificationDialog(iface_cast(callback), canPop, bundleName); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleCanPopEnableNotificationDialog] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(canPop)) { + ANS_LOGE("[HandleCanPopEnableNotificationDialog] fail: write canPop failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + if (!reply.WriteString(bundleName)) { + ANS_LOGE("[HandleCanPopEnableNotificationDialog] fail: write bundleName failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleRemoveEnableNotificationDialog(MessageParcel &data, MessageParcel &reply) +{ + ErrCode result = RemoveEnableNotificationDialog(); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleRemoveEnableNotificationDialog] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleIsSpecialBundleAllowedNotify(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool allowed = false; + ErrCode result = IsSpecialBundleAllowedNotify(bundleOption, allowed); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(allowed)) { + ANS_LOGE("[IsSpecialBundleAllowedNotify] fail: write allowed failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleCancelGroup(MessageParcel &data, MessageParcel &reply) +{ + std::string groupName; + if (!data.ReadString(groupName)) { + ANS_LOGE("[HandleCancelGroup] fail: read groupName failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::string appInstanceKey; + if (!data.ReadString(appInstanceKey)) { + ANS_LOGE("[HandleCancelGroup] fail: read instanceKey failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = CancelGroup(groupName, appInstanceKey); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleCancelGroup] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleRemoveGroupByBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleRemoveGroupByBundle] fail: read bundleOption failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::string groupName; + if (!data.ReadString(groupName)) { + ANS_LOGE("[HandleRemoveGroupByBundle] fail: read groupName failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = RemoveGroupByBundle(bundleOption, groupName); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleRemoveGroupByBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleIsDistributedEnabled(MessageParcel &data, MessageParcel &reply) +{ + bool enabled = false; + ErrCode result = IsDistributedEnabled(enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleIsDistributedEnabled] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(enabled)) { + ANS_LOGE("[HandleIsDistributedEnabled] fail: write enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleEnableDistributed(MessageParcel &data, MessageParcel &reply) +{ + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleEnableDistributed] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = EnableDistributed(enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleEnableDistributed] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleEnableDistributedByBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleEnableDistributedByBundle] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleEnableDistributedByBundle] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = EnableDistributedByBundle(bundleOption, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleEnableDistributedByBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleEnableDistributedSelf(MessageParcel &data, MessageParcel &reply) +{ + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleEnableDistributedSelf] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = EnableDistributedSelf(enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleEnableDistributedSelf] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleIsDistributedEnableByBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleIsDistributedEnableByBundle] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + ErrCode result = IsDistributedEnableByBundle(bundleOption, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleIsDistributedEnableByBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(enabled)) { + ANS_LOGE("[HandleIsDistributedEnableByBundle] fail: write enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetDeviceRemindType(MessageParcel &data, MessageParcel &reply) +{ + auto rType{ NotificationConstant::RemindType::NONE }; + ErrCode result = GetDeviceRemindType(rType); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetDeviceRemindType] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteInt32(static_cast(rType))) { + ANS_LOGE("[HandleGetDeviceRemindType] fail: write remind type failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleShellDump(MessageParcel &data, MessageParcel &reply) +{ + std::string cmd; + if (!data.ReadString(cmd)) { + ANS_LOGE("[HandleShellDump] fail: read cmd failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + std::string bundle; + if (!data.ReadString(bundle)) { + ANS_LOGE("[HandleShellDump] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + int32_t userId; + if (!data.ReadInt32(userId)) { + ANS_LOGE("[HandleShellDump] fail: read userId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + int32_t recvUserId; + if (!data.ReadInt32(recvUserId)) { + ANS_LOGE("[HandleShellDump] fail: read recvUserId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + std::vector notificationsInfo; + ErrCode result = ShellDump(cmd, bundle, userId, recvUserId, notificationsInfo); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetRecentNotificationsInfo] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteStringVector(notificationsInfo)) { + ANS_LOGE("[HandleGetRecentNotificationsInfo] fail: write notificationsInfo failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleIsSupportTemplate(MessageParcel &data, MessageParcel &reply) +{ + std::string templateName; + if (!data.ReadString(templateName)) { + ANS_LOGE("[HandleIsSupportTemplate] fail: read template name failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + bool support = false; + ErrCode result = IsSupportTemplate(templateName, support); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleIsSupportTemplate] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + if (!reply.WriteBool(support)) { + ANS_LOGE("[HandleIsSupportTemplate] fail: write support failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleIsSpecialUserAllowedNotifyByUser(MessageParcel &data, MessageParcel &reply) +{ + int32_t userId = SUBSCRIBE_USER_INIT; + if (!data.ReadInt32(userId)) { + ANS_LOGE("[HandleIsSpecialUserAllowedNotifyByUser] fail: read userId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool allowed = false; + ErrCode result = IsSpecialUserAllowedNotify(userId, allowed); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleIsSpecialUserAllowedNotifyByUser] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(allowed)) { + ANS_LOGE("[HandleIsSpecialUserAllowedNotifyByUser] fail: write allowed failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetNotificationsEnabledByUser(MessageParcel &data, MessageParcel &reply) +{ + int32_t userId = SUBSCRIBE_USER_INIT; + if (!data.ReadInt32(userId)) { + ANS_LOGE("[HandleSetNotificationsEnabledByUser] fail: read userId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleSetNotificationsEnabledByUser] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetNotificationsEnabledByUser(userId, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetNotificationsEnabledByUser] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleDeleteAllByUser(MessageParcel &data, MessageParcel &reply) +{ + int32_t userId = SUBSCRIBE_USER_INIT; + if (!data.ReadInt32(userId)) { + ANS_LOGE("[HandleDeleteAllByUser] fail: read userId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = DeleteAllByUser(userId); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleDeleteAllByUser] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetDoNotDisturbDateByUser(MessageParcel &data, MessageParcel &reply) +{ + int32_t userId = SUBSCRIBE_USER_INIT; + if (!data.ReadInt32(userId)) { + ANS_LOGE("[HandleSetDoNotDisturbDateByUser] fail: read userId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr date = data.ReadParcelable(); + if (date == nullptr) { + ANS_LOGE("[HandleSetDoNotDisturbDateByUser] fail: read date failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetDoNotDisturbDate(userId, date); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetDoNotDisturbDateByUser] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetDoNotDisturbDateByUser(MessageParcel &data, MessageParcel &reply) +{ + int32_t userId = SUBSCRIBE_USER_INIT; + if (!data.ReadInt32(userId)) { + ANS_LOGE("[HandleGetDoNotDisturbDateByUser] fail: read userId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr date = nullptr; + ErrCode result = GetDoNotDisturbDate(userId, date); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetDoNotDisturbDateByUser] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (result == ERR_OK) { + if (!reply.WriteParcelable(date)) { + ANS_LOGE("[HandleGetDoNotDisturbDateByUser] fail: write date failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetEnabledForBundleSlot(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleSetEnabledForBundleSlot] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t type = 0; + if (!data.ReadInt32(type)) { + ANS_LOGE("[HandleSetEnabledForBundleSlot] fail: read slot type failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + NotificationConstant::SlotType slotType = static_cast(type); + + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleSetEnabledForBundleSlot] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool isForceControl = false; + if (!data.ReadBool(isForceControl)) { + ANS_LOGE("[HandleSetEnabledForBundleSlot] fail: read isForceControl failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetEnabledForBundleSlot(bundleOption, slotType, enabled, isForceControl); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetEnabledForBundleSlot] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetEnabledForBundleSlot(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleGetEnabledForBundleSlot] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t type = 0; + if (!data.ReadInt32(type)) { + ANS_LOGE("[HandleGetEnabledForBundleSlot] fail: read slot type failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + NotificationConstant::SlotType slotType = static_cast(type); + + bool enabled = false; + ErrCode result = GetEnabledForBundleSlot(bundleOption, slotType, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetEnabledForBundleSlot] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(enabled)) { + ANS_LOGE("[HandleGetEnabledForBundleSlot] fail: write enabled failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetEnabledForBundleSlotSelf(MessageParcel &data, MessageParcel &reply) +{ + int32_t type = 0; + if (!data.ReadInt32(type)) { + ANS_LOGE("[HandleGetEnabledForBundleSlotSelf] fail: read slot type failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + NotificationConstant::SlotType slotType = static_cast(type); + + bool enabled = false; + ErrCode result = GetEnabledForBundleSlotSelf(slotType, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetEnabledForBundleSlotSelf] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(enabled)) { + ANS_LOGE("[HandleGetEnabledForBundleSlotSelf] fail: write enabled failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleDistributedSetEnabledWithoutApp(MessageParcel &data, MessageParcel &reply) +{ + int32_t userId = SUBSCRIBE_USER_INIT; + if (!data.ReadInt32(userId)) { + ANS_LOGE("[HandleDistributedSetEnabledWithoutApp] fail: read userId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleDistributedSetEnabledWithoutApp] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetSyncNotificationEnabledWithoutApp(userId, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleDistributedSetEnabledWithoutApp] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleDistributedGetEnabledWithoutApp(MessageParcel &data, MessageParcel &reply) +{ + int32_t userId = SUBSCRIBE_USER_INIT; + if (!data.ReadInt32(userId)) { + ANS_LOGE("[HandleDistributedGetEnabledWithoutApp] fail: read userId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + ErrCode result = GetSyncNotificationEnabledWithoutApp(userId, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleDistributedGetEnabledWithoutApp] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(enabled)) { + ANS_LOGE("[HandleDistributedGetEnabledWithoutApp] fail: write enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetBadgeNumber(MessageParcel &data, MessageParcel &reply) +{ + ANSR_LOGI("HandleSetBadgeNumber"); + int32_t badgeNumber = -1; + if (!data.ReadInt32(badgeNumber)) { + ANSR_LOGE("Read badge number failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::string appInstanceKey; + if (!data.ReadString(appInstanceKey)) { + ANSR_LOGE("Read instance key failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetBadgeNumber(badgeNumber, appInstanceKey); + if (!reply.WriteInt32(result)) { + ANSR_LOGE("Write badge number failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + +ErrCode AnsManagerStub::HandleSetBadgeNumberByBundle(MessageParcel &data, MessageParcel &reply) +{ + ANS_LOGD("Called."); + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("Read bundle option failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + int32_t badgeNumber = 0; + if (!data.ReadInt32(badgeNumber)) { + ANS_LOGE("Read badge number failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetBadgeNumberByBundle(bundleOption, badgeNumber); + if (!reply.WriteInt32(result)) { + ANS_LOGE("Write result failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + +ErrCode AnsManagerStub::HandleGetAllNotificationEnableStatus(MessageParcel &data, MessageParcel &reply) +{ + std::vector bundleOption; + ErrCode result = GetAllNotificationEnabledBundles(bundleOption); + int32_t vectorSize = bundleOption.size(); + if (vectorSize > MAX_STATUS_VECTOR_NUM) { + ANS_LOGE("Bundle bundleOption vector is over size."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteInt32(result)) { + ANS_LOGE("Write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteInt32(vectorSize)) { + ANS_LOGE("Write bundleOption size failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + for (const auto &item : bundleOption) { + if (!reply.WriteParcelable(&item)) { + ANS_LOGE("Write bundleOption failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleRegisterPushCallback(MessageParcel &data, MessageParcel &reply) +{ + sptr pushCallBack = data.ReadRemoteObject(); + if (pushCallBack == nullptr) { + ANS_LOGE("fail: read JSPushCallBack failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr notificationCheckRequest = data.ReadParcelable(); + if (notificationCheckRequest == nullptr) { + ANS_LOGE("fail: read notificationCheckRequest failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = RegisterPushCallback(pushCallBack, notificationCheckRequest); + if (!reply.WriteInt32(result)) { + ANS_LOGE("fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + +ErrCode AnsManagerStub::HandleUnregisterPushCallback(MessageParcel &data, MessageParcel &reply) +{ + ErrCode result = UnregisterPushCallback(); + if (!reply.WriteInt32(result)) { + ANS_LOGE("fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + +ErrCode AnsManagerStub::HandleAddDoNotDisturbProfiles(MessageParcel &data, MessageParcel &reply) +{ + std::vector> profiles; + if (!ReadParcelableVector(profiles, data)) { + ANS_LOGE("Read profiles failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (profiles.size() > MAX_STATUS_VECTOR_NUM) { + ANS_LOGE("The profiles is exceeds limit."); + return ERR_ANS_INVALID_PARAM; + } + + ErrCode result = AddDoNotDisturbProfiles(profiles); + if (!reply.WriteInt32(result)) { + ANS_LOGE("Write result failed, ErrCode is %{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetDistributedEnabledByBundle(MessageParcel &data, MessageParcel &reply) +{ + ANS_LOGD("enter"); + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleSetNotificationsEnabledForSpecialBundle] fail: read bundleOption failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::string deviceType; + if (!data.ReadString(deviceType)) { + ANS_LOGE("[HandleSetNotificationsEnabledForSpecialBundle] fail: read deviceId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleSetNotificationsEnabledForSpecialBundle] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetDistributedEnabledByBundle(bundleOption, deviceType, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetNotificationsEnabledForSpecialBundle] fail: write result failed, ErrCode=%{public}d", + result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleRemoveDoNotDisturbProfiles(MessageParcel &data, MessageParcel &reply) +{ + std::vector> profiles; + if (!ReadParcelableVector(profiles, data)) { + ANS_LOGE("Read profiles failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (profiles.size() > MAX_STATUS_VECTOR_NUM) { + ANS_LOGE("The profiles is exceeds limit."); + return ERR_ANS_INVALID_PARAM; + } + + ErrCode result = RemoveDoNotDisturbProfiles(profiles); + if (!reply.WriteInt32(result)) { + ANS_LOGE("Write result failed, ErrCode is %{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleIsDistributedEnabledByBundle(MessageParcel &data, MessageParcel &reply) +{ + ANS_LOGD("enter"); + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleIsDistributedEnabledByBundle] fail: read bundleOption failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::string deviceType; + if (!data.ReadString(deviceType)) { + ANS_LOGE("[HandleIsDistributedEnabledByBundle] fail: read deviceId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + ErrCode result = IsDistributedEnabledByBundle(bundleOption, deviceType, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleIsDistributedEnabledByBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(enabled)) { + ANS_LOGE("[HandleIsDistributedEnabledByBundle] fail: write enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetAdditionConfig(MessageParcel &data, MessageParcel &reply) +{ + std::string key; + if (!data.ReadString(key)) { + ANS_LOGE("Failed to read key."); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::string value; + if (!data.ReadString(value)) { + ANS_LOGE("Failed to read value."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetAdditionConfig(key, value); + if (!reply.WriteInt32(result)) { + ANS_LOGE("Failed to write result, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + +ErrCode AnsManagerStub::HandleSetSmartReminderEnabled(MessageParcel &data, MessageParcel &reply) +{ + ANS_LOGD("enter"); + std::string deviceType; + if (!data.ReadString(deviceType)) { + ANS_LOGE("[HandleSetSmartReminderEnabled] fail: read deviceId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleSetSmartReminderEnabled] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetSmartReminderEnabled(deviceType, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetSmartReminderEnabled] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleCancelAsBundleWithAgent(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("Read bundleOption failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t id = 0; + if (!data.ReadInt32(id)) { + ANS_LOGE("Read notification id failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = CancelAsBundleWithAgent(bundleOption, id); + if (!reply.WriteInt32(result)) { + ANS_LOGE("Write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + +ErrCode AnsManagerStub::HandleIsSmartReminderEnabled(MessageParcel &data, MessageParcel &reply) +{ + ANS_LOGD("enter"); + std::string deviceType; + if (!data.ReadString(deviceType)) { + ANS_LOGE("[HandleIsSmartReminderEnabled] fail: read deviceId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool enabled = false; + ErrCode result = IsSmartReminderEnabled(deviceType, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleIsSmartReminderEnabled] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(enabled)) { + ANS_LOGE("[HandleIsSmartReminderEnabled] fail: write enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleSetTargetDeviceStatus(MessageParcel &data, MessageParcel &reply) +{ + std::string deviceType; + if (!data.ReadString(deviceType)) { + ANS_LOGE("[HandleSetTargetDeviceStatus] fail: read deviceType failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t status = 0; + if (!data.ReadInt32(status)) { + ANS_LOGE("[HandleSetTargetDeviceStatus] fail: read status failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetTargetDeviceStatus(deviceType, status); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetTargetDeviceStatus] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetDoNotDisturbProfile(MessageParcel &data, MessageParcel &reply) +{ + int32_t profileId = data.ReadInt32(); + sptr profile = nullptr; + ErrCode result = GetDoNotDisturbProfile(profileId, profile); + if (!reply.WriteInt32(result)) { + ANS_LOGE("HandleGetDoNotDisturbProfile write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (result == ERR_OK) { + if (!reply.WriteParcelable(profile)) { + ANS_LOGE("HandleGetDoNotDisturbProfile write slot failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + } + return ERR_OK; +} + +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED +ErrCode AnsManagerStub::HandleRegisterSwingCallback(MessageParcel &data, MessageParcel &reply) +{ + sptr swingCallBack = data.ReadRemoteObject(); + if (swingCallBack == nullptr) { + ANS_LOGE("fail: read SwingCallBack failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = RegisterSwingCallback(swingCallBack); + if (!reply.WriteInt32(result)) { + ANS_LOGE("fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} +#endif + +ErrCode AnsManagerStub::HandleUpdateNotificationTimerByUid(MessageParcel &data, MessageParcel &reply) +{ + int32_t uid = data.ReadInt32(); + bool isPaused = data.ReadBool(); + ErrCode result = UpdateNotificationTimerByUid(uid, isPaused); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleUpdateNotificationTimerByUid] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleAllowUseReminder(MessageParcel &data, MessageParcel &reply) +{ + ANS_LOGD("enter"); + std::string bundleName; + if (!data.ReadString(bundleName)) { + ANS_LOGE("fail: read deviceId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool isAllowUseReminder = false; + ErrCode result = AllowUseReminder(bundleName, isAllowUseReminder); + if (!reply.WriteInt32(result)) { + ANS_LOGE("fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(isAllowUseReminder)) { + ANS_LOGE("fail: write enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} +} // namespace Notification +} // namespace OHOS diff --git a/services/ans/src/ans_manager_stub_invalid.cpp b/services/ans/src/ans_manager_stub_invalid.cpp new file mode 100644 index 000000000..ce3db3ebb --- /dev/null +++ b/services/ans/src/ans_manager_stub_invalid.cpp @@ -0,0 +1,633 @@ +/* + * Copyright (c) 2021-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. + */ + +#include "ans_manager_stub.h" +#include "ans_const_define.h" +#include "ans_inner_errors.h" +#include "ans_log_wrapper.h" +#include "message_option.h" +#include "message_parcel.h" +#include "parcel.h" +#include "reminder_request_alarm.h" +#include "reminder_request_calendar.h" +#include "reminder_request_timer.h" + +namespace OHOS { +namespace Notification { +ErrCode AnsManagerStub::Publish(const std::string &label, const sptr ¬ification) +{ + ANS_LOGE("AnsManagerStub::Publish called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::PublishNotificationForIndirectProxy(const sptr ¬ification) +{ + ANS_LOGE("AnsManagerStub::PublishNotificationForIndirectProxy called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::Cancel(int notificationId, const std::string &label, const std::string &instanceKey) +{ + ANS_LOGE("AnsManagerStub::Cancel called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::CancelAll(const std::string &instanceKey) +{ + ANS_LOGE("AnsManagerStub::CancelAll called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::CancelAsBundle(int32_t notificationId, const std::string &representativeBundle, int32_t userId) +{ + ANS_LOGE("AnsManagerStub::CancelAsBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::CancelAsBundle(const sptr &bundleOption, int32_t notificationId) +{ + ANS_LOGE("AnsManagerStub::CancelAsBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::CancelAsBundle( + const sptr &bundleOption, int32_t notificationId, int32_t userId) +{ + ANS_LOGE("AnsManagerStub::CancelAsBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::AddSlotByType(NotificationConstant::SlotType slotType) +{ + ANS_LOGE("AnsManagerStub::AddSlotByType called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::AddSlots(const std::vector> &slots) +{ + ANS_LOGE("AnsManagerStub::AddSlots called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::RemoveSlotByType(const NotificationConstant::SlotType &slotType) +{ + ANS_LOGE("AnsManagerStub::RemoveSlotByType called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::RemoveAllSlots() +{ + ANS_LOGE("AnsManagerStub::RemoveAllSlots called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetSlotByType(const NotificationConstant::SlotType &slotType, sptr &slot) +{ + ANS_LOGE("AnsManagerStub::GetSlotByType called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetSlots(std::vector> &slots) +{ + ANS_LOGE("AnsManagerStub::GetSlots called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetSlotNumAsBundle(const sptr &bundleOption, uint64_t &num) +{ + ANS_LOGE("AnsManagerStub::GetSlotNumAsBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetActiveNotifications( + std::vector> ¬ifications, const std::string &instanceKey) +{ + ANS_LOGE("AnsManagerStub::GetActiveNotifications called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetActiveNotificationNums(uint64_t &num) +{ + ANS_LOGE("AnsManagerStub::GetActiveNotificationNums called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetAllActiveNotifications(std::vector> ¬ifications) +{ + ANS_LOGE("AnsManagerStub::GetAllActiveNotifications called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetSpecialActiveNotifications( + const std::vector &key, std::vector> ¬ifications) +{ + ANS_LOGE("AnsManagerStub::GetSpecialActiveNotifications called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetActiveNotificationByFilter( + const sptr &bundleOption, const int32_t notificationId, const std::string &label, + std::vector extraInfoKeys, sptr &request) +{ + ANS_LOGE("AnsManagerStub::GetActiveNotificationByFilter called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::CanPublishAsBundle(const std::string &representativeBundle, bool &canPublish) +{ + ANS_LOGE("AnsManagerStub::CanPublishAsBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::PublishAsBundle( + const sptr notification, const std::string &representativeBundle) +{ + ANS_LOGE("AnsManagerStub::PublishAsBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetNotificationBadgeNum(int num) +{ + ANS_LOGE("AnsManagerStub::SetNotificationBadgeNum called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetBundleImportance(int &importance) +{ + ANS_LOGE("AnsManagerStub::GetBundleImportance called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetSlotFlagsAsBundle(const sptr &bundleOption, uint32_t &slotFlags) +{ + ANS_LOGE("AnsManagerStub::GetSlotFlagsAsBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetSlotFlagsAsBundle(const sptr &bundleOption, uint32_t slotFlags) +{ + ANS_LOGE("AnsManagerStub::SetSlotFlagsAsBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::HasNotificationPolicyAccessPermission(bool &granted) +{ + ANS_LOGE("AnsManagerStub::HasNotificationPolicyAccessPermission called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::TriggerLocalLiveView(const sptr &bundleOption, + const int32_t notificationId, const sptr &buttonOption) +{ + ANS_LOGE("AnsManagerStub::TriggerLocalLiveView called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::RemoveNotification(const sptr &bundleOption, + int notificationId, const std::string &label, int32_t removeReason) +{ + ANS_LOGE("AnsManagerStub::RemoveNotification called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::RemoveAllNotifications(const sptr &bundleOption) +{ + ANS_LOGE("AnsManagerStub::RemoveAllNotifications called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::RemoveNotifications(const std::vector &keys, int32_t removeReason) +{ + ANS_LOGD("called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::Delete(const std::string &key, int32_t removeReason) +{ + ANS_LOGE("AnsManagerStub::Delete called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::DeleteByBundle(const sptr &bundleOption) +{ + ANS_LOGE("AnsManagerStub::DeleteByBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::DeleteAll() +{ + ANS_LOGE("AnsManagerStub::DeleteAll called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetSlotsByBundle( + const sptr &bundleOption, std::vector> &slots) +{ + ANS_LOGE("AnsManagerStub::GetSlotsByBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetSlotByBundle( + const sptr &bundleOption, const NotificationConstant::SlotType &slotType, + sptr &slot) +{ + ANS_LOGE("AnsManagerStub::GetSlotByBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::UpdateSlots( + const sptr &bundleOption, const std::vector> &slots) +{ + ANS_LOGE("AnsManagerStub::UpdateSlots called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::RequestEnableNotification(const std::string &deviceId, + const sptr &callback, + const sptr &callerToken) +{ + ANS_LOGE("AnsManagerStub::RequestEnableNotification called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetNotificationsEnabledForBundle(const std::string &bundle, bool enabled) +{ + ANS_LOGE("AnsManagerStub::SetNotificationsEnabledForBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled) +{ + ANS_LOGE("AnsManagerStub::SetNotificationsEnabledForAllBundles called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetNotificationsEnabledForSpecialBundle( + const std::string &deviceId, const sptr &bundleOption, bool enabled) +{ + ANS_LOGE("AnsManagerStub::SetNotificationsEnabledForSpecialBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetShowBadgeEnabledForBundle(const sptr &bundleOption, bool enabled) +{ + ANS_LOGE("AnsManagerStub::SetShowBadgeEnabledForBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetShowBadgeEnabledForBundle(const sptr &bundleOption, bool &enabled) +{ + ANS_LOGE("AnsManagerStub::GetShowBadgeEnabledForBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetShowBadgeEnabled(bool &enabled) +{ + ANS_LOGE("AnsManagerStub::GetShowBadgeEnabled called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::Subscribe(const sptr &subscriber, + const sptr &info) +{ + ANS_LOGE("AnsManagerStub::Subscribe called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SubscribeSelf(const sptr &subscriber) +{ + ANS_LOGE("AnsManagerStub::SubscribeSelf called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SubscribeLocalLiveView(const sptr &subscriber, + const sptr &info, const bool isNative) +{ + ANS_LOGE("AnsManagerStub::SubscribeLocalLiveView called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::Unsubscribe(const sptr &subscriber, + const sptr &info) +{ + ANS_LOGE("AnsManagerStub::Unsubscribe called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::IsAllowedNotify(bool &allowed) +{ + ANS_LOGE("AnsManagerStub::IsAllowedNotify called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::IsAllowedNotifySelf(bool &allowed) +{ + ANS_LOGE("AnsManagerStub::IsAllowedNotifySelf called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::CanPopEnableNotificationDialog(const sptr &callback, + bool &canPop, std::string &bundleName) +{ + ANS_LOGE("AnsManagerStub::CanPopEnableNotificationDialog called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::RemoveEnableNotificationDialog() +{ + ANS_LOGE("AnsManagerStub::RemoveEnableNotificationDialog called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::IsSpecialBundleAllowedNotify(const sptr &bundleOption, bool &allowed) +{ + ANS_LOGE("AnsManagerStub::IsSpecialBundleAllowedNotify called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::CancelGroup(const std::string &groupName, const std::string &instanceKey) +{ + ANS_LOGE("AnsManagerStub::CancelGroup called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::RemoveGroupByBundle( + const sptr &bundleOption, const std::string &groupName) +{ + ANS_LOGE("AnsManagerStub::RemoveGroupByBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetDoNotDisturbDate(const sptr &date) +{ + ANS_LOGE("AnsManagerStub::SetDoNotDisturbDate called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetDoNotDisturbDate(sptr &date) +{ + ANS_LOGE("AnsManagerStub::GetDoNotDisturbDate called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::AddDoNotDisturbProfiles(const std::vector> &profiles) +{ + ANS_LOGD("Called."); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::RemoveDoNotDisturbProfiles(const std::vector> &profiles) +{ + ANS_LOGD("Called."); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::DoesSupportDoNotDisturbMode(bool &doesSupport) +{ + ANS_LOGE("AnsManagerStub::DoesSupportDoNotDisturbMode called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber, int32_t callerType) +{ + ANS_LOGE("AnsManagerStub::IsNeedSilentInDoNotDisturbMode called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::IsDistributedEnabled(bool &enabled) +{ + ANS_LOGE("AnsManagerStub::IsDistributedEnabled called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::EnableDistributed(bool enabled) +{ + ANS_LOGE("AnsManagerStub::EnableDistributed called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::EnableDistributedByBundle(const sptr &bundleOption, bool enabled) +{ + ANS_LOGE("AnsManagerStub::EnableDistributedByBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::EnableDistributedSelf(bool enabled) +{ + ANS_LOGE("AnsManagerStub::EnableDistributedSelf called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::IsDistributedEnableByBundle(const sptr &bundleOption, bool &enabled) +{ + ANS_LOGE("AnsManagerStub::IsDistributedEnableByBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetDeviceRemindType(NotificationConstant::RemindType &remindType) +{ + ANS_LOGE("AnsManagerStub::GetDeviceRemindType called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::PublishContinuousTaskNotification(const sptr &request) +{ + ANS_LOGE("AnsManagerStub::PublishContinuousTaskNotification called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) +{ + ANS_LOGE("AnsManagerStub::CancelContinuousTaskNotification called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::IsSupportTemplate(const std::string &templateName, bool &support) +{ + ANS_LOGE("AnsManagerStub::IsSupportTemplate called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::IsSpecialUserAllowedNotify(const int32_t &userId, bool &allowed) +{ + ANS_LOGE("AnsManagerStub::IsSpecialUserAllowedNotify called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetNotificationsEnabledByUser(const int32_t &deviceId, bool enabled) +{ + ANS_LOGE("AnsManagerStub::SetNotificationsEnabledByUser called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::DeleteAllByUser(const int32_t &userId) +{ + ANS_LOGE("AnsManagerStub::DeleteAllByUser called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetDoNotDisturbDate(const int32_t &userId, const sptr &date) +{ + ANS_LOGE("AnsManagerStub::SetDoNotDisturbDate called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetDoNotDisturbDate(const int32_t &userId, sptr &date) +{ + ANS_LOGE("AnsManagerStub::GetDoNotDisturbDate called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetEnabledForBundleSlot(const sptr &bundleOption, + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) +{ + ANS_LOGE("AnsManagerStub::SetEnabledForBundleSlot called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetEnabledForBundleSlot( + const sptr &bundleOption, const NotificationConstant::SlotType &slotType, bool &enabled) +{ + ANS_LOGE("AnsManagerStub::GetEnabledForBundleSlot called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) +{ + ANS_LOGE("AnsManagerStub::GetEnabledForBundleSlotSelf called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::ShellDump(const std::string &cmd, const std::string &bundle, int32_t userId, + int32_t recvUserId, std::vector &dumpInfo) +{ + ANS_LOGE("AnsManagerStub::ShellDump called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetSyncNotificationEnabledWithoutApp(const int32_t userId, const bool enabled) +{ + ANS_LOGE("AnsManagerStub::SetSyncNotificationEnabledWithoutApp called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetSyncNotificationEnabledWithoutApp(const int32_t userId, bool &enabled) +{ + ANS_LOGE("AnsManagerStub::GetSyncNotificationEnabledWithoutApp called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetBadgeNumber(int32_t badgeNumber, const std::string &instanceKey) +{ + ANS_LOGE("AnsManagerStub::SetBadgeNumber called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetBadgeNumberByBundle(const sptr &bundleOption, int32_t badgeNumber) +{ + ANS_LOGD("Called."); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetAllNotificationEnabledBundles(std::vector &bundleOption) +{ + ANS_LOGE("AnsManagerStub::GetAllNotificationEnabledBundles called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::RegisterPushCallback( + const sptr& pushCallback, const sptr ¬ificationCheckRequest) +{ + ANS_LOGE("RegisterPushCallback called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::UnregisterPushCallback() +{ + ANS_LOGE("UnregisterPushCallback called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetDistributedEnabledByBundle(const sptr &bundleOption, + const std::string &deviceType, const bool enabled) +{ + ANS_LOGE("SetDistributedEnabledByBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::IsDistributedEnabledByBundle(const sptr &bundleOption, + const std::string &deviceType, bool &enabled) +{ + ANS_LOGE("IsDistributedEnabledByBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetSmartReminderEnabled(const std::string &deviceType, const bool enabled) +{ + ANS_LOGE("SetSmartReminderEnabled called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::IsSmartReminderEnabled(const std::string &deviceType, bool &enabled) +{ + ANS_LOGE("IsSmartReminderEnabled called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetAdditionConfig(const std::string &key, const std::string &value) +{ + ANS_LOGE("Called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::CancelAsBundleWithAgent(const sptr &bundleOption, const int32_t id) +{ + ANS_LOGE("Called."); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetTargetDeviceStatus(const std::string &deviceType, const uint32_t status) +{ + ANS_LOGE("SetTargetDeviceStatus called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetDoNotDisturbProfile(int32_t id, sptr &profile) +{ + ANS_LOGE("GetDoNotDisturbProfile called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::AllowUseReminder(const std::string& bundleName, bool& isAllowUseReminder) +{ + ANS_LOGE("AllowUseReminder called!"); + return ERR_INVALID_OPERATION; +} + +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED +ErrCode AnsManagerStub::RegisterSwingCallback(const sptr& swingCallback) +{ + ANS_LOGE("RegisterSwingCallback called!"); + return ERR_INVALID_OPERATION; +} +#endif + +ErrCode AnsManagerStub::UpdateNotificationTimerByUid(const int32_t uid, const bool isPaused) +{ + ANS_LOGE("UpdateNotificationTimerByUid called!"); + return ERR_INVALID_OPERATION; +} +} // namespace Notification +} // namespace OHOS diff --git a/services/ans/src/slot_manager/AddSlots.cpp b/services/ans/src/slot_manager/AddSlots.cpp new file mode 100644 index 000000000..340ffc901 --- /dev/null +++ b/services/ans/src/slot_manager/AddSlots.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2021-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. + */ + +#include "slot_manager.h" + +#include +#include +#include + +#include "access_token_helper.h" +#include "ans_inner_errors.h" +#include "ans_log_wrapper.h" +#include "ans_permission_def.h" +#include "errors.h" +#include "common_event_manager.h" +#include "common_event_support.h" +#include "hitrace_meter_adapter.h" +#include "os_account_manager_helper.h" +#include "ipc_skeleton.h" +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED +#include "smart_reminder_center.h" +#endif + +#include "../advanced_notification_inline.cpp" +#include "notification_extension_wrapper.h" +#include "notification_analytics_util.h" + +namespace OHOS { +namespace Notification { +ErrCode SlotManager::AddSlots(MessageParcel &data, MessageParcel &reply) +{ + ANS_LOGD("%{public}s", __FUNCTION__); + std::vector> slots; + if (!ReadParcelableVector(slots, data)) { + ANS_LOGE("[HandleAddSlots] fail: read slotsSize failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr bundleOption = AdvancedNotificationService::GenerateBundleOption(); + if (bundleOption == nullptr) { + return ERR_ANS_INVALID_BUNDLE; + } + + ErrCode result = AddSlotsSyncQue(slots, bundleOption); + + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleAddSlots] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode SlotManager::AddSlotsSyncQue(const std::vector> &slots, sptr bundleOption) +{ + auto excuteQueue = AdvancedNotificationService::GetInstance()->GetNotificationSvrQueue(); + if (excuteQueue == nullptr) { + ANS_LOGE("Serial queue is invalid."); + return ERR_ANS_INVALID_PARAM; + } + + ErrCode result; + ffrt::task_handle handler = excuteQueue->submit_h(std::bind([&]() { + result = AddSlotsInner(slots, bundleOption); + })); + excuteQueue->wait(handler); + return result; +} + +ErrCode SlotManager::AddSlotsInner(const std::vector> &slots, sptr bundleOption) +{ + if (slots.size() == 0) { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode result = ERR_OK; + std::vector> addSlots; + for (auto slot : slots) { + sptr originalSlot; + result = NotificationPreferences::GetInstance()->GetNotificationSlot(bundleOption, + slot->GetType(), originalSlot); + if ((result == ERR_OK) && (originalSlot != nullptr)) { + continue; + } + + GenerateSlotReminderMode(slot, bundleOption, true); + addSlots.push_back(slot); + } + + if (addSlots.size() == 0) { + result = ERR_OK; + } else { + result = NotificationPreferences::GetInstance()->AddNotificationSlots(bundleOption, addSlots); + } + return result; +} + +} // namespace Notification +} // namespace OHOS diff --git a/services/ans/src/slot_manager/setNotificationEnableSlot.cpp b/services/ans/src/slot_manager/setNotificationEnableSlot.cpp new file mode 100644 index 000000000..bf24c3870 --- /dev/null +++ b/services/ans/src/slot_manager/setNotificationEnableSlot.cpp @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2021-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. + */ + +#include "slot_manager.h" + +#include "advanced_notification_service.h" + +#include +#include +#include + +#include "access_token_helper.h" +#include "ans_inner_errors.h" +#include "ans_log_wrapper.h" +#include "ans_permission_def.h" +#include "errors.h" +#include "common_event_manager.h" +#include "common_event_support.h" +#include "hitrace_meter_adapter.h" +#include "os_account_manager_helper.h" +#include "ipc_skeleton.h" +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED +#include "smart_reminder_center.h" +#endif + +#include "../advanced_notification_inline.cpp" +#include "notification_extension_wrapper.h" +#include "notification_analytics_util.h" +#include "event_report.h" + +namespace OHOS { +namespace Notification { +ErrCode SlotManager::SetEnabledForBundleSlot(MessageParcel &data, MessageParcel &reply) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + sptr bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleSetEnabledForBundleSlot] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t type = 0; + if (!data.ReadInt32(type)) { + ANS_LOGE("[HandleSetEnabledForBundleSlot] fail: read slot type failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + NotificationConstant::SlotType slotType = static_cast(type); + + bool enabled = false; + if (!data.ReadBool(enabled)) { + ANS_LOGE("[HandleSetEnabledForBundleSlot] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool isForceControl = false; + if (!data.ReadBool(isForceControl)) { + ANS_LOGE("[HandleSetEnabledForBundleSlot] fail: read isForceControl failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr bundle = AdvancedNotificationService::GenerateValidBundleOption(bundleOption); + if (bundle == nullptr) { + return ERR_ANS_INVALID_BUNDLE; + } + + ANS_LOGD("slotType: %{public}d, enabled: %{public}d, isForceControl: %{public}d", + slotType, enabled, isForceControl); + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_5, EventBranchId::BRANCH_4); + message.Message(bundleOption->GetBundleName() + "_" +std::to_string(bundleOption->GetUid()) + + " slotType: " + std::to_string(static_cast(slotType)) + + " enabled: " +std::to_string(enabled) + "isForceControl" + std::to_string(isForceControl)); + + ErrCode result = SetEnabledForBundleSlotSyncQue(bundleOption, bundle, slotType, enabled, isForceControl); + + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetEnabledForBundleSlot] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + SendEnableNotificationSlotHiSysEvent(bundleOption, slotType, enabled, result); + message.ErrorCode(result); + NotificationAnalyticsUtil::ReportModifyEvent(message); + ANS_LOGI("%{public}s_%{public}d, SetEnabledForBundleSlot successful.", + bundleOption->GetBundleName().c_str(), bundleOption->GetUid()); + return result; +} + +ErrCode SlotManager::SetEnabledForBundleSlotSyncQue( + const sptr &bundleOption, + const sptr &bundle, + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) +{ + auto excuteQueue = AdvancedNotificationService::GetInstance()->GetNotificationSvrQueue(); + if (excuteQueue == nullptr) { + ANS_LOGE("Serial queue is invalid."); + return ERR_ANS_INVALID_PARAM; + } + ErrCode result; + ffrt::task_handle handler = excuteQueue->submit_h(std::bind([&]() { + result = SetEnabledForBundleSlotInner(bundleOption, bundle, slotType, enabled, isForceControl); + })); + excuteQueue->wait(handler); + return result; +} + +ErrCode SlotManager::SetEnabledForBundleSlotInner( + const sptr &bundleOption, + const sptr &bundle, + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) +{ + sptr slot; + ErrCode result = NotificationPreferences::GetInstance()->GetNotificationSlot(bundle, slotType, slot); + if (result == ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST || + result == ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST) { + slot = new (std::nothrow) NotificationSlot(slotType); + if (slot == nullptr) { + ANS_LOGE("Failed to create NotificationSlot ptr."); + return ERR_ANS_NO_MEMORY; + } + GenerateSlotReminderMode(slot, bundleOption); + return AddSlotThenPublishEvent(slot, bundle, enabled, isForceControl); + } else if ((result == ERR_OK) && (slot != nullptr)) { + if (slot->GetEnable() == enabled && slot->GetForceControl() == isForceControl) { + slot->SetAuthorizedStatus(NotificationSlot::AuthorizedStatus::AUTHORIZED); + std::vector> slots; + slots.push_back(slot); + return NotificationPreferences::GetInstance()->AddNotificationSlots(bundle, slots); + } + NotificationPreferences::GetInstance()->RemoveNotificationSlot(bundle, slotType); + return AddSlotThenPublishEvent(slot, bundle, enabled, isForceControl); + } + ANS_LOGE("Set enable slot: GetNotificationSlot failed"); + return result; +} + +void SlotManager::SendEnableNotificationSlotHiSysEvent( + const sptr &bundleOption, const NotificationConstant::SlotType &slotType, + bool enabled, ErrCode errCode) +{ + if (bundleOption == nullptr) { + return; + } + + EventInfo eventInfo; + eventInfo.bundleName = bundleOption->GetBundleName(); + eventInfo.uid = bundleOption->GetUid(); + eventInfo.slotType = slotType; + eventInfo.enable = enabled; + if (errCode != ERR_OK) { + eventInfo.errCode = errCode; + EventReport::SendHiSysEvent(ENABLE_NOTIFICATION_SLOT_ERROR, eventInfo); + } else { + EventReport::SendHiSysEvent(ENABLE_NOTIFICATION_SLOT, eventInfo); + } +} + +ErrCode SlotManager::AddSlotThenPublishEvent( + const sptr &slot, + const sptr &bundle, + bool enabled, bool isForceControl) +{ + bool allowed = false; + ErrCode result = NotificationPreferences::GetInstance()->GetNotificationsEnabledForBundle(bundle, allowed); + if (result == ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST) { + result = ERR_OK; + allowed = AdvancedNotificationService::GetInstance()->CheckApiCompatibility(bundle); + AdvancedNotificationService::GetInstance()->SetDefaultNotificationEnabled(bundle, allowed); + } + + slot->SetEnable(enabled); + slot->SetForceControl(isForceControl); + slot->SetAuthorizedStatus(NotificationSlot::AuthorizedStatus::AUTHORIZED); + std::vector> slots; + slots.push_back(slot); + result = NotificationPreferences::GetInstance()->AddNotificationSlots(bundle, slots); + if (result != ERR_OK) { + ANS_LOGE("Set enable slot: AddNotificationSlot failed"); + return result; + } + + if (!slot->GetEnable()) { + AdvancedNotificationService::GetInstance()->RemoveNotificationBySlot(bundle, slot, NotificationConstant::DISABLE_SLOT_REASON_DELETE); + } else { + if (!slot->GetForceControl() && !allowed) { + AdvancedNotificationService::GetInstance()->RemoveNotificationBySlot(bundle, slot, NotificationConstant::DISABLE_NOTIFICATION_REASON_DELETE); + } + } + + AdvancedNotificationService::GetInstance()->PublishSlotChangeCommonEvent(bundle); + return result; +} +} // namespace Notification +} // namespace OHOS diff --git a/services/ans/src/slot_manager/slot_manager.cpp b/services/ans/src/slot_manager/slot_manager.cpp new file mode 100644 index 000000000..c6abd0174 --- /dev/null +++ b/services/ans/src/slot_manager/slot_manager.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2021-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. + */ + +#include "slot_manager.h" + +#include +#include +#include + +#include "access_token_helper.h" +#include "ans_inner_errors.h" +#include "ans_log_wrapper.h" +#include "ans_permission_def.h" +#include "errors.h" +#include "common_event_manager.h" +#include "common_event_support.h" +#include "hitrace_meter_adapter.h" +#include "os_account_manager_helper.h" +#include "ipc_skeleton.h" +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED +#include "smart_reminder_center.h" +#endif + +#include "../advanced_notification_inline.cpp" +#include "notification_extension_wrapper.h" +#include "notification_analytics_util.h" + +namespace OHOS { +namespace Notification { +SlotManager::SlotManager() = default; +SlotManager::~SlotManager() = default; +int32_t SlotManager::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) +{ + ErrCode result = CheckInterfacePermission(code); + if (result != ERR_OK) { + return result; + } + + switch (code) { + case static_cast(NotificationInterfaceCode::ADD_SLOTS): { + result = AddSlots(data, reply); + break; + } + case static_cast(NotificationInterfaceCode::SET_ENABLED_FOR_BUNDLE_SLOT): { + result = SetEnabledForBundleSlot(data, reply); + break; + } + default: { + ANS_LOGE("[OnRemoteRequest] fail: unknown code!"); + return ERR_ANS_INVALID_PARAM; + } + } + if (SUCCEEDED(result)) { + return NO_ERROR; + } + + return result; +} + +int32_t SlotManager::CheckInterfacePermission(uint32_t code) +{ + switch (code) { + case static_cast(NotificationInterfaceCode::ADD_SLOTS): + case static_cast(NotificationInterfaceCode::SET_ENABLED_FOR_BUNDLE_SLOT): { + bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID()); + if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) { + return ERR_ANS_NON_SYSTEM_APP; + } + + if (!AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) { + return ERR_ANS_PERMISSION_DENIED; + } + + return ERR_OK; + } + default: { + ANS_LOGE("[OnRemoteRequest] fail: unknown code!"); + return ERR_ANS_INVALID_PARAM; + } + } +} + +void SlotManager::GenerateSlotReminderMode(const sptr &slot, + const sptr &bundle, bool isSpecifiedSlot, uint32_t defaultSlotFlags) +{ + uint32_t slotFlags = defaultSlotFlags; + auto ret = NotificationPreferences::GetInstance()->GetNotificationSlotFlagsForBundle(bundle, slotFlags); + if (ret != ERR_OK) { + ANS_LOGI("Failed to get slotflags for bundle, use default slotflags."); + } + + auto configSlotReminderMode = + DelayedSingleton::GetInstance()->GetConfigSlotReminderModeByType(slot->GetType()); + if (isSpecifiedSlot) { + slot->SetReminderMode(configSlotReminderMode & slotFlags & slot->GetReminderMode()); + } else { + slot->SetReminderMode(configSlotReminderMode & slotFlags); + } + + std::string bundleName = (bundle == nullptr) ? "" : bundle->GetBundleName(); + ANS_LOGI("The reminder mode of %{public}d is %{public}d in %{public}s,specifiedSlot:%{public}d default:%{public}u", + slot->GetType(), slot->GetReminderMode(), bundleName.c_str(), isSpecifiedSlot, defaultSlotFlags); +} +} // namespace Notification +} // namespace OHOS diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index c462c4ce6..473d59d44 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -309,6 +309,7 @@ ohos_unittest("notification_service_test") { "advanced_notification_service_test.cpp", "advanced_notification_slot_service_test.cpp", "advanced_notification_utils_test.cpp", + "ans_manager_stub_test.cpp", "clone_test/notification_clone_bundle_info_test.cpp", "mock/blob.cpp", "mock/distributed_kv_data_manager.cpp", diff --git a/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp b/services/ans/test/unittest/ans_manager_stub_test.cpp similarity index 100% rename from frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp rename to services/ans/test/unittest/ans_manager_stub_test.cpp diff --git a/test/fuzztest/ansmanagerstubannexthree_fuzzer/BUILD.gn b/test/fuzztest/ansmanagerstubannexthree_fuzzer/BUILD.gn index edb15b1dd..3de53d93c 100644 --- a/test/fuzztest/ansmanagerstubannexthree_fuzzer/BUILD.gn +++ b/test/fuzztest/ansmanagerstubannexthree_fuzzer/BUILD.gn @@ -34,6 +34,7 @@ ohos_fuzztest("AnsManagerStubAnnexThreeFuzzTest") { deps = [ "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", "${frameworks_module_ans_path}:ans_innerkits", + "${services_path}/ans:ans_service_sources", ] external_deps = [ diff --git a/test/fuzztest/ansmanagerstubannextwo_fuzzer/BUILD.gn b/test/fuzztest/ansmanagerstubannextwo_fuzzer/BUILD.gn index ac4595be6..7d9bf9100 100644 --- a/test/fuzztest/ansmanagerstubannextwo_fuzzer/BUILD.gn +++ b/test/fuzztest/ansmanagerstubannextwo_fuzzer/BUILD.gn @@ -34,6 +34,7 @@ ohos_fuzztest("AnsManagerStubAnnexTwoFuzzTest") { deps = [ "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", "${frameworks_module_ans_path}:ans_innerkits", + "${services_path}/ans:ans_service_sources", ] external_deps = [ diff --git a/tools/test/unittest/dump/BUILD.gn b/tools/test/unittest/dump/BUILD.gn index bcf940b4a..08247e9d0 100644 --- a/tools/test/unittest/dump/BUILD.gn +++ b/tools/test/unittest/dump/BUILD.gn @@ -60,6 +60,7 @@ ohos_unittest("notification_shell_command_dump_test") { deps = [ "${frameworks_module_ans_path}:ans_innerkits", + "${services_path}/ans:ans_service_sources", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] -- Gitee