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