122736c2fSopenharmony_ci/*
222736c2fSopenharmony_ci * Copyright (c) 2022-2022 Huawei Device Co., Ltd.
322736c2fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
422736c2fSopenharmony_ci * you may not use this file except in compliance with the License.
522736c2fSopenharmony_ci * You may obtain a copy of the License at
622736c2fSopenharmony_ci *
722736c2fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
822736c2fSopenharmony_ci *
922736c2fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1022736c2fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1122736c2fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1222736c2fSopenharmony_ci * See the License for the specific language governing permissions and
1322736c2fSopenharmony_ci * limitations under the License.
1422736c2fSopenharmony_ci */
1522736c2fSopenharmony_ci
1622736c2fSopenharmony_ci#ifndef INPUTMETHOD_SYSEVENT_H
1722736c2fSopenharmony_ci#define INPUTMETHOD_SYSEVENT_H
1822736c2fSopenharmony_ci
1922736c2fSopenharmony_ci#include <map>
2022736c2fSopenharmony_ci#include <mutex>
2122736c2fSopenharmony_ci#include <string>
2222736c2fSopenharmony_ci#include <unordered_map>
2322736c2fSopenharmony_ci
2422736c2fSopenharmony_ci#include "global.h"
2522736c2fSopenharmony_ci#include "timer.h"
2622736c2fSopenharmony_ci
2722736c2fSopenharmony_cinamespace OHOS {
2822736c2fSopenharmony_cinamespace MiscServices {
2922736c2fSopenharmony_cienum class OperateIMEInfoCode : int32_t {
3022736c2fSopenharmony_ci    IME_SHOW_ATTACH = 0,
3122736c2fSopenharmony_ci    IME_SHOW_ENEDITABLE,
3222736c2fSopenharmony_ci    IME_SHOW_NORMAL,
3322736c2fSopenharmony_ci    IME_UNBIND,
3422736c2fSopenharmony_ci    IME_HIDE_UNBIND,
3522736c2fSopenharmony_ci    IME_HIDE_UNEDITABLE,
3622736c2fSopenharmony_ci    IME_HIDE_NORMAL,
3722736c2fSopenharmony_ci    IME_HIDE_UNFOCUSED,
3822736c2fSopenharmony_ci    IME_HIDE_SELF,
3922736c2fSopenharmony_ci    IME_HIDE_FORCE,
4022736c2fSopenharmony_ci};
4122736c2fSopenharmony_ci
4222736c2fSopenharmony_cienum class IMEBehaviour : int32_t {
4322736c2fSopenharmony_ci    START_IME = 0,
4422736c2fSopenharmony_ci    CHANGE_IME,
4522736c2fSopenharmony_ci};
4622736c2fSopenharmony_ci
4722736c2fSopenharmony_cienum class ImeState : int32_t { UNBIND = 0, BIND };
4822736c2fSopenharmony_ci
4922736c2fSopenharmony_ciclass InputMethodSysEvent {
5022736c2fSopenharmony_cipublic:
5122736c2fSopenharmony_ci    static InputMethodSysEvent &GetInstance();
5222736c2fSopenharmony_ci    void ServiceFaultReporter(const std::string &componentName, int32_t errCode);
5322736c2fSopenharmony_ci    void InputmethodFaultReporter(int32_t errCode, const std::string &name, const std::string &info);
5422736c2fSopenharmony_ci    void RecordEvent(IMEBehaviour behaviour);
5522736c2fSopenharmony_ci    void OperateSoftkeyboardBehaviour(OperateIMEInfoCode infoCode);
5622736c2fSopenharmony_ci    void ReportImeState(ImeState state, pid_t pid, const std::string &bundleName);
5722736c2fSopenharmony_ci    bool StartTimerForReport();
5822736c2fSopenharmony_ci    void SetUserId(int32_t userId);
5922736c2fSopenharmony_ci
6022736c2fSopenharmony_ciprivate:
6122736c2fSopenharmony_ci    InputMethodSysEvent() = default;
6222736c2fSopenharmony_ci    ~InputMethodSysEvent();
6322736c2fSopenharmony_ci    using TimerCallback = std::function<void()>;
6422736c2fSopenharmony_ci    void ImeUsageBehaviourReporter();
6522736c2fSopenharmony_ci    const std::string GetOperateInfo(int32_t infoCode);
6622736c2fSopenharmony_ci    std::string GetOperateAction(int32_t infoCode);
6722736c2fSopenharmony_ci    bool StartTimer(const TimerCallback &callback, uint32_t interval);
6822736c2fSopenharmony_ci    void StopTimer();
6922736c2fSopenharmony_ci
7022736c2fSopenharmony_ciprivate:
7122736c2fSopenharmony_ci    static const std::unordered_map<int32_t, std::string> operateInfo_;
7222736c2fSopenharmony_ci    static std::map<int32_t, int32_t> inputmethodBehaviour_;
7322736c2fSopenharmony_ci    std::mutex behaviourMutex_;
7422736c2fSopenharmony_ci
7522736c2fSopenharmony_ci    std::shared_ptr<Utils::Timer> timer_ = nullptr;
7622736c2fSopenharmony_ci    int32_t userId_ = 0;
7722736c2fSopenharmony_ci    uint32_t timerId_ = 0;
7822736c2fSopenharmony_ci    std::mutex timerLock_;
7922736c2fSopenharmony_ci    static inline constexpr int32_t ONE_DAY_IN_HOURS = 24;
8022736c2fSopenharmony_ci    static inline constexpr int32_t ONE_HOUR_IN_SECONDS = 1 * 60 * 60; // 1 hour
8122736c2fSopenharmony_ci    static inline constexpr int32_t SECONDS_TO_MILLISECONDS = 1000;
8222736c2fSopenharmony_ci};
8322736c2fSopenharmony_ci} // namespace MiscServices
8422736c2fSopenharmony_ci} // namespace OHOS
8522736c2fSopenharmony_ci#endif // INPUTMETHOD_SYSEVENT_H