域账号扩展参数, shortName参数

Signed-off-by: zhoushimiao <zhoushimiao@huawei.com>
Change-Id: I3f9796a77e645ed8405a435622fee9bd76aefb3a
This commit is contained in:
ZhouShimiao 2024-04-25 16:53:57 +08:00
parent c64da62b70
commit 2809c37bdf
23 changed files with 211 additions and 42 deletions

View File

@ -350,5 +350,42 @@ DomainAuthResult *DomainAuthResult::Unmarshalling(Parcel &parcel)
} }
return result; return result;
} }
bool CreateOsAccountForDomainOptions::Marshalling(Parcel &parcel) const
{
if (!parcel.WriteString(shortName)) {
ACCOUNT_LOGE("Failed to write shortName");
return false;
}
if (!parcel.WriteBool(hasShortName)) {
ACCOUNT_LOGE("Failed to write hasShortName");
return false;
}
return true;
}
CreateOsAccountForDomainOptions *CreateOsAccountForDomainOptions::Unmarshalling(Parcel &parcel)
{
CreateOsAccountForDomainOptions *options = new (std::nothrow) CreateOsAccountForDomainOptions();
if ((options != nullptr) && (!options->ReadFromParcel(parcel))) {
ACCOUNT_LOGE("Failed to read from parcel");
delete options;
options = nullptr;
}
return options;
}
bool CreateOsAccountForDomainOptions::ReadFromParcel(Parcel &parcel)
{
if (!parcel.ReadString(shortName)) {
ACCOUNT_LOGE("Failed to read shortName.");
return false;
}
if (!parcel.ReadBool(hasShortName)) {
ACCOUNT_LOGE("Failed to read hasShortName.");
return false;
}
return true;
}
} // namespace AccountSA } // namespace AccountSA
} // namespace OHOS } // namespace OHOS

View File

@ -67,6 +67,7 @@ const std::vector<uint8_t> DEFAULT_TOKEN = {49, 50, 51, 52, 53};
static uint64_t g_selfTokenID; static uint64_t g_selfTokenID;
#ifdef ENABLE_MULTIPLE_OS_ACCOUNTS #ifdef ENABLE_MULTIPLE_OS_ACCOUNTS
const int32_t WAIT_TIME = 2; const int32_t WAIT_TIME = 2;
const std::string STRING_SHORT_NAME_OUT_OF_RANGE(256, '1');
#endif #endif
const std::map<PluginMethodEnum, void *> PLUGIN_METHOD_MAP = { const std::map<PluginMethodEnum, void *> PLUGIN_METHOD_MAP = {
{PluginMethodEnum::AUTH, reinterpret_cast<void *>(Auth)}, {PluginMethodEnum::AUTH, reinterpret_cast<void *>(Auth)},
@ -697,7 +698,69 @@ HWTEST_F(DomainAccountClientMockPluginSoModuleTest, DomainAccountClientModuleTes
EXPECT_EQ(OsAccountManager::GetOsAccountLocalIdFromDomain(domainInfo, userId), ERR_OK); EXPECT_EQ(OsAccountManager::GetOsAccountLocalIdFromDomain(domainInfo, userId), ERR_OK);
EXPECT_EQ(OsAccountManager::RemoveOsAccount(userId), ERR_OK); EXPECT_EQ(OsAccountManager::RemoveOsAccount(userId), ERR_OK);
} }
#endif
/**
* @tc.name: DomainAccountClientModuleTest_IsAuthenticationExpired_005
* @tc.desc: IsAuthenticationExpired success.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DomainAccountClientMockPluginSoModuleTest, DomainAccountClientModuleTest_IsAuthenticationExpired_007,
TestSize.Level0)
{
DomainAccountInfo domainInfo;
domainInfo.accountName_ = "testaccount";
domainInfo.domain_ = "test.example.com";
domainInfo.accountId_ = "testid";
CreateOsAccountForDomainOptions options;
options.hasShortName = true;
OsAccountInfo osAccountInfo;
ErrCode code = OsAccountManager::CreateOsAccount("domain007", "shortExist", OsAccountType::NORMAL, osAccountInfo);
EXPECT_EQ(code, ERR_OK);
auto testCallback1 = nullptr;
options.shortName = "TEST1*";
EXPECT_NE(OsAccountManager::CreateOsAccountForDomain(OsAccountType::NORMAL, domainInfo,
testCallback1, options), ERR_OK);
options.shortName = "..";
EXPECT_NE(OsAccountManager::CreateOsAccountForDomain(OsAccountType::NORMAL, domainInfo,
testCallback1, options), ERR_OK);
options.shortName = "";
EXPECT_NE(OsAccountManager::CreateOsAccountForDomain(OsAccountType::NORMAL, domainInfo,
testCallback1, options), ERR_OK);
options.shortName = STRING_SHORT_NAME_OUT_OF_RANGE;
EXPECT_NE(OsAccountManager::CreateOsAccountForDomain(OsAccountType::NORMAL, domainInfo,
testCallback1, options), ERR_OK);
options.shortName = "shortExist";
EXPECT_NE(OsAccountManager::CreateOsAccountForDomain(OsAccountType::NORMAL, domainInfo,
testCallback1, options), ERR_OK);
LoadPluginMethods();
auto callback = std::make_shared<MockPluginSoDomainCreateDomainAccountCallback>();
ASSERT_NE(callback, nullptr);
auto testCallback = std::make_shared<TestPluginSoCreateDomainAccountCallback>(callback);
EXPECT_CALL(*callback, OnResult(ERR_OK, "testaccount", "test.example.com", _)).Times(Exactly(1));
ASSERT_NE(testCallback, nullptr);
options.shortName = "shortNameTest";
options.hasShortName = false;
ErrCode errCode = OsAccountManager::CreateOsAccountForDomain(OsAccountType::NORMAL, domainInfo,
testCallback, options);
std::unique_lock<std::mutex> lock(testCallback->mutex);
testCallback->cv.wait_for(lock, std::chrono::seconds(WAIT_TIME),
[lockCallback = testCallback]() { return lockCallback->isReady; });
EXPECT_EQ(errCode, ERR_OK);
int32_t userId = -1;
EXPECT_EQ(OsAccountManager::GetOsAccountLocalIdFromDomain(domainInfo, userId), ERR_OK);
EXPECT_EQ(OsAccountManager::RemoveOsAccount(userId), ERR_OK);
EXPECT_EQ(OsAccountManager::RemoveOsAccount(osAccountInfo.GetLocalId()), ERR_OK);
}
#endif // ENABLE_MULTIPLE_OS_ACCOUNTS
/** /**
* @tc.name: DomainAccountClientModuleTest_IsAuthenticationExpired_006 * @tc.name: DomainAccountClientModuleTest_IsAuthenticationExpired_006

View File

@ -719,7 +719,10 @@ HWTEST_F(DomainAccountClientModuleTest, DomainAccountClientModuleTest_CreateOsAc
EXPECT_CALL(*callback, OnResult(ERR_OK, EXPECT_CALL(*callback, OnResult(ERR_OK,
STRING_NAME, INVALID_STRING_DOMAIN, STRING_ACCOUNTID_NEW)).Times(Exactly(1)); STRING_NAME, INVALID_STRING_DOMAIN, STRING_ACCOUNTID_NEW)).Times(Exactly(1));
ASSERT_NE(testCallback, nullptr); ASSERT_NE(testCallback, nullptr);
ErrCode errCode = OsAccountManager::CreateOsAccountForDomain(OsAccountType::NORMAL, domainInfo, testCallback); CreateOsAccountForDomainOptions options;
options.shortName = "shortName";
ErrCode errCode = OsAccountManager::CreateOsAccountForDomain(OsAccountType::NORMAL, domainInfo,
testCallback, options);
std::unique_lock<std::mutex> lock(testCallback->mutex); std::unique_lock<std::mutex> lock(testCallback->mutex);
testCallback->cv.wait_for( testCallback->cv.wait_for(
lock, std::chrono::seconds(WAIT_TIME), [lockCallback = testCallback]() { return lockCallback->isReady; }); lock, std::chrono::seconds(WAIT_TIME), [lockCallback = testCallback]() { return lockCallback->isReady; });
@ -729,6 +732,9 @@ HWTEST_F(DomainAccountClientModuleTest, DomainAccountClientModuleTest_CreateOsAc
int32_t userId = -1; int32_t userId = -1;
errCode = OsAccountManager::GetOsAccountLocalIdFromDomain(domainInfo, userId); errCode = OsAccountManager::GetOsAccountLocalIdFromDomain(domainInfo, userId);
EXPECT_EQ(errCode, ERR_OK); EXPECT_EQ(errCode, ERR_OK);
OsAccountInfo osAccountInfo;
EXPECT_EQ(OsAccountManager::QueryOsAccountById(userId, osAccountInfo), ERR_OK);
EXPECT_EQ(osAccountInfo.GetShortName(), options.shortName);
EXPECT_EQ(OsAccountManager::RemoveOsAccount(userId), ERR_OK); EXPECT_EQ(OsAccountManager::RemoveOsAccount(userId), ERR_OK);
} }
#endif // ENABLE_MULTIPLE_OS_ACCOUNTS #endif // ENABLE_MULTIPLE_OS_ACCOUNTS

View File

@ -39,7 +39,7 @@ public:
virtual ErrCode CreateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo) = 0; virtual ErrCode CreateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo) = 0;
virtual ErrCode UpdateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo) = 0; virtual ErrCode UpdateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo) = 0;
virtual ErrCode CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo, virtual ErrCode CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo,
const sptr<IDomainAccountCallback> &callback) = 0; const sptr<IDomainAccountCallback> &callback, const CreateOsAccountForDomainOptions& options = {}) = 0;
virtual ErrCode RemoveOsAccount(const int id) = 0; virtual ErrCode RemoveOsAccount(const int id) = 0;
virtual ErrCode IsOsAccountExists(const int id, bool &isOsAccountExists) = 0; virtual ErrCode IsOsAccountExists(const int id, bool &isOsAccountExists) = 0;
virtual ErrCode IsOsAccountActived(const int id, bool &isOsAccountActived) = 0; virtual ErrCode IsOsAccountActived(const int id, bool &isOsAccountActived) = 0;

View File

@ -32,7 +32,7 @@ public:
ErrCode CreateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo); ErrCode CreateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo);
ErrCode UpdateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo); ErrCode UpdateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo);
ErrCode CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo, ErrCode CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo,
const std::shared_ptr<DomainAccountCallback> &callback); const std::shared_ptr<DomainAccountCallback> &callback, const CreateOsAccountForDomainOptions& options = {});
ErrCode RemoveOsAccount(const int id); ErrCode RemoveOsAccount(const int id);
ErrCode IsOsAccountExists(const int id, bool &isOsAccountExists); ErrCode IsOsAccountExists(const int id, bool &isOsAccountExists);
ErrCode IsOsAccountActived(const int id, bool &isOsAccountActived); ErrCode IsOsAccountActived(const int id, bool &isOsAccountActived);

View File

@ -33,7 +33,7 @@ public:
ErrCode CreateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo) override; ErrCode CreateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo) override;
ErrCode UpdateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo) override; ErrCode UpdateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo) override;
ErrCode CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo, ErrCode CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo,
const sptr<IDomainAccountCallback> &callback) override; const sptr<IDomainAccountCallback> &callback, const CreateOsAccountForDomainOptions& options) override;
ErrCode RemoveOsAccount(const int id) override; ErrCode RemoveOsAccount(const int id) override;
ErrCode IsOsAccountExists(const int id, bool &isOsAccountExists) override; ErrCode IsOsAccountExists(const int id, bool &isOsAccountExists) override;
ErrCode IsOsAccountActived(const int id, bool &isOsAccountActived) override; ErrCode IsOsAccountActived(const int id, bool &isOsAccountActived) override;

View File

@ -114,17 +114,23 @@ ErrCode OsAccount::UpdateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo)
} }
ErrCode OsAccount::CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo, ErrCode OsAccount::CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo,
const std::shared_ptr<DomainAccountCallback> &callback) const std::shared_ptr<DomainAccountCallback> &callback, const CreateOsAccountForDomainOptions& options)
{ {
if (domainInfo.domain_.empty() || if (domainInfo.domain_.empty() ||
domainInfo.domain_.size() > Constants::DOMAIN_NAME_MAX_SIZE) { domainInfo.domain_.size() > Constants::DOMAIN_NAME_MAX_SIZE) {
ACCOUNT_LOGE("domain is empty or too long, len %{public}zu.", domainInfo.domain_.size()); ACCOUNT_LOGE("Domain is empty or too long, len=%{public}zu.", domainInfo.domain_.size());
return ERR_ACCOUNT_COMMON_INVALID_PARAMETER; return ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
} }
if (domainInfo.accountName_.empty() || if (domainInfo.accountName_.empty() ||
domainInfo.accountName_.size() > Constants::DOMAIN_ACCOUNT_NAME_MAX_SIZE) { domainInfo.accountName_.size() > Constants::DOMAIN_ACCOUNT_NAME_MAX_SIZE) {
ACCOUNT_LOGE("account name is empty or too long, len %{public}zu.", domainInfo.accountName_.size()); ACCOUNT_LOGE("Account name is empty or too long, len=%{public}zu.", domainInfo.accountName_.size());
return ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
}
if (options.hasShortName && ((options.shortName.size() > Constants::SHORT_NAME_MAX_SIZE) ||
(options.shortName == ""))) {
ACCOUNT_LOGE("Account short name is empty or too long, len=%{public}zu.", options.shortName.size());
return ERR_ACCOUNT_COMMON_INVALID_PARAMETER; return ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
} }
@ -133,7 +139,7 @@ ErrCode OsAccount::CreateOsAccountForDomain(const OsAccountType &type, const Dom
return ERR_ACCOUNT_COMMON_GET_PROXY; return ERR_ACCOUNT_COMMON_GET_PROXY;
} }
sptr<DomainAccountCallbackService> callbackService = new (std::nothrow) DomainAccountCallbackService(callback); sptr<DomainAccountCallbackService> callbackService = new (std::nothrow) DomainAccountCallbackService(callback);
return proxy->CreateOsAccountForDomain(type, domainInfo, callbackService); return proxy->CreateOsAccountForDomain(type, domainInfo, callbackService, options);
} }
ErrCode OsAccount::RemoveOsAccount(const int id) ErrCode OsAccount::RemoveOsAccount(const int id)

View File

@ -174,40 +174,45 @@ ErrCode OsAccountProxy::UpdateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo
} }
ErrCode OsAccountProxy::CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo, ErrCode OsAccountProxy::CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo,
const sptr<IDomainAccountCallback> &callback) const sptr<IDomainAccountCallback> &callback, const CreateOsAccountForDomainOptions& options)
{ {
MessageParcel data; MessageParcel data;
MessageParcel reply; MessageParcel reply;
if (!data.WriteInterfaceToken(GetDescriptor())) { if (!data.WriteInterfaceToken(GetDescriptor())) {
ACCOUNT_LOGE("failed to write descriptor!"); ACCOUNT_LOGE("Failed to write descriptor!");
return ERR_ACCOUNT_COMMON_WRITE_DESCRIPTOR_ERROR; return ERR_ACCOUNT_COMMON_WRITE_DESCRIPTOR_ERROR;
} }
if (!data.WriteInt32(static_cast<int32_t>(type))) { if (!data.WriteInt32(static_cast<int32_t>(type))) {
ACCOUNT_LOGE("failed to write type "); ACCOUNT_LOGE("Failed to write type ");
return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR; return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
} }
if (!data.WriteParcelable(&domainInfo)) { if (!data.WriteParcelable(&domainInfo)) {
ACCOUNT_LOGE("fail to write name"); ACCOUNT_LOGE("Fail to write domainInfo");
return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR; return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
} }
if ((callback == nullptr) || (!data.WriteRemoteObject(callback->AsObject()))) { if ((callback == nullptr) || (!data.WriteRemoteObject(callback->AsObject()))) {
ACCOUNT_LOGE("fail to write callback"); ACCOUNT_LOGE("Fail to write callback");
return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
}
if (!data.WriteParcelable(&options)) {
ACCOUNT_LOGE("Failed to write options");
return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR; return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
} }
ErrCode result = SendRequest(OsAccountInterfaceCode::CREATE_OS_ACCOUNT_FOR_DOMAIN, data, reply); ErrCode result = SendRequest(OsAccountInterfaceCode::CREATE_OS_ACCOUNT_FOR_DOMAIN, data, reply);
if (result != ERR_OK) { if (result != ERR_OK) {
ACCOUNT_LOGE("failed to send request, result %{public}d.", result); ACCOUNT_LOGE("Failed to send request, result %{public}d.", result);
return result; return result;
} }
result = reply.ReadInt32(); result = reply.ReadInt32();
if (result != ERR_OK) { if (result != ERR_OK) {
ACCOUNT_LOGE("failed to read reply for create os account for domain, result %{public}d.", result); ACCOUNT_LOGE("Failed to read reply for create os account for domain, result %{public}d.", result);
return result; return result;
} }
return ERR_OK; return ERR_OK;

View File

@ -18,9 +18,11 @@
"VTT for OHOS::AccountSA::OsAccountInfo"; "VTT for OHOS::AccountSA::OsAccountInfo";
"VTT for OHOS::AccountSA::OsAccountSubscribeInfo"; "VTT for OHOS::AccountSA::OsAccountSubscribeInfo";
"VTT for OHOS::AccountSA::CreateOsAccountOptions"; "VTT for OHOS::AccountSA::CreateOsAccountOptions";
"VTT for OHOS::AccountSA::CreateOsAccountForDomainOptions";
"vtable for OHOS::AccountSA::OsAccountInfo"; "vtable for OHOS::AccountSA::OsAccountInfo";
"vtable for OHOS::AccountSA::OsAccountSubscribeInfo"; "vtable for OHOS::AccountSA::OsAccountSubscribeInfo";
"vtable for OHOS::AccountSA::CreateOsAccountOptions"; "vtable for OHOS::AccountSA::CreateOsAccountOptions";
"vtable for OHOS::AccountSA::CreateOsAccountForDomainOptions";
"OHOS::AccountSA::OsAccount::GetInstance()"; "OHOS::AccountSA::OsAccount::GetInstance()";
"OHOS::AccountSA::OsAccount::CreateOsAccountEventListener(std::__h::shared_ptr<OHOS::AccountSA::OsAccountSubscriber> const&, OHOS::sptr<OHOS::IRemoteObject>&)"; "OHOS::AccountSA::OsAccount::CreateOsAccountEventListener(std::__h::shared_ptr<OHOS::AccountSA::OsAccountSubscriber> const&, OHOS::sptr<OHOS::IRemoteObject>&)";
"OHOS::AccountSA::OsAccount::CreateOsAccount(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, OHOS::AccountSA::OsAccountType const&, OHOS::AccountSA::OsAccountInfo&)"; "OHOS::AccountSA::OsAccount::CreateOsAccount(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, OHOS::AccountSA::OsAccountType const&, OHOS::AccountSA::OsAccountInfo&)";
@ -84,7 +86,6 @@
"OHOS::AccountSA::OsAccountManager::CreateOsAccount(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, OHOS::AccountSA::OsAccountType const&, OHOS::AccountSA::OsAccountInfo&)"; "OHOS::AccountSA::OsAccountManager::CreateOsAccount(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, OHOS::AccountSA::OsAccountType const&, OHOS::AccountSA::OsAccountInfo&)";
"OHOS::AccountSA::OsAccountManager::CreateOsAccountWithFullInfo(OHOS::AccountSA::OsAccountInfo&)"; "OHOS::AccountSA::OsAccountManager::CreateOsAccountWithFullInfo(OHOS::AccountSA::OsAccountInfo&)";
"OHOS::AccountSA::OsAccountManager::UpdateOsAccountWithFullInfo(OHOS::AccountSA::OsAccountInfo&)"; "OHOS::AccountSA::OsAccountManager::UpdateOsAccountWithFullInfo(OHOS::AccountSA::OsAccountInfo&)";
"OHOS::AccountSA::OsAccountManager::CreateOsAccountForDomain(OHOS::AccountSA::OsAccountType const&, OHOS::AccountSA::DomainAccountInfo const&, OHOS::AccountSA::OsAccountInfo&)";
"OHOS::AccountSA::OsAccountManager::RemoveOsAccount(int)"; "OHOS::AccountSA::OsAccountManager::RemoveOsAccount(int)";
"OHOS::AccountSA::OsAccountManager::IsOsAccountExists(int, bool&)"; "OHOS::AccountSA::OsAccountManager::IsOsAccountExists(int, bool&)";
"OHOS::AccountSA::OsAccountManager::IsOsAccountActived(int, bool&)"; "OHOS::AccountSA::OsAccountManager::IsOsAccountActived(int, bool&)";
@ -224,6 +225,7 @@
"OHOS::AccountSA::OsAccountSubscribeInfo::SetOsAccountSubscribeType(OHOS::AccountSA::OS_ACCOUNT_SUBSCRIBE_TYPE const&)"; "OHOS::AccountSA::OsAccountSubscribeInfo::SetOsAccountSubscribeType(OHOS::AccountSA::OS_ACCOUNT_SUBSCRIBE_TYPE const&)";
"OHOS::AccountSA::OsAccountSubscribeInfo::SetName(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&)"; "OHOS::AccountSA::OsAccountSubscribeInfo::SetName(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&)";
*OHOS::AccountSA::CreateOsAccountOptions*; *OHOS::AccountSA::CreateOsAccountOptions*;
*OHOS::AccountSA::CreateOsAccountForDomainOptions*;
"vtable for OHOS::AccountSA::DomainAccountInfo"; "vtable for OHOS::AccountSA::DomainAccountInfo";
"OHOS::AccountSA::DomainAccountInfo::DomainAccountInfo()"; "OHOS::AccountSA::DomainAccountInfo::DomainAccountInfo()";
"OHOS::AccountSA::DomainAccountClient::GetInstance()"; "OHOS::AccountSA::DomainAccountClient::GetInstance()";

View File

@ -50,9 +50,9 @@ ErrCode OsAccountManager::UpdateOsAccountWithFullInfo(OsAccountInfo &osAccountIn
} }
ErrCode OsAccountManager::CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo, ErrCode OsAccountManager::CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo,
const std::shared_ptr<DomainAccountCallback> &callback) const std::shared_ptr<DomainAccountCallback> &callback, const CreateOsAccountForDomainOptions &options)
{ {
return OsAccount::GetInstance().CreateOsAccountForDomain(type, domainInfo, callback); return OsAccount::GetInstance().CreateOsAccountForDomain(type, domainInfo, callback, options);
} }
ErrCode OsAccountManager::RemoveOsAccount(const int id) ErrCode OsAccountManager::RemoveOsAccount(const int id)

View File

@ -45,6 +45,14 @@ typedef enum {
LOG_OUT, LOG_OUT,
} DomainAccountEvent; } DomainAccountEvent;
struct CreateOsAccountForDomainOptions: public Parcelable {
bool ReadFromParcel(Parcel &parcel);
bool Marshalling(Parcel &parcel) const override;
static CreateOsAccountForDomainOptions *Unmarshalling(Parcel &parcel);
std::string shortName;
bool hasShortName = false;
};
class DomainAccountInfo : public Parcelable { class DomainAccountInfo : public Parcelable {
public: public:
DomainAccountInfo(); DomainAccountInfo();

View File

@ -108,7 +108,7 @@ public:
* @return error code, see account_error_no.h * @return error code, see account_error_no.h
*/ */
static ErrCode CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo, static ErrCode CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo,
const std::shared_ptr<DomainAccountCallback> &callback); const std::shared_ptr<DomainAccountCallback> &callback, const CreateOsAccountForDomainOptions& options = {});
/** /**
* @brief Removes an OS account based on its local ID. * @brief Removes an OS account based on its local ID.

View File

@ -85,6 +85,7 @@ struct CreateOAForDomainAsyncContext : public CommonAsyncContext {
OsAccountType type; OsAccountType type;
DomainAccountInfo domainInfo; DomainAccountInfo domainInfo;
OsAccountInfo osAccountInfos; OsAccountInfo osAccountInfos;
CreateOsAccountForDomainOptions domainOptions;
ThreadLockInfo *lockInfo; ThreadLockInfo *lockInfo;
}; };

View File

@ -533,6 +533,16 @@ static bool ParseDomainAccountInfo(napi_env env, napi_value object, DomainAccoun
return true; return true;
} }
static bool ParseDomainOptionInfo(napi_env env, napi_value object, CreateOsAccountForDomainOptions &domainOptions)
{
if (!GetStringPropertyByKey(env, object, "shortName", domainOptions.shortName)) {
ACCOUNT_LOGE("Failed to get options's shortName");
return false;
}
domainOptions.hasShortName = true;
return true;
}
bool ParseParaCreateOAForDomain(napi_env env, napi_callback_info cbInfo, bool ParseParaCreateOAForDomain(napi_env env, napi_callback_info cbInfo,
CreateOAForDomainAsyncContext *asyncContext) CreateOAForDomainAsyncContext *asyncContext)
{ {
@ -540,12 +550,16 @@ bool ParseParaCreateOAForDomain(napi_env env, napi_callback_info cbInfo,
napi_value argv[ARGS_SIZE_THREE] = {0}; napi_value argv[ARGS_SIZE_THREE] = {0};
napi_get_cb_info(env, cbInfo, &argc, argv, nullptr, nullptr); napi_get_cb_info(env, cbInfo, &argc, argv, nullptr, nullptr);
napi_valuetype valueType = napi_undefined;
if (argc == ARGS_SIZE_THREE) { if (argc == ARGS_SIZE_THREE) {
if (!GetCallbackProperty(env, argv[argc - 1], asyncContext->callbackRef, 1)) { napi_typeof(env, argv[ARGS_SIZE_TWO], &valueType);
ACCOUNT_LOGE("Get CreateOAForDomain callbackRef failed"); if (!GetCallbackProperty(env, argv[PARAMTWO], asyncContext->callbackRef, 1)) {
std::string errMsg = "The type of arg " + std::to_string(argc) + " must be function"; if (!ParseDomainOptionInfo(env, argv[PARAMTWO], asyncContext->domainOptions)) {
AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, asyncContext->throwErr); ACCOUNT_LOGE("Failed to get domainOptions");
return false; std::string errMsg = "The type of arg 3 must contains shortName";
AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, asyncContext->throwErr);
return false;
}
} }
} }
@ -592,7 +606,8 @@ void CreateOAForDomainExecuteCB(napi_env env, void *data)
CreateOAForDomainAsyncContext *asyncContext = reinterpret_cast<CreateOAForDomainAsyncContext *>(data); CreateOAForDomainAsyncContext *asyncContext = reinterpret_cast<CreateOAForDomainAsyncContext *>(data);
auto callback = std::make_shared<NapiCreateDomainCallback>(env, asyncContext->callbackRef, asyncContext->deferred); auto callback = std::make_shared<NapiCreateDomainCallback>(env, asyncContext->callbackRef, asyncContext->deferred);
asyncContext->errCode = asyncContext->errCode =
OsAccountManager::CreateOsAccountForDomain(asyncContext->type, asyncContext->domainInfo, callback); OsAccountManager::CreateOsAccountForDomain(asyncContext->type, asyncContext->domainInfo,
callback, asyncContext->domainOptions);
if (asyncContext->errCode != ERR_OK) { if (asyncContext->errCode != ERR_OK) {
Parcel emptyParcel; Parcel emptyParcel;
callback->OnResult(asyncContext->errCode, emptyParcel); callback->OnResult(asyncContext->errCode, emptyParcel);

View File

@ -35,7 +35,7 @@ public:
virtual ErrCode CreateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo) = 0; virtual ErrCode CreateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo) = 0;
virtual ErrCode UpdateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo) = 0; virtual ErrCode UpdateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo) = 0;
virtual ErrCode CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo, virtual ErrCode CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo,
const sptr<IDomainAccountCallback> &callback) = 0; const sptr<IDomainAccountCallback> &callback, const CreateOsAccountForDomainOptions &options = {}) = 0;
virtual ErrCode RemoveOsAccount(const int id) = 0; virtual ErrCode RemoveOsAccount(const int id) = 0;
virtual ErrCode IsOsAccountExists(const int id, bool &isOsAccountExits) = 0; virtual ErrCode IsOsAccountExists(const int id, bool &isOsAccountExits) = 0;
virtual ErrCode IsOsAccountActived(const int id, bool &isOsAccountActived) = 0; virtual ErrCode IsOsAccountActived(const int id, bool &isOsAccountActived) = 0;

View File

@ -40,7 +40,7 @@ public:
ErrCode CreateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo) override; ErrCode CreateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo) override;
ErrCode UpdateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo) override; ErrCode UpdateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo) override;
ErrCode CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo, ErrCode CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo,
const sptr<IDomainAccountCallback> &callback) override; const sptr<IDomainAccountCallback> &callback, const CreateOsAccountForDomainOptions &options = {}) override;
ErrCode RemoveOsAccount(const int id) override; ErrCode RemoveOsAccount(const int id) override;
ErrCode IsOsAccountExists(const int id, bool &isOsAccountExits) override; ErrCode IsOsAccountExists(const int id, bool &isOsAccountExits) override;
ErrCode IsOsAccountActived(const int id, bool &isOsAccountActived) override; ErrCode IsOsAccountActived(const int id, bool &isOsAccountActived) override;
@ -108,7 +108,7 @@ public:
ErrCode GetBackgroundOsAccountLocalIds(std::vector<int32_t> &localIds) override; ErrCode GetBackgroundOsAccountLocalIds(std::vector<int32_t> &localIds) override;
ErrCode SetOsAccountToBeRemoved(int32_t localId, bool toBeRemoved) override; ErrCode SetOsAccountToBeRemoved(int32_t localId, bool toBeRemoved) override;
ErrCode BindDomainAccount(const OsAccountType &type, const DomainAccountInfo &domainAccountInfo, ErrCode BindDomainAccount(const OsAccountType &type, const DomainAccountInfo &domainAccountInfo,
const sptr<IDomainAccountCallback> &callback); const sptr<IDomainAccountCallback> &callback, const CreateOsAccountForDomainOptions &options = {});
ErrCode SendMsgForAccountCreate(OsAccountInfo &osAccountInfo, const CreateOsAccountOptions &options = {}); ErrCode SendMsgForAccountCreate(OsAccountInfo &osAccountInfo, const CreateOsAccountOptions &options = {});
ErrCode GetOsAccountInfoById(const int id, OsAccountInfo &osAccountInfo); ErrCode GetOsAccountInfoById(const int id, OsAccountInfo &osAccountInfo);
ErrCode UpdateAccountStatusForDomain(const int id, DomainAccountStatus status); ErrCode UpdateAccountStatusForDomain(const int id, DomainAccountStatus status);

View File

@ -28,12 +28,13 @@ namespace AccountSA {
class CheckAndCreateDomainAccountCallback final : public DomainAccountCallbackStub { class CheckAndCreateDomainAccountCallback final : public DomainAccountCallbackStub {
public: public:
CheckAndCreateDomainAccountCallback(const OsAccountType &type, const DomainAccountInfo &domainAccountInfo_, CheckAndCreateDomainAccountCallback(const OsAccountType &type, const DomainAccountInfo &domainAccountInfo_,
const sptr<IDomainAccountCallback> &callback); const sptr<IDomainAccountCallback> &callback, const CreateOsAccountForDomainOptions &accountOptions);
void OnResult(const int32_t errCode, Parcel &parcel) override; void OnResult(const int32_t errCode, Parcel &parcel) override;
private: private:
OsAccountType type_; OsAccountType type_;
DomainAccountInfo domainAccountInfo_; DomainAccountInfo domainAccountInfo_;
CreateOsAccountForDomainOptions accountOptions_;
sptr<IDomainAccountCallback> innerCallback_ = nullptr; sptr<IDomainAccountCallback> innerCallback_ = nullptr;
}; };

View File

@ -36,7 +36,7 @@ public:
ErrCode CreateOsAccount(const std::string &localName, const std::string &shortName, ErrCode CreateOsAccount(const std::string &localName, const std::string &shortName,
const OsAccountType &type, OsAccountInfo &osAccountInfo, const CreateOsAccountOptions &options = {}) override; const OsAccountType &type, OsAccountInfo &osAccountInfo, const CreateOsAccountOptions &options = {}) override;
ErrCode CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo, ErrCode CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo,
const sptr<IDomainAccountCallback> &callback) override; const sptr<IDomainAccountCallback> &callback, const CreateOsAccountForDomainOptions &options = {}) override;
ErrCode CreateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo) override; ErrCode CreateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo) override;
ErrCode UpdateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo) override; ErrCode UpdateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo) override;

View File

@ -540,7 +540,7 @@ bool IInnerOsAccountManager::CheckDomainAccountBound(
} }
ErrCode IInnerOsAccountManager::BindDomainAccount(const OsAccountType &type, const DomainAccountInfo &domainAccountInfo, ErrCode IInnerOsAccountManager::BindDomainAccount(const OsAccountType &type, const DomainAccountInfo &domainAccountInfo,
const sptr<IDomainAccountCallback> &callback) const sptr<IDomainAccountCallback> &callback, const CreateOsAccountForDomainOptions &options)
{ {
std::vector<OsAccountInfo> osAccountInfos; std::vector<OsAccountInfo> osAccountInfos;
(void)QueryAllCreatedOsAccounts(osAccountInfos); (void)QueryAllCreatedOsAccounts(osAccountInfos);
@ -567,7 +567,7 @@ ErrCode IInnerOsAccountManager::BindDomainAccount(const OsAccountType &type, con
} }
if (osAccountInfo.GetLocalId() != Constants::START_USER_ID) { if (osAccountInfo.GetLocalId() != Constants::START_USER_ID) {
#ifdef ENABLE_MULTIPLE_OS_ACCOUNTS #ifdef ENABLE_MULTIPLE_OS_ACCOUNTS
ErrCode errCode = PrepareOsAccountInfo(osAccountName, domainAccountInfo.accountName_, ErrCode errCode = PrepareOsAccountInfo(osAccountName, options.shortName,
type, domainAccountInfo, osAccountInfo); type, domainAccountInfo, osAccountInfo);
if (errCode != ERR_OK) { if (errCode != ERR_OK) {
return errCode; return errCode;
@ -588,7 +588,8 @@ ErrCode IInnerOsAccountManager::BindDomainAccount(const OsAccountType &type, con
} }
ErrCode IInnerOsAccountManager::CreateOsAccountForDomain( ErrCode IInnerOsAccountManager::CreateOsAccountForDomain(
const OsAccountType &type, const DomainAccountInfo &domainInfo, const sptr<IDomainAccountCallback> &callback) const OsAccountType &type, const DomainAccountInfo &domainInfo, const sptr<IDomainAccountCallback> &callback,
const CreateOsAccountForDomainOptions &options)
{ {
if (!pluginManager_.IsCreationAllowed()) { if (!pluginManager_.IsCreationAllowed()) {
ACCOUNT_LOGI("Not allow creation account."); ACCOUNT_LOGI("Not allow creation account.");
@ -609,7 +610,7 @@ ErrCode IInnerOsAccountManager::CreateOsAccountForDomain(
return ERR_DOMAIN_ACCOUNT_SERVICE_PLUGIN_NOT_EXIST; return ERR_DOMAIN_ACCOUNT_SERVICE_PLUGIN_NOT_EXIST;
} }
sptr<CheckAndCreateDomainAccountCallback> callbackWrapper = sptr<CheckAndCreateDomainAccountCallback> callbackWrapper =
new (std::nothrow) CheckAndCreateDomainAccountCallback(type, domainInfo, callback); new (std::nothrow) CheckAndCreateDomainAccountCallback(type, domainInfo, callback, options);
if (callbackWrapper == nullptr) { if (callbackWrapper == nullptr) {
ACCOUNT_LOGE("new DomainCreateDomainCallback failed"); ACCOUNT_LOGE("new DomainCreateDomainCallback failed");
return ERR_ACCOUNT_COMMON_INSUFFICIENT_MEMORY_ERROR; return ERR_ACCOUNT_COMMON_INSUFFICIENT_MEMORY_ERROR;

View File

@ -29,8 +29,9 @@
namespace OHOS { namespace OHOS {
namespace AccountSA { namespace AccountSA {
CheckAndCreateDomainAccountCallback::CheckAndCreateDomainAccountCallback( CheckAndCreateDomainAccountCallback::CheckAndCreateDomainAccountCallback(
const OsAccountType &type, const DomainAccountInfo &domainAccountInfo, const sptr<IDomainAccountCallback> &callback) const OsAccountType &type, const DomainAccountInfo &domainAccountInfo,
: type_(type), domainAccountInfo_(domainAccountInfo), innerCallback_(callback) const sptr<IDomainAccountCallback> &callback, const CreateOsAccountForDomainOptions &accountOptions)
: type_(type), domainAccountInfo_(domainAccountInfo), accountOptions_(accountOptions), innerCallback_(callback)
{} {}
void CheckAndCreateDomainAccountCallback::OnResult(int32_t errCode, Parcel &parcel) void CheckAndCreateDomainAccountCallback::OnResult(int32_t errCode, Parcel &parcel)
@ -60,7 +61,8 @@ void CheckAndCreateDomainAccountCallback::OnResult(int32_t errCode, Parcel &parc
ACCOUNT_LOGE("domain account not found"); ACCOUNT_LOGE("domain account not found");
return innerCallback_->OnResult(ERR_JS_ACCOUNT_NOT_FOUND, resultParcel); return innerCallback_->OnResult(ERR_JS_ACCOUNT_NOT_FOUND, resultParcel);
} }
errCode = IInnerOsAccountManager::GetInstance().BindDomainAccount(type_, domainAccountInfo, innerCallback_); errCode = IInnerOsAccountManager::GetInstance().BindDomainAccount(type_, domainAccountInfo,
innerCallback_, accountOptions_);
if (errCode != ERR_OK) { if (errCode != ERR_OK) {
return innerCallback_->OnResult(errCode, resultParcel); return innerCallback_->OnResult(errCode, resultParcel);
} }

View File

@ -209,7 +209,8 @@ ErrCode OsAccountManagerService::UpdateOsAccountWithFullInfo(OsAccountInfo &osAc
} }
ErrCode OsAccountManagerService::CreateOsAccountForDomain(const OsAccountType &type, ErrCode OsAccountManagerService::CreateOsAccountForDomain(const OsAccountType &type,
const DomainAccountInfo &domainInfo, const sptr<IDomainAccountCallback> &callback) const DomainAccountInfo &domainInfo, const sptr<IDomainAccountCallback> &callback,
const CreateOsAccountForDomainOptions &options)
{ {
ACCOUNT_LOGI("start"); ACCOUNT_LOGI("start");
// permission check // permission check
@ -224,22 +225,35 @@ ErrCode OsAccountManagerService::CreateOsAccountForDomain(const OsAccountType &t
return ERR_ACCOUNT_COMMON_INVALID_PARAMETER; return ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
} }
if (domainInfo.accountName_.empty() || domainInfo.domain_.empty()) { if (domainInfo.accountName_.empty() || domainInfo.domain_.empty()) {
ACCOUNT_LOGE("Domain account name is empty or domain is empty");
return ERR_ACCOUNT_COMMON_INVALID_PARAMETER; return ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
} }
if (domainInfo.accountName_.size() > Constants::DOMAIN_ACCOUNT_NAME_MAX_SIZE || if (domainInfo.accountName_.size() > Constants::DOMAIN_ACCOUNT_NAME_MAX_SIZE ||
domainInfo.domain_.size() > Constants::DOMAIN_NAME_MAX_SIZE) { domainInfo.domain_.size() > Constants::DOMAIN_NAME_MAX_SIZE) {
ACCOUNT_LOGE("Domain account name is overlength or domain is overlength");
return ERR_ACCOUNT_COMMON_INVALID_PARAMETER; return ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
} }
if (options.hasShortName || (options.shortName != "")) {
ErrCode code = innerManager_.ValidateShortName(options.shortName);
if (code != ERR_OK) {
ACCOUNT_LOGE("Failed to create os account for domain, shortName=%{public}s is invalid!",
options.shortName.c_str());
return code;
}
}
bool isAllowedCreateAdmin = false; bool isAllowedCreateAdmin = false;
ErrCode errCode = innerManager_.IsAllowedCreateAdmin(isAllowedCreateAdmin); ErrCode errCode = innerManager_.IsAllowedCreateAdmin(isAllowedCreateAdmin);
if (errCode != ERR_OK) { if (errCode != ERR_OK) {
ACCOUNT_LOGE("Failed to get allowed create admin permission, code=%{public}d.", errCode);
return errCode; return errCode;
} }
if (!isAllowedCreateAdmin && type == OsAccountType::ADMIN) { if (!isAllowedCreateAdmin && type == OsAccountType::ADMIN) {
ACCOUNT_LOGE("Do not allowed create admin.");
return ERR_OSACCOUNT_SERVICE_MANAGER_CREATE_OSACCOUNT_TYPE_ERROR; return ERR_OSACCOUNT_SERVICE_MANAGER_CREATE_OSACCOUNT_TYPE_ERROR;
} }
return innerManager_.CreateOsAccountForDomain(type, domainInfo, callback); return innerManager_.CreateOsAccountForDomain(type, domainInfo, callback, options);
} }
ErrCode OsAccountManagerService::RemoveOsAccount(const int id) ErrCode OsAccountManagerService::RemoveOsAccount(const int id)

View File

@ -622,7 +622,13 @@ ErrCode OsAccountStub::ProcCreateOsAccountForDomain(MessageParcel &data, Message
ACCOUNT_LOGE("failed to read parcel"); ACCOUNT_LOGE("failed to read parcel");
return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR; return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
} }
ErrCode result = CreateOsAccountForDomain(type, *info, callback);
sptr<CreateOsAccountForDomainOptions> options = data.ReadParcelable<CreateOsAccountForDomainOptions>();
if (options == nullptr) {
ACCOUNT_LOGE("Read options failed");
return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
}
ErrCode result = CreateOsAccountForDomain(type, *info, callback, *options);
return WriteResultWithOsAccountInfo(reply, result, osAccountInfo); return WriteResultWithOsAccountInfo(reply, result, osAccountInfo);
} }

View File

@ -66,7 +66,9 @@ void DomainAccountCallbackTest::TearDown(void)
HWTEST_F(DomainAccountCallbackTest, DomainAccountCallbackTest_OnResult_001, TestSize.Level0) HWTEST_F(DomainAccountCallbackTest, DomainAccountCallbackTest_OnResult_001, TestSize.Level0)
{ {
DomainAccountInfo info; DomainAccountInfo info;
auto callbackPtr = std::make_shared<CheckAndCreateDomainAccountCallback>(OsAccountType::NORMAL, info, nullptr); CreateOsAccountForDomainOptions accountOptions;
auto callbackPtr = std::make_shared<CheckAndCreateDomainAccountCallback>(OsAccountType::NORMAL,
info, nullptr, accountOptions);
Parcel parcel; Parcel parcel;
callbackPtr->OnResult(0, parcel); callbackPtr->OnResult(0, parcel);
EXPECT_EQ(callbackPtr->innerCallback_, nullptr); EXPECT_EQ(callbackPtr->innerCallback_, nullptr);