• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "advanced_notification_service.h"
19 #undef private
20 #undef protected
21 #include "ans_permission_def.h"
22 #include "ansmanagerstubannextwo_fuzzer.h"
23 
24 
25 constexpr uint8_t SLOT_TYPE_NUM = 5;
26 
27 namespace OHOS {
DoSomethingInterestingWithMyAPI(FuzzedDataProvider * fuzzData)28     bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData)
29     {
30         auto service = std::make_shared<Notification::AdvancedNotificationService>();
31         service->InitPublishProcess();
32         service->CreateDialogManager();
33         sptr<Notification::NotificationBundleOption> bundleOption = new Notification::NotificationBundleOption();
34         bundleOption->SetBundleName(fuzzData->ConsumeRandomLengthString());
35         bundleOption->SetUid(fuzzData->ConsumeIntegral<int32_t>());
36         uint8_t type = fuzzData->ConsumeIntegral<uint8_t>() % SLOT_TYPE_NUM;
37         Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(type);
38         int32_t userId = fuzzData->ConsumeIntegral<int32_t>();
39         bool enabled = fuzzData->ConsumeBool();
40         service->GetEnabledForBundleSlot(bundleOption, slotType, enabled);
41         service->SetSyncNotificationEnabledWithoutApp(userId, enabled);
42         service->GetSyncNotificationEnabledWithoutApp(userId, enabled);
43         return true;
44     }
45 }
46 
47 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)48 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
49 {
50     /* Run your code on data */
51     FuzzedDataProvider fdp(data, size);
52     std::vector<std::string> requestPermission = {
53         OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER,
54         OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER,
55         OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION
56     };
57     SystemHapTokenGet(requestPermission);
58     OHOS::DoSomethingInterestingWithMyAPI(&fdp);
59     return 0;
60 }
61