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