Description:optimize code

Sig:SIG_ApplicationFramework
Feature or Bugfix:Bugfix
Binary Source:No

Signed-off-by: yuwenze <yuaqiang1@huawei.com>
Change-Id: Ic9104919682bab7c5bc869fd8ec47e3c1956776a
This commit is contained in:
yuwenze 2022-08-29 11:23:13 +08:00
parent 425a2a22ce
commit 2e19db2845
8 changed files with 23 additions and 60 deletions

View File

@ -228,10 +228,10 @@ void Ability::OnStart(const Want &want)
InitWindow(winType, displayId, option);
if (abilityWindow_ != nullptr) {
HILOG_DEBUG("%{public}s begin abilityWindow_->OnPostAbilityStart.", __func__);
abilityWindow_->OnPostAbilityStart();
HILOG_DEBUG("%{public}s get window from abilityWindow.", __func__);
auto window = abilityWindow_->GetWindow();
if (window) {
HILOG_DEBUG("%{public}s get window id from window.", __func__);
auto windowId = window->GetWindowId();
if (winType == Rosen::WindowType::WINDOW_TYPE_APP_MAIN_WINDOW) {
HILOG_DEBUG("Call RegisterDisplayMoveListener, windowId: %{public}d", windowId);
@ -240,7 +240,6 @@ void Ability::OnStart(const Want &want)
window->RegisterDisplayMoveListener(abilityDisplayMoveListener_);
}
}
HILOG_DEBUG("%{public}s end abilityWindow_->OnPostAbilityStart.", __func__);
}
// Update resMgr, Configuration

View File

@ -590,12 +590,6 @@ void AbilityImpl::WindowLifeCycleImpl::AfterUnfocused()
void AbilityImpl::WindowLifeCycleImpl::ForegroundFailed()
{
HILOG_DEBUG("%{public}s begin.", __func__);
auto owner = owner_.lock();
if (owner && !owner->IsStageBasedModel()) {
return;
}
HILOG_DEBUG("The ability is stage mode, schedule foreground failed.");
PacMap restoreData;
AbilityManagerClient::GetInstance()->AbilityTransitionDone(token_,
AbilityLifeCycleState::ABILITY_STATE_FOREGROUND_FAILED, restoreData);

View File

@ -72,24 +72,6 @@ bool AbilityWindow::InitWindow(Rosen::WindowType winType,
return true;
}
/**
* @brief Called when this ability is started.
*
*/
void AbilityWindow::OnPostAbilityStart()
{
if (!isWindowAttached) {
HILOG_ERROR("AbilityWindow::OnPostAbilityStart window not attached.");
return;
}
if (windowScene_) {
HILOG_DEBUG("%{public}s begin windowScene_->GoBackground.", __func__);
windowScene_->GoBackground();
HILOG_DEBUG("%{public}s end windowScene_->GoBackground.", __func__);
}
}
/**
* @brief Called when this ability is activated.
*

View File

@ -46,12 +46,6 @@ public:
sptr<Rosen::IWindowLifeCycle> &listener, int32_t displayId, sptr<Rosen::WindowOption> option,
bool isPrivacy);
/**
* @brief Called when this ability is started.
*
*/
void OnPostAbilityStart();
/**
* @brief Called when this ability is activated.
*

View File

@ -289,7 +289,7 @@ public:
* foreground the ability.
*
*/
void ForegroundAbility(const Closure &task, uint32_t sceneFlag = 0);
void ForegroundAbility(uint32_t sceneFlag = 0);
/**
* process request of foregrounding the ability.

View File

@ -231,17 +231,13 @@ bool AbilityRecord::CanRestartRootLauncher()
return true;
}
void AbilityRecord::ForegroundAbility(const Closure &task, uint32_t sceneFlag)
void AbilityRecord::ForegroundAbility(uint32_t sceneFlag)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
HILOG_INFO("Start to foreground ability, name is %{public}s.", abilityInfo_.name.c_str());
CHECK_POINTER(lifecycleDeal_);
SendEvent(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, AbilityManagerService::FOREGROUND_TIMEOUT);
auto handler = DelayedSingleton<AbilityManagerService>::GetInstance()->GetEventHandler();
if (handler && task) {
handler->PostTask(task, "CancelStartingWindow", AbilityManagerService::FOREGROUND_TIMEOUT);
}
// schedule active after updating AbilityState and sending timeout message to avoid ability async callback
// earlier than above actions.
@ -268,7 +264,10 @@ void AbilityRecord::ProcessForegroundAbility(uint32_t sceneFlag)
HILOG_DEBUG("ability record: %{public}s", element.c_str());
if (isReady_) {
if (IsAbilityState(AbilityState::BACKGROUND)) {
if (IsAbilityState(AbilityState::FOREGROUND)) {
HILOG_DEBUG("Activate %{public}s", element.c_str());
ForegroundAbility(sceneFlag);
} else {
// background to active state
HILOG_DEBUG("MoveToForeground, %{public}s", element.c_str());
lifeCycleStateInfo_.sceneFlagBak = sceneFlag;
@ -279,9 +278,6 @@ void AbilityRecord::ProcessForegroundAbility(uint32_t sceneFlag)
uid, bundleName, "THAW_BY_FOREGROUND_ABILITY");
#endif // EFFICIENCY_MANAGER_ENABLE
DelayedSingleton<AppScheduler>::GetInstance()->MoveToForeground(token_);
} else {
HILOG_DEBUG("Activate %{public}s", element.c_str());
ForegroundAbility(nullptr, sceneFlag);
}
} else {
HILOG_INFO("To load ability.");
@ -319,7 +315,10 @@ void AbilityRecord::ProcessForegroundAbility(bool isRecent, const AbilityRequest
HILOG_INFO("SUPPORT_GRAPHICS: ability record: %{public}s", element.c_str());
if (isReady_) {
if (IsAbilityState(AbilityState::BACKGROUND)) {
if (IsAbilityState(AbilityState::FOREGROUND)) {
HILOG_DEBUG("Activate %{public}s", element.c_str());
ForegroundAbility(sceneFlag);
} else {
// background to active state
HILOG_DEBUG("MoveToForeground, %{public}s", element.c_str());
lifeCycleStateInfo_.sceneFlagBak = sceneFlag;
@ -329,9 +328,6 @@ void AbilityRecord::ProcessForegroundAbility(bool isRecent, const AbilityRequest
CancelStartingWindowHotTask();
DelayedSingleton<AppScheduler>::GetInstance()->MoveToForeground(token_);
} else {
HILOG_DEBUG("Activate %{public}s", element.c_str());
ForegroundAbility(nullptr, sceneFlag);
}
} else {
HILOG_INFO("SUPPORT_GRAPHICS: to load ability.");

View File

@ -36,7 +36,6 @@ constexpr char EVENT_KEY_MESSAGE[] = "MSG";
constexpr char EVENT_KEY_PACKAGE_NAME[] = "PACKAGE_NAME";
constexpr char EVENT_KEY_PROCESS_NAME[] = "PROCESS_NAME";
constexpr int32_t MAX_INSTANCE_COUNT = 128;
constexpr uint32_t NEXTABILITY_TIMEOUT = 1000; // ms
constexpr uint64_t NANO_SECOND_PER_SEC = 1000000000; // ns
const std::string DMS_SRC_NETWORK_ID = "dmsSrcNetworkId";
const std::string DMS_MISSION_ID = "dmsMissionId";
@ -234,8 +233,8 @@ void MissionListManager::StartWaitingAbility()
auto topAbility = GetCurrentTopAbilityLocked();
CHECK_POINTER(topAbility);
if (!topAbility->IsAbilityState(FOREGROUND)) {
HILOG_INFO("Top ability is not foreground new, must return for start waiting again.");
if (topAbility->IsAbilityState(FOREGROUNDING)) {
HILOG_INFO("Top ability is foregrounding, must return for start waiting again.");
return;
}
@ -267,6 +266,11 @@ int MissionListManager::StartAbilityLocked(const std::shared_ptr<AbilityRecord>
return ERR_INVALID_VALUE;
}
if (targetAbilityRecord->IsTerminating()) {
HILOG_ERROR("%{public}s is terminating.", targetAbilityRecord->GetAbilityInfo().name.c_str());
return ERR_INVALID_VALUE;
}
if (abilityRequest.IsContinuation()) {
targetAbilityRecord->SetLaunchReason(LaunchReason::LAUNCHREASON_CONTINUATION);
} else {
@ -712,13 +716,7 @@ void MissionListManager::OnAbilityRequestDone(const sptr<IRemoteObject> &token,
CHECK_POINTER(abilityRecord);
std::string element = abilityRecord->GetWant().GetElement().GetURI();
HILOG_DEBUG("Ability is %{public}s, start to foreground.", element.c_str());
#ifdef SUPPORT_GRAPHICS
auto delayTask = GetCancelStartingWindow(abilityRecord);
abilityRecord->ForegroundAbility(delayTask, abilityRecord->lifeCycleStateInfo_.sceneFlagBak);
#else
abilityRecord->ForegroundAbility(nullptr, abilityRecord->lifeCycleStateInfo_.sceneFlagBak);
#endif
abilityRecord->ForegroundAbility(abilityRecord->lifeCycleStateInfo_.sceneFlagBak);
}
}
@ -963,7 +961,7 @@ void MissionListManager::CompleteForegroundSuccess(const std::shared_ptr<Ability
CHECK_POINTER_LOG(handler, "Fail to get AbilityEventHandler.");
/* PostTask to trigger start Ability from waiting queue */
handler->PostTask(startWaitingAbilityTask, "startWaitingAbility", NEXTABILITY_TIMEOUT);
handler->PostTask(startWaitingAbilityTask, "startWaitingAbility");
TerminatePreviousAbility(abilityRecord);
// new version. started by caller, scheduler call request

View File

@ -398,10 +398,10 @@ void AppRunningManager::TerminateAbility(const sptr<IRemoteObject> &token, bool
HILOG_ERROR("appRecord is nullptr.");
return;
}
appRecord->TerminateAbility(token, false);
auto isLastAbility =
clearMissionFlag ? appRecord->IsLastPageAbilityRecord(token) : appRecord->IsLastAbilityRecord(token);
appRecord->TerminateAbility(token, false);
auto isKeepAliveApp = appRecord->IsKeepAliveApp();
auto isLauncherApp = appRecord->GetApplicationInfo()->isLauncherApp;
if (isLastAbility && !isKeepAliveApp && !isLauncherApp) {