diff --git a/frameworks/kits/appkit/native/app/include/main_thread.h b/frameworks/kits/appkit/native/app/include/main_thread.h index 987620ff53d1d01ddc397f2a00125c85b8b9e4af..c5dda20920e01550d3163a7bc49fadddf2b689e6 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 70bd13639a4ec252f2411b65100fc29cc140d72a..7aa1790afbdb0135da97c6b4c3eec20f248912be 100644 --- a/frameworks/kits/appkit/native/app/src/main_thread.cpp +++ b/frameworks/kits/appkit/native/app/src/main_thread.cpp @@ -47,6 +47,10 @@ namespace OHOS { namespace AppExecFwk { +namespace { +constexpr int32_t DELIVERY_TIME = 200; +constexpr int32_t DISTRIBUTE_TIME = 100; +} #define ACEABILITY_LIBRARY_LOADER #ifdef ABILITY_LIBRARY_LOADER #endif @@ -1232,6 +1236,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__); @@ -1257,6 +1283,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.");