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 "ans_subscriber_proxy.h"
19 #undef private
20 #undef protected
21 #include "ans_permission_def.h"
22 #include "anssubscriberproxy_fuzzer.h"
23 #include "notification_request.h"
24 #include "notification_subscriber.h"
25
26 namespace OHOS {
DoSomethingInterestingWithMyAPI(const char * data,size_t size)27 bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
28 {
29 sptr<IRemoteObject> impl;
30 Notification::AnsSubscriberProxy ansSubscriberProxy(impl);
31 uint32_t code = GetU32Data(data);
32 MessageParcel datas;
33 MessageParcel reply;
34 MessageOption flags;
35 // test InnerTransact function
36 ansSubscriberProxy.InnerTransact(static_cast<Notification::NotificationInterfaceCode>(code),
37 flags, datas, reply);
38 // test InnerTransact function
39 ansSubscriberProxy.OnConnected();
40 // test InnerTransact function
41 ansSubscriberProxy.OnDisconnected();
42 sptr<Notification::NotificationRequest> request = new Notification::NotificationRequest();
43 // test InnerTransact function
44 sptr<Notification::Notification> notification = new Notification::Notification(request);
45
46 sptr<Notification::NotificationSortingMap> notificationMap = new Notification::NotificationSortingMap();
47 ansSubscriberProxy.OnConsumed(notification, notificationMap);
48 // test OnCanceled function
49 int32_t deleteReason = 1;
50 ansSubscriberProxy.OnCanceled(notification, notificationMap, deleteReason);
51 // test OnCanceled function
52 ansSubscriberProxy.OnUpdated(notificationMap);
53 // test OnCanceled function
54 sptr<Notification::NotificationDoNotDisturbDate> date = new Notification::NotificationDoNotDisturbDate();
55 ansSubscriberProxy.OnDoNotDisturbDateChange(date);
56 // test OnEnabledNotificationChanged function
57 sptr<Notification::EnabledNotificationCallbackData> callbackData = new Notification::EnabledNotificationCallbackData();
58 ansSubscriberProxy.OnEnabledNotificationChanged(callbackData);
59 return true;
60 }
61 }
62
63 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)64 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
65 {
66 /* Run your code on data */
67 char *ch = ParseData(data, size);
68 if (ch != nullptr && size >= GetU32Size()) {
69 std::vector<std::string> requestPermission = {
70 OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER,
71 OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER,
72 OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION
73 };
74 SystemHapTokenGet(requestPermission);
75 OHOS::DoSomethingInterestingWithMyAPI(ch, size);
76 free(ch);
77 ch = nullptr;
78 }
79 return 0;
80 }
81