1 /* 2 * Copyright (c) 2022-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef INPUTMETHOD_SYSEVENT_H 17 #define INPUTMETHOD_SYSEVENT_H 18 19 #include <map> 20 #include <mutex> 21 #include <string> 22 #include <unordered_map> 23 24 #include "global.h" 25 #include "timer.h" 26 27 namespace OHOS { 28 namespace MiscServices { 29 enum class OperateIMEInfoCode : int32_t { 30 IME_SHOW_ATTACH = 0, 31 IME_SHOW_ENEDITABLE, 32 IME_SHOW_NORMAL, 33 IME_UNBIND, 34 IME_HIDE_UNBIND, 35 IME_HIDE_UNEDITABLE, 36 IME_HIDE_NORMAL, 37 IME_HIDE_UNFOCUSED, 38 IME_HIDE_SELF, 39 }; 40 41 enum class IMEBehaviour : int32_t { 42 START_IME = 0, 43 CHANGE_IME, 44 }; 45 46 class InputMethodSysEvent { 47 public: 48 static InputMethodSysEvent &GetInstance(); 49 void ServiceFaultReporter(const std::string &componentName, int32_t errCode); 50 void InputmethodFaultReporter(int32_t errCode, const std::string &name, const std::string &info); 51 void RecordEvent(IMEBehaviour behaviour); 52 void OperateSoftkeyboardBehaviour(OperateIMEInfoCode infoCode); 53 bool StartTimerForReport(); 54 void SetUserId(int32_t userId); 55 56 private: 57 InputMethodSysEvent() = default; 58 ~InputMethodSysEvent(); 59 using TimerCallback = std::function<void()>; 60 void ImeUsageBehaviourReporter(); 61 const std::string GetOperateInfo(int32_t infoCode); 62 std::string GetOperateAction(int32_t infoCode); 63 bool StartTimer(const TimerCallback &callback, uint32_t interval); 64 void StopTimer(); 65 66 private: 67 static const std::unordered_map<int32_t, std::string> operateInfo_; 68 static std::map<int32_t, int32_t> inputmethodBehaviour_; 69 std::mutex behaviourMutex_; 70 71 std::shared_ptr<Utils::Timer> timer_ = nullptr; 72 int32_t userId_ = 0; 73 uint32_t timerId_ = 0; 74 std::mutex timerLock_; 75 static inline constexpr int32_t ONE_DAY_IN_HOURS = 24; 76 static inline constexpr int32_t ONE_HOUR_IN_SECONDS = 1 * 60 * 60; // 1 hour 77 static inline constexpr int32_t SECONDS_TO_MILLISECONDS = 1000; 78 }; 79 } // namespace MiscServices 80 } // namespace OHOS 81 #endif // INPUTMETHOD_SYSEVENT_H