From e040f0320a1d90fe21b49422cd3966556629c2f2 Mon Sep 17 00:00:00 2001 From: wanchengzhen Date: Thu, 17 Feb 2022 18:01:55 +0000 Subject: [PATCH 1/9] ANR Repair Registration Mechanism Signed-off-by: wanchengzhen --- .../AMS/mock_serviceability_manager_service.h | 4 ++-- .../mock/include/mock_ability_manager_service.h | 4 ++-- .../kits/appkit/native/app/src/main_thread.cpp | 17 ++++++++++++++--- .../mock/AMS/mock_ability_manager_service.h | 4 ++-- .../AMS/mock_serviceability_manager_service.h | 4 ++-- .../include/ability_manager_client.h | 8 ++++++++ .../include/ability_manager_errors.h | 5 +++++ .../include/ability_manager_interface.h | 4 +++- .../abilitymgr/include/ability_manager_proxy.h | 4 +++- .../include/ability_manager_service.h | 3 ++- .../abilitymgr/src/ability_manager_client.cpp | 8 ++++++++ .../abilitymgr/src/ability_manager_proxy.cpp | 13 ++++++------- .../abilitymgr/src/ability_manager_service.cpp | 7 ++++--- .../abilitymgr/src/ability_manager_stub.cpp | 4 ++-- .../ability_manager_stub_mock.h | 4 ++-- .../ability_manager_stub_impl_mock.h | 4 ++-- .../test/mock/include/mock_ability_manager.h | 4 ++-- .../mock/include/mock_ability_mgr_service.h | 4 ++-- tools/test/mock/mock_ability_manager_stub.h | 4 ++-- 19 files changed, 73 insertions(+), 36 deletions(-) diff --git a/frameworks/kits/ability/ability_runtime/test/mock/AMS/mock_serviceability_manager_service.h b/frameworks/kits/ability/ability_runtime/test/mock/AMS/mock_serviceability_manager_service.h index 8dd975e778..a028c81742 100644 --- a/frameworks/kits/ability/ability_runtime/test/mock/AMS/mock_serviceability_manager_service.h +++ b/frameworks/kits/ability/ability_runtime/test/mock/AMS/mock_serviceability_manager_service.h @@ -278,9 +278,9 @@ public: return true; } - bool SendANRProcessID(int pid) override + int SendANRProcessID(int pid) override { - return true; + return 0; } int RegisterSnapshotHandler(const sptr& handler) override diff --git a/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h b/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h index bc54e39062..8aad0460ee 100644 --- a/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h +++ b/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h @@ -276,9 +276,9 @@ public: return 0; } - virtual bool SendANRProcessID(int pid) override + virtual int SendANRProcessID(int pid) override { - return true; + return 0; } virtual int StartUserTest(const Want &want, const sptr &observer) override diff --git a/frameworks/kits/appkit/native/app/src/main_thread.cpp b/frameworks/kits/appkit/native/app/src/main_thread.cpp index 0afeb32904..798383f7b7 100644 --- a/frameworks/kits/appkit/native/app/src/main_thread.cpp +++ b/frameworks/kits/appkit/native/app/src/main_thread.cpp @@ -1376,13 +1376,16 @@ void MainThread::HandleANRProcess(int sigMessage) { if (sigMessage == SIGUSR1) { int rFD = -1; + std::string mainThreadStackInfo; if ((rFD = RequestFileDescriptor(int32_t(FaultLoggerType::CPP_CRASH))) < 0) { APP_LOGE("MainThread::HandleANRProcess request file eescriptor failed"); } auto jsRuntime = std::move((std::unique_ptr&)applicationForAnr_->GetRuntime()); - std::string mainThreadStackInfo = jsRuntime->BuildNativeAndJsBackStackTrace(); - if (write(rFD, mainThreadStackInfo.c_str(), mainThreadStackInfo.size()) != mainThreadStackInfo.size()) { - APP_LOGE("MainThread::HandleANRProcess write main thread stack info failed"); + if (jsRuntime != nullptr) { + mainThreadStackInfo= jsRuntime->BuildNativeAndJsBackStackTrace(); + if (write(rFD, mainThreadStackInfo.c_str(), mainThreadStackInfo.size()) != mainThreadStackInfo.size()) { + APP_LOGE("MainThread::HandleANRProcess write main thread stack info failed"); + } } OHOS::HiviewDFX::DfxDumpCatcher dumplog; std::string proStackInfo; @@ -1418,6 +1421,14 @@ void MainThread::Start() return; } + APP_LOGI("MainThread::main Register sig handle start"); + struct sigaction sigAct; + sigemptyset(&sigAct.sa_mask); + sigAct.sa_flags = 0; + sigAct.sa_handler = &MainThread::HandleANRProcess; + sigaction(SIGUSR1, &sigAct, NULL); + APP_LOGI("MainThread::main Register sig handle end"); + APP_LOGI("MainThread::main called start Init"); thread->Init(runner, runnerWatchDog); APP_LOGI("MainThread::main called end Init"); diff --git a/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h b/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h index 59d7862913..cd237cd566 100644 --- a/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h +++ b/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h @@ -239,9 +239,9 @@ public: { return true; } - virtual bool SendANRProcessID(int pid) override + virtual int SendANRProcessID(int pid) override { - return true; + return 0; } virtual int StartUserTest(const Want &want, const sptr &observer) override diff --git a/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h b/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h index bab683317a..e38951442a 100644 --- a/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h +++ b/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h @@ -260,9 +260,9 @@ public: { return true; } - virtual bool SendANRProcessID(int pid) override + virtual int SendANRProcessID(int pid) override { - return true; + return 0; } virtual int StartUserTest(const Want &want, const sptr &observer) override diff --git a/interfaces/innerkits/ability_manager/include/ability_manager_client.h b/interfaces/innerkits/ability_manager/include/ability_manager_client.h index aa9e4a9d77..18471698a3 100644 --- a/interfaces/innerkits/ability_manager/include/ability_manager_client.h +++ b/interfaces/innerkits/ability_manager/include/ability_manager_client.h @@ -772,6 +772,14 @@ public: virtual int SetAbilityController(const sptr &abilityController, bool imAStabilityTest); + /** + * Send not response process ID to ability manager service. + * + * @param pid The not response process ID. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode SendANRProcessID(int pid); + private: static std::mutex mutex_; static std::shared_ptr instance_; diff --git a/interfaces/innerkits/ability_manager/include/ability_manager_errors.h b/interfaces/innerkits/ability_manager/include/ability_manager_errors.h index f2248c6d20..2eb031c503 100644 --- a/interfaces/innerkits/ability_manager/include/ability_manager_errors.h +++ b/interfaces/innerkits/ability_manager/include/ability_manager_errors.h @@ -375,6 +375,11 @@ enum { * Result() for start user test fail. */ START_USER_TEST_FAIL, + + /** + * Result(2097220) for send usr1 sig to the process of not response fail. + */ + SEND_USR1_SIG_FAIL, }; enum { diff --git a/interfaces/innerkits/ability_manager/include/ability_manager_interface.h b/interfaces/innerkits/ability_manager/include/ability_manager_interface.h index 7bc635de35..27823366b5 100644 --- a/interfaces/innerkits/ability_manager/include/ability_manager_interface.h +++ b/interfaces/innerkits/ability_manager/include/ability_manager_interface.h @@ -703,9 +703,11 @@ public: /** * Send not response process ID to ability manager service. + * * @param pid The not response process ID. + * @return Returns ERR_OK on success, others on failure. */ - virtual bool SendANRProcessID(int pid) = 0; + virtual int SendANRProcessID(int pid) = 0; enum { // ipc id 1-1000 for kit diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 6441c704a4..4e38abe4b5 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -665,9 +665,11 @@ public: /** * Send not response process ID to ability manager service. + * * @param pid The not response process ID. + * @return Returns ERR_OK on success, others on failure. */ - virtual bool SendANRProcessID(int pid) override; + virtual int SendANRProcessID(int pid) override; private: template diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 0b870bff7c..ecce01b64c 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -860,8 +860,9 @@ public: /** * Send not response process ID to ability manager service. * @param pid The not response process ID. + * @return Returns ERR_OK on success, others on failure. */ - virtual bool SendANRProcessID(int pid) override; + virtual int SendANRProcessID(int pid) override; // MSG 0 - 20 represents timeout message static constexpr uint32_t LOAD_TIMEOUT_MSG = 0; diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index 65fd32a775..f841e8e2c2 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -948,5 +948,13 @@ ErrCode AbilityManagerClient::SetAbilityController(const sptr abms = iface_cast(remoteObject_); return abms->SetAbilityController(abilityController, imAStabilityTest); } + +ErrCode AbilityManagerClient::SendANRProcessID(int pid) +{ + CHECK_REMOTE_OBJECT_AND_RETURN(remoteObject_, ABILITY_SERVICE_NOT_CONNECTED); + + sptr abms = iface_cast(remoteObject_); + return abms->SendANRProcessID(pid); +} } // namespace AAFwk } // namespace AAFwk diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 9a12330bd9..7e5389e67e 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -2596,25 +2596,24 @@ int AbilityManagerProxy::DoAbilityBackground(const sptr &token, u return reply.ReadInt32(); } -bool AbilityManagerProxy::SendANRProcessID(int pid) +int AbilityManagerProxy::SendANRProcessID(int pid) { - int error; MessageParcel data; MessageParcel reply; MessageOption option; if (!WriteInterfaceToken(data)) { - return false; + return INNER_ERR; } if (!data.WriteInt32(pid)) { HILOG_ERROR("pid WriteInt32 fail."); - return false; + return ERR_INVALID_VALUE; } - error = Remote()->SendRequest(IAbilityManager::SEND_APP_NOT_RESPONSE_PROCESS_ID, data, reply, option); + auto error = Remote()->SendRequest(IAbilityManager::SEND_APP_NOT_RESPONSE_PROCESS_ID, data, reply, option); if (error != NO_ERROR) { HILOG_ERROR("SendANRProcessID error: %d", error); - return false; + return error; } - return reply.ReadBool(); + return reply.ReadInt32(); } } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 1f43c2827c..f1bcce3aaa 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -4004,7 +4004,7 @@ int AbilityManagerService::SetAbilityController(const sptr & return ERR_OK; } -bool AbilityManagerService::SendANRProcessID(int pid) +int AbilityManagerService::SendANRProcessID(int pid) { int anrTimeOut = amsConfigResolver_->GetANRTimeOutTime(); auto timeoutTask = [pid]() { @@ -4012,11 +4012,12 @@ bool AbilityManagerService::SendANRProcessID(int pid) HILOG_ERROR("Kill app not response process failed"); } }; + handler_->PostTask(timeoutTask, "TIME_OUT_TASK", anrTimeOut); if (kill(pid, SIGUSR1) != ERR_OK) { HILOG_ERROR("Send sig to app not response process failed"); + return SEND_USR1_SIG_FAIL; } - handler_->PostTask(timeoutTask, "TIME_OUT_TASK", anrTimeOut); - return true; + return ERR_OK; } bool AbilityManagerService::IsRunningInStabilityTest() diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index a26f2142da..c337711309 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -1505,8 +1505,8 @@ int AbilityManagerStub::DoAbilityBackgroundInner(MessageParcel &data, MessagePar int AbilityManagerStub::SendANRProcessIDInner(MessageParcel &data, MessageParcel &reply) { int32_t pid = data.ReadInt32(); - bool result = SendANRProcessID(pid); - if (!reply.WriteBool(result)) { + int32_t result = SendANRProcessID(pid); + if (!reply.WriteInt32(result)) { HILOG_ERROR("reply write failed."); return ERR_INVALID_VALUE; } diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h b/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h index 61bc3ac8ea..b29bb10bce 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h @@ -375,9 +375,9 @@ public: return true; } - virtual bool SendANRProcessID(int pid) override + virtual int SendANRProcessID(int pid) override { - return true; + return 0; } MOCK_METHOD2(TerminateAbilityByCaller, int(const sptr &callerToken, int requestCode)); diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h b/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h index 224a3dfc6e..970bd387ad 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h @@ -426,9 +426,9 @@ public: { return true; } - virtual bool SendANRProcessID(int pid) override + virtual int SendANRProcessID(int pid) override { - return true; + return 0; } virtual int StartUserTest(const Want &want, const sptr &observer) override diff --git a/services/formmgr/test/mock/include/mock_ability_manager.h b/services/formmgr/test/mock/include/mock_ability_manager.h index d109939e55..6edb24db9c 100644 --- a/services/formmgr/test/mock/include/mock_ability_manager.h +++ b/services/formmgr/test/mock/include/mock_ability_manager.h @@ -865,9 +865,9 @@ public: { return 0; } - virtual bool SendANRProcessID(int pid) + virtual int SendANRProcessID(int pid) { - return true; + return 0; } virtual int StartAbilityByCall( const Want &want, const sptr &connect, const sptr &callerToken) override diff --git a/services/test/mock/include/mock_ability_mgr_service.h b/services/test/mock/include/mock_ability_mgr_service.h index d16763d530..4a7448c6c7 100644 --- a/services/test/mock/include/mock_ability_mgr_service.h +++ b/services/test/mock/include/mock_ability_mgr_service.h @@ -192,9 +192,9 @@ public: return true; } - virtual bool SendANRProcessID(int pid) override + virtual int SendANRProcessID(int pid) override { - return true; + return 0; } virtual int StartUserTest(const Want &want, const sptr &observer) override diff --git a/tools/test/mock/mock_ability_manager_stub.h b/tools/test/mock/mock_ability_manager_stub.h index 10a5692a20..68c86d0e0d 100644 --- a/tools/test/mock/mock_ability_manager_stub.h +++ b/tools/test/mock/mock_ability_manager_stub.h @@ -207,9 +207,9 @@ public: { return 0; } - virtual bool SendANRProcessID(int pid) + virtual int SendANRProcessID(int pid) { - return true; + return 0; } virtual int SetAbilityController(const sptr &abilityController, bool imAStabilityTest) override From ed01612f811ffcdd97460fe0f08b5be340dc54e8 Mon Sep 17 00:00:00 2001 From: wanchengzhen Date: Thu, 17 Feb 2022 18:47:23 +0000 Subject: [PATCH 2/9] Replenish Signed-off-by: wanchengzhen --- frameworks/kits/appkit/native/app/src/main_thread.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/kits/appkit/native/app/src/main_thread.cpp b/frameworks/kits/appkit/native/app/src/main_thread.cpp index 798383f7b7..74ab88bc0c 100644 --- a/frameworks/kits/appkit/native/app/src/main_thread.cpp +++ b/frameworks/kits/appkit/native/app/src/main_thread.cpp @@ -1379,6 +1379,7 @@ void MainThread::HandleANRProcess(int sigMessage) std::string mainThreadStackInfo; if ((rFD = RequestFileDescriptor(int32_t(FaultLoggerType::CPP_CRASH))) < 0) { APP_LOGE("MainThread::HandleANRProcess request file eescriptor failed"); + return; } auto jsRuntime = std::move((std::unique_ptr&)applicationForAnr_->GetRuntime()); if (jsRuntime != nullptr) { From 6ab5612429f4cdad24b5e3b5304d2d9b0895fadb Mon Sep 17 00:00:00 2001 From: wanchengzhen Date: Thu, 17 Feb 2022 19:35:08 +0000 Subject: [PATCH 3/9] ANR test code Signed-off-by: wanchengzhen --- tools/aa/BUILD.gn | 11 +-- tools/aa/include/ability_command.h | 11 ++- tools/aa/src/ability_command.cpp | 114 ++++++++++++++++++++++++++++- 3 files changed, 127 insertions(+), 9 deletions(-) diff --git a/tools/aa/BUILD.gn b/tools/aa/BUILD.gn index 625017bad2..7b55a42e6b 100644 --- a/tools/aa/BUILD.gn +++ b/tools/aa/BUILD.gn @@ -19,7 +19,9 @@ config("ability_command_config") { "include", "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", "//foundation/aafwk/standard/interfaces/innerkits/app_manager/include/appmgr", - "//utils/system/safwk/native/include", + "//foundation/aafwk/standard/services/abilitymgr/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include", "//third_party/jsoncpp/include", ] } @@ -73,12 +75,7 @@ ohos_executable("aa") { cflags += [ "-DBINDER_IPC_32BIT" ] } - deps = [ - ":tools_aa_source_set", - "${appexecfwk_path}/interfaces/innerkits/appexecfwk_base:appexecfwk_base", - "${innerkits_path}/want:want", - "//utils/native/base:utils", - ] + deps = [ ":tools_aa_source_set" ] external_deps = [ "hiviewdfx_hilog_native:libhilog", diff --git a/tools/aa/include/ability_command.h b/tools/aa/include/ability_command.h index b6ad7dd126..ce7f301c3d 100644 --- a/tools/aa/include/ability_command.h +++ b/tools/aa/include/ability_command.h @@ -31,7 +31,8 @@ const std::string HELP_MSG = "usage: aa \n" " stop-service stop service with options\n" " dump dump the ability info\n" " force-stop force stop the process with bundle name\n" - " test start the test framework with options\n"; + " test start the test framework with options\n" + " anr Pass in pid with options\n"; const std::string HELP_MSG_SCREEN = "usage: aa screen \n" @@ -39,6 +40,12 @@ const std::string HELP_MSG_SCREEN = " -h, --help list available commands\n" " -p, --power power on or off with a state name\n"; +const std::string HELP_ANR = + "usage: aa anr \n" + "options list:\n" + " -h, --help list available commands\n" + " -p, --pid anr SendANRProcessID\n"; + const std::string HELP_MSG_START = "usage: aa start \n" "options list:\n" @@ -136,6 +143,8 @@ private: ErrCode RunAsDumpCommand(); ErrCode RunAsDumpsysCommand(); ErrCode RunAsForceStop(); + ErrCode RunAsSendANRProcessID(); + sptr GetAbilityManagerService(); ErrCode RunAsDumpCommandOptopt(); ErrCode MakeWantFromCmd(Want &want, std::string &windowMode); diff --git a/tools/aa/src/ability_command.cpp b/tools/aa/src/ability_command.cpp index 849f595f4c..f61e17a256 100644 --- a/tools/aa/src/ability_command.cpp +++ b/tools/aa/src/ability_command.cpp @@ -17,10 +17,14 @@ #include #include "ability_manager_client.h" +#include "iservice_registry.h" #include "mission_snapshot.h" #include "hilog_wrapper.h" #include "ohos/aafwk/base/bool_wrapper.h" #include "test_observer.h" +#include "sa_mgr_client.h" +#include "system_ability_definition.h" +#include using namespace OHOS::AppExecFwk; @@ -38,7 +42,12 @@ const struct option LONG_OPTIONS[] = { {"debug", no_argument, nullptr, 'D'}, {nullptr, 0, nullptr, 0}, }; - +const std::string SHORT_OPTIONS_ANR = "hp:"; +const struct option LONG_OPTIONS_ANR[] = { + {"help", no_argument, nullptr, 'h'}, + {"pid", required_argument, nullptr, 'p'}, + {nullptr, 0, nullptr, 0}, +}; const std::string SHORT_OPTIONS_DUMP = "has:m:lud::e::LS"; const struct option LONG_OPTIONS_DUMP[] = { {"help", no_argument, nullptr, 'h'}, @@ -87,6 +96,7 @@ ErrCode AbilityManagerShellCommand::CreateCommandMap() {"dump", std::bind(&AbilityManagerShellCommand::RunAsDumpsysCommand, this)}, {"force-stop", std::bind(&AbilityManagerShellCommand::RunAsForceStop, this)}, {"test", std::bind(&AbilityManagerShellCommand::RunAsTestCommand, this)}, + {"anr", std::bind(&AbilityManagerShellCommand::RunAsSendANRProcessID, this)}, }; return OHOS::ERR_OK; @@ -1287,5 +1297,107 @@ ErrCode AbilityManagerShellCommand::StartUserTest(const std::map AbilityManagerShellCommand::GetAbilityManagerService() +{ + sptr systemManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (systemManager == nullptr) { + HILOG_ERROR("Fail to get registry."); + return nullptr; + } + sptr remoteObject = systemManager->GetSystemAbility(ABILITY_MGR_SERVICE_ID); + return iface_cast(remoteObject); +} + +ErrCode AbilityManagerShellCommand::RunAsSendANRProcessID() +{ + static sptr abilityMs_; + std::string pid = ""; + int option = -1; + ErrCode result = OHOS::ERR_OK; + option = getopt_long(argc_, argv_, SHORT_OPTIONS_ANR.c_str(), LONG_OPTIONS_ANR, nullptr); + HILOG_INFO("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); + if (optind < 0 || optind > argc_) { + return OHOS::ERR_INVALID_VALUE; + } + if (option == -1) { + if ( strcmp(argv_[optind], cmd_.c_str()) == 0) { + HILOG_INFO("'aa %{public}s' %{public}s", HELP_ANR.c_str(), cmd_.c_str()); + result = OHOS::ERR_INVALID_VALUE; + } + } + else if (option == '?') { + switch (optopt) { + case 'h': { + result = OHOS::ERR_INVALID_VALUE; + break; + } + case 'p': { + HILOG_INFO("'aa anr -p' with no argument."); + resultReceiver_.append("error: option -p "); + resultReceiver_.append("' requires a value.\n"); + result = OHOS::ERR_INVALID_VALUE; + break; + } + case 0: { + std::string unknownOption = ""; + std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption); + + HILOG_INFO("'aa anr' with an unknown option."); + + resultReceiver_.append(unknownOptionMsg); + result = OHOS::ERR_INVALID_VALUE; + break; + } + default: { + std::string unknownOption = ""; + std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption); + + HILOG_INFO("'aa anr' with an unknown option."); + + resultReceiver_.append(unknownOptionMsg); + result = OHOS::ERR_INVALID_VALUE; + break; + } + } + } + else { + switch (option) { + case 'h': { + result = OHOS::ERR_INVALID_VALUE; + break; + } + case 'p':{ + HILOG_INFO("aa anr 'aa %{public}s' -p process.", cmd_.c_str()); + HILOG_INFO("aa anr 'aa optarg = %{public}s'.", optarg); + pid = optarg; + HILOG_INFO("aa anr 'aa pid = %{public}s'.", pid.c_str()); + break; + } + case 0: { + HILOG_INFO("'aa %{public}s' with an unknown option.", cmd_.c_str()); + result = OHOS::ERR_INVALID_VALUE; + break; + } + default: { + HILOG_INFO("'aa %{public}s' with an unknown option.", cmd_.c_str()); + result = OHOS::ERR_INVALID_VALUE; + break; + } + } + } + + if (result == OHOS::ERR_OK) { + HILOG_INFO("'aa pid = %{public}d'.", atoi(pid.c_str())); + abilityMs_ = GetAbilityManagerService(); + if(abilityMs_ == nullptr){ + std::cout << "abilityMsObj is nullptr"; + } + abilityMs_->SendANRProcessID(atoi(pid.c_str())); + }else{ + resultReceiver_.append(HELP_ANR+ "\n"); + result = OHOS::ERR_INVALID_VALUE; + } + return result; +} } // namespace AAFwk } // namespace OHOS From a3cf694b5f0a8e312cba14f3cb00c864308ae157 Mon Sep 17 00:00:00 2001 From: wanchengzhen Date: Thu, 17 Feb 2022 20:30:19 +0000 Subject: [PATCH 4/9] Fix codeCheck Signed-off-by: wanchengzhen --- tools/aa/include/ability_command.h | 2 +- tools/aa/src/ability_command.cpp | 27 +++++++++++++-------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/tools/aa/include/ability_command.h b/tools/aa/include/ability_command.h index ce7f301c3d..20bd8cbd9f 100644 --- a/tools/aa/include/ability_command.h +++ b/tools/aa/include/ability_command.h @@ -40,7 +40,7 @@ const std::string HELP_MSG_SCREEN = " -h, --help list available commands\n" " -p, --power power on or off with a state name\n"; -const std::string HELP_ANR = +const std::string HELP_ApplicationNotRespondin = "usage: aa anr \n" "options list:\n" " -h, --help list available commands\n" diff --git a/tools/aa/src/ability_command.cpp b/tools/aa/src/ability_command.cpp index f61e17a256..8d8f4e4635 100644 --- a/tools/aa/src/ability_command.cpp +++ b/tools/aa/src/ability_command.cpp @@ -14,9 +14,9 @@ */ #include "ability_command.h" - -#include #include "ability_manager_client.h" +#include +#include #include "iservice_registry.h" #include "mission_snapshot.h" #include "hilog_wrapper.h" @@ -24,7 +24,6 @@ #include "test_observer.h" #include "sa_mgr_client.h" #include "system_ability_definition.h" -#include using namespace OHOS::AppExecFwk; @@ -1321,7 +1320,7 @@ ErrCode AbilityManagerShellCommand::RunAsSendANRProcessID() } if (option == -1) { if ( strcmp(argv_[optind], cmd_.c_str()) == 0) { - HILOG_INFO("'aa %{public}s' %{public}s", HELP_ANR.c_str(), cmd_.c_str()); + HILOG_INFO("'aa %{public}s' %{public}s", HELP_ApplicationNotRespondin.c_str(), cmd_.c_str()); result = OHOS::ERR_INVALID_VALUE; } } @@ -1332,7 +1331,7 @@ ErrCode AbilityManagerShellCommand::RunAsSendANRProcessID() break; } case 'p': { - HILOG_INFO("'aa anr -p' with no argument."); + HILOG_INFO("'aa ApplicationNotRespondin -p' with no argument."); resultReceiver_.append("error: option -p "); resultReceiver_.append("' requires a value.\n"); result = OHOS::ERR_INVALID_VALUE; @@ -1342,7 +1341,7 @@ ErrCode AbilityManagerShellCommand::RunAsSendANRProcessID() std::string unknownOption = ""; std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption); - HILOG_INFO("'aa anr' with an unknown option."); + HILOG_INFO("'aa ApplicationNotRespondin' with an unknown option."); resultReceiver_.append(unknownOptionMsg); result = OHOS::ERR_INVALID_VALUE; @@ -1352,7 +1351,7 @@ ErrCode AbilityManagerShellCommand::RunAsSendANRProcessID() std::string unknownOption = ""; std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption); - HILOG_INFO("'aa anr' with an unknown option."); + HILOG_INFO("'aa ApplicationNotRespondin' with an unknown option."); resultReceiver_.append(unknownOptionMsg); result = OHOS::ERR_INVALID_VALUE; @@ -1366,11 +1365,11 @@ ErrCode AbilityManagerShellCommand::RunAsSendANRProcessID() result = OHOS::ERR_INVALID_VALUE; break; } - case 'p':{ - HILOG_INFO("aa anr 'aa %{public}s' -p process.", cmd_.c_str()); - HILOG_INFO("aa anr 'aa optarg = %{public}s'.", optarg); + case 'p': { + HILOG_INFO("aa ApplicationNotRespondin 'aa %{public}s' -p process.", cmd_.c_str()); + HILOG_INFO("aa ApplicationNotRespondin 'aa optarg = %{public}s'.", optarg); pid = optarg; - HILOG_INFO("aa anr 'aa pid = %{public}s'.", pid.c_str()); + HILOG_INFO("aa ApplicationNotRespondinr 'aa pid = %{public}s'.", pid.c_str()); break; } case 0: { @@ -1389,12 +1388,12 @@ ErrCode AbilityManagerShellCommand::RunAsSendANRProcessID() if (result == OHOS::ERR_OK) { HILOG_INFO("'aa pid = %{public}d'.", atoi(pid.c_str())); abilityMs_ = GetAbilityManagerService(); - if(abilityMs_ == nullptr){ + if (abilityMs_ == nullptr) { std::cout << "abilityMsObj is nullptr"; } abilityMs_->SendANRProcessID(atoi(pid.c_str())); - }else{ - resultReceiver_.append(HELP_ANR+ "\n"); + } else { + resultReceiver_.append(HELP_ApplicationNotRespondin+ "\n"); result = OHOS::ERR_INVALID_VALUE; } return result; From bf2dd1f6350a2b6503024cba4a35c7382ac2d1f5 Mon Sep 17 00:00:00 2001 From: wanchengzhen Date: Thu, 17 Feb 2022 21:09:36 +0000 Subject: [PATCH 5/9] Fix codex Signed-off-by: wanchengzhen --- tools/aa/src/ability_command.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tools/aa/src/ability_command.cpp b/tools/aa/src/ability_command.cpp index 8d8f4e4635..7cac18148f 100644 --- a/tools/aa/src/ability_command.cpp +++ b/tools/aa/src/ability_command.cpp @@ -12,11 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include +#include #include "ability_command.h" #include "ability_manager_client.h" -#include -#include #include "iservice_registry.h" #include "mission_snapshot.h" #include "hilog_wrapper.h" @@ -1319,12 +1319,11 @@ ErrCode AbilityManagerShellCommand::RunAsSendANRProcessID() return OHOS::ERR_INVALID_VALUE; } if (option == -1) { - if ( strcmp(argv_[optind], cmd_.c_str()) == 0) { + if (strcmp(argv_[optind], cmd_.c_str()) == 0) { HILOG_INFO("'aa %{public}s' %{public}s", HELP_ApplicationNotRespondin.c_str(), cmd_.c_str()); result = OHOS::ERR_INVALID_VALUE; } - } - else if (option == '?') { + } else if (option == '?') { switch (optopt) { case 'h': { result = OHOS::ERR_INVALID_VALUE; @@ -1358,8 +1357,7 @@ ErrCode AbilityManagerShellCommand::RunAsSendANRProcessID() break; } } - } - else { + } else { switch (option) { case 'h': { result = OHOS::ERR_INVALID_VALUE; From 74dd1720ed684224a5847ed3ffdf14717caf2dcf Mon Sep 17 00:00:00 2001 From: wanchengzhen Date: Thu, 17 Feb 2022 21:27:07 +0000 Subject: [PATCH 6/9] Fix codex Signed-off-by: wanchengzhen --- tools/aa/src/ability_command.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/aa/src/ability_command.cpp b/tools/aa/src/ability_command.cpp index 7cac18148f..c86f45a6e1 100644 --- a/tools/aa/src/ability_command.cpp +++ b/tools/aa/src/ability_command.cpp @@ -17,13 +17,13 @@ #include "ability_command.h" #include "ability_manager_client.h" +#include "hilog_wrapper.h" #include "iservice_registry.h" #include "mission_snapshot.h" -#include "hilog_wrapper.h" #include "ohos/aafwk/base/bool_wrapper.h" -#include "test_observer.h" #include "sa_mgr_client.h" #include "system_ability_definition.h" +#include "test_observer.h" using namespace OHOS::AppExecFwk; @@ -1357,7 +1357,7 @@ ErrCode AbilityManagerShellCommand::RunAsSendANRProcessID() break; } } - } else { + } else { switch (option) { case 'h': { result = OHOS::ERR_INVALID_VALUE; From a53de56fe504b3f5326590bbb4adcffe4c900cb8 Mon Sep 17 00:00:00 2001 From: wanchengzhen Date: Thu, 17 Feb 2022 21:39:48 +0000 Subject: [PATCH 7/9] Fix codex Signed-off-by: wanchengzhen --- tools/aa/src/ability_command.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/aa/src/ability_command.cpp b/tools/aa/src/ability_command.cpp index c86f45a6e1..0b95674714 100644 --- a/tools/aa/src/ability_command.cpp +++ b/tools/aa/src/ability_command.cpp @@ -12,10 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "ability_command.h" + #include #include - -#include "ability_command.h" #include "ability_manager_client.h" #include "hilog_wrapper.h" #include "iservice_registry.h" From 7471b19384ac37f95a40c10fc1d168b17644cdf6 Mon Sep 17 00:00:00 2001 From: wanchengzhen Date: Thu, 17 Feb 2022 22:25:58 +0000 Subject: [PATCH 8/9] Fix codex Signed-off-by: wanchengzhen --- frameworks/kits/ability/native/src/ability.cpp | 4 ++-- tools/aa/include/ability_command.h | 8 ++++---- tools/aa/src/ability_command.cpp | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/frameworks/kits/ability/native/src/ability.cpp b/frameworks/kits/ability/native/src/ability.cpp index 9351692298..7879ba5c42 100755 --- a/frameworks/kits/ability/native/src/ability.cpp +++ b/frameworks/kits/ability/native/src/ability.cpp @@ -202,7 +202,7 @@ void Ability::OnStart(const Want &want) } if (abilityInfo_->bundleName == LAUNCHER_BUNDLE_NAME && abilityInfo_->name == LAUNCHER_ABILITY_NAME) { - winType = Rosen::WindowType::WINDOW_TYPE_WALLPAPER; + winType = Rosen::WindowType::WINDOW_TYPE_DESKTOP; } int defualtDisplayId = Rosen::WindowScene::DEFAULT_DISPLAY_ID; @@ -3333,7 +3333,7 @@ sptr Ability::GetWindowOption(const Want &want) if (want.GetElement().GetBundleName() == LAUNCHER_BUNDLE_NAME && want.GetElement().GetAbilityName() == LAUNCHER_ABILITY_NAME) { APP_LOGI("Set window type for launcher"); - option->SetWindowType(Rosen::WindowType::WINDOW_TYPE_WALLPAPER); + option->SetWindowType(Rosen::WindowType::WINDOW_TYPE_DESKTOP); } APP_LOGI("%{public}s end", __func__); diff --git a/tools/aa/include/ability_command.h b/tools/aa/include/ability_command.h index 20bd8cbd9f..10dbfeaed6 100644 --- a/tools/aa/include/ability_command.h +++ b/tools/aa/include/ability_command.h @@ -32,7 +32,7 @@ const std::string HELP_MSG = "usage: aa \n" " dump dump the ability info\n" " force-stop force stop the process with bundle name\n" " test start the test framework with options\n" - " anr Pass in pid with options\n"; + " ApplicationNotRespondin Pass in pid with options\n"; const std::string HELP_MSG_SCREEN = "usage: aa screen \n" @@ -41,10 +41,10 @@ const std::string HELP_MSG_SCREEN = " -p, --power power on or off with a state name\n"; const std::string HELP_ApplicationNotRespondin = - "usage: aa anr \n" + "usage: aa ApplicationNotRespondin \n" "options list:\n" " -h, --help list available commands\n" - " -p, --pid anr SendANRProcessID\n"; + " -p, --pid Pass in pid with option\n"; const std::string HELP_MSG_START = "usage: aa start \n" @@ -143,7 +143,7 @@ private: ErrCode RunAsDumpCommand(); ErrCode RunAsDumpsysCommand(); ErrCode RunAsForceStop(); - ErrCode RunAsSendANRProcessID(); + ErrCode RunAsSendAppNotRespondinProcessID(); sptr GetAbilityManagerService(); ErrCode RunAsDumpCommandOptopt(); diff --git a/tools/aa/src/ability_command.cpp b/tools/aa/src/ability_command.cpp index 0b95674714..4f1cf245cd 100644 --- a/tools/aa/src/ability_command.cpp +++ b/tools/aa/src/ability_command.cpp @@ -41,8 +41,8 @@ const struct option LONG_OPTIONS[] = { {"debug", no_argument, nullptr, 'D'}, {nullptr, 0, nullptr, 0}, }; -const std::string SHORT_OPTIONS_ANR = "hp:"; -const struct option LONG_OPTIONS_ANR[] = { +const std::string SHORT_OPTIONS_ApplicationNotRespondin = "hp:"; +const struct option LONG_OPTIONS_ApplicationNotRespondin[] = { {"help", no_argument, nullptr, 'h'}, {"pid", required_argument, nullptr, 'p'}, {nullptr, 0, nullptr, 0}, @@ -95,7 +95,7 @@ ErrCode AbilityManagerShellCommand::CreateCommandMap() {"dump", std::bind(&AbilityManagerShellCommand::RunAsDumpsysCommand, this)}, {"force-stop", std::bind(&AbilityManagerShellCommand::RunAsForceStop, this)}, {"test", std::bind(&AbilityManagerShellCommand::RunAsTestCommand, this)}, - {"anr", std::bind(&AbilityManagerShellCommand::RunAsSendANRProcessID, this)}, + {"ApplicationNotRespondin", std::bind(&AbilityManagerShellCommand::RunAsSendAppNotRespondinProcessID, this)}, }; return OHOS::ERR_OK; @@ -1307,13 +1307,13 @@ sptr AbilityManagerShellCommand::GetAbilityManagerService() return iface_cast(remoteObject); } -ErrCode AbilityManagerShellCommand::RunAsSendANRProcessID() +ErrCode AbilityManagerShellCommand::RunAsSendAppNotRespondinProcessID() { static sptr abilityMs_; std::string pid = ""; int option = -1; ErrCode result = OHOS::ERR_OK; - option = getopt_long(argc_, argv_, SHORT_OPTIONS_ANR.c_str(), LONG_OPTIONS_ANR, nullptr); + option = getopt_long(argc_, argv_, SHORT_OPTIONS_ApplicationNotRespondin.c_str(), LONG_OPTIONS_ApplicationNotRespondin, nullptr); HILOG_INFO("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); if (optind < 0 || optind > argc_) { return OHOS::ERR_INVALID_VALUE; From 6f3cfa1f7a68dbdacfd6678d0009c8d9e5ef0681 Mon Sep 17 00:00:00 2001 From: wanchengzhen Date: Thu, 17 Feb 2022 22:33:44 +0000 Subject: [PATCH 9/9] Fix codex Signed-off-by: wanchengzhen --- tools/aa/src/ability_command.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/aa/src/ability_command.cpp b/tools/aa/src/ability_command.cpp index 4f1cf245cd..8a51480bbf 100644 --- a/tools/aa/src/ability_command.cpp +++ b/tools/aa/src/ability_command.cpp @@ -1313,7 +1313,8 @@ ErrCode AbilityManagerShellCommand::RunAsSendAppNotRespondinProcessID() std::string pid = ""; int option = -1; ErrCode result = OHOS::ERR_OK; - option = getopt_long(argc_, argv_, SHORT_OPTIONS_ApplicationNotRespondin.c_str(), LONG_OPTIONS_ApplicationNotRespondin, nullptr); + option = getopt_long(argc_, argv_, SHORT_OPTIONS_ApplicationNotRespondin.c_str(), + LONG_OPTIONS_ApplicationNotRespondin, nullptr); HILOG_INFO("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); if (optind < 0 || optind > argc_) { return OHOS::ERR_INVALID_VALUE;