From c0d0c59b29ab02b66025651b04526504f30df28d Mon Sep 17 00:00:00 2001 From: zero-cyc Date: Fri, 1 Jul 2022 16:30:30 +0800 Subject: [PATCH] notification dump Signed-off-by: zero-cyc Change-Id: I55262fcba0d72645cd6100f39f85fbc0bd1cb29a --- .../dump/include/notification_shell_command.h | 5 +-- tools/dump/src/notification_shell_command.cpp | 31 ++++++++++++------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/tools/dump/include/notification_shell_command.h b/tools/dump/include/notification_shell_command.h index f86e2a53b..4da8e2f5b 100644 --- a/tools/dump/include/notification_shell_command.h +++ b/tools/dump/include/notification_shell_command.h @@ -45,8 +45,9 @@ private: ErrCode RunHelp(); void CheckDumpOpt(); - void SetDumpCmdInfo(std::string &cmd, std::string &bundle, ErrCode &ret); - ErrCode RunDumpCmd(const std::string& cmd, const std::string& bundle, std::vector &infos); + void SetDumpCmdInfo(std::string &cmd, std::string &bundle, int32_t &userId, ErrCode &ret); + ErrCode RunDumpCmd(const std::string& cmd, const std::string& bundle, int32_t userId, + std::vector &infos); private: std::shared_ptr ans_; diff --git a/tools/dump/src/notification_shell_command.cpp b/tools/dump/src/notification_shell_command.cpp index af45fce40..44dcb37f1 100644 --- a/tools/dump/src/notification_shell_command.cpp +++ b/tools/dump/src/notification_shell_command.cpp @@ -28,9 +28,9 @@ constexpr char COMMAND_ACTIVE[] = "active"; constexpr char COMMAND_RECENT[] = "recent"; #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED constexpr char COMMAND_DISTRIBUTED[] = "distributed"; -constexpr char SHORT_OPTIONS[] = "hARDb:"; +constexpr char SHORT_OPTIONS[] = "hARDb:u:"; #else -constexpr char SHORT_OPTIONS[] = "hARb:"; +constexpr char SHORT_OPTIONS[] = "hARb:u:"; #endif constexpr char COMMAND_SET_RECENT_COUNT[] = "setRecentCount"; const struct option LONG_OPTIONS[] = { @@ -41,6 +41,7 @@ const struct option LONG_OPTIONS[] = { {COMMAND_DISTRIBUTED, no_argument, nullptr, 'D'}, #endif {"bundle", required_argument, nullptr, 'b'}, + {"user-id", required_argument, nullptr, 'u'}, }; constexpr char HELP_MSG[] = "usage: anm []\n" @@ -55,9 +56,10 @@ constexpr char DUMP_HELP_MSG[] = #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED " --distributed, -D list all distributed notifications by remote device\n" #endif - " --active, -A list all active notifications\n" - " --recent, -R list recent notifications\n" - " --bundle, -b specified a bundle filter\n"; + " --active, -A list all active notifications\n" + " --recent, -R list recent notifications\n" + " --bundle, -b dump the info filter by the specified bundle name\n" + " --user-id, -u dump the info filter by the specified userId\n"; constexpr char SETTING_SHORT_OPTIONS[] = "c:"; const struct option SETTING_LONG_OPTIONS[] = { @@ -114,7 +116,8 @@ ErrCode NotificationShellCommand::RunAsDumpCommand() std::vector infos; std::string cmd; std::string bundle; - SetDumpCmdInfo(cmd, bundle, ret); + int32_t userId = SUBSCRIBE_USER_INIT; + SetDumpCmdInfo(cmd, bundle, userId, ret); if (ret != ERR_OK) { return ret; } @@ -125,7 +128,7 @@ ErrCode NotificationShellCommand::RunAsDumpCommand() return ERR_INVALID_VALUE; } - ret = RunDumpCmd(cmd, bundle, infos); + ret = RunDumpCmd(cmd, bundle, userId, infos); int index = 0; for (const auto &info : infos) { resultReceiver_.append("No." + std::to_string(++index) + "\n"); @@ -135,10 +138,10 @@ ErrCode NotificationShellCommand::RunAsDumpCommand() } ErrCode NotificationShellCommand::RunDumpCmd(const std::string& cmd, const std::string& bundle, - std::vector &infos) + int32_t userId, std::vector &infos) { if (ans_ != nullptr) { - ErrCode ret = ans_->ShellDump(cmd, bundle, SUBSCRIBE_USER_INIT, infos); + ErrCode ret = ans_->ShellDump(cmd, bundle, userId, infos); if (strncmp(cmd.c_str(), COMMAND_SET_RECENT_COUNT, strlen(COMMAND_SET_RECENT_COUNT)) == 0) { if (ret == ERR_OK) { resultReceiver_.append("set recent count success\n"); @@ -153,7 +156,7 @@ ErrCode NotificationShellCommand::RunDumpCmd(const std::string& cmd, const std:: return ERR_ANS_SERVICE_NOT_CONNECTED; } -void NotificationShellCommand::SetDumpCmdInfo(std::string &cmd, std::string &bundle, ErrCode &ret) +void NotificationShellCommand::SetDumpCmdInfo(std::string &cmd, std::string &bundle, int32_t &userId, ErrCode &ret) { int option = -1; bool hasOption = false; @@ -183,6 +186,9 @@ void NotificationShellCommand::SetDumpCmdInfo(std::string &cmd, std::string &bun case 'b': bundle = optarg; break; + case 'u': + userId = atoi(optarg); + break; default: resultReceiver_.append(DUMP_HELP_MSG); break; @@ -200,6 +206,9 @@ void NotificationShellCommand::CheckDumpOpt() case 'b': resultReceiver_.append("error: option 'b' requires a value.\n"); break; + case 'u': + resultReceiver_.append("error: option 'u' requires a value.\n"); + break; default: resultReceiver_.append("error: unknown option.\n"); break; @@ -228,7 +237,7 @@ ErrCode NotificationShellCommand::RunAsSettingCommand() } std::string cmd = COMMAND_SET_RECENT_COUNT; cmd.append(" ").append(std::string(optarg)); - return RunDumpCmd(cmd, "", infos); + return RunDumpCmd(cmd, "", SUBSCRIBE_USER_INIT, infos); } resultReceiver_.append(SETTING_HELP_MSG); return ERR_INVALID_VALUE; -- Gitee