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 "workschedulerislastworktimeout_fuzzer.h"
17
18 #include "iwork_sched_service_ipc_interface_code.h"
19 #include "work_scheduler_service.h"
20
21
DecStrongRef(void const * obj)22 void OHOS::RefBase::DecStrongRef(void const* obj) {}
23
24 namespace OHOS {
25 namespace WorkScheduler {
26 const std::u16string WORK_SCHEDULER_STUB_TOKEN = u"ohos.workscheduler.iworkschedservice";
27 static std::shared_ptr<WorkSchedulerService> workSchedulerService_;
28
GetUidByBundleName(const std::string & bundleName,int32_t & uid)29 bool WorkSchedulerService::GetUidByBundleName(const std::string &bundleName, int32_t &uid)
30 {
31 return true;
32 }
33
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)34 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
35 {
36 MessageParcel dataMessageParcel;
37 dataMessageParcel.WriteInterfaceToken(WORK_SCHEDULER_STUB_TOKEN);
38 dataMessageParcel.WriteBuffer(data, size);
39 dataMessageParcel.RewindRead(0);
40 MessageParcel reply;
41 MessageOption option;
42 workSchedulerService_ = DelayedSingleton<WorkSchedulerService>::GetInstance();
43 uint32_t code = static_cast<int32_t>(IWorkSchedServiceInterfaceCode::IS_LAST_WORK_TIMEOUT);
44 workSchedulerService_->OnStart();
45 workSchedulerService_->InitBgTaskSubscriber();
46 if (!workSchedulerService_->ready_) {
47 workSchedulerService_->ready_ = true;
48 }
49 workSchedulerService_->OnRemoteRequest(code, dataMessageParcel, reply, option);
50 workSchedulerService_->OnStop();
51 return true;
52 }
53 } // WorkScheduler
54 } // OHOS
55
56 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)57 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
58 {
59 /* Run your code on data */
60 OHOS::WorkScheduler::DoSomethingInterestingWithMyAPI(data, size);
61 return 0;
62 }