1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <cstdint>
17 #include <fuzzer/FuzzedDataProvider.h>
18 #include <memory>
19 #include <string>
20 #include "reminder_agent_service.h"
21 #include "reminderservice_fuzzer.h"
22 #include "ans_permission_def.h"
23
24 constexpr uint8_t SLOT_TYPE_NUM = 5;
25
26 namespace OHOS {
27
DoSomethingInterestingWithMyAPI(FuzzedDataProvider * fuzzData)28 bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData)
29 {
30 auto service = std::make_shared<Notification::ReminderAgentService>();
31 std::string stringData = fuzzData->ConsumeRandomLengthString();
32 int32_t userId = fuzzData->ConsumeIntegral<int32_t>();
33 Notification::ReminderRequest reminder;
34 int32_t reminderId2 = 0;
35 service->PublishReminder(reminder, reminderId2);
36 int32_t reminderId = fuzzData->ConsumeIntegral<int32_t>();
37 service->CancelReminder(reminderId);
38 std::vector<Notification::ReminderRequestAdaptation> reminders;
39 service->GetValidReminders(reminders);
40 service->CancelAllReminders();
41 int64_t excludeDate = fuzzData->ConsumeIntegral<int64_t>();
42 service->AddExcludeDate(reminderId, excludeDate);
43 service->DelExcludeDates(reminderId);
44 std::vector<int64_t> excludeDates;
45 service->GetExcludeDates(reminderId, excludeDates);
46 return true;
47 }
48 }
49
50 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)51 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
52 {
53 /* Run your code on data */
54 FuzzedDataProvider fdp(data, size);
55 std::vector<std::string> requestPermission = {
56 OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER,
57 OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER,
58 OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION
59 };
60 SystemHapTokenGet(requestPermission);
61 OHOS::DoSomethingInterestingWithMyAPI(&fdp);
62 return 0;
63 }
64