!2056 用户创建和删除, 调用存储用户创建完成接口

Merge pull request !2056 from 周士淼/fix_0903_create
This commit is contained in:
openharmony_ci 2024-09-06 12:58:53 +00:00 committed by Gitee
commit fa4a524c7b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 57 additions and 5 deletions

View File

@ -45,6 +45,7 @@ public:
static void SendToCESAccountCreate(OsAccountInfo &osAccountInfo);
static void SendToCESAccountDelete(OsAccountInfo &osAccountInfo);
static void SendToCESAccountSwitched(int newId, int oldId);
static ErrCode SendToStorageAccountCreateComplete(int32_t localId);
static ErrCode SendToStorageAccountCreate(OsAccountInfo &osAccountInfo);
static ErrCode SendToStorageAccountRemove(OsAccountInfo &osAccountInfo);
static ErrCode SendToStorageAccountStart(OsAccountInfo &osAccountInfo);
@ -53,6 +54,7 @@ public:
const OsAccountInfo &osAccountInfo, const std::string &commonEvent, const std::string &operation);
private:
static ErrCode InnerSendToStorageAccountCreateComplete(int32_t localId);
static ErrCode InnerSendToStorageAccountCreate(OsAccountInfo &osAccountInfo);
static int32_t UnlockUser(const int localId);
};

View File

@ -367,8 +367,9 @@ ErrCode IInnerOsAccountManager::SendMsgForAccountCreate(
ACCOUNT_LOGE("create os account SendToStorageAccountCreate failed, errCode %{public}d.", errCode);
return ERR_ACCOUNT_COMMON_GET_SYSTEM_ABILITY_MANAGER;
}
int32_t localId = osAccountInfo.GetLocalId();
#ifdef HAS_THEME_SERVICE_PART
auto task = [localId = osAccountInfo.GetLocalId()] { OsAccountInterface::InitThemeResource(localId); };
auto task = OsAccountInterface::InitThemeResource(localId);
std::thread theme_thread(task);
pthread_setname_np(theme_thread.native_handle(), "InitTheme");
#endif
@ -396,16 +397,17 @@ ErrCode IInnerOsAccountManager::SendMsgForAccountCreate(
if (errCode != ERR_OK) {
ACCOUNT_LOGE("create os account when update isCreateCompleted");
ReportOsAccountOperationFail(
osAccountInfo.GetLocalId(), Constants::OPERATION_CREATE, errCode, "UpdateOsAccount failed!");
localId, Constants::OPERATION_CREATE, errCode, "UpdateOsAccount failed!");
if (osAccountInfo.GetIsDataRemovable()) {
(void)OsAccountInterface::SendToBMSAccountDelete(osAccountInfo);
(void)OsAccountInterface::SendToStorageAccountRemove(osAccountInfo);
}
return ERR_OSACCOUNT_SERVICE_INNER_UPDATE_ACCOUNT_ERROR;
}
ReportOsAccountLifeCycle(osAccountInfo.GetLocalId(), Constants::OPERATION_CREATE);
(void)OsAccountInterface::SendToStorageAccountCreateComplete(localId);
ReportOsAccountLifeCycle(localId, Constants::OPERATION_CREATE);
OsAccountInterface::SendToCESAccountCreate(osAccountInfo);
subscribeManager_.Publish(osAccountInfo.GetLocalId(), OS_ACCOUNT_SUBSCRIBE_TYPE::CREATED);
subscribeManager_.Publish(localId, OS_ACCOUNT_SUBSCRIBE_TYPE::CREATED);
ACCOUNT_LOGI("OsAccountAccountMgr send to storage and bm for start success");
return ERR_OK;
}
@ -784,7 +786,12 @@ ErrCode IInnerOsAccountManager::RemoveOsAccount(const int id)
ACCOUNT_LOGE("RemoveOsAccount cannot find os account info, errCode %{public}d.", errCode);
return ERR_ACCOUNT_COMMON_ACCOUNT_NOT_EXIST_ERROR;
}
errCode = OsAccountInterface::SendToStorageAccountCreateComplete(id);
if (errCode != ERR_OK) {
RemoveLocalIdToOperating(id);
ACCOUNT_LOGE("SendToStorageAccountCreateComplete failed, errCode=%{public}d, id=%{public}d", errCode, id);
return errCode;
}
// set remove flag first
osAccountInfo.SetToBeRemoved(true);
osAccountControl_->UpdateOsAccount(osAccountInfo);

View File

@ -545,5 +545,41 @@ ErrCode OsAccountInterface::SendToStorageAccountStop(OsAccountInfo &osAccountInf
osAccountInfo.SetIsVerified(false);
return ERR_OK;
}
ErrCode OsAccountInterface::SendToStorageAccountCreateComplete(int32_t localId)
{
ErrCode errCode = ERR_OK;
int32_t retryTimes = 0;
while (retryTimes < MAX_RETRY_TIMES) {
errCode = InnerSendToStorageAccountCreateComplete(localId);
if (errCode == ERR_OK) {
break;
}
ACCOUNT_LOGE("Fail to complete account, localId=%{public}d, errCode=%{public}d.", localId, errCode);
retryTimes++;
std::this_thread::sleep_for(std::chrono::milliseconds(DELAY_FOR_EXCEPTION));
}
return errCode;
}
ErrCode OsAccountInterface::InnerSendToStorageAccountCreateComplete(int32_t localId)
{
#ifdef HAS_STORAGE_PART
sptr<StorageManager::IStorageManager> proxy = nullptr;
if (GetStorageProxy(proxy) != ERR_OK) {
ACCOUNT_LOGE("Failed to get STORAGE_MANAGER_MANAGER_ID proxy.");
return ERR_ACCOUNT_COMMON_GET_SYSTEM_ABILITY_MANAGER;
}
StartTraceAdapter("StorageManager CompleteAddUser");
int errCode = proxy->CompleteAddUser(localId);
if (errCode != 0) {
ACCOUNT_LOGE("Failed to CompleteAddUser, localId=%{public}d, errCode=%{public}d", localId, errCode);
ReportOsAccountOperationFail(localId, Constants::OPERATION_CREATE, errCode, "Storage CompleteAddUser failed!");
return errCode;
}
FinishTraceAdapter();
#endif
return ERR_OK;
}
} // namespace AccountSA
} // namespace OHOS

View File

@ -87,6 +87,12 @@ void OsAccountInterface::PublishCommonEvent(
return;
}
ErrCode OsAccountInterface::SendToStorageAccountCreateComplete(int32_t localId)
{
ACCOUNT_LOGI("mock OsAccountInterface SendToStorageAccountCreateComplete start");
return ERR_OK;
}
ErrCode OsAccountInterface::SendToStorageAccountCreate(OsAccountInfo &osAccountInfo)
{
ACCOUNT_LOGI("mock OsAccountInterface SendToStorageAccountCreate start");

View File

@ -36,6 +36,7 @@ public:
static void SendToCESAccountCreate(OsAccountInfo &osAccountInfo);
static void SendToCESAccountDelete(OsAccountInfo &osAccountInfo);
static void SendToCESAccountSwitched(int newId, int oldId);
static ErrCode SendToStorageAccountCreateComplete(int32_t localId);
static ErrCode SendToStorageAccountCreate(OsAccountInfo &osAccountInfo);
static ErrCode SendToStorageAccountRemove(OsAccountInfo &osAccountInfo);
static ErrCode SendToStorageAccountStart(OsAccountInfo &osAccountInfo);