!2765 修复terminateAbility超时上报问题

Merge pull request !2765 from 于文泽/dfx
This commit is contained in:
openharmony_ci 2022-08-22 10:58:38 +00:00 committed by Gitee
commit 6c286c6cc9
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 29 additions and 13 deletions

View File

@ -521,6 +521,7 @@ public:
using Closure = std::function<void()>;
void PostTask(std::string msg, int64_t timeOut, const Closure &task);
void RemoveTerminateAbilityTimeoutTask(const sptr<IRemoteObject>& token) const;
private:
/**

View File

@ -177,6 +177,8 @@ public:
const std::shared_ptr<ApplicationInfo> GetAppInfo();
bool RemoveTerminateAbilityTimeoutTask(const sptr<IRemoteObject>& token) const;
private:
void SendEvent(uint32_t msg, int64_t timeOut, const std::shared_ptr<AbilityRunningRecord> &abilityRecord);

View File

@ -375,19 +375,17 @@ void AppRunningManager::TerminateAbility(const sptr<IRemoteObject> &token, bool
HILOG_ERROR("appRecord is nullptr.");
return;
}
bool isLastAbilityRecord = appRecord->IsLastAbilityRecord(token);
bool isClearMission = (clearMissionFlag && appMgrServiceInner != nullptr);
if (isClearMission) {
isLastAbilityRecord = appRecord->IsLastPageAbilityRecord(token);
}
appRecord->TerminateAbility(token, false);
auto isLastAbility =
clearMissionFlag ? appRecord->IsLastPageAbilityRecord(token) : appRecord->IsLastAbilityRecord(token);
auto isKeepAliveApp = appRecord->IsKeepAliveApp();
auto isLauncherApp = appRecord->GetApplicationInfo()->isLauncherApp;
if (isLastAbilityRecord && !isKeepAliveApp && !isLauncherApp) {
if (isLastAbility && !isKeepAliveApp && !isLauncherApp) {
HILOG_DEBUG("The ability is the last in the app:%{public}s.", appRecord->GetName().c_str());
appRecord->SetTerminating();
if (isClearMission) {
if (clearMissionFlag && appMgrServiceInner != nullptr) {
appRecord->RemoveTerminateAbilityTimeoutTask(token);
HILOG_DEBUG("The ability is the last, kill application");
auto pid = appRecord->GetPriorityObject()->GetPid();
auto result = appMgrServiceInner->KillProcessByPid(pid);

View File

@ -1148,5 +1148,15 @@ bool AppRunningRecord::IsKilling() const
{
return isKilling_;
}
void AppRunningRecord::RemoveTerminateAbilityTimeoutTask(const sptr<IRemoteObject>& token) const
{
auto moduleRecord = GetModuleRunningRecordByToken(token);
if (!moduleRecord) {
HILOG_ERROR("can not find module record");
return;
}
(void)moduleRecord->RemoveTerminateAbilityTimeoutTask(token);
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -294,19 +294,24 @@ void ModuleRunningRecord::AbilityTerminated(const sptr<IRemoteObject> &token)
return;
}
if (!eventHandler_) {
HILOG_ERROR("eventHandler_ is nullptr");
return;
if (RemoveTerminateAbilityTimeoutTask(token)) {
terminateAbilitys_.erase(token);
}
}
bool ModuleRunningRecord::RemoveTerminateAbilityTimeoutTask(const sptr<IRemoteObject>& token) const
{
auto abilityRecord = GetAbilityByTerminateLists(token);
if (!abilityRecord) {
HILOG_ERROR("ModuleRunningRecord::AbilityTerminated can not find ability record");
return;
return false;
}
if (!eventHandler_) {
HILOG_ERROR("eventHandler_ is nullptr");
return false;
}
eventHandler_->RemoveEvent(AMSEventHandler::TERMINATE_ABILITY_TIMEOUT_MSG, abilityRecord->GetEventId());
terminateAbilitys_.erase(token);
return true;
}
void ModuleRunningRecord::SetAppMgrServiceInner(const std::weak_ptr<AppMgrServiceInner> &inner)