diff --git a/frameworks/kits/appkit/native/app/include/main_thread.h b/frameworks/kits/appkit/native/app/include/main_thread.h index 123c0c7f9b62f1b975e9d166e3eedc1c51e40383..bf484f587ef4d2c8145665ade78fee29dc877b85 100644 --- a/frameworks/kits/appkit/native/app/include/main_thread.h +++ b/frameworks/kits/appkit/native/app/include/main_thread.h @@ -376,6 +376,13 @@ private: */ void Init(const std::shared_ptr &runner, const std::shared_ptr &watchDogRunner); + /** + * + * @brief Task in event handler timeout detected. + * + */ + void TaskTimeoutDetected(); + /** * * @brief Check whether the OHOSApplication is ready. diff --git a/frameworks/kits/appkit/native/app/src/main_thread.cpp b/frameworks/kits/appkit/native/app/src/main_thread.cpp index 92ea68d88afa30140f3486b57176915273515902..f911cef54bd77ccd5c54c6a574ab4978bfeba0e2 100644 --- a/frameworks/kits/appkit/native/app/src/main_thread.cpp +++ b/frameworks/kits/appkit/native/app/src/main_thread.cpp @@ -49,6 +49,8 @@ namespace OHOS { namespace AppExecFwk { namespace { constexpr int TARGET_VERSION_THRESHOLDS = 8; +constexpr int32_t DELIVERY_TIME = 200; +constexpr int32_t DISTRIBUTE_TIME = 100; } #define ACEABILITY_LIBRARY_LOADER @@ -1227,6 +1229,28 @@ void MainThread::HandleConfigurationUpdated(const Configuration &config) APP_LOGI("MainThread::HandleConfigurationUpdated called end."); } +void MainThread::TaskTimeoutDetected() +{ + BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__); + APP_LOGI("MainThread::TaskTimeoutDetected called start."); + + auto deliveryTimeoutCallback = []() { + APP_LOGI("MainThread::TaskTimeoutDetected delivery timeout"); + }; + auto distributeTimeoutCallback = []() { + APP_LOGI("MainThread::TaskTimeoutDetected delivery timeout"); + }; + + if (mainHandler_ != nullptr) { + mainHandler_->SetDeliveryTimeout(DELIVERY_TIME); + mainHandler_->SetDeliveryTimeoutCallback(deliveryTimeoutCallback); + + mainHandler_->SetDistributeTimeout(DISTRIBUTE_TIME); + mainHandler_->SetDistributeTimeoutCallback(distributeTimeoutCallback); + } + APP_LOGI("MainThread::TaskTimeoutDetected called end."); +} + void MainThread::Init(const std::shared_ptr &runner, const std::shared_ptr &watchDogRunner) { BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__); @@ -1252,6 +1276,7 @@ void MainThread::Init(const std::shared_ptr &runner, const std::sha if (!watchDogHandler_->PostTask(taskWatchDog)) { APP_LOGE("MainThread::Init WatchDog postTask task failed"); } + TaskTimeoutDetected(); /* watchDogHandler_->Init(mainHandler_, watchDogHandler_); APP_LOGI("MainThread:Init before CreateRunner.");