1c29fa5a6Sopenharmony_ci/*
2c29fa5a6Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
3c29fa5a6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4c29fa5a6Sopenharmony_ci * you may not use this file except in compliance with the License.
5c29fa5a6Sopenharmony_ci * You may obtain a copy of the License at
6c29fa5a6Sopenharmony_ci *
7c29fa5a6Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
8c29fa5a6Sopenharmony_ci *
9c29fa5a6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10c29fa5a6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11c29fa5a6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12c29fa5a6Sopenharmony_ci * See the License for the specific language governing permissions and
13c29fa5a6Sopenharmony_ci * limitations under the License.
14c29fa5a6Sopenharmony_ci */
15c29fa5a6Sopenharmony_ci
16c29fa5a6Sopenharmony_ci#include "mmi_log.h"
17c29fa5a6Sopenharmony_ci#include "input_device_manager.h"
18c29fa5a6Sopenharmony_ci#include "inputdevicemanager_fuzzer.h"
19c29fa5a6Sopenharmony_ci
20c29fa5a6Sopenharmony_ci#undef MMI_LOG_TAG
21c29fa5a6Sopenharmony_ci#define MMI_LOG_TAG "InputDeviceManagerFuzzTest"
22c29fa5a6Sopenharmony_ci
23c29fa5a6Sopenharmony_cinamespace OHOS {
24c29fa5a6Sopenharmony_cinamespace MMI {
25c29fa5a6Sopenharmony_cinamespace OHOS {
26c29fa5a6Sopenharmony_cibool InputDeviceManagerFuzzTest(const uint8_t *data, size_t size)
27c29fa5a6Sopenharmony_ci{
28c29fa5a6Sopenharmony_ci    int32_t id = 1;
29c29fa5a6Sopenharmony_ci    int32_t deviceId = 1;
30c29fa5a6Sopenharmony_ci    int32_t keyboardType = 1;
31c29fa5a6Sopenharmony_ci    std::string type = "hello";
32c29fa5a6Sopenharmony_ci    bool checked = true;
33c29fa5a6Sopenharmony_ci    bool enable = true;
34c29fa5a6Sopenharmony_ci    bool hasPointerDevice = true;
35c29fa5a6Sopenharmony_ci    bool isVisible = true;
36c29fa5a6Sopenharmony_ci    bool isHotPlug = true;
37c29fa5a6Sopenharmony_ci    libinput_device* deviceOrigin = nullptr;
38c29fa5a6Sopenharmony_ci    std::shared_ptr<InputDevice> inputDevice;
39c29fa5a6Sopenharmony_ci    std::shared_ptr<IDeviceObserver> observer;
40c29fa5a6Sopenharmony_ci    std::shared_ptr<InputDevice> devicePtr = std::make_shared<InputDevice>();
41c29fa5a6Sopenharmony_ci    struct libinput_device* structDevice = nullptr;
42c29fa5a6Sopenharmony_ci    std::vector<int32_t> keyCodes = {1};
43c29fa5a6Sopenharmony_ci    std::vector<bool> keystroke = {true};
44c29fa5a6Sopenharmony_ci    std::vector<std::string> args = {"hello"};
45c29fa5a6Sopenharmony_ci    SessionPtr session;
46c29fa5a6Sopenharmony_ci    InputDeviceManager::InputDeviceInfo inDevice;
47c29fa5a6Sopenharmony_ci
48c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->GetInputDevice(deviceId, checked);
49c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->FillInputDevice(inputDevice, deviceOrigin);
50c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->GetInputDeviceIds();
51c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->SupportKeys(deviceId, keyCodes, keystroke);
52c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->IsMatchKeys(structDevice, keyCodes);
53c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->GetDeviceConfig(deviceId, keyboardType);
54c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->GetKeyboardBusMode(deviceId);
55c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->GetDeviceSupportKey(deviceId, keyboardType);
56c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->GetKeyboardType(deviceId, keyboardType);
57c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->AddDevListener(session);
58c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->RemoveDevListener(session);
59c29fa5a6Sopenharmony_ci    #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING
60c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->HasPointerDevice();
61c29fa5a6Sopenharmony_ci    #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING
62c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->HasTouchDevice();
63c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->NotifyDevCallback(deviceId, inDevice);
64c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->ScanPointerDevice();
65c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->IsKeyboardDevice(devicePtr);
66c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->Attach(observer);
67c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->Detach(observer);
68c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->NotifyPointerDevice(hasPointerDevice, isVisible, isHotPlug);
69c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->IsRemote(id);
70c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->GetVendorConfig(deviceId);
71c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->OnEnableInputDevice(enable);
72c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->AddVirtualInputDevice(devicePtr, deviceId);
73c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->RemoveVirtualInputDevice(deviceId);
74c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->MakeVirtualDeviceInfo(devicePtr, inDevice);
75c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->GenerateVirtualDeviceId(deviceId);
76c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->NotifyDevRemoveCallback(deviceId, inDevice);
77c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->NotifyMessage(session, id, type);
78c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->InitSessionLostCallback();
79c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->OnSessionLost(session);
80c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->GetTouchPadIds();
81c29fa5a6Sopenharmony_ci    INPUT_DEV_MGR->IsTouchableDevice(devicePtr);
82c29fa5a6Sopenharmony_ci    return true;
83c29fa5a6Sopenharmony_ci}
84c29fa5a6Sopenharmony_ci} // namespace OHOS
85c29fa5a6Sopenharmony_ci
86c29fa5a6Sopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
87c29fa5a6Sopenharmony_ci{
88c29fa5a6Sopenharmony_ci    /* Run your code on data */
89c29fa5a6Sopenharmony_ci    if (data == nullptr) {
90c29fa5a6Sopenharmony_ci        return 0;
91c29fa5a6Sopenharmony_ci    }
92c29fa5a6Sopenharmony_ci
93c29fa5a6Sopenharmony_ci    OHOS::InputDeviceManagerFuzzTest(data, size);
94c29fa5a6Sopenharmony_ci    return 0;
95c29fa5a6Sopenharmony_ci}
96c29fa5a6Sopenharmony_ci} // namespace MMI
97c29fa5a6Sopenharmony_ci} // namespace OHOS