!345 系统账号支持多用户激活需求开发

Merge pull request !345 from lichenchen/master
This commit is contained in:
openharmony_ci 2022-07-05 06:38:40 +00:00 committed by Gitee
commit 7b188231eb
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 408 additions and 92 deletions

View File

@ -18,7 +18,8 @@
],
"features": [
"os_account_enable_app_account = true",
"os_account_enable_os_account = true"
"os_account_enable_os_account = true",
"os_account_multiple_active_accounts"
],
"hisysevent_config": [
"//base/account/os_account/hisysevent.yaml"

View File

@ -72,3 +72,7 @@ if (!defined(global_parts_info) ||
} else {
has_hiviewdfx_hitrace_part = false
}
declare_args() {
os_account_multiple_active_accounts = false
}

View File

@ -116,6 +116,9 @@ ohos_shared_library("accountmgr") {
"-Wfloat-equal",
"-Wshadow",
]
if (os_account_multiple_active_accounts) {
cflags += [ "-DENABLE_MULTIPLE_ACTIVE_ACCOUNTS" ]
}
sources = [
"${os_account_dfx_path}/hidumper_adapter/account_dump_helper.cpp",

View File

@ -85,12 +85,14 @@ public:
private:
void StartAccount();
void RestartActiveAccount();
void CreateBaseAdminAccount();
void CreateBaseStandardAccount();
void CreateBaseStandardAccountSendToOther();
void StartBaseStandardAccount(void);
void DeActivateOsAccount(const int id);
void ResetActiveStatus(void);
void StartActivatedAccount(int32_t id);
ErrCode DeActivateOsAccount(const int id);
ErrCode GetEventHandler(void);
ErrCode PrepareOsAccountInfo(const std::string &name, const OsAccountType &type,
const DomainAccountInfo &domainAccount, OsAccountInfo &osAccountInfo);
@ -105,7 +107,8 @@ private:
ErrCode DealWithDeviceOwnerId(const bool isDeviceOwner, const int32_t localId);
// operations for active list
void PushIDIntoActiveList(int32_t id);
void PushIdIntoActiveList(int32_t id);
void EraseIdFromActiveList(int32_t id);
bool IsOsAccountIDInActiveList(int32_t id);
void CopyFromActiveList(std::vector<int32_t>& idList);
void RefreshActiveList(int32_t newId);
@ -117,6 +120,7 @@ private:
std::shared_ptr<IOsAccountSubscribe> subscribeManagerPtr_;
std::int32_t counterForStandard_;
std::int32_t counterForStandardCreate_;
std::int32_t counterForAccountStart_;
std::int32_t deviceOwnerId_;
bool isSendToStorageCreate_;
bool isSendToStorageStart_;

View File

@ -27,6 +27,7 @@ IInnerOsAccountManager::IInnerOsAccountManager() : subscribeManagerPtr_(OsAccoun
{
counterForStandard_ = 0;
counterForStandardCreate_ = 0;
counterForAccountStart_ = 0;
isSendToStorageCreate_ = false;
isSendToStorageStart_ = false;
activeAccountId_.clear();
@ -92,7 +93,9 @@ void IInnerOsAccountManager::StartAccount()
errCode);
return;
}
#ifndef ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
ResetActiveStatus();
#endif // ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
GetEventHandler();
if (!osAccountInfo.GetIsCreateCompleted()) {
ACCOUNT_LOGI("OsAccountAccountMgr send to storage and bm for start");
@ -106,6 +109,54 @@ void IInnerOsAccountManager::StartAccount()
handler_->PostTask(callbackStartStandard, DELAY_FOR_FOUNDATION_SERVICE);
}
void IInnerOsAccountManager::RestartActiveAccount()
{
// query active account to restart and refresh into list
std::vector<OsAccountInfo> osAccountInfos;
if (QueryAllCreatedOsAccounts(osAccountInfos) != ERR_OK) {
return;
}
for (size_t i = 0; i < osAccountInfos.size(); ++i) {
if (osAccountInfos[i].GetIsActived() && osAccountInfos[i].GetLocalId() != Constants::START_USER_ID) {
// reactivate account state
GetEventHandler();
OHOS::AppExecFwk::InnerEvent::Callback callbackForRestart =
std::bind(&IInnerOsAccountManager::StartActivatedAccount, this, osAccountInfos[i].GetLocalId());
handler_->PostTask(callbackForRestart, DELAY_FOR_FOUNDATION_SERVICE);
}
}
}
void IInnerOsAccountManager::StartActivatedAccount(int32_t id)
{
OsAccountInfo osAccountInfo;
osAccountControl_->GetOsAccountInfoById(Constants::START_USER_ID, osAccountInfo);
if (!IsOsAccountIDInActiveList(id)) {
ErrCode errCode = ActivateOsAccount(id);
if (errCode != ERR_OK) {
if (++counterForAccountStart_ == MAX_TRY_TIMES) {
ACCOUNT_LOGE("failed to reactivate account, id = %{public}d", id);
} else {
GetEventHandler();
OHOS::AppExecFwk::InnerEvent::Callback callbackForRestart =
std::bind(&IInnerOsAccountManager::StartActivatedAccount, this, id);
handler_->PostTask(callbackForRestart, DELAY_FOR_FOUNDATION_SERVICE);
}
return;
}
ACCOUNT_LOGI("reactive account ok");
counterForAccountStart_ = 0;
}
int64_t time = std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now().time_since_epoch()).count();
osAccountInfo.SetLastLoginTime(time);
osAccountControl_->UpdateOsAccount(osAccountInfo);
PushIdIntoActiveList(id);
subscribeManagerPtr_->PublishActivatedOsAccount(Constants::START_USER_ID);
OsAccountInterface::SendToCESAccountSwitched(osAccountInfo);
ACCOUNT_LOGI("restart account ok");
}
void IInnerOsAccountManager::CreateBaseStandardAccountSendToOther(void)
{
OsAccountInfo osAccountInfo;
@ -208,7 +259,7 @@ void IInnerOsAccountManager::StartBaseStandardAccount(void)
std::chrono::system_clock::now().time_since_epoch()).count();
osAccountInfo.SetLastLoginTime(time);
osAccountControl_->UpdateOsAccount(osAccountInfo);
PushIDIntoActiveList(Constants::START_USER_ID);
PushIdIntoActiveList(Constants::START_USER_ID);
subscribeManagerPtr_->PublishActivatedOsAccount(Constants::START_USER_ID);
OsAccountInterface::SendToCESAccountSwitched(osAccountInfo);
ACCOUNT_LOGI("connect AM to start account ok");
@ -331,6 +382,7 @@ ErrCode IInnerOsAccountManager::RemoveOsAccount(const int id)
return ERR_OSACCOUNT_SERVICE_INNER_ACCOUNT_OPERATING_ERROR;
}
AddLocalIdToOperating(id);
#ifndef ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
if (IsOsAccountIDInActiveList(id)) {
ACCOUNT_LOGI("RemoveOsAccount started account to inactive, account id : %{public}d.", id);
ErrCode activeErrCode = ActivateOsAccount(Constants::START_USER_ID);
@ -340,6 +392,7 @@ ErrCode IInnerOsAccountManager::RemoveOsAccount(const int id)
return ERR_OSACCOUNT_SERVICE_INNER_REMOVE_ACCOUNT_ACTIVED_ERROR;
}
}
#endif // ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
OsAccountInfo osAccountInfo;
ErrCode errCode = osAccountControl_->GetOsAccountInfoById(id, osAccountInfo);
if (errCode != ERR_OK) {
@ -393,6 +446,15 @@ ErrCode IInnerOsAccountManager::SendMsgForAccountStop(OsAccountInfo &osAccountIn
osAccountInfo.GetLocalId(), errCode);
return ERR_OSACCOUNT_SERVICE_INTERFACE_TO_STORAGE_ACCOUNT_STOP_ERROR;
}
#ifdef ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
errCode = DeActivateOsAccount(osAccountInfo.GetLocalId());
if (errCode != ERR_OK) {
ACCOUNT_LOGE("DeActivateOsAccount failed, id %{public}d, errCode %{public}d",
osAccountInfo.GetLocalId(), errCode);
return errCode;
}
ACCOUNT_LOGI("SendMsgForAccountStop ok");
#endif // ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
return errCode;
}
@ -434,6 +496,9 @@ void IInnerOsAccountManager::Init()
CreateBaseAdminAccount();
CreateBaseStandardAccount();
StartAccount();
#ifdef ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
RestartActiveAccount();
#endif // ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
CleanGarbageAccounts();
}
@ -707,6 +772,7 @@ ErrCode IInnerOsAccountManager::QueryAllCreatedOsAccounts(std::vector<OsAccountI
ACCOUNT_LOGE("get osaccount info list error, errCode %{public}d.", errCode);
return ERR_OSACCOUNT_SERVICE_INNER_GET_ACCOUNT_LIST_ERROR;
}
#ifndef ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
for (auto osAccountInfosPtr = osAccountInfos.begin(); osAccountInfosPtr != osAccountInfos.end();
++osAccountInfosPtr) {
if (IsOsAccountIDInActiveList(osAccountInfosPtr->GetLocalId())) {
@ -715,6 +781,7 @@ ErrCode IInnerOsAccountManager::QueryAllCreatedOsAccounts(std::vector<OsAccountI
osAccountInfosPtr->SetIsActived(false);
}
}
#endif // ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
return ERR_OK;
}
@ -959,21 +1026,37 @@ ErrCode IInnerOsAccountManager::SetOsAccountProfilePhoto(const int id, const std
return ERR_OK;
}
void IInnerOsAccountManager::DeActivateOsAccount(const int id)
ErrCode IInnerOsAccountManager::DeActivateOsAccount(const int id)
{
if (id == Constants::ADMIN_LOCAL_ID) {
return;
ACCOUNT_LOGI("this osaccount can't deactive, id: %{public}d", Constants::ADMIN_LOCAL_ID);
return ERR_OK;
}
#ifdef ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
if (id == Constants::START_USER_ID) {
ACCOUNT_LOGI("this osaccount can't deactive, id: %{public}d", Constants::START_USER_ID);
return ERR_OK;
}
#endif // ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
OsAccountInfo osAccountInfo;
ErrCode errCode = osAccountControl_->GetOsAccountInfoById(id, osAccountInfo);
if (errCode != ERR_OK) {
ACCOUNT_LOGE("DeActivateOsAccount cannot get os account %{public}d info. error %{public}d.",
id, errCode);
return;
return errCode;
}
osAccountInfo.SetIsActived(false);
(void)osAccountControl_->UpdateOsAccount(osAccountInfo);
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;
}
#ifdef ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
EraseIdFromActiveList(osAccountInfo.GetLocalId());
#endif // ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
return ERR_OK;
}
ErrCode IInnerOsAccountManager::ActivateOsAccount(const int id)
@ -1001,7 +1084,7 @@ ErrCode IInnerOsAccountManager::ActivateOsAccount(const int id)
// check complete
if (!osAccountInfo.GetIsCreateCompleted()) {
RemoveLocalIdToOperating(id);
ACCOUNT_LOGE("account %{public}d is not Completed", id);
ACCOUNT_LOGE("account %{public}d is not completed", id);
return ERR_OSACCOUNT_SERVICE_INNER_ACCOUNT_IS_UNVERIFIED_ERROR;
}
@ -1036,7 +1119,7 @@ ErrCode IInnerOsAccountManager::SendMsgForAccountActivate(OsAccountInfo &osAccou
}
errCode = OsAccountInterface::SendToAMSAccountStart(osAccountInfo);
if (errCode != ERR_OK) {
ACCOUNT_LOGE("account %{public}d call am active failed, errCode %{public}d.",
ACCOUNT_LOGE("account %{public}d call ams active failed, errCode %{public}d.",
osAccountInfo.GetLocalId(), errCode);
return ERR_OSACCOUNT_SERVICE_INNER_SEND_AM_ACCOUNT_SWITCH_ERROR;
}
@ -1064,6 +1147,55 @@ ErrCode IInnerOsAccountManager::StartOsAccount(const int id)
ErrCode IInnerOsAccountManager::StopOsAccount(const int id)
{
#ifdef ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
if (id == Constants::START_USER_ID) {
ACCOUNT_LOGW("the %{public}d os account can't stop", id);
return ERR_OSACCOUNT_SERVICE_INNER_ACCOUNT_STOP_ACTIVE_ERROR;
}
if (IsLocalIdInOperating(id)) {
ACCOUNT_LOGW("the %{public}d already in operating", id);
return ERR_OSACCOUNT_SERVICE_INNER_ACCOUNT_OPERATING_ERROR;
}
AddLocalIdToOperating(id);
if (!IsOsAccountIDInActiveList(id)) {
RemoveLocalIdToOperating(id);
ACCOUNT_LOGW("account is %{public}d already stop", id);
return ERR_OSACCOUNT_SERVICE_INNER_ACCOUNT_ALREADY_ACTIVE_ERROR;
}
// get information
OsAccountInfo osAccountInfo;
ErrCode errCode = osAccountControl_->GetOsAccountInfoById(id, osAccountInfo);
if (errCode != ERR_OK) {
RemoveLocalIdToOperating(id);
ACCOUNT_LOGW("cannot find os account info by id:%{public}d, errCode %{public}d.", id, errCode);
return ERR_OSACCOUNT_SERVICE_INNER_SELECT_OSACCOUNT_BYID_ERROR;
}
// check complete
if (!osAccountInfo.GetIsCreateCompleted()) {
RemoveLocalIdToOperating(id);
ACCOUNT_LOGW("account %{public}d is not completed", id);
return ERR_OSACCOUNT_SERVICE_INNER_ACCOUNT_IS_UNVERIFIED_ERROR;
}
// check to be removed
if (osAccountInfo.GetToBeRemoved()) {
RemoveLocalIdToOperating(id);
ACCOUNT_LOGW("account %{public}d will be removed, don't need to stop!", id);
return ERR_OSACCOUNT_SERVICE_INNER_ACCOUNT_TO_BE_REMOVED_ERROR;
}
// stop
errCode = SendMsgForAccountStop(osAccountInfo);
if (errCode != ERR_OK) {
RemoveLocalIdToOperating(id);
ACCOUNT_LOGE("update %{public}d account info failed, errCode %{public}d.", id, errCode);
return errCode;
}
RemoveLocalIdToOperating(id);
ACCOUNT_LOGI("IInnerOsAccountManager ActivateOsAccount end");
#endif // ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
return ERR_OK;
}
@ -1245,11 +1377,27 @@ ErrCode IInnerOsAccountManager::QueryActiveOsAccountIds(std::vector<int32_t>& id
return ERR_OK;
}
void IInnerOsAccountManager::PushIDIntoActiveList(int32_t id)
void IInnerOsAccountManager::PushIdIntoActiveList(int32_t id)
{
std::lock_guard<std::mutex> lock(ativeMutex_);
activeAccountId_.push_back(id);
ValueTrace("activeid", (int64_t)id);
if (std::find(activeAccountId_.begin(), activeAccountId_.end(), id) == activeAccountId_.end()) {
activeAccountId_.push_back(id);
ValueTrace("activeId", (int64_t)id);
}
return;
}
void IInnerOsAccountManager::EraseIdFromActiveList(int32_t id)
{
std::lock_guard<std::mutex> lock(ativeMutex_);
if (std::find(activeAccountId_.begin(), activeAccountId_.end(), id) != activeAccountId_.end()) {
ACCOUNT_LOGE("EraseIdFromActiveList enter0");
activeAccountId_.erase(
std::remove(activeAccountId_.begin(), activeAccountId_.end(), id), activeAccountId_.end());
} else {
ACCOUNT_LOGI("os account is not in active list, no need to erase!");
}
ValueTrace("deActiveId", (int64_t)id);
}
bool IInnerOsAccountManager::IsOsAccountIDInActiveList(int32_t id)
@ -1270,18 +1418,18 @@ void IInnerOsAccountManager::CopyFromActiveList(std::vector<int32_t>& idList)
void IInnerOsAccountManager::RefreshActiveList(int32_t newId)
{
std::lock_guard<std::mutex> lock(ativeMutex_);
#ifdef ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
PushIdIntoActiveList(newId);
return;
#endif // ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
// deactivate old ids first
for (size_t i = 0; i < activeAccountId_.size(); ++i) {
DeActivateOsAccount(activeAccountId_[i]);
}
int32_t oldId = (activeAccountId_.empty() ? -1 : activeAccountId_[0]);
ReportOsAccountSwitchEvent(newId, oldId);
activeAccountId_.clear();
activeAccountId_.push_back(newId);
ValueTrace("activeid", (int64_t)newId);
PushIdIntoActiveList(newId);
}
} // namespace AccountSA
} // namespace OHOS

View File

@ -42,6 +42,9 @@ ohos_source_set("tools_acm_source_set") {
if (target_cpu == "arm") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
if (os_account_multiple_active_accounts) {
cflags += [ "-DENABLE_MULTIPLE_ACTIVE_ACCOUNTS" ]
}
cflags += [ "-pipe" ]
cflags_cc = [
"-Wdate-time",

View File

@ -30,6 +30,9 @@ const std::string HELP_MSG = "usage: acm <command> [<options>]\n"
" create create a local account with options\n"
" delete delete a local account with options\n"
" switch switch to a local account with options\n"
#ifdef ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
" stop stop the local accounts\n"
#endif // ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
" set set constraints of a local account\n"
" dump dump the info of local accounts\n";
@ -65,6 +68,12 @@ const std::string HELP_MSG_SWITCH =
" -h, --help list available commands\n"
" -i <local-account-id> switch a local account with an id\n";
const std::string HELP_MSG_STOP =
"usage: acm stop <options>\n"
"options list:\n"
" -h, --help list available commands\n"
" -i <local-account-id> stop a local account with an id\n";
const std::string HELP_MSG_OPTION_REQUIRES_AN_ARGUMENT = "error: option requires an argument.";
const std::string HELP_MSG_NO_NAME_OPTION = "error: -n <local-account-name> is expected";
const std::string HELP_MSG_NO_TYPE_OPTION = "error: -t <type> is expected";
@ -82,6 +91,8 @@ const std::string STRING_SET_OS_ACCOUNT_CONSTRAINTS_OK = "set constraints for th
const std::string STRING_SET_OS_ACCOUNT_CONSTRAINTS_NG = "error: failed to set constraints for the local account.";
const std::string STRING_SWITCH_OS_ACCOUNT_OK = "switch the local account successfully.";
const std::string STRING_SWITCH_OS_ACCOUNT_NG = "error: failed to switch the local account.";
const std::string STRING_STOP_OS_ACCOUNT_OK = "stop the local account successfully.";
const std::string STRING_STOP_OS_ACCOUNT_NG = "error: failed to stop the local account.";
} // namespace
class AccountCommand : public OHOS::AAFwk::ShellCommand {
@ -98,6 +109,7 @@ private:
ErrCode RunAsCreateCommand(void);
ErrCode RunAsDeleteCommand(void);
ErrCode RunAsSwitchCommand(void);
ErrCode RunAsStopCommand(void);
ErrCode RunAsDumpCommand(void);
ErrCode RunAsSetCommand(void);
@ -117,6 +129,9 @@ private:
ErrCode RunAsSwitchCommandError(void);
ErrCode RunAsSwitchCommandMissingOptionArgument(void);
ErrCode RunAsSwitchCommandExistentOptionArgument(const int &option, int &id);
ErrCode RunAsStopCommandError(void);
ErrCode RunAsStopCommandMissingOptionArgument(void);
ErrCode RunAsStopCommandExistentOptionArgument(const int &option, int &id);
ErrCode AnalyzeTypeArgument(OsAccountType &type);
ErrCode AnalyzeLocalIdArgument(int &id);

View File

@ -36,16 +36,16 @@ const struct option LONG_OPTIONS[] = {
AccountCommand::AccountCommand(int argc, char *argv[]) : ShellCommand(argc, argv, TOOL_NAME)
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
for (int i = 0; i < argc_; i++) {
ACCOUNT_LOGI("argv_[%{public}d]: %{public}s", i, argv_[i]);
ACCOUNT_LOGD("argv_[%{public}d]: %{public}s", i, argv_[i]);
}
}
ErrCode AccountCommand::CreateCommandMap()
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
commandMap_ = {
{"help", std::bind(&AccountCommand::RunAsHelpCommand, this)},
@ -54,6 +54,9 @@ ErrCode AccountCommand::CreateCommandMap()
{"dump", std::bind(&AccountCommand::RunAsDumpCommand, this)},
{"set", std::bind(&AccountCommand::RunAsSetCommand, this)},
{"switch", std::bind(&AccountCommand::RunAsSwitchCommand, this)},
#ifdef ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
{"stop", std::bind(&AccountCommand::RunAsStopCommand, this)},
#endif // ENABLE_MULTIPLE_ACTIVE_ACCOUNTS
};
return ERR_OK;
@ -61,14 +64,14 @@ ErrCode AccountCommand::CreateCommandMap()
ErrCode AccountCommand::CreateMessageMap()
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
return ERR_OK;
}
ErrCode AccountCommand::init()
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
@ -84,7 +87,7 @@ ErrCode AccountCommand::init()
ErrCode AccountCommand::RunAsHelpCommand(void)
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
resultReceiver_.append(HELP_MSG);
@ -93,7 +96,7 @@ ErrCode AccountCommand::RunAsHelpCommand(void)
ErrCode AccountCommand::RunAsCreateCommand(void)
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
@ -106,7 +109,7 @@ ErrCode AccountCommand::RunAsCreateCommand(void)
counter++;
int option = getopt_long(argc_, argv_, SHORT_OPTIONS.c_str(), LONG_OPTIONS, nullptr);
ACCOUNT_LOGI("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind);
ACCOUNT_LOGD("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind);
if (option == -1) {
if (counter == 1) {
@ -125,7 +128,7 @@ ErrCode AccountCommand::RunAsCreateCommand(void)
if (result == ERR_OK) {
if (name.size() == 0 || osAccountType == static_cast<OsAccountType>(-1)) {
ACCOUNT_LOGI("'acm create' without enough options");
ACCOUNT_LOGD("'acm create' without enough options");
if (name.size() == 0) {
resultReceiver_.append(HELP_MSG_NO_NAME_OPTION + "\n");
@ -156,14 +159,14 @@ ErrCode AccountCommand::RunAsCreateCommand(void)
}
}
ACCOUNT_LOGI("result = %{public}d, name = %{public}s, type = %{public}d", result, name.c_str(), osAccountType);
ACCOUNT_LOGD("result = %{public}d, name = %{public}s, type = %{public}d", result, name.c_str(), osAccountType);
return result;
}
ErrCode AccountCommand::RunAsDeleteCommand(void)
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
@ -175,7 +178,7 @@ ErrCode AccountCommand::RunAsDeleteCommand(void)
counter++;
int option = getopt_long(argc_, argv_, SHORT_OPTIONS.c_str(), LONG_OPTIONS, nullptr);
ACCOUNT_LOGI("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind);
ACCOUNT_LOGD("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind);
if (option == -1) {
if (counter == 1) {
@ -206,14 +209,14 @@ ErrCode AccountCommand::RunAsDeleteCommand(void)
}
}
ACCOUNT_LOGI("result = %{public}d, id = %{public}d", result, id);
ACCOUNT_LOGD("result = %{public}d, id = %{public}d", result, id);
return result;
}
ErrCode AccountCommand::RunAsDumpCommand(void)
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
@ -225,7 +228,7 @@ ErrCode AccountCommand::RunAsDumpCommand(void)
counter++;
int option = getopt_long(argc_, argv_, SHORT_OPTIONS.c_str(), LONG_OPTIONS, nullptr);
ACCOUNT_LOGI("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind);
ACCOUNT_LOGD("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind);
if (option == -1) {
if (counter == 1) {
@ -259,14 +262,14 @@ ErrCode AccountCommand::RunAsDumpCommand(void)
}
}
ACCOUNT_LOGI("result = %{public}d, id = %{public}d", result, id);
ACCOUNT_LOGD("result = %{public}d, id = %{public}d", result, id);
return result;
}
ErrCode AccountCommand::RunAsSetCommand(void)
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
@ -280,7 +283,7 @@ ErrCode AccountCommand::RunAsSetCommand(void)
counter++;
int option = getopt_long(argc_, argv_, SHORT_OPTIONS.c_str(), LONG_OPTIONS, nullptr);
ACCOUNT_LOGI("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind);
ACCOUNT_LOGD("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind);
if (option == -1) {
if (counter == 1) {
@ -299,7 +302,7 @@ ErrCode AccountCommand::RunAsSetCommand(void)
if (result == ERR_OK) {
if (id == -1 || constraints.size() == 0) {
ACCOUNT_LOGI("'acm set' without enough options");
ACCOUNT_LOGD("'acm set' without enough options");
if (id == -1) {
resultReceiver_.append(HELP_MSG_NO_ID_OPTION + "\n");
@ -327,9 +330,9 @@ ErrCode AccountCommand::RunAsSetCommand(void)
}
}
ACCOUNT_LOGI("result = %{public}d, id = %{public}d, enable = %{public}d", result, id, enable);
ACCOUNT_LOGD("result = %{public}d, id = %{public}d, enable = %{public}d", result, id, enable);
for (auto constraint : constraints) {
ACCOUNT_LOGI("constraint = %{public}s", constraint.c_str());
ACCOUNT_LOGD("constraint = %{public}s", constraint.c_str());
}
return result;
@ -337,7 +340,7 @@ ErrCode AccountCommand::RunAsSetCommand(void)
ErrCode AccountCommand::RunAsSwitchCommand(void)
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
@ -349,7 +352,7 @@ ErrCode AccountCommand::RunAsSwitchCommand(void)
counter++;
int option = getopt_long(argc_, argv_, SHORT_OPTIONS.c_str(), LONG_OPTIONS, nullptr);
ACCOUNT_LOGI("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind);
ACCOUNT_LOGD("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind);
if (option == -1) {
if (counter == 1) {
@ -380,14 +383,64 @@ ErrCode AccountCommand::RunAsSwitchCommand(void)
}
}
ACCOUNT_LOGI("result = %{public}d, id = %{public}d", result, id);
ACCOUNT_LOGD("result = %{public}d, id = %{public}d", result, id);
return result;
}
ErrCode AccountCommand::RunAsStopCommand(void)
{
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
int counter = 0;
int id = -1;
while (true) {
counter++;
int option = getopt_long(argc_, argv_, SHORT_OPTIONS.c_str(), LONG_OPTIONS, nullptr);
ACCOUNT_LOGD("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind);
if (option == -1) {
if (counter == 1) {
result = RunAsStopCommandError();
}
break;
}
if (option == '?') {
result = RunAsStopCommandMissingOptionArgument();
break;
}
result = RunAsStopCommandExistentOptionArgument(option, id);
}
if (result != ERR_OK) {
resultReceiver_.append(HELP_MSG_STOP);
} else {
/* stop */
// stop an os account
result = osAccountPtr_->StopOsAccount(id);
if (result == ERR_OK) {
resultReceiver_ = STRING_STOP_OS_ACCOUNT_OK + "\n";
} else {
resultReceiver_ = STRING_STOP_OS_ACCOUNT_NG + "\n";
}
}
ACCOUNT_LOGD("result = %{public}d, id = %{public}d", result, id);
return result;
}
ErrCode AccountCommand::RunAsCreateCommandError(void)
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
@ -399,20 +452,20 @@ ErrCode AccountCommand::RunAsCreateCommandError(void)
if (strcmp(argv_[optind], cmd_.c_str()) == 0) {
// 'acm create' with no option: acm create
// 'acm create' with a wrong argument: acm create xxx
ACCOUNT_LOGI("'acm create' with no option.");
ACCOUNT_LOGD("'acm create' with no option.");
resultReceiver_.append(HELP_MSG_NO_OPTION + "\n");
result = ERR_INVALID_VALUE;
}
ACCOUNT_LOGI("end, result = %{public}d", result);
ACCOUNT_LOGD("end, result = %{public}d", result);
return result;
}
ErrCode AccountCommand::RunAsCreateCommandMissingOptionArgument(void)
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
@ -420,7 +473,7 @@ ErrCode AccountCommand::RunAsCreateCommandMissingOptionArgument(void)
case 'n': {
// 'acm create -n <name>' with no argument: acm create -n
// 'acm create --name <name>' with no argument: acm create --name
ACCOUNT_LOGI("'acm create -n' with no argument.");
ACCOUNT_LOGD("'acm create -n' with no argument.");
resultReceiver_.append(HELP_MSG_OPTION_REQUIRES_AN_ARGUMENT + "\n");
result = ERR_INVALID_VALUE;
@ -429,7 +482,7 @@ ErrCode AccountCommand::RunAsCreateCommandMissingOptionArgument(void)
case 't': {
// 'acm create -t <type>' with no argument: acm create -t
// 'acm create --type <type>' with no argument: acm create --type
ACCOUNT_LOGI("'acm create -t' with no argument.");
ACCOUNT_LOGD("'acm create -t' with no argument.");
resultReceiver_.append(HELP_MSG_OPTION_REQUIRES_AN_ARGUMENT + "\n");
@ -442,7 +495,7 @@ ErrCode AccountCommand::RunAsCreateCommandMissingOptionArgument(void)
std::string unknownOption = "";
std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption);
ACCOUNT_LOGI("'acm create' with an unknown option.");
ACCOUNT_LOGD("'acm create' with an unknown option.");
resultReceiver_.append(unknownOptionMsg);
result = ERR_INVALID_VALUE;
@ -454,7 +507,7 @@ ErrCode AccountCommand::RunAsCreateCommandMissingOptionArgument(void)
std::string unknownOption = "";
std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption);
ACCOUNT_LOGI("'acm create' with an unknown option.");
ACCOUNT_LOGD("'acm create' with an unknown option.");
resultReceiver_.append(unknownOptionMsg);
result = ERR_INVALID_VALUE;
@ -462,7 +515,7 @@ ErrCode AccountCommand::RunAsCreateCommandMissingOptionArgument(void)
}
}
ACCOUNT_LOGI("end, result = %{public}d", result);
ACCOUNT_LOGD("end, result = %{public}d", result);
return result;
}
@ -470,7 +523,7 @@ ErrCode AccountCommand::RunAsCreateCommandMissingOptionArgument(void)
ErrCode AccountCommand::RunAsCreateCommandExistentOptionArgument(
const int &option, std::string &name, OsAccountType &type)
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
@ -501,14 +554,14 @@ ErrCode AccountCommand::RunAsCreateCommandExistentOptionArgument(
}
}
ACCOUNT_LOGI("end, result = %{public}d", result);
ACCOUNT_LOGD("end, result = %{public}d", result);
return result;
}
ErrCode AccountCommand::RunAsDeleteCommandError(void)
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
@ -520,20 +573,20 @@ ErrCode AccountCommand::RunAsDeleteCommandError(void)
if (strcmp(argv_[optind], cmd_.c_str()) == 0) {
// 'acm delete' with no option: acm delete
// 'acm delete' with a wrong argument: acm delete xxx
ACCOUNT_LOGI("'acm delete' with no option.");
ACCOUNT_LOGD("'acm delete' with no option.");
resultReceiver_.append(HELP_MSG_NO_OPTION + "\n");
result = ERR_INVALID_VALUE;
}
ACCOUNT_LOGI("end, result = %{public}d", result);
ACCOUNT_LOGD("end, result = %{public}d", result);
return result;
}
ErrCode AccountCommand::RunAsDeleteCommandMissingOptionArgument(void)
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
@ -541,7 +594,7 @@ ErrCode AccountCommand::RunAsDeleteCommandMissingOptionArgument(void)
case 'i': {
// 'acm delete -i <id>' with no argument: acm delete -i
// 'acm delete --id <id>' with no argument: acm delete --id
ACCOUNT_LOGI("'acm delete -i' with no argument.");
ACCOUNT_LOGD("'acm delete -i' with no argument.");
resultReceiver_.append(HELP_MSG_OPTION_REQUIRES_AN_ARGUMENT + "\n");
result = ERR_INVALID_VALUE;
@ -553,7 +606,7 @@ ErrCode AccountCommand::RunAsDeleteCommandMissingOptionArgument(void)
std::string unknownOption = "";
std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption);
ACCOUNT_LOGI("'acm delete' with an unknown option.");
ACCOUNT_LOGD("'acm delete' with an unknown option.");
resultReceiver_.append(unknownOptionMsg);
result = ERR_INVALID_VALUE;
@ -565,7 +618,7 @@ ErrCode AccountCommand::RunAsDeleteCommandMissingOptionArgument(void)
std::string unknownOption = "";
std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption);
ACCOUNT_LOGI("'acm delete' with an unknown option.");
ACCOUNT_LOGD("'acm delete' with an unknown option.");
resultReceiver_.append(unknownOptionMsg);
result = ERR_INVALID_VALUE;
@ -578,7 +631,7 @@ ErrCode AccountCommand::RunAsDeleteCommandMissingOptionArgument(void)
ErrCode AccountCommand::RunAsDeleteCommandExistentOptionArgument(const int &option, int &id)
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
@ -608,7 +661,7 @@ ErrCode AccountCommand::RunAsDeleteCommandExistentOptionArgument(const int &opti
ErrCode AccountCommand::RunAsDumpCommandError(void)
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
@ -620,20 +673,20 @@ ErrCode AccountCommand::RunAsDumpCommandError(void)
if (strcmp(argv_[optind], cmd_.c_str()) == 0) {
// 'acm dump' with no option: acm dump
// 'acm dump' with a wrong argument: acm dump xxx
ACCOUNT_LOGI("'acm dump' with no option.");
ACCOUNT_LOGD("'acm dump' with no option.");
resultReceiver_.append(HELP_MSG_NO_OPTION + "\n");
result = ERR_INVALID_VALUE;
}
ACCOUNT_LOGI("end, result = %{public}d", result);
ACCOUNT_LOGD("end, result = %{public}d", result);
return result;
}
ErrCode AccountCommand::RunAsDumpCommandMissingOptionArgument(void)
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
@ -641,7 +694,7 @@ ErrCode AccountCommand::RunAsDumpCommandMissingOptionArgument(void)
case 'i': {
// 'acm dump -i <id>' with no argument: acm dump -i
// 'acm dump --id <id>' with no argument: acm dump --id
ACCOUNT_LOGI("'acm dump -i' with no argument.");
ACCOUNT_LOGD("'acm dump -i' with no argument.");
resultReceiver_.append(HELP_MSG_OPTION_REQUIRES_AN_ARGUMENT + "\n");
result = ERR_INVALID_VALUE;
@ -653,7 +706,7 @@ ErrCode AccountCommand::RunAsDumpCommandMissingOptionArgument(void)
std::string unknownOption = "";
std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption);
ACCOUNT_LOGI("'acm dump' with an unknown option.");
ACCOUNT_LOGD("'acm dump' with an unknown option.");
resultReceiver_.append(unknownOptionMsg);
result = ERR_INVALID_VALUE;
@ -665,7 +718,7 @@ ErrCode AccountCommand::RunAsDumpCommandMissingOptionArgument(void)
std::string unknownOption = "";
std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption);
ACCOUNT_LOGI("'acm dump' with an unknown option.");
ACCOUNT_LOGD("'acm dump' with an unknown option.");
resultReceiver_.append(unknownOptionMsg);
result = ERR_INVALID_VALUE;
@ -678,7 +731,7 @@ ErrCode AccountCommand::RunAsDumpCommandMissingOptionArgument(void)
ErrCode AccountCommand::RunAsDumpCommandExistentOptionArgument(const int &option, int &id)
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
@ -708,14 +761,14 @@ ErrCode AccountCommand::RunAsDumpCommandExistentOptionArgument(const int &option
}
}
ACCOUNT_LOGI("end, result = %{public}d, id = %{public}d", result, id);
ACCOUNT_LOGD("end, result = %{public}d, id = %{public}d", result, id);
return result;
}
ErrCode AccountCommand::RunAsSetCommandError(void)
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
@ -727,20 +780,20 @@ ErrCode AccountCommand::RunAsSetCommandError(void)
if (strcmp(argv_[optind], cmd_.c_str()) == 0) {
// 'acm set' with no option: acm set
// 'acm set' with a wrong argument: acm set xxx
ACCOUNT_LOGI("'acm set' with no option.");
ACCOUNT_LOGD("'acm set' with no option.");
resultReceiver_.append(HELP_MSG_NO_OPTION + "\n");
result = ERR_INVALID_VALUE;
}
ACCOUNT_LOGI("end, result = %{public}d", result);
ACCOUNT_LOGD("end, result = %{public}d", result);
return result;
}
ErrCode AccountCommand::RunAsSetCommandMissingOptionArgument(void)
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
@ -748,7 +801,7 @@ ErrCode AccountCommand::RunAsSetCommandMissingOptionArgument(void)
case 'i': {
// 'acm set -i <id>' with no argument: acm set -i
// 'acm set --id <id>' with no argument: acm set --id
ACCOUNT_LOGI("'acm set -i' with no argument.");
ACCOUNT_LOGD("'acm set -i' with no argument.");
resultReceiver_.append(HELP_MSG_OPTION_REQUIRES_AN_ARGUMENT + "\n");
result = ERR_INVALID_VALUE;
@ -757,7 +810,7 @@ ErrCode AccountCommand::RunAsSetCommandMissingOptionArgument(void)
case 'c': {
// 'acm set -c <constraints>' with no argument: acm set -c
// 'acm set --constraint <constraints>' with no argument: acm set --constraint
ACCOUNT_LOGI("'acm set -c' with no argument.");
ACCOUNT_LOGD("'acm set -c' with no argument.");
resultReceiver_.append(HELP_MSG_OPTION_REQUIRES_AN_ARGUMENT + "\n");
result = ERR_INVALID_VALUE;
@ -769,7 +822,7 @@ ErrCode AccountCommand::RunAsSetCommandMissingOptionArgument(void)
std::string unknownOption = "";
std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption);
ACCOUNT_LOGI("'acm set' with an unknown option.");
ACCOUNT_LOGD("'acm set' with an unknown option.");
resultReceiver_.append(unknownOptionMsg);
result = ERR_INVALID_VALUE;
@ -781,7 +834,7 @@ ErrCode AccountCommand::RunAsSetCommandMissingOptionArgument(void)
std::string unknownOption = "";
std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption);
ACCOUNT_LOGI("'set dump' with an unknown option.");
ACCOUNT_LOGD("'set dump' with an unknown option.");
resultReceiver_.append(unknownOptionMsg);
result = ERR_INVALID_VALUE;
@ -795,7 +848,7 @@ ErrCode AccountCommand::RunAsSetCommandMissingOptionArgument(void)
ErrCode AccountCommand::RunAsSetCommandExistentOptionArgument(
const int &option, int &id, std::vector<std::string> &constraints, bool &enable)
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
@ -832,14 +885,14 @@ ErrCode AccountCommand::RunAsSetCommandExistentOptionArgument(
}
}
ACCOUNT_LOGI("end, result = %{public}d, id = %{public}d", result, id);
ACCOUNT_LOGD("end, result = %{public}d, id = %{public}d", result, id);
return result;
}
ErrCode AccountCommand::RunAsSwitchCommandError(void)
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
@ -851,20 +904,45 @@ ErrCode AccountCommand::RunAsSwitchCommandError(void)
if (strcmp(argv_[optind], cmd_.c_str()) == 0) {
// 'acm switch' with no option: acm switch
// 'acm switch' with a wrong argument: acm switch xxx
ACCOUNT_LOGI("'acm switch' with no option.");
ACCOUNT_LOGD("'acm switch' with no option.");
resultReceiver_.append(HELP_MSG_NO_OPTION + "\n");
result = ERR_INVALID_VALUE;
}
ACCOUNT_LOGI("end, result = %{public}d", result);
ACCOUNT_LOGD("end, result = %{public}d", result);
return result;
}
ErrCode AccountCommand::RunAsStopCommandError(void)
{
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
if (optind < 0 || optind >= argc_) {
return ERR_INVALID_VALUE;
}
// When scanning the first argument
if (strcmp(argv_[optind], cmd_.c_str()) == 0) {
// 'acm stop' with no option: acm stop
// 'acm stop' with a wrong argument: acm stop xxx
ACCOUNT_LOGD("'acm stop' with no option.");
resultReceiver_.append(HELP_MSG_NO_OPTION + "\n");
result = ERR_INVALID_VALUE;
}
ACCOUNT_LOGD("end, result = %{public}d", result);
return result;
}
ErrCode AccountCommand::RunAsSwitchCommandMissingOptionArgument(void)
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
@ -872,7 +950,7 @@ ErrCode AccountCommand::RunAsSwitchCommandMissingOptionArgument(void)
case 'i': {
// 'acm switch -i <id>' with no argument: acm switch -i
// 'acm switch --id <id>' with no argument: acm switch --id
ACCOUNT_LOGI("'acm switch -i' with no argument.");
ACCOUNT_LOGD("'acm switch -i' with no argument.");
resultReceiver_.append(HELP_MSG_OPTION_REQUIRES_AN_ARGUMENT + "\n");
result = ERR_INVALID_VALUE;
@ -884,7 +962,7 @@ ErrCode AccountCommand::RunAsSwitchCommandMissingOptionArgument(void)
std::string unknownOption = "";
std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption);
ACCOUNT_LOGI("'acm switch' with an unknown option.");
ACCOUNT_LOGD("'acm switch' with an unknown option.");
resultReceiver_.append(unknownOptionMsg);
result = ERR_INVALID_VALUE;
@ -896,7 +974,40 @@ ErrCode AccountCommand::RunAsSwitchCommandMissingOptionArgument(void)
std::string unknownOption = "";
std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption);
ACCOUNT_LOGI("'acm switch' with an unknown option.");
ACCOUNT_LOGD("'acm switch' with an unknown option.");
resultReceiver_.append(unknownOptionMsg);
result = ERR_INVALID_VALUE;
break;
}
}
return result;
}
ErrCode AccountCommand::RunAsStopCommandMissingOptionArgument(void)
{
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
switch (optopt) {
case 'i': {
// 'acm stop -i <id>' with no argument: acm stop -i
// 'acm stop --id <id>' with no argument: acm stop --id
ACCOUNT_LOGD("'acm stop -i' with no argument.");
resultReceiver_.append(HELP_MSG_OPTION_REQUIRES_AN_ARGUMENT + "\n");
result = ERR_INVALID_VALUE;
break;
}
default: {
// 'acm stop' with an unknown option: acm stop -x
// 'acm stop' with an unknown option: acm stop -xxx
std::string unknownOption = "";
std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption);
ACCOUNT_LOGD("'acm stop' with an unknown option.");
resultReceiver_.append(unknownOptionMsg);
result = ERR_INVALID_VALUE;
@ -909,7 +1020,7 @@ ErrCode AccountCommand::RunAsSwitchCommandMissingOptionArgument(void)
ErrCode AccountCommand::RunAsSwitchCommandExistentOptionArgument(const int &option, int &id)
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
@ -937,6 +1048,33 @@ ErrCode AccountCommand::RunAsSwitchCommandExistentOptionArgument(const int &opti
return result;
}
ErrCode AccountCommand::RunAsStopCommandExistentOptionArgument(const int &option, int &id)
{
ACCOUNT_LOGD("enter");
ErrCode result = ERR_OK;
switch (option) {
case 'h': {
// 'acm stop -h'
// 'acm stop --help'
result = ERR_INVALID_VALUE;
break;
}
case 'i': {
// 'acm stop -i <id>'
// 'acm stop --id <id>'
result = AnalyzeLocalIdArgument(id);
break;
}
default: {
break;
}
}
return result;
}
ErrCode AccountCommand::AnalyzeTypeArgument(OsAccountType &type)
{
ErrCode result = ERR_OK;
@ -977,10 +1115,10 @@ ErrCode AccountCommand::AnalyzeLocalIdArgument(int &id)
ErrCode AccountCommand::AnalyzeConstraintArgument(std::vector<std::string> &constraints)
{
ACCOUNT_LOGI("enter");
ACCOUNT_LOGD("enter");
std::string constraintsByUser = optarg;
ACCOUNT_LOGI("constraintsByUser = %{public}s", constraintsByUser.c_str());
ACCOUNT_LOGD("constraintsByUser = %{public}s", constraintsByUser.c_str());
constraints.clear();
std::string constraint = "";
@ -990,13 +1128,13 @@ ErrCode AccountCommand::AnalyzeConstraintArgument(std::vector<std::string> &cons
size_t next = 0;
while ((next = constraintsByUser.find(delimiter, last)) != std::string::npos) {
constraint = constraintsByUser.substr(last, next - last);
ACCOUNT_LOGI("constraint = %{public}s", constraint.c_str());
ACCOUNT_LOGD("constraint = %{public}s", constraint.c_str());
constraints.emplace_back(constraint);
last = next + 1;
}
constraint = constraintsByUser.substr(last);
ACCOUNT_LOGI("constraint = %{public}s", constraint.c_str());
ACCOUNT_LOGD("constraint = %{public}s", constraint.c_str());
constraints.emplace_back(constraint);
return ERR_OK;