/* * Copyright (C) 2021 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 SERVICES_INCLUDE_PERUSER_SESSION_H #define SERVICES_INCLUDE_PERUSER_SESSION_H #include #include #include #include #include #include #include "block_data.h" #include "event_handler.h" #include "event_status_manager.h" #include "global.h" #include "i_input_client.h" #include "i_input_control_channel.h" #include "i_input_data_channel.h" #include "i_input_method_agent.h" #include "i_input_method_core.h" #include "ime_cfg_manager.h" #include "input_attribute.h" #include "input_client_info.h" #include "input_control_channel_stub.h" #include "input_death_recipient.h" #include "input_method_info.h" #include "input_method_property.h" #include "input_window_info.h" #include "inputmethod_sysevent.h" #include "iremote_object.h" #include "message.h" #include "message_handler.h" #include "panel_info.h" #include "unRegistered_type.h" namespace OHOS { namespace MiscServices { struct ImeData { sptr core{ nullptr }; sptr agent{ nullptr }; sptr deathRecipient{ nullptr }; ImeData(sptr core, sptr agent, sptr deathRecipient) : core(std::move(core)), agent(std::move(agent)), deathRecipient(std::move(deathRecipient)) { } }; /**@class PerUserSession * * @brief The class provides session management in input method management service * * This class manages the sessions between input clients and input method engines for each unlocked user. */ class PerUserSession { public: explicit PerUserSession(int userId); ~PerUserSession(); int32_t OnPrepareInput(const InputClientInfo &clientInfo); int32_t OnStartInput(const InputClientInfo &inputClientInfo, sptr &agent); int32_t OnReleaseInput(const sptr &client); int32_t OnSetCoreAndAgent(const sptr &core, const sptr &agent); int32_t OnHideCurrentInput(); int32_t OnShowCurrentInput(); int32_t OnShowInput(sptr client); int32_t OnHideInput(sptr client); int32_t OnRequestShowInput(); int32_t OnRequestHideInput(); void OnSecurityChange(int32_t &security); void OnHideSoftKeyBoardSelf(); void NotifyImeChangeToClients(const Property &property, const SubProperty &subProperty); int32_t SwitchSubtype(const SubProperty &subProperty); void UpdateCurrentUserId(int32_t userId); void OnFocused(int32_t pid, int32_t uid); void OnUnfocused(int32_t pid, int32_t uid); int64_t GetCurrentClientPid(); int32_t OnPanelStatusChange(const InputWindowStatus &status, const InputWindowInfo &windowInfo); int32_t OnUpdateListenEventFlag(const InputClientInfo &clientInfo); int32_t OnRegisterProxyIme(const sptr &core, const sptr &agent); int32_t OnUnRegisteredProxyIme(UnRegisteredType type, const sptr &core); bool StartCurrentIme(int32_t userId, bool isRetry); void StopCurrentIme(); bool StartInputService(const std::shared_ptr &ime, bool isRetry); bool ActivateIme(const std::shared_ptr &ime, bool isRetry); void DeactivateIme(const std::string &bundleName, const std::string &subName); bool IsProxyImeEnable(); bool IsBoundToClient(); int32_t ExitCurrentInputType(); int32_t IsPanelShown(const PanelInfo &panelInfo, bool &isShown); bool CheckSecurityMode(); bool IsWmsReady(); private: struct ResetManager { uint32_t num{ 0 }; time_t last{}; }; enum ClientAddEvent : int32_t { PREPARE_INPUT = 0, START_LISTENING, }; int32_t userId_; // the id of the user to whom the object is linking std::recursive_mutex mtx; std::map, std::shared_ptr> mapClients_; static const int MAX_RESTART_NUM = 3; static const int IME_RESET_TIME_OUT = 3; static const int MAX_IME_START_TIME = 1000; std::mutex clientLock_; sptr currentClient_; // the current input client std::mutex resetLock; ResetManager manager; PerUserSession(const PerUserSession &); PerUserSession &operator=(const PerUserSession &); PerUserSession(const PerUserSession &&); PerUserSession &operator=(const PerUserSession &&); void OnClientDied(sptr remote); void OnImeDied(const sptr &remote, ImeType type); int AddClientInfo(sptr inputClient, const InputClientInfo &clientInfo, ClientAddEvent event); void RemoveClientInfo(const sptr &client, bool isClientDied = false); int32_t RemoveClient(const sptr &client, bool isUnbindFromClient = false); void DeactivateClient(const sptr &client); std::shared_ptr GetClientInfo(sptr inputClient); std::shared_ptr GetClientInfo(pid_t pid); void UpdateClientInfo(const sptr &client, const std::unordered_map> &updateInfos); int32_t AddImeData(ImeType type, sptr core, sptr agent); void RemoveImeData(ImeType type, bool isImeDied); int32_t RemoveIme(const sptr &core, ImeType type); std::shared_ptr GetImeData(ImeType type); std::shared_ptr GetValidIme(ImeType type); int32_t BindClientWithIme( const std::shared_ptr &clientInfo, ImeType type, bool isBindFromClient = false); void UnBindClientWithIme( const std::shared_ptr ¤tClientInfo, bool isUnbindFromClient = false); void StopClientInput(const sptr ¤tClient); void StopImeInput(ImeType currentType, const sptr ¤tChannel); int32_t HideKeyboard(const sptr ¤tClient); int32_t ShowKeyboard(const sptr ¤tClient); int32_t InitInputControlChannel(); bool IsRestartIme(); void RestartIme(); void SetCurrentClient(sptr client); sptr GetCurrentClient(); void ReplaceCurrentClient(const sptr &client); void SetInactiveClient(sptr client); sptr GetInactiveClient(); bool IsCurrentClient(int32_t pid, int32_t uid); bool IsSameClient(sptr source, sptr dest); bool IsImeStartInBind(ImeType bindImeType, ImeType startImeType); bool IsProxyImeStartInBind(ImeType bindImeType, ImeType startImeType); bool IsProxyImeStartInImeBind(ImeType bindImeType, ImeType startImeType); bool IsBindProxyImeInImeBind(ImeType bindImeType); bool IsBindImeInProxyImeBind(ImeType bindImeType); bool IsImeBindChanged(ImeType bindImeType); std::map, std::shared_ptr> GetClientMap(); BlockData isImeStarted_{ MAX_IME_START_TIME, false }; std::mutex imeDataLock_; std::unordered_map> imeData_; std::mutex attachLock_; std::condition_variable imeAttachCv_; std::mutex inactiveClientLock_; sptr inactiveClient_; // the inactive input client std::mutex focusedClientLock_; }; } // namespace MiscServices } // namespace OHOS #endif // SERVICES_INCLUDE_PERUSER_SESSION_H