add errcode check

Signed-off-by: xuqian <xuqian65@huawei.com>
This commit is contained in:
xuqian 2024-10-28 14:58:36 +08:00
parent 0790783e71
commit 0802575942
2 changed files with 10 additions and 6 deletions

View File

@ -284,15 +284,16 @@ void AccountMgrService::OnAddSystemAbility(int32_t systemAbilityId, const std::s
return;
}
bool isAccountCompleted = false;
IInnerOsAccountManager::GetInstance().IsOsAccountCompleted(Constants::START_USER_ID, isAccountCompleted);
if (!isAccountCompleted) {
ErrCode errCode =
IInnerOsAccountManager::GetInstance().IsOsAccountCompleted(Constants::START_USER_ID, isAccountCompleted);
if (errCode == ERR_ACCOUNT_COMMON_ACCOUNT_NOT_EXIST_ERROR || (errCode == ERR_OK && !isAccountCompleted)) {
if (!isBmsReady_) {
return;
}
IInnerOsAccountManager::GetInstance().Init();
}
if (!isDefaultOsAccountActivated_ && isAmsReady_) {
ErrCode errCode = IInnerOsAccountManager::GetInstance().ActivateDefaultOsAccount();
errCode = IInnerOsAccountManager::GetInstance().ActivateDefaultOsAccount();
if (errCode == ERR_OK) {
isDefaultOsAccountActivated_ = true;
}

View File

@ -537,19 +537,22 @@ ErrCode OsAccountControlFileManager::GetOsAccountInfoById(const int id, OsAccoun
InsertOsAccount(osAccountInfo);
return ERR_OK;
}
return ERR_ACCOUNT_COMMON_ACCOUNT_NOT_EXIST_ERROR;
return errno == ENOENT ? ERR_ACCOUNT_COMMON_ACCOUNT_NOT_EXIST_ERROR : ERR_ACCOUNT_COMMON_FILE_READ_FAILED;
}
std::string accountInfoStr;
if (accountFileOperator_->GetFileContentByPath(path, accountInfoStr) != ERR_OK) {
ACCOUNT_LOGE("get content from file %{public}s failed!", path.c_str());
return ERR_ACCOUNT_COMMON_ACCOUNT_NOT_EXIST_ERROR;
if (GetOsAccountFromDatabase("", id, osAccountInfo) == ERR_OK) {
return ERR_OK;
}
return ERR_ACCOUNT_COMMON_FILE_READ_FAILED;
}
Json osAccountInfoJson = Json::parse(accountInfoStr, nullptr, false);
if (osAccountInfoJson.is_discarded() || !osAccountInfo.FromJson(osAccountInfoJson)) {
ACCOUNT_LOGE("parse os account info json for %{public}d failed", id);
if (GetOsAccountFromDatabase("", id, osAccountInfo) != ERR_OK) {
ACCOUNT_LOGE("GetOsAccountFromDatabase failed id=%{public}d", id);
return ERR_ACCOUNT_COMMON_BAD_JSON_FORMAT_ERROR;
return ERR_ACCOUNT_COMMON_ACCOUNT_NOT_EXIST_ERROR;
}
}
return ERR_OK;