support max logged in OS account num and default activated OS account

Signed-off-by: jidong <jidong4@huawei.com>
Change-Id: I5653b6fd57bf80df9b245b2de6917c1a2a414ef5
This commit is contained in:
jidong 2024-04-19 12:08:52 +08:00
parent 756861547c
commit 7d6951a7e6
50 changed files with 625 additions and 186 deletions

View File

@ -27,7 +27,8 @@
"os_account_file_encryption_el1_feature",
"os_account_enable_multiple_os_accounts",
"os_account_enable_default_admin_name",
"os_account_enable_account_short_name"
"os_account_enable_account_short_name",
"os_account_activate_last_logged_in_account"
],
"hisysevent_config": [
"//base/account/os_account/hisysevent.yaml"
@ -70,7 +71,8 @@
"mbedtls",
"json",
"theme_mgr",
"benchmark"
"benchmark",
"config_policy"
],
"third_party": [
"mbedtls",

View File

@ -96,6 +96,8 @@ int32_t OsAccountConvertToJSErrCode(int32_t errCode)
return ERR_JS_ACCOUNT_ALREADY_ACTIVATED;
case ERR_OSACCOUNT_SERVICE_CONTROL_MAX_CAN_CREATE_ERROR:
return ERR_JS_ACCOUNT_NUMBER_REACH_LIMIT;
case ERR_OSACCOUNT_SERVICE_LOGGED_IN_ACCOUNTS_OVERSIZE:
return ERR_JS_ACCOUNT_LOGGED_IN_ACCOUNTS_OVERSIZE;
case ERR_OSACCOUNT_SERVICE_MANAGER_NOT_ENABLE_MULTI_ERROR:
return ERR_JS_MULTI_USER_NOT_SUPPORT;
case ERR_OSACCOUNT_SERVICE_MANAGER_CREATE_OSACCOUNT_TYPE_ERROR:

View File

@ -98,7 +98,8 @@ enum class OsAccountInterfaceCode : uint32_t {
GET_FOREGROUND_OS_ACCOUNT_LOCAL_ID,
GET_FOREGROUND_OS_ACCOUNTS,
GET_BACKGROUND_OS_ACCOUNT_LOCAL_IDS,
SET_OS_ACCOUNT_TO_BE_REMOVED
SET_OS_ACCOUNT_TO_BE_REMOVED,
QUERY_MAX_LOGGED_IN_OS_ACCOUNT_NUMBER
};
enum class AppAccountInterfaceCode : uint32_t {

View File

@ -157,6 +157,7 @@ ohos_moduletest("domain_account_frameworks_module_mock_test") {
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"config_policy:configpolicy_util",
"hilog:libhilog",
"huks:libhukssdk",
"init:libbegetutil",
@ -240,6 +241,7 @@ ohos_moduletest("domain_account_client_mock_plugin_so_module_test") {
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"config_policy:configpolicy_util",
"hilog:libhilog",
"huks:libhukssdk",
"init:libbegetutil",

View File

@ -145,6 +145,7 @@ ohos_moduletest("AccountInnerSdkModuleMockTest") {
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"config_policy:configpolicy_util",
"hilog:libhilog",
"huks:libhukssdk",
"init:libbegetutil",

View File

@ -52,7 +52,8 @@ public:
virtual ErrCode GetOsAccountLocalIdFromProcess(int &id) = 0;
virtual ErrCode IsMainOsAccount(bool &isMainOsAccount) = 0;
virtual ErrCode GetOsAccountLocalIdFromDomain(const DomainAccountInfo &domainInfo, int &id) = 0;
virtual ErrCode QueryMaxOsAccountNumber(int &maxOsAccountNumber) = 0;
virtual ErrCode QueryMaxOsAccountNumber(uint32_t &maxOsAccountNumber) = 0;
virtual ErrCode QueryMaxLoggedInOsAccountNumber(uint32_t &maxNum) = 0;
virtual ErrCode GetOsAccountAllConstraints(const int id, std::vector<std::string> &constraints) = 0;
virtual ErrCode QueryAllCreatedOsAccounts(std::vector<OsAccountInfo> &osAccountInfos) = 0;
virtual ErrCode QueryCurrentOsAccount(OsAccountInfo &osAccountInfo) = 0;

View File

@ -43,7 +43,8 @@ public:
ErrCode GetOsAccountLocalIdFromProcess(int &id);
ErrCode IsMainOsAccount(bool &isMainOsAccount);
ErrCode GetOsAccountLocalIdFromDomain(const DomainAccountInfo &domainInfo, int &id);
ErrCode QueryMaxOsAccountNumber(int &maxOsAccountNumber);
ErrCode QueryMaxOsAccountNumber(uint32_t &maxOsAccountNumber);
ErrCode QueryMaxLoggedInOsAccountNumber(uint32_t &maxNum);
ErrCode GetOsAccountAllConstraints(const int id, std::vector<std::string> &constraints);
ErrCode QueryAllCreatedOsAccounts(std::vector<OsAccountInfo> &osAccountInfos);
ErrCode QueryCurrentOsAccount(OsAccountInfo &osAccountInfo);

View File

@ -46,7 +46,8 @@ public:
ErrCode GetOsAccountLocalIdFromProcess(int &id) override;
ErrCode IsMainOsAccount(bool &isMainOsAccount) override;
ErrCode GetOsAccountLocalIdFromDomain(const DomainAccountInfo &domainInfo, int &id) override;
ErrCode QueryMaxOsAccountNumber(int &maxOsAccountNumber) override;
ErrCode QueryMaxOsAccountNumber(uint32_t &maxOsAccountNumber) override;
ErrCode QueryMaxLoggedInOsAccountNumber(uint32_t &maxNum) override;
ErrCode GetOsAccountAllConstraints(const int id, std::vector<std::string> &constraints) override;
ErrCode QueryAllCreatedOsAccounts(std::vector<OsAccountInfo> &osAccountInfos) override;
ErrCode QueryCurrentOsAccount(OsAccountInfo &osAccountInfo) override;

View File

@ -281,7 +281,7 @@ ErrCode OsAccount::GetOsAccountLocalIdFromDomain(const DomainAccountInfo &domain
return proxy->GetOsAccountLocalIdFromDomain(domainInfo, id);
}
ErrCode OsAccount::QueryMaxOsAccountNumber(int &maxOsAccountNumber)
ErrCode OsAccount::QueryMaxOsAccountNumber(uint32_t &maxOsAccountNumber)
{
auto proxy = GetOsAccountProxy();
if (proxy == nullptr) {
@ -291,6 +291,16 @@ ErrCode OsAccount::QueryMaxOsAccountNumber(int &maxOsAccountNumber)
return proxy->QueryMaxOsAccountNumber(maxOsAccountNumber);
}
ErrCode OsAccount::QueryMaxLoggedInOsAccountNumber(uint32_t &maxNum)
{
auto proxy = GetOsAccountProxy();
if (proxy == nullptr) {
return ERR_ACCOUNT_COMMON_GET_PROXY;
}
return proxy->QueryMaxLoggedInOsAccountNumber(maxNum);
}
ErrCode OsAccount::GetOsAccountAllConstraints(const int id, std::vector<std::string> &constraints)
{
ErrCode result = CheckInvalidLocalId(id);

View File

@ -409,7 +409,7 @@ ErrCode OsAccountProxy::GetOsAccountLocalIdFromDomain(const DomainAccountInfo &d
return ERR_OK;
}
ErrCode OsAccountProxy::QueryMaxOsAccountNumber(int &maxOsAccountNumber)
ErrCode OsAccountProxy::QueryMaxOsAccountNumber(uint32_t &maxOsAccountNumber)
{
MessageParcel data;
MessageParcel reply;
@ -434,6 +434,34 @@ ErrCode OsAccountProxy::QueryMaxOsAccountNumber(int &maxOsAccountNumber)
return ERR_OK;
}
ErrCode OsAccountProxy::QueryMaxLoggedInOsAccountNumber(uint32_t &maxNum)
{
MessageParcel data;
if (!data.WriteInterfaceToken(GetDescriptor())) {
ACCOUNT_LOGE("Failed to write descriptor!");
return ERR_ACCOUNT_COMMON_WRITE_DESCRIPTOR_ERROR;
}
MessageParcel reply;
ErrCode result = SendRequest(OsAccountInterfaceCode::QUERY_MAX_LOGGED_IN_OS_ACCOUNT_NUMBER, data, reply);
if (result != ERR_OK) {
ACCOUNT_LOGE("SendRequest err, result %{public}d.", result);
return result;
}
if (!reply.ReadInt32(result)) {
ACCOUNT_LOGE("Failed to read errCode");
return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
}
if (result != ERR_OK) {
return result;
}
if (!reply.ReadUint32(maxNum)) {
ACCOUNT_LOGE("Failed to read maxNum");
return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
}
return ERR_OK;
}
ErrCode OsAccountProxy::GetOsAccountAllConstraints(const int id, std::vector<std::string> &constraints)
{
MessageParcel reply;

View File

@ -120,7 +120,8 @@
"OHOS::AccountSA::OsAccountManager::GetBundleIdFromUid(int, int&)";
"OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromDomain(OHOS::AccountSA::DomainAccountInfo const&, int&)";
"OHOS::AccountSA::OsAccountManager::SetOsAccountProfilePhoto(int, std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&)";
"OHOS::AccountSA::OsAccountManager::QueryMaxOsAccountNumber(int&)";
"OHOS::AccountSA::OsAccountManager::QueryMaxOsAccountNumber(unsigned int&)";
"OHOS::AccountSA::OsAccountManager::QueryMaxLoggedInOsAccountNumber(unsigned int&)";
"OHOS::AccountSA::OsAccountManager::CheckOsAccountConstraintEnabled(int, std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, bool&)";
"OHOS::AccountSA::OsAccountManager::IsOsAccountConstraintEnable(int, std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, bool&)";
"OHOS::AccountSA::OsAccountManager::GetOsAccountTypeFromProcess(OHOS::AccountSA::OsAccountType&)";
@ -197,6 +198,8 @@
"OHOS::AccountSA::OsAccountInfo::SetSerialNumber(long)";
"OHOS::AccountSA::OsAccountInfo::SetIsForeground(bool)";
"OHOS::AccountSA::OsAccountInfo::GetIsForeground() const";
"OHOS::AccountSA::OsAccountInfo::SetIsLoggedIn(bool)";
"OHOS::AccountSA::OsAccountInfo::GetIsLoggedIn() const";
*OHOS::AccountSA::OsAccountInfo::SetDisplayId*;
*OHOS::AccountSA::OsAccountInfo::GetDisplayId*;
"OHOS::AccountSA::OsAccountInfo::OsAccountInfo(int, std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>>, OHOS::AccountSA::OsAccountType, long long)";

View File

@ -42,6 +42,7 @@ const std::string TO_BE_REMOVED = "toBeRemoved";
const std::string CREDENTIAL_ID = "credentialId";
const std::string DISPLAY_ID = "displayId";
const std::string IS_FOREGROUND = "isForeground";
const std::string IS_LOGGED_IN = "isLoggedIn";
const std::string DOMAIN_ACCOUNT_STATUS = "domainAccountStatus";
const std::string DOMAIN_ACCOUNT_CONFIG = "domainServerConfigId";
} // namespace
@ -158,6 +159,16 @@ void OsAccountInfo::SetIsForeground(bool isForeground)
isForeground_ = isForeground;
}
bool OsAccountInfo::GetIsLoggedIn() const
{
return isLoggedIn_;
}
void OsAccountInfo::SetIsLoggedIn(bool isLoggedIn)
{
isLoggedIn_ = isLoggedIn;
}
bool OsAccountInfo::SetDomainInfo(const DomainAccountInfo &domainInfo)
{
if (domainInfo.accountName_.size() > Constants::DOMAIN_ACCOUNT_NAME_MAX_SIZE) {
@ -236,6 +247,7 @@ Json OsAccountInfo::ToJson() const
{CREDENTIAL_ID, credentialId_},
{DISPLAY_ID, displayId_},
{IS_FOREGROUND, isForeground_},
{IS_LOGGED_IN, isLoggedIn_},
{DOMAIN_INFO, {
{DOMAIN_NAME, domainInfo_.domain_},
{DOMAIN_ACCOUNT_NAME, domainInfo_.accountName_},
@ -315,6 +327,8 @@ void OsAccountInfo::FromJson(const Json &jsonObject)
jsonObject, jsonObjectEnd, DISPLAY_ID, displayId_, OHOS::AccountSA::JsonType::NUMBER);
OHOS::AccountSA::GetDataByType<bool>(
jsonObject, jsonObjectEnd, IS_FOREGROUND, isForeground_, OHOS::AccountSA::JsonType::BOOLEAN);
OHOS::AccountSA::GetDataByType<bool>(
jsonObject, jsonObjectEnd, IS_LOGGED_IN, isLoggedIn_, OHOS::AccountSA::JsonType::BOOLEAN);
GetDomainInfoFromJson(jsonObject);
}

View File

@ -132,11 +132,16 @@ ErrCode OsAccountManager::GetOsAccountLocalIdFromDomain(const DomainAccountInfo
return OsAccount::GetInstance().GetOsAccountLocalIdFromDomain(domainInfo, id);
}
ErrCode OsAccountManager::QueryMaxOsAccountNumber(int &maxOsAccountNumber)
ErrCode OsAccountManager::QueryMaxOsAccountNumber(uint32_t &maxOsAccountNumber)
{
return OsAccount::GetInstance().QueryMaxOsAccountNumber(maxOsAccountNumber);
}
ErrCode OsAccountManager::QueryMaxLoggedInOsAccountNumber(uint32_t &maxNum)
{
return OsAccount::GetInstance().QueryMaxLoggedInOsAccountNumber(maxNum);
}
ErrCode OsAccountManager::GetOsAccountAllConstraints(const int id, std::vector<std::string> &constraints)
{
return OsAccount::GetInstance().GetOsAccountAllConstraints(id, constraints);

View File

@ -249,7 +249,7 @@ BENCHMARK_F(OsAccountManagerBenchmarkTest, OsAccountManagerTestCase0010)(
{
GTEST_LOG_(INFO) << "OsAccountManagerBenchmarkTest OsAccountManagerTestCase0010 start!";
for (auto _ : st) {
int maxOsAccountNumber = 0;
uint32_t maxOsAccountNumber = 0;
EXPECT_EQ(OsAccountManager::QueryMaxOsAccountNumber(maxOsAccountNumber), ERR_OK);
}
}

View File

@ -158,6 +158,7 @@ ohos_moduletest("os_account_frameworks_module_mock_test") {
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"config_policy:configpolicy_util",
"hilog:libhilog",
"huks:libhukssdk",
"init:libbegetutil",
@ -251,6 +252,7 @@ ohos_moduletest("os_account_manager_no_bms_mock_test") {
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"config_policy:configpolicy_util",
"hilog:libhilog",
"huks:libhukssdk",
"init:libbegetutil",

View File

@ -749,10 +749,22 @@ HWTEST_F(OsAccountManagerModuleTest, OsAccountManagerModuleTest024, TestSize.Lev
*/
HWTEST_F(OsAccountManagerModuleTest, OsAccountManagerModuleTest025, TestSize.Level1)
{
int maxOsAccountNumber = 0;
uint32_t maxOsAccountNumber = 0;
EXPECT_EQ(OsAccountManager::QueryMaxOsAccountNumber(maxOsAccountNumber), ERR_OK);
}
/**
* @tc.name: QueryMaxLoggedInOsAccountNumberModuleTest001
* @tc.desc: Test QueryMaxLoggedInOsAccountNumber.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(OsAccountManagerModuleTest, QueryMaxLoggedInOsAccountNumberModuleTest001, TestSize.Level1)
{
uint32_t maxNum = 0;
EXPECT_EQ(OsAccountManager::QueryMaxLoggedInOsAccountNumber(maxNum), ERR_OK);
}
/**
* @tc.name: OsAccountManagerModuleTest026
* @tc.desc: Test GetOsAccountAllConstraints with exisit os account id.

View File

@ -204,10 +204,11 @@ enum {
ERR_OSACCOUNT_SERVICE_CONTROL_INSERT_FILE_EXISTS_ERROR,
ERR_OSACCOUNT_SERVICE_CONTROL_UPDATE_FILE_NOT_EXISTS_ERROR,
ERR_OSACCOUNT_SERVICE_CONTROL_MAX_CAN_CREATE_ERROR,
ERR_OSACCOUNT_SERVICE_LOGGED_IN_ACCOUNTS_OVERSIZE,
ERR_OSACCOUNT_SERVICE_CONTROL_SELECT_CAN_USE_ID_ERROR,
ERR_OSACCOUNT_SERVICE_CONTROL_ID_CANNOT_CREATE_ERROR,
ERR_OSACCOUNT_SERVICE_CONTROL_CANNOT_DELETE_ID_ERROR,
// 4653130
// 4653131
ERR_OSACCOUNT_SERVICE_FILE_DELE_ERROR,
ERR_OSACCOUNT_SERVICE_FILE_FIND_FILE_ERROR,
ERR_OSACCOUNT_SERVICE_FILE_CREATE_DIR_ERROR,
@ -215,7 +216,7 @@ enum {
ERR_OSACCOUNT_SERVICE_DATA_STORAGE_KEY_NOT_EXISTS_ERROR,
ERR_OSACCOUNT_SERVICE_DATA_STORAGE_KEY_EXISTED_ERROR,
ERR_OSACCOUNT_SERVICE_ACCOUNT_INFO_EMPTY_ERROR,
// 4653141
// 4653142
ERR_OSACCOUNT_SERVICE_INTERFACE_TO_AM_ACCOUNT_START_ERROR,
ERR_OSACCOUNT_SERVICE_INTERFACE_TO_BM_ACCOUNT_CREATE_ERROR,
ERR_OSACCOUNT_SERVICE_INTERFACE_TO_BM_ACCOUNT_DELETE_ERROR,
@ -278,6 +279,7 @@ enum JSErrorCode {
ERR_JS_PLUGIN_NETWORK_EXCEPTION = 12300013,
ERR_JS_ACCOUNT_NOT_AUTHENTICATED = 12300014,
ERR_JS_ACCOUNT_SHORT_NAME_ALREADY_EXIST = 12300015,
ERR_JS_ACCOUNT_LOGGED_IN_ACCOUNTS_OVERSIZE = 12300016,
ERR_JS_AUTH_CREDENTIAL_WRONG_ERROR = 12300101,
ERR_JS_CREDENTIAL_NOT_EXIST = 12300102,

View File

@ -147,6 +147,10 @@ public:
void SetIsForeground(const bool isForeground);
bool GetIsLoggedIn() const;
void SetIsLoggedIn(const bool isLoggedIn);
ErrCode ParamCheck();
bool IsTypeOutOfRange() const;
@ -169,6 +173,7 @@ private:
DomainAccountInfo domainInfo_;
uint64_t displayId_ = -1;
bool isForeground_ = false;
bool isLoggedIn_ = false;
};
typedef enum {

View File

@ -215,7 +215,14 @@ public:
* @param maxOsAccountNumber - Returns the maximum number of OS accounts that can be created.
* @return error code, see account_error_no.h
*/
static ErrCode QueryMaxOsAccountNumber(int &maxOsAccountNumber);
static ErrCode QueryMaxOsAccountNumber(uint32_t &maxOsAccountNumber);
/**
* @brief Queries the maximum number of OS accounts that can be logged in.
* @param maxNum - Returns the maximum number of OS accounts that can be created.
* @return error code, see account_error_no.h
*/
static ErrCode QueryMaxLoggedInOsAccountNumber(uint32_t &maxNum);
/**
* @brief Gets all constraints of an account based on its ID.

View File

@ -68,6 +68,7 @@ static const std::unordered_map<uint32_t, std::string> g_errorStringMap = {
{ERR_JS_PERMISSION_DENIED, "Permission denied"},
{ERR_JS_PLUGIN_NETWORK_EXCEPTION, "Network exception"},
{ERR_JS_CAPABILITY_NOT_SUPPORTED, "capability not supported"},
{ERR_JS_ACCOUNT_LOGGED_IN_ACCOUNTS_OVERSIZE, "The number of the logged in OS accounts reaches upper limit"}
};
napi_value GenerateBusinessError(napi_env env, int32_t jsErrCode, const std::string &jsErrMsg)

View File

@ -152,7 +152,8 @@ struct SetOAPhotoAsyncContext : public CommonAsyncContext {
};
struct QueryMaxNumAsyncContext : public CommonAsyncContext {
int maxOsAccountNumber = 0;
uint32_t maxOsAccountNumber = 0;
uint32_t maxLoggedInNumber = 0;
};
struct IsActivedAsyncContext : public CommonAsyncContext {
@ -308,6 +309,8 @@ napi_value SetOsAccountProfilePhoto(napi_env env, napi_callback_info cbInfo);
napi_value QueryMaxOsAccountNumber(napi_env env, napi_callback_info cbInfo);
napi_value QueryMaxLoggedInOsAccountNumber(napi_env env, napi_callback_info cbInfo);
napi_value QueryOsAccountConstraintSourceTypes(napi_env env, napi_callback_info cbInfo);
napi_value IsOsAccountActived(napi_env env, napi_callback_info cbInfo);

View File

@ -74,6 +74,7 @@ static napi_property_descriptor g_osAccountProperties[] = {
DECLARE_NAPI_FUNCTION("getOsAccountLocalIdForDomain", QueryOsAccountLocalIdFromDomain),
DECLARE_NAPI_FUNCTION("setOsAccountProfilePhoto", SetOsAccountProfilePhoto),
DECLARE_NAPI_FUNCTION("queryMaxOsAccountNumber", QueryMaxOsAccountNumber),
DECLARE_NAPI_FUNCTION("queryMaxLoggedInOsAccountNumber", QueryMaxLoggedInOsAccountNumber),
DECLARE_NAPI_FUNCTION("isOsAccountActived", IsOsAccountActived),
DECLARE_NAPI_FUNCTION("checkOsAccountActivated", CheckOsAccountActivated),
DECLARE_NAPI_FUNCTION("isOsAccountConstraintEnable", IsOsAccountConstraintEnable),
@ -1022,6 +1023,34 @@ napi_value QueryMaxOsAccountNumber(napi_env env, napi_callback_info cbInfo)
return result;
}
napi_value QueryMaxLoggedInOsAccountNumber(napi_env env, napi_callback_info cbInfo)
{
auto context = std::make_unique<QueryMaxNumAsyncContext>();
napi_value result = nullptr;
NAPI_CALL(env, napi_create_promise(env, &context->deferred, &result));
napi_value resource = nullptr;
NAPI_CALL(env, napi_create_string_utf8(env, "QueryMaxLoggedInOsAccountNumber", NAPI_AUTO_LENGTH, &resource));
NAPI_CALL(env, napi_create_async_work(env, nullptr, resource,
[](napi_env env, void *data) {
auto context = reinterpret_cast<QueryMaxNumAsyncContext *>(data);
context->errCode = OsAccountManager::QueryMaxLoggedInOsAccountNumber(context->maxLoggedInNumber);
}, [](napi_env env, napi_status status, void *data) {
auto context = reinterpret_cast<QueryMaxNumAsyncContext *>(data);
napi_value errJs = nullptr;
napi_value dataJs = nullptr;
if (context->errCode == napi_ok) {
napi_create_uint32(env, context->maxLoggedInNumber, &dataJs);
} else {
errJs = GenerateBusinessError(env, context->errCode);
}
ProcessCallbackOrPromise(env, context, errJs, dataJs);
delete context;
}, reinterpret_cast<void *>(context.get()), &context->work));
NAPI_CALL(env, napi_queue_async_work_with_qos(env, context->work, napi_qos_default));
context.release();
return result;
}
napi_value InnerIsOsAccountActived(napi_env env, napi_callback_info cbInfo, bool throwErr)
{
auto isActived = std::make_unique<IsActivedAsyncContext>();

View File

@ -236,6 +236,10 @@ void GetOACBInfoToJs(napi_env env, OsAccountInfo &info, napi_value &objOAInfo)
napi_set_named_property(env, objOAInfo, "isActived", isActivedToJs);
napi_set_named_property(env, objOAInfo, "isActivated", isActivedToJs);
napi_value isLoggedInToJs = nullptr;
napi_get_boolean(env, info.GetIsLoggedIn(), &isLoggedInToJs);
napi_set_named_property(env, objOAInfo, "isLoggedIn", isLoggedInToJs);
napi_value isCreateCompletedToJs = nullptr;
napi_get_boolean(env, info.GetIsCreateCompleted(), &isCreateCompletedToJs);
napi_set_named_property(env, objOAInfo, "isCreateCompleted", isCreateCompletedToJs);
@ -1277,7 +1281,7 @@ void QueryMaxNumCompletedCB(napi_env env, napi_status status, void *data)
napi_value dataJs = nullptr;
if (asyncContext->status == napi_ok) {
napi_get_null(env, &errJs);
napi_create_int32(env, asyncContext->maxOsAccountNumber, &dataJs);
napi_create_uint32(env, asyncContext->maxOsAccountNumber, &dataJs);
} else {
errJs = GenerateBusinessError(env, asyncContext->errCode, asyncContext->throwErr);
napi_get_null(env, &dataJs);

View File

@ -146,6 +146,10 @@ declare_args() {
os_account_enable_account_short_name = false
}
declare_args() {
os_account_activate_last_logged_in_account = false
}
if (!defined(global_parts_info) ||
defined(global_parts_info.hiviewdfx_hicollie)) {
hicollie_enable = true

View File

@ -28,6 +28,13 @@ ohos_prebuilt_etc("osaccount_constraint") {
part_name = "os_account"
}
ohos_prebuilt_etc("os_account_config") {
source = "os_account_config.json"
relative_install_dir = "account"
subsystem_name = "account"
part_name = "os_account"
}
ohos_prebuilt_etc("constraints_list_collection") {
source = "constraints_list_collection.json"
relative_install_dir = "account"
@ -193,6 +200,10 @@ ohos_shared_library("accountmgr") {
cflags += [ "-DENABLE_ACCOUNT_SHORT_NAME" ]
}
if (os_account_activate_last_logged_in_account) {
cflags += [ "-DACTIVATE_LAST_LOGGED_IN_ACCOUNT" ]
}
sources = [
"${common_path}/utils/src/account_permission_manager.cpp",
"${domain_account_framework_path}/src/domain_account_callback_proxy.cpp",
@ -246,6 +257,7 @@ ohos_shared_library("accountmgr") {
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"config_policy:configpolicy_util",
"hilog:libhilog",
"huks:libhukssdk",
"init:libbegetutil",
@ -355,6 +367,7 @@ group("accountmgr_target") {
":accountmgr",
":accountmgr.init",
":constraints_list_collection",
":os_account_config",
":osaccount_constraint",
]
}

View File

@ -43,7 +43,8 @@ public:
const int id, const std::string &constraint, bool &isOsAccountConstraintEnable) = 0;
virtual ErrCode IsOsAccountVerified(const int id, bool &isVerified) = 0;
virtual ErrCode GetCreatedOsAccountsCount(unsigned int &createdOsAccountCount) = 0;
virtual ErrCode QueryMaxOsAccountNumber(int &maxOsAccountNumber) = 0;
virtual ErrCode QueryMaxOsAccountNumber(uint32_t &maxOsAccountNumber) = 0;
virtual ErrCode QueryMaxLoggedInOsAccountNumber(uint32_t &maxNum) = 0;
virtual ErrCode GetOsAccountAllConstraints(const int id, std::vector<std::string> &constraints) = 0;
virtual ErrCode QueryAllCreatedOsAccounts(std::vector<OsAccountInfo> &osAccountInfos) = 0;
virtual ErrCode QueryOsAccountById(const int id, OsAccountInfo &osAccountInfo) = 0;
@ -70,6 +71,7 @@ public:
virtual OS_ACCOUNT_SWITCH_MOD GetOsAccountSwitchMod() = 0;
virtual ErrCode IsOsAccountCompleted(const int id, bool &isOsAccountCompleted) = 0;
virtual ErrCode SetOsAccountIsVerified(const int id, const bool isVerified) = 0;
virtual ErrCode SetOsAccountIsLoggedIn(const int32_t id, const bool isLoggedIn) = 0;
virtual ErrCode GetOsAccountCredentialId(const int id, uint64_t &credentialId) = 0;
virtual ErrCode SetOsAccountCredentialId(const int id, uint64_t credentialId) = 0;
virtual ErrCode IsAllowedCreateAdmin(bool &isAllowedCreateAdmin) = 0;

View File

@ -48,7 +48,8 @@ public:
const int id, const std::string &constraint, bool &isOsAccountConstraintEnable) override;
ErrCode IsOsAccountVerified(const int id, bool &isVerified) override;
ErrCode GetCreatedOsAccountsCount(unsigned int &createdOsAccountCount) override;
ErrCode QueryMaxOsAccountNumber(int &maxOsAccountNumber) override;
ErrCode QueryMaxOsAccountNumber(uint32_t &maxOsAccountNumber) override;
ErrCode QueryMaxLoggedInOsAccountNumber(uint32_t &maxNum) override;
ErrCode GetOsAccountAllConstraints(const int id, std::vector<std::string> &constraints) override;
ErrCode QueryAllCreatedOsAccounts(std::vector<OsAccountInfo> &osAccountInfos) override;
ErrCode QueryOsAccountById(const int id, OsAccountInfo &osAccountInfo) override;
@ -75,6 +76,7 @@ public:
OS_ACCOUNT_SWITCH_MOD GetOsAccountSwitchMod() override;
ErrCode IsOsAccountCompleted(const int id, bool &isOsAccountCompleted) override;
ErrCode SetOsAccountIsVerified(const int id, const bool isVerified) override;
ErrCode SetOsAccountIsLoggedIn(const int32_t id, const bool isLoggedIn) override;
ErrCode GetOsAccountCredentialId(const int id, uint64_t &credentialId) override;
ErrCode SetOsAccountCredentialId(const int id, uint64_t credentialId) override;
ErrCode IsAllowedCreateAdmin(bool &isAllowedCreateAdmin) override;
@ -156,7 +158,7 @@ private:
void RetryToGetAccount(OsAccountInfo &osAccountInfo);
bool JudgeOsAccountUpdate(Json &accountIndexJson);
ErrCode UpdateAccountToForeground(const uint64_t displayId, OsAccountInfo &osAccountInfo);
ErrCode UpdateAccountToBackground(OsAccountInfo &oldOsAccountInfo);
ErrCode UpdateAccountToBackground(int32_t oldId);
private:
std::shared_ptr<IOsAccountControl> osAccountControl_;
@ -165,10 +167,12 @@ private:
IOsAccountSubscribe &subscribeManager_;
std::int32_t deviceOwnerId_ = -1;
std::int32_t defaultActivatedId_ = -1;
OsAccountConfig config_;
mutable std::mutex ativeMutex_;
mutable std::mutex operatingMutex_;
SafeMap<uint64_t, int32_t> foregroundAccountMap_;
OsAccountPluginManager &pluginManager_;
SafeMap<int32_t, bool> loggedInAccounts_;
};
} // namespace AccountSA
} // namespace OHOS

View File

@ -19,17 +19,23 @@
#include <stdint.h>
namespace OHOS {
namespace AccountSA {
struct OsAccountConfig {
uint32_t maxOsAccountNum = 999;
uint32_t maxLoggedInOsAccountNum = 999;
};
class IOsAccountControl {
public:
virtual void Init() = 0;
virtual ErrCode GetOsAccountConfig(OsAccountConfig &config) = 0;
virtual ErrCode GetOsAccountList(std::vector<OsAccountInfo> &osAccountList) = 0;
virtual ErrCode GetOsAccountIdList(std::vector<int32_t> &idList) = 0;
virtual ErrCode GetOsAccountInfoById(const int id, OsAccountInfo &osAccountInfo) = 0;
virtual ErrCode GetConstraintsByType(const OsAccountType type, std::vector<std::string> &constraints) = 0;
virtual ErrCode InsertOsAccount(OsAccountInfo &osAccountInfo) = 0;
virtual ErrCode DelOsAccount(const int id) = 0;
virtual ErrCode UpdateOsAccount(OsAccountInfo &osAccountInfo) = 0;
virtual ErrCode GetAccountIndexFromFile(Json &accountIndexJson) = 0;
virtual ErrCode GetMaxCreatedOsAccountNum(int &maxCreatedOsAccountNum) = 0;
virtual ErrCode GetSerialNumber(int64_t &serialNumber) = 0;
virtual ErrCode GetAllowCreateId(int &id) = 0;
virtual ErrCode IsOsAccountExists(const int id, bool &isExists) = 0;

View File

@ -39,14 +39,15 @@ public:
virtual ~OsAccountControlFileManager();
void Init() override;
void FileInit();
ErrCode GetOsAccountConfig(OsAccountConfig &config) override;
ErrCode GetOsAccountList(std::vector<OsAccountInfo> &osAccountList) override;
ErrCode GetOsAccountIdList(std::vector<int32_t> &idList) override;
ErrCode GetOsAccountInfoById(const int id, OsAccountInfo &osAccountInfo) override;
ErrCode GetConstraintsByType(const OsAccountType type, std::vector<std::string> &constraints) override;
ErrCode InsertOsAccount(OsAccountInfo &osAccountInfo) override;
ErrCode DelOsAccount(const int id) override;
ErrCode UpdateOsAccount(OsAccountInfo &osAccountInfo) override;
ErrCode GetAccountIndexFromFile(Json &accountIndexJson) override;
ErrCode GetMaxCreatedOsAccountNum(int &maxCreatedOsAccountNum) override;
ErrCode GetSerialNumber(int64_t &serialNumber) override;
ErrCode GetAllowCreateId(int &id) override;
ErrCode IsOsAccountExists(const int id, bool &isExists) override;
@ -92,6 +93,7 @@ public:
ErrCode UpdateAccountIndex(const OsAccountInfo &osAccountInfo, const bool isDelete) override;
private:
ErrCode GetDefaultOsAccountConfig(OsAccountConfig &config);
ErrCode RemoveAccountIndex(const int32_t id);
int GetNextLocalId(const std::vector<std::string> &accountIdList);
ErrCode UpdateAccountList(const std::string &idStr, bool isAdd);

View File

@ -22,7 +22,7 @@
#include "account_permission_manager.h"
#include "os_account_stub.h"
#include "idomain_account_callback.h"
#include "iinner_os_account.h"
#include "iinner_os_account_manager.h"
namespace OHOS {
namespace AccountSA {
@ -57,7 +57,8 @@ public:
ErrCode IsMainOsAccount(bool &isMainOsAccount) override;
ErrCode GetOsAccountLocalIdFromDomain(const DomainAccountInfo &domainInfo, int &id) override;
ErrCode QueryMaxOsAccountNumber(int &maxOsAccountNumber) override;
ErrCode QueryMaxOsAccountNumber(uint32_t &maxOsAccountNumber) override;
ErrCode QueryMaxLoggedInOsAccountNumber(uint32_t &maxNum) override;
ErrCode GetOsAccountAllConstraints(const int id, std::vector<std::string> &constraints) override;
ErrCode QueryAllCreatedOsAccounts(std::vector<OsAccountInfo> &osAccountInfos) override;
@ -141,7 +142,7 @@ private:
ErrCode ValidateAccountCreateParamAndPermission(const std::string &localName, const OsAccountType &type);
private:
IInnerOsAccount &innerManager_;
IInnerOsAccountManager &innerManager_;
DISALLOW_COPY_AND_MOVE(OsAccountManagerService);
};
} // namespace AccountSA

View File

@ -48,6 +48,7 @@ public:
ErrCode ProcQueryCurrentOsAccount(MessageParcel &data, MessageParcel &reply);
ErrCode ProcQueryAllCreatedOsAccounts(MessageParcel &data, MessageParcel &reply);
ErrCode ProcQueryMaxOsAccountNumber(MessageParcel &data, MessageParcel &reply);
ErrCode ProcQueryMaxLoggedInOsAccountNumber(MessageParcel &data, MessageParcel &reply);
ErrCode ProcGetCreatedOsAccountsCount(MessageParcel &data, MessageParcel &reply);
ErrCode ProcGetOsAccountAllConstraints(MessageParcel &data, MessageParcel &reply);
ErrCode ProcGetOsAccountLocalIdFromProcess(MessageParcel &data, MessageParcel &reply);

View File

@ -0,0 +1,4 @@
{
"maxOsAccountNum": 999,
"maxLoggedInOsAccountNum": 999
}

View File

@ -123,6 +123,7 @@ void AuthCallback::OnResult(int32_t result, const Attributes &extraInfo)
}
innerCallback_->OnResult(result, extraInfo);
(void)IInnerOsAccountManager::GetInstance().SetOsAccountIsVerified(userId_, true);
(void)IInnerOsAccountManager::GetInstance().SetOsAccountIsLoggedIn(userId_, true);
AccountInfoReport::ReportSecurityInfo("", userId_, ReportEvent::EVENT_LOGIN, result);
}

View File

@ -61,7 +61,9 @@ IInnerOsAccountManager::IInnerOsAccountManager() : subscribeManager_(OsAccountSu
osAccountControl_->Init();
osAccountControl_->GetDeviceOwnerId(deviceOwnerId_);
osAccountControl_->GetDefaultActivatedOsAccount(defaultActivatedId_);
ACCOUNT_LOGD("OsAccountAccountMgr Init end");
osAccountControl_->GetOsAccountConfig(config_);
ACCOUNT_LOGI("Init end, maxOsAccountNum: %{public}d, maxLoggedInOsAccountNum: %{public}d",
config_.maxOsAccountNum, config_.maxLoggedInOsAccountNum);
}
IInnerOsAccountManager &IInnerOsAccountManager::GetInstance()
@ -161,7 +163,6 @@ void IInnerOsAccountManager::RetryToGetAccount(OsAccountInfo &osAccountInfo)
void IInnerOsAccountManager::StartAccount()
{
ACCOUNT_LOGI("start to activate default account");
ResetAccountStatus();
OsAccountInfo osAccountInfo;
ErrCode errCode = osAccountControl_->GetOsAccountInfoById(defaultActivatedId_, osAccountInfo);
if (errCode != ERR_OK || osAccountInfo.GetToBeRemoved()) {
@ -204,12 +205,10 @@ void IInnerOsAccountManager::RestartActiveAccount()
void IInnerOsAccountManager::ResetAccountStatus(void)
{
std::vector<OsAccountInfo> osAccountInfos;
if (QueryAllCreatedOsAccounts(osAccountInfos) != ERR_OK) {
return;
}
for (size_t i = 0; i < osAccountInfos.size(); ++i) {
DeactivateOsAccount(osAccountInfos[i].GetLocalId());
std::vector<int32_t> idList;
(void) osAccountControl_->GetOsAccountIdList(idList);
for (const auto id : idList) {
DeactivateOsAccount(id);
}
}
@ -226,7 +225,6 @@ ErrCode IInnerOsAccountManager::PrepareOsAccountInfo(const std::string &localNam
if (errCode != ERR_OK) {
return errCode;
}
errCode = ValidateOsAccount(osAccountInfo);
if (errCode != ERR_OK) {
ACCOUNT_LOGE("account name already exist, errCode %{public}d.", errCode);
@ -374,6 +372,12 @@ ErrCode IInnerOsAccountManager::CreateOsAccount(
ACCOUNT_LOGI("Not allow creation account.");
return ERR_OSACCOUNT_SERVICE_INNER_ACCOUNT_PLUGIN_NOT_ALLOWED_CREATION_ERROR;
}
unsigned int osAccountNum = 0;
GetCreatedOsAccountsCount(osAccountNum);
if (osAccountNum >= config_.maxOsAccountNum) {
ACCOUNT_LOGE("The number of OS accounts has oversize, max num: %{public}d", config_.maxOsAccountNum);
return ERR_OSACCOUNT_SERVICE_CONTROL_MAX_CAN_CREATE_ERROR;
}
DomainAccountInfo domainInfo; // default empty domain info
ErrCode errCode = PrepareOsAccountInfo(name, type, domainInfo, osAccountInfo);
if (errCode != ERR_OK) {
@ -411,6 +415,12 @@ ErrCode IInnerOsAccountManager::CreateOsAccount(const std::string &localName, co
return code;
}
#endif // ENABLE_ACCOUNT_SHORT_NAME
unsigned int osAccountNum = 0;
GetCreatedOsAccountsCount(osAccountNum);
if (osAccountNum >= config_.maxOsAccountNum) {
ACCOUNT_LOGE("The number of OS accounts has oversize, max num: %{public}d", config_.maxOsAccountNum);
return ERR_OSACCOUNT_SERVICE_CONTROL_MAX_CAN_CREATE_ERROR;
}
DomainAccountInfo domainInfo; // default empty domain info
ErrCode errCode = PrepareOsAccountInfo(localName, shortName, type, domainInfo, osAccountInfo);
if (errCode != ERR_OK) {
@ -590,6 +600,10 @@ ErrCode IInnerOsAccountManager::CreateOsAccountForDomain(
ACCOUNT_LOGE("the domain account is already bound");
return ERR_OSACCOUNT_SERVICE_INNER_DOMAIN_ALREADY_BIND_ERROR;
}
if (osAccountInfos.size() >= config_.maxOsAccountNum) {
ACCOUNT_LOGE("The number of OS accounts has oversize, max num: %{public}d", config_.maxOsAccountNum);
return ERR_OSACCOUNT_SERVICE_CONTROL_MAX_CAN_CREATE_ERROR;
}
if (!InnerDomainAccountManager::GetInstance().IsPluginAvailable()) {
ACCOUNT_LOGE("plugin is not available");
return ERR_DOMAIN_ACCOUNT_SERVICE_PLUGIN_NOT_EXIST;
@ -683,6 +697,7 @@ ErrCode IInnerOsAccountManager::RemoveOsAccount(const int id)
}
// set remove flag first
osAccountInfo.SetToBeRemoved(true);
loggedInAccounts_.Erase(id);
osAccountControl_->UpdateOsAccount(osAccountInfo);
// stop account first
@ -711,7 +726,7 @@ ErrCode IInnerOsAccountManager::SendMsgForAccountStop(OsAccountInfo &osAccountIn
osAccountInfo.GetLocalId(), errCode);
return ERR_ACCOUNT_COMMON_GET_SYSTEM_ABILITY_MANAGER;
}
return DeactivateOsAccountById(osAccountInfo.GetLocalId());
return DeactivateOsAccountByInfo(osAccountInfo);
}
ErrCode IInnerOsAccountManager::SendMsgForAccountDeactivate(OsAccountInfo &osAccountInfo)
@ -834,6 +849,7 @@ void IInnerOsAccountManager::Init()
{
CreateBaseAdminAccount();
CreateBaseStandardAccount();
ResetAccountStatus();
StartAccount();
CleanGarbageAccounts();
}
@ -911,26 +927,32 @@ ErrCode IInnerOsAccountManager::IsOsAccountVerified(const int id, bool &isVerifi
ErrCode IInnerOsAccountManager::GetCreatedOsAccountsCount(unsigned int &createdOsAccountCount)
{
std::vector<OsAccountInfo> osAccountInfos;
ErrCode errCode = osAccountControl_->GetOsAccountList(osAccountInfos);
std::vector<int32_t> idList;
ErrCode errCode = osAccountControl_->GetOsAccountIdList(idList);
if (errCode != ERR_OK) {
ACCOUNT_LOGE("get osaccount info list error, errCode %{public}d.", errCode);
return errCode;
}
createdOsAccountCount = osAccountInfos.size();
createdOsAccountCount = idList.size();
return ERR_OK;
}
ErrCode IInnerOsAccountManager::QueryMaxOsAccountNumber(int &maxOsAccountNumber)
ErrCode IInnerOsAccountManager::QueryMaxOsAccountNumber(uint32_t &maxOsAccountNumber)
{
#ifdef ENABLE_MULTIPLE_OS_ACCOUNTS
ErrCode errCode = osAccountControl_->GetMaxCreatedOsAccountNum(maxOsAccountNumber);
if (errCode != ERR_OK) {
ACCOUNT_LOGE("get max created osaccount num error, errCode %{public}d.", errCode);
return errCode;
}
maxOsAccountNumber = config_.maxOsAccountNum;
#else
maxOsAccountNumber = 0;
maxOsAccountNumber = 1;
#endif // ENABLE_MULTIPLE_OS_ACCOUNTS
return ERR_OK;
}
ErrCode IInnerOsAccountManager::QueryMaxLoggedInOsAccountNumber(uint32_t &maxNum)
{
#ifdef ENABLE_MULTIPLE_OS_ACCOUNTS
maxNum = config_.maxLoggedInOsAccountNum;
#else
maxNum = 1;
#endif // ENABLE_MULTIPLE_OS_ACCOUNTS
return ERR_OK;
}
@ -1403,20 +1425,17 @@ ErrCode IInnerOsAccountManager::SetOsAccountProfilePhoto(const int id, const std
ErrCode IInnerOsAccountManager::DeactivateOsAccountByInfo(OsAccountInfo &osAccountInfo)
{
int localId = osAccountInfo.GetLocalId();
if (localId == Constants::ADMIN_LOCAL_ID) {
ACCOUNT_LOGI("this osaccount can't deactive, id: %{public}d", Constants::ADMIN_LOCAL_ID);
return ERR_OK;
}
osAccountInfo.SetIsActived(false);
osAccountInfo.SetDisplayId(Constants::INVALID_DISPALY_ID);
osAccountInfo.SetIsForeground(false);
osAccountInfo.SetDisplayId(Constants::INVALID_DISPALY_ID);
osAccountInfo.SetIsLoggedIn(false);
ErrCode errCode = osAccountControl_->UpdateOsAccount(osAccountInfo);
if (errCode != ERR_OK) {
ACCOUNT_LOGE("Update account failed, id=%{public}d, errCode=%{public}d.", localId, errCode);
ACCOUNT_LOGE("Update account failed, id=%{public}d, errCode=%{public}d.", osAccountInfo.GetLocalId(), errCode);
return ERR_OSACCOUNT_SERVICE_INNER_UPDATE_ACCOUNT_ERROR;
}
int localId = osAccountInfo.GetLocalId();
loggedInAccounts_.Erase(localId);
int32_t foregroundId = -1;
if (foregroundAccountMap_.Find(Constants::DEFAULT_DISPALY_ID, foregroundId) && foregroundId == localId) {
foregroundAccountMap_.Erase(Constants::DEFAULT_DISPALY_ID);
@ -1431,18 +1450,6 @@ ErrCode IInnerOsAccountManager::DeactivateOsAccountByInfo(OsAccountInfo &osAccou
ErrCode IInnerOsAccountManager::DeactivateOsAccountById(const int id)
{
if (id == Constants::ADMIN_LOCAL_ID) {
ACCOUNT_LOGI("this osaccount can't deactive, id: %{public}d", Constants::ADMIN_LOCAL_ID);
return ERR_OK;
}
#ifndef SUPPROT_STOP_MAIN_OS_ACCOUNT
if (id == Constants::START_USER_ID) {
ACCOUNT_LOGI("this osaccount can't deactive, id: %{public}d", Constants::START_USER_ID);
return ERR_OK;
}
#endif // SUPPORT_STOP_OS_ACCOUNT
OsAccountInfo osAccountInfo;
ErrCode errCode = osAccountControl_->GetOsAccountInfoById(id, osAccountInfo);
if (errCode != ERR_OK) {
@ -1450,20 +1457,7 @@ ErrCode IInnerOsAccountManager::DeactivateOsAccountById(const int id)
id, errCode);
return ERR_ACCOUNT_COMMON_ACCOUNT_NOT_EXIST_ERROR;
}
osAccountInfo.SetIsActived(false);
osAccountInfo.SetIsForeground(false);
osAccountInfo.SetDisplayId(Constants::INVALID_DISPALY_ID);
errCode = osAccountControl_->UpdateOsAccount(osAccountInfo);
if (errCode != ERR_OK) {
ACCOUNT_LOGE("update %{public}d account info failed, errCode %{public}d.",
osAccountInfo.GetLocalId(), errCode);
return ERR_OSACCOUNT_SERVICE_INNER_UPDATE_ACCOUNT_ERROR;
}
EraseIdFromActiveList(osAccountInfo.GetLocalId());
AccountInfoReport::ReportSecurityInfo(osAccountInfo.GetLocalName(), id, ReportEvent::EVENT_LOGOUT, 0);
return ERR_OK;
return DeactivateOsAccountByInfo(osAccountInfo);
}
ErrCode IInnerOsAccountManager::ActivateOsAccount(const int id, const uint64_t displayId)
@ -1502,6 +1496,14 @@ ErrCode IInnerOsAccountManager::ActivateOsAccount(const int id, const uint64_t d
return ERR_OSACCOUNT_SERVICE_INNER_ACCOUNT_TO_BE_REMOVED_ERROR;
}
if (!osAccountInfo.GetIsActived() &&
(static_cast<uint32_t>(loggedInAccounts_.Size()) >= config_.maxLoggedInOsAccountNum)) {
RemoveLocalIdToOperating(id);
ACCOUNT_LOGE("The number of logged in account reaches the upper limit, maxLoggedInNum: %{public}d",
config_.maxLoggedInOsAccountNum);
return ERR_OSACCOUNT_SERVICE_LOGGED_IN_ACCOUNTS_OVERSIZE;
}
subscribeManager_.Publish(id, OS_ACCOUNT_SUBSCRIBE_TYPE::ACTIVATING);
errCode = SendMsgForAccountActivate(osAccountInfo);
RemoveLocalIdToOperating(id);
@ -1534,10 +1536,10 @@ ErrCode IInnerOsAccountManager::DeactivateOsAccount(const int id)
return ERR_ACCOUNT_COMMON_ACCOUNT_NOT_EXIST_ERROR;
}
if ((!IsOsAccountIDInActiveList(id)) && (!osAccountInfo.GetIsVerified())) {
if ((!osAccountInfo.GetIsActived()) && (!osAccountInfo.GetIsVerified())) {
RemoveLocalIdToOperating(id);
ACCOUNT_LOGW("account %{public}d is neither active nor verified, don't need to deactivate!", id);
return ERR_OSACCOUNT_SERVICE_INNER_ACCOUNT_IS_UNVERIFIED_ERROR;
return ERR_OK;
}
if (!osAccountInfo.GetIsCreateCompleted()) {
RemoveLocalIdToOperating(id);
@ -1601,24 +1603,22 @@ ErrCode IInnerOsAccountManager::SendMsgForAccountActivate(OsAccountInfo &osAccou
localId, errCode);
return errCode;
}
if (oldIdExist) {
OsAccountInfo oldOsAccountInfo;
errCode = osAccountControl_->GetOsAccountInfoById(oldId, oldOsAccountInfo);
if (errCode != ERR_OK) {
ACCOUNT_LOGE("Get osaccount info failed, errCode=%{public}d.", errCode);
return ERR_ACCOUNT_COMMON_ACCOUNT_NOT_EXIST_ERROR;
}
errCode = UpdateAccountToBackground(oldOsAccountInfo);
if (errCode != ERR_OK) {
return errCode;
}
}
errCode = UpdateAccountToForeground(displayId, osAccountInfo);
if (errCode != ERR_OK) {
return errCode;
}
ReportOsAccountSwitch(localId, oldId);
if (oldIdExist) {
errCode = UpdateAccountToBackground(oldId);
if (errCode != ERR_OK) {
return errCode;
}
#ifdef ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
bool isLoggedIn = false;
if (!loggedInAccounts_.Find(oldId, isLoggedIn)) {
DeactivateOsAccount(oldId);
}
#endif // ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
}
#ifndef ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
if (oldId >= Constants::START_USER_ID) {
DeactivateOsAccountById(oldId);
@ -1630,6 +1630,7 @@ ErrCode IInnerOsAccountManager::SendMsgForAccountActivate(OsAccountInfo &osAccou
subscribeManager_.Publish(localId, OS_ACCOUNT_SUBSCRIBE_TYPE::ACTIVED);
subscribeManager_.Publish(localId, oldId, OS_ACCOUNT_SUBSCRIBE_TYPE::SWITCHED);
ACCOUNT_LOGI("SendMsgForAccountActivate ok");
ReportOsAccountSwitch(localId, oldId);
return errCode;
}
@ -1807,6 +1808,39 @@ ErrCode IInnerOsAccountManager::SetOsAccountIsVerified(const int id, const bool
return ERR_OK;
}
ErrCode IInnerOsAccountManager::SetOsAccountIsLoggedIn(const int32_t id, const bool isLoggedIn)
{
OsAccountInfo osAccountInfo;
ErrCode errCode = osAccountControl_->GetOsAccountInfoById(id, osAccountInfo);
if (errCode != ERR_OK) {
ACCOUNT_LOGE("get osaccount info error, errCode %{public}d.", errCode);
return ERR_ACCOUNT_COMMON_ACCOUNT_NOT_EXIST_ERROR;
}
if (osAccountInfo.GetToBeRemoved()) {
ACCOUNT_LOGE("account %{public}d will be removed, cannot change verify state!", id);
return ERR_OSACCOUNT_SERVICE_INNER_ACCOUNT_TO_BE_REMOVED_ERROR;
}
if (!osAccountInfo.GetIsLoggedIn()) {
#ifdef ACTIVATE_LAST_LOGGED_IN_ACCOUNT
osAccountControl_->SetDefaultActivatedOsAccount(id);
#endif
osAccountInfo.SetIsLoggedIn(isLoggedIn);
osAccountInfo.SetLastLoginTime(std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now().time_since_epoch()).count());
}
errCode = osAccountControl_->UpdateOsAccount(osAccountInfo);
if (errCode != ERR_OK) {
ACCOUNT_LOGE("Update account info failed, errCode: %{public}d, id: %{public}d", errCode, id);
return ERR_OSACCOUNT_SERVICE_INNER_UPDATE_ACCOUNT_ERROR;
}
if (isLoggedIn) {
loggedInAccounts_.EnsureInsert(id, true);
} else {
loggedInAccounts_.Erase(id);
}
return ERR_OK;
}
ErrCode IInnerOsAccountManager::GetOsAccountCredentialId(const int id, uint64_t &credentialId)
{
credentialId = 0;
@ -2088,9 +2122,12 @@ ErrCode IInnerOsAccountManager::UpdateAccountToForeground(const uint64_t display
osAccountInfo.SetIsActived(true);
osAccountInfo.SetDisplayId(displayId);
osAccountInfo.SetIsForeground(true);
int64_t time =
std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
osAccountInfo.SetLastLoginTime(time);
if (osAccountInfo.GetIsLoggedIn()) {
loggedInAccounts_.EnsureInsert(localId, true);
#ifdef ACTIVATE_LAST_LOGGED_IN_ACCOUNT
osAccountControl_->SetDefaultActivatedOsAccount(localId);
#endif
}
ErrCode errCode = osAccountControl_->UpdateOsAccount(osAccountInfo);
if (errCode != ERR_OK) {
ACCOUNT_LOGE("Update account failed, localId=%{public}d, errCode=%{public}d.",
@ -2103,11 +2140,17 @@ ErrCode IInnerOsAccountManager::UpdateAccountToForeground(const uint64_t display
return ERR_OK;
}
ErrCode IInnerOsAccountManager::UpdateAccountToBackground(OsAccountInfo &oldOsAccountInfo)
ErrCode IInnerOsAccountManager::UpdateAccountToBackground(int32_t oldId)
{
OsAccountInfo oldOsAccountInfo;
ErrCode errCode = osAccountControl_->GetOsAccountInfoById(oldId, oldOsAccountInfo);
if (errCode != ERR_OK) {
ACCOUNT_LOGE("Get osaccount info failed, errCode=%{public}d.", errCode);
return ERR_ACCOUNT_COMMON_ACCOUNT_NOT_EXIST_ERROR;
}
oldOsAccountInfo.SetIsForeground(false);
oldOsAccountInfo.SetDisplayId(Constants::INVALID_DISPALY_ID);
ErrCode errCode = osAccountControl_->UpdateOsAccount(oldOsAccountInfo);
errCode = osAccountControl_->UpdateOsAccount(oldOsAccountInfo);
if (errCode != ERR_OK) {
ACCOUNT_LOGE("Update osaccount failed, errCode=%{public}d, id=%{public}d",
errCode, oldOsAccountInfo.GetLocalId());

View File

@ -24,6 +24,7 @@
#include "account_log_wrapper.h"
#include "account_hisysevent_adapter.h"
#include "config_policy_utils.h"
#include "os_account_constants.h"
#include "os_account_interface.h"
@ -40,6 +41,14 @@ const std::string ACCOUNT_CFG_DIR_ROOT_PATH = "/data/service/el1/public/account/
const std::string ACCOUNT_CFG_DIR_ROOT_PATH = "/data/service/el1/public/account/test/";
#endif // ACCOUNT_TEST
const std::string DISTRIBUTED_ACCOUNT_FILE_NAME = "/account.json";
const std::string OS_ACCOUNT_CONFIG_FILE = "etc/os_account/os_account_config.json";
const std::string MAX_OS_ACCOUNT_NUM = "maxOsAccountNum";
const std::string MAX_LOGGED_IN_OS_ACCOUNT_NUM = "maxLoggedInOsAccountNum";
#ifndef ACCOUNT_TEST
const std::string DEFAULT_OS_ACCOUNT_CONFIG_FILE = "/system/etc/account/os_account_config.json";
#else
const std::string DEFAULT_OS_ACCOUNT_CONFIG_FILE = ACCOUNT_CFG_DIR_ROOT_PATH + "os_account_config.json";
#endif // ACCOUNT_TEST
}
bool GetValidAccountID(const std::string& dirName, std::int32_t& accountID)
@ -64,6 +73,46 @@ bool GetValidAccountID(const std::string& dirName, std::int32_t& accountID)
return (accountID >= Constants::ADMIN_LOCAL_ID && accountID <= Constants::MAX_USER_ID);
}
ErrCode OsAccountControlFileManager::GetOsAccountConfig(OsAccountConfig &config)
{
std::string cfgPath = DEFAULT_OS_ACCOUNT_CONFIG_FILE;
CfgFiles *cfgFiles = GetCfgFiles(OS_ACCOUNT_CONFIG_FILE.c_str());
if (cfgFiles != nullptr) {
if (cfgFiles->paths[0] != nullptr) {
cfgPath = cfgFiles->paths[0];
}
FreeCfgFiles(cfgFiles);
}
std::string configStr;
ErrCode errCode = accountFileOperator_->GetFileContentByPath(cfgPath, configStr);
if (errCode != ERR_OK) {
ACCOUNT_LOGE("get content from file %{public}s failed!", cfgPath.c_str());
return errCode;
}
Json configJson = Json::parse(configStr, nullptr, false);
if (configJson.is_discarded()) {
ACCOUNT_LOGE("parse os account info json data failed");
return ERR_ACCOUNT_COMMON_BAD_JSON_FORMAT_ERROR;
}
auto jsonEnd = configJson.end();
int32_t maxOsAccountNum = -1;
OHOS::AccountSA::GetDataByType<int32_t>(configJson, jsonEnd, MAX_OS_ACCOUNT_NUM,
maxOsAccountNum, OHOS::AccountSA::JsonType::NUMBER);
if (maxOsAccountNum > 0) {
config.maxOsAccountNum = static_cast<uint32_t>(maxOsAccountNum);
}
int32_t maxLoggedInOsAccountNum = -1;
OHOS::AccountSA::GetDataByType<int32_t>(configJson, jsonEnd, MAX_LOGGED_IN_OS_ACCOUNT_NUM,
config.maxLoggedInOsAccountNum, OHOS::AccountSA::JsonType::NUMBER);
if (maxLoggedInOsAccountNum > 0) {
config.maxLoggedInOsAccountNum = static_cast<uint32_t>(maxLoggedInOsAccountNum);
}
if (config.maxLoggedInOsAccountNum > config.maxOsAccountNum) {
config.maxLoggedInOsAccountNum = config.maxOsAccountNum;
}
return ERR_OK;
}
bool OsAccountControlFileManager::RecoverAccountData(const std::string &fileName, const int32_t id)
{
#ifdef HAS_KV_STORE_PART
@ -392,6 +441,23 @@ void OsAccountControlFileManager::RecoverAccountListJsonFile()
BuildAndSaveAccountListJsonFile(accounts);
}
ErrCode OsAccountControlFileManager::GetOsAccountIdList(std::vector<int32_t> &idList)
{
idList.clear();
Json accountListJson;
ErrCode errCode = GetAccountListFromFile(accountListJson);
if (errCode != ERR_OK) {
return errCode;
}
std::vector<std::string> idStrList;
OHOS::AccountSA::GetDataByType<std::vector<std::string>>(accountListJson, accountListJson.end(),
Constants::ACCOUNT_LIST, idStrList, OHOS::AccountSA::JsonType::ARRAY);
for (const auto &idStr : idStrList) {
idList.emplace_back(atoi(idStr.c_str()));
}
return errCode;
}
ErrCode OsAccountControlFileManager::GetOsAccountList(std::vector<OsAccountInfo> &osAccountList)
{
osAccountList.clear();
@ -950,24 +1016,6 @@ ErrCode OsAccountControlFileManager::UpdateOsAccount(OsAccountInfo &osAccountInf
return ERR_OK;
}
ErrCode OsAccountControlFileManager::GetMaxCreatedOsAccountNum(int &maxCreatedOsAccountNum)
{
ACCOUNT_LOGD("start");
Json accountListJson;
ErrCode result = GetAccountListFromFile(accountListJson);
if (result != ERR_OK) {
return result;
}
OHOS::AccountSA::GetDataByType<int>(accountListJson,
accountListJson.end(),
Constants::MAX_ALLOW_CREATE_ACCOUNT_ID,
maxCreatedOsAccountNum,
OHOS::AccountSA::JsonType::NUMBER);
maxCreatedOsAccountNum -= Constants::START_USER_ID;
ACCOUNT_LOGD("end");
return ERR_OK;
}
bool AccountExistsWithSerialNumber(const std::vector<OsAccountInfo>& osAccountInfos, int serialNumber)
{
const auto targetSerialNumber = Constants::SERIAL_NUMBER_NUM_START_FOR_ADMIN * Constants::CARRY_NUM + serialNumber;
@ -1049,10 +1097,6 @@ ErrCode OsAccountControlFileManager::GetAllowCreateId(int &id)
std::vector<std::string> accountIdList;
OHOS::AccountSA::GetDataByType<std::vector<std::string>>(
accountListJson, jsonEnd, Constants::ACCOUNT_LIST, accountIdList, OHOS::AccountSA::JsonType::ARRAY);
if (accountIdList.size() >= Constants::MAX_USER_ID) {
ACCOUNT_LOGE("GetAllowCreateId cannot create more account error");
return ERR_OSACCOUNT_SERVICE_CONTROL_MAX_CAN_CREATE_ERROR;
}
id = GetNextLocalId(accountIdList);
nextLocalId_++;
return ERR_OK;

View File

@ -413,12 +413,10 @@ ErrCode OsAccountInterface::SendToStorageAccountStart(OsAccountInfo &osAccountIn
return ERR_ACCOUNT_COMMON_GET_SYSTEM_ABILITY_MANAGER;
}
StartTraceAdapter("StorageManager PrepareStartUser");
if ((!osAccountInfo.GetIsVerified()) && (osAccountInfo.GetCredentialId() <= 0)) {
std::vector<uint8_t> emptyData;
if (proxy->ActiveUserKey(osAccountInfo.GetLocalId(), emptyData, emptyData) == 0) {
isUserUnlocked = true;
}
}
int32_t err = proxy->PrepareStartUser(osAccountInfo.GetLocalId());
if (err != 0) {
ReportOsAccountOperationFail(osAccountInfo.GetLocalId(), Constants::OPERATION_ACTIVATE,
@ -427,10 +425,16 @@ ErrCode OsAccountInterface::SendToStorageAccountStart(OsAccountInfo &osAccountIn
ACCOUNT_LOGI("end, Storage PrepareStartUser ret %{public}d.", err);
FinishTraceAdapter();
#else
isUserUnlocked = !osAccountInfo.GetIsVerified();
isUserUnlocked = true;
#endif
if (isUserUnlocked) {
if (!osAccountInfo.GetIsVerified() && isUserUnlocked) {
osAccountInfo.SetIsVerified(true);
bool hasCredential = osAccountInfo.GetCredentialId() > 0;
if (!hasCredential) {
osAccountInfo.SetIsLoggedIn(true);
osAccountInfo.SetLastLoginTime(std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now().time_since_epoch()).count());
}
PublishCommonEvent(osAccountInfo, OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_UNLOCKED,
Constants::OPERATION_UNLOCK);
OsAccountSubscribeManager::GetInstance().Publish(osAccountInfo.GetLocalId(),

View File

@ -401,11 +401,16 @@ ErrCode OsAccountManagerService::GetOsAccountLocalIdFromDomain(const DomainAccou
return innerManager_.GetOsAccountLocalIdFromDomain(domainInfo, id);
}
ErrCode OsAccountManagerService::QueryMaxOsAccountNumber(int &maxOsAccountNumber)
ErrCode OsAccountManagerService::QueryMaxOsAccountNumber(uint32_t &maxOsAccountNumber)
{
return innerManager_.QueryMaxOsAccountNumber(maxOsAccountNumber);
}
ErrCode OsAccountManagerService::QueryMaxLoggedInOsAccountNumber(uint32_t &maxNum)
{
return innerManager_.QueryMaxLoggedInOsAccountNumber(maxNum);
}
ErrCode OsAccountManagerService::GetOsAccountAllConstraints(const int id, std::vector<std::string> &constraints)
{
ErrCode res = CheckInvalidLocalId(id);

View File

@ -129,6 +129,13 @@ const std::map<uint32_t, OsAccountStub::OsAccountMessageProc> messageProcMap = {
.isSyetemApi = true,
}
},
{
static_cast<uint32_t>(OsAccountInterfaceCode::QUERY_MAX_LOGGED_IN_OS_ACCOUNT_NUMBER),
{
.messageProcFunction = &OsAccountStub::ProcQueryMaxLoggedInOsAccountNumber,
.isSyetemApi = true,
}
},
{
static_cast<uint32_t>(OsAccountInterfaceCode::GET_OS_ACCOUNT_ALL_CONSTRAINTS),
{
@ -726,19 +733,34 @@ ErrCode OsAccountStub::ProcQueryAllCreatedOsAccounts(MessageParcel &data, Messag
ErrCode OsAccountStub::ProcQueryMaxOsAccountNumber(MessageParcel &data, MessageParcel &reply)
{
int maxOsAccountNumber = 0;
uint32_t maxOsAccountNumber = 0;
ErrCode result = QueryMaxOsAccountNumber(maxOsAccountNumber);
if (!reply.WriteInt32(result)) {
ACCOUNT_LOGE("failed to write reply, result %{public}d.", result);
return IPC_STUB_WRITE_PARCEL_ERR;
}
if (!reply.WriteInt32(maxOsAccountNumber)) {
if (!reply.WriteUint32(maxOsAccountNumber)) {
ACCOUNT_LOGE("failed to write reply");
return IPC_STUB_WRITE_PARCEL_ERR;
}
return ERR_NONE;
}
ErrCode OsAccountStub::ProcQueryMaxLoggedInOsAccountNumber(MessageParcel &data, MessageParcel &reply)
{
uint32_t maxNum = 0;
ErrCode result = QueryMaxLoggedInOsAccountNumber(maxNum);
if (!reply.WriteInt32(result)) {
ACCOUNT_LOGE("Failed to write reply, result %{public}d.", result);
return IPC_STUB_WRITE_PARCEL_ERR;
}
if (!reply.WriteUint32(maxNum)) {
ACCOUNT_LOGE("Failed to write reply");
return IPC_STUB_WRITE_PARCEL_ERR;
}
return ERR_NONE;
}
ErrCode OsAccountStub::ProcGetCreatedOsAccountsCount(MessageParcel &data, MessageParcel &reply)
{
unsigned int osAccountsCount = 0;

View File

@ -102,6 +102,8 @@ ErrCode OsAccountInterface::SendToStorageAccountRemove(OsAccountInfo &osAccountI
ErrCode OsAccountInterface::SendToStorageAccountStart(OsAccountInfo &osAccountInfo)
{
ACCOUNT_LOGI("mock OsAccountInterface SendToStorageAccountStart start");
osAccountInfo.SetIsVerified(true);
osAccountInfo.SetIsLoggedIn(true);
return ERR_OK;
}

View File

@ -141,6 +141,7 @@ ohos_moduletest("os_account_manager_service_module_test") {
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"config_policy:configpolicy_util",
"eventhandler:libeventhandler",
"hilog:libhilog",
"ipc:ipc_single",
@ -321,6 +322,7 @@ ohos_moduletest("os_account_manager_service_subscribe_module_test") {
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"config_policy:configpolicy_util",
"eventhandler:libeventhandler",
"hilog:libhilog",
"ipc:ipc_single",

View File

@ -170,6 +170,5 @@ HWTEST_F(IInnerOsAccountManagerTest, InnerOsAccountManagerTest003, TestSize.Leve
EXPECT_NE(ret, ERR_OK);
innerMgrService_->RemoveOsAccount(osAccountInfo.GetLocalId());
}
} // namespace AccountSA
} // namespace OHOS

View File

@ -82,12 +82,21 @@ const std::string PHOTO_IMG_ERROR =
"D3I1NZvmdCXz+XOv5wJANKHOVYjRTAghxIyh0FHKb+0QQH5+kXf2zkYGAG0oFr5RfnK8DAGkwY19wliRT2L448vjv0YGQFVa8VKdDXUU+"
"faFUxpblhxYRNRzmd6FNnS0H3/X/VH6j0IIIRxMLJ5k/j/2L/"
"zchW8pKj7iFAA0R2wajl5d46idlR3+GtPV2XOvQ3bBNvyFs8U39v9PLX0Bp0CN+yY0OAEAAAAASUVORK5CYII=";
const std::string CONFIG_JSON_NORMAL = "{\"maxOsAccountNum\": 5, \"maxLoggedInOsAccountNum\": 3}";
const std::string CONFIG_JSON_LAGER_LOGGED_IN_NUM = "{\"maxOsAccountNum\": 5, \"maxLoggedInOsAccountNum\": 9}";
const std::string CONFIG_JSON_INVALID_KEY_OR_VALUE = "{\"version\": 1, \"maxLoggedInOsAccountNum\": -1}";
const std::string CONFIG_JSON_INVALID_FORMAT = "maxOsAccountNum=5, maxLoggedInOsAccountNum=3";
const std::string CONFIG_PATH = "/data/service/el1/public/account/test/os_account_config.json";
const std::string STRING_DOMAIN_NAME_OUT_OF_RANGE(200, '1'); // length 200
const std::string STRING_DOMAIN_ACCOUNT_NAME_OUT_OF_RANGE(600, '1'); // length 600
const std::string STRING_DOMAIN_VALID = "TestDomainMT";
const std::string STRING_DOMAIN_ACCOUNT_NAME_VALID = "TestDomainAccountNameMT";
const std::int32_t MAIN_ACCOUNT_ID = 100;
const std::int32_t INVALID_ACCOUNT_ID = 200;
const std::uint32_t MAX_OS_ACCOUNT_NUM = 5;
const std::uint32_t MAX_LOGGED_IN_OS_ACCOUNT_NUM = 3;
const std::uint32_t DEFAULT_MAX_OS_ACCOUNT_NUM = 999;
const std::uint32_t DEFAULT_MAX_LOGGED_IN_OS_ACCOUNT_NUM = 999;
const std::shared_ptr<AccountFileOperator> g_accountFileOperator =
AccountFileWatcherMgr::GetInstance().accountFileOperator_;
@ -552,7 +561,7 @@ HWTEST_F(OsAccountManagerServiceModuleTest, OsAccountManagerServiceModuleTest024
*/
HWTEST_F(OsAccountManagerServiceModuleTest, OsAccountManagerServiceModuleTest025, TestSize.Level1)
{
int maxOsAccountNumber = 0;
uint32_t maxOsAccountNumber = 0;
EXPECT_EQ(osAccountManagerService_->QueryMaxOsAccountNumber(maxOsAccountNumber), ERR_OK);
}
@ -2343,6 +2352,177 @@ HWTEST_F(OsAccountManagerServiceModuleTest, PrivateTypeTest003, TestSize.Level1)
EXPECT_EQ(osAccountManagerService_->RemoveOsAccount(osAccountInfoB.GetLocalId()), ERR_OK);
EXPECT_EQ(osAccountManagerService_->RemoveOsAccount(osAccountInfoC.GetLocalId()), ERR_OK);
}
/**
* @tc.name: MaxNumTest001
* @tc.desc: test maxOsAccount and maxLoggedInOsAccount is valid
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(OsAccountManagerServiceModuleTest, MaxNumTest001, TestSize.Level1)
{
AccountFileOperator osAccountFileOperator;
osAccountFileOperator.InputFileByPathAndContent(CONFIG_PATH, CONFIG_JSON_NORMAL);
auto &innerMgr = osAccountManagerService_->innerManager_;
ASSERT_NE(innerMgr.osAccountControl_, nullptr);
innerMgr.osAccountControl_->GetOsAccountConfig(innerMgr.config_);
uint32_t maxOsAccountNum = 0;
EXPECT_EQ(osAccountManagerService_->QueryMaxOsAccountNumber(maxOsAccountNum), ERR_OK);
ASSERT_EQ(maxOsAccountNum, MAX_OS_ACCOUNT_NUM);
uint32_t maxLoggedInOsAccountNum = 0;
EXPECT_EQ(osAccountManagerService_->QueryMaxLoggedInOsAccountNumber(maxLoggedInOsAccountNum), ERR_OK);
ASSERT_EQ(maxLoggedInOsAccountNum, MAX_LOGGED_IN_OS_ACCOUNT_NUM);
std::vector<int32_t> createdOsAccounts;
ErrCode ret = ERR_OK;
OsAccountInfo osAccountInfo;
for (uint32_t i = 1; i < maxOsAccountNum; ++i) {
ret = osAccountManagerService_->CreateOsAccount(
"InnerOsAccountManager004" + std::to_string(i), OsAccountType::NORMAL, osAccountInfo);
EXPECT_EQ(ret, ERR_OK);
createdOsAccounts.emplace_back(osAccountInfo.GetLocalId());
}
ret = osAccountManagerService_->CreateOsAccount(
"InnerOsAccountManager004" + std::to_string(maxOsAccountNum), OsAccountType::NORMAL, osAccountInfo);
EXPECT_EQ(ret, ERR_OSACCOUNT_SERVICE_CONTROL_MAX_CAN_CREATE_ERROR);
for (uint32_t i = 0; i < maxLoggedInOsAccountNum - 1; ++i) {
ret = osAccountManagerService_->ActivateOsAccount(createdOsAccounts[i]);
EXPECT_EQ(ret, ERR_OK);
}
#ifndef ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
if (maxLoggedInOsAccountNum < maxOsAccountNum && createdOsAccounts.size() > 0) {
ret = osAccountManagerService_->ActivateOsAccount(createdOsAccounts[createdOsAccounts.size() - 1]);
EXPECT_EQ(ret, ERR_OK);
}
#endif
for (uint32_t i = 0; i < maxOsAccountNum; ++i) {
osAccountManagerService_->RemoveOsAccount(createdOsAccounts[i]);
}
osAccountFileOperator.DeleteDirOrFile(CONFIG_PATH);
}
/**
* @tc.name: MaxNumTest002
* @tc.desc: test the maxLoggedInOsAccountNum is larger then the maxOsAccountNum
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(OsAccountManagerServiceModuleTest, MaxNumTest002, TestSize.Level1)
{
AccountFileOperator osAccountFileOperator;
osAccountFileOperator.InputFileByPathAndContent(CONFIG_PATH, CONFIG_JSON_LAGER_LOGGED_IN_NUM);
auto &innerMgr = osAccountManagerService_->innerManager_;
ASSERT_NE(innerMgr.osAccountControl_, nullptr);
innerMgr.osAccountControl_->GetOsAccountConfig(innerMgr.config_);
uint32_t maxOsAccountNum = 0;
EXPECT_EQ(osAccountManagerService_->QueryMaxOsAccountNumber(maxOsAccountNum), ERR_OK);
ASSERT_EQ(maxOsAccountNum, MAX_OS_ACCOUNT_NUM);
uint32_t maxLoggedInOsAccountNum = 0;
EXPECT_EQ(osAccountManagerService_->QueryMaxLoggedInOsAccountNumber(maxLoggedInOsAccountNum), ERR_OK);
ASSERT_EQ(maxLoggedInOsAccountNum, MAX_OS_ACCOUNT_NUM);
osAccountFileOperator.DeleteDirOrFile(CONFIG_PATH);
}
/**
* @tc.name: MaxNumTest003
* @tc.desc: test config json is invalid format.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(OsAccountManagerServiceModuleTest, MaxNumTest003, TestSize.Level1)
{
AccountFileOperator osAccountFileOperator;
osAccountFileOperator.InputFileByPathAndContent(CONFIG_PATH, CONFIG_JSON_INVALID_FORMAT);
auto &innerMgr = osAccountManagerService_->innerManager_;
innerMgr.config_.maxOsAccountNum = DEFAULT_MAX_OS_ACCOUNT_NUM;
innerMgr.config_.maxLoggedInOsAccountNum = DEFAULT_MAX_LOGGED_IN_OS_ACCOUNT_NUM;
ASSERT_NE(innerMgr.osAccountControl_, nullptr);
innerMgr.osAccountControl_->GetOsAccountConfig(innerMgr.config_);
uint32_t maxOsAccountNum = 0;
EXPECT_EQ(osAccountManagerService_->QueryMaxOsAccountNumber(maxOsAccountNum), ERR_OK);
ASSERT_EQ(maxOsAccountNum, DEFAULT_MAX_OS_ACCOUNT_NUM);
uint32_t maxLoggedInOsAccountNum = 0;
EXPECT_EQ(osAccountManagerService_->QueryMaxLoggedInOsAccountNumber(maxLoggedInOsAccountNum), ERR_OK);
ASSERT_EQ(maxLoggedInOsAccountNum, DEFAULT_MAX_LOGGED_IN_OS_ACCOUNT_NUM);
osAccountFileOperator.DeleteDirOrFile(CONFIG_PATH);
}
/**
* @tc.name: MaxNumTest004
* @tc.desc: test key not found, or value is negative.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(OsAccountManagerServiceModuleTest, MaxNumTest004, TestSize.Level1)
{
AccountFileOperator osAccountFileOperator;
osAccountFileOperator.InputFileByPathAndContent(CONFIG_PATH, CONFIG_JSON_INVALID_KEY_OR_VALUE);
auto &innerMgr = osAccountManagerService_->innerManager_;
innerMgr.config_.maxOsAccountNum = DEFAULT_MAX_OS_ACCOUNT_NUM;
innerMgr.config_.maxLoggedInOsAccountNum = DEFAULT_MAX_LOGGED_IN_OS_ACCOUNT_NUM;
ASSERT_NE(innerMgr.osAccountControl_, nullptr);
innerMgr.osAccountControl_->GetOsAccountConfig(innerMgr.config_);
uint32_t maxOsAccountNum = 0;
EXPECT_EQ(osAccountManagerService_->QueryMaxOsAccountNumber(maxOsAccountNum), ERR_OK);
ASSERT_EQ(maxOsAccountNum, DEFAULT_MAX_OS_ACCOUNT_NUM);
uint32_t maxLoggedInOsAccountNum = 0;
EXPECT_EQ(osAccountManagerService_->QueryMaxLoggedInOsAccountNumber(maxLoggedInOsAccountNum), ERR_OK);
ASSERT_EQ(maxLoggedInOsAccountNum, DEFAULT_MAX_LOGGED_IN_OS_ACCOUNT_NUM);
osAccountFileOperator.DeleteDirOrFile(CONFIG_PATH);
}
/**
* @tc.name: MaxNumTest005
* @tc.desc: test activateOsAccount failed when the number of the logged in accounts reaches upper limit.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(OsAccountManagerServiceModuleTest, MaxNumTest005, TestSize.Level1)
{
auto &innerMgr = osAccountManagerService_->innerManager_;
innerMgr.config_.maxLoggedInOsAccountNum = 1;
OsAccountInfo osAccountInfo;
EXPECT_EQ(osAccountManagerService_->CreateOsAccount("MaxNumTest005", OsAccountType::NORMAL, osAccountInfo),
ERR_OK);
EXPECT_EQ(osAccountManagerService_->ActivateOsAccount(osAccountInfo.GetLocalId()),
ERR_OSACCOUNT_SERVICE_LOGGED_IN_ACCOUNTS_OVERSIZE);
}
/**
* @tc.name: SetOsAccountIsLoggedInTest001
* @tc.desc: coverage SetOsAccountIsLoggedIn
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(OsAccountManagerServiceModuleTest, SetOsAccountIsLoggedInTest001, TestSize.Level1)
{
OsAccountInfo osAccountInfo;
ErrCode ret = osAccountManagerService_->CreateOsAccount(
"SetOsAccountIsLoggedInTest001", OsAccountType::NORMAL, osAccountInfo);
ASSERT_EQ(ret, ERR_OK);
int localId = osAccountInfo.GetLocalId();
// account not found, login fail
EXPECT_EQ(osAccountManagerService_->innerManager_.SetOsAccountIsLoggedIn(localId + 1, true),
ERR_ACCOUNT_COMMON_ACCOUNT_NOT_EXIST_ERROR);
// to be removed, login fail
ASSERT_EQ(osAccountManagerService_->SetOsAccountToBeRemoved(localId, true), ERR_OK);
EXPECT_EQ(osAccountManagerService_->innerManager_.SetOsAccountIsLoggedIn(localId, true),
ERR_OSACCOUNT_SERVICE_INNER_ACCOUNT_TO_BE_REMOVED_ERROR);
// unset toBeRemoved
ASSERT_EQ(osAccountManagerService_->SetOsAccountToBeRemoved(localId, false), ERR_OK);
EXPECT_FALSE(osAccountInfo.GetIsLoggedIn());
EXPECT_FALSE(osAccountInfo.GetLastLoginTime() > 0);
// login
EXPECT_EQ(osAccountManagerService_->innerManager_.SetOsAccountIsLoggedIn(localId, true), ERR_OK);
EXPECT_EQ(osAccountManagerService_->QueryOsAccountById(localId, osAccountInfo), ERR_OK);
EXPECT_TRUE(osAccountInfo.GetIsLoggedIn());
EXPECT_TRUE(osAccountInfo.GetLastLoginTime() > 0);
bool val = true;
EXPECT_TRUE(osAccountManagerService_->innerManager_.loggedInAccounts_.Find(localId, val));
// logout
EXPECT_EQ(osAccountManagerService_->innerManager_.SetOsAccountIsLoggedIn(localId, false), ERR_OK);
EXPECT_FALSE(osAccountManagerService_->innerManager_.loggedInAccounts_.Find(localId, val));
osAccountManagerService_->RemoveOsAccount(osAccountInfo.GetLocalId());
}
#endif //ENABLE_MULTIPLE_OS_ACCOUNTS
} // namespace AccountSA
} // namespace OHOS

View File

@ -452,6 +452,7 @@ ohos_unittest("OsAccountInnerAccmgrBundleAdapterMockTest") {
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"config_policy:configpolicy_util",
"hilog:libhilog",
"huks:libhukssdk",
"init:libbegetutil",

View File

@ -32,6 +32,8 @@ class MockOsAccountControlFileManager : public IOsAccountControl {
public:
MockOsAccountControlFileManager() {}
virtual ~MockOsAccountControlFileManager() {}
MOCK_METHOD1(GetOsAccountConfig, ErrCode(OsAccountConfig &config));
MOCK_METHOD1(GetOsAccountIdList, ErrCode(std::vector<int32_t> &idList));
MOCK_METHOD1(GetOsAccountList, ErrCode(std::vector<OsAccountInfo> &osAccountList));
MOCK_METHOD2(GetConstraintsByType, ErrCode(const OsAccountType type, std::vector<std::string> &constraints));
MOCK_METHOD2(GetOsAccountInfoById, ErrCode(const int id, OsAccountInfo &osAccountInfo));
@ -43,7 +45,6 @@ public:
MOCK_METHOD1(UpdateOsAccount, ErrCode(OsAccountInfo &osAccountInfo));
MOCK_METHOD1(RemoveOAConstraintsInfo, ErrCode(const int32_t id));
MOCK_METHOD1(DelOsAccount, ErrCode(const int id));
MOCK_METHOD1(GetMaxCreatedOsAccountNum, ErrCode(int &maxCreatedOsAccountNum));
MOCK_METHOD1(GetGlobalOAConstraintsList, ErrCode(std::vector<std::string> &constraintsList));
MOCK_METHOD2(GetSpecificOAConstraintsList, ErrCode (const int32_t id, std::vector<std::string> &constraintsList));
MOCK_METHOD4(IsFromGlobalOAConstraintsList, ErrCode(const int32_t id, const int32_t deviceOwnerId,

View File

@ -227,19 +227,6 @@ HWTEST_F(OsAccountControlFileManagerTest, OsAccountControlFileManagerTest008, Te
EXPECT_EQ(isOsAccountExists, false);
}
/**
* @tc.name: OsAccountControlFileManagerTest009
* @tc.desc: Test GetMaxCreatedOsAccountNum
* @tc.type: FUNC
* @tc.require: SR000GGVFG
*/
HWTEST_F(OsAccountControlFileManagerTest, OsAccountControlFileManagerTest009, TestSize.Level1)
{
int maxCreatedOsAccountNum = 0;
EXPECT_EQ(g_controlManager->GetMaxCreatedOsAccountNum(maxCreatedOsAccountNum), ERR_OK);
EXPECT_NE(maxCreatedOsAccountNum, 0);
}
/**
* @tc.name: OsAccountControlFileManagerTest010
* @tc.desc: Test GetAllowCreateId

View File

@ -28,12 +28,11 @@
#include "matching_skills.h"
#endif // HAS_CES_PART
#include "os_account_constants.h"
#define private public
#include "os_account_manager_service.h"
#include "os_account_interface.h"
#include "os_account_info.h"
#include "account_log_wrapper.h"
#define private public
#include "iinner_os_account_manager.h"
#undef private
#include "os_account_subscribe_manager.h"
#include "token_setproc.h"

View File

@ -20,13 +20,11 @@
#include "account_error_no.h"
#include "os_account_constants.h"
#include "os_account_manager.h"
#include "os_account_manager_service.h"
#include "os_account_interface.h"
#include "os_account_info.h"
#include "account_log_wrapper.h"
#define private public
#include "account_file_watcher_manager.h"
#include "iinner_os_account_manager.h"
#include "os_account_control_file_manager.h"
#undef private
#include "os_account_subscribe_manager.h"
@ -219,7 +217,7 @@ HWTEST_F(OsAccountInnerAccmgrMockTest, OsAccountInnerAccmgrMockTest008, TestSize
{
auto ptr = std::make_shared<MockOsAccountControlFileManager>();
EXPECT_CALL(*ptr, GetOsAccountList(::testing::_))
EXPECT_CALL(*ptr, GetOsAccountIdList(::testing::_))
.WillRepeatedly(testing::Return(-1));
innerMgrService_->SetOsAccountControl(ptr);
@ -461,37 +459,6 @@ HWTEST_F(OsAccountInnerAccmgrMockTest, OsAccountInnerAccmgrMockTest015, TestSize
}
#endif // ENABLE_MULTIPLE_OS_ACCOUNTS
/*
* @tc.name: OsAccountInnerAccmgrMockTest016
* @tc.desc: coverage test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(OsAccountInnerAccmgrMockTest, OsAccountInnerAccmgrMockTest016, TestSize.Level1)
{
auto ptr = std::make_shared<MockOsAccountControlFileManager>();
innerMgrService_->SetOsAccountControl(ptr);
int id = 0;
bool flag;
EXPECT_CALL(*ptr, GetOsAccountInfoById(_, _))
.WillRepeatedly(testing::Return(-1));
ErrCode ret = innerMgrService_->IsOsAccountActived(id, flag);
EXPECT_EQ(ret, ERR_ACCOUNT_COMMON_ACCOUNT_NOT_EXIST_ERROR);
EXPECT_CALL(*ptr, GetMaxCreatedOsAccountNum(_))
.WillRepeatedly(testing::Return(-1));
int num = 0;
ret = innerMgrService_->QueryMaxOsAccountNumber(num);
#ifdef ENABLE_MULTIPLE_OS_ACCOUNTS
EXPECT_EQ(ret, -1);
#else
EXPECT_EQ(ret, 0);
#endif // ENABLE_MULTIPLE_OS_ACCOUNTS
}
/*
* @tc.name: OsAccountInnerAccmgrMockTest017
* @tc.desc: coverage test

View File

@ -26,7 +26,6 @@
#include "os_account_subscribe_manager.h"
#include "ability_manager_adapter.h"
#undef private
#include "os_account_manager_service.h"
#include "os_account_interface.h"
#include "mock_account_mgr_service.h"
#include "os_account_info.h"

View File

@ -61,11 +61,18 @@ bool QueryOsAccountByIdFuzzTest(const uint8_t* data, size_t size)
bool QueryMaxOsAccountNumberFuzzTest(const uint8_t* data, size_t size)
{
int32_t result = ERR_OK;
int32_t testMaxOsAccountNumber;
uint32_t testMaxOsAccountNumber;
result = OsAccountManager::QueryMaxOsAccountNumber(testMaxOsAccountNumber);
return result == ERR_OK;
}
bool QueryMaxLoggedInOsAccountNumberFuzzTest(const uint8_t* data, size_t size)
{
uint32_t maxNum;
ErrCode result = OsAccountManager::QueryMaxLoggedInOsAccountNumber(maxNum);
return result == ERR_OK;
}
bool QueryCurrentOsAccountFuzzTest(const uint8_t* data, size_t size)
{
int32_t result = ERR_OK;
@ -95,6 +102,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
OHOS::QueryOsAccountConstraintSourceTypesFuzzTest(data, size);
OHOS::QueryOsAccountByIdFuzzTest(data, size);
OHOS::QueryMaxOsAccountNumberFuzzTest(data, size);
OHOS::QueryMaxLoggedInOsAccountNumberFuzzTest(data, size);
OHOS::QueryCurrentOsAccountFuzzTest(data, size);
OHOS::QueryAllCreatedOsAccountsFuzzTest(data, size);
return 0;

View File

@ -142,6 +142,7 @@ ohos_moduletest("account_command_create_module_mock_test") {
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"config_policy:configpolicy_util",
"hilog:libhilog",
"huks:libhukssdk",
"init:libbegetutil",
@ -242,6 +243,7 @@ ohos_moduletest("account_command_delete_module_mock_test") {
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"config_policy:configpolicy_util",
"hilog:libhilog",
"huks:libhukssdk",
"init:libbegetutil",