15ba71b47Sopenharmony_ci/*
25ba71b47Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
35ba71b47Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
45ba71b47Sopenharmony_ci * you may not use this file except in compliance with the License.
55ba71b47Sopenharmony_ci * You may obtain a copy of the License at
65ba71b47Sopenharmony_ci *
75ba71b47Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
85ba71b47Sopenharmony_ci *
95ba71b47Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
105ba71b47Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
115ba71b47Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
125ba71b47Sopenharmony_ci * See the License for the specific language governing permissions and
135ba71b47Sopenharmony_ci * limitations under the License.
145ba71b47Sopenharmony_ci */
155ba71b47Sopenharmony_ci
165ba71b47Sopenharmony_ci#include "unsubscribesystemprocess_fuzzer.h"
175ba71b47Sopenharmony_ci
185ba71b47Sopenharmony_ci#include "fuzztest_utils.h"
195ba71b47Sopenharmony_ci#include "samgr_ipc_interface_code.h"
205ba71b47Sopenharmony_cinamespace OHOS {
215ba71b47Sopenharmony_cinamespace Samgr {
225ba71b47Sopenharmony_cinamespace {
235ba71b47Sopenharmony_ciconstexpr size_t THRESHOLD = 4;
245ba71b47Sopenharmony_ciconst std::u16string SAMGR_INTERFACE_TOKEN = u"ohos.samgr.accessToken";
255ba71b47Sopenharmony_ci}
265ba71b47Sopenharmony_ci
275ba71b47Sopenharmony_civoid FuzzSubscribeSystemProcess(const uint8_t *data, size_t size)
285ba71b47Sopenharmony_ci{
295ba71b47Sopenharmony_ci    sptr<MockSystemProcessStatusChange> listener = new(std::nothrow) MockSystemProcessStatusChange();
305ba71b47Sopenharmony_ci    if (listener == nullptr) {
315ba71b47Sopenharmony_ci        return;
325ba71b47Sopenharmony_ci    }
335ba71b47Sopenharmony_ci    MessageParcel parcelData;
345ba71b47Sopenharmony_ci    parcelData.WriteInterfaceToken(SAMGR_INTERFACE_TOKEN);
355ba71b47Sopenharmony_ci    parcelData.WriteRemoteObject(listener);
365ba71b47Sopenharmony_ci    FuzzTestUtils::FuzzTestRemoteRequest(parcelData,
375ba71b47Sopenharmony_ci        static_cast<uint32_t>(SamgrInterfaceCode::SUBSCRIBE_SYSTEM_PROCESS_TRANSACTION));
385ba71b47Sopenharmony_ci}
395ba71b47Sopenharmony_ci
405ba71b47Sopenharmony_civoid FuzzUnSubscribeSystemProcess(const uint8_t *data, size_t size)
415ba71b47Sopenharmony_ci{
425ba71b47Sopenharmony_ci    sptr<MockSystemProcessStatusChange> listener = new(std::nothrow) MockSystemProcessStatusChange();
435ba71b47Sopenharmony_ci    if (listener == nullptr) {
445ba71b47Sopenharmony_ci        return;
455ba71b47Sopenharmony_ci    }
465ba71b47Sopenharmony_ci    MessageParcel parcelData;
475ba71b47Sopenharmony_ci    parcelData.WriteInterfaceToken(SAMGR_INTERFACE_TOKEN);
485ba71b47Sopenharmony_ci    parcelData.WriteRemoteObject(listener);
495ba71b47Sopenharmony_ci    FuzzTestUtils::FuzzTestRemoteRequest(parcelData,
505ba71b47Sopenharmony_ci        static_cast<uint32_t>(SamgrInterfaceCode::UNSUBSCRIBE_SYSTEM_PROCESS_TRANSACTION));
515ba71b47Sopenharmony_ci}
525ba71b47Sopenharmony_ci}
535ba71b47Sopenharmony_ci}
545ba71b47Sopenharmony_ci/* Fuzzer entry point */
555ba71b47Sopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
565ba71b47Sopenharmony_ci{
575ba71b47Sopenharmony_ci    if (size < OHOS::Samgr::THRESHOLD) {
585ba71b47Sopenharmony_ci        return 0;
595ba71b47Sopenharmony_ci    }
605ba71b47Sopenharmony_ci    OHOS::Samgr::FuzzSubscribeSystemProcess(data, size);
615ba71b47Sopenharmony_ci    OHOS::Samgr::FuzzUnSubscribeSystemProcess(data, size);
625ba71b47Sopenharmony_ci    return 0;
635ba71b47Sopenharmony_ci}