!3758 对于foregroundFailed和foregroundInvalidMode场景不需要等待应用生命周期执行完

Merge pull request !3758 from 于文泽/lifecycle
This commit is contained in:
openharmony_ci
2022-11-08 08:24:38 +00:00
committed by Gitee
3 changed files with 31 additions and 61 deletions
@@ -596,7 +596,29 @@ void AbilityImpl::WindowLifeCycleImpl::AfterForeground()
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
HILOG_DEBUG("%{public}s begin.", __func__);
AbilityTransitionDone(AbilityLifeCycleState::ABILITY_STATE_FOREGROUND_NEW);
auto owner = owner_.lock();
if (owner == nullptr || !owner->IsStageBasedModel()) {
HILOG_ERROR("Not stage mode ability or abilityImpl is nullptr.");
return;
}
bool needNotifyAMS = false;
{
std::lock_guard<std::mutex> lock(owner->notifyForegroundLock_);
if (owner->notifyForegroundByAbility_) {
owner->notifyForegroundByAbility_ = false;
needNotifyAMS = true;
} else {
HILOG_DEBUG("Notify foreground invalid mode by window, but client's foreground is running.");
owner->notifyForegroundByWindow_ = true;
}
}
if (needNotifyAMS) {
HILOG_DEBUG("Stage mode ability, window after foreground, notify ability manager service.");
PacMap restoreData;
AbilityManagerClient::GetInstance()->AbilityTransitionDone(token_,
AbilityLifeCycleState::ABILITY_STATE_FOREGROUND_NEW, restoreData);
}
}
void AbilityImpl::WindowLifeCycleImpl::AfterBackground()
@@ -637,75 +659,24 @@ void AbilityImpl::WindowLifeCycleImpl::AfterUnfocused()
void AbilityImpl::WindowLifeCycleImpl::ForegroundFailed()
{
HILOG_DEBUG("%{public}s begin.", __func__);
auto owner = owner_.lock();
if (owner == nullptr) {
HILOG_ERROR("abilityImpl is nullptr.");
return;
}
auto ability = owner->ability_;
if (ability == nullptr) {
HILOG_ERROR("jsAbility is nullptr.");
return;
}
bool needNotifyAMS = false;
{
std::lock_guard<std::mutex> lock(owner->notifyForegroundLock_);
if (owner->notifyForegroundByAbility_) {
owner->notifyForegroundByAbility_ = false;
needNotifyAMS = true;
} else {
HILOG_DEBUG("Notify foreground failed by window, but client's foreground is running.");
owner->notifyForegroundByWindow_ = true;
}
}
if (needNotifyAMS) {
HILOG_DEBUG("The ability is stage mode, schedule foreground failed.");
PacMap restoreData;
AbilityManagerClient::GetInstance()->AbilityTransitionDone(token_,
AbilityLifeCycleState::ABILITY_STATE_FOREGROUND_FAILED, restoreData);
}
PacMap restoreData;
AbilityManagerClient::GetInstance()->AbilityTransitionDone(token_,
AbilityLifeCycleState::ABILITY_STATE_FOREGROUND_FAILED, restoreData);
}
void AbilityImpl::WindowLifeCycleImpl::ForegroundInvalidMode()
{
HILOG_DEBUG("%{public}s begin.", __func__);
AbilityTransitionDone(AbilityLifeCycleState::ABILITY_STATE_INVALID_WINDOW_MODE);
}
void AbilityImpl::WindowLifeCycleImpl::AbilityTransitionDone(AbilityLifeCycleState state) const
{
auto owner = owner_.lock();
if (owner == nullptr || !owner->IsStageBasedModel()) {
HILOG_ERROR("Not stage mode ability or abilityImpl is nullptr.");
return;
}
auto ability = owner->ability_;
if (ability == nullptr) {
HILOG_ERROR("jsAbility is nullptr.");
return;
}
bool needNotifyAMS = false;
{
std::lock_guard<std::mutex> lock(owner->notifyForegroundLock_);
if (owner->notifyForegroundByAbility_) {
owner->notifyForegroundByAbility_ = false;
needNotifyAMS = true;
} else {
HILOG_DEBUG("Notify foreground invalid mode by window, but client's foreground is running.");
owner->notifyForegroundByWindow_ = true;
}
}
if (needNotifyAMS) {
HILOG_DEBUG("The ability is stage mode, schedule %{public}u.", static_cast<uint32_t>(state));
PacMap restoreData;
AbilityManagerClient::GetInstance()->AbilityTransitionDone(token_, state, restoreData);
}
HILOG_DEBUG("The ability is stage mode, schedule foreground invalid mode.");
PacMap restoreData;
AbilityManagerClient::GetInstance()->AbilityTransitionDone(token_,
AbilityLifeCycleState::ABILITY_STATE_INVALID_WINDOW_MODE, restoreData);
}
void AbilityImpl::Foreground(const Want &want)
@@ -112,8 +112,8 @@ bool NewAbilityImpl::AbilityTransaction(const Want &want, const AAFwk::LifeCycle
Foreground(want);
std::lock_guard<std::mutex> lock(notifyForegroundLock_);
ret = notifyForegroundByWindow_;
notifyForegroundByWindow_ = false;
if (ret) {
notifyForegroundByWindow_ = false;
notifyForegroundByAbility_ = false;
}
}
@@ -494,7 +494,6 @@ public:
void ForegroundFailed() override;
void ForegroundInvalidMode() override;
private:
void AbilityTransitionDone(AbilityLifeCycleState state) const;
sptr<IRemoteObject> token_ = nullptr;
std::weak_ptr<AbilityImpl> owner_;
};