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