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 MISCSERVICES_PASTEBOARD_HI_VIEW_ADAPTER_H 17 #define MISCSERVICES_PASTEBOARD_HI_VIEW_ADAPTER_H 18 19 #include <sys/time.h> 20 21 #include <map> 22 #include <mutex> 23 #include <string> 24 #include <vector> 25 26 #include "dfx_code_constant.h" 27 #include "dfx_types.h" 28 #include "hisysevent.h" 29 30 namespace OHOS { 31 namespace MiscServices { 32 enum DataConsumingLevel : std::int32_t { 33 DATA_LEVEL_ONE = 0, 34 DATA_LEVEL_TWO, 35 DATA_LEVEL_THREE, 36 DATA_LEVEL_FOUR, 37 DATA_LEVEL_FIVE, 38 DATA_LEVEL_SIX, 39 DATA_LEVEL_SEVEN, 40 }; 41 enum TimeConsumingLevel : std::int32_t { 42 TIME_LEVEL_ONE = 0, 43 TIME_LEVEL_TWO, 44 TIME_LEVEL_THREE, 45 TIME_LEVEL_FOUR, 46 TIME_LEVEL_FIVE, 47 TIME_LEVEL_SIX, 48 TIME_LEVEL_SEVEN, 49 TIME_LEVEL_EIGHT, 50 TIME_LEVEL_NINE, 51 TIME_LEVEL_TEN, 52 TIME_LEVEL_ELEVEN, 53 }; 54 55 class HiViewAdapter { 56 public: 57 ~HiViewAdapter(); 58 static void ReportPasteboardFault(int dfxCode, const PasteboardFaultMsg &msg); 59 static void ReportTimeConsumingStatistic(const TimeConsumingStat &stat); 60 static void ReportPasteboardBehaviour(const PasteboardBehaviourMsg &msg); 61 static void StartTimerThread(); 62 static std::map<int, int> InitDataMap(); 63 static std::map<int, int> InitTimeMap(); 64 65 private: 66 static void InvokePasteBoardBehaviour(); 67 static void InitializeTimeConsuming(int initFlag); 68 static void CopyTimeConsumingCount(int dataLevel, int timeLevel); 69 static void PasteTimeConsumingCount(int dataLevel, int timeLevel); 70 static void RemotePasteTimeConsumingCount(int dataLevel, int timeLevel); 71 static void CopyTimeConsuming(const TimeConsumingStat &stat, int level); 72 static void PasteTimeConsuming(const TimeConsumingStat &stat, int level); 73 static const char *GetDataLevel(int dataLevel); 74 static void InvokeTimeConsuming(); 75 static void ReportBehaviour(std::map<std::string, int> &behaviour, const char *statePasteboard); 76 static void ReportStatisticEvent( 77 const std::vector<std::map<int, int>> &timeConsumingStat, const std::string &pasteboardState); 78 79 static std::mutex timeConsumingMutex_; 80 static std::vector<std::map<int, int>> copyTimeConsumingStat_; 81 static std::vector<std::map<int, int>> pasteTimeConsumingStat_; 82 static std::vector<std::map<int, int>> remotePasteTimeConsumingStat_; 83 84 static std::mutex behaviourMutex_; 85 static std::map<std::string, int> copyPasteboardBehaviour_; 86 static std::map<std::string, int> pastePasteboardBehaviour_; 87 static std::map<std::string, int> remotePastePasteboardBehaviour_; 88 89 static std::map<int, int> dataMap_; 90 static std::map<int, int> timeMap_; 91 92 static std::string CoverEventID(int dfxCode); 93 private: 94 static std::mutex runMutex_; 95 static bool running_; 96 97 static inline constexpr int ONE_DAY_IN_HOURS = 24; 98 static inline constexpr int EXEC_HOUR_TIME = 23; 99 static inline constexpr int EXEC_MIN_TIME = 60; 100 static inline constexpr int ONE_MINUTE_IN_SECONDS = 60; 101 static inline constexpr int ONE_HOUR_IN_SECONDS = 1 * 60 * 60; // 1 hour 102 103 // statistic key 104 static inline const char *PASTEBOARD_STATE = "PASTEBOARD_STATE"; 105 106 static inline const char *ZERO_TO_HUNDRED_KB = "ZERO_TO_HUNDRED_KB"; 107 static inline const char *HUNDRED_TO_FIVE_HUNDREDS_KB = "HUNDRED_TO_FIVE_HUNDREDS_KB"; 108 static inline const char *FIVE_HUNDREDS_TO_THOUSAND_KB = "FIVE_HUNDREDS_TO_THOUSAND_KB"; 109 static inline const char *ONE_TO_FIVE_MB = "ONE_TO_FIVE_MB"; 110 static inline const char *FIVE_TO_TEN_MB = "FIVE_TO_TEN_MB"; 111 static inline const char *TEN_TO_FIFTY_MB = "TEN_TO_FIFTY_MB"; 112 static inline const char *OVER_FIFTY_MB = "OVER_FIFTY_MB"; 113 static inline const char *CONSUMING_DATA = "CONSUMING_DATA"; 114 static inline const char *DATA_LEVEL = "DATA_LEVEL"; 115 static inline constexpr const char *NET_TYPE = "NET_TYPE"; 116 // behaviour key 117 static inline const char *TOP_ONE_APP = "TOP_ONE_APP"; 118 static inline const char *TOP_TOW_APP = "TOP_TOW_APP"; 119 static inline const char *TOP_THREE_APP = "TOP_THREE_APP"; 120 static inline const char *TOP_FOUR_APP = "TOP_FOUR_APP"; 121 static inline const char *TOP_FIVE_APP = "TOP_FIVE_APP"; 122 static inline const char *TOP_SIX_APP = "TOP_SIX_APP"; 123 static inline const char *TOP_SEVEN_APP = "TOP_SEVEN_APP"; 124 static inline const char *TOP_EIGHT_APP = "TOP_EIGHT_APP"; 125 static inline const char *TOP_NINE_APP = "TOP_NINE_APP"; 126 static inline const char *TOP_TEN_APP = "TOP_TEN_APP"; 127 128 static inline const char *COPY_STATE = "COPY_STATE"; 129 static inline const char *PASTE_STATE = "PASTE_STATE"; 130 static inline constexpr const char *REMOTE_PASTE_STATE = "REMOTE_PASTE_STATE"; 131 132 static inline const int INIT_COPY_TIME_SONSUMING = 7; 133 static inline const int INIT_PASTE_TIME_SONSUMING = 8; 134 static inline constexpr const int INIT_REMOTE_PASTE_TIME_SONSUMING = 9; 135 }; 136 } // namespace MiscServices 137 } // namespace OHOS 138 #endif // MISCSERVICES_PASTEBOARD_HI_VIEW_ADAPTER_H 139