• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #include "workschedulersetworkschedulerconfig_fuzzer.h"
17 
18 #include "iwork_sched_service.h"
19 #include "work_scheduler_service.h"
20 #include "work_sched_common.h"
21 #include "work_condition.h"
22 #include "work_sched_config.h"
23 
24 
DecStrongRef(void const * obj)25 void OHOS::RefBase::DecStrongRef(void const* obj) {}
26 
27 namespace OHOS {
28 namespace WorkScheduler {
29     const std::u16string WORK_SCHEDULER_STUB_TOKEN = u"ohos.workscheduler.iworkschedservice";
30     static std::shared_ptr<WorkSchedulerService> workSchedulerService_;
31 
GetUidByBundleName(const std::string & bundleName,int32_t & uid)32     bool WorkSchedulerService::GetUidByBundleName(const std::string &bundleName, int32_t &uid)
33     {
34         return true;
35     }
36 
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)37     bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
38     {
39         MessageParcel dataMessageParcel;
40         dataMessageParcel.WriteInterfaceToken(WORK_SCHEDULER_STUB_TOKEN);
41         dataMessageParcel.WriteBuffer(data, size);
42         dataMessageParcel.RewindRead(0);
43         MessageParcel reply;
44         MessageOption option;
45         workSchedulerService_ = DelayedSingleton<WorkSchedulerService>::GetInstance();
46         uint32_t code = static_cast<int32_t>(IWorkSchedServiceIpcCode::COMMAND_SET_WORK_SCHEDULER_CONFIG);
47         std::string configData = "{\"active_group_whitelist\":["
48                                         "\"test1\","
49                                         "\"test2\","
50                                         "\"test3\","
51                                         "\"test4\""
52                                     "]"
53                                 "}";
54         if (!dataMessageParcel.WriteString(configData)) {
55             return false;
56         }
57         workSchedulerService_->OnStart();
58         workSchedulerService_->InitBgTaskSubscriber();
59         if (!workSchedulerService_->ready_) {
60             workSchedulerService_->ready_ = true;
61         }
62         if (workSchedulerService_->checkBundle_) {
63             workSchedulerService_->checkBundle_ = false;
64         }
65         workSchedulerService_->OnRemoteRequest(code, dataMessageParcel, reply, option);
66         workSchedulerService_->OnStop();
67         return true;
68     }
69 } // WorkScheduler
70 } // OHOS
71 
72 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)73 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
74 {
75     /* Run your code on data */
76     OHOS::WorkScheduler::DoSomethingInterestingWithMyAPI(data, size);
77     return 0;
78 }