diff --git a/frameworks/native_engine/async/js_async_work.cpp b/frameworks/native_engine/async/js_async_work.cpp index 7f90dfe..7fc523f 100644 --- a/frameworks/native_engine/async/js_async_work.cpp +++ b/frameworks/native_engine/async/js_async_work.cpp @@ -24,15 +24,21 @@ FatalHandleFunc JsAsyncWork::isAppExiting_ = nullptr; #if (defined(__LINUX__) || defined(__LITEOS_A__)) PostUITaskFunc JsAsyncWork::postUITask_ = nullptr; #endif +bool JsAsyncWork::isEnvInitialized_ = false; void JsAsyncWork::SetAppQueueHandler(const QueueHandler handler) { appQueuehandler_ = handler; } +void JsAsyncWork::SetEnvStatus(bool envInitialized) +{ + isEnvInitialized_ = envInitialized; +} + bool JsAsyncWork::DispatchToLoop(AbilityMsgId msgId, void *data) { - if (appQueuehandler_ == nullptr) { + if (appQueuehandler_ == nullptr || !isEnvInitialized_) { HILOG_ERROR(HILOG_MODULE_ACE, "JsAsyncWork:DispatchAsyncWork app not launched yet!"); return false; } diff --git a/frameworks/src/core/context/js_ability.cpp b/frameworks/src/core/context/js_ability.cpp index 7e96ede..6a46fdf 100644 --- a/frameworks/src/core/context/js_ability.cpp +++ b/frameworks/src/core/context/js_ability.cpp @@ -114,6 +114,10 @@ void JSAbility::Launch(const char * const abilityPath, const char * const bundle ACE_EVENT_PRINT(MT_ACE_FWK_LAUNCHING, 0); FatalHandler::GetInstance().RegisterFatalHandler(this); jsAbilityImpl->DeliverCreate(pageInfo); +#ifndef MOCK_JS_ASYNC_WORK + // simulator uses the self-implementation for async work, this interface is not included + JsAsyncWork::SetEnvStatus(true); +#endif STOP_TRACING(); OUTPUT_TRACE(); } @@ -156,6 +160,10 @@ void JSAbility::TransferToDestroy() return; } +#ifndef MOCK_JS_ASYNC_WORK + // simulator uses the self-implementation for async work, this interface is not included + JsAsyncWork::SetEnvStatus(false); +#endif HILOG_INFO(HILOG_MODULE_ACE, "LIFECYCLE: JS Ability is exiting"); ACE_EVENT_PRINT(MT_ACE_FWK_DESTROYING, 0); JSAbilityImpl *jsAbilityImpl = CastAbilityImpl(jsAbilityImpl_); diff --git a/interfaces/innerkits/builtin/async/js_async_work.h b/interfaces/innerkits/builtin/async/js_async_work.h index fb18e22..fbea5ea 100644 --- a/interfaces/innerkits/builtin/async/js_async_work.h +++ b/interfaces/innerkits/builtin/async/js_async_work.h @@ -114,6 +114,7 @@ public: static void SetFatalHandleFunc(FatalHandleFunc isFatalErrorHitted, FatalHandleFunc isAppExiting); + static void SetEnvStatus(bool envInitialized); #if (defined(__LINUX__) || defined(__LITEOS_A__)) static void SetPostUITaskFunc(PostUITaskFunc postUITask); #endif @@ -130,6 +131,7 @@ private: #if (defined(__LINUX__) || defined(__LITEOS_A__)) static PostUITaskFunc postUITask_; #endif + static bool isEnvInitialized_; }; } // namespace ACELite } // namespace OHOS