From d136b70aad2f92f759bd2727ef42d9f5015054e2 Mon Sep 17 00:00:00 2001 From: zhangzezhong Date: Mon, 19 May 2025 21:23:07 +0800 Subject: [PATCH] ans add fuzz test Signed-off-by: zhangzezhong --- test/fuzztest/BUILD.gn | 1 + .../ansmanagerstub_fuzzer.cpp | 70 ++++- .../ansmanagerstubannex_fuzzer.cpp | 179 +++++++++++-- .../ansmanagerstubannexthree_fuzzer/BUILD.gn | 120 +++++++++ .../ansmanagerstubannexthree_fuzzer.cpp | 251 ++++++++++++++++++ .../ansmanagerstubannexthree_fuzzer.h | 24 ++ .../corpus/init | 13 + .../project.xml | 25 ++ 8 files changed, 662 insertions(+), 21 deletions(-) create mode 100644 test/fuzztest/ansmanagerstubannexthree_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp create mode 100644 test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.h create mode 100644 test/fuzztest/ansmanagerstubannexthree_fuzzer/corpus/init create mode 100644 test/fuzztest/ansmanagerstubannexthree_fuzzer/project.xml diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index d3443b844..06f73fb19 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -21,6 +21,7 @@ group("fuzztest") { "advancednotificationservice_fuzzer:AdvancedNotificationServiceFuzzTest", "ansmanagerstub_fuzzer:AnsManagerStubFuzzTest", "ansmanagerstubannex_fuzzer:AnsManagerStubAnnexFuzzTest", + "ansmanagerstubannexthree_fuzzer:AnsManagerStubAnnexThreeFuzzTest", "ansmanagerstubannextwo_fuzzer:AnsManagerStubAnnexTwoFuzzTest", "anssubscriberproxy_fuzzer:AnsSubscriberProxyFuzzTest", "anssubscriberstub_fuzzer:AnsSubscriberStubFuzzTest", diff --git a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp index 395791700..15f69d257 100644 --- a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp @@ -20,10 +20,14 @@ #include "advanced_notification_service.h" #undef private #undef protected +#include "ans_dialog_callback_proxy.h" #include "ans_permission_def.h" #include "ansmanagerstub_fuzzer.h" #include "notification_record.h" #include "notification_request.h" +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED +#include "swing_call_back_proxy.h" +#endif constexpr uint8_t SLOT_TYPE_NUM = 5; @@ -42,6 +46,7 @@ namespace OHOS { auto content = std::make_shared(); notification->SetContent(std::make_shared(content)); service->Publish(stringData, notification); + service->PublishWithMaxCapacity(stringData, notification); int notificationId = fuzzData->ConsumeIntegral(); service->Cancel(notificationId, stringData, fuzzData->ConsumeRandomLengthString()); service->CancelAll(fuzzData->ConsumeRandomLengthString()); @@ -63,6 +68,7 @@ namespace OHOS { bundleOption->SetUid(fuzzData->ConsumeIntegral()); uint64_t num = fuzzData->ConsumeIntegral(); service->CancelAsBundle(bundleOption, fuzzData->ConsumeIntegral()); + service->CancelAsBundle(bundleOption, fuzzData->ConsumeIntegral(), userId); service->CancelAsBundleWithAgent(bundleOption, fuzzData->ConsumeIntegral()); service->GetSlotNumAsBundle(bundleOption, num); std::vector> notifications; @@ -75,6 +81,7 @@ namespace OHOS { bool canPublish = fuzzData->ConsumeBool(); service->CanPublishAsBundle(stringData, canPublish); service->PublishAsBundle(notification, stringData); + service->PublishAsBundleWithMaxCapacity(notification, stringData); service->SetNotificationBadgeNum(num); int importance = fuzzData->ConsumeIntegral(); service->GetBundleImportance(importance); @@ -98,14 +105,15 @@ namespace OHOS { sptr info = new Notification::NotificationSubscribeInfo(); bool allowed = fuzzData->ConsumeBool(); service->IsAllowedNotify(allowed); + service->IsAllowedNotifySelf(allowed); service->IsAllowedNotifySelf(bundleOption, allowed); service->IsAllowedNotifyForBundle(bundleOption, allowed); service->IsSpecialBundleAllowedNotify(bundleOption, allowed); service->CancelGroup(stringData, fuzzData->ConsumeRandomLengthString()); service->RemoveGroupByBundle(bundleOption, stringData); sptr date = new Notification::NotificationDoNotDisturbDate(); - service->SetDoNotDisturbDate(date); - service->GetDoNotDisturbDate(date); + service->SetDoNotDisturbDateByUser(userId, date); + service->GetDoNotDisturbDateByUser(userId, date); bool doesSupport = fuzzData->ConsumeBool(); service->DoesSupportDoNotDisturbMode(doesSupport); service->IsDistributedEnabled(enabled); @@ -144,6 +152,8 @@ namespace OHOS { std::vector> recordList; bool isNative = fuzzData->ConsumeBool(); service->CanPopEnableNotificationDialog(nullptr, enable, bundleName); + service->RemoveEnableNotificationDialog(); + service->RemoveEnableNotificationDialog(bundleOption); std::vector keys; std::string key1 = fuzzData->ConsumeRandomLengthString(); keys.emplace_back(fuzzData->ConsumeRandomLengthString()); @@ -173,7 +183,11 @@ namespace OHOS { service->RemoveExpiredUniqueKey(); service->SetSmartReminderEnabled(deviceType, enabled); service->IsSmartReminderEnabled(deviceType, enabled); - service->SetTargetDeviceStatus(deviceType, fuzzData->ConsumeIntegral(), ""); + + uint32_t status = fuzzData->ConsumeIntegral(); + uint32_t controlFlag = fuzzData->ConsumeIntegral(); + service->SetTargetDeviceStatus(deviceType, status, stringData); + service->SetTargetDeviceStatus(deviceType, status, controlFlag, stringData); service->ClearAllNotificationGroupInfo(localSwitch); service->SetSlotFlagsAsBundle(bundleOption, fuzzData->ConsumeIntegral()); @@ -196,6 +210,56 @@ namespace OHOS { service->RegisterPushCallback(nullptr, notificationCheckRequest); service->UnregisterPushCallback(); service->SetAdditionConfig(key1, value); + service->PublishNotificationForIndirectProxy(notification); + service->PublishNotificationForIndirectProxyWithMaxCapacity(notification); + + bool enabledByslot; + service->GetEnabledForBundleSlotSelf(slotType, enabledByslot); + + service->Subscribe(nullptr, info); + service->Subscribe(nullptr); + service->Unsubscribe(nullptr, info); + service->Unsubscribe(nullptr); + service->SubscribeSelf(nullptr); + + service->SubscribeLocalLiveView(nullptr, info, isNative); + service->SubscribeLocalLiveView(nullptr, isNative); + + int32_t uid = fuzzData->ConsumeIntegral(); + sptr callback = new Notification::AnsDialogCallbackProxy(nullptr); + service->RequestEnableNotification(stringData, callback, nullptr); + service->RequestEnableNotification(stringData, callback); + + service->SetDistributedEnabledBySlot(slotType, deviceType, enabled); + service->GetAllDistribuedEnabledBundles(deviceType, bundleOptions); + std::vector> notificationsVector; + service->GetAllNotificationsBySlotType(notificationsVector, slotType); + service->AllowUseReminder(bundleName, allowed); + int32_t deviceStatus; + service->GetTargetDeviceStatus(deviceType, deviceStatus); + bool isPaused = fuzzData->ConsumeBool(); + service->UpdateNotificationTimerByUid(uid, isPaused); + + service->SetBadgeNumberForDhByBundle(bundleOption, badgeNum); + service->GetNotificationRequestByHashCode(stringData, notification); + sptr operationInfo = new Notification::NotificationOperationInfo(); + operationInfo->SetActionName(fuzzData->ConsumeRandomLengthString()); + operationInfo->SetUserInput(fuzzData->ConsumeRandomLengthString()); + operationInfo->SetHashCode(fuzzData->ConsumeRandomLengthString()); + operationInfo->SetEventId(fuzzData->ConsumeRandomLengthString()); + service->DistributeOperation(operationInfo, nullptr); + service->SetHashCodeRule(fuzzData->ConsumeIntegral()); + service->GetAllLiveViewEnabledBundles(bundleOptions); + sptr notificationDisable = new Notification::NotificationDisable(); + service->DisableNotificationFeature(notificationDisable); + service->ReplyDistributeOperation(stringData, fuzzData->ConsumeIntegral()); + service->UpdateNotificationTimerByUid(uid, isPaused); + +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED + sptr swingCallBack = new Notification::SwingCallBackProxy(nullptr); + service->RegisterSwingCallback(swingCallBack->AsObject()); +#endif + return true; } } diff --git a/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp index 9affb2969..758fd77f1 100644 --- a/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp @@ -20,9 +20,11 @@ #undef protected #include "ans_dialog_callback_proxy.h" #include "ans_permission_def.h" -#include "ans_subscriber_proxy.h" #include "ansmanagerstubannex_fuzzer.h" #include "reminder_request_timer.h" +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED +#include "swing_call_back_proxy.h" +#endif constexpr uint8_t SLOT_TYPE_NUM = 5; @@ -32,33 +34,92 @@ namespace OHOS { auto service = std::make_shared(); service->InitPublishProcess(); service->CreateDialogManager(); + + bool allowed = fuzzData->ConsumeBool(); + bool canPublish = fuzzData->ConsumeBool(); + bool enabled = fuzzData->ConsumeBool(); + bool granted = fuzzData->ConsumeBool(); + bool isForceControl = fuzzData->ConsumeBool(); + bool isNative = fuzzData->ConsumeBool(); + bool isPaused = fuzzData->ConsumeBool(); + bool support = fuzzData->ConsumeBool(); + + uint8_t type = fuzzData->ConsumeIntegral() % SLOT_TYPE_NUM; + uint32_t controlFlag = fuzzData->ConsumeIntegral(); + uint32_t hashCodeType = fuzzData->ConsumeIntegral(); + uint32_t slotFlags = fuzzData->ConsumeIntegral(); + uint32_t status = fuzzData->ConsumeIntegral(); + int32_t badgeNum = fuzzData->ConsumeIntegral(); + int32_t callerType = fuzzData->ConsumeIntegral(); + int32_t deviceIds = fuzzData->ConsumeIntegral(); + int32_t deviceStatus = fuzzData->ConsumeIntegral(); + int32_t importance = fuzzData->ConsumeIntegral(); + int32_t notificationId = fuzzData->ConsumeIntegral(); + int32_t remindType = fuzzData->ConsumeIntegral(); + int32_t removeReason = fuzzData->ConsumeIntegral(); + int32_t result = fuzzData->ConsumeIntegral(); + int32_t uid = fuzzData->ConsumeIntegral(); + int32_t userId = fuzzData->ConsumeIntegral(); + uint64_t num = fuzzData->ConsumeIntegral(); + int64_t id = fuzzData->ConsumeIntegral(); + std::string stringData = fuzzData->ConsumeRandomLengthString(); + std::string phoneNumber = fuzzData->ConsumeRandomLengthString(); + std::string deviceType = fuzzData->ConsumeRandomLengthString(); + std::string bundleName = fuzzData->ConsumeRandomLengthString(); + std::string value = fuzzData->ConsumeRandomLengthString(); + std::string key1 = fuzzData->ConsumeRandomLengthString(); + std::vector keys; + keys.emplace_back(fuzzData->ConsumeRandomLengthString()); + + sptr buttonOption = new Notification::NotificationButtonOption(); sptr bundleOption = new Notification::NotificationBundleOption(); bundleOption->SetBundleName(fuzzData->ConsumeRandomLengthString()); bundleOption->SetUid(fuzzData->ConsumeIntegral()); - int32_t removeReason = fuzzData->ConsumeIntegral(); - std::vector> slots; - bool allowed = fuzzData->ConsumeBool(); - int32_t userId = fuzzData->ConsumeIntegral(); sptr info = new Notification::NotificationSubscribeInfo(); - uint8_t type = fuzzData->ConsumeIntegral() % SLOT_TYPE_NUM; Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(type); + sptr notificationRequest = new Notification::NotificationRequest(); + notificationRequest->SetOwnerUid(fuzzData->ConsumeIntegral()); + notificationRequest->SetCreatorUid(fuzzData->ConsumeIntegral()); + notificationRequest->SetSlotType(Notification::NotificationConstant::SlotType::LIVE_VIEW); + auto content = std::make_shared(); + notificationRequest->SetContent(std::make_shared(content)); + sptr operationInfo = new Notification::NotificationOperationInfo(); + operationInfo->SetActionName(fuzzData->ConsumeRandomLengthString()); + operationInfo->SetUserInput(fuzzData->ConsumeRandomLengthString()); + operationInfo->SetHashCode(fuzzData->ConsumeRandomLengthString()); + operationInfo->SetEventId(fuzzData->ConsumeRandomLengthString()); + + sptr notificationDisable = new Notification::NotificationDisable(); + sptr slot = new Notification::NotificationSlot(); + sptr disturbDate = new Notification::NotificationDoNotDisturbDate(); + sptr callback = new Notification::AnsDialogCallbackProxy(nullptr); + sptr notificationCheckRequest = + new Notification::NotificationCheckRequest(); + + std::vector> profiles; + sptr profile = + new Notification::NotificationDoNotDisturbProfile(); + profiles.emplace_back(profile); + + std::vector> notificationsVector; + std::vector bundleOptions; + std::vector> slots; + std::vector> notificationRequests; service->Delete(stringData, removeReason); service->DeleteByBundle(bundleOption); service->DeleteAll(); service->GetSlotsByBundle(bundleOption, slots); service->UpdateSlots(bundleOption, slots); - - bool enabled = fuzzData->ConsumeBool(); service->SetNotificationsEnabledForBundle(stringData, enabled); service->SetNotificationsEnabledForAllBundles(stringData, enabled); service->SetNotificationsEnabledForSpecialBundle(stringData, bundleOption, enabled); service->SetShowBadgeEnabledForBundle(bundleOption, enabled); service->GetShowBadgeEnabledForBundle(bundleOption, enabled); service->GetShowBadgeEnabled(enabled); - service->IsAllowedNotify(allowed); + service->IsAllowedNotifySelf(allowed); service->IsAllowedNotifySelf(bundleOption, allowed); service->IsSpecialBundleAllowedNotify(bundleOption, allowed); service->CancelGroup(stringData, fuzzData->ConsumeRandomLengthString()); @@ -68,23 +129,105 @@ namespace OHOS { service->EnableDistributedSelf(enabled); service->EnableDistributed(enabled); service->IsDistributedEnableByBundle(bundleOption, enabled); - int32_t remindType; service->GetDeviceRemindType(remindType); - std::vector dumpInfo; - service->ShellDump(stringData, stringData, userId, userId, dumpInfo); - - bool support = fuzzData->ConsumeBool(); + service->ShellDump(stringData, stringData, userId, userId, keys); service->IsSupportTemplate(stringData, support); service->IsSpecialUserAllowedNotify(userId, allowed); - - int32_t deviceIds = fuzzData->ConsumeIntegral(); service->SetNotificationsEnabledByUser(deviceIds, enabled); service->DeleteAllByUser(userId); + service->SetEnabledForBundleSlot(bundleOption, slotType, enabled, isForceControl); + service->RequestEnableNotification(stringData, callback, nullptr); + service->RequestEnableNotification(stringData, callback); + service->Subscribe(nullptr, info); + service->Subscribe(nullptr); + service->Unsubscribe(nullptr, info); + service->Unsubscribe(nullptr); + service->SubscribeLocalLiveView(nullptr, info, isNative); + service->SubscribeLocalLiveView(nullptr, isNative); + service->IsNeedSilentInDoNotDisturbMode(phoneNumber, callerType); + service->Publish(stringData, notificationRequest); + service->PublishWithMaxCapacity(stringData, notificationRequest); + service->PublishNotificationForIndirectProxy(notificationRequest); + service->PublishNotificationForIndirectProxyWithMaxCapacity(notificationRequest); + service->CancelAsBundle(notificationId, stringData, userId); + service->CancelAsBundle(bundleOption, notificationId); + service->CancelAsBundle(bundleOption, notificationId, userId); + service->CancelAll(key1); + service->Cancel(notificationId, stringData, key1); + service->AddSlotByType(slotType); + service->AddSlots(slots); + service->RemoveSlotByType(slotType); + service->RemoveAllSlots(); + service->GetSlots(slots); + service->GetSlotByType(slotType, slot); + service->GetSlotNumAsBundle(bundleOption, num); + service->SetSlotFlagsAsBundle(bundleOption, slotFlags); + service->GetSlotFlagsAsBundle(bundleOption, slotFlags); + service->GetActiveNotifications(notificationRequests, key1); + service->GetActiveNotificationNums(num); + service->GetAllActiveNotifications(notificationsVector); + service->GetSpecialActiveNotifications(keys, notificationsVector); + service->GetActiveNotificationByFilter(bundleOption, notificationId, stringData, keys, notificationRequest); + service->CanPublishAsBundle(stringData, canPublish); + service->PublishAsBundle(notificationRequest, stringData); + service->PublishAsBundleWithMaxCapacity(notificationRequest, stringData); + service->SetNotificationBadgeNum(num); + service->GetBundleImportance(importance); + service->PublishContinuousTaskNotification(notificationRequest); + service->CancelContinuousTaskNotification(stringData, notificationId); + service->HasNotificationPolicyAccessPermission(granted); + service->TriggerLocalLiveView(bundleOption, notificationId, buttonOption); + service->RemoveNotification(bundleOption, notificationId, stringData, removeReason); + service->RemoveAllNotifications(bundleOption); + service->RemoveNotifications(keys, removeReason); + service->GetSlotByBundle(bundleOption, slotType, slot); + service->CanPopEnableNotificationDialog(nullptr, enabled, bundleName); + service->RemoveEnableNotificationDialog(); + service->RemoveEnableNotificationDialog(bundleOption); + service->GetEnabledForBundleSlot(bundleOption, slotType, enabled); + service->GetEnabledForBundleSlotSelf(slotType, enabled); + service->SetSyncNotificationEnabledWithoutApp(userId, enabled); + service->GetSyncNotificationEnabledWithoutApp(userId, enabled); + service->SetBadgeNumber(badgeNum, key1); + service->SetBadgeNumberByBundle(bundleOption, badgeNum); + service->GetAllNotificationEnabledBundles(bundleOptions); + service->RegisterPushCallback(nullptr, notificationCheckRequest); + service->UnregisterPushCallback(); + service->SetDistributedEnabledBySlot(slotType, deviceType, enabled); + service->GetAllDistribuedEnabledBundles(deviceType, bundleOptions); + service->GetAllNotificationsBySlotType(notificationsVector, slotType); + service->AllowUseReminder(bundleName, allowed); + service->SetTargetDeviceStatus(deviceType, status, stringData); + service->SetTargetDeviceStatus(deviceType, status, controlFlag, stringData); + service->SetDistributedEnabledByBundle(bundleOption, deviceType, enabled); + service->IsDistributedEnabledByBundle(bundleOption, deviceType, enabled); + service->SetSmartReminderEnabled(deviceType, enabled); + service->IsSmartReminderEnabled(deviceType, enabled); + service->SetAdditionConfig(key1, value); + service->CancelAsBundleWithAgent(bundleOption, userId); + service->GetTargetDeviceStatus(deviceType, deviceStatus); - sptr disturbDate = new Notification::NotificationDoNotDisturbDate(); + service->AddDoNotDisturbProfiles(profiles); + service->RemoveDoNotDisturbProfiles(profiles); service->SetDoNotDisturbDate(disturbDate); service->GetDoNotDisturbDate(disturbDate); - service->SetEnabledForBundleSlot(bundleOption, slotType, enabled, fuzzData->ConsumeBool()); + service->SetDoNotDisturbDateByUser(userId, disturbDate); + service->GetDoNotDisturbDateByUser(userId, disturbDate); + service->GetDoNotDisturbProfile(id, profile); + service->DoesSupportDoNotDisturbMode(support); + + service->SetBadgeNumberForDhByBundle(bundleOption, badgeNum); + service->GetNotificationRequestByHashCode(stringData, notificationRequest); + service->DistributeOperation(operationInfo, nullptr); + service->SetHashCodeRule(hashCodeType); + service->GetAllLiveViewEnabledBundles(bundleOptions); + service->DisableNotificationFeature(notificationDisable); + service->ReplyDistributeOperation(stringData, result); + service->UpdateNotificationTimerByUid(uid, isPaused); +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED + sptr swingCallBack = new Notification::SwingCallBackProxy(nullptr); + service->RegisterSwingCallback(swingCallBack->AsObject()); +#endif return true; } } diff --git a/test/fuzztest/ansmanagerstubannexthree_fuzzer/BUILD.gn b/test/fuzztest/ansmanagerstubannexthree_fuzzer/BUILD.gn new file mode 100644 index 000000000..0b99bb6ed --- /dev/null +++ b/test/fuzztest/ansmanagerstubannexthree_fuzzer/BUILD.gn @@ -0,0 +1,120 @@ +# Copyright (c) 2022 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("AnsManagerStubAnnexThreeFuzzTest") { + module_out_path = service_fuzz_test_path + fuzz_config_file = + "${component_path}/test/fuzztest/ansmanagerstubannexthree_fuzzer" + + include_dirs = [ + "${component_path}/test/fuzztest/fuzz_common_base", + "${services_path}/ans/include", + "${core_path}/include" + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "ansmanagerstubannexthree_fuzzer.cpp" ] + + 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 = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "ffrt:libffrt", + "hilog:libhilog", + "kv_store:distributeddata_inner", + "image_framework:image_native", + "ipc:ipc_single", + "relational_store:native_rdb", + ] + + defines = [] + + if (is_double_framework) { + cflags += [ "-DCONFIG_DUAL_FRAMEWORK" ] + } + + if (distributed_notification_supported) { + defines += [ "DISTRIBUTED_NOTIFICATION_SUPPORTED" ] + deps += [ "${services_path}/distributed:libans_distributed" ] + include_dirs += [ "${services_path}/distributed/include" ] + } + + if (notification_smart_reminder_supported) { + defines += [ "NOTIFICATION_SMART_REMINDER_SUPPORTED" ] + } + + if (player_framework) { + external_deps += [ "player_framework:media_client" ] + defines += [ "PLAYER_FRAMEWORK_ENABLE" ] + } + + if (ans_hitrace_usage) { + external_deps += [ "hitrace:hitrace_meter" ] + defines += [ "HITRACE_METER_ENABLE" ] + } + + if (ans_config_policy_enable) { + external_deps += [ "config_policy:configpolicy_util" ] + defines += [ "CONFIG_POLICY_ENABLE" ] + } + + if (screenlock_mgr_enable) { + external_deps += [ "screenlock_mgr:screenlock_client" ] + defines += [ "SCREENLOCK_MGR_ENABLE" ] + } + + if (distributed_notification_service_feature_summary || + distributed_notification_service_feature_additional_control) { + defines += [ "ENABLE_ANS_EXT_WRAPPER" ] + } + + if (distributed_notification_service_feature_additional_control) { + defines += [ "ENABLE_ANS_ADDITIONAL_CONTROL" ] + } + + if (distributed_notification_service_feature_summary) { + defines += [ "ENABLE_ANS_AGGREGATION" ] + } + + if (telephony_cust) { + defines += [ "ENABLE_ANS_TELEPHONY_CUST_WRAPPER" ] + } + + if (distributed_notification_service_feature_disable_fa_model) { + defines += [ "ANS_DISABLE_FA_MODEL" ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":AnsManagerStubAnnexThreeFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp new file mode 100644 index 000000000..cf18bd29b --- /dev/null +++ b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp @@ -0,0 +1,251 @@ +/* + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#define private public +#define protected public +#include "advanced_notification_service.h" +#undef private +#undef protected +#include "ans_dialog_callback_proxy.h" +#include "ans_permission_def.h" +#include "ans_subscriber_local_live_view_proxy.h" +#include "ans_subscriber_proxy.h" +#include "ansmanagerstubannexthree_fuzzer.h" +#include "reminder_request_timer.h" +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED +#include "swing_call_back_proxy.h" +#endif + +constexpr uint8_t SLOT_TYPE_NUM = 5; + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) + { + auto service = std::make_shared(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + bool allowed = fuzzData->ConsumeBool(); + bool canPublish = fuzzData->ConsumeBool(); + bool enabled = fuzzData->ConsumeBool(); + bool granted = fuzzData->ConsumeBool(); + bool isForceControl = fuzzData->ConsumeBool(); + bool isNative = fuzzData->ConsumeBool(); + bool isPaused = fuzzData->ConsumeBool(); + bool support = fuzzData->ConsumeBool(); + + uint8_t type = fuzzData->ConsumeIntegral() % SLOT_TYPE_NUM; + uint32_t controlFlag = fuzzData->ConsumeIntegral(); + uint32_t hashCodeType = fuzzData->ConsumeIntegral(); + uint32_t slotFlags = fuzzData->ConsumeIntegral(); + uint32_t status = fuzzData->ConsumeIntegral(); + int32_t badgeNum = fuzzData->ConsumeIntegral(); + int32_t callerType = fuzzData->ConsumeIntegral(); + int32_t deviceIds = fuzzData->ConsumeIntegral(); + int32_t deviceStatus = fuzzData->ConsumeIntegral(); + int32_t importance = fuzzData->ConsumeIntegral(); + int32_t notificationId = fuzzData->ConsumeIntegral(); + int32_t remindType = fuzzData->ConsumeIntegral(); + int32_t removeReason = fuzzData->ConsumeIntegral(); + int32_t result = fuzzData->ConsumeIntegral(); + int32_t uid = fuzzData->ConsumeIntegral(); + int32_t userId = fuzzData->ConsumeIntegral(); + uint64_t num = fuzzData->ConsumeIntegral(); + int64_t id = fuzzData->ConsumeIntegral(); + + std::string stringData = fuzzData->ConsumeRandomLengthString(); + std::string phoneNumber = fuzzData->ConsumeRandomLengthString(); + std::string deviceType = fuzzData->ConsumeRandomLengthString(); + std::string bundleName = fuzzData->ConsumeRandomLengthString(); + std::string value = fuzzData->ConsumeRandomLengthString(); + std::string key1 = fuzzData->ConsumeRandomLengthString(); + std::vector keys; + keys.emplace_back(fuzzData->ConsumeRandomLengthString()); + + sptr buttonOption = new Notification::NotificationButtonOption(); + sptr bundleOption = new Notification::NotificationBundleOption(); + bundleOption->SetBundleName(fuzzData->ConsumeRandomLengthString()); + bundleOption->SetUid(fuzzData->ConsumeIntegral()); + sptr info = new Notification::NotificationSubscribeInfo(); + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(type); + sptr notificationRequest = new Notification::NotificationRequest(); + notificationRequest->SetOwnerUid(fuzzData->ConsumeIntegral()); + notificationRequest->SetCreatorUid(fuzzData->ConsumeIntegral()); + notificationRequest->SetSlotType(Notification::NotificationConstant::SlotType::LIVE_VIEW); + auto content = std::make_shared(); + notificationRequest->SetContent(std::make_shared(content)); + sptr operationInfo = new Notification::NotificationOperationInfo(); + operationInfo->SetActionName(fuzzData->ConsumeRandomLengthString()); + operationInfo->SetUserInput(fuzzData->ConsumeRandomLengthString()); + operationInfo->SetHashCode(fuzzData->ConsumeRandomLengthString()); + operationInfo->SetEventId(fuzzData->ConsumeRandomLengthString()); + + sptr notificationDisable = new Notification::NotificationDisable(); + sptr slot = new Notification::NotificationSlot(); + sptr disturbDate = new Notification::NotificationDoNotDisturbDate(); + sptr callback = new Notification::AnsDialogCallbackProxy(nullptr); + sptr notificationCheckRequest = + new Notification::NotificationCheckRequest(); + + std::vector> profiles; + sptr profile = + new Notification::NotificationDoNotDisturbProfile(); + profiles.emplace_back(profile); + + std::vector> notificationsVector; + std::vector bundleOptions; + std::vector> slots; + std::vector> notificationRequests; + + service->Delete(stringData, removeReason); + service->DeleteByBundle(bundleOption); + service->DeleteAll(); + service->GetSlotsByBundle(bundleOption, slots); + service->UpdateSlots(bundleOption, slots); + service->SetNotificationsEnabledForBundle(stringData, enabled); + service->SetNotificationsEnabledForAllBundles(stringData, enabled); + service->SetNotificationsEnabledForSpecialBundle(stringData, bundleOption, enabled); + service->SetShowBadgeEnabledForBundle(bundleOption, enabled); + service->GetShowBadgeEnabledForBundle(bundleOption, enabled); + service->GetShowBadgeEnabled(enabled); + service->IsAllowedNotify(allowed); + service->IsAllowedNotifySelf(allowed); + service->IsAllowedNotifySelf(bundleOption, allowed); + service->IsSpecialBundleAllowedNotify(bundleOption, allowed); + service->CancelGroup(stringData, fuzzData->ConsumeRandomLengthString()); + service->RemoveGroupByBundle(bundleOption, stringData); + service->IsDistributedEnabled(enabled); + service->EnableDistributedByBundle(bundleOption, enabled); + service->EnableDistributedSelf(enabled); + service->EnableDistributed(enabled); + service->IsDistributedEnableByBundle(bundleOption, enabled); + service->GetDeviceRemindType(remindType); + service->ShellDump(stringData, stringData, userId, userId, keys); + service->IsSupportTemplate(stringData, support); + service->IsSpecialUserAllowedNotify(userId, allowed); + service->SetNotificationsEnabledByUser(deviceIds, enabled); + service->DeleteAllByUser(userId); + service->SetEnabledForBundleSlot(bundleOption, slotType, enabled, isForceControl); + service->RequestEnableNotification(stringData, callback, nullptr); + service->RequestEnableNotification(stringData, callback); + service->Subscribe(nullptr, info); + service->Subscribe(nullptr); + service->Unsubscribe(nullptr, info); + service->Unsubscribe(nullptr); + service->SubscribeLocalLiveView(nullptr, info, isNative); + service->SubscribeLocalLiveView(nullptr, isNative); + service->IsNeedSilentInDoNotDisturbMode(phoneNumber, callerType); + service->Publish(stringData, notificationRequest); + service->PublishWithMaxCapacity(stringData, notificationRequest); + service->PublishNotificationForIndirectProxy(notificationRequest); + service->PublishNotificationForIndirectProxyWithMaxCapacity(notificationRequest); + service->CancelAsBundle(notificationId, stringData, userId); + service->CancelAsBundle(bundleOption, notificationId); + service->CancelAsBundle(bundleOption, notificationId, userId); + service->CancelAll(key1); + service->Cancel(notificationId, stringData, key1); + service->AddSlotByType(slotType); + service->AddSlots(slots); + service->RemoveSlotByType(slotType); + service->RemoveAllSlots(); + service->GetSlots(slots); + service->GetSlotByType(slotType, slot); + service->GetSlotNumAsBundle(bundleOption, num); + service->SetSlotFlagsAsBundle(bundleOption, slotFlags); + service->GetSlotFlagsAsBundle(bundleOption, slotFlags); + service->GetActiveNotifications(notificationRequests, key1); + service->GetActiveNotificationNums(num); + service->GetAllActiveNotifications(notificationsVector); + service->GetSpecialActiveNotifications(keys, notificationsVector); + service->GetActiveNotificationByFilter(bundleOption, notificationId, stringData, keys, notificationRequest); + service->CanPublishAsBundle(stringData, canPublish); + service->PublishAsBundle(notificationRequest, stringData); + service->PublishAsBundleWithMaxCapacity(notificationRequest, stringData); + service->SetNotificationBadgeNum(num); + service->GetBundleImportance(importance); + service->PublishContinuousTaskNotification(notificationRequest); + service->CancelContinuousTaskNotification(stringData, notificationId); + service->HasNotificationPolicyAccessPermission(granted); + service->TriggerLocalLiveView(bundleOption, notificationId, buttonOption); + service->RemoveNotification(bundleOption, notificationId, stringData, removeReason); + service->RemoveAllNotifications(bundleOption); + service->RemoveNotifications(keys, removeReason); + service->GetSlotByBundle(bundleOption, slotType, slot); + service->CanPopEnableNotificationDialog(nullptr, enabled, bundleName); + service->RemoveEnableNotificationDialog(); + service->RemoveEnableNotificationDialog(bundleOption); + service->GetEnabledForBundleSlot(bundleOption, slotType, enabled); + service->GetEnabledForBundleSlotSelf(slotType, enabled); + service->SetSyncNotificationEnabledWithoutApp(userId, enabled); + service->GetSyncNotificationEnabledWithoutApp(userId, enabled); + service->SetBadgeNumber(badgeNum, key1); + service->SetBadgeNumberByBundle(bundleOption, badgeNum); + service->GetAllNotificationEnabledBundles(bundleOptions); + service->RegisterPushCallback(nullptr, notificationCheckRequest); + service->UnregisterPushCallback(); + service->SetDistributedEnabledBySlot(slotType, deviceType, enabled); + service->GetAllDistribuedEnabledBundles(deviceType, bundleOptions); + service->GetAllNotificationsBySlotType(notificationsVector, slotType); + service->AllowUseReminder(bundleName, allowed); + service->SetTargetDeviceStatus(deviceType, status, stringData); + service->SetTargetDeviceStatus(deviceType, status, controlFlag, stringData); + service->SetDistributedEnabledByBundle(bundleOption, deviceType, enabled); + service->IsDistributedEnabledByBundle(bundleOption, deviceType, enabled); + service->SetSmartReminderEnabled(deviceType, enabled); + service->IsSmartReminderEnabled(deviceType, enabled); + service->SetAdditionConfig(key1, value); + service->CancelAsBundleWithAgent(bundleOption, userId); + service->GetTargetDeviceStatus(deviceType, deviceStatus); + + service->AddDoNotDisturbProfiles(profiles); + service->RemoveDoNotDisturbProfiles(profiles); + service->SetDoNotDisturbDate(disturbDate); + service->GetDoNotDisturbDate(disturbDate); + service->SetDoNotDisturbDateByUser(userId, disturbDate); + service->GetDoNotDisturbDateByUser(userId, disturbDate); + service->GetDoNotDisturbProfile(id, profile); + service->DoesSupportDoNotDisturbMode(support); + + service->SetBadgeNumberForDhByBundle(bundleOption, badgeNum); + service->GetNotificationRequestByHashCode(stringData, notificationRequest); + service->DistributeOperation(operationInfo, nullptr); + service->SetHashCodeRule(hashCodeType); + service->GetAllLiveViewEnabledBundles(bundleOptions); + service->DisableNotificationFeature(notificationDisable); + service->ReplyDistributeOperation(stringData, result); + service->UpdateNotificationTimerByUid(uid, isPaused); +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED + sptr swingCallBack = new Notification::SwingCallBackProxy(nullptr); + service->RegisterSwingCallback(swingCallBack->AsObject()); +#endif + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + NativeTokenGet(requestPermission); + OHOS::DoSomethingInterestingWithMyAPI(&fdp); + return 0; +} diff --git a/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.h b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.h new file mode 100644 index 000000000..baa7e06d7 --- /dev/null +++ b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2022 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 TEST_FUZZTEST_ANSMANAGERSTUBANNEXTHREE_FUZZER_ANSMANAGERSTUBANNEXTHREE_FUZZER_H +#define TEST_FUZZTEST_ANSMANAGERSTUBANNEXTHREE_FUZZER_ANSMANAGERSTUBANNEXTHREE_FUZZER_H + +#include +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "ansmanagerstubannexthree_fuzzer" + +#endif // TEST_FUZZTEST_ANSMANAGERSTUBANNEXTHREE_FUZZER_ANSMANAGERSTUBANNEXTHREE_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/ansmanagerstubannexthree_fuzzer/corpus/init b/test/fuzztest/ansmanagerstubannexthree_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/ansmanagerstubannexthree_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/ansmanagerstubannexthree_fuzzer/project.xml b/test/fuzztest/ansmanagerstubannexthree_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/ansmanagerstubannexthree_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + -- Gitee