cpp_crash场景使能APPrecover

Change-Id: I8c9bea6bc4077ff44359e525c676a9b03c2e9fd9
Signed-off-by: tsuk1ii <linsicheng1@huawei.com>
This commit is contained in:
l00814634
2026-03-13 10:31:41 +08:00
parent d3729379f9
commit d8aebcd4d3
9 changed files with 31 additions and 19 deletions
@@ -22,7 +22,7 @@ export default namespace appRecovery {
ALWAYS_RESTART = 0,
RESTART_WHEN_JS_CRASH = 0x0001,
RESTART_WHEN_APP_FREEZE = 0x0002,
RESTART_WHEN_CPP_CRASH = 0x0008,
RESTART_WHEN_CPP_CRASH = 0x0004,
NO_RESTART = 0xFFFF
}
@@ -398,6 +398,7 @@ void AppRecovery::EnableAppRecovery(uint16_t restartFlag, uint16_t saveFlag, uin
{
isEnable_ = true;
restartFlag_ = restartFlag;
crashFlag_ = restartFlag;
saveOccasion_ = saveFlag;
saveMode_ = saveMode;
useAppSettedValue_.store(true);
@@ -44,7 +44,7 @@ enum RestartFlag {
ALWAYS_RESTART = 0,
RESTART_WHEN_JS_CRASH = 0x0001,
RESTART_WHEN_APP_FREEZE = 0x0002,
RESTART_WHEN_CPP_CRASH = 0x0008,
RESTART_WHEN_CPP_CRASH = 0x0004,
NO_RESTART = 0xFFFF,
};
@@ -44,8 +44,8 @@ enum RestartFlag {
ALWAYS_RESTART = 0x0000,
RESTART_WHEN_JS_CRASH = 0x0001,
RESTART_WHEN_APP_FREEZE = 0x0002,
RESTART_WHEN_CJ_CRASH = 0x0004,
RESTART_WHEN_CPP_CRASH = 0x0008,
RESTART_WHEN_CPP_CRASH = 0x0004,
RESTART_WHEN_CJ_CRASH = 0x0008,
NO_RESTART = 0xFFFF,
};
@@ -3370,7 +3370,7 @@ private:
void RecordRecoveryExitReason(bool isAppRecovery, int32_t callerPid, int32_t callerUid);
void SetAppDeathRecipient(const sptr<IRemoteObject>& abilityToken);
void HandleAppDiedForRecovery(const sptr<IRemoteObject>& remote, const AbilityInfo& abilityInfo,
int32_t pid, int32_t uid);
int32_t pid, int32_t uid, int32_t userId);
void startRecoveryMgr();
int getAppRecoveryFlag(const sptr<IRemoteObject> &token);
void HandleRecoveryRecipient(const std::shared_ptr<AbilityRecord>& abilityRecord,
@@ -40,7 +40,7 @@ public:
int32_t GetAppExitReason(const std::string &bundleName, uint32_t accessTokenId, const std::string &abilityName,
bool &isSetReason, AAFwk::ExitReason &exitReason, AppExecFwk::RunningProcessInfo &processInfo,
int64_t &time_stamp, bool &withKillMsg);
int64_t &time_stamp, bool &withKillMsg, bool cleanFlag = true);
int32_t DeleteAppExitReason(const std::string &bundleName, int32_t uid, int32_t appIndex);
@@ -74,6 +74,8 @@ public:
void UpdateAppExitReason(uint32_t accessTokenId, const std::vector<std::string> &abilityList,
const AAFwk::ExitReason &exitReason, const AppExecFwk::RunningProcessInfo &processInfo, bool withKillMsg);
void HandleAbilityMatchAndCleanup(const std::string& abilityName, std::vector<std::string>& abilityList,
bool& isSetReason, bool cleanFlag);
private:
DistributedKv::Status GetKvStore();
@@ -16861,17 +16861,17 @@ void AbilityManagerService::SetAppDeathRecipient(const sptr<IRemoteObject> &toke
const auto &abilityInfo = abilityRecord->GetAbilityInfo();
int32_t pid = abilityRecord->GetPid();
int32_t uid = abilityRecord->GetUid();
auto callback = [this,abilityInfo,pid,uid](const sptr<IRemoteObject>& remote) {
this->HandleAppDiedForRecovery(remote,abilityInfo,pid,uid);
int32_t userId = abilityRecord->GetOwnerMissionUserId();
auto callback = [this,abilityInfo,pid,uid,userId](const sptr<IRemoteObject>& remote) {
this->HandleAppDiedForRecovery(remote,abilityInfo,pid,uid,userId);
};
AppRecoveryMgr::AppRecoveryMgr::GetInstance().SetOnRemoteDieCallback(token, callback);
}
void AbilityManagerService::HandleAppDiedForRecovery(const sptr<IRemoteObject>& remote,
const AbilityInfo& abilityInfo,
int32_t pid,
int32_t uid)
const AbilityInfo& abilityInfo, int32_t pid,
int32_t uid, int32_t userId)
{
if (remote == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "remote is null, cannot recover app");
@@ -16893,7 +16893,7 @@ void AbilityManagerService::HandleAppDiedForRecovery(const sptr<IRemoteObject>&
auto accessTokenId = abilityInfo.applicationInfo.accessTokenId;
AAFwk::ExitReason exitReason = {AAFwk::REASON_JS_ERROR, "Js Error."};
auto result = DelayedSingleton<AppExitReasonDataManager>::GetInstance()->GetAppExitReason(abilityInfo.bundleName, accessTokenId,
abilityInfo.name, isSetReason, exitReason, processInfo, stamp, withKillMsg);
abilityInfo.name, isSetReason, exitReason, processInfo, stamp, withKillMsg, false);
if(exitReason.reason!= AAFwk::REASON_CPP_CRASH) {
TAG_LOGI(AAFwkTag::APPMGR, "app exit reason is not REASON_CPP_CRASH");
return;
@@ -16914,8 +16914,8 @@ void AbilityManagerService::HandleAppDiedForRecovery(const sptr<IRemoteObject>&
AAFwk::Want *newWant=new AAFwk::Want();
newWant->SetElementName(abilityInfo.bundleName, abilityInfo.name);
newWant->SetParam(AAFwk::Want::PARAM_ABILITY_RECOVERY_RESTART, true);
StartAbility(*newWant,MAIN_USER_ID);
TAG_LOGW(AAFwkTag::ABILITYMGR,"now is %{public}lld,timestamp is %{public}lld",static_cast<long long>(now),static_cast<long long>(stamp));
StartAbility(*newWant,userId);
TAG_LOGI(AAFwkTag::ABILITYMGR,"CPP_CRASH recovery. bundleName is %{public}s",abilityInfo.bundleName.c_str());
}
if (remote != nullptr) {
AppRecoveryMgr::AppRecoveryMgr::GetInstance().RemoveOnRemoteDieCallback(remote);
@@ -190,7 +190,8 @@ int32_t AppExitReasonDataManager::DeleteAppExitReason(const std::string &bundleN
int32_t AppExitReasonDataManager::GetAppExitReason(const std::string &bundleName, uint32_t accessTokenId,
const std::string &abilityName, bool &isSetReason, AAFwk::ExitReason &exitReason,
AppExecFwk::RunningProcessInfo &processInfo, int64_t &time_stamp, bool &withKillMsg)
AppExecFwk::RunningProcessInfo &processInfo, int64_t &time_stamp, bool &withKillMsg,
bool cleanFlag)
{
auto accessTokenIdStr = std::to_string(accessTokenId);
if (bundleName.empty() || accessTokenId == Security::AccessToken::INVALID_TOKENID) {
@@ -219,8 +220,7 @@ int32_t AppExitReasonDataManager::GetAppExitReason(const std::string &bundleName
withKillMsg);
auto pos = std::find(abilityList.begin(), abilityList.end(), abilityName);
if (pos != abilityList.end()) {
isSetReason = true;
abilityList.erase(std::remove(abilityList.begin(), abilityList.end(), abilityName), abilityList.end());
HandleAbilityMatchAndCleanup(abilityName, abilityList, isSetReason, cleanFlag);
UpdateAppExitReason(accessTokenId, abilityList, exitReason, processInfo, withKillMsg);
}
TAG_LOGD(AAFwkTag::ABILITYMGR, "current bundle name: %{public}s, tokenId:%{private}u, reason: %{public}d,"
@@ -237,6 +237,17 @@ int32_t AppExitReasonDataManager::GetAppExitReason(const std::string &bundleName
return ERR_OK;
}
void AppExitReasonDataManager::HandleAbilityMatchAndCleanup(
const std::string& abilityName, std::vector<std::string>& abilityList,
bool& isSetReason, bool cleanFlag)
{
isSetReason = true;
if (cleanFlag) {
auto newEnd = std::remove(abilityList.begin(), abilityList.end(), abilityName);
abilityList.erase(newEnd, abilityList.end());
}
}
void AppExitReasonDataManager::UpdateAppExitReason(uint32_t accessTokenId, const std::vector<std::string> &abilityList,
const AAFwk::ExitReason &exitReason, const AppExecFwk::RunningProcessInfo &processInfo, bool withKillMsg)
{
@@ -11579,8 +11579,6 @@ void AppMgrServiceInner::HandleForegroundAbilityDied(
continue;
}
AppRecoveryMgr::AppRecoveryMgr::GetInstance().HandleAppDied(token);
TAG_LOGI(AAFwkTag::APPMGR, "Notified AppRecoveryMgr for ability token: %{public}p",
token.GetRefPtr());
}
}
} // namespace AppExecFwk