1f857971dSopenharmony_ci/*
2f857971dSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
3f857971dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4f857971dSopenharmony_ci * you may not use this file except in compliance with the License.
5f857971dSopenharmony_ci * You may obtain a copy of the License at
6f857971dSopenharmony_ci *
7f857971dSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8f857971dSopenharmony_ci *
9f857971dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10f857971dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11f857971dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12f857971dSopenharmony_ci * See the License for the specific language governing permissions and
13f857971dSopenharmony_ci * limitations under the License.
14f857971dSopenharmony_ci */
15f857971dSopenharmony_ci
16f857971dSopenharmony_ci#include "updatepreviewstyle_fuzzer.h"
17f857971dSopenharmony_ci
18f857971dSopenharmony_ci#include "singleton.h"
19f857971dSopenharmony_ci
20f857971dSopenharmony_ci#define private public
21f857971dSopenharmony_ci#include "devicestatus_service.h"
22f857971dSopenharmony_ci#include "fi_log.h"
23f857971dSopenharmony_ci#include "message_parcel.h"
24f857971dSopenharmony_ci#include "preview_style_packer.h"
25f857971dSopenharmony_ci
26f857971dSopenharmony_ci#undef LOG_TAG
27f857971dSopenharmony_ci#define LOG_TAG "UpdatePreviewStyleFuzzTest"
28f857971dSopenharmony_ci
29f857971dSopenharmony_cinamespace OHOS {
30f857971dSopenharmony_cinamespace Msdp {
31f857971dSopenharmony_cinamespace DeviceStatus {
32f857971dSopenharmony_ci
33f857971dSopenharmony_cinamespace OHOS {
34f857971dSopenharmony_ciconstexpr uint32_t FOREGROUND_COLOR_IN { 0x33FF0000 };
35f857971dSopenharmony_ci
36f857971dSopenharmony_cibool UpdatePreviewStyleFuzzTest(const uint8_t* data, size_t size)
37f857971dSopenharmony_ci{
38f857971dSopenharmony_ci    const std::u16string FORMMGR_DEVICE_TOKEN { u"ohos.msdp.Idevicestatus" };
39f857971dSopenharmony_ci    MessageParcel datas;
40f857971dSopenharmony_ci    if (!datas.WriteInterfaceToken(FORMMGR_DEVICE_TOKEN)) {
41f857971dSopenharmony_ci        FI_HILOGE("Failed to write interface token");
42f857971dSopenharmony_ci        return false;
43f857971dSopenharmony_ci    }
44f857971dSopenharmony_ci
45f857971dSopenharmony_ci    PreviewStyle previewStyle;
46f857971dSopenharmony_ci    previewStyle.types = { PreviewType::FOREGROUND_COLOR };
47f857971dSopenharmony_ci    previewStyle.foregroundColor = FOREGROUND_COLOR_IN;
48f857971dSopenharmony_ci    if (PreviewStylePacker::Marshalling(previewStyle, datas) != RET_OK) {
49f857971dSopenharmony_ci        FI_HILOGE("Marshalling previewStyle failed");
50f857971dSopenharmony_ci        return false;
51f857971dSopenharmony_ci    }
52f857971dSopenharmony_ci    if (!datas.WriteBuffer(data, size) || !datas.RewindRead(0)) {
53f857971dSopenharmony_ci        FI_HILOGE("Failed to write buffer");
54f857971dSopenharmony_ci        return false;
55f857971dSopenharmony_ci    }
56f857971dSopenharmony_ci    MessageOption option;
57f857971dSopenharmony_ci    MessageParcel reply;
58f857971dSopenharmony_ci    DelayedSingleton<DeviceStatusService>::GetInstance()->OnRemoteRequest(
59f857971dSopenharmony_ci        static_cast<uint32_t>(Msdp::DeviceInterfaceCode::UPDATE_PREVIEW_STYLE), datas, reply, option);
60f857971dSopenharmony_ci    return true;
61f857971dSopenharmony_ci}
62f857971dSopenharmony_ci} // namespace OHOS
63f857971dSopenharmony_ci
64f857971dSopenharmony_ci/* Fuzzer entry point */
65f857971dSopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
66f857971dSopenharmony_ci{
67f857971dSopenharmony_ci    /* Run your code on data */
68f857971dSopenharmony_ci    if (data == nullptr) {
69f857971dSopenharmony_ci        return 0;
70f857971dSopenharmony_ci    }
71f857971dSopenharmony_ci
72f857971dSopenharmony_ci    OHOS::UpdatePreviewStyleFuzzTest(data, size);
73f857971dSopenharmony_ci    return 0;
74f857971dSopenharmony_ci}
75f857971dSopenharmony_ci} // namespace DeviceStatus
76f857971dSopenharmony_ci} // namespace Msdp
77f857971dSopenharmony_ci} // namespace OHOS
78