From 8b1d8d7ac96ee8b0c0eddd2581962e05b3d2645f Mon Sep 17 00:00:00 2001 From: xuchenghua09 Date: Tue, 14 Jun 2022 13:28:32 +0800 Subject: [PATCH 1/8] ANR Signed-off-by: xuchenghua09 --- .../test/unittest/pending_want_test/BUILD.gn | 2 +- .../unittest/want_agent_helper_test/BUILD.gn | 2 +- .../include/appmgr/ams_mgr_interface.h | 3 + .../include/appmgr/ams_mgr_proxy.h | 2 + .../app_manager/include/appmgr/ams_mgr_stub.h | 1 + .../include/appmgr/app_mgr_client.h | 2 + .../include/appmgr/app_mgr_interface.h | 2 +- .../include/appmgr/app_mgr_proxy.h | 2 +- .../app_manager/src/appmgr/ams_mgr_proxy.cpp | 33 +++ .../app_manager/src/appmgr/ams_mgr_stub.cpp | 19 ++ .../app_manager/src/appmgr/app_mgr_client.cpp | 15 ++ services/abilitymgr/BUILD.gn | 2 + services/abilitymgr/abilitymgr.gni | 7 + .../include/ability_manager_service.h | 11 +- .../include/ams_configuration_parameter.h | 6 + .../include/app_no_response_disposer.h | 55 +++++ services/abilitymgr/include/app_scheduler.h | 11 +- services/abilitymgr/include/mission.h | 2 +- .../abilitymgr/include/mission_list_manager.h | 2 + .../include/system_dialog_scheduler.h | 84 +++++++ .../resource/ams_service_config.json | 3 +- .../src/ability_manager_service.cpp | 70 +++--- .../src/ams_configuration_parameter.cpp | 6 + .../src/app_no_response_disposer.cpp | 133 +++++++++++ services/abilitymgr/src/app_scheduler.cpp | 12 + services/abilitymgr/src/mission.cpp | 4 +- .../abilitymgr/src/mission_list_manager.cpp | 18 ++ .../src/system_dialog_scheduler.cpp | 210 ++++++++++++++++++ services/abilitymgr/test/BUILD.gn | 6 + services/abilitymgr/test/mock/BUILD.gn | 2 + .../test/mock/libs/arkui_mock/BUILD.gn | 52 +++++ .../include/ui_service_mgr_client_mock.h | 88 ++++++++ .../src/ui_service_mgr_client_mock.cpp | 132 +++++++++++ .../ability_manager_service_anr_test/BUILD.gn | 73 ++++++ .../ability_manager_service_anr_test.cpp | 191 ++++++++++++++++ services/appmgr/include/ams_mgr_scheduler.h | 2 + services/appmgr/include/app_mgr_service.h | 9 +- .../appmgr/include/app_mgr_service_inner.h | 1 + services/appmgr/src/ams_mgr_scheduler.cpp | 9 + services/appmgr/src/app_mgr_service_inner.cpp | 23 ++ .../mock/include/mock_ams_mgr_scheduler.h | 1 + services/dialog_ui/dialog_anr/js/BUILD.gn | 25 +++ .../dialog_ui/dialog_anr/js/i18n/en-US.json | 8 + .../dialog_ui/dialog_anr/js/i18n/zh-CN.json | 8 + .../dialog_anr/js/pages/index/index.css | 87 ++++++++ .../dialog_anr/js/pages/index/index.hml | 33 +++ .../dialog_anr/js/pages/index/index.js | 41 ++++ services/test/BUILD.gn | 1 + services/test/moduletest/common/ams/BUILD.gn | 1 + .../specified_ability_service_test/BUILD.gn | 1 + .../on_new_want_module_test/BUILD.gn | 1 + .../running_infos_module_test/BUILD.gn | 1 + 52 files changed, 1452 insertions(+), 63 deletions(-) create mode 100644 services/abilitymgr/include/app_no_response_disposer.h create mode 100644 services/abilitymgr/include/system_dialog_scheduler.h create mode 100644 services/abilitymgr/src/app_no_response_disposer.cpp create mode 100644 services/abilitymgr/src/system_dialog_scheduler.cpp create mode 100644 services/abilitymgr/test/mock/libs/arkui_mock/BUILD.gn create mode 100644 services/abilitymgr/test/mock/libs/arkui_mock/include/ui_service_mgr_client_mock.h create mode 100644 services/abilitymgr/test/mock/libs/arkui_mock/src/ui_service_mgr_client_mock.cpp create mode 100644 services/abilitymgr/test/unittest/phone/ability_manager_service_anr_test/BUILD.gn create mode 100644 services/abilitymgr/test/unittest/phone/ability_manager_service_anr_test/ability_manager_service_anr_test.cpp create mode 100644 services/dialog_ui/dialog_anr/js/BUILD.gn create mode 100644 services/dialog_ui/dialog_anr/js/i18n/en-US.json create mode 100644 services/dialog_ui/dialog_anr/js/i18n/zh-CN.json create mode 100644 services/dialog_ui/dialog_anr/js/pages/index/index.css create mode 100644 services/dialog_ui/dialog_anr/js/pages/index/index.hml create mode 100644 services/dialog_ui/dialog_anr/js/pages/index/index.js diff --git a/frameworks/kits/wantagent/test/unittest/pending_want_test/BUILD.gn b/frameworks/kits/wantagent/test/unittest/pending_want_test/BUILD.gn index c71c715177..00e1202559 100644 --- a/frameworks/kits/wantagent/test/unittest/pending_want_test/BUILD.gn +++ b/frameworks/kits/wantagent/test/unittest/pending_want_test/BUILD.gn @@ -20,7 +20,7 @@ module_output_path = "ans_standard/wantagent" ohos_unittest("pending_want_test") { module_out_path = module_output_path include_dirs = [ - "//aafwk/standard/frameworks/kits/appkit/native/ability_runtime/context/", + "${aafwk_path}/frameworks/kits/appkit/native/ability_runtime/context/", "${aafwk_path}/frameworks/kits/appkit/native/ability_runtime", "${aafwk_path}/services/abilitymgr/include", "//foundation/distributedschedule/samgr/adapter/interfaces/innerkits/include/", diff --git a/frameworks/kits/wantagent/test/unittest/want_agent_helper_test/BUILD.gn b/frameworks/kits/wantagent/test/unittest/want_agent_helper_test/BUILD.gn index 0b5b0f1af8..ea038fdddc 100644 --- a/frameworks/kits/wantagent/test/unittest/want_agent_helper_test/BUILD.gn +++ b/frameworks/kits/wantagent/test/unittest/want_agent_helper_test/BUILD.gn @@ -20,7 +20,7 @@ module_output_path = "ans_standard/wantagent" ohos_unittest("want_agent_helper_test") { module_out_path = module_output_path include_dirs = [ - "//aafwk/standard/frameworks/kits/appkit/native/ability_runtime/context/", + "${aafwk_path}/frameworks/kits/appkit/native/ability_runtime/context/", "${aafwk_path}/frameworks/kits/appkit/native/ability_runtime", "${aafwk_path}/services/abilitymgr/include", ] diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h index 3aa5d2d952..aa6476c07c 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h @@ -151,6 +151,8 @@ public: virtual void RegisterStartSpecifiedAbilityResponse(const sptr &response) = 0; + virtual int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application) = 0; + enum class Message { LOAD_ABILITY = 0, TERMINATE_ABILITY, @@ -170,6 +172,7 @@ public: REGISTER_START_SPECIFIED_ABILITY_RESPONSE, UPDATE_CONFIGURATION, GET_CONFIGURATION, + GET_APPLICATION_INFO_BY_PROCESS_ID, }; }; } // namespace AppExecFwk diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h index cc9b1776c8..3ac75a6c4d 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h @@ -134,6 +134,8 @@ public: */ virtual int32_t KillApplicationByUid(const std::string &bundleName, const int uid) override; + virtual int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application) override; + virtual void AbilityAttachTimeOut(const sptr &token) override; virtual void PrepareTerminate(const sptr &token) override; diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h index a250fbb83e..dd95592e38 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h @@ -59,6 +59,7 @@ private: int32_t HandleGetRunningProcessInfoByToken(MessageParcel &data, MessageParcel &reply); int32_t HandleStartSpecifiedAbility(MessageParcel &data, MessageParcel &reply); int32_t HandleRegisterStartSpecifiedAbilityResponse(MessageParcel &data, MessageParcel &reply); + int32_t HandleGetApplicationInfoByProcessID(MessageParcel &data, MessageParcel &reply); using AmsMgrFunc = int32_t (AmsMgrStub::*)(MessageParcel &data, MessageParcel &reply); std::map memberFuncMap_; diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h index 27bc0c317d..a39ffd81fa 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h @@ -274,6 +274,8 @@ public: */ virtual int GetRenderProcessTerminationStatus(pid_t renderPid, int &status); + int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application); + private: void SetServiceManager(std::unique_ptr serviceMgr); /** diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h index 475194536b..d99c40813b 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h @@ -191,7 +191,7 @@ public: * * @param pid The process id. * @param tokens The token of ability records. - * @return Returns true on success, others on failure. + * @return Returns ERR_OK on success, others on failure. */ virtual int GetAbilityRecordsByProcessID(const int pid, std::vector> &tokens) = 0; #ifdef ABILITY_COMMAND_FOR_TEST diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h index 9f2de072af..226fbb001b 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h @@ -224,7 +224,7 @@ public: */ virtual int BlockAppService() override; #endif - + virtual int32_t GetConfiguration(Configuration& config) override; virtual int32_t UpdateConfiguration(const Configuration &config) override; diff --git a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp index 54738b5780..54b1640e08 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp @@ -556,5 +556,38 @@ void AmsMgrProxy::RegisterStartSpecifiedAbilityResponse(const sptr remote = Remote(); + if (remote == nullptr) { + HILOG_ERROR("Remote is nullptr."); + return ERR_NULL_OBJECT; + } + data.WriteInt32(pid); + int32_t ret = remote->SendRequest( + static_cast(IAmsMgr::Message::GET_APPLICATION_INFO_BY_PROCESS_ID), data, reply, option); + if (ret != NO_ERROR) { + return ERR_NULL_OBJECT; + } + if (!reply.ReadBool()) { + HILOG_ERROR("reply result false"); + return ERR_NULL_OBJECT; + } + std::unique_ptr info(reply.ReadParcelable()); + if (!info) { + HILOG_ERROR("readParcelableInfo failed"); + return ERR_NULL_OBJECT; + } + application = *info; + HILOG_DEBUG("get parcelable info success"); + return 0; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp index 5975ea82be..7bbdc88ae2 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp @@ -61,6 +61,8 @@ AmsMgrStub::AmsMgrStub() &AmsMgrStub::HandleStartSpecifiedAbility; memberFuncMap_[static_cast(IAmsMgr::Message::REGISTER_START_SPECIFIED_ABILITY_RESPONSE)] = &AmsMgrStub::HandleRegisterStartSpecifiedAbilityResponse; + memberFuncMap_[static_cast(IAmsMgr::Message::GET_APPLICATION_INFO_BY_PROCESS_ID)] = + &AmsMgrStub::HandleGetApplicationInfoByProcessID; } AmsMgrStub::~AmsMgrStub() @@ -288,5 +290,22 @@ int32_t AmsMgrStub::HandleRegisterStartSpecifiedAbilityResponse(MessageParcel &d RegisterStartSpecifiedAbilityResponse(response); return NO_ERROR; } + +int32_t AmsMgrStub::HandleGetApplicationInfoByProcessID(MessageParcel &data, MessageParcel &reply) +{ + HITRACE_METER(HITRACE_TAG_APP); + int32_t pid = data.ReadInt32(); + AppExecFwk::ApplicationInfo application; + bool result = GetApplicationInfoByProcessID(pid, application); + if (!reply.WriteBool(result)) { + HILOG_ERROR("write result error."); + return ERR_INVALID_VALUE; + } + if (result && !reply.WriteParcelable(&application)) { + HILOG_ERROR("write application info failed"); + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp index 097390e3f1..bba4193848 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp @@ -511,6 +511,21 @@ int AppMgrClient::GetAbilityRecordsByProcessID(const int pid, std::vectorGetAbilityRecordsByProcessID(pid, tokens); } +int AppMgrClient::GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application) +{ + sptr service = iface_cast(mgrHolder_->GetRemoteObject()); + if (service == nullptr) { + HILOG_ERROR("service is nullptr"); + return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; + } + sptr amsService = service->GetAmsMgr(); + if (amsService == nullptr) { + HILOG_ERROR("amsService is nullptr"); + return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; + } + return amsService->GetApplicationInfoByProcessID(pid, application); +} + int AppMgrClient::StartRenderProcess(const std::string &renderParam, int32_t ipcFd, int32_t sharedFd, pid_t &renderPid) { diff --git a/services/abilitymgr/BUILD.gn b/services/abilitymgr/BUILD.gn index d783f289ab..e948283a64 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -89,7 +89,9 @@ ohos_shared_library("abilityms") { "${innerkits_path}/uri_permission:uri_permission_mgr", "${services_path}/common:event_report", "${services_path}/common:perm_verification", + "${services_path}/dialog_ui/dialog_anr/js:dialog_anr_js_files_etc", "//base/hiviewdfx/hiview/adapter/utility:hiview_adapter_utility", + "//third_party/icu/icu4c:shared_icuuc", ] external_deps = [ diff --git a/services/abilitymgr/abilitymgr.gni b/services/abilitymgr/abilitymgr.gni index 8735f65494..69156e3610 100644 --- a/services/abilitymgr/abilitymgr.gni +++ b/services/abilitymgr/abilitymgr.gni @@ -24,6 +24,7 @@ abilityms_files = [ "src/ability_scheduler_stub.cpp", "src/ability_scheduler_proxy.cpp", "src/ability_token_stub.cpp", + "src/app_no_response_disposer.cpp", "src/app_scheduler.cpp", "src/connection_record.cpp", "src/data_ability_caller_recipient.cpp", @@ -83,3 +84,9 @@ abilityms_files = [ "src/background_task_observer.cpp", ] + +if (ability_runtime_graphics) { + abilityms_files += [ + "src/system_dialog_scheduler.cpp", + ] +} \ No newline at end of file diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 6ac4d8fb36..e2e0f17516 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -28,6 +28,7 @@ #include "ability_event_handler.h" #include "ability_manager_stub.h" #include "app_scheduler.h" +#include "app_no_response_disposer.h" #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE #include "background_task_observer.h" #endif @@ -44,13 +45,15 @@ #include "pending_want_manager.h" #include "ams_configuration_parameter.h" #include "user_controller.h" +#ifdef SUPPORT_GRAPHICS +#include "system_dialog_scheduler.h" +#endif namespace OHOS { namespace AAFwk { enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING }; const int32_t BASE_USER_RANGE = 200000; using OHOS::AppExecFwk::IAbilityController; - class PendingWantManager; /** * @class AbilityManagerService @@ -929,7 +932,6 @@ private: bool IsExistFile(const std::string &path); int CheckCallPermissions(const AbilityRequest &abilityRequest); - bool JudgeMultiUserConcurrency(const int32_t userId); /** * dumpsys info @@ -1009,8 +1011,6 @@ private: void GrantUriPermission(const Want &want, int32_t validUserId); bool VerifyUriPermission(const AbilityRequest &abilityRequest, const Want &want); - bool SetANRMissionByProcessID(int pid); - void StartMainElement(int userId, std::vector &bundleInfos); bool GetValidDataAbilityUri(const std::string &abilityInfoUri, std::string &adjustUri); @@ -1068,9 +1068,10 @@ private: #ifdef SUPPORT_GRAPHICS int32_t ShowPickerDialog(const Want& want, int32_t userId); - + std::shared_ptr sysDialogScheduler_; sptr wmsHandler_; #endif + std::shared_ptr anrDisposer_; }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/include/ams_configuration_parameter.h b/services/abilitymgr/include/ams_configuration_parameter.h index bb72b8dfec..29f17bd589 100644 --- a/services/abilitymgr/include/ams_configuration_parameter.h +++ b/services/abilitymgr/include/ams_configuration_parameter.h @@ -31,6 +31,7 @@ const std::string STARTUP_SETTINGS_DATA {"startup_settings_data"}; const std::string MISSION_SAVE_TIME {"mission_save_time"}; const std::string APP_NOT_RESPONSE_PROCESS_TIMEOUT_TIME {"app_not_response_process_timeout_time"}; const std::string AMS_TIMEOUT_TIME {"ams_timeout_time"}; +const std::string DEVICE_TYPE {"device_type"}; const std::string SYSTEM_CONFIGURATION {"system_configuration"}; const std::string SYSTEM_ORIENTATION {"system_orientation"}; const std::string ROOT_LAUNCHER_RESTART_MAX {"root_launcher_restart_max"}; @@ -81,6 +82,10 @@ public: * get ability manager service not response process timeout time. */ int GetAMSTimeOutTime() const; + /** + * get device type. + */ + std::string GetDeviceType() const; enum { READ_OK = 0, READ_FAIL = 1, READ_JSON_FAIL = 2 }; @@ -102,6 +107,7 @@ private: int missionSaveTime_ {12 * 60 * 60 * 1000}; int anrTime_ {5000}; int amsTime_ {5000}; + std::string deviceType_ {""}; std::map memThreshold_; }; } // namespace AAFwk diff --git a/services/abilitymgr/include/app_no_response_disposer.h b/services/abilitymgr/include/app_no_response_disposer.h new file mode 100644 index 0000000000..b0eca0fe6a --- /dev/null +++ b/services/abilitymgr/include/app_no_response_disposer.h @@ -0,0 +1,55 @@ +/* + * 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_AAFWK_APP_NO_RESPONE_DISPOSER_H +#define OHOS_AAFWK_APP_NO_RESPONE_DISPOSER_H + +#include +#include + +#include "iremote_object.h" + +namespace OHOS { +namespace AAFwk { +/** + * @class AppNoResponseDisposer + * AppNoResponseDisposer. + */ +class AppNoResponseDisposer : public std::enable_shared_from_this { +public: + using Closure = std::function; + using SetMissionClosure = std::function> &tokens)>; + using ShowDialogClosure = std::function; + + explicit AppNoResponseDisposer(const int timeout); + virtual ~AppNoResponseDisposer() = default; + +#ifdef SUPPORT_GRAPHICS + int DisposeAppNoRespose(int pid, + const SetMissionClosure &task, const ShowDialogClosure &showDialogTask) const; +#else + int DisposeAppNoRespose(int pid, const SetMissionClosure &task) const; +#endif + +private: + int ExcuteANRSaveStackInfoTask(int pid, const SetMissionClosure &task) const; + int PostTimeoutTask(int pid, std::string bundleName = "") const; + +private: + int timeout_ = 0; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_AAFWK_APP_NO_RESPONE_DISPOSER_H \ No newline at end of file diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index a181570798..11a82f7573 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -279,10 +279,19 @@ public: * * @param pid The process id. * @param tokens The token of ability records. - * @return Returns true on success, others on failure. + * @return Returns ERR_OK on success, others on failure. */ int GetAbilityRecordsByProcessID(const int pid, std::vector> &tokens); + /** + * Get the application info by process ID. + * + * @param pid The process id. + * @param application The application info. + * @return Returns ERR_OK on success, others on failure. + */ + int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application); + #ifdef ABILITY_COMMAND_FOR_TEST /** * Block app service. diff --git a/services/abilitymgr/include/mission.h b/services/abilitymgr/include/mission.h index 723bd22966..5acb1099f2 100644 --- a/services/abilitymgr/include/mission.h +++ b/services/abilitymgr/include/mission.h @@ -107,7 +107,7 @@ public: /** * @brief Set application not response state true */ - void SetANRState(); + void SetANRState(bool state); /** * @brief Is application not response state diff --git a/services/abilitymgr/include/mission_list_manager.h b/services/abilitymgr/include/mission_list_manager.h index bd46d79977..9899f97450 100644 --- a/services/abilitymgr/include/mission_list_manager.h +++ b/services/abilitymgr/include/mission_list_manager.h @@ -339,6 +339,8 @@ public: void PauseManager(); void ResumeManager(); + void SetMissionANRStateByTokens(const std::vector> &tokens); + #ifdef SUPPORT_GRAPHICS public: /** diff --git a/services/abilitymgr/include/system_dialog_scheduler.h b/services/abilitymgr/include/system_dialog_scheduler.h new file mode 100644 index 0000000000..02f6628f1b --- /dev/null +++ b/services/abilitymgr/include/system_dialog_scheduler.h @@ -0,0 +1,84 @@ +/* + * 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_AAFWK_SYSTEM_DIALOG_SCHEDULER_H +#define OHOS_AAFWK_SYSTEM_DIALOG_SCHEDULER_H + +#include + +#include "bundle_mgr_interface.h" + +namespace OHOS { +namespace AAFwk { +enum DialogType { + DIALOG_ANR = 0, + DIALOG_TIPS, + DIALOG_SELECTOR, +}; +enum DialogAlign { + TOP = 0, + CENTER, + BOTTOM, + LEFT, + RIGHT, +}; +struct DialogPosition { + int32_t offsetX = 0; + int32_t offsetY = 0; + int32_t width = 0; + int32_t height = 0; + int32_t width_narrow = 0; + int32_t height_narrow = 0; + bool wideScreen = true; + DialogAlign align = DialogAlign::CENTER; +}; +struct DialogAppInfo { + int32_t iconId = 0; + int32_t labelId = 0; + std::string bundleName = {}; + std::string abilityName = {}; +}; +/** + * @class SystemDialogScheduler + * SystemDialogScheduler. + */ +class SystemDialogScheduler { +public: + using DialogCallback = std::function; + using Closure = std::function; + + explicit SystemDialogScheduler(const std::string &deviceType); + virtual ~SystemDialogScheduler() = default; + + int32_t ShowANRDialog(const std::string &appName, const Closure &callBack); + + void GetAppNameFromResource(int32_t labelId, + const std::string &bundleName, int32_t userId, std::string &appName); + +private: + void InitDialogPosition(DialogType type, DialogPosition &position) const; + void GetDialogPositionAndSize(DialogType type, DialogPosition &position, int lineNums = 0) const; + + void ScheduleShowDialog(const std::string &name, const DialogPosition &position, + const std::string ¶ms, DialogCallback callback) const; + + sptr GetBundleManager(); + +private: + sptr iBundleManager_; + std::string deviceType_ = {}; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_AAFWK_SYSTEM_DIALOG_SCHEDULER_H \ No newline at end of file diff --git a/services/abilitymgr/resource/ams_service_config.json b/services/abilitymgr/resource/ams_service_config.json index 12ed342cb1..752a8094f3 100644 --- a/services/abilitymgr/resource/ams_service_config.json +++ b/services/abilitymgr/resource/ams_service_config.json @@ -4,7 +4,8 @@ "mission_save_time" : 43200000, "root_launcher_restart_max":15, "app_not_response_process_timeout_time" : 5000, - "ams_timeout_time" : 180 + "ams_timeout_time" : 180, + "device_type": "phone" }, "memorythreshold":{ "home_application": "20" diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 248ae3a4ab..3c27a7462d 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -64,7 +64,6 @@ #include "display_manager.h" #include "png.h" #include "ui_service_mgr_client.h" -#include "locale_config.h" #endif using OHOS::AppExecFwk::ElementName; @@ -247,6 +246,10 @@ bool AbilityManagerService::Init() if (HiviewDFX::Watchdog::GetInstance().AddThread(threadName, handler_, amsTimeOut) != 0) { HILOG_ERROR("HiviewDFX::Watchdog::GetInstance AddThread Fail"); } +#ifdef SUPPORT_GRAPHICS + sysDialogScheduler_ = std::make_shared(amsConfigResolver_->GetDeviceType()); +#endif + anrDisposer_ = std::make_shared(amsConfigResolver_->GetANRTimeOutTime()); auto startSystemTask = [aams = shared_from_this()]() { aams->StartSystemApplication(); }; handler_->PostTask(startSystemTask, "StartSystemApplication"); @@ -4070,27 +4073,40 @@ int AbilityManagerService::SetAbilityController(const sptr & int AbilityManagerService::SendANRProcessID(int pid) { - HILOG_INFO("AbilityManagerService::SendANRProcessID come, pid is %{public}d", pid); + HILOG_INFO("SendANRProcessID come, pid is %{public}d", pid); auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); if (!isSaCall) { HILOG_ERROR("%{public}s: Permission verification failed", __func__); return CHECK_PERMISSION_FAILED; } + CHECK_POINTER_AND_RETURN(anrDisposer_, ERR_INVALID_VALUE); - int anrTimeOut = amsConfigResolver_->GetANRTimeOutTime(); - auto timeoutTask = [pid]() { - if (kill(pid, SIGKILL) != ERR_OK) { - HILOG_ERROR("Kill app not response process failed"); + auto setMissionTask = [manager = currentMissionListManager_](const std::vector> &tokens) { + HILOG_WARN("set some mission anr status."); + if (manager) { + manager->SetMissionANRStateByTokens(tokens); } }; - if (!SetANRMissionByProcessID(pid)) { - HILOG_ERROR("Set app not response mission record failed"); - } - handler_->PostTask(timeoutTask, "TIME_OUT_TASK", anrTimeOut); - if (kill(pid, SIGUSR1) != ERR_OK) { - HILOG_ERROR("Send singal SIGUSR1 error."); - return SEND_USR1_SIG_FAIL; +#ifdef SUPPORT_GRAPHICS + auto showDialogTask = [sysDialog = sysDialogScheduler_, pid, userId = GetUserId()](int timeout, + int32_t labelId, const std::string &bundle, const Closure &callBack) { + std::string appName {""}; + if (!sysDialog) { + HILOG_ERROR("sysDialogScheduler_ is nullptr."); + return; + } + sysDialog->GetAppNameFromResource(labelId, bundle, userId, appName); + sysDialog->ShowANRDialog(appName, callBack); + }; + auto ret = anrDisposer_->DisposeAppNoRespose(pid, setMissionTask, showDialogTask); +#else + auto ret = anrDisposer_->DisposeAppNoRespose(pid, setMissionTask); +#endif + if (ret != ERR_OK) { + HILOG_ERROR("dispose app no respose failed."); + return ret; } + HILOG_INFO("AbilityManagerService::SendANRProcessID end"); return ERR_OK; } @@ -4436,34 +4452,6 @@ bool AbilityManagerService::VerifyUriPermission(const AbilityRequest &abilityReq return false; } -bool AbilityManagerService::SetANRMissionByProcessID(int pid) -{ - HILOG_INFO("start."); - if (appScheduler_ == nullptr || currentMissionListManager_ == nullptr) { - HILOG_ERROR("null point."); - return false; - } - std::vector> tokens; - if (appScheduler_->GetAbilityRecordsByProcessID(pid, tokens) != ERR_OK) { - HILOG_ERROR("Get ability record failed."); - return false; - } - for (auto &item : tokens) { - auto abilityRecord = currentMissionListManager_->GetAbilityRecordByToken(item); - if (abilityRecord == nullptr) { - HILOG_WARN("abilityRecord is nullptr."); - continue; - } - auto mission = abilityRecord->GetMission(); - if (mission == nullptr) { - HILOG_WARN("mission is nullptr."); - continue; - } - mission->SetANRState(); - } - return true; -} - void AbilityManagerService::StartupResidentProcess(int userId) { // Location may change diff --git a/services/abilitymgr/src/ams_configuration_parameter.cpp b/services/abilitymgr/src/ams_configuration_parameter.cpp index aa07ae96d3..8e100e4fcf 100644 --- a/services/abilitymgr/src/ams_configuration_parameter.cpp +++ b/services/abilitymgr/src/ams_configuration_parameter.cpp @@ -62,6 +62,11 @@ int AmsConfigurationParameter::GetMaxRestartNum() const return maxRestartNum_; } +std::string AmsConfigurationParameter::GetDeviceType() const +{ + return deviceType_; +} + int AmsConfigurationParameter::LoadAmsConfiguration(const std::string &filePath) { HILOG_DEBUG("%{public}s", __func__); @@ -119,6 +124,7 @@ int AmsConfigurationParameter::LoadAppConfigurationForStartUpService(nlohmann::j amsTime_ = Object.at(AmsConfig::SERVICE_ITEM_AMS).at(AmsConfig::AMS_TIMEOUT_TIME).get(); maxRestartNum_ = Object.at(AmsConfig::SERVICE_ITEM_AMS).at(AmsConfig::ROOT_LAUNCHER_RESTART_MAX).get(); + deviceType_ = Object.at(AmsConfig::SERVICE_ITEM_AMS).at(AmsConfig::DEVICE_TYPE).get(); HILOG_INFO("get ams service config succes!"); ret = 0; } diff --git a/services/abilitymgr/src/app_no_response_disposer.cpp b/services/abilitymgr/src/app_no_response_disposer.cpp new file mode 100644 index 0000000000..223a2893e3 --- /dev/null +++ b/services/abilitymgr/src/app_no_response_disposer.cpp @@ -0,0 +1,133 @@ +/* + * 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 "app_no_response_disposer.h" + +#include + +#include "ability_manager_service.h" +#include "app_scheduler.h" +#include "ability_util.h" +#include "errors.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace AAFwk { +const std::string TASK_NAME_ANR = "ANR_TIME_OUT_TASK"; + +AppNoResponseDisposer::AppNoResponseDisposer(const int timeout): timeout_(timeout) {} + +#ifdef SUPPORT_GRAPHICS +int AppNoResponseDisposer::DisposeAppNoRespose(int pid, + const SetMissionClosure &task, const ShowDialogClosure &showDialogTask) const + { + auto appScheduler = DelayedSingleton::GetInstance(); + CHECK_POINTER_AND_RETURN(appScheduler, ERR_INVALID_VALUE); + + AppExecFwk::ApplicationInfo appInfo; + if (appScheduler->GetApplicationInfoByProcessID(pid, appInfo) != ERR_OK) { + HILOG_ERROR("Get application info failed."); + return ERR_INVALID_VALUE; + } + + auto ret = ExcuteANRSaveStackInfoTask(pid, task); + if (ret != ERR_OK) { + HILOG_ERROR("excute anr save stack info task failed."); + return ret; + } + + auto callback = [disposer = shared_from_this(), pid, bundleName = appInfo.bundleName]() { + CHECK_POINTER(disposer); + disposer->PostTimeoutTask(pid, bundleName); + HILOG_WARN("user choose to kill no response app."); + }; + + showDialogTask(timeout_, appInfo.labelId, appInfo.bundleName, callback); + + HILOG_INFO("DisposeAppNoRespose success."); + return ERR_OK; +} +#else +int AppNoResponseDisposer::DisposeAppNoRespose(int pid, const SetMissionClosure &task) const + { + HILOG_INFO("DisposeAppNoRespose start."); + auto ret = PostTimeoutTask(pid); + if (ret != ERR_OK) { + HILOG_ERROR("post anr timeout task failed."); + return ret; + } + + ret = ExcuteANRSaveStackInfoTask(pid, task); + if (ret != ERR_OK) { + HILOG_ERROR("excute anr save stack info task failed."); + return ret; + } + + HILOG_INFO("DisposeAppNoRespose success."); + return ERR_OK; +} +#endif + +int AppNoResponseDisposer::PostTimeoutTask(int pid, std::string bundleName) const +{ + auto appScheduler = DelayedSingleton::GetInstance(); + CHECK_POINTER_AND_RETURN(appScheduler, ERR_INVALID_VALUE); + + AppExecFwk::ApplicationInfo appInfo; + if (appScheduler->GetApplicationInfoByProcessID(pid, appInfo) != ERR_OK) { + HILOG_ERROR("Get application info failed."); + return ERR_INVALID_VALUE; + } + + // if callback process, check the process must be the same bundle name. + if (!bundleName.empty() && appInfo.bundleName != bundleName) { + HILOG_ERROR("this application is not exist."); + return ERR_INVALID_VALUE; + } + + auto timeoutTask = [pid]() { + if (kill(pid, SIGKILL) != ERR_OK) { + HILOG_ERROR("Kill app not response process failed."); + } + HILOG_WARN("send kill app not response process signal."); + }; + auto abilityMgr = DelayedSingleton::GetInstance(); + CHECK_POINTER_AND_RETURN(abilityMgr, ERR_INVALID_VALUE); + abilityMgr->GetEventHandler()->PostTask(timeoutTask, TASK_NAME_ANR, timeout_); + + return ERR_OK; +} + +int AppNoResponseDisposer::ExcuteANRSaveStackInfoTask(int pid, const SetMissionClosure &task) const +{ + std::vector> tokens; + auto appScheduler = DelayedSingleton::GetInstance(); + CHECK_POINTER_AND_RETURN(appScheduler, ERR_INVALID_VALUE); + + if (appScheduler->GetAbilityRecordsByProcessID(pid, tokens) != ERR_OK) { + HILOG_ERROR("Get ability record failed."); + return ERR_INVALID_VALUE; + } + + task(tokens); + + if (kill(pid, SIGUSR1) != ERR_OK) { + HILOG_ERROR("Send singal SIGUSR1 error."); + return SEND_USR1_SIG_FAIL; + } + + return ERR_OK; +} +} // namespace AAFwk +} // namespace OHOS diff --git a/services/abilitymgr/src/app_scheduler.cpp b/services/abilitymgr/src/app_scheduler.cpp index 90aadbac7a..f56fe05361 100644 --- a/services/abilitymgr/src/app_scheduler.cpp +++ b/services/abilitymgr/src/app_scheduler.cpp @@ -366,6 +366,18 @@ int AppScheduler::GetAbilityRecordsByProcessID(const int pid, std::vector(appMgrClient_->GetApplicationInfoByProcessID(pid, application)); + if (ret != ERR_OK) { + HILOG_ERROR("GetApplicationInfoByProcessID failed."); + return ret; + } + + return ERR_OK; +} + #ifdef ABILITY_COMMAND_FOR_TEST int AppScheduler::BlockAppService() { diff --git a/services/abilitymgr/src/mission.cpp b/services/abilitymgr/src/mission.cpp index f6bb79859b..e93e651de9 100644 --- a/services/abilitymgr/src/mission.cpp +++ b/services/abilitymgr/src/mission.cpp @@ -96,9 +96,9 @@ bool Mission::IsMovingState() const return isMovingToFront_; } -void Mission::SetANRState() +void Mission::SetANRState(bool state) { - isANRState_ = true; + isANRState_ = state; } bool Mission::IsANRState() const diff --git a/services/abilitymgr/src/mission_list_manager.cpp b/services/abilitymgr/src/mission_list_manager.cpp index 6d06885127..44044a7b01 100644 --- a/services/abilitymgr/src/mission_list_manager.cpp +++ b/services/abilitymgr/src/mission_list_manager.cpp @@ -2671,5 +2671,23 @@ int MissionListManager::BlockAbility(int32_t abilityRecordId) return ret; } #endif + +void MissionListManager::SetMissionANRStateByTokens(const std::vector> &tokens) +{ + HILOG_INFO("%{public}s", __func__); + for (auto &item : tokens) { + auto abilityRecord = GetAbilityRecordByToken(item); + if (abilityRecord == nullptr) { + HILOG_WARN("abilityRecord is nullptr."); + continue; + } + auto mission = abilityRecord->GetMission(); + if (mission == nullptr) { + HILOG_WARN("mission is nullptr."); + continue; + } + mission->SetANRState(true); + } +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/system_dialog_scheduler.cpp b/services/abilitymgr/src/system_dialog_scheduler.cpp new file mode 100644 index 0000000000..093835603e --- /dev/null +++ b/services/abilitymgr/src/system_dialog_scheduler.cpp @@ -0,0 +1,210 @@ +/* + * 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 "system_dialog_scheduler.h" + +#include + +#include "ability_util.h" +#include "display_manager.h" +#include "errors.h" +#include "hilog_wrapper.h" +#include "in_process_call_wrapper.h" +#include "locale_config.h" +#include "resource_manager.h" +#include "ui_service_mgr_client.h" + +namespace OHOS { +namespace AAFwk { +const int32_t UI_ANR_DIALOG_WIDTH = 328 * 2; +const int32_t UI_ANR_DIALOG_HEIGHT = 192 * 2; +const std::string EVENT_WAITING_CODE = "0"; +const std::string EVENT_CLOSE_CODE = "1"; +const std::string APP_NAME = "appName"; + +const int32_t UI_HALF = 2; +const int32_t UI_DEFAULT_BUTTOM_CLIP = 100; +const int32_t UI_WIDTH_780DP = 1560; +const int32_t UI_DEFAULT_WIDTH = 2560; +const int32_t UI_DEFAULT_HEIGHT = 1600; + +const std::string STR_PHONE = "phone"; +const std::string STR_PC = "pc"; +const std::string DIALOG_NAME_ANR = "dialog_anr_service"; + +SystemDialogScheduler::SystemDialogScheduler(const std::string &deviceType): deviceType_(deviceType) {} + +void SystemDialogScheduler::ScheduleShowDialog(const std::string &name, const DialogPosition &position, + const std::string ¶ms, DialogCallback callback) const +{ + if (name.empty()) { + HILOG_ERROR("dialog name is empty."); + return; + } + + HILOG_INFO("Show Dialog:[%{public}s], \ + Dialog position:[%{public}d, %{public}d, %{public}d, %{public}d], str: %{public}s", + name.data(), position.offsetX, position.offsetY, position.width, position.height, params.data()); + + Ace::UIServiceMgrClient::GetInstance()->ShowDialog( + name, + params, + OHOS::Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, + position.offsetX, position.offsetY, position.width, position.height, + callback); + + HILOG_INFO("Show UI Dialog finished."); +} + +int32_t SystemDialogScheduler::ShowANRDialog(const std::string &appName, const Closure &anrCallBack) +{ + HILOG_DEBUG("ShowAnrDialog start"); + + DialogPosition position; + GetDialogPositionAndSize(DialogType::DIALOG_ANR, position); + + nlohmann::json jsonObj; + jsonObj[APP_NAME] = appName; + const std::string params = jsonObj.dump(); + + auto callback = [anrCallBack] (int32_t id, const std::string& event, const std::string& params) { + HILOG_INFO("Dialog anr callback: id : %{public}d, event: %{public}s, params: %{public}s", + id, event.data(), params.data()); + + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); + + if (params == EVENT_WAITING_CODE) { + HILOG_WARN("user choose to wait no response app."); + return; + } + if (params == EVENT_CLOSE_CODE) { + HILOG_WARN("user choose to kill no response app."); + anrCallBack(); + } + }; + + ScheduleShowDialog(DIALOG_NAME_ANR, position, params, callback); + + HILOG_DEBUG("ShowAnrDialog end"); + return ERR_OK; +} + +void SystemDialogScheduler::InitDialogPosition(DialogType type, DialogPosition &position) const +{ + position.wideScreen = (deviceType_ == STR_PC); + position.align = (deviceType_ == STR_PHONE) ? DialogAlign::BOTTOM : DialogAlign::CENTER; + + switch (type) { + case DialogType::DIALOG_ANR: + position.width = UI_ANR_DIALOG_WIDTH; + position.height = UI_ANR_DIALOG_HEIGHT; + position.width_narrow = UI_ANR_DIALOG_WIDTH; + position.height_narrow = UI_ANR_DIALOG_HEIGHT; + position.align = DialogAlign::CENTER; + break; + default: + position.width = UI_DEFAULT_WIDTH; + position.height = UI_DEFAULT_HEIGHT; + position.width_narrow = UI_DEFAULT_WIDTH; + position.height_narrow = UI_DEFAULT_HEIGHT; + break; + } +} + +void SystemDialogScheduler::GetDialogPositionAndSize(DialogType type, DialogPosition &position, int lineNums) const +{ + InitDialogPosition(type, position); + + auto display = Rosen::DisplayManager::GetInstance().GetDefaultDisplay(); + if (display == nullptr) { + HILOG_WARN("share dialog GetDefaultDisplay fail, try again."); + display = Rosen::DisplayManager::GetInstance().GetDefaultDisplay(); + } + if (display != nullptr) { + if (display->GetWidth() < UI_WIDTH_780DP) { + HILOG_INFO("show dialog narrow."); + position.width = position.width_narrow; + position.height = position.height_narrow; + } + switch (position.align) { + case DialogAlign::CENTER: + position.offsetX = (display->GetWidth() - position.width) / UI_HALF; + position.offsetY = (display->GetHeight() - position.height - UI_DEFAULT_BUTTOM_CLIP) / UI_HALF; + break; + case DialogAlign::BOTTOM: + position.offsetX = (display->GetWidth() - position.width) / UI_HALF; + position.offsetY = display->GetHeight() - position.height - UI_DEFAULT_BUTTOM_CLIP; + break; + default: + position.offsetX = (display->GetWidth() - position.width) / UI_HALF; + position.offsetY = (display->GetHeight() - position.height - UI_DEFAULT_BUTTOM_CLIP) / UI_HALF; + break; + } + } else { + HILOG_WARN("share dialog get display fail, use default wide."); + position.offsetX = (UI_DEFAULT_WIDTH - position.width) / UI_HALF; + position.offsetY = UI_DEFAULT_HEIGHT - position.height - UI_DEFAULT_BUTTOM_CLIP; + } +} + +void SystemDialogScheduler::GetAppNameFromResource(int32_t labelId, + const std::string &bundleName, int32_t userId, std::string &appName) +{ + std::shared_ptr resourceManager(Global::Resource::CreateResourceManager()); + if (resourceManager == nullptr) { + HILOG_ERROR("resourceManager init failed!"); + return; + } + + AppExecFwk::BundleInfo bundleInfo; + auto bms = GetBundleManager(); + CHECK_POINTER(bms); + if (!IN_PROCESS_CALL( + bms->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, userId))) { + HILOG_ERROR("Failed to get bundle info."); + return; + } + std::unique_ptr resConfig(Global::Resource::CreateResConfig()); + UErrorCode status = U_ZERO_ERROR; + icu::Locale locale = icu::Locale::forLanguageTag(Global::I18n::LocaleConfig::GetSystemLanguage(), status); + resConfig->SetLocaleInfo(locale); + resourceManager->UpdateResConfig(*resConfig); + + for (auto resPath = bundleInfo.moduleResPaths.begin(); resPath != bundleInfo.moduleResPaths.end(); resPath++) { + if (resPath->empty()) { + continue; + } + if (!resourceManager->AddResource(resPath->c_str())) { + HILOG_INFO("resourceManager add %{public}s resource path failed!", bundleInfo.name.c_str()); + } + } + resourceManager->GetStringById(static_cast(labelId), appName); + HILOG_INFO("get app display info, labelId: %{public}d, appname: %{public}s", labelId, appName.c_str()); +} + +sptr SystemDialogScheduler::GetBundleManager() +{ + if (iBundleManager_ == nullptr) { + auto bundleObj = + OHOS::DelayedSingleton::GetInstance()->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + if (bundleObj == nullptr) { + HILOG_ERROR("Failed to get bundle manager service."); + return nullptr; + } + iBundleManager_ = iface_cast(bundleObj); + } + return iBundleManager_; +} +} // namespace AAFwk +} // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/test/BUILD.gn b/services/abilitymgr/test/BUILD.gn index 62237f11bf..86d9745a85 100644 --- a/services/abilitymgr/test/BUILD.gn +++ b/services/abilitymgr/test/BUILD.gn @@ -31,6 +31,7 @@ ohos_source_set("abilityms_test_source") { "${services_path}/abilitymgr/src/ability_start_setting.cpp", "${services_path}/abilitymgr/src/ability_token_stub.cpp", "${services_path}/abilitymgr/src/ams_configuration_parameter.cpp", + "${services_path}/abilitymgr/src/app_no_response_disposer.cpp", "${services_path}/abilitymgr/src/atomic_service_status_callback.cpp", "${services_path}/abilitymgr/src/atomic_service_status_callback_proxy.cpp", "${services_path}/abilitymgr/src/atomic_service_status_callback_stub.cpp", @@ -63,6 +64,10 @@ ohos_source_set("abilityms_test_source") { "${services_path}/common/src/event_report.cpp", ] + if (ability_runtime_graphics) { + sources += [ "${services_path}/abilitymgr/src/system_dialog_scheduler.cpp" ] + } + include_dirs = [ "${bundlefwk_inner_api_path}/appexecfwk_core/include/", "${services_path}/abilitymgr/test/mock/libs/system_ability_mock", @@ -169,6 +174,7 @@ group("unittest") { "unittest/phone/ability_manager_client_test:unittest", "unittest/phone/ability_manager_proxy_test:unittest", "unittest/phone/ability_manager_service_account_test:unittest", + "unittest/phone/ability_manager_service_anr_test:unittest", "unittest/phone/ability_manager_stub_test:unittest", "unittest/phone/ability_record_dump_test:unittest", "unittest/phone/ability_record_test:unittest", diff --git a/services/abilitymgr/test/mock/BUILD.gn b/services/abilitymgr/test/mock/BUILD.gn index d14a58aa56..98734a3e8f 100644 --- a/services/abilitymgr/test/mock/BUILD.gn +++ b/services/abilitymgr/test/mock/BUILD.gn @@ -21,6 +21,7 @@ group("mock_target") { "libs/aakit:aakit_mock", "libs/appexecfwk_core:appexecfwk_appmgr_mock", "libs/appexecfwk_core:appexecfwk_bundlemgr_mock", + "libs/arkui_mock:arkui_mock", "libs/sa_mgr:sa_mgr_mock", ] } @@ -30,6 +31,7 @@ config("aafwk_mock_config") { "libs/aakit:aakit_mock_config", "libs/appexecfwk_core:appexecfwk_core_mock_config", "libs/sa_mgr:sa_mgr_mock_config", + "libs/arkui_mock:arkui_mock_config", "appmgr_test_service:appmgr_test_service_config", ] } diff --git a/services/abilitymgr/test/mock/libs/arkui_mock/BUILD.gn b/services/abilitymgr/test/mock/libs/arkui_mock/BUILD.gn new file mode 100644 index 0000000000..248b365176 --- /dev/null +++ b/services/abilitymgr/test/mock/libs/arkui_mock/BUILD.gn @@ -0,0 +1,52 @@ +# 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. + +import("//build/ohos.gni") +import("//foundation/ability/ability_runtime/aafwk.gni") + +config("arkui_mock_config") { + include_dirs = [ + "//foundation/arkui/ace_engine/interfaces/inner_api/ui_service_manager/include", + "//foundation/ability/ability_runtime/services/abilitymgr/test/mock/libs/arkui_mock/include", + "//foundation/arkui/ace_engine/adapter/ohos/services/uiservice/include", + "//foundation/windowmanager/interfaces/innerkits", + "//foundation/multimodalinput/input/interfaces/native/innerkits/event/include", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } +} + +ohos_source_set("arkui_mock") { + sources = [ "src/ui_service_mgr_client_mock.cpp" ] + testonly = true + configs = [ ":arkui_mock_config" ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + "//utils/native/base:utils", + ] + + external_deps = [ + "ability_base:want", + "bundle_framework:appexecfwk_base", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] +} diff --git a/services/abilitymgr/test/mock/libs/arkui_mock/include/ui_service_mgr_client_mock.h b/services/abilitymgr/test/mock/libs/arkui_mock/include/ui_service_mgr_client_mock.h new file mode 100644 index 0000000000..8938990ccb --- /dev/null +++ b/services/abilitymgr/test/mock/libs/arkui_mock/include/ui_service_mgr_client_mock.h @@ -0,0 +1,88 @@ +/* + * 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_AAFWK_UI_SERVICE_MANAGER_CLIENT_MOCK_H +#define OHOS_AAFWK_UI_SERVICE_MANAGER_CLIENT_MOCK_H + +#include + +#include "ability_info.h" +#include "dialog_callback_interface.h" +#include "iremote_object.h" +#include "ui_service_interface.h" +#include "ui_service_mgr_errors.h" +#include "ui_service_mgr_interface.h" +#include "uri.h" + +namespace OHOS { +namespace Ace { +class UIServiceMgrClientMock { +public: + UIServiceMgrClientMock(); + virtual ~UIServiceMgrClientMock(); + static std::shared_ptr GetInstance(); + + ErrCode RegisterCallBack(const AAFwk::Want& want, const sptr& uiService); + + ErrCode UnregisterCallBack(const AAFwk::Want& want); + + ErrCode Push(const AAFwk::Want& want, + const std::string& name, const std::string& jsonPath, const std::string& data, const std::string& extraData); + + ErrCode Request(const AAFwk::Want& want, const std::string& name, const std::string& data); + + ErrCode ReturnRequest( + const AAFwk::Want& want, const std::string& source, const std::string& data, const std::string& extraData); + + ErrCode ShowDialog(const std::string& name, + const std::string& params, + OHOS::Rosen::WindowType windowType, + int x, + int y, + int width, + int height, + DialogCallback callback, + int* id = nullptr); + + ErrCode CancelDialog(int32_t id); + + ErrCode UpdateDialog(int32_t id, const std::string& data); + + ErrCode ShowAppPickerDialog( + const AAFwk::Want& want, const std::vector& abilityInfos, int32_t userId); + + void static SetDialogCheckState(int pid, const std::string& code) + { + pid_ = pid; + code_ = code; + } + +private: + ErrCode Connect(); + + const std::string GetPickerDialogParam(const AAFwk::Want& want, + const std::vector& abilityInfos, bool wideScreen = true) const; + void GetDisplayPosition( + int32_t& offsetX, int32_t& offsetY, int32_t& width, int32_t& height, bool& wideScreen); + + static std::mutex mutex_; + static std::shared_ptr instance_; + sptr remoteObject_; + static int pid_; + static std::string code_; +}; +} // namespace Ace +} // namespace OHOS +#endif // OHOS_AAFWK_UI_SERVICE_MANAGER_CLIENT_MOCK_H diff --git a/services/abilitymgr/test/mock/libs/arkui_mock/src/ui_service_mgr_client_mock.cpp b/services/abilitymgr/test/mock/libs/arkui_mock/src/ui_service_mgr_client_mock.cpp new file mode 100644 index 0000000000..eef1e0514d --- /dev/null +++ b/services/abilitymgr/test/mock/libs/arkui_mock/src/ui_service_mgr_client_mock.cpp @@ -0,0 +1,132 @@ +/* + * 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 "ui_service_mgr_client_mock.h" + +#include + +#include "dialog_callback_stub.h" +#include "hilog_wrapper.h" +#include "if_system_ability_manager.h" +#include "ipc_skeleton.h" +#include "iservice_registry.h" +#include "string_ex.h" +#include "system_ability_definition.h" + +// external dependence +#include "ability_manager_client.h" +#include "display_manager.h" + +namespace OHOS { +namespace Ace { +std::shared_ptr UIServiceMgrClientMock::instance_ = nullptr; +int UIServiceMgrClientMock::pid_ = 0; +std::string UIServiceMgrClientMock::code_ = "0"; +std::mutex UIServiceMgrClientMock::mutex_; +namespace { +const std::string EVENT_WAITING_CODE = "0"; +const std::string EVENT_CLOSE_CODE = "1"; +} + +std::shared_ptr UIServiceMgrClientMock::GetInstance() +{ + if (instance_ == nullptr) { + std::lock_guard lock_l(mutex_); + if (instance_ == nullptr) { + instance_ = std::make_shared(); + } + } + return instance_; +} + +UIServiceMgrClientMock::UIServiceMgrClientMock() +{} + +UIServiceMgrClientMock::~UIServiceMgrClientMock() +{} + +ErrCode UIServiceMgrClientMock::RegisterCallBack(const AAFwk::Want& want, const sptr& uiService) +{ + return 0; +} + +ErrCode UIServiceMgrClientMock::UnregisterCallBack(const AAFwk::Want& want) +{ + return 0; +} + +ErrCode UIServiceMgrClientMock::Push(const AAFwk::Want& want, const std::string& name, const std::string& jsonPath, + const std::string& data, const std::string& extraData) +{ + return 0; +} + +ErrCode UIServiceMgrClientMock::Request(const AAFwk::Want& want, const std::string& name, const std::string& data) +{ + return 0; +} + +ErrCode UIServiceMgrClientMock::ReturnRequest(const AAFwk::Want& want, const std::string& source, + const std::string& data, const std::string& extraData) +{ + return 0; +} + +ErrCode UIServiceMgrClientMock::ShowDialog(const std::string& name, const std::string& params, + OHOS::Rosen::WindowType windowType, int x, int y, int width, int height, DialogCallback callback, int* id) +{ + if (code_ == EVENT_WAITING_CODE) { + return 0; + } + if (code_ == EVENT_CLOSE_CODE) { + kill(pid_, SIGKILL); + } + return 0; +} + +ErrCode UIServiceMgrClientMock::CancelDialog(int32_t id) +{ + return 0; +} + +ErrCode UIServiceMgrClientMock::UpdateDialog(int32_t id, const std::string& data) +{ + return 0; +} + +ErrCode UIServiceMgrClientMock::ShowAppPickerDialog( + const AAFwk::Want& want, const std::vector& abilityInfos, int32_t userId) +{ + return 0; +} + +ErrCode UIServiceMgrClientMock::Connect() +{ + return 0; +} + +const std::string UIServiceMgrClientMock::GetPickerDialogParam( + const AAFwk::Want& want, const std::vector& abilityInfos, bool wideScreen) const +{ + return ""; +} + +void UIServiceMgrClientMock::GetDisplayPosition( + int32_t& offsetX, int32_t& offsetY, int32_t& width, int32_t& height, bool& wideScreen) +{ + return; +} +} // namespace Ace +} // namespace OHOS diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_service_anr_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/ability_manager_service_anr_test/BUILD.gn new file mode 100644 index 0000000000..91b8b7ddaf --- /dev/null +++ b/services/abilitymgr/test/unittest/phone/ability_manager_service_anr_test/BUILD.gn @@ -0,0 +1,73 @@ +# 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. + +import("//build/test.gni") +import("//foundation/ability/ability_runtime/aafwk.gni") + +module_output_path = "ability_runtime/abilitymgr" + +ohos_unittest("ability_manager_service_anr_test") { + module_out_path = module_output_path + + include_dirs = [ + "${services_path}/abilitymgr/test/mock/libs/system_ability_mock", + "${services_path}/abilitymgr/test/mock/libs/arkui_mock", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include", + "//foundation/distributedschedule/samgr/adapter/interfaces/innerkits/include/", + "${aafwk_path}/interfaces/inner_api/app_manager/include/appmgr", + "${aafwk_path}/frameworks/kits/ability/native/test/mock/include", + "//base/notification/common_event_service/frameworks/core/include", + "//base/notification/common_event_service/interfaces/inner_api", + ] + + sources = [ + # add mock file + "${services_path}/abilitymgr/test/mock/libs/arkui_mock/src/ui_service_mgr_client_mock.cpp", + "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", + "ability_manager_service_anr_test.cpp", + ] + + configs = [ "${services_path}/abilitymgr:abilityms_config" ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${services_path}/abilitymgr/test:abilityms_test_source", + "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", + "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", + "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", + "${services_path}/common:perm_verification", + "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native", + "${aafwk_path}/interfaces/inner_api/app_manager:app_manager", + "${aafwk_path}/services/abilitymgr:abilityms", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + "//third_party/icu/icu4c:shared_icuuc", + "//third_party/libpng:libpng", + "//utils/native/base:utils", + ] + + external_deps = [ + "ability_base:zuri", + "access_token:libaccesstoken_sdk", + "dsoftbus_standard:softbus_client", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] +} + +group("unittest") { + testonly = true + deps = [ ":ability_manager_service_anr_test" ] +} diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_service_anr_test/ability_manager_service_anr_test.cpp b/services/abilitymgr/test/unittest/phone/ability_manager_service_anr_test/ability_manager_service_anr_test.cpp new file mode 100644 index 0000000000..8e9f9849a4 --- /dev/null +++ b/services/abilitymgr/test/unittest/phone/ability_manager_service_anr_test/ability_manager_service_anr_test.cpp @@ -0,0 +1,191 @@ +/* + * 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 +#define private public +#define protected public +#include "ability_manager_service.h" +#include "ability_event_handler.h" +#undef private +#undef protected + +#include "app_process_data.h" +#include "ability_manager_errors.h" +#include "ability_scheduler.h" +#include "bundlemgr/mock_bundle_manager.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" +#include "mock_ability_connect_callback.h" +#include "mock_ability_token.h" +#include "sa_mgr_client.h" +#include "system_ability_definition.h" +#include "ui_service_mgr_client_mock.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::AppExecFwk; + +namespace { + const std::string DEVICE_ID = "15010038475446345206a332922cb765"; + const std::string BUNDLE_NAME = "testBundle"; + const std::string NAME = ".testMainAbility"; + const std::string EVENT_WAITING_CODE = "0"; + const std::string EVENT_CLOSE_CODE = "1"; +} + +namespace OHOS { +namespace AAFwk { +static void WaitUntilTaskFinished() +{ + const uint32_t maxRetryCount = 1000; + const uint32_t sleepTime = 1000; + uint32_t count = 0; + auto handler = OHOS::DelayedSingleton::GetInstance()->GetEventHandler(); + std::atomic taskCalled(false); + auto f = [&taskCalled]() { taskCalled.store(true); }; + if (handler->PostTask(f)) { + while (!taskCalled.load()) { + ++count; + if (count >= maxRetryCount) { + break; + } + usleep(sleepTime); + } + } +} + +namespace { +const std::string WaitUntilTaskFinishedByTimer = "BundleMgrService"; +} // namespace + +class AbilityManagerServiceAnrTest : public testing::Test { +public: + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + void OnStartAms(); + void OnStopAms(); + static constexpr int TEST_WAIT_TIME = 100000; + +public: + AbilityRequest abilityRequest_; + std::shared_ptr abilityRecord_ {nullptr}; + std::shared_ptr abilityMs_ = DelayedSingleton::GetInstance(); +}; + +void AbilityManagerServiceAnrTest::OnStartAms() +{ + if (abilityMs_) { + if (abilityMs_->state_ == ServiceRunningState::STATE_RUNNING) { + return; + } + + abilityMs_->state_ = ServiceRunningState::STATE_RUNNING; + + abilityMs_->eventLoop_ = AppExecFwk::EventRunner::Create(AbilityConfig::NAME_ABILITY_MGR_SERVICE); + EXPECT_TRUE(abilityMs_->eventLoop_); + + abilityMs_->handler_ = std::make_shared(abilityMs_->eventLoop_, abilityMs_); + + abilityMs_->dataAbilityManager_ = std::make_shared(); + abilityMs_->dataAbilityManagers_.emplace(0, abilityMs_->dataAbilityManager_); + EXPECT_TRUE(abilityMs_->dataAbilityManager_); + + abilityMs_->amsConfigResolver_ = std::make_shared(); + EXPECT_TRUE(abilityMs_->amsConfigResolver_); + abilityMs_->amsConfigResolver_->Parse(); + + abilityMs_->pendingWantManager_ = std::make_shared(); + EXPECT_TRUE(abilityMs_->pendingWantManager_); + + abilityMs_->eventLoop_->Run(); + return; + } + + GTEST_LOG_(INFO) << "OnStart fail"; +} + +void AbilityManagerServiceAnrTest::OnStopAms() +{ + abilityMs_->OnStop(); +} + +void AbilityManagerServiceAnrTest::TearDownTestCase() +{ + OHOS::DelayedSingleton::DestroyInstance(); +} + +void AbilityManagerServiceAnrTest::SetUp() +{ + OnStartAms(); + WaitUntilTaskFinished(); +} + +void AbilityManagerServiceAnrTest::TearDown() +{ + OnStopAms(); +} + +/* + * Feature: AbilityManagerService + * Function: SendANRProcessID + * SubFunction: NA + * FunctionPoints: Kill anr process + * EnvConditions: NA + * CaseDescription: Fork a new process, call SendANRProcessID func in new process id + * click close buntton, kill the new process + */ +HWTEST_F(AbilityManagerServiceAnrTest, SendANRProcessID_001, TestSize.Level1) +{ + pid_t pid; + if ((pid=fork()) == 0) { + for (;;) { + } + } + else { + Ace::UIServiceMgrClientMock::GetInstance()->SetDialogCheckState(pid, EVENT_CLOSE_CODE); + auto result = abilityMs_->SendANRProcessID(pid); + sleep(6); + result = kill(pid, SIGKILL); + EXPECT_EQ(result, -1); + } +} + +/* + * Feature: AbilityManagerService + * Function: SendANRProcessID + * SubFunction: NA + * FunctionPoints: Waiting anr process + * EnvConditions: NA + * CaseDescription: Fork a new process, call SendANRProcessID func in new process id + * click waiting buntton, do not kill the new process + */ +HWTEST_F(AbilityManagerServiceAnrTest, SendANRProcessID_002, TestSize.Level1) +{ + pid_t pid; + if ((pid=fork()) == 0) { + for (;;) { + } + } + else { + Ace::UIServiceMgrClientMock::GetInstance()->SetDialogCheckState(pid, EVENT_WAITING_CODE); + auto result = abilityMs_->SendANRProcessID(pid); + sleep(6); + result = kill(pid, SIGKILL); + EXPECT_EQ(result, 0); + } +} +} +} \ No newline at end of file diff --git a/services/appmgr/include/ams_mgr_scheduler.h b/services/appmgr/include/ams_mgr_scheduler.h index 5bc4689f35..156d55358f 100644 --- a/services/appmgr/include/ams_mgr_scheduler.h +++ b/services/appmgr/include/ams_mgr_scheduler.h @@ -146,6 +146,8 @@ public: */ virtual int KillApplicationByUid(const std::string &bundleName, const int uid) override; + int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application) override; + virtual void AbilityAttachTimeOut(const sptr &token) override; virtual void PrepareTerminate(const sptr &token) override; diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index e388c280a4..f0d9898403 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -201,14 +201,7 @@ public: virtual void ScheduleAcceptWantDone( const int32_t recordId, const AAFwk::Want &want, const std::string &flag) override; - /** - * Get the token of ability records by process ID. - * - * @param pid The process id. - * @param tokens The token of ability records. - * @return Returns true on success, others on failure. - */ - int GetAbilityRecordsByProcessID(const int pid, std::vector> &tokens) override; + virtual int GetAbilityRecordsByProcessID(const int pid, std::vector> &tokens) override; virtual int StartRenderProcess(const std::string &renderParam, int32_t ipcFd, int32_t sharedFd, pid_t &renderPid) override; diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 1bdcaea7c7..b6368d7c53 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -519,6 +519,7 @@ public: void ClearAppRunningData(const std::shared_ptr &appRecord, bool containsApp); + int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application); /** * Notify application status. * diff --git a/services/appmgr/src/ams_mgr_scheduler.cpp b/services/appmgr/src/ams_mgr_scheduler.cpp index f813077037..01c8f55ee6 100644 --- a/services/appmgr/src/ams_mgr_scheduler.cpp +++ b/services/appmgr/src/ams_mgr_scheduler.cpp @@ -251,5 +251,14 @@ void AmsMgrScheduler::RegisterStartSpecifiedAbilityResponse(const sptrRegisterStartSpecifiedAbilityResponse(response); }; amsHandler_->PostTask(task); } + +int AmsMgrScheduler::GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application) +{ + if (!IsReady()) { + return ERR_INVALID_OPERATION; + } + return amsMgrServiceInner_->GetApplicationInfoByProcessID(pid, application); +} + } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index cc9b3c3f5e..b6f86c894c 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -2234,6 +2234,29 @@ int AppMgrServiceInner::GetAbilityRecordsByProcessID(const int pid, std::vector< return ERR_OK; } +int AppMgrServiceInner::GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application) +{ + auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); + if (!isSaCall) { + HILOG_ERROR("no permissions."); + return ERR_PERMISSION_DENIED; + } + auto appRecord = GetAppRunningRecordByPid(pid); + if (!appRecord) { + HILOG_ERROR("no such appRecord"); + return ERR_NAME_NOT_FOUND; + } + + auto info = appRecord->GetApplicationInfo(); + if (info) { + application = *info; + } else { + HILOG_ERROR("ApplicationInfo is nullptr !"); + return ERR_NO_INIT; + } + return ERR_OK; +} + int AppMgrServiceInner::VerifyProcessPermission() { auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); diff --git a/services/appmgr/test/mock/include/mock_ams_mgr_scheduler.h b/services/appmgr/test/mock/include/mock_ams_mgr_scheduler.h index 9265c36921..9484ff387a 100644 --- a/services/appmgr/test/mock/include/mock_ams_mgr_scheduler.h +++ b/services/appmgr/test/mock/include/mock_ams_mgr_scheduler.h @@ -45,6 +45,7 @@ public: void(const sptr &token, OHOS::AppExecFwk::RunningProcessInfo &info)); MOCK_METHOD2(StartSpecifiedAbility, void(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo)); MOCK_METHOD1(RegisterStartSpecifiedAbilityResponse, void(const sptr &response)); + MOCK_METHOD2(GetApplicationInfoByProcessID, int(const int pid, AppExecFwk::ApplicationInfo &application)); MockAmsMgrScheduler() : AmsMgrStub() {}; virtual ~MockAmsMgrScheduler() {}; diff --git a/services/dialog_ui/dialog_anr/js/BUILD.gn b/services/dialog_ui/dialog_anr/js/BUILD.gn new file mode 100644 index 0000000000..e621a414ff --- /dev/null +++ b/services/dialog_ui/dialog_anr/js/BUILD.gn @@ -0,0 +1,25 @@ +# 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. + +import("//foundation/arkui/ace_engine/build/ace_gen_sa_dialog_js.gni") + +gen_sa_dialog_js("dialog_anr_js_files_etc") { + project_path = "//foundation/ability/ability_runtime/services/dialog_ui/dialog_anr/js" + i18n_files = [ + "i18n/en-US.json", + "i18n/zh-CN.json", + ] + dialog_name = "dialog_anr_service" + part_name = "ability_runtime" + subsystem_name = "aafwk" +} diff --git a/services/dialog_ui/dialog_anr/js/i18n/en-US.json b/services/dialog_ui/dialog_anr/js/i18n/en-US.json new file mode 100644 index 0000000000..fcbbd62500 --- /dev/null +++ b/services/dialog_ui/dialog_anr/js/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "message": { + "title": "no response", + "titleList": "The app is not responding, if you close the app, you may lose recent data, and the app may respond if you keep waiting.", + "waiting": "Wait", + "close": "Close" + } +} \ No newline at end of file diff --git a/services/dialog_ui/dialog_anr/js/i18n/zh-CN.json b/services/dialog_ui/dialog_anr/js/i18n/zh-CN.json new file mode 100644 index 0000000000..dc7d562e12 --- /dev/null +++ b/services/dialog_ui/dialog_anr/js/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "message": { + "title": "未响应", + "titleList": "应用未响应,如果您关闭应用,可能丢失最近的数据,如果您继续等待,应用可能会响应。", + "waiting": "等待响应", + "close": "关闭应用" + } +} \ No newline at end of file diff --git a/services/dialog_ui/dialog_anr/js/pages/index/index.css b/services/dialog_ui/dialog_anr/js/pages/index/index.css new file mode 100644 index 0000000000..03112cdf1e --- /dev/null +++ b/services/dialog_ui/dialog_anr/js/pages/index/index.css @@ -0,0 +1,87 @@ +/* + 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. +*/ + +.container { + flex-direction: column; + justify-content: center; + align-items: center; + border-radius: 16vp; + background-color: #FFFFFF; +} + +.div-title { + text-align: left; + flex-direction: column; +} + +.title { + font-size: 20vp; + font-weight: Medium; + height: 29%; + text-align: left; + margin-left: 5%; + text-overflow: ellipsis; +} + +.title-list { + font-size: 16fp; + height: 38%; + margin-left: 5%; + margin-right: 5%; + margin-bottom: 8%; + font-weight: regular; +} + +.but { + text-align: center; +} + +.but-close { + width: 44%; + height: 21%; + margin-right: 5%; + margin-bottom: 8%; + align-items: center; + flex-direction: column; + justify-content: center; + line-height: 21%; + background-color: #0A59F7; + border-radius: 50%; +} + +.but-waiting { + width: 44%; + height: 21%; + margin-left: 5%; + margin-bottom: 8%; + align-items: center; + flex-direction: column; + justify-content: center; + line-height: 21%; + background-color: #FFFFFF; + border-radius: 50%; +} + +.text-waiting { + font-size: 16fp; + color: #0A59F7; + font-weight: regular; +} + +.text-close { + font-size: 16fp; + color: #FFFFFF; + font-weight: regular; +} \ No newline at end of file diff --git a/services/dialog_ui/dialog_anr/js/pages/index/index.hml b/services/dialog_ui/dialog_anr/js/pages/index/index.hml new file mode 100644 index 0000000000..9a7d1cd82e --- /dev/null +++ b/services/dialog_ui/dialog_anr/js/pages/index/index.hml @@ -0,0 +1,33 @@ + + +
+
+ + {{labelAppName}}{{$t('message.title')}} + + + {{$t('message.titleList')}} + +
+
+
+ {{$t('message.waiting')}} +
+
+ {{$t('message.close')}} +
+
+
\ No newline at end of file diff --git a/services/dialog_ui/dialog_anr/js/pages/index/index.js b/services/dialog_ui/dialog_anr/js/pages/index/index.js new file mode 100644 index 0000000000..f1cdceaa07 --- /dev/null +++ b/services/dialog_ui/dialog_anr/js/pages/index/index.js @@ -0,0 +1,41 @@ +/* + 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. +*/ + +import resourceManager from '@ohos.resourceManager'; + +var EVENT_WAITING = "EVENT_WAITING"; +var EVENT_CLOSE = "EVENT_CLOSE"; +var EVENT_WAITING_CODE = "0"; +var EVENT_CLOSE_CODE = "1"; +export default { + data: { + labelAppName: "", + }, + onInit() { + console.info('onInit'); + this.labelAppName = this.appName; + }, + onShow() { + console.info('onshow'); + }, + onWaiting() { + console.info('click waiting for a response'); + callNativeHandler(EVENT_WAITING, EVENT_WAITING_CODE); + }, + onCloseApp() { + console.info('click close app'); + callNativeHandler(EVENT_CLOSE, EVENT_CLOSE_CODE); + } +} \ No newline at end of file diff --git a/services/test/BUILD.gn b/services/test/BUILD.gn index ea2095b1d8..1cb45fd9a2 100644 --- a/services/test/BUILD.gn +++ b/services/test/BUILD.gn @@ -57,6 +57,7 @@ group("moduletest") { "moduletest/panding_want_manager_test:moduletest", "moduletest/running_infos_module_test:moduletest", "moduletest/start_option_display_id_test:moduletest", + "//third_party/icu/icu4c:shared_icuuc", "//third_party/jsoncpp:jsoncpp", ] } diff --git a/services/test/moduletest/common/ams/BUILD.gn b/services/test/moduletest/common/ams/BUILD.gn index 310fe8c063..c4de1acb30 100644 --- a/services/test/moduletest/common/ams/BUILD.gn +++ b/services/test/moduletest/common/ams/BUILD.gn @@ -88,6 +88,7 @@ ohos_source_set("appmgr_mst_source") { "${services_path}/common:perm_verification", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", + "//third_party/icu/icu4c:shared_icuuc", "//utils/native/base:utils", ] diff --git a/services/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn b/services/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn index 4474475a5d..325c235aa5 100644 --- a/services/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn +++ b/services/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn @@ -62,6 +62,7 @@ ohos_moduletest("specified_ability_service_test") { "//base/notification/eventhandler/frameworks/eventhandler:libeventhandler", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", + "//third_party/icu/icu4c:shared_icuuc", "//third_party/jsoncpp:jsoncpp", "//utils/native/base:utils", ] diff --git a/services/test/moduletest/on_new_want_module_test/BUILD.gn b/services/test/moduletest/on_new_want_module_test/BUILD.gn index ecdc45f117..1f38ca50d3 100644 --- a/services/test/moduletest/on_new_want_module_test/BUILD.gn +++ b/services/test/moduletest/on_new_want_module_test/BUILD.gn @@ -60,6 +60,7 @@ ohos_moduletest("on_new_want_module_test") { "//base/notification/eventhandler/frameworks/eventhandler:libeventhandler", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", + "//third_party/icu/icu4c:shared_icuuc", "//third_party/jsoncpp:jsoncpp", "//utils/native/base:utils", ] diff --git a/services/test/moduletest/running_infos_module_test/BUILD.gn b/services/test/moduletest/running_infos_module_test/BUILD.gn index 301d9597bc..67a9c55e30 100644 --- a/services/test/moduletest/running_infos_module_test/BUILD.gn +++ b/services/test/moduletest/running_infos_module_test/BUILD.gn @@ -83,6 +83,7 @@ ohos_moduletest("running_infos_module_test") { "//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", + "//third_party/icu/icu4c:shared_icuuc", "//third_party/jsoncpp:jsoncpp", "//utils/native/base:utils", ] -- Gitee From b30ad2a39e4659907d8af5507ea921aa21ace3cb Mon Sep 17 00:00:00 2001 From: xuchenghua09 Date: Tue, 14 Jun 2022 14:31:36 +0800 Subject: [PATCH 2/8] update Signed-off-by: xuchenghua09 --- services/abilitymgr/abilitymgr.gni | 6 ++---- .../phone/ability_manager_service_anr_test/BUILD.gn | 9 +++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/services/abilitymgr/abilitymgr.gni b/services/abilitymgr/abilitymgr.gni index 69156e3610..6cba5fe826 100644 --- a/services/abilitymgr/abilitymgr.gni +++ b/services/abilitymgr/abilitymgr.gni @@ -86,7 +86,5 @@ abilityms_files = [ ] if (ability_runtime_graphics) { - abilityms_files += [ - "src/system_dialog_scheduler.cpp", - ] -} \ No newline at end of file + abilityms_files += [ "src/system_dialog_scheduler.cpp" ] +} diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_service_anr_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/ability_manager_service_anr_test/BUILD.gn index 91b8b7ddaf..81e693cd6e 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_service_anr_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/ability_manager_service_anr_test/BUILD.gn @@ -13,6 +13,7 @@ import("//build/test.gni") import("//foundation/ability/ability_runtime/aafwk.gni") +import("//foundation/resourceschedule/background_task_mgr/bgtaskmgr.gni") module_output_path = "ability_runtime/abilitymgr" @@ -32,8 +33,8 @@ ohos_unittest("ability_manager_service_anr_test") { sources = [ # add mock file - "${services_path}/abilitymgr/test/mock/libs/arkui_mock/src/ui_service_mgr_client_mock.cpp", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", + "${services_path}/abilitymgr/test/mock/libs/arkui_mock/src/ui_service_mgr_client_mock.cpp", "ability_manager_service_anr_test.cpp", ] @@ -43,14 +44,14 @@ ohos_unittest("ability_manager_service_anr_test") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ + "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native", + "${aafwk_path}/interfaces/inner_api/app_manager:app_manager", + "${aafwk_path}/services/abilitymgr:abilityms", "${services_path}/abilitymgr/test:abilityms_test_source", "${services_path}/abilitymgr/test/mock/libs/aakit:aakit_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${services_path}/abilitymgr/test/mock/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", "${services_path}/common:perm_verification", - "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native", - "${aafwk_path}/interfaces/inner_api/app_manager:app_manager", - "${aafwk_path}/services/abilitymgr:abilityms", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", "//third_party/icu/icu4c:shared_icuuc", -- Gitee From 315e74aec775f4817852bd012edb72f7d5ec2499 Mon Sep 17 00:00:00 2001 From: xuchenghua09 Date: Tue, 14 Jun 2022 14:32:46 +0800 Subject: [PATCH 3/8] update Signed-off-by: xuchenghua09 --- services/abilitymgr/include/system_dialog_scheduler.h | 2 +- services/abilitymgr/src/app_no_response_disposer.cpp | 2 +- services/abilitymgr/src/system_dialog_scheduler.cpp | 4 ++-- services/appmgr/src/ams_mgr_scheduler.cpp | 1 - 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/services/abilitymgr/include/system_dialog_scheduler.h b/services/abilitymgr/include/system_dialog_scheduler.h index 02f6628f1b..ac93749a9f 100644 --- a/services/abilitymgr/include/system_dialog_scheduler.h +++ b/services/abilitymgr/include/system_dialog_scheduler.h @@ -37,7 +37,7 @@ struct DialogPosition { int32_t offsetX = 0; int32_t offsetY = 0; int32_t width = 0; - int32_t height = 0; + int32_t height = 0; int32_t width_narrow = 0; int32_t height_narrow = 0; bool wideScreen = true; diff --git a/services/abilitymgr/src/app_no_response_disposer.cpp b/services/abilitymgr/src/app_no_response_disposer.cpp index 223a2893e3..543f32cb22 100644 --- a/services/abilitymgr/src/app_no_response_disposer.cpp +++ b/services/abilitymgr/src/app_no_response_disposer.cpp @@ -90,7 +90,7 @@ int AppNoResponseDisposer::PostTimeoutTask(int pid, std::string bundleName) cons return ERR_INVALID_VALUE; } - // if callback process, check the process must be the same bundle name. + // if callback process, check the process must be the same bundle name. if (!bundleName.empty() && appInfo.bundleName != bundleName) { HILOG_ERROR("this application is not exist."); return ERR_INVALID_VALUE; diff --git a/services/abilitymgr/src/system_dialog_scheduler.cpp b/services/abilitymgr/src/system_dialog_scheduler.cpp index 093835603e..f91e453044 100644 --- a/services/abilitymgr/src/system_dialog_scheduler.cpp +++ b/services/abilitymgr/src/system_dialog_scheduler.cpp @@ -54,7 +54,7 @@ void SystemDialogScheduler::ScheduleShowDialog(const std::string &name, const Di } HILOG_INFO("Show Dialog:[%{public}s], \ - Dialog position:[%{public}d, %{public}d, %{public}d, %{public}d], str: %{public}s", + Dialog position : [%{public}d, %{public}d, %{public}d, %{public}d], str : %{public}s", name.data(), position.offsetX, position.offsetY, position.width, position.height, params.data()); Ace::UIServiceMgrClient::GetInstance()->ShowDialog( @@ -87,7 +87,7 @@ int32_t SystemDialogScheduler::ShowANRDialog(const std::string &appName, const C if (params == EVENT_WAITING_CODE) { HILOG_WARN("user choose to wait no response app."); return; - } + } if (params == EVENT_CLOSE_CODE) { HILOG_WARN("user choose to kill no response app."); anrCallBack(); diff --git a/services/appmgr/src/ams_mgr_scheduler.cpp b/services/appmgr/src/ams_mgr_scheduler.cpp index 01c8f55ee6..fde669bd71 100644 --- a/services/appmgr/src/ams_mgr_scheduler.cpp +++ b/services/appmgr/src/ams_mgr_scheduler.cpp @@ -259,6 +259,5 @@ int AmsMgrScheduler::GetApplicationInfoByProcessID(const int pid, AppExecFwk::Ap } return amsMgrServiceInner_->GetApplicationInfoByProcessID(pid, application); } - } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file -- Gitee From 8045b573d8d9b0f319a8da00832157f99bd6b37d Mon Sep 17 00:00:00 2001 From: xuchenghua09 Date: Tue, 14 Jun 2022 14:57:49 +0800 Subject: [PATCH 4/8] update Signed-off-by: xuchenghua09 --- .../unittest/phone/ability_manager_service_anr_test/BUILD.gn | 4 +++- services/dialog_ui/dialog_anr/js/BUILD.gn | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_service_anr_test/BUILD.gn b/services/abilitymgr/test/unittest/phone/ability_manager_service_anr_test/BUILD.gn index 81e693cd6e..31fbe83f91 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_service_anr_test/BUILD.gn +++ b/services/abilitymgr/test/unittest/phone/ability_manager_service_anr_test/BUILD.gn @@ -13,7 +13,6 @@ import("//build/test.gni") import("//foundation/ability/ability_runtime/aafwk.gni") -import("//foundation/resourceschedule/background_task_mgr/bgtaskmgr.gni") module_output_path = "ability_runtime/abilitymgr" @@ -66,6 +65,9 @@ ohos_unittest("ability_manager_service_anr_test") { "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", ] + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } } group("unittest") { diff --git a/services/dialog_ui/dialog_anr/js/BUILD.gn b/services/dialog_ui/dialog_anr/js/BUILD.gn index e621a414ff..5d44a5347e 100644 --- a/services/dialog_ui/dialog_anr/js/BUILD.gn +++ b/services/dialog_ui/dialog_anr/js/BUILD.gn @@ -14,7 +14,8 @@ import("//foundation/arkui/ace_engine/build/ace_gen_sa_dialog_js.gni") gen_sa_dialog_js("dialog_anr_js_files_etc") { - project_path = "//foundation/ability/ability_runtime/services/dialog_ui/dialog_anr/js" + project_path = + "//foundation/ability/ability_runtime/services/dialog_ui/dialog_anr/js" i18n_files = [ "i18n/en-US.json", "i18n/zh-CN.json", -- Gitee From 9dcc9f7617d8539b783973339d630fe19e1257cc Mon Sep 17 00:00:00 2001 From: xuchenghua09 Date: Tue, 14 Jun 2022 15:27:50 +0800 Subject: [PATCH 5/8] update Signed-off-by: xuchenghua09 --- services/abilitymgr/src/system_dialog_scheduler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/abilitymgr/src/system_dialog_scheduler.cpp b/services/abilitymgr/src/system_dialog_scheduler.cpp index f91e453044..3123d4fcf4 100644 --- a/services/abilitymgr/src/system_dialog_scheduler.cpp +++ b/services/abilitymgr/src/system_dialog_scheduler.cpp @@ -54,7 +54,7 @@ void SystemDialogScheduler::ScheduleShowDialog(const std::string &name, const Di } HILOG_INFO("Show Dialog:[%{public}s], \ - Dialog position : [%{public}d, %{public}d, %{public}d, %{public}d], str : %{public}s", + Dialog position: [%{public}d, %{public}d, %{public}d, %{public}d], str: %{public}s", name.data(), position.offsetX, position.offsetY, position.width, position.height, params.data()); Ace::UIServiceMgrClient::GetInstance()->ShowDialog( -- Gitee From 1b34545eae6079bf20d62ea0bcc5c187258e9ff1 Mon Sep 17 00:00:00 2001 From: xuchenghua09 Date: Tue, 14 Jun 2022 16:01:22 +0800 Subject: [PATCH 6/8] codex Signed-off-by: xuchenghua09 --- services/abilitymgr/src/system_dialog_scheduler.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/abilitymgr/src/system_dialog_scheduler.cpp b/services/abilitymgr/src/system_dialog_scheduler.cpp index 3123d4fcf4..2dab5ce394 100644 --- a/services/abilitymgr/src/system_dialog_scheduler.cpp +++ b/services/abilitymgr/src/system_dialog_scheduler.cpp @@ -53,8 +53,7 @@ void SystemDialogScheduler::ScheduleShowDialog(const std::string &name, const Di return; } - HILOG_INFO("Show Dialog:[%{public}s], \ - Dialog position: [%{public}d, %{public}d, %{public}d, %{public}d], str: %{public}s", + HILOG_INFO("Show Dialog:[%{public}s],Dialog position:[%{public}d,%{public}d,%{public}d,%{public}d],str:%{public}s", name.data(), position.offsetX, position.offsetY, position.width, position.height, params.data()); Ace::UIServiceMgrClient::GetInstance()->ShowDialog( -- Gitee From 5fcac84305095dfec54f9b293e6272dc76e1534d Mon Sep 17 00:00:00 2001 From: xuchenghua09 Date: Wed, 15 Jun 2022 14:39:38 +0800 Subject: [PATCH 7/8] update review Signed-off-by: xuchenghua09 --- .../app_manager/src/appmgr/ams_mgr_proxy.cpp | 13 ++++++++----- .../app_manager/src/appmgr/ams_mgr_stub.cpp | 6 +++--- .../abilitymgr/include/ability_manager_service.h | 2 +- .../abilitymgr/include/app_no_response_disposer.h | 3 +-- .../abilitymgr/include/system_dialog_scheduler.h | 4 ++-- services/abilitymgr/src/ability_manager_service.cpp | 4 ++-- .../abilitymgr/src/app_no_response_disposer.cpp | 4 ++-- services/dialog_ui/dialog_anr/js/BUILD.gn | 5 +++-- 8 files changed, 22 insertions(+), 19 deletions(-) diff --git a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp index 54b1640e08..114553e59c 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp @@ -563,6 +563,7 @@ int AmsMgrProxy::GetApplicationInfoByProcessID(const int pid, AppExecFwk::Applic MessageParcel reply; MessageOption option(MessageOption::TF_SYNC); if (!WriteInterfaceToken(data)) { + HILOG_ERROR("token write error."); return ERR_FLATTEN_OBJECT; } sptr remote = Remote(); @@ -574,20 +575,22 @@ int AmsMgrProxy::GetApplicationInfoByProcessID(const int pid, AppExecFwk::Applic int32_t ret = remote->SendRequest( static_cast(IAmsMgr::Message::GET_APPLICATION_INFO_BY_PROCESS_ID), data, reply, option); if (ret != NO_ERROR) { - return ERR_NULL_OBJECT; + HILOG_ERROR("send request fail."); + return ret; } - if (!reply.ReadBool()) { + auto result = reply.ReadInt32(); + if (result != NO_ERROR) { HILOG_ERROR("reply result false"); - return ERR_NULL_OBJECT; + return result; } std::unique_ptr info(reply.ReadParcelable()); if (!info) { HILOG_ERROR("readParcelableInfo failed"); - return ERR_NULL_OBJECT; + return ERR_NAME_NOT_FOUND; } application = *info; HILOG_DEBUG("get parcelable info success"); - return 0; + return NO_ERROR; } } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp index 7bbdc88ae2..9590eb1e89 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp @@ -296,12 +296,12 @@ int32_t AmsMgrStub::HandleGetApplicationInfoByProcessID(MessageParcel &data, Mes HITRACE_METER(HITRACE_TAG_APP); int32_t pid = data.ReadInt32(); AppExecFwk::ApplicationInfo application; - bool result = GetApplicationInfoByProcessID(pid, application); - if (!reply.WriteBool(result)) { + int32_t result = GetApplicationInfoByProcessID(pid, application); + if (!reply.WriteInt32(result)) { HILOG_ERROR("write result error."); return ERR_INVALID_VALUE; } - if (result && !reply.WriteParcelable(&application)) { + if (!reply.WriteParcelable(&application)) { HILOG_ERROR("write application info failed"); return ERR_INVALID_VALUE; } diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index e2e0f17516..b9dfbfea05 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -27,8 +27,8 @@ #include "ability_connect_manager.h" #include "ability_event_handler.h" #include "ability_manager_stub.h" -#include "app_scheduler.h" #include "app_no_response_disposer.h" +#include "app_scheduler.h" #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE #include "background_task_observer.h" #endif diff --git a/services/abilitymgr/include/app_no_response_disposer.h b/services/abilitymgr/include/app_no_response_disposer.h index b0eca0fe6a..70ca9255d6 100644 --- a/services/abilitymgr/include/app_no_response_disposer.h +++ b/services/abilitymgr/include/app_no_response_disposer.h @@ -30,8 +30,7 @@ class AppNoResponseDisposer : public std::enable_shared_from_this; using SetMissionClosure = std::function> &tokens)>; - using ShowDialogClosure = std::function; + using ShowDialogClosure = std::function; explicit AppNoResponseDisposer(const int timeout); virtual ~AppNoResponseDisposer() = default; diff --git a/services/abilitymgr/include/system_dialog_scheduler.h b/services/abilitymgr/include/system_dialog_scheduler.h index ac93749a9f..efd8c6f0b9 100644 --- a/services/abilitymgr/include/system_dialog_scheduler.h +++ b/services/abilitymgr/include/system_dialog_scheduler.h @@ -21,12 +21,12 @@ namespace OHOS { namespace AAFwk { -enum DialogType { +enum class DialogType { DIALOG_ANR = 0, DIALOG_TIPS, DIALOG_SELECTOR, }; -enum DialogAlign { +enum class DialogAlign { TOP = 0, CENTER, BOTTOM, diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 3c27a7462d..2a37a49fb9 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -4088,8 +4088,8 @@ int AbilityManagerService::SendANRProcessID(int pid) } }; #ifdef SUPPORT_GRAPHICS - auto showDialogTask = [sysDialog = sysDialogScheduler_, pid, userId = GetUserId()](int timeout, - int32_t labelId, const std::string &bundle, const Closure &callBack) { + auto showDialogTask = [sysDialog = sysDialogScheduler_, pid, userId = GetUserId()](int32_t labelId, + const std::string &bundle, const Closure &callBack) { std::string appName {""}; if (!sysDialog) { HILOG_ERROR("sysDialogScheduler_ is nullptr."); diff --git a/services/abilitymgr/src/app_no_response_disposer.cpp b/services/abilitymgr/src/app_no_response_disposer.cpp index 543f32cb22..738e7eb742 100644 --- a/services/abilitymgr/src/app_no_response_disposer.cpp +++ b/services/abilitymgr/src/app_no_response_disposer.cpp @@ -17,8 +17,8 @@ #include #include "ability_manager_service.h" -#include "app_scheduler.h" #include "ability_util.h" +#include "app_scheduler.h" #include "errors.h" #include "hilog_wrapper.h" @@ -53,7 +53,7 @@ int AppNoResponseDisposer::DisposeAppNoRespose(int pid, HILOG_WARN("user choose to kill no response app."); }; - showDialogTask(timeout_, appInfo.labelId, appInfo.bundleName, callback); + showDialogTask(appInfo.labelId, appInfo.bundleName, callback); HILOG_INFO("DisposeAppNoRespose success."); return ERR_OK; diff --git a/services/dialog_ui/dialog_anr/js/BUILD.gn b/services/dialog_ui/dialog_anr/js/BUILD.gn index 5d44a5347e..08ac0faa64 100644 --- a/services/dialog_ui/dialog_anr/js/BUILD.gn +++ b/services/dialog_ui/dialog_anr/js/BUILD.gn @@ -11,16 +11,17 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//foundation/ability/ability_runtime/aafwk.gni") import("//foundation/arkui/ace_engine/build/ace_gen_sa_dialog_js.gni") gen_sa_dialog_js("dialog_anr_js_files_etc") { project_path = - "//foundation/ability/ability_runtime/services/dialog_ui/dialog_anr/js" + "${services_path}/dialog_ui/dialog_anr/js" i18n_files = [ "i18n/en-US.json", "i18n/zh-CN.json", ] dialog_name = "dialog_anr_service" part_name = "ability_runtime" - subsystem_name = "aafwk" + subsystem_name = "ability" } -- Gitee From b1420477f5d159257752f06f80b6adba147eab8f Mon Sep 17 00:00:00 2001 From: xuchenghua09 Date: Wed, 15 Jun 2022 15:03:30 +0800 Subject: [PATCH 8/8] format Signed-off-by: xuchenghua09 --- services/dialog_ui/dialog_anr/js/BUILD.gn | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/dialog_ui/dialog_anr/js/BUILD.gn b/services/dialog_ui/dialog_anr/js/BUILD.gn index 08ac0faa64..b04b4b3ecc 100644 --- a/services/dialog_ui/dialog_anr/js/BUILD.gn +++ b/services/dialog_ui/dialog_anr/js/BUILD.gn @@ -15,8 +15,7 @@ import("//foundation/ability/ability_runtime/aafwk.gni") import("//foundation/arkui/ace_engine/build/ace_gen_sa_dialog_js.gni") gen_sa_dialog_js("dialog_anr_js_files_etc") { - project_path = - "${services_path}/dialog_ui/dialog_anr/js" + project_path = "${services_path}/dialog_ui/dialog_anr/js" i18n_files = [ "i18n/en-US.json", "i18n/zh-CN.json", -- Gitee