• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "distributed_extension_service.h"
19 #undef private
20 #undef protected
21 #include "notification_capsule.h"
22 #include "notification_disable.h"
23 #include "notification_do_not_disturb_profile.h"
24 #include "notification_icon_button.h"
25 #include "notification_live_view_content.h"
26 #include "notification_local_live_view_button.h"
27 #include "notification_local_live_view_content.h"
28 #include "notification_operation_info.h"
29 #include "notification_unified_group_Info.h"
30 #include "resource_manager.h"
31 #include "notificationextension_fuzzer.h"
32 #include <fuzzer/FuzzedDataProvider.h>
33 #include "notification_content.h"
34 #include "notification_check_request.h"
35 
36 namespace OHOS {
37 namespace Notification {
38 
DoSomethingInterestingWithMyAPI(FuzzedDataProvider * fdp)39     bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fdp)
40     {
41         bool result = DistributedExtensionService::GetInstance().initConfig();
42         const int32_t MIN_LENGTH = 1;
43         const int32_t MAX_LENGTH = 10;
44         const int32_t messageType = 7;
45         std::string reason = "ok";
46         std::string deviceType = DistributedExtensionService::TransDeviceTypeToName(DmDeviceType::DEVICE_TYPE_WATCH);
47         deviceType = DistributedExtensionService::TransDeviceTypeToName(DmDeviceType::DEVICE_TYPE_PAD);
48         deviceType = DistributedExtensionService::TransDeviceTypeToName(DmDeviceType::DEVICE_TYPE_PHONE);
49         deviceType = DistributedExtensionService::TransDeviceTypeToName(DmDeviceType::DEVICE_TYPE_2IN1);
50         deviceType = DistributedExtensionService::TransDeviceTypeToName(DmDeviceType::DEVICE_TYPE_PC);
51         deviceType = DistributedExtensionService::TransDeviceTypeToName(DmDeviceType::DEVICE_TYPE_WIFI_CAMERA);
52         deviceType = DistributedExtensionService::DeviceTypeToTypeString(DmDeviceType::DEVICE_TYPE_PAD);
53         deviceType = DistributedExtensionService::DeviceTypeToTypeString(DmDeviceType::DEVICE_TYPE_PC);
54         deviceType = DistributedExtensionService::DeviceTypeToTypeString(DmDeviceType::DEVICE_TYPE_2IN1);
55         deviceType = DistributedExtensionService::DeviceTypeToTypeString(DmDeviceType::DEVICE_TYPE_WATCH);
56 
57         DistributedExtensionService::GetInstance().InitDans();
58         DistributedExtensionService::GetInstance().ReleaseLocalDevice();
59         DistributedHardware::DmDeviceInfo deviceInfo;
60         DistributedExtensionService::GetInstance().OnDeviceOnline(deviceInfo);
61         DistributedExtensionService::GetInstance().OnDeviceOffline(deviceInfo);
62         DistributedExtensionService::GetInstance().HADotCallback(0, 0, 0, "{\"deviceType\":\"pc\"}");
63         DistributedExtensionService::GetInstance().SendReportCallback(messageType, 0, reason);
64 
65         DistributedHardware::DmDeviceInfo info;
66         strcpy_s(info.deviceId, sizeof(info.deviceId) - 1, "device");
67         DistributedExtensionService::GetInstance().OnDeviceOffline(info);
68         DistributedExtensionService::GetInstance().OnDeviceChanged(info);
69         nlohmann::json contentJson;
70         contentJson["operationReplyTimeout"] = fdp->ConsumeIntegralInRange<int32_t>(MIN_LENGTH, MAX_LENGTH);
71         contentJson["maxContentLength"] = fdp->ConsumeIntegralInRange<int32_t>(MIN_LENGTH, MAX_LENGTH);
72         contentJson["localType"] = fdp->ConsumeRandomLengthString(MAX_LENGTH);
73         contentJson["supportPeerDevice"] = fdp->ConsumeRandomLengthString(MAX_LENGTH);
74         contentJson["maxTitleLength"] = fdp->ConsumeIntegralInRange<int32_t>(MIN_LENGTH, MAX_LENGTH);
75         DistributedExtensionService::GetInstance().SetOperationReplyTimeout(contentJson);
76         DistributedExtensionService::GetInstance().SetMaxContentLength(contentJson);
77         DistributedExtensionService::GetInstance().SetLocalType(contentJson);
78         DistributedExtensionService::GetInstance().SetSupportPeerDevice(contentJson);
79         DistributedExtensionService::GetInstance().SetMaxTitleLength(contentJson);
80 
81         return true;
82     }
83 }
84 }
85 
86 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)87 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
88 {
89     /* Run your code on data */
90     FuzzedDataProvider fdp(data, size);
91     OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp);
92     return 0;
93 }
94