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 #include "abilitystartwithwaitobservermanager_fuzzer.h"
17
18 #include <cstddef>
19 #include <cstdint>
20 #include <fuzzer/FuzzedDataProvider.h>
21
22 #define private public
23 #define protected public
24 #include "ability_start_with_wait_observer_manager.h"
25 #undef protected
26 #undef private
27 #include "securec.h"
28 #include "ability_fuzz_util.h"
29 #include "ability_record.h"
30
31 using namespace OHOS::AAFwk;
32 using namespace OHOS::AppExecFwk;
33
34 namespace OHOS {
35 namespace {
36 constexpr size_t U32_AT_SIZE = 4;
37 }
38
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)39 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
40 {
41 Want want;
42 AbilityRequest info;
43 sptr<IAbilityStartWithWaitObserver> observer = nullptr;
44 FuzzedDataProvider fdp(data, size);
45 AbilityFuzzUtil::GetRandomAbilityRequestInfo(fdp, info);
46 std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(info);
47 std::shared_ptr<AbilityStartWithWaitObserverManager> infos =
48 std::make_shared<AbilityStartWithWaitObserverManager>();
49 infos->RegisterObserver(want, observer);
50 infos->UnregisterObserver(observer);
51 infos->NotifyAATerminateWait(want);
52 infos->NotifyAATerminateWait(abilityRecord);
53 infos->SetColdStartForShellCall(abilityRecord);
54 infos->GenerateDeathRecipient(observer);
55 return true;
56 }
57 }
58
59 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)60 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
61 {
62 // Run your code on data.
63 OHOS::DoSomethingInterestingWithMyAPI(data, size);
64 return 0;
65 }