1 /* 2 * Copyright (c) 2020-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 OHOS_ACELITE_FATAL_HANDLER_H 17 #define OHOS_ACELITE_FATAL_HANDLER_H 18 19 #include "component.h" 20 #include "gfx_utils/list.h" 21 #include "js_ability.h" 22 #include "non_copyable.h" 23 #include "ui_view.h" 24 25 namespace OHOS { 26 namespace ACELite { 27 class FatalHandler final : public MemoryHeap { 28 public: 29 ACE_DISALLOW_COPY_AND_MOVE(FatalHandler); 30 static FatalHandler& GetInstance(); 31 static bool IsErrorHittedWrapper(); 32 static bool IsAppExitingWrapper(); 33 const char* GetErrorStr(int errorCode) const; 34 void RegisterFatalHandler(JSAbility *ability); 35 void SetFatalError(int errorCode); 36 void HandleFatalError(int errorCode); 37 void HandleFatalInternal(); 38 void CleanUpFatalResource(); 39 bool IsJSRuntimeFatal() const; 40 bool IsJSHeapOverflow() const; 41 bool IsFatalErrorHitted() const; 42 bool IsFatalErrorHandling() const; 43 bool IsFatalErrorHandleDone() const; 44 void AttachComponentNode(Component* component); 45 void DetachComponentNode(const Component* component); 46 void SetTEHandlingFlag(bool flag); 47 bool IsTEHandling() const; 48 void ResetRendering(); 49 void SetExitingFlag(bool flag); 50 bool IsAppExiting() const; 51 // when the page is attached or destroyed by state machine, the fatal handler will be got notified 52 void SetCurrentPageRootView(UIView *pageRoot); 53 void DumpFatalTrace(int errorCode) const; 54 uint16_t GetComponentCount() const; 55 void NotifyVisibleStatusChange(bool isVisible) const; 56 // define all fatal error below, please note the jerry fatal defines, avoid conflicts 57 static const int ERR_INVALID = 0; 58 static const int ERR_NATIVE_OUT_OF_MEMORY = 200; 59 static const int ERR_READ_FWK_FILE_FAILED = 201; 60 static const int ERR_EVAL_FWK_FAILED = 202; 61 static const int ERR_READ_JS_FILE_FAILED = 203; 62 static const int ERR_EVAL_JS_FAILED = 204; 63 64 private: FatalHandler()65 FatalHandler() 66 : jsAbility_(nullptr), 67 pageRootView_(nullptr), 68 componentNodes_(), 69 fatalErrorCode_(0), 70 isRecycling_(false), 71 isFatalHandled_(false), 72 isTEHandling_(false), 73 isExiting_(false) {} ~FatalHandler()74 ~FatalHandler() {} 75 bool IsErrorSupported(int errorCode) const; 76 void RecycleComponents(); 77 JSAbility *jsAbility_; 78 UIView *pageRootView_; 79 List<Component *> componentNodes_; 80 int fatalErrorCode_; 81 bool isRecycling_; 82 bool isFatalHandled_; 83 bool isTEHandling_; 84 bool isExiting_; 85 }; 86 } // namespace ACELite 87 } // namespace OHOS 88 #endif // OHOS_ACELITE_FATAL_HANDLER_H 89