1 /*
2 * Copyright (c) 2022 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 #define private public
17 #define protected public
18 #include "reminder_request.h"
19 #undef private
20 #undef protected
21 #include "reminderrequest_fuzzer.h"
22
23 namespace OHOS {
24 namespace {
25 constexpr uint8_t ENABLE = 2;
26 constexpr uint8_t ACTION_BUTTON_TYPE = 3;
27 constexpr uint8_t COLUMN_TYPE = 2;
28 constexpr uint8_t SLOT_TYPE_NUM = 5;
29 }
DoSomethingInterestingWithMyAPI(const char * data,size_t size)30 bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
31 {
32 std::string stringData(data);
33 int32_t reminderId = static_cast<int32_t>(GetU32Data(data));
34 Notification::ReminderRequest reminderRequest(reminderId);
35 reminderRequest.CanRemove();
36 reminderRequest.CanShow();
37 reminderRequest.Dump();
38 uint8_t types = *data % ACTION_BUTTON_TYPE;
39 Notification::ReminderRequest::ActionButtonType type =
40 Notification::ReminderRequest::ActionButtonType(types);
41 reminderRequest.SetActionButton(stringData, type);
42 reminderRequest.SetContent(stringData);
43 reminderRequest.SetExpiredContent(stringData);
44 bool enabled = *data % ENABLE;
45 reminderRequest.SetExpired(enabled);
46 reminderRequest.InitReminderId();
47 reminderRequest.InitUserId(reminderId);
48 reminderRequest.InitUid(reminderId);
49 reminderRequest.IsExpired();
50 reminderRequest.IsShowing();
51 reminderRequest.OnClose(enabled);
52 reminderRequest.OnDateTimeChange();
53 uint64_t oriTriggerTime = 2;
54 uint64_t optTriggerTimes = 2;
55 reminderRequest.HandleSysTimeChange(oriTriggerTime, optTriggerTimes);
56 uint64_t oldZoneTriggerTime = 1;
57 uint64_t newZoneTriggerTime = 2;
58 uint64_t optTriggerTime = 3;
59 reminderRequest.HandleTimeZoneChange(oldZoneTriggerTime, newZoneTriggerTime, optTriggerTime);
60 reminderRequest.OnSameNotificationIdCovered();
61 reminderRequest.OnShow(enabled, enabled, enabled);
62 reminderRequest.OnShowFail();
63 reminderRequest.OnSnooze();
64 reminderRequest.OnStart();
65 reminderRequest.OnStop();
66 reminderRequest.OnTerminate();
67 reminderRequest.OnTimeZoneChange();
68 std::shared_ptr<NativeRdb::AbsSharedResultSet> resultSet =
69 std::make_shared<NativeRdb::AbsSharedResultSet>();
70 uint8_t column = *data % COLUMN_TYPE;
71 Notification::ReminderRequest::DbRecoveryType columnType =
72 Notification::ReminderRequest::DbRecoveryType(column);
73 reminderRequest.RecoverInt64FromDb(resultSet, stringData, columnType);
74 reminderRequest.RecoverFromDb(resultSet);
75 reminderRequest.RecoverActionButton(resultSet);
76 reminderRequest.StringSplit(stringData, stringData);
77 reminderRequest.RecoverWantAgent(stringData, *data);
78 std::shared_ptr< Notification::ReminderRequest::MaxScreenAgentInfo> maxScreenWantAgentInfo =
79 std::make_shared< Notification::ReminderRequest::MaxScreenAgentInfo>();
80 reminderRequest.SetMaxScreenWantAgentInfo(maxScreenWantAgentInfo);
81 reminderRequest.SetNotificationId(reminderId);
82 uint8_t typed = *data % SLOT_TYPE_NUM;
83 Notification::NotificationConstant::SlotType slotType =
84 Notification::NotificationConstant::SlotType(typed);
85 reminderRequest.SetSlotType(slotType);
86 reminderRequest.SetSnoozeContent(stringData);
87 return reminderRequest.ShouldShowImmediately();
88 }
89 }
90
91 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)92 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
93 {
94 /* Run your code on data */
95 char *ch = ParseData(data, size);
96 if (ch != nullptr && size >= GetU32Size()) {
97 OHOS::DoSomethingInterestingWithMyAPI(ch, size);
98 free(ch);
99 ch = nullptr;
100 }
101 return 0;
102 }
103