IssueNo: #I5ML6M

Description: application_未正确初始化导致崩溃
Sig: SIG_ApplicationFramework
Feature or Bugfix: Bugfix
Binary Source: No

Signed-off-by: 杨亮 <yangliang36@huawei.com>
Change-Id: Ibcb3d53bfc7682db80ff3fb6335ffa498f2b3027
This commit is contained in:
杨亮
2022-08-16 17:49:00 +08:00
parent 30748ced85
commit e596a90455
2 changed files with 20 additions and 7 deletions
+1 -1
View File
@@ -109,6 +109,7 @@ void Ability::Init(const std::shared_ptr<AbilityInfo> &abilityInfo, const std::s
std::shared_ptr<AbilityHandler> &handler, const sptr<IRemoteObject> &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> &abilityInfo, const std::s
HILOG_ERROR("%{public}s abilityLifecycleExecutor_ make failed.", __func__);
}
application_ = application;
if (abilityContext_ != nullptr) {
abilityContext_->RegisterAbilityCallback(weak_from_this());
}
@@ -48,7 +48,7 @@ void ApplicationImpl::SetApplication(const std::shared_ptr<OHOSApplication> &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);
}
}
/**