Description: improve async work dispatching protecting

IssueNo: I4H2AG
Feature or Bugfix: Feature
Binary Source:No

Signed-off-by: jiadexiang <jiadexiang@huawei.com>
This commit is contained in:
jiadexiang
2021-11-05 15:57:45 +08:00
parent 4d810a948a
commit 6ac8a5a75a
3 changed files with 17 additions and 1 deletions
@@ -24,15 +24,21 @@ FatalHandleFunc JsAsyncWork::isAppExiting_ = nullptr;
#if (defined(__LINUX__) || defined(__LITEOS_A__)) #if (defined(__LINUX__) || defined(__LITEOS_A__))
PostUITaskFunc JsAsyncWork::postUITask_ = nullptr; PostUITaskFunc JsAsyncWork::postUITask_ = nullptr;
#endif #endif
bool JsAsyncWork::isEnvInitialized_ = false;
void JsAsyncWork::SetAppQueueHandler(const QueueHandler handler) void JsAsyncWork::SetAppQueueHandler(const QueueHandler handler)
{ {
appQueuehandler_ = handler; appQueuehandler_ = handler;
} }
void JsAsyncWork::SetEnvStatus(bool envInitialized)
{
isEnvInitialized_ = envInitialized;
}
bool JsAsyncWork::DispatchToLoop(AbilityMsgId msgId, void *data) 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!"); HILOG_ERROR(HILOG_MODULE_ACE, "JsAsyncWork:DispatchAsyncWork app not launched yet!");
return false; return false;
} }
@@ -114,6 +114,10 @@ void JSAbility::Launch(const char * const abilityPath, const char * const bundle
ACE_EVENT_PRINT(MT_ACE_FWK_LAUNCHING, 0); ACE_EVENT_PRINT(MT_ACE_FWK_LAUNCHING, 0);
FatalHandler::GetInstance().RegisterFatalHandler(this); FatalHandler::GetInstance().RegisterFatalHandler(this);
jsAbilityImpl->DeliverCreate(pageInfo); 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(); STOP_TRACING();
OUTPUT_TRACE(); OUTPUT_TRACE();
} }
@@ -156,6 +160,10 @@ void JSAbility::TransferToDestroy()
return; 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"); HILOG_INFO(HILOG_MODULE_ACE, "LIFECYCLE: JS Ability is exiting");
ACE_EVENT_PRINT(MT_ACE_FWK_DESTROYING, 0); ACE_EVENT_PRINT(MT_ACE_FWK_DESTROYING, 0);
JSAbilityImpl *jsAbilityImpl = CastAbilityImpl(jsAbilityImpl_); JSAbilityImpl *jsAbilityImpl = CastAbilityImpl(jsAbilityImpl_);
@@ -114,6 +114,7 @@ public:
static void SetFatalHandleFunc(FatalHandleFunc isFatalErrorHitted, FatalHandleFunc isAppExiting); static void SetFatalHandleFunc(FatalHandleFunc isFatalErrorHitted, FatalHandleFunc isAppExiting);
static void SetEnvStatus(bool envInitialized);
#if (defined(__LINUX__) || defined(__LITEOS_A__)) #if (defined(__LINUX__) || defined(__LITEOS_A__))
static void SetPostUITaskFunc(PostUITaskFunc postUITask); static void SetPostUITaskFunc(PostUITaskFunc postUITask);
#endif #endif
@@ -130,6 +131,7 @@ private:
#if (defined(__LINUX__) || defined(__LITEOS_A__)) #if (defined(__LINUX__) || defined(__LITEOS_A__))
static PostUITaskFunc postUITask_; static PostUITaskFunc postUITask_;
#endif #endif
static bool isEnvInitialized_;
}; };
} // namespace ACELite } // namespace ACELite
} // namespace OHOS } // namespace OHOS