/* * Copyright (c) 2021-2022 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. */ #ifndef INPUT_MANAGER_IMPL_H #define INPUT_MANAGER_IMPL_H #include #include "singleton.h" #include "net_packet.h" #include "display_info.h" #include "event_filter_service.h" #include "event_handler.h" #include "if_mmi_client.h" #include "input_device_impl.h" #include "input_device_cooperate_impl.h" #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR #include "input_interceptor_manager.h" #endif // OHOS_BUILD_ENABLE_INTERCEPTOR #ifdef OHOS_BUILD_ENABLE_MONITOR #include "input_monitor_manager.h" #endif // OHOS_BUILD_ENABLE_MONITOR #include "i_anr_observer.h" #include "i_input_event_consumer.h" #include "key_option.h" #include "pointer_event.h" namespace OHOS { namespace MMI { class InputManagerImpl final { DECLARE_SINGLETON(InputManagerImpl); public: DISALLOW_MOVE(InputManagerImpl); void UpdateDisplayInfo(const DisplayGroupInfo &displayGroupInfo); int32_t SubscribeKeyEvent( std::shared_ptr keyOption, std::function)> callback ); void UnsubscribeKeyEvent(int32_t subscriberId); int32_t AddInputEventFilter(std::function)> filter); void SetWindowInputEventConsumer(std::shared_ptr inputEventConsumer, std::shared_ptr eventHandler); #ifdef OHOS_BUILD_ENABLE_KEYBOARD void OnKeyEvent(std::shared_ptr keyEvent); #endif // OHOS_BUILD_ENABLE_KEYBOARD #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) void OnPointerEvent(std::shared_ptr pointerEvent); #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH int32_t PackDisplayData(NetPacket &pkt); int32_t AddMonitor(std::function)> monitor); int32_t AddMonitor(std::function)> monitor); int32_t AddMonitor(std::shared_ptr consumer); void RemoveMonitor(int32_t monitorId); void MarkConsumed(int32_t monitorId, int32_t eventId); void MoveMouse(int32_t offsetX, int32_t offsetY); int32_t AddInterceptor(std::shared_ptr interceptor); int32_t AddInterceptor(std::function)> interceptor); void RemoveInterceptor(int32_t interceptorId); void SimulateInputEvent(std::shared_ptr keyEvent); void SimulateInputEvent(std::shared_ptr pointerEvent); void OnConnected(); int32_t RegisterDevListener(std::string type, std::shared_ptr listener); int32_t UnregisterDevListener(std::string type, std::shared_ptr listener = nullptr); int32_t GetDeviceIds(std::function&)> callback); int32_t GetDevice(int32_t deviceId, std::function)> callback); int32_t SupportKeys(int32_t deviceId, std::vector &keyCodes, std::function&)> callback); int32_t GetKeyboardType(int32_t deviceId, std::function callback); int32_t SetPointerVisible(bool visible); bool IsPointerVisible(); int32_t SetPointerStyle(int32_t windowId, int32_t pointerStyle); int32_t GetPointerStyle(int32_t windowId, int32_t &pointerStyle); int32_t SetPointerSpeed(int32_t speed); int32_t GetPointerSpeed(int32_t &speed); void SetAnrObserver(std::shared_ptr observer); void OnAnr(int32_t pid); int32_t RegisterCooperateListener(std::shared_ptr listener); int32_t UnregisterCooperateListener(std::shared_ptr listener = nullptr); int32_t EnableInputDeviceCooperate(bool enabled, std::function callback); int32_t StartInputDeviceCooperate(const std::string &sinkDeviceId, int32_t srcInputDeviceId, std::function callback); int32_t StopDeviceCooperate(std::function callback); int32_t GetInputDeviceCooperateState(const std::string &deviceId, std::function callback); int32_t SetInputDevice(const std::string& dhid, const std::string& screenId); bool GetFunctionKeyState(int32_t funcKey); int32_t SetFunctionKeyState(int32_t funcKey, bool enable); private: int32_t PackWindowInfo(NetPacket &pkt); int32_t PackDisplayInfo(NetPacket &pkt); void PrintDisplayInfo(); void SendDisplayInfo(); #ifdef OHOS_BUILD_ENABLE_KEYBOARD void OnKeyEventTask(std::shared_ptr consumer, std::shared_ptr keyEvent); #endif // OHOS_BUILD_ENABLE_KEYBOARD #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) void OnPointerEventTask(std::shared_ptr consumer, std::shared_ptr pointerEvent); #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH private: sptr eventFilterService_ { nullptr }; std::shared_ptr consumer_ { nullptr }; std::vector> anrObservers_; DisplayGroupInfo displayGroupInfo_ {}; std::mutex mtx_; std::mutex handleMtx_; std::condition_variable cv_; std::thread ehThread_; std::shared_ptr eventHandler_ { nullptr }; }; #define InputMgrImpl ::OHOS::Singleton::GetInstance() } // namespace MMI } // namespace OHOS #endif // INPUT_MANAGER_IMPL_H