1686862fbSopenharmony_ci/*
2686862fbSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
3686862fbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4686862fbSopenharmony_ci * you may not use this file except in compliance with the License.
5686862fbSopenharmony_ci * You may obtain a copy of the License at
6686862fbSopenharmony_ci *
7686862fbSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8686862fbSopenharmony_ci *
9686862fbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10686862fbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11686862fbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12686862fbSopenharmony_ci * See the License for the specific language governing permissions and
13686862fbSopenharmony_ci * limitations under the License.
14686862fbSopenharmony_ci */
15686862fbSopenharmony_ci
16686862fbSopenharmony_ci#include "bundlemanagercallbackstub_fuzzer.h"
17686862fbSopenharmony_ci
18686862fbSopenharmony_ci#include "bundle/bundle_manager_callback_stub.h"
19686862fbSopenharmony_ci#include "mock_fuzz_util.h"
20686862fbSopenharmony_ci
21686862fbSopenharmony_cinamespace OHOS {
22686862fbSopenharmony_cinamespace DistributedSchedule {
23686862fbSopenharmony_ci
24686862fbSopenharmony_cibool OnQueryInstallationFinishedInnerFuzzTest(const uint8_t* data, size_t size)
25686862fbSopenharmony_ci{
26686862fbSopenharmony_ci    if ((data == nullptr) || (size < sizeof(int32_t))) {
27686862fbSopenharmony_ci        return false;
28686862fbSopenharmony_ci    }
29686862fbSopenharmony_ci    FuzzUtil::MockPermission();
30686862fbSopenharmony_ci    std::shared_ptr<DmsBundleManagerCallbackStub> bundleManager_ =
31686862fbSopenharmony_ci        std::make_shared<DmsBundleManagerCallbackStub>();
32686862fbSopenharmony_ci    uint32_t code = 0;
33686862fbSopenharmony_ci    MessageParcel dataParcel;
34686862fbSopenharmony_ci    MessageParcel reply;
35686862fbSopenharmony_ci    MessageOption option;
36686862fbSopenharmony_ci    bundleManager_->OnRemoteRequest(code, dataParcel, reply, option);
37686862fbSopenharmony_ci
38686862fbSopenharmony_ci    std::u16string descriptor = bundleManager_->GetDescriptor();
39686862fbSopenharmony_ci    dataParcel.WriteInterfaceToken(descriptor);
40686862fbSopenharmony_ci    bundleManager_->OnRemoteRequest(code, dataParcel, reply, option);
41686862fbSopenharmony_ci
42686862fbSopenharmony_ci    code = static_cast<uint32_t>(IDBundleManagerCallbackInterfaceCod::ON_QUERY_INSTALLATION_DONE);
43686862fbSopenharmony_ci    int32_t resultCode = *(reinterpret_cast<const int32_t*>(data));
44686862fbSopenharmony_ci    uint32_t versionCode = *(reinterpret_cast<const uint32_t*>(data));
45686862fbSopenharmony_ci    int32_t missionId = *(reinterpret_cast<const int32_t*>(data));
46686862fbSopenharmony_ci    dataParcel.WriteInt32(resultCode);
47686862fbSopenharmony_ci    dataParcel.WriteUint32(versionCode);
48686862fbSopenharmony_ci    dataParcel.WriteInt32(missionId);
49686862fbSopenharmony_ci    bundleManager_->OnRemoteRequest(code, dataParcel, reply, option);
50686862fbSopenharmony_ci    bundleManager_->OnQueryInstallationFinishedInner(dataParcel, reply);
51686862fbSopenharmony_ci    return true;
52686862fbSopenharmony_ci}
53686862fbSopenharmony_ci}
54686862fbSopenharmony_ci}
55686862fbSopenharmony_ci
56686862fbSopenharmony_ci/* Fuzzer entry point */
57686862fbSopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
58686862fbSopenharmony_ci{
59686862fbSopenharmony_ci    OHOS::DistributedSchedule::OnQueryInstallationFinishedInnerFuzzTest(data, size);
60686862fbSopenharmony_ci    return 0;
61686862fbSopenharmony_ci}