mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-25 12:23:20 -04:00
IssueNo:#I4WXIG:launcher cannot restart when it was killed
Description:launcher cannot restart when it was killed Sig:SIG_ApplicationFramework Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: zhoujun62 <zhoujun62@huawei.com> Change-Id: I0d43107c20a73e515dab5e307451b6a639d7da7c
This commit is contained in:
@@ -411,6 +411,8 @@ private:
|
||||
*/
|
||||
void PostTimeOutTask(const std::shared_ptr<AbilityRecord> &abilityRecord, uint32_t messageId);
|
||||
|
||||
bool IsAbilityNeedRestart(const std::shared_ptr<AbilityRecord> &abilityRecord);
|
||||
|
||||
private:
|
||||
const std::string TASK_ON_CALLBACK_DIED = "OnCallbackDiedTask";
|
||||
const std::string TASK_ON_ABILITY_DIED = "OnAbilityDiedTask";
|
||||
|
||||
@@ -58,6 +58,7 @@ private:
|
||||
private:
|
||||
DataAbilityRecordPtr LoadLocked(const std::string &name, const AbilityRequest &req);
|
||||
void DumpLocked(const char *func, int line);
|
||||
void RestartDataAbility(const std::shared_ptr<AbilityRecord> &abilityRecord);
|
||||
|
||||
private:
|
||||
std::mutex mutex_;
|
||||
|
||||
@@ -910,23 +910,15 @@ void AbilityConnectManager::OnAbilityDied(const std::shared_ptr<AbilityRecord> &
|
||||
}
|
||||
}
|
||||
|
||||
void AbilityConnectManager::HandleAbilityDiedTask(const std::shared_ptr<AbilityRecord> &abilityRecord)
|
||||
bool AbilityConnectManager::IsAbilityNeedRestart(const std::shared_ptr<AbilityRecord> &abilityRecord)
|
||||
{
|
||||
HILOG_INFO("Handle ability died task.");
|
||||
std::lock_guard<std::recursive_mutex> guard(Lock_);
|
||||
CHECK_POINTER(abilityRecord);
|
||||
if (!GetServiceRecordByToken(abilityRecord->GetToken())) {
|
||||
HILOG_ERROR("Died ability record is not exist in service map.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto bms = AbilityUtil::GetBundleManager();
|
||||
CHECK_POINTER(bms);
|
||||
CHECK_POINTER_AND_RETURN(bms, false);
|
||||
std::vector<AppExecFwk::BundleInfo> bundleInfos;
|
||||
bool getBundleInfos = bms->GetBundleInfos(OHOS::AppExecFwk::GET_BUNDLE_DEFAULT, bundleInfos, USER_ID_NO_HEAD);
|
||||
if (!getBundleInfos) {
|
||||
HILOG_ERROR("Handle ability died task, get bundle infos failed");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto GetKeepAliveAbilities = [&bundleInfos](std::vector<std::string> &keepAliveAbilities) -> void {
|
||||
@@ -955,13 +947,27 @@ void AbilityConnectManager::HandleAbilityDiedTask(const std::shared_ptr<AbilityR
|
||||
abilityRecord->GetAbilityInfo().name == AbilityConfig::PHONE_SERVICE_ABILITY_NAME ||
|
||||
abilityRecord->GetAbilityInfo().name == AbilityConfig::CONTACTS_ABILITY_NAME ||
|
||||
abilityRecord->GetAbilityInfo().name == AbilityConfig::MMS_ABILITY_NAME ||
|
||||
abilityRecord->GetAbilityInfo().name == AbilityConfig::SYSTEM_UI_ABILITY_NAME);
|
||||
abilityRecord->GetAbilityInfo().name == AbilityConfig::SYSTEM_UI_ABILITY_NAME ||
|
||||
abilityRecord->GetAbilityInfo().name == AbilityConfig::LAUNCHER_ABILITY_NAME);
|
||||
};
|
||||
|
||||
std::vector<std::string> keepAliveAbilities;
|
||||
GetKeepAliveAbilities(keepAliveAbilities);
|
||||
auto findIter = find_if(keepAliveAbilities.begin(), keepAliveAbilities.end(), findKeepAliveAbility);
|
||||
if (findIter != keepAliveAbilities.end()) {
|
||||
return (findIter != keepAliveAbilities.end());
|
||||
}
|
||||
|
||||
void AbilityConnectManager::HandleAbilityDiedTask(const std::shared_ptr<AbilityRecord> &abilityRecord)
|
||||
{
|
||||
HILOG_INFO("Handle ability died task.");
|
||||
std::lock_guard<std::recursive_mutex> guard(Lock_);
|
||||
CHECK_POINTER(abilityRecord);
|
||||
if (!GetServiceRecordByToken(abilityRecord->GetToken())) {
|
||||
HILOG_ERROR("Died ability record is not exist in service map.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsAbilityNeedRestart(abilityRecord)) {
|
||||
HILOG_INFO("restart ability: %{public}s", abilityRecord->GetAbilityInfo().name.c_str());
|
||||
AbilityRequest requestInfo;
|
||||
requestInfo.want = abilityRecord->GetWant();
|
||||
|
||||
@@ -315,41 +315,7 @@ void DataAbilityManager::OnAbilityDied(const std::shared_ptr<AbilityRecord> &abi
|
||||
}
|
||||
}
|
||||
|
||||
auto bms = AbilityUtil::GetBundleManager();
|
||||
CHECK_POINTER(bms);
|
||||
std::vector<AppExecFwk::BundleInfo> bundleInfos;
|
||||
bool getBundleInfos = bms->GetBundleInfos(OHOS::AppExecFwk::GET_BUNDLE_DEFAULT, bundleInfos, USER_ID_NO_HEAD);
|
||||
if (!getBundleInfos) {
|
||||
HILOG_ERROR("Handle ability died task, get bundle infos failed");
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < bundleInfos.size(); i++) {
|
||||
if (!bundleInfos[i].isKeepAlive) {
|
||||
continue;
|
||||
}
|
||||
for (auto hapModuleInfo : bundleInfos[i].hapModuleInfos) {
|
||||
if (hapModuleInfo.isModuleJson) {
|
||||
// new application model, it cannot be a data ability
|
||||
continue;
|
||||
}
|
||||
// old application model, it maybe a data ability
|
||||
std::string mainElement = hapModuleInfo.mainAbility;
|
||||
if (abilityRecord->GetAbilityInfo().name != mainElement) {
|
||||
continue;
|
||||
}
|
||||
std::string uriStr;
|
||||
bool getDataAbilityUri = OHOS::DelayedSingleton<AbilityManagerService>::GetInstance()->GetDataAbilityUri(
|
||||
hapModuleInfo.abilityInfos, mainElement, uriStr);
|
||||
if (getDataAbilityUri) {
|
||||
HILOG_INFO("restart data ability: %{public}s, uri: %{public}s",
|
||||
abilityRecord->GetAbilityInfo().name.c_str(), uriStr.c_str());
|
||||
Uri uri(uriStr);
|
||||
OHOS::DelayedSingleton<AbilityManagerService>::GetInstance()->AcquireDataAbility(uri, true, nullptr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
RestartDataAbility(abilityRecord);
|
||||
}
|
||||
|
||||
void DataAbilityManager::OnAppStateChanged(const AppInfo &info)
|
||||
@@ -618,5 +584,45 @@ void DataAbilityManager::GetAbilityRunningInfos(std::vector<AbilityRunningInfo>
|
||||
std::for_each(dataAbilityRecordsLoading_.begin(), dataAbilityRecordsLoading_.end(), queryInfo);
|
||||
std::for_each(dataAbilityRecordsLoaded_.begin(), dataAbilityRecordsLoaded_.end(), queryInfo);
|
||||
}
|
||||
|
||||
void DataAbilityManager::RestartDataAbility(const std::shared_ptr<AbilityRecord> &abilityRecord)
|
||||
{
|
||||
// restart data ability if necessary
|
||||
auto bms = AbilityUtil::GetBundleManager();
|
||||
CHECK_POINTER(bms);
|
||||
std::vector<AppExecFwk::BundleInfo> bundleInfos;
|
||||
bool getBundleInfos = bms->GetBundleInfos(OHOS::AppExecFwk::GET_BUNDLE_DEFAULT, bundleInfos, USER_ID_NO_HEAD);
|
||||
if (!getBundleInfos) {
|
||||
HILOG_ERROR("Handle ability died task, get bundle infos failed");
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < bundleInfos.size(); i++) {
|
||||
if (!bundleInfos[i].isKeepAlive) {
|
||||
continue;
|
||||
}
|
||||
for (auto hapModuleInfo : bundleInfos[i].hapModuleInfos) {
|
||||
if (hapModuleInfo.isModuleJson) {
|
||||
// new application model, it cannot be a data ability
|
||||
continue;
|
||||
}
|
||||
// old application model, it maybe a data ability
|
||||
std::string mainElement = hapModuleInfo.mainAbility;
|
||||
if (abilityRecord->GetAbilityInfo().name != mainElement) {
|
||||
continue;
|
||||
}
|
||||
std::string uriStr;
|
||||
bool getDataAbilityUri = OHOS::DelayedSingleton<AbilityManagerService>::GetInstance()->GetDataAbilityUri(
|
||||
hapModuleInfo.abilityInfos, mainElement, uriStr);
|
||||
if (getDataAbilityUri) {
|
||||
HILOG_INFO("restart data ability: %{public}s, uri: %{public}s",
|
||||
abilityRecord->GetAbilityInfo().name.c_str(), uriStr.c_str());
|
||||
Uri uri(uriStr);
|
||||
OHOS::DelayedSingleton<AbilityManagerService>::GetInstance()->AcquireDataAbility(uri, true, nullptr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
||||
Reference in New Issue
Block a user