1 /* 2 * Copyright (c) 2021 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 FOUNDATION_ACE_FRAMEWORKS_BASE_LOG_EVENT_REPORT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BASE_LOG_EVENT_REPORT_H 18 19 #include <string> 20 #include <vector> 21 #include <unordered_map> 22 23 #include "base/perfmonitor/perf_monitor.h" 24 #include "base/utils/macros.h" 25 #include "core/components_ng/pattern/scrollable/scrollable.h" 26 #include "core/components_ng/base/frame_scene_status.h" 27 28 namespace OHOS::Ace { 29 30 const std::string EXCEPTION_FRAMEWORK_APP_START = "FRAMEWORK_APP_START_EXCEPTION"; 31 const std::string EXCEPTION_FRAMEWORK_PAGE_ROUTER = "FRAMEWORK_PAGE_ROUTER_EXCEPTION"; 32 const std::string EXCEPTION_COMPONENT = "COMPONENT_EXCEPTION"; 33 const std::string EXCEPTION_API_CHANNEL = "API_CHANNEL_EXCEPTION"; 34 const std::string EXCEPTION_RENDER = "RENDER_EXCEPTION"; 35 const std::string EXCEPTION_JS = "JS_EXCEPTION"; 36 const std::string EXCEPTION_ANIMATION = "ANIMATION_EXCEPTION"; 37 const std::string EXCEPTION_EVENT = "EVENT_EXCEPTION"; 38 const std::string EXCEPTION_INTERNATIONALIZATION = "INTERNATIONALIZATION_EXCEPTION"; 39 const std::string EXCEPTION_ACCESSIBILITY = "ACCESSIBILITY_EXCEPTION"; 40 const std::string EXCEPTION_FORM = "FORM_EXCEPTION"; 41 42 // EXCEPTION_FRAMEWORK_APP_START 43 enum class AppStartExcepType { 44 CREATE_CONTAINER_ERR = 1, 45 SET_VIEW_ERR, 46 VIEW_TYPE_ERR, 47 GET_PACKAGE_PATH_ERR, 48 JNI_CLASS_ERR, 49 JNI_INIT_ERR = 10, 50 FRONTEND_TYPE_ERR, 51 PIPELINE_CONTEXT_ERR, 52 VIEW_STATE_ERR, 53 RESOURCE_REGISTER_INIT_ERR, 54 JS_ENGINE_CREATE_ERR, 55 JAVA_EVENT_CALLBACK_INIT_ERR, 56 }; 57 58 // EXCEPTION_FRAMEWORK_PAGE_ROUTER 59 enum class PageRouterExcepType { 60 ROUTE_PARSE_ERR = 0, 61 PAGE_STACK_OVERFLOW_ERR, 62 RUN_PAGE_ERR, 63 UPDATE_PAGE_ERR, 64 LOAD_PAGE_ERR, 65 REPLACE_PAGE_ERR, 66 }; 67 68 // EXCEPTION_COMPONENT 69 enum class ComponentExcepType { 70 TEXT_INPUT_CONNECTION_CLOSE_ERR = 0, 71 GET_THEME_ERR, 72 BUTTON_COMPONENT_ERR, 73 DIALOG_EVENT_ERR, 74 DOM_NODE_NOT_FOUND, 75 SET_ROOT_DOM_NODE_ERR, 76 IMAGE_ANIMATOR_ERR, 77 LIST_COMPONENT_ERR, 78 LIST_ITEM_ERR, 79 MARQUEE_ERR, 80 NAVIGATION_BAR_ERR, 81 }; 82 83 // EXCEPTION_API_CHANNEL 84 enum class APIChannelExcepType { 85 JS_BRIDGE_INIT_ERR = 0, 86 SET_FUNCTION_ERR, 87 }; 88 89 // EXCEPTION_RENDER 90 enum class RenderExcepType { 91 VIEW_SCALE_ERR = 0, 92 RENDER_ANIMATION_ERR, 93 RENDER_COMPONENT_ERR, 94 CLIP_ERR, 95 UI_THREAD_STUCK, 96 }; 97 98 // EXCEPTION_JS 99 enum class JsExcepType { 100 GET_NODE_ERR = 0, 101 CREATE_NODE_ERR, 102 CREATE_DOM_BODY_ERR, 103 REMOVE_DOM_ELEMENT_ERR, 104 UPDATE_DOM_ELEMENT_ERR, 105 JS_ENGINE_INIT_ERR, 106 JS_RUNTIME_OBJ_ERR, 107 JS_CONTEXT_INIT_ERR, 108 JS_THREAD_STUCK, 109 }; 110 111 // EXCEPTION_ANIMATION 112 enum class AnimationExcepType { 113 ANIMATION_BRIDGE_ERR = 0, 114 ANIMATION_PAGE_ERR, 115 }; 116 117 // EXCEPTION_EVENT 118 enum class EventExcepType { 119 FIRE_EVENT_ERR = 1, 120 }; 121 122 // EXCEPTION_INTERNATIONALIZATION 123 enum class InternalExcepType { 124 CHANGE_LOCALE_ERR = 0, 125 }; 126 127 // EXCEPTION_ACCESSIBILITY 128 enum class AccessibilityExcepType { 129 CREATE_ACCESSIBILITY_NODE_ERR = 0, 130 GET_NODE_ERR, 131 }; 132 133 // EXCEPTION_FORM 134 enum class FormExcepType { 135 RUN_PAGE_ERR = 0, 136 LOAD_PAGE_ERR, 137 CREATE_NODE_ERR, 138 UPDATE_PAGE_ERR, 139 FIRE_FORM_EVENT_ERR, 140 ACTION_EVENT_CALLBACK_ERR, 141 }; 142 143 #ifdef VSYNC_TIMEOUT_CHECK 144 enum class VsyncExcepType { 145 UI_VSYNC_TIMEOUT 146 }; 147 #endif 148 149 enum class RawEventType { WARNING, FREEZE, RECOVER }; 150 151 enum class ScrollableErrorType { 152 GET_CHILD_FAILED = 0, 153 INTERNAL_ERROR, 154 GESTURE_MISMATCH, 155 CONTROLLER_NOT_BIND, 156 STOP_ANIMATION_TIMEOUT, 157 }; 158 159 struct EventInfo { 160 std::string eventType; 161 int32_t errorType = 0; 162 std::string pageUrl; 163 }; 164 165 struct DragInfo { 166 int32_t isCrossing = -1; 167 int32_t result = -1; 168 int32_t summaryNum = -1; 169 std::string dragBehavior; 170 std::string pNameId; 171 std::string pVersionId; 172 std::string hostName; 173 std::string summaryType; 174 std::string allowDropType; 175 }; 176 177 enum class RichEditorErrorType { 178 DELETE_BACKWARD = 0, 179 DELETE_FORWARD, 180 INSERT_VALUE, 181 DELETE_NODE, 182 }; 183 184 struct RichEditorInfo { 185 RichEditorErrorType errorType; 186 int32_t spanLength = -1; 187 int32_t textLength = -1; 188 int32_t spanIndex = -1; 189 }; 190 191 struct FRCSceneFpsInfo { 192 int64_t duration_120 = 0; 193 int64_t duration_90 = 0; 194 int64_t duration_72 = 0; 195 int64_t duration_60 = 0; 196 }; 197 198 class ACE_FORCE_EXPORT EventReport { 199 public: 200 static void SendEvent(const EventInfo& eventInfo); 201 static void SendJsCardRenderTimeEvent( 202 const std::string& sessionID, 203 const std::string& timeType, 204 uint64_t timeDelay); 205 206 static void SendAppStartException(AppStartExcepType type); 207 static void SendPageRouterException(PageRouterExcepType type, const std::string& pageUrl = ""); 208 static void SendComponentException(ComponentExcepType type); 209 static void SendAPIChannelException(APIChannelExcepType type); 210 static void SendRenderException(RenderExcepType type); 211 static void SendJsException(JsExcepType type); 212 static void SendAnimationException(AnimationExcepType type); 213 static void SendEventException(EventExcepType type); 214 static void SendInternalException(InternalExcepType type); 215 static void SendAccessibilityException(AccessibilityExcepType type); 216 static void ReportAccessibilityFailEvent(const std::string& actionName); 217 static void SendFormException(FormExcepType type); 218 #ifdef VSYNC_TIMEOUT_CHECK 219 static void SendVsyncException(VsyncExcepType type, uint32_t windowId, int32_t instanceId, uint64_t timeStamp); 220 #endif 221 222 static void JsEventReport(int32_t eventType, const std::string& jsonStr); 223 static void JsErrReport( 224 const std::string& packageName, const std::string& reason, const std::string& summary); 225 static void ANRRawReport(RawEventType type, int32_t uid, const std::string& packageName, 226 const std::string& processName, const std::string& msg = " "); 227 static void ANRShowDialog(int32_t uid, const std::string& packageName, 228 const std::string& processName, const std::string& msg = ""); 229 static void JankFrameReport(int64_t startTime, int64_t duration, const std::vector<uint16_t>& jank, 230 const std::string& pageUrl, uint32_t jankStatusVersion = 1); 231 static void ReportDoubleClickTitle(int32_t stateChange); 232 static void ReportClickTitleMaximizeMenu(int32_t maxMenuItem, int32_t stateChange); 233 static void ReportPageNodeOverflow(const std::string& pageUrl, int32_t nodeCount, int32_t threshold); 234 static void ReportPageDepthOverflow(const std::string& pageUrl, int32_t depth, int32_t threshold); 235 static void ReportFunctionTimeout(const std::string& functionName, int64_t time, int32_t threshold); 236 static void ReportHoverStatusChange(int32_t foldStatus, int32_t time, bool isHoverMode, 237 int32_t appRotation, int32_t windowMode); 238 static void ReportNonManualPostCardActionInfo(const std::string& formName, const std::string& bundleName, 239 const std::string& abilityName, const std::string& moduleName, int32_t dimension); 240 static void ReportUiExtensionTransparentEvent(const std::string& pageUrl, const std::string& bundleName, 241 const std::string& moduleName); 242 static void ReportDragInfo(const DragInfo& dragInfo); 243 static void ReportRichEditorInfo(const RichEditorInfo& richEditorInfo); 244 static void ReportScrollableErrorEvent( 245 const std::string& nodeType, ScrollableErrorType errorType, const std::string& subErrorType); 246 static void ReportTextFieldErrorEvent(int32_t frameNodeId, int32_t depth, const std::string& errorType); 247 static void ReportClipboardFailEvent(const std::string& errorType); 248 static void ReportReusedNodeSkipMeasureApp(); 249 static void ReportPageSlidInfo(NG::SlidInfo &slidInfo); 250 static void SendDiffFrameRatesDuring(const std::string& scene, const FRCSceneFpsInfo& curFRCSceneFpsInfo_); 251 static void FrameRateDurationsStatistics(int32_t expectedRate, const std::string& scene, NG::SceneStatus status); 252 static void AddFrameRateDuration(int32_t frameRate, int64_t duration); 253 254 static void StartFormModifyTimeoutReportTimer(int64_t formId, const std::string &bundleName, 255 const std::string &formName); 256 static void StopFormModifyTimeoutReportTimer(int64_t formId); 257 private: 258 static void SendEventInner(const EventInfo& eventInfo); 259 static FRCSceneFpsInfo curFRCSceneFpsInfo_; 260 static int64_t calTime_; 261 static int32_t calFrameRate_; 262 static std::unordered_map<int64_t, int32_t> formEventTimerMap_; 263 static std::mutex formEventTimerMutex_; 264 }; 265 266 } // namespace OHOS::Ace 267 268 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_LOG_EVENT_REPORT_H 269