diff --git a/services/abilitymgr/BUILD.gn b/services/abilitymgr/BUILD.gn index 58c890f32964a96c123e33cd3841b37116101a92..8bca132d3060686604abdf39800e595f03c8e790 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -111,6 +111,7 @@ ohos_shared_library("abilityms") { "hisysevent_native:libhisysevent", "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", + "input:libmmi-client", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/services/abilitymgr/abilitymgr.gni b/services/abilitymgr/abilitymgr.gni index ac3367340f27ee7e782809734929fb7b43646020..eb2b9f5259c4a5640337498a241dd66c2c6d28e8 100644 --- a/services/abilitymgr/abilitymgr.gni +++ b/services/abilitymgr/abilitymgr.gni @@ -26,6 +26,7 @@ abilityms_files = [ "src/ability_token_stub.cpp", "src/app_no_response_disposer.cpp", "src/app_scheduler.cpp", + "src/application_anr_listener.cpp", "src/connection_record.cpp", "src/data_ability_caller_recipient.cpp", "src/data_ability_manager.cpp", diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 24e73e1c703887e7eb2f47b5a88445e2cc816358..76085b0e908872ed81f36fef4b7460514e10211f 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -29,6 +29,7 @@ #include "ability_manager_stub.h" #include "app_no_response_disposer.h" #include "app_scheduler.h" +#include "application_anr_listener.h" #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE #include "background_task_observer.h" #endif @@ -1067,6 +1068,7 @@ private: sptr wmsHandler_; #endif std::shared_ptr anrDisposer_; + std::shared_ptr anrListener_; }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/include/application_anr_listener.h b/services/abilitymgr/include/application_anr_listener.h new file mode 100644 index 0000000000000000000000000000000000000000..73316584a28d0963d4b70ab02366f670be5bca17 --- /dev/null +++ b/services/abilitymgr/include/application_anr_listener.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_APPLICATION_ANR_LISTENER_H +#define OHOS_ABILITY_RUNTIME_APPLICATION_ANR_LISTENER_H + +#include + +#include "i_anr_observer.h" + +namespace OHOS { +namespace AAFwk { +/** + * @class ApplicationAnrListener + * ApplicationAnrListener. + */ +class ApplicationAnrListener : public MMI::IAnrObserver { +public: + ApplicationAnrListener(); + virtual ~ApplicationAnrListener(); + void OnAnr(int32_t pid) const override; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_APPLICATION_ANR_LISTENER_H diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index b9a31e4fce9197a40de6ee4dd5dc1178d0a27927..1aca3976ee87616e189473dc77765caa2b246510 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -40,6 +40,7 @@ #include "hilog_wrapper.h" #include "if_system_ability_manager.h" #include "in_process_call_wrapper.h" +#include "input_manager.h" #include "ipc_skeleton.h" #include "iservice_registry.h" #include "itest_observer.h" @@ -272,6 +273,9 @@ bool AbilityManagerService::Init() handler_->PostTask(subscribeBackgroundTask, "SubscribeBackgroundTask"); #endif + anrListener_ = std::make_shared(); + MMI::InputManager::GetInstance()->SetAnrObserver(anrListener_); + HILOG_INFO("Init success."); return true; } diff --git a/services/abilitymgr/src/application_anr_listener.cpp b/services/abilitymgr/src/application_anr_listener.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4f5004bc559e266ab986c139a42a145b66217fa3 --- /dev/null +++ b/services/abilitymgr/src/application_anr_listener.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "application_anr_listener.h" + +#include "ability_manager_service.h" + +namespace OHOS { +namespace AAFwk { +ApplicationAnrListener::ApplicationAnrListener() {} + +ApplicationAnrListener::~ApplicationAnrListener() {} + +void ApplicationAnrListener::OnAnr(int32_t pid) const +{ + DelayedSingleton::GetInstance()->SendANRProcessID(pid); +} +} // namespace AAFwk +} // namespace OHOS diff --git a/test/fuzztest/abilitymanager_fuzzer/BUILD.gn b/test/fuzztest/abilitymanager_fuzzer/BUILD.gn index 61100fb4e1e771f141ed7d42ad0e02c095338c66..801b1c94f313875b6c27fcd063c5b17c9cd6a70e 100644 --- a/test/fuzztest/abilitymanager_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymanager_fuzzer/BUILD.gn @@ -47,6 +47,7 @@ ohos_fuzztest("AbilityManagerFuzzTest") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "common_event_service:cesfwk_innerkits", + "input:libmmi-client", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", diff --git a/test/moduletest/ability_record_test/BUILD.gn b/test/moduletest/ability_record_test/BUILD.gn index b40688f187d9aa429eff4695ca7fb47cd206cbf2..b237f0eb136f8934aeadd632e0cf2f0d51085673 100644 --- a/test/moduletest/ability_record_test/BUILD.gn +++ b/test/moduletest/ability_record_test/BUILD.gn @@ -37,6 +37,7 @@ ohos_moduletest("AbilityRecordModuleTest") { "${ability_runtime_services_path}/abilitymgr/src/ability_scheduler_stub.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_token_stub.cpp", "${ability_runtime_services_path}/abilitymgr/src/app_scheduler.cpp", + "${ability_runtime_services_path}/abilitymgr/src/application_anr_listener.cpp", "${ability_runtime_services_path}/abilitymgr/src/call_container.cpp", "${ability_runtime_services_path}/abilitymgr/src/call_record.cpp", "${ability_runtime_services_path}/abilitymgr/src/caller_info.cpp", @@ -114,6 +115,7 @@ ohos_moduletest("AbilityRecordModuleTest") { "hisysevent_native:libhisysevent", "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", + "input:libmmi-client", "ipc:ipc_core", "relational_store:native_appdatafwk", "relational_store:native_dataability", diff --git a/test/moduletest/ability_timeout_module_test/BUILD.gn b/test/moduletest/ability_timeout_module_test/BUILD.gn index 435b7bdd6754bdd25c859228879aad557de92e6e..42114e8b7ffa14dfccfb89ecc90c035bb1848fc3 100644 --- a/test/moduletest/ability_timeout_module_test/BUILD.gn +++ b/test/moduletest/ability_timeout_module_test/BUILD.gn @@ -38,6 +38,7 @@ ohos_moduletest("ability_timeout_module_test") { "${ability_runtime_services_path}/abilitymgr/src/ability_scheduler_proxy.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_scheduler_stub.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_token_stub.cpp", + "${ability_runtime_services_path}/abilitymgr/src/application_anr_listener.cpp", "${ability_runtime_services_path}/abilitymgr/src/call_container.cpp", "${ability_runtime_services_path}/abilitymgr/src/call_record.cpp", "${ability_runtime_services_path}/abilitymgr/src/caller_info.cpp", @@ -115,6 +116,7 @@ ohos_moduletest("ability_timeout_module_test") { "hisysevent_native:libhisysevent", "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", + "input:libmmi-client", "ipc:ipc_core", "relational_store:native_appdatafwk", "relational_store:native_dataability", diff --git a/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn b/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn index f50e9760355830ed9d2b54910880a5f13bc66c6c..a30c9a0784341616e4d426bb40079ce66aff9432 100644 --- a/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn +++ b/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn @@ -30,6 +30,7 @@ ohos_moduletest("specified_ability_service_test") { sources += [ "${ability_runtime_services_path}/abilitymgr/src/ability_manager_proxy.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_manager_service.cpp", + "${ability_runtime_services_path}/abilitymgr/src/application_anr_listener.cpp", "${ability_runtime_services_path}/common/src/event_report.cpp", "${ability_runtime_services_path}/common/src/permission_verification.cpp", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/sa_mgr/src/sa_mgr_client_mock.cpp", @@ -90,6 +91,7 @@ ohos_moduletest("specified_ability_service_test") { "hisysevent_native:libhisysevent", "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", + "input:libmmi-client", "ipc:ipc_core", "relational_store:native_appdatafwk", "relational_store:native_dataability", diff --git a/test/moduletest/on_new_want_module_test/BUILD.gn b/test/moduletest/on_new_want_module_test/BUILD.gn index 28132d18f4c6a47c2398dfd7ee66b4c695a44066..cad14822d8b0c31e92bacfa4085e5664628da6da 100644 --- a/test/moduletest/on_new_want_module_test/BUILD.gn +++ b/test/moduletest/on_new_want_module_test/BUILD.gn @@ -29,6 +29,7 @@ ohos_moduletest("on_new_want_module_test") { sources = [ "on_new_want_module_test.cpp" ] sources += [ "${ability_runtime_services_path}/abilitymgr/src/ability_manager_service.cpp", + "${ability_runtime_services_path}/abilitymgr/src/application_anr_listener.cpp", "${ability_runtime_services_path}/abilitymgr/src/mission_list.cpp", "${ability_runtime_services_path}/abilitymgr/src/mission_list_manager.cpp", "${ability_runtime_services_path}/common/src/event_report.cpp", @@ -88,6 +89,7 @@ ohos_moduletest("on_new_want_module_test") { "hisysevent_native:libhisysevent", "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", + "input:libmmi-client", "ipc:ipc_core", "relational_store:native_appdatafwk", "relational_store:native_dataability", diff --git a/test/moduletest/running_infos_module_test/BUILD.gn b/test/moduletest/running_infos_module_test/BUILD.gn index a39b173483a9d04c3220550b33d372fb34a53763..c92de7e97efc326b27449a7af96604bcf26802da 100644 --- a/test/moduletest/running_infos_module_test/BUILD.gn +++ b/test/moduletest/running_infos_module_test/BUILD.gn @@ -38,6 +38,7 @@ ohos_moduletest("running_infos_module_test") { "${ability_runtime_services_path}/abilitymgr/src/ability_scheduler_proxy.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_scheduler_stub.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_token_stub.cpp", + "${ability_runtime_services_path}/abilitymgr/src/application_anr_listener.cpp", "${ability_runtime_services_path}/abilitymgr/src/caller_info.cpp", "${ability_runtime_services_path}/abilitymgr/src/connection_record.cpp", "${ability_runtime_services_path}/abilitymgr/src/data_ability_manager.cpp", @@ -113,6 +114,7 @@ ohos_moduletest("running_infos_module_test") { "hisysevent_native:libhisysevent", "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", + "input:libmmi-client", "ipc:ipc_core", "relational_store:native_appdatafwk", "relational_store:native_dataability", diff --git a/test/moduletest/start_ability_implicit_module_test/BUILD.gn b/test/moduletest/start_ability_implicit_module_test/BUILD.gn index 1b4eeaaf907dd26ce318b88b30b4847402cc15cf..8f686025e027283892706c3fa8cbbe8809105cf0 100644 --- a/test/moduletest/start_ability_implicit_module_test/BUILD.gn +++ b/test/moduletest/start_ability_implicit_module_test/BUILD.gn @@ -43,6 +43,7 @@ ohos_moduletest("start_ability_implicit_module_test") { "${ability_runtime_services_path}/abilitymgr/src/ability_scheduler_proxy.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_scheduler_stub.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_token_stub.cpp", + "${ability_runtime_services_path}/abilitymgr/src/application_anr_listener.cpp", "${ability_runtime_services_path}/abilitymgr/src/caller_info.cpp", "${ability_runtime_services_path}/abilitymgr/src/connection_record.cpp", "${ability_runtime_services_path}/abilitymgr/src/data_ability_manager.cpp", @@ -117,6 +118,7 @@ ohos_moduletest("start_ability_implicit_module_test") { "hisysevent_native:libhisysevent", "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", + "input:libmmi-client", "ipc:ipc_core", "relational_store:native_appdatafwk", "relational_store:native_dataability", diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 05664541403fad5c8c51b70d5adc4c4fd898e687..aab9ee19ee22b88260561fcea393406386e5ec9c 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -113,6 +113,7 @@ ohos_source_set("abilityms_test_source") { "${ability_runtime_services_path}/abilitymgr/src/ability_token_stub.cpp", "${ability_runtime_services_path}/abilitymgr/src/ams_configuration_parameter.cpp", "${ability_runtime_services_path}/abilitymgr/src/app_no_response_disposer.cpp", + "${ability_runtime_services_path}/abilitymgr/src/application_anr_listener.cpp", "${ability_runtime_services_path}/abilitymgr/src/atomic_service_status_callback.cpp", "${ability_runtime_services_path}/abilitymgr/src/atomic_service_status_callback_proxy.cpp", "${ability_runtime_services_path}/abilitymgr/src/atomic_service_status_callback_stub.cpp", @@ -192,6 +193,7 @@ ohos_source_set("abilityms_test_source") { "hisysevent_native:libhisysevent", "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", + "input:libmmi-client", "ipc:ipc_core", "relational_store:native_appdatafwk", "relational_store:native_dataability",