Merge branch 'master' of gitee.com:openharmony/account_os_account into master

Signed-off-by: lichenchen <lichenchen22@huawei.com>
This commit is contained in:
lichenchen 2024-11-14 08:17:38 +00:00 committed by Gitee
commit 81cea1e017
10 changed files with 37 additions and 14 deletions

View File

@ -96,7 +96,7 @@ public:
ErrCode SetAuthenticatorProperties(const std::string &owner, const SetPropertiesOptions &options, ErrCode SetAuthenticatorProperties(const std::string &owner, const SetPropertiesOptions &options,
const sptr<IAppAccountAuthenticatorCallback> &callback) override; const sptr<IAppAccountAuthenticatorCallback> &callback) override;
ErrCode SubscribeAppAccount( ErrCode SubscribeAppAccount(
const AppAccountSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &eventListener) override; AppAccountSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &eventListener) override;
ErrCode UnsubscribeAppAccount(const sptr<IRemoteObject> &eventListener) override; ErrCode UnsubscribeAppAccount(const sptr<IRemoteObject> &eventListener) override;
private: private:

View File

@ -100,7 +100,7 @@ public:
const sptr<IAppAccountAuthenticatorCallback> &callback) = 0; const sptr<IAppAccountAuthenticatorCallback> &callback) = 0;
virtual ErrCode SubscribeAppAccount( virtual ErrCode SubscribeAppAccount(
const AppAccountSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &eventListener) = 0; AppAccountSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &eventListener) = 0;
virtual ErrCode UnsubscribeAppAccount(const sptr<IRemoteObject> &eventListener) = 0; virtual ErrCode UnsubscribeAppAccount(const sptr<IRemoteObject> &eventListener) = 0;
}; };
} // namespace AccountSA } // namespace AccountSA

View File

@ -1071,7 +1071,7 @@ ErrCode AppAccountProxy::SetAuthenticatorProperties(const std::string &owner,
} }
ErrCode AppAccountProxy::SubscribeAppAccount( ErrCode AppAccountProxy::SubscribeAppAccount(
const AppAccountSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &eventListener) AppAccountSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &eventListener)
{ {
MessageParcel data; MessageParcel data;
MessageParcel reply; MessageParcel reply;

View File

@ -100,7 +100,7 @@ public:
const sptr<IAppAccountAuthenticatorCallback> &callback) override; const sptr<IAppAccountAuthenticatorCallback> &callback) override;
ErrCode SubscribeAppAccount( ErrCode SubscribeAppAccount(
const AppAccountSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &eventListener) override; AppAccountSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &eventListener) override;
ErrCode UnsubscribeAppAccount(const sptr<IRemoteObject> &eventListener) override; ErrCode UnsubscribeAppAccount(const sptr<IRemoteObject> &eventListener) override;
virtual ErrCode OnPackageRemoved(const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex); virtual ErrCode OnPackageRemoved(const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex);

View File

@ -665,7 +665,7 @@ ErrCode AppAccountManagerService::SetAuthenticatorProperties(const std::string &
} }
ErrCode AppAccountManagerService::SubscribeAppAccount( ErrCode AppAccountManagerService::SubscribeAppAccount(
const AppAccountSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &eventListener) AppAccountSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &eventListener)
{ {
int32_t callingUid = -1; int32_t callingUid = -1;
std::string bundleName; std::string bundleName;
@ -683,16 +683,22 @@ ErrCode AppAccountManagerService::SubscribeAppAccount(
} }
int32_t userId = callingUid / UID_TRANSFORM_DIVISOR; int32_t userId = callingUid / UID_TRANSFORM_DIVISOR;
std::vector<std::string> existOwners;
for (auto owner : owners) { for (auto owner : owners) {
AppExecFwk::BundleInfo bundleInfo; AppExecFwk::BundleInfo bundleInfo;
bool bundleRet = BundleManagerAdapter::GetInstance()->GetBundleInfo(owner, bool bundleRet = BundleManagerAdapter::GetInstance()->GetBundleInfo(owner,
AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, userId); AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, userId);
if (!bundleRet) { if (!bundleRet) {
ACCOUNT_LOGE("failed to get bundle info"); ACCOUNT_LOGE("Failed to get bundle info, name=%{public}s", owner.c_str());
return ERR_OK; continue;
} }
existOwners.push_back(owner);
} }
if (existOwners.size() == 0) {
ACCOUNT_LOGI("ExistOwners is empty.");
return ERR_OK;
}
subscribeInfo.SetOwners(existOwners);
return innerManager_->SubscribeAppAccount(subscribeInfo, eventListener, callingUid, bundleName, appIndex); return innerManager_->SubscribeAppAccount(subscribeInfo, eventListener, callingUid, bundleName, appIndex);
} }

View File

@ -1865,6 +1865,7 @@ ErrCode IInnerOsAccountManager::DeactivateOsAccount(const int id, bool isStopSto
OsAccountInterface::PublishCommonEvent(osAccountInfo, OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_STOPPED, OsAccountInterface::PublishCommonEvent(osAccountInfo, OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_STOPPED,
Constants::OPERATION_STOP); Constants::OPERATION_STOP);
subscribeManager_.Publish(id, OS_ACCOUNT_SUBSCRIBE_TYPE::STOPPED); subscribeManager_.Publish(id, OS_ACCOUNT_SUBSCRIBE_TYPE::STOPPED);
ReportOsAccountLifeCycle(id, Constants::OPERATION_STOP);
RemoveLocalIdToOperating(id); RemoveLocalIdToOperating(id);
ACCOUNT_LOGI("IInnerOsAccountManager DeactivateOsAccount end"); ACCOUNT_LOGI("IInnerOsAccountManager DeactivateOsAccount end");
@ -1878,6 +1879,7 @@ ErrCode IInnerOsAccountManager::SendMsgForAccountActivate(OsAccountInfo &osAccou
int32_t oldId = -1; int32_t oldId = -1;
bool oldIdExist = foregroundAccountMap_.Find(displayId, oldId); bool oldIdExist = foregroundAccountMap_.Find(displayId, oldId);
int32_t localId = static_cast<int32_t>(osAccountInfo.GetLocalId()); int32_t localId = static_cast<int32_t>(osAccountInfo.GetLocalId());
bool preActivated = osAccountInfo.GetIsActived();
if (oldId != localId) { if (oldId != localId) {
subscribeManager_.Publish(localId, oldId, OS_ACCOUNT_SUBSCRIBE_TYPE::SWITCHING); subscribeManager_.Publish(localId, oldId, OS_ACCOUNT_SUBSCRIBE_TYPE::SWITCHING);
} }
@ -1912,6 +1914,9 @@ ErrCode IInnerOsAccountManager::SendMsgForAccountActivate(OsAccountInfo &osAccou
subscribeManager_.Publish(localId, oldId, OS_ACCOUNT_SUBSCRIBE_TYPE::SWITCHED); subscribeManager_.Publish(localId, oldId, OS_ACCOUNT_SUBSCRIBE_TYPE::SWITCHED);
ReportOsAccountSwitch(localId, oldId); ReportOsAccountSwitch(localId, oldId);
} }
if (!preActivated) {
ReportOsAccountLifeCycle(defaultActivatedId_, Constants::OPERATION_ACTIVATE);
}
ACCOUNT_LOGI("SendMsgForAccountActivate ok"); ACCOUNT_LOGI("SendMsgForAccountActivate ok");
return errCode; return errCode;
} }
@ -1936,6 +1941,7 @@ ErrCode IInnerOsAccountManager::SendToStorageAccountStart(OsAccountInfo &osAcco
OsAccountInterface::PublishCommonEvent(osAccountInfo, OsAccountInterface::PublishCommonEvent(osAccountInfo,
OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_UNLOCKED, Constants::OPERATION_UNLOCK); OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_UNLOCKED, Constants::OPERATION_UNLOCK);
subscribeManager_.Publish(localId, OS_ACCOUNT_SUBSCRIBE_TYPE::UNLOCKED); subscribeManager_.Publish(localId, OS_ACCOUNT_SUBSCRIBE_TYPE::UNLOCKED);
ReportOsAccountLifeCycle(localId, Constants::OPERATION_UNLOCK);
} }
return ERR_OK; return ERR_OK;
} }
@ -2088,6 +2094,7 @@ ErrCode IInnerOsAccountManager::SetOsAccountIsVerified(const int id, const bool
OsAccountInterface::PublishCommonEvent(osAccountInfo, OsAccountInterface::PublishCommonEvent(osAccountInfo,
OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_UNLOCKED, Constants::OPERATION_UNLOCK); OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_UNLOCKED, Constants::OPERATION_UNLOCK);
subscribeManager_.Publish(id, OS_ACCOUNT_SUBSCRIBE_TYPE::UNLOCKED); subscribeManager_.Publish(id, OS_ACCOUNT_SUBSCRIBE_TYPE::UNLOCKED);
ReportOsAccountLifeCycle(id, Constants::OPERATION_UNLOCK);
CleanGarbageOsAccountsAsync(); CleanGarbageOsAccountsAsync();
} }

View File

@ -331,7 +331,7 @@ ErrCode OsAccountInterface::SendToStorageAccountCreate(OsAccountInfo &osAccountI
int32_t retryTimes = 0; int32_t retryTimes = 0;
while (retryTimes < MAX_RETRY_TIMES) { while (retryTimes < MAX_RETRY_TIMES) {
errCode = InnerSendToStorageAccountCreate(osAccountInfo); errCode = InnerSendToStorageAccountCreate(osAccountInfo);
if (errCode == ERR_OK) { if (errCode != Constants::E_IPC_ERROR && errCode != Constants::E_IPC_SA_DIED) {
break; break;
} }
ACCOUNT_LOGE("Fail to SendToStorageAccountCreate,id=%{public}d, errCode %{public}d.", ACCOUNT_LOGE("Fail to SendToStorageAccountCreate,id=%{public}d, errCode %{public}d.",
@ -343,7 +343,7 @@ ErrCode OsAccountInterface::SendToStorageAccountCreate(OsAccountInfo &osAccountI
} }
#ifdef HAS_STORAGE_PART #ifdef HAS_STORAGE_PART
static ErrCode PrepareAddUser(sptr<StorageManager::IStorageManager> &proxy, int32_t userId) static ErrCode PrepareAddUser(const sptr<StorageManager::IStorageManager> &proxy, int32_t userId)
{ {
ErrCode err = proxy->PrepareAddUser(userId, CRYPTO_FLAG_EL1 | CRYPTO_FLAG_EL2); ErrCode err = proxy->PrepareAddUser(userId, CRYPTO_FLAG_EL1 | CRYPTO_FLAG_EL2);
if (err == 0) { if (err == 0) {
@ -383,18 +383,20 @@ ErrCode OsAccountInterface::InnerSendToStorageAccountCreate(OsAccountInfo &osAcc
return ERR_ACCOUNT_COMMON_GET_SYSTEM_ABILITY_MANAGER; return ERR_ACCOUNT_COMMON_GET_SYSTEM_ABILITY_MANAGER;
} }
StartTraceAdapter("StorageManager PrepareAddUser"); StartTraceAdapter("StorageManager PrepareAddUser");
ErrCode err = PrepareAddUser(proxy, localId); ErrCode err = PrepareAddUser(proxy, localId);
if (err == ERR_OK) { if (err == ERR_OK) {
FinishTraceAdapter(); FinishTraceAdapter();
return ERR_OK; return ERR_OK;
} }
ACCOUNT_LOGI("PrepareAddUser Failed, start check and clear accounts.");
ACCOUNT_LOGI("PrepareAddUser Failed, start check and clean accounts.");
auto &osAccountManager = IInnerOsAccountManager::GetInstance(); auto &osAccountManager = IInnerOsAccountManager::GetInstance();
if (osAccountManager.CleanGarbageOsAccounts(localId) <= 0) { if (osAccountManager.CleanGarbageOsAccounts(localId) <= 0) {
FinishTraceAdapter(); FinishTraceAdapter();
return err; return err;
} }
ACCOUNT_LOGI("Clean garbage account data, Retry storage PrepareAddUser."); ACCOUNT_LOGI("Clean garbage account data, Retry Storage PrepareAddUser.");
err = PrepareAddUser(proxy, localId); err = PrepareAddUser(proxy, localId);
FinishTraceAdapter(); FinishTraceAdapter();
return err; return err;

View File

@ -1155,6 +1155,14 @@ ErrCode OsAccountManagerService::GetBackgroundOsAccountLocalIds(std::vector<int3
ErrCode OsAccountManagerService::SetOsAccountToBeRemoved(int32_t localId, bool toBeRemoved) ErrCode OsAccountManagerService::SetOsAccountToBeRemoved(int32_t localId, bool toBeRemoved)
{ {
ErrCode res = CheckLocalId(localId);
if (res != ERR_OK) {
return res;
}
if ((localId == Constants::START_USER_ID) || (localId == Constants::ADMIN_LOCAL_ID)) {
ACCOUNT_LOGE("Cannot remove system preinstalled user.");
return ERR_OSACCOUNT_SERVICE_MANAGER_ID_ERROR;
}
if (!PermissionCheck(MANAGE_LOCAL_ACCOUNTS, "")) { if (!PermissionCheck(MANAGE_LOCAL_ACCOUNTS, "")) {
ACCOUNT_LOGE("Permission denied."); ACCOUNT_LOGE("Permission denied.");
return ERR_ACCOUNT_COMMON_PERMISSION_DENIED; return ERR_ACCOUNT_COMMON_PERMISSION_DENIED;

View File

@ -364,7 +364,7 @@ ErrCode MockAppAccountStub::SetAuthenticatorProperties(const std::string &owner,
} }
ErrCode MockAppAccountStub::SubscribeAppAccount( ErrCode MockAppAccountStub::SubscribeAppAccount(
const AppAccountSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &eventListener) AppAccountSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &eventListener)
{ {
ACCOUNT_LOGI("mock enter"); ACCOUNT_LOGI("mock enter");

View File

@ -96,7 +96,7 @@ public:
const sptr<IAppAccountAuthenticatorCallback> &callback) override; const sptr<IAppAccountAuthenticatorCallback> &callback) override;
ErrCode SubscribeAppAccount( ErrCode SubscribeAppAccount(
const AppAccountSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &eventListener) override; AppAccountSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &eventListener) override;
ErrCode UnsubscribeAppAccount(const sptr<IRemoteObject> &eventListener) override; ErrCode UnsubscribeAppAccount(const sptr<IRemoteObject> &eventListener) override;
}; };
} // namespace AccountSA } // namespace AccountSA