From e596a90455d030dda2576e1857e2bc4414345d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E4=BA=AE?= Date: Tue, 16 Aug 2022 17:49:00 +0800 Subject: [PATCH] =?UTF-8?q?IssueNo:=20#I5ML6M=20Description:=20application?= =?UTF-8?q?=5F=E6=9C=AA=E6=AD=A3=E7=A1=AE=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E5=B4=A9=E6=BA=83=20Sig:=20SIG=5FApplication?= =?UTF-8?q?Framework=20Feature=20or=20Bugfix:=20Bugfix=20Binary=20Source:?= =?UTF-8?q?=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 杨亮 Change-Id: Ibcb3d53bfc7682db80ff3fb6335ffa498f2b3027 --- frameworks/native/ability/native/ability.cpp | 2 +- .../native/appkit/app/application_impl.cpp | 25 ++++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/frameworks/native/ability/native/ability.cpp b/frameworks/native/ability/native/ability.cpp index a87768359b..c5089c42f1 100644 --- a/frameworks/native/ability/native/ability.cpp +++ b/frameworks/native/ability/native/ability.cpp @@ -109,6 +109,7 @@ void Ability::Init(const std::shared_ptr &abilityInfo, const std::s std::shared_ptr &handler, const sptr &token) { HILOG_DEBUG("%{public}s begin.", __func__); + application_ = application; abilityInfo_ = abilityInfo; handler_ = handler; AbilityContext::token_ = token; @@ -156,7 +157,6 @@ void Ability::Init(const std::shared_ptr &abilityInfo, const std::s HILOG_ERROR("%{public}s abilityLifecycleExecutor_ make failed.", __func__); } - application_ = application; if (abilityContext_ != nullptr) { abilityContext_->RegisterAbilityCallback(weak_from_this()); } diff --git a/frameworks/native/appkit/app/application_impl.cpp b/frameworks/native/appkit/app/application_impl.cpp index 21ab979a37..abb67856f8 100644 --- a/frameworks/native/appkit/app/application_impl.cpp +++ b/frameworks/native/appkit/app/application_impl.cpp @@ -48,7 +48,7 @@ void ApplicationImpl::SetApplication(const std::shared_ptr &app bool ApplicationImpl::PerformAppReady() { HILOG_DEBUG("ApplicationImpl::PerformAppReady called"); - if (curState_ == APP_STATE_CREATE) { + if (curState_ == APP_STATE_CREATE && application_ != nullptr) { application_->OnStart(); curState_ = APP_STATE_READY; return true; @@ -66,7 +66,7 @@ bool ApplicationImpl::PerformAppReady() bool ApplicationImpl::PerformForeground() { HILOG_DEBUG("ApplicationImpl::performForeground called"); - if ((curState_ == APP_STATE_READY) || (curState_ == APP_STATE_BACKGROUND)) { + if (((curState_ == APP_STATE_READY) || (curState_ == APP_STATE_BACKGROUND)) && application_ != nullptr) { application_->OnForeground(); curState_ = APP_STATE_FOREGROUND; return true; @@ -84,7 +84,7 @@ bool ApplicationImpl::PerformForeground() bool ApplicationImpl::PerformBackground() { HILOG_DEBUG("ApplicationImpl::performBackground called"); - if (curState_ == APP_STATE_FOREGROUND) { + if (curState_ == APP_STATE_FOREGROUND && application_ != nullptr) { application_->OnBackground(); curState_ = APP_STATE_BACKGROUND; return true; @@ -102,7 +102,7 @@ bool ApplicationImpl::PerformBackground() bool ApplicationImpl::PerformTerminate() { HILOG_DEBUG("ApplicationImpl::PerformTerminate called"); - if (curState_ == APP_STATE_BACKGROUND) { + if (curState_ == APP_STATE_BACKGROUND && application_ != nullptr) { application_->OnTerminate(); curState_ = APP_STATE_TERMINATED; RemoveUriPermission(); @@ -121,12 +121,21 @@ bool ApplicationImpl::PerformTerminate() void ApplicationImpl::PerformTerminateStrong() { HILOG_DEBUG("ApplicationImpl::PerformTerminateStrong called"); + if (application_ == nullptr) { + HILOG_ERROR("ApplicationImpl::PerformTerminateStrong: invalid application_."); + return; + } application_->OnTerminate(); RemoveUriPermission(); } void ApplicationImpl::RemoveUriPermission() { + if (application_ == nullptr) { + HILOG_ERROR("ApplicationImpl::RemoveUriPermission: invalid application_."); + return; + } + auto appContext = application_->GetAppContext(); if (!appContext) { HILOG_ERROR("ApplicationImpl::RemoveUriPermission: Get appliction context failed."); @@ -150,7 +159,9 @@ void ApplicationImpl::RemoveUriPermission() void ApplicationImpl::PerformMemoryLevel(int level) { HILOG_DEBUG("ApplicationImpl::PerformMemoryLevel called"); - application_->OnMemoryLevel(level); + if (application_ != nullptr) { + application_->OnMemoryLevel(level); + } } /** @@ -162,7 +173,9 @@ void ApplicationImpl::PerformMemoryLevel(int level) void ApplicationImpl::PerformConfigurationUpdated(const Configuration &config) { HILOG_DEBUG("ApplicationImpl::PerformConfigurationUpdated called"); - application_->OnConfigurationUpdated(config); + if (application_ != nullptr) { + application_->OnConfigurationUpdated(config); + } } /**