1 /* 2 * Copyright (c) 2025 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 IMF_HISYSEVENT_INFO_H 17 #define IMF_HISYSEVENT_INFO_H 18 #include <algorithm> 19 #include <utility> 20 21 #include "input_client_info.h" 22 #include "serializable.h" 23 namespace OHOS { 24 namespace MiscServices { 25 26 enum ImfEventType : uint32_t { 27 CLIENT_ATTACH, 28 CLIENT_SHOW, 29 IME_START_INPUT, 30 BASE_TEXT_OPERATOR, 31 }; 32 33 enum ImfFaultEvent : uint32_t { 34 HI_SYS_FAULT_EVENT_BEGIN, 35 CLIENT_ATTACH_FAILED = HI_SYS_FAULT_EVENT_BEGIN, 36 CLIENT_SHOW_FAILED, 37 IME_START_INPUT_FAILED, 38 BASE_TEXT_OPERATION_FAILED, 39 HI_SYS_FAULT_EVENT_END, 40 }; 41 42 enum ImfStatisticsEvent : uint32_t { 43 HI_SYS_STATISTICS_EVENT_BEGIN, 44 CLIENT_ATTACH_STATISTICS = HI_SYS_STATISTICS_EVENT_BEGIN, 45 CLIENT_SHOW_STATISTICS, 46 IME_START_INPUT_STATISTICS, 47 BASE_TEXT_OPERATION_STATISTICS, 48 HI_SYS_STATISTICS_EVENT_END, 49 }; 50 51 struct HiSysOriginalInfo { 52 int32_t eventCode; 53 int32_t errCode; 54 std::string peerName; 55 int64_t peerPid; 56 int32_t peerUserId; 57 ClientType clientType; 58 int32_t inputPattern; 59 bool isShowKeyboard; 60 std::string imeName; 61 int32_t imeCbTime; // ms 62 int32_t baseTextOperationTime; // ms 63 bool operator==(const HiSysOriginalInfo &info) const 64 { 65 return (eventCode == info.eventCode && errCode == info.errCode && peerName == info.peerName 66 && peerUserId == info.peerUserId && clientType == info.clientType && inputPattern == info.inputPattern 67 && isShowKeyboard == info.isShowKeyboard && imeName == info.imeName && imeCbTime == info.imeCbTime 68 && baseTextOperationTime == info.baseTextOperationTime); 69 } 70 class Builder { 71 public: 72 Builder(); 73 Builder &SetEventCode(int32_t eventCode); 74 Builder &SetErrCode(int32_t errCode); 75 Builder &SetPeerName(const std::string &peerName); 76 Builder &SetPeerUserId(int32_t peerUserId); 77 Builder &SetPeerPid(int64_t peerPid); 78 Builder &SetClientType(ClientType clientType); 79 Builder &SetInputPattern(int32_t inputPattern); 80 Builder &SetIsShowKeyboard(bool isShowKeyboard); 81 Builder &SetImeName(const std::string &imeName); 82 Builder &SetImeCbTime(int32_t imeCbTime); 83 Builder &SetBaseTextOperatorTime(int32_t baseTextOperationTime); 84 std::shared_ptr<HiSysOriginalInfo> Build(); 85 86 private: 87 std::shared_ptr<HiSysOriginalInfo> info_ = nullptr; 88 }; 89 }; 90 91 struct CountDistributionInfo : public Serializable { 92 static constexpr uint32_t MAX_COUNT_DISTRIBUTIONS_INTERVAL = 10; CountDistributionInfoCountDistributionInfo93 explicit CountDistributionInfo(uint32_t intervalNum) 94 { 95 if (intervalNum > MAX_COUNT_DISTRIBUTIONS_INTERVAL) { 96 intervalNum = MAX_COUNT_DISTRIBUTIONS_INTERVAL; 97 } 98 countDistributions.resize(intervalNum); 99 }; 100 void ModCountDistributions(uint32_t intervalIndex, const std::string &key); 101 bool Marshal(cJSON *node) const override; 102 int32_t count{ 0 }; 103 std::vector<std::vector<std::pair<std::string, uint32_t>>> countDistributions; 104 }; 105 106 struct SuccessRateStatistics : public Serializable { SuccessRateStatisticsSuccessRateStatistics107 SuccessRateStatistics(uint32_t succeedIntervalNum, uint32_t failedIntervalNum) 108 : succeedInfo(CountDistributionInfo(succeedIntervalNum)), failedInfo(CountDistributionInfo(failedIntervalNum)) 109 { 110 } MarshalSuccessRateStatistics111 bool Marshal(cJSON *node) const override 112 { 113 auto ret = SetValue(node, GET_NAME(SUCCEED), succeedInfo); 114 return SetValue(node, GET_NAME(FAILED), failedInfo) && ret; 115 } 116 CountDistributionInfo succeedInfo; 117 CountDistributionInfo failedInfo; 118 }; 119 120 } // namespace MiscServices 121 } // namespace OHOS 122 123 #endif // IMF_HISYSEVENT_INFO_H