/* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "input_adapter.h" #include "input_manager.h" #include "devicestatus_define.h" #undef LOG_TAG #define LOG_TAG "InputAdapter" namespace OHOS { namespace Msdp { namespace DeviceStatus { int32_t InputAdapter::AddMonitor(std::function)> callback) { int32_t monitorId = MMI::InputManager::GetInstance()->AddMonitor(callback); if (monitorId < 0) { FI_HILOGE("AddMonitor fail"); } return monitorId; } int32_t InputAdapter::AddMonitor(std::function)> callback) { int32_t monitorId = MMI::InputManager::GetInstance()->AddMonitor(callback); if (monitorId < 0) { FI_HILOGE("AddMonitor fail"); } return monitorId; } void InputAdapter::RemoveMonitor(int32_t monitorId) { MMI::InputManager::GetInstance()->RemoveMonitor(monitorId); } int32_t InputAdapter::AddInterceptor(std::function)> pointerCb) { return AddInterceptor(pointerCb, nullptr); } int32_t InputAdapter::AddInterceptor(std::function)> keyCb) { return AddInterceptor(nullptr, keyCb); } int32_t InputAdapter::AddInterceptor(std::function)> pointerCb, std::function)> keyCb) { uint32_t tags { 0u }; if (pointerCb != nullptr) { tags |= MMI::CapabilityToTags(MMI::INPUT_DEV_CAP_POINTER); } if (keyCb != nullptr) { tags |= MMI::CapabilityToTags(MMI::INPUT_DEV_CAP_KEYBOARD); } if (tags == 0u) { FI_HILOGE("Both interceptors are null"); return -1; } auto interceptor = std::make_shared(pointerCb, keyCb); constexpr int32_t DEFAULT_PRIORITY { 499 }; int32_t interceptorId = MMI::InputManager::GetInstance()->AddInterceptor(interceptor, DEFAULT_PRIORITY, tags); if (interceptorId < 0) { FI_HILOGE("AddInterceptor fail"); } return interceptorId; } void InputAdapter::RemoveInterceptor(int32_t interceptorId) { MMI::InputManager::GetInstance()->RemoveInterceptor(interceptorId); } int32_t InputAdapter::AddFilter(std::function)> callback) { constexpr int32_t DEFAULT_PRIORITY { 220 }; auto filter = std::make_shared(callback); uint32_t tags = CapabilityToTags(MMI::INPUT_DEV_CAP_POINTER); int32_t filterId = MMI::InputManager::GetInstance()->AddInputEventFilter(filter, DEFAULT_PRIORITY, tags); if (filterId < 0) { FI_HILOGE("AddInputEventFilter fail"); } return filterId; } void InputAdapter::RemoveFilter(int32_t filterId) { MMI::InputManager::GetInstance()->RemoveInputEventFilter(filterId); } int32_t InputAdapter::SetPointerVisibility(bool visible, int32_t priority) { FI_HILOGI("Set pointer visibility, visible:%{public}s", visible ? "true" : "false"); return MMI::InputManager::GetInstance()->SetPointerVisible(visible, priority); } int32_t InputAdapter::SetPointerLocation(int32_t x, int32_t y) { return MMI::InputManager::GetInstance()->SetPointerLocation(x, y); } int32_t InputAdapter::EnableInputDevice(bool enable) { return MMI::InputManager::GetInstance()->EnableInputDevice(enable); } void InputAdapter::SimulateInputEvent(std::shared_ptr pointerEvent) { MMI::InputManager::GetInstance()->SimulateInputEvent(pointerEvent); } void InputAdapter::SimulateInputEvent(std::shared_ptr keyEvent) { MMI::InputManager::GetInstance()->SimulateInputEvent(keyEvent); } int32_t InputAdapter::AddVirtualInputDevice(std::shared_ptr device, int32_t &deviceId) { return MMI::InputManager::GetInstance()->AddVirtualInputDevice(device, deviceId); } int32_t InputAdapter::RemoveVirtualInputDevice(int32_t deviceId) { return MMI::InputManager::GetInstance()->RemoveVirtualInputDevice(deviceId); } } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS