diff --git a/test/fuzztest/advancednotificationservice/BUILD.gn b/test/fuzztest/advancednotificationservice/BUILD.gn
index c91e375d7c58ce24a41897bf139c39c39a6ecca6..bafc0f38a6cf8743fbbd29236402e5486c6bf961 100644
--- a/test/fuzztest/advancednotificationservice/BUILD.gn
+++ b/test/fuzztest/advancednotificationservice/BUILD.gn
@@ -107,5 +107,6 @@ group("fuzztest") {
"serviceupdatenotificationtimerbyuid_fuzzer:ServiceUpdateNotificationTimerByUidFuzzTest",
"serviceisdistributedenabledbyslot_fuzzer:ServiceIsDistributedEnabledBySlotFuzzTest",
"serviceremovedistributednotifications_fuzzer:ServiceRemoveDistributedNotificationsFuzzTest",
+ "servicepublishpreparednotification_fuzzer:ServicePublishPreparedNotificationFuzzTest",
]
}
\ No newline at end of file
diff --git a/test/fuzztest/advancednotificationservice/servicepublishpreparednotification_fuzzer/BUILD.gn b/test/fuzztest/advancednotificationservice/servicepublishpreparednotification_fuzzer/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..94f6665e459a6e32b9053ec3c833100a1ac1ba55
--- /dev/null
+++ b/test/fuzztest/advancednotificationservice/servicepublishpreparednotification_fuzzer/BUILD.gn
@@ -0,0 +1,32 @@
+# Copyright (c) 2025 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+#####################hydra-fuzz###################
+import("../advancednotificationservice_fuzztest_common.gni") # 导入公共配置
+
+##############################fuzztest##########################################
+advancednotificationservice_fuzztest_target("ServicePublishPreparedNotificationFuzzTest") {
+ sources_value = [ "service_publishpreparednotification_fuzzer.cpp" ]
+ fuzz_config_file_value =
+ "${component_path}/test/fuzztest/advancednotificationservice/servicepublishpreparednotification_fuzzer"
+ deps_value = [] # 如果不需要额外依赖,可以留空
+ common_deps_value = common_deps # 使用公共依赖
+}
+
+###############################################################################
+group("fuzztest") {
+ testonly = true
+ deps = [ ":ServicePublishPreparedNotificationFuzzTest" ]
+}
+###############################################################################
\ No newline at end of file
diff --git a/test/fuzztest/advancednotificationservice/servicepublishpreparednotification_fuzzer/corpus/init b/test/fuzztest/advancednotificationservice/servicepublishpreparednotification_fuzzer/corpus/init
new file mode 100644
index 0000000000000000000000000000000000000000..d9719cafab50ed61d354cfa865b56390a0df320f
--- /dev/null
+++ b/test/fuzztest/advancednotificationservice/servicepublishpreparednotification_fuzzer/corpus/init
@@ -0,0 +1,13 @@
+# Copyright (c) 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.
+FUZZ
\ No newline at end of file
diff --git a/test/fuzztest/advancednotificationservice/servicepublishpreparednotification_fuzzer/project.xml b/test/fuzztest/advancednotificationservice/servicepublishpreparednotification_fuzzer/project.xml
new file mode 100644
index 0000000000000000000000000000000000000000..f373defa7ec4fb5861095733a9ace8215d11c56f
--- /dev/null
+++ b/test/fuzztest/advancednotificationservice/servicepublishpreparednotification_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 10000
+
+ 300
+
+ 4096
+
+
\ No newline at end of file
diff --git a/test/fuzztest/advancednotificationservice/servicepublishpreparednotification_fuzzer/service_publishpreparednotification_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicepublishpreparednotification_fuzzer/service_publishpreparednotification_fuzzer.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..cd372e70e9b7c5d7d57dd971321489c9fcbab13f
--- /dev/null
+++ b/test/fuzztest/advancednotificationservice/servicepublishpreparednotification_fuzzer/service_publishpreparednotification_fuzzer.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2025 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "service_publishpreparednotification_fuzzer.h"
+
+#include
+#include "advanced_notification_service.h"
+#include "ans_permission_def.h"
+#include "mock_notification_request.h"
+
+namespace OHOS {
+namespace Notification {
+ bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData)
+ {
+ auto service = AdvancedNotificationService::GetInstance();
+ sptr request = ObjectBuilder::Build(fuzzData);
+ sptr bundleOption = ObjectBuilder::Build(fuzzData);
+ bool isUpdateByOwner = fuzzData->ConsumeBool();
+ service->PublishPreparedNotification(request, bundleOption, isUpdateByOwner);
+ 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
+ };
+ MockRandomToken(&fdp, requestPermission);
+ OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp);
+ return 0;
+}
diff --git a/test/fuzztest/advancednotificationservice/servicepublishpreparednotification_fuzzer/service_publishpreparednotification_fuzzer.h b/test/fuzztest/advancednotificationservice/servicepublishpreparednotification_fuzzer/service_publishpreparednotification_fuzzer.h
new file mode 100644
index 0000000000000000000000000000000000000000..20b9d7923dfa09295e7113a39eaba20a467f17ef
--- /dev/null
+++ b/test/fuzztest/advancednotificationservice/servicepublishpreparednotification_fuzzer/service_publishpreparednotification_fuzzer.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2025 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TEST_FUZZTEST_ADVANCEDNOTIFICATIONSERVICE_FUZZER_SERVICE_PUBLISHPREPAREDNOTIFICATION_FUZZER_H
+#define TEST_FUZZTEST_ADVANCEDNOTIFICATIONSERVICE_FUZZER_SERVICE_PUBLISHPREPAREDNOTIFICATION_FUZZER_H
+
+#include "fuzz_common_base.h"
+#include
+
+#define FUZZ_PROJECT_NAME "advancednotificationservicepublishpreparednotification_fuzzer"
+
+#endif // TEST_FUZZTEST_ADVANCEDNOTIFICATIONSERVICE_FUZZER_SERVICE_PUBLISHPREPAREDNOTIFICATION_FUZZER_H
\ No newline at end of file
diff --git a/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp b/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp
index ad9ec56c5918a34a39dcf678d9d032b719bc8b9a..bca321d9435146119f9b5902b2591d4c6d57791c 100644
--- a/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp
+++ b/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp
@@ -254,7 +254,6 @@ namespace OHOS {
std::shared_ptr record =
service->MakeNotificationRecord(request, bundleOption);
record->slot = new Notification::NotificationSlot(Notification::NotificationConstant::SlotType::LIVE_VIEW);
- service->PublishPreparedNotification(request, bundleOption, fuzzData->ConsumeBool());
service->QueryDoNotDisturbProfile(randomInt32, randomString, randomString);
service->CheckDoNotDisturbProfile(record);
service->DoNotDisturbUpdataReminderFlags(record);
diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_content.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_content.h
index 2dbe094d2706a7348fced99a506e9a06abd27ab2..f43c4f869bbb7e7acc2782f939bc47cee644ba80 100644
--- a/test/fuzztest/fuzz_common_base/mock/mock_notification_content.h
+++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_content.h
@@ -27,24 +27,47 @@
namespace OHOS {
namespace Notification {
+const int INDEX_ZERO = 0;
+const int INDEX_ONE = 1;
+const int INDEX_TWO = 2;
+const int INDEX_THREE = 3;
+
template <>
NotificationContent* ObjectBuilder::Build(FuzzedDataProvider *fdp)
{
- int caseNum = fdp->ConsumeIntegralInRange(0, 5);
+ int caseNum = fdp->ConsumeIntegralInRange(0, 4);
ANS_LOGE("Build mock veriables");
switch (caseNum) {
- case 0:
- return reinterpret_cast(ObjectBuilder::Build(fdp));
- case 1:
- return reinterpret_cast(ObjectBuilder::Build(fdp));
- case 2:
- return reinterpret_cast(ObjectBuilder::Build(fdp));
- case 3:
- return reinterpret_cast(ObjectBuilder::Build(fdp));
- case 4:
- return reinterpret_cast(ObjectBuilder::Build(fdp));
- default:
- return reinterpret_cast(ObjectBuilder::Build(fdp));
+ case INDEX_ZERO: {
+ std::shared_ptr conversationalContent (
+ ObjectBuilder::Build(fdp));
+ return new NotificationContent(conversationalContent);
+ break;
+ }
+ case INDEX_ONE: {
+ std::shared_ptr mediaContent (
+ ObjectBuilder::Build(fdp));
+ return new NotificationContent(mediaContent);
+ break;
+ }
+ case INDEX_TWO: {
+ std::shared_ptr multiContent (
+ ObjectBuilder::Build(fdp));
+ return new NotificationContent(multiContent);
+ break;
+ }
+ case INDEX_THREE: {
+ std::shared_ptr normalContent (
+ ObjectBuilder::Build(fdp));
+ return new NotificationContent(normalContent);
+ break;
+ }
+ default: {
+ std::shared_ptr defaultNormalContent (
+ ObjectBuilder::Build(fdp));
+ return new NotificationContent(defaultNormalContent);
+ break;
+ }
}
}
diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_request.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_request.h
index 923ec46f0f3e1cdf9b8cea1e61844d6f86fedf2c..05e9841c2bd3ecbd1fb84855160523c38e92c980 100644
--- a/test/fuzztest/fuzz_common_base/mock/mock_notification_request.h
+++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_request.h
@@ -137,7 +137,14 @@ NotificationRequest* ObjectBuilder::Build(FuzzedDataProvide
GenerateStringTypeVeriables(fdp, request);
GenerateEnumTypeVeriables(fdp, request);
- request->SetContent(ObjectBuilder::BuildSharedPtr(fdp));
+ if (NotificationConstant::SlotType::LIVE_VIEW == request->GetSlotType()) {
+ std::shared_ptr liveViewContent (
+ ObjectBuilder::Build(fdp));
+ std::shared_ptr content = std::make_shared(liveViewContent);
+ request->SetContent(content);
+ } else {
+ request->SetContent(ObjectBuilder::BuildSharedPtr(fdp));
+ }
request->SetTemplate(ObjectBuilder::BuildSharedPtr(fdp));
request->SetBundleOption(ObjectBuilder::BuildSharedPtr(fdp));
request->SetAgentBundle(ObjectBuilder::BuildSharedPtr(fdp));