From 61095da743b9731e9d1630250ffdc02367f6df49 Mon Sep 17 00:00:00 2001 From: yangxuguang-huawei Date: Thu, 9 May 2024 15:50:59 +0800 Subject: [PATCH] feat: support hidumper ffrt Signed-off-by: yangxuguang-huawei --- frameworks/native/appkit/BUILD.gn | 1 + .../native/appkit/app/dump_ffrt_helper.cpp | 38 ++ .../native/appkit/app/dump_ipc_helper.cpp | 8 +- frameworks/native/appkit/app/main_thread.cpp | 17 +- .../include/appmgr/app_scheduler_const.h | 15 +- .../include/appmgr/app_scheduler_host.h | 1 + .../include/appmgr/app_scheduler_interface.h | 11 + .../include/appmgr/app_scheduler_proxy.h | 10 + .../src/appmgr/app_scheduler_host.cpp | 14 + .../src/appmgr/app_scheduler_proxy.cpp | 84 ++-- .../kits/native/appkit/app/dump_ffrt_helper.h | 29 +- .../kits/native/appkit/app/main_thread.h | 10 + services/appmgr/BUILD.gn | 9 +- services/appmgr/include/app_lifecycle_deal.h | 2 + services/appmgr/include/app_mgr_service.h | 9 +- .../appmgr/include/app_mgr_service_inner.h | 2 + services/appmgr/include/app_running_manager.h | 2 + services/appmgr/include/app_running_record.h | 2 + .../include/utils/app_mgr_service_const.h | 20 +- services/appmgr/src/app_lifecycle_deal.cpp | 31 +- services/appmgr/src/app_mgr_service.cpp | 141 ++++-- services/appmgr/src/app_mgr_service_inner.cpp | 48 +- services/appmgr/src/app_running_manager.cpp | 49 +- services/appmgr/src/app_running_record.cpp | 30 +- .../appmgrservicefirst_fuzzer.cpp | 2 +- .../include/mock_app_scheduler.h | 1 + .../include/mock_application.h | 1 + test/moduletest/common/ams/BUILD.gn | 1 - ...ams_ability_running_record_module_test.cpp | 5 + .../ams_app_mgr_service_module_test.cpp | 5 + test/unittest/BUILD.gn | 2 +- .../app_mgr_service_dump_ffrt_test/BUILD.gn | 67 +++ .../app_mgr_service_dump_ffrt_test.cpp | 457 ++++++++++++++++++ .../mock/include/mock_app_mgr_service_inner.h | 35 ++ .../mock/include/mock_ipc_skeleton.h | 65 +++ .../mock/src/mock_ipc_skeleton.cpp} | 38 +- .../app_mgr_service_dump_ipc_test/BUILD.gn | 2 - .../app_mgr_service_dump_ipc_test.cpp | 61 --- .../include/mock_permission_verification.h | 95 ---- .../mock/src/mock_permission_verification.cpp | 122 ----- 40 files changed, 1106 insertions(+), 436 deletions(-) create mode 100644 frameworks/native/appkit/app/dump_ffrt_helper.cpp rename test/unittest/app_mgr_service_dump_ipc_test/mock/include/mock_my_flag.h => interfaces/kits/native/appkit/app/dump_ffrt_helper.h (64%) create mode 100644 test/unittest/app_mgr_service_dump_ffrt_test/BUILD.gn create mode 100644 test/unittest/app_mgr_service_dump_ffrt_test/app_mgr_service_dump_ffrt_test.cpp create mode 100644 test/unittest/app_mgr_service_dump_ffrt_test/mock/include/mock_app_mgr_service_inner.h create mode 100644 test/unittest/app_mgr_service_dump_ffrt_test/mock/include/mock_ipc_skeleton.h rename test/unittest/{app_mgr_service_dump_ipc_test/mock/src/mock_my_flag.cpp => app_mgr_service_dump_ffrt_test/mock/src/mock_ipc_skeleton.cpp} (56%) delete mode 100644 test/unittest/app_mgr_service_dump_ipc_test/mock/include/mock_permission_verification.h delete mode 100644 test/unittest/app_mgr_service_dump_ipc_test/mock/src/mock_permission_verification.cpp diff --git a/frameworks/native/appkit/BUILD.gn b/frameworks/native/appkit/BUILD.gn index e3efe992925..f20f4daceec 100644 --- a/frameworks/native/appkit/BUILD.gn +++ b/frameworks/native/appkit/BUILD.gn @@ -119,6 +119,7 @@ ohos_shared_library("appkit_native") { "${ability_runtime_native_path}/appkit/app/assert_fault_callback.cpp", "${ability_runtime_native_path}/appkit/app/assert_fault_task_thread.cpp", "${ability_runtime_native_path}/appkit/app/child_main_thread.cpp", + "${ability_runtime_native_path}/appkit/app/dump_ffrt_helper.cpp", "${ability_runtime_native_path}/appkit/app/dump_ipc_helper.cpp", "${ability_runtime_native_path}/appkit/app/extension_plugin_info.cpp", "${ability_runtime_native_path}/appkit/app/idle_time.cpp", diff --git a/frameworks/native/appkit/app/dump_ffrt_helper.cpp b/frameworks/native/appkit/app/dump_ffrt_helper.cpp new file mode 100644 index 00000000000..13f705d6da6 --- /dev/null +++ b/frameworks/native/appkit/app/dump_ffrt_helper.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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 "dump_ffrt_helper.h" + +#include +#include +#include "ffrt_inner.h" + +namespace OHOS { +namespace AppExecFwk { +constexpr const uint32_t MAX_BUF_SIZE = (1U << 19); +int DumpFfrtHelper::DumpFfrt(std::string& result) +{ + result.resize(MAX_BUF_SIZE); + + int printNum = ffrt_dump(static_cast(ffrt_dump_cmd_t::DUMP_INFO_ALL), &result[0], MAX_BUF_SIZE); + if (printNum > 0) { + result.resize(printNum); + return 0; + } + result.resize(0); + return -1; +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/frameworks/native/appkit/app/dump_ipc_helper.cpp b/frameworks/native/appkit/app/dump_ipc_helper.cpp index 3f2fdcc652b..040a9bd8e24 100644 --- a/frameworks/native/appkit/app/dump_ipc_helper.cpp +++ b/frameworks/native/appkit/app/dump_ipc_helper.cpp @@ -19,8 +19,8 @@ #include #include -#include "string_ex.h" #include "ipc_payload_statistics.h" +#include "string_ex.h" namespace OHOS { namespace AppExecFwk { @@ -29,7 +29,7 @@ const std::string DUMP_IPC_CMD_FAIL = "fail"; void DumpIpcHelper::DumpIpcStart(std::string& result) { - result += "StartIpcStatistics pid: " + std::to_string(getpid()) + "\t"; + result += "StartIpcStatistics pid: " + std::to_string(getprocpid()) + "\t"; if (IPCPayloadStatistics::StartStatistics()) { result += DUMP_IPC_CMD_SUCCESS; return; @@ -39,7 +39,7 @@ void DumpIpcHelper::DumpIpcStart(std::string& result) void DumpIpcHelper::DumpIpcStop(std::string& result) { - result += "StopIpcStatistics pid: " + std::to_string(getpid()) + "\t"; + result += "StopIpcStatistics pid: " + std::to_string(getprocpid()) + "\t"; if (IPCPayloadStatistics::StopStatistics()) { result += DUMP_IPC_CMD_SUCCESS; return; @@ -51,7 +51,7 @@ void DumpIpcHelper::DumpIpcStat(std::string& result) { result += "********************************GlobalStatisticsInfo********************************"; result += "\nCurrentPid:"; - result += std::to_string(getpid()); + result += std::to_string(getprocpid()); result += "\nTotalCount:"; result += std::to_string(IPCPayloadStatistics::GetTotalCount()); result += "\nTotalTimeCost:"; diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 79038833f37..c43081fb63e 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -45,6 +45,8 @@ #include "global_constant.h" #include "context_deal.h" #include "context_impl.h" +#include "dump_ffrt_helper.h" +#include "dump_ipc_helper.h" #include "exit_reason.h" #include "extension_ability_info.h" #include "extension_module_loader.h" @@ -82,7 +84,6 @@ #include "js_runtime_utils.h" #include "context/application_context.h" #include "os_account_manager_wrapper.h" -#include "dump_ipc_helper.h" #if defined(NWEB) #include @@ -2419,7 +2420,7 @@ void MainThread::ForceFullGC() void MainThread::Start() { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); - TAG_LOGI(AAFwkTag::APPKIT, "App main thread create, pid:%{public}d.", getpid()); + TAG_LOGI(AAFwkTag::APPKIT, "App main thread create, pid:%{public}d.", getprocpid()); if (AAFwk::AppUtils::GetInstance().IsMultiProcessModel()) { ChildProcessInfo info; @@ -3177,23 +3178,29 @@ void MainThread::HandleCancelAssertFaultTask() int32_t MainThread::ScheduleDumpIpcStart(std::string& result) { - TAG_LOGD(AAFwkTag::APPKIT, "MainThread::ScheduleDumpIpcStart::pid:%{public}d", getpid()); + TAG_LOGD(AAFwkTag::APPKIT, "MainThread::ScheduleDumpIpcStart::pid:%{public}d", getprocpid()); DumpIpcHelper::DumpIpcStart(result); return ERR_OK; } int32_t MainThread::ScheduleDumpIpcStop(std::string& result) { - TAG_LOGD(AAFwkTag::APPKIT, "MainThread::ScheduleDumpIpcStop::pid:%{public}d", getpid()); + TAG_LOGD(AAFwkTag::APPKIT, "MainThread::ScheduleDumpIpcStop::pid:%{public}d", getprocpid()); DumpIpcHelper::DumpIpcStop(result); return ERR_OK; } int32_t MainThread::ScheduleDumpIpcStat(std::string& result) { - TAG_LOGD(AAFwkTag::APPKIT, "MainThread::ScheduleDumpIpcStat::pid:%{public}d", getpid()); + TAG_LOGD(AAFwkTag::APPKIT, "MainThread::ScheduleDumpIpcStat::pid:%{public}d", getprocpid()); DumpIpcHelper::DumpIpcStat(result); return ERR_OK; } + +int32_t MainThread::ScheduleDumpFfrt(std::string& result) +{ + TAG_LOGD(AAFwkTag::APPKIT, "MainThread::ScheduleDumpFfrt::pid:%{public}d", getprocpid()); + return DumpFfrtHelper::DumpFfrt(result); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_const.h b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_const.h index 3a12f94a9b4..ed5edc95dd9 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_const.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_const.h @@ -16,15 +16,18 @@ #ifndef OHOS_ABILITY_RUNTIME_APP_SCHEDULER_CONST_H #define OHOS_ABILITY_RUNTIME_APP_SCHEDULER_CONST_H -#include +#include +#include namespace OHOS { namespace AppExecFwk { -const std::string MSG_DUMP_IPC_START_STAT = "StartIpcStatistics\t"; -const std::string MSG_DUMP_IPC_STOP_STAT = "StopIpcStatistics\t"; -const std::string MSG_DUMP_IPC_STAT = "IpcStatistics\t"; -const std::string MSG_DUMP_IPC_FAIL = "fail\n"; -const std::string MSG_DUMP_IPC_FAIL_REASON_INTERNAL = "internal error.\n"; +constexpr const size_t MAX_CAPACITY = (1U << 20); + +constexpr const char* MSG_DUMP_IPC_START_STAT = "StartIpcStatistics\t"; +constexpr const char* MSG_DUMP_IPC_STOP_STAT = "StopIpcStatistics\t"; +constexpr const char* MSG_DUMP_IPC_STAT = "IpcStatistics\t"; +constexpr const char* MSG_DUMP_FAIL = "fail\n"; +constexpr const char* MSG_DUMP_FAIL_REASON_INTERNAL = "internal error.\n"; enum DumpErrorCode { // success diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_host.h b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_host.h index eb513363cb9..d0722996dc3 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_host.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_host.h @@ -63,6 +63,7 @@ private: int32_t HandleScheduleDumpIpcStart(MessageParcel &data, MessageParcel &reply); int32_t HandleScheduleDumpIpcStop(MessageParcel &data, MessageParcel &reply); int32_t HandleScheduleDumpIpcStat(MessageParcel &data, MessageParcel &reply); + int32_t HandleScheduleDumpFfrt(MessageParcel &data, MessageParcel &reply); using AppSchedulerFunc = int32_t (AppSchedulerHost::*)(MessageParcel &data, MessageParcel &reply); std::map memberFuncMap_; diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h index 4c80f3f1dd6..2b04eb76784 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h @@ -262,6 +262,16 @@ public: */ virtual int32_t ScheduleDumpIpcStat(std::string& result) = 0; + /** + * ScheduleDumpFfrt, call ScheduleDumpFfrt(std::string& result) through proxy project, + * Start querying the application's ffrt usage. + * + * @param result, ffrt dump result output. + * + * @return Returns 0 on success, error code on failure. + */ + virtual int32_t ScheduleDumpFfrt(std::string& result) = 0; + enum class Message { SCHEDULE_FOREGROUND_APPLICATION_TRANSACTION = 0, SCHEDULE_BACKGROUND_APPLICATION_TRANSACTION, @@ -291,6 +301,7 @@ public: SCHEDULE_DUMP_IPC_START, SCHEDULE_DUMP_IPC_STOP, SCHEDULE_DUMP_IPC_STAT, + SCHEDULE_DUMP_FFRT, }; }; } // namespace AppExecFwk diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h index 56c3ffd6ceb..72197fc710b 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h @@ -222,6 +222,16 @@ public: */ virtual int32_t ScheduleDumpIpcStat(std::string& result) override; + /** + * ScheduleDumpFfrt, call ScheduleDumpFfrt(std::string& result) through proxy project, + * Start querying the application's ffrt usage. + * + * @param result, ffrt dump result output. + * + * @return Returns 0 on success, error code on failure. + */ + virtual int32_t ScheduleDumpFfrt(std::string& result) override; + private: bool WriteInterfaceToken(MessageParcel &data); void ScheduleMemoryCommon(const int32_t level, const uint32_t operation); diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_host.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_host.cpp index 6672d3cf82a..84aa6e86f6f 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_host.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_host.cpp @@ -86,6 +86,8 @@ void AppSchedulerHost::InitMemberFuncMap() &AppSchedulerHost::HandleScheduleDumpIpcStop; memberFuncMap_[static_cast(IAppScheduler::Message::SCHEDULE_DUMP_IPC_STAT)] = &AppSchedulerHost::HandleScheduleDumpIpcStat; + memberFuncMap_[static_cast(IAppScheduler::Message::SCHEDULE_DUMP_FFRT)] = + &AppSchedulerHost::HandleScheduleDumpFfrt; } AppSchedulerHost::~AppSchedulerHost() @@ -433,5 +435,17 @@ int32_t AppSchedulerHost::HandleScheduleDumpIpcStat(MessageParcel &data, Message } return NO_ERROR; } + +int32_t AppSchedulerHost::HandleScheduleDumpFfrt(MessageParcel &data, MessageParcel &reply) +{ + HITRACE_METER(HITRACE_TAG_APP); + std::string result; + ScheduleDumpFfrt(result); + if (!reply.WriteString(result)) { + TAG_LOGE(AAFwkTag::APPMGR, "Fail to write string of ScheduleDumpFfrt result"); + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp index c86db0c84e5..6172932d562 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp @@ -615,24 +615,24 @@ int32_t AppSchedulerProxy::ScheduleDumpIpcStart(std::string& result) MessageParcel reply; MessageOption option(MessageOption::TF_SYNC); if (!WriteInterfaceToken(data)) { - result.append(MSG_DUMP_IPC_START_STAT) - .append(MSG_DUMP_IPC_FAIL) - .append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_IPC_START_STAT, strlen(MSG_DUMP_IPC_START_STAT)) + .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "AppSchedulerProxy !WriteInterfaceToken."); return DumpErrorCode::ERR_INTERNAL_ERROR; } int32_t ret = SendTransactCmd(operation, data, reply, option); if (ret != NO_ERROR) { - result.append(MSG_DUMP_IPC_START_STAT) - .append(MSG_DUMP_IPC_FAIL) - .append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_IPC_START_STAT, strlen(MSG_DUMP_IPC_START_STAT)) + .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); return DumpErrorCode::ERR_INTERNAL_ERROR; } if (!reply.ReadString(result)) { - result.append(MSG_DUMP_IPC_START_STAT) - .append(MSG_DUMP_IPC_FAIL) - .append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_IPC_START_STAT, strlen(MSG_DUMP_IPC_START_STAT)) + .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "Fail to read string of ScheduleDumpIpcStart result"); return DumpErrorCode::ERR_INTERNAL_ERROR; } @@ -647,24 +647,24 @@ int32_t AppSchedulerProxy::ScheduleDumpIpcStop(std::string& result) MessageParcel reply; MessageOption option(MessageOption::TF_SYNC); if (!WriteInterfaceToken(data)) { - result.append(MSG_DUMP_IPC_STOP_STAT) - .append(MSG_DUMP_IPC_FAIL) - .append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_IPC_STOP_STAT, strlen(MSG_DUMP_IPC_STOP_STAT)) + .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "AppSchedulerProxy !WriteInterfaceToken."); return DumpErrorCode::ERR_INTERNAL_ERROR; } int32_t ret = SendTransactCmd(operation, data, reply, option); if (ret != NO_ERROR) { - result.append(MSG_DUMP_IPC_STOP_STAT) - .append(MSG_DUMP_IPC_FAIL) - .append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_IPC_STOP_STAT, strlen(MSG_DUMP_IPC_STOP_STAT)) + .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); return DumpErrorCode::ERR_INTERNAL_ERROR; } if (!reply.ReadString(result)) { - result.append(MSG_DUMP_IPC_STOP_STAT) - .append(MSG_DUMP_IPC_FAIL) - .append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_IPC_STOP_STAT, strlen(MSG_DUMP_IPC_STOP_STAT)) + .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "Fail to read string of ScheduleDumpIpcStop result"); return DumpErrorCode::ERR_INTERNAL_ERROR; } @@ -679,30 +679,60 @@ int32_t AppSchedulerProxy::ScheduleDumpIpcStat(std::string& result) MessageParcel reply; MessageOption option(MessageOption::TF_SYNC); if (!WriteInterfaceToken(data)) { - result.append(MSG_DUMP_IPC_STAT) - .append(MSG_DUMP_IPC_FAIL) - .append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_IPC_STAT, strlen(MSG_DUMP_IPC_STAT)) + .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "AppSchedulerProxy !WriteInterfaceToken."); return DumpErrorCode::ERR_INTERNAL_ERROR; } int32_t ret = SendTransactCmd(operation, data, reply, option); if (ret != NO_ERROR) { - result.append(MSG_DUMP_IPC_STAT) - .append(MSG_DUMP_IPC_FAIL) - .append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_IPC_STAT, strlen(MSG_DUMP_IPC_STAT)) + .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); return DumpErrorCode::ERR_INTERNAL_ERROR; } if (!reply.ReadString(result)) { - result.append(MSG_DUMP_IPC_STAT) - .append(MSG_DUMP_IPC_FAIL) - .append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_IPC_STAT, strlen(MSG_DUMP_IPC_STAT)) + .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "Fail to read string of ScheduleDumpIpcStat result"); return DumpErrorCode::ERR_INTERNAL_ERROR; } return DumpErrorCode::ERR_OK; } +int32_t AppSchedulerProxy::ScheduleDumpFfrt(std::string& result) +{ + TAG_LOGD(AAFwkTag::APPMGR, "AppSchedulerProxy::ScheduleDumpFfrt start"); + uint32_t operation = static_cast(IAppScheduler::Message::SCHEDULE_DUMP_FFRT); + MessageParcel data; + MessageParcel reply; + reply.SetMaxCapacity(MAX_CAPACITY); + MessageOption option(MessageOption::TF_SYNC); + if (!WriteInterfaceToken(data)) { + result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); + TAG_LOGE(AAFwkTag::APPMGR, "AppSchedulerProxy !WriteInterfaceToken."); + return DumpErrorCode::ERR_INTERNAL_ERROR; + } + int32_t ret = SendTransactCmd(operation, data, reply, option); + if (ret != NO_ERROR) { + result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); + TAG_LOGE(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); + return DumpErrorCode::ERR_INTERNAL_ERROR; + } + if (!reply.ReadString(result)) { + result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); + TAG_LOGE(AAFwkTag::APPMGR, "Fail to read string of ScheduleDumpFfrt result"); + return DumpErrorCode::ERR_INTERNAL_ERROR; + } + return DumpErrorCode::ERR_OK; +} + int32_t AppSchedulerProxy::SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { diff --git a/test/unittest/app_mgr_service_dump_ipc_test/mock/include/mock_my_flag.h b/interfaces/kits/native/appkit/app/dump_ffrt_helper.h similarity index 64% rename from test/unittest/app_mgr_service_dump_ipc_test/mock/include/mock_my_flag.h rename to interfaces/kits/native/appkit/app/dump_ffrt_helper.h index 50accf24aaa..96f20cbcf94 100644 --- a/test/unittest/app_mgr_service_dump_ipc_test/mock/include/mock_my_flag.h +++ b/interfaces/kits/native/appkit/app/dump_ffrt_helper.h @@ -13,20 +13,21 @@ * limitations under the License. */ -#ifndef MOCK_MY_FLAG_H -#define MOCK_MY_FLAG_H +#ifndef OHOS_ABILITY_RUNTIME_DUMP_FFRT_HELPER_H +#define OHOS_ABILITY_RUNTIME_DUMP_FFRT_HELPER_H + +#include + namespace OHOS { -namespace AAFwk { -class MyFlag { +namespace AppExecFwk { + +class DumpFfrtHelper { public: - enum FLAG { - IS_INVALID_CALL = 0, - IS_SA_CALL, - IS_SHELL_CALL, - IS_SA_AND_SHELL_CALL, - }; - static int flag_; + DumpFfrtHelper(); + ~DumpFfrtHelper(); + + static int DumpFfrt(std::string& result); }; -} // namespace AAFwk -} // namespace OHOS -#endif // MOCK_MY_FLAG_H +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_DUMP_FFRT_HELPER_H diff --git a/interfaces/kits/native/appkit/app/main_thread.h b/interfaces/kits/native/appkit/app/main_thread.h index 1a7b93a33e6..751c0044cf7 100644 --- a/interfaces/kits/native/appkit/app/main_thread.h +++ b/interfaces/kits/native/appkit/app/main_thread.h @@ -329,6 +329,16 @@ public: */ int32_t ScheduleDumpIpcStat(std::string& result) override; + /** + * ScheduleDumpFfrt, call ScheduleDumpFfrt(std::string& result) through proxy project, + * Start querying the application's ffrt usage. + * + * @param result, ffrt dump result output. + * + * @return Returns 0 on success, error code on failure. + */ + int32_t ScheduleDumpFfrt(std::string& result) override; + private: /** * diff --git a/services/appmgr/BUILD.gn b/services/appmgr/BUILD.gn index e6fcebeadb6..13bf86aa6fb 100644 --- a/services/appmgr/BUILD.gn +++ b/services/appmgr/BUILD.gn @@ -28,10 +28,6 @@ config("appmgr_config") { ] } -config("appmgr_exception_config") { - cflags_cc = [ "-fexceptions" ] -} - group("appms_target") { deps = [ ":libappms" ] } @@ -83,10 +79,7 @@ ohos_shared_library("libappms") { defines += [ "ABILITY_FAULT_AND_EXIT_TEST" ] } - configs = [ - ":appmgr_config", - ":appmgr_exception_config", - ] + configs = [ ":appmgr_config" ] cflags = [] if (target_cpu == "arm") { cflags += [ "-DBINDER_IPC_32BIT" ] diff --git a/services/appmgr/include/app_lifecycle_deal.h b/services/appmgr/include/app_lifecycle_deal.h index 441ca00ec22..7dac5b7c649 100644 --- a/services/appmgr/include/app_lifecycle_deal.h +++ b/services/appmgr/include/app_lifecycle_deal.h @@ -223,6 +223,8 @@ public: int DumpIpcStat(std::string& result); + int DumpFfrt(std::string& result); + private: mutable std::mutex schedulerMutex_; sptr appThread_ = nullptr; diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index ce653ae473f..8d16a88ba90 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -577,7 +577,7 @@ private: virtual int32_t GetForegroundApplications(std::vector &list) override; int Dump(const std::vector& args, std::string& result); - void ShowHelp(std::string& result) const; + int ShowHelp(const std::vector& args, std::string& result); int DumpIpc(const std::vector& args, std::string& result); int DumpIpcAllStart(std::string& result); int DumpIpcAllStop(std::string& result); @@ -586,6 +586,8 @@ private: int DumpIpcStop(const int32_t pid, std::string& result); int DumpIpcStat(const int32_t pid, std::string& result); + int DumpFfrt(const std::vector& args, std::string& result); + bool JudgeAppSelfCalled(int32_t recordId); /** @@ -633,6 +635,8 @@ private: int DumpIpcWithPidInner(const AppMgrService::DumpIpcKey key, const std::string& optionPid, std::string& result); + int DumpFfrtInner(const std::string& pidsRaw, std::string& result); + private: std::shared_ptr appMgrServiceInner_; AppMgrServiceState appMgrServiceState_; @@ -641,6 +645,9 @@ private: sptr systemAbilityMgr_; sptr amsMgrScheduler_; + using DumpFuncType = int (AppMgrService::*)(const std::vector& args, std::string& result); + const static std::map dumpFuncMap_; + const static std::map dumpIpcMap; using DumpIpcAllFuncType = int (AppMgrService::*)(std::string& result); diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index d58b5f5de49..d1a1400e946 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -1050,6 +1050,8 @@ public: virtual int DumpIpcStat(const int32_t pid, std::string& result); + virtual int DumpFfrt(const std::vector& pids, std::string& result); + int32_t SetSupportedProcessCacheSelf(bool isSupport); void OnAppCacheStateChanged(const std::shared_ptr &appRecord); diff --git a/services/appmgr/include/app_running_manager.h b/services/appmgr/include/app_running_manager.h index 57997917ae0..07c1d6cbf89 100644 --- a/services/appmgr/include/app_running_manager.h +++ b/services/appmgr/include/app_running_manager.h @@ -296,6 +296,8 @@ public: int DumpIpcStat(const int32_t pid, std::string& result); + int DumpFfrt(const std::vector& pids, std::string& result); + private: std::shared_ptr GetAbilityRunningRecord(const int64_t eventId); void AssignRunningProcessInfoByAppRecord( diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index d00ef5fd91f..c808d4a79f5 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -761,6 +761,8 @@ public: int DumpIpcStop(std::string& result); int DumpIpcStat(std::string& result); + int DumpFfrt(std::string &result); + void SetExitReason(int32_t reason); int32_t GetExitReason() const; diff --git a/services/appmgr/include/utils/app_mgr_service_const.h b/services/appmgr/include/utils/app_mgr_service_const.h index f67b588c5e6..311780d2c54 100644 --- a/services/appmgr/include/utils/app_mgr_service_const.h +++ b/services/appmgr/include/utils/app_mgr_service_const.h @@ -16,19 +16,19 @@ #ifndef OHOS_ABILITY_RUNTIME_APP_MGR_SERVICE_CONST_H #define OHOS_ABILITY_RUNTIME_APP_MGR_SERVICE_CONST_H -#include +#include namespace OHOS { namespace AppExecFwk { -const std::string MSG_DUMP_IPC_START_STAT = "StartIpcStatistics\t"; -const std::string MSG_DUMP_IPC_STOP_STAT = "StopIpcStatistics\t"; -const std::string MSG_DUMP_IPC_STAT = "IpcStatistics\t"; -const std::string MSG_DUMP_IPC_FAIL = "fail\n"; -const std::string MSG_DUMP_IPC_FAIL_REASON_INTERNAL = "internal error.\n"; -const std::string MSG_DUMP_IPC_FAIL_REASON_INVALILD_CMD = "invalid cmd.\n"; -const std::string MSG_DUMP_IPC_FAIL_REASON_INVALILD_PID = "invalid pid.\n"; -const std::string MSG_DUMP_IPC_FAIL_REASON_INVALILD_NUM_ARGS = "invalid number of arguments.\n"; -const std::string MSG_DUMP_IPC_FAIL_REASON_PERMISSION_DENY = "permission deny.\n"; +constexpr const char* MSG_DUMP_IPC_START_STAT = "StartIpcStatistics\t"; +constexpr const char* MSG_DUMP_IPC_STOP_STAT = "StopIpcStatistics\t"; +constexpr const char* MSG_DUMP_IPC_STAT = "IpcStatistics\t"; +constexpr const char* MSG_DUMP_FAIL = "fail\n"; +constexpr const char* MSG_DUMP_FAIL_REASON_INTERNAL = "internal error.\n"; +constexpr const char* MSG_DUMP_FAIL_REASON_INVALILD_CMD = "invalid cmd.\n"; +constexpr const char* MSG_DUMP_FAIL_REASON_INVALILD_PID = "invalid pid.\n"; +constexpr const char* MSG_DUMP_FAIL_REASON_INVALILD_NUM_ARGS = "invalid number of arguments.\n"; +constexpr const char* MSG_DUMP_FAIL_REASON_PERMISSION_DENY = "permission deny.\n"; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/app_lifecycle_deal.cpp b/services/appmgr/src/app_lifecycle_deal.cpp index a553af006a0..7387db0b90e 100644 --- a/services/appmgr/src/app_lifecycle_deal.cpp +++ b/services/appmgr/src/app_lifecycle_deal.cpp @@ -334,9 +334,9 @@ int AppLifeCycleDeal::DumpIpcStart(std::string& result) TAG_LOGD(AAFwkTag::APPMGR, "Called."); auto appThread = GetApplicationClient(); if (appThread == nullptr) { - result.append(MSG_DUMP_IPC_START_STAT) - .append(MSG_DUMP_IPC_FAIL) - .append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_IPC_START_STAT, strlen(MSG_DUMP_IPC_START_STAT)) + .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "appThread is nullptr."); return DumpErrorCode::ERR_INTERNAL_ERROR; } @@ -348,9 +348,9 @@ int AppLifeCycleDeal::DumpIpcStop(std::string& result) TAG_LOGD(AAFwkTag::APPMGR, "Called."); auto appThread = GetApplicationClient(); if (appThread == nullptr) { - result.append(MSG_DUMP_IPC_STOP_STAT) - .append(MSG_DUMP_IPC_FAIL) - .append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_IPC_STOP_STAT, strlen(MSG_DUMP_IPC_STOP_STAT)) + .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "appThread is nullptr."); return DumpErrorCode::ERR_INTERNAL_ERROR; } @@ -362,13 +362,26 @@ int AppLifeCycleDeal::DumpIpcStat(std::string& result) TAG_LOGD(AAFwkTag::APPMGR, "Called."); auto appThread = GetApplicationClient(); if (appThread == nullptr) { - result.append(MSG_DUMP_IPC_STAT) - .append(MSG_DUMP_IPC_FAIL) - .append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_IPC_STAT, strlen(MSG_DUMP_IPC_STAT)) + .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "appThread is nullptr."); return DumpErrorCode::ERR_INTERNAL_ERROR; } return appThread->ScheduleDumpIpcStat(result); } + +int AppLifeCycleDeal::DumpFfrt(std::string& result) +{ + TAG_LOGD(AAFwkTag::APPMGR, "Called."); + auto appThread = GetApplicationClient(); + if (appThread == nullptr) { + result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); + TAG_LOGE(AAFwkTag::APPMGR, "appThread is nullptr."); + return DumpErrorCode::ERR_INTERNAL_ERROR; + } + return appThread->ScheduleDumpFfrt(result); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index a7fecdd30ae..03ed44a33f4 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -16,6 +16,7 @@ #include "app_mgr_service.h" #include +#include #include #include #include @@ -41,10 +42,15 @@ namespace OHOS { namespace AppExecFwk { const std::string OPTION_KEY_HELP = "-h"; const std::string OPTION_KEY_DUMP_IPC = "--ipc"; +const std::string OPTION_KEY_DUMP_FFRT = "--ffrt"; const int32_t HIDUMPER_SERVICE_UID = 1212; constexpr const int INDEX_PID = 1; constexpr const int INDEX_CMD = 2; constexpr const size_t VALID_DUMP_IPC_ARG_SIZE = 3; +constexpr const size_t VALID_DUMP_FFRT_ARG_SIZE = 2; +constexpr const int MAX_DUMP_FFRT_PID_NUMBER = 3; +constexpr const int BASE_TEN = 10; +constexpr const char SIGN_TERMINAL = '\0'; namespace { using namespace std::chrono_literals; #ifdef ABILITY_COMMAND_FOR_TEST @@ -71,6 +77,12 @@ constexpr int32_t USER_UID = 2000; REGISTER_SYSTEM_ABILITY_BY_ID(AppMgrService, APP_MGR_SERVICE_ID, true); +const std::map AppMgrService::dumpFuncMap_ = { + std::map::value_type(OPTION_KEY_HELP, &AppMgrService::ShowHelp), + std::map::value_type(OPTION_KEY_DUMP_IPC, &AppMgrService::DumpIpc), + std::map::value_type(OPTION_KEY_DUMP_FFRT, &AppMgrService::DumpFfrt), +}; + const std::map AppMgrService::dumpIpcMap = { std::map::value_type("--start-stat", KEY_DUMP_IPC_START), std::map::value_type("--stop-stat", KEY_DUMP_IPC_STOP), @@ -616,42 +628,50 @@ int AppMgrService::Dump(const std::vector& args, std::string& re TAG_LOGD(AAFwkTag::APPMGR, "Called."); auto size = args.size(); if (size == 0) { - ShowHelp(result); - return DumpErrorCode::ERR_OK; + return ShowHelp(args, result); } std::string optionKey = Str16ToStr8(args[0]); - if (optionKey == OPTION_KEY_HELP) { - ShowHelp(result); - return DumpErrorCode::ERR_OK; - } - if (optionKey == OPTION_KEY_DUMP_IPC) { - return DumpIpc(args, result); + auto itDumpFunc = dumpFuncMap_.find(optionKey); + if (itDumpFunc == dumpFuncMap_.end()) { + TAG_LOGE(AAFwkTag::APPMGR, "option key %{public}s does not exist", optionKey.c_str()); + result.append("error: unkown option.\n"); + return DumpErrorCode::ERR_UNKNOWN_OPTION_ERROR; } - result.append("error: unkown option.\n"); - return DumpErrorCode::ERR_UNKNOWN_OPTION_ERROR; + auto dumpFunc = itDumpFunc->second; + if (dumpFunc == nullptr) { + result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); + TAG_LOGE(AAFwkTag::APPMGR, "dump ffrt function does not exist"); + return DumpErrorCode::ERR_INTERNAL_ERROR; + } + return (this->*dumpFunc)(args, result); } -void AppMgrService::ShowHelp(std::string& result) const +int AppMgrService::ShowHelp(const std::vector& args, std::string& result) { result.append("Usage:\n") .append("-h ") .append("help text for the tool\n"); + + return ERR_OK; } int AppMgrService::DumpIpcAllInner(const AppMgrService::DumpIpcKey key, std::string& result) { - TAG_LOGD(AAFwkTag::APPMGR, "Called."); + TAG_LOGI(AAFwkTag::APPMGR, "Called."); auto itFunc = dumpIpcAllFuncMap_.find(key); if (itFunc == dumpIpcAllFuncMap_.end()) { - result.append(MSG_DUMP_IPC_FAIL).append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "option key %{public}d does not exist", key); return DumpErrorCode::ERR_INTERNAL_ERROR; } auto dumpFunc = itFunc->second; if (dumpFunc == nullptr) { - result.append(MSG_DUMP_IPC_FAIL).append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "dump ipc all function does not exist"); return DumpErrorCode::ERR_INTERNAL_ERROR; } @@ -661,47 +681,88 @@ int AppMgrService::DumpIpcAllInner(const AppMgrService::DumpIpcKey key, std::str int AppMgrService::DumpIpcWithPidInner(const AppMgrService::DumpIpcKey key, const std::string& optionPid, std::string& result) { - TAG_LOGD(AAFwkTag::APPMGR, "Called."); + TAG_LOGI(AAFwkTag::APPMGR, "Called."); int32_t pid = -1; - try { - pid = static_cast(std::stoi(optionPid)); - } catch (...) { - result.append(MSG_DUMP_IPC_FAIL).append(MSG_DUMP_IPC_FAIL_REASON_INVALILD_PID); - TAG_LOGE(AAFwkTag::APPMGR, "stoi(%{public}s) failed", optionPid.c_str()); + char* end = nullptr; + pid = static_cast(std::strtol(optionPid.c_str(), &end, BASE_TEN)); + if (end && *end != SIGN_TERMINAL) { + result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INVALILD_PID, strlen(MSG_DUMP_FAIL_REASON_INVALILD_PID)); + TAG_LOGE(AAFwkTag::APPMGR, "invalid pid: %{public}s", optionPid.c_str()); return DumpErrorCode::ERR_INVALID_PID_ERROR; } if (pid < 0) { - result.append(MSG_DUMP_IPC_FAIL).append(MSG_DUMP_IPC_FAIL_REASON_INVALILD_PID); + result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INVALILD_PID, strlen(MSG_DUMP_FAIL_REASON_INVALILD_PID)); TAG_LOGE(AAFwkTag::APPMGR, "invalid pid: %{public}s", optionPid.c_str()); return DumpErrorCode::ERR_INVALID_PID_ERROR; } auto itFunc = dumpIpcFuncMap_.find(key); if (itFunc == dumpIpcFuncMap_.end()) { - result.append(MSG_DUMP_IPC_FAIL).append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "option key %{public}d does not exist", key); return DumpErrorCode::ERR_INTERNAL_ERROR; } auto dumpFunc = itFunc->second; if (dumpFunc == nullptr) { - result.append(MSG_DUMP_IPC_FAIL).append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "dump ipc function does not exist"); return DumpErrorCode::ERR_INTERNAL_ERROR; } return (this->*dumpFunc)(pid, result); } +int AppMgrService::DumpFfrtInner(const std::string& pidsRaw, std::string& result) +{ + TAG_LOGI(AAFwkTag::APPMGR, "Called"); + std::vector pidsStr; + SplitStr(pidsRaw, ",", pidsStr); + if (pidsStr.empty()) { + TAG_LOGE(AAFwkTag::APPMGR, "no valid pids are found"); + return DumpErrorCode::ERR_INVALID_PID_ERROR; + } + if (pidsStr.size() > MAX_DUMP_FFRT_PID_NUMBER) { + pidsStr.resize(MAX_DUMP_FFRT_PID_NUMBER); + } + std::vector pids; + for (const auto& pidStr : pidsStr) { + int pid = -1; + char* end = nullptr; + pid = static_cast(std::strtol(pidStr.c_str(), &end, BASE_TEN)); + if (end && *end != SIGN_TERMINAL) { + TAG_LOGE(AAFwkTag::APPMGR, "invalid pid:%{public}s", pidStr.c_str()); + continue; + } + if (pid < 0) { + TAG_LOGE(AAFwkTag::APPMGR, "invalid pid: %{public}s", pidStr.c_str()); + continue; + } + TAG_LOGD(AAFwkTag::APPMGR, "valid pid:%{public}d", pid); + pids.push_back(pid); + } + TAG_LOGD(AAFwkTag::APPMGR, "number of valid pids:%{public}d", static_cast(pids.size())); + if (pids.empty()) { + TAG_LOGE(AAFwkTag::APPMGR, "no valid pids are found"); + return DumpErrorCode::ERR_INVALID_PID_ERROR; + } + return appMgrServiceInner_->DumpFfrt(pids, result); +} + int AppMgrService::DumpIpc(const std::vector& args, std::string& result) { TAG_LOGD(AAFwkTag::APPMGR, "Called. AppMgrService::DumpIpc start"); if (args.size() != VALID_DUMP_IPC_ARG_SIZE) { - result.append(MSG_DUMP_IPC_FAIL).append(MSG_DUMP_IPC_FAIL_REASON_INVALILD_NUM_ARGS); + result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INVALILD_NUM_ARGS, strlen(MSG_DUMP_FAIL_REASON_INVALILD_NUM_ARGS)); TAG_LOGE(AAFwkTag::APPMGR, "invalid number of arguments"); return DumpErrorCode::ERR_INVALID_NUM_ARGS_ERROR; } - auto isShellCall = AAFwk::PermissionVerification::GetInstance()->IsShellCall(); auto isHidumperServiceCall = (IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID); - if (!isShellCall && !isHidumperServiceCall) { - result.append(MSG_DUMP_IPC_FAIL).append(MSG_DUMP_IPC_FAIL_REASON_PERMISSION_DENY); + if (!isHidumperServiceCall) { + result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_PERMISSION_DENY, strlen(MSG_DUMP_FAIL_REASON_PERMISSION_DENY)); TAG_LOGE(AAFwkTag::APPMGR, "Permission deny."); return DumpErrorCode::ERR_PERMISSION_DENY_ERROR; } @@ -713,7 +774,8 @@ int AppMgrService::DumpIpc(const std::vector& args, std::string& auto itDumpKey = dumpIpcMap.find(optionCmd); if (itDumpKey == dumpIpcMap.end()) { - result.append(MSG_DUMP_IPC_FAIL).append(MSG_DUMP_IPC_FAIL_REASON_INVALILD_CMD); + result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INVALILD_CMD, strlen(MSG_DUMP_FAIL_REASON_INVALILD_CMD)); TAG_LOGE(AAFwkTag::APPMGR, "option command %{public}s does not exist", optionCmd.c_str()); return DumpErrorCode::ERR_INVALID_CMD_ERROR; } @@ -725,6 +787,29 @@ int AppMgrService::DumpIpc(const std::vector& args, std::string& return DumpIpcWithPidInner(key, optionPid, result); } +int AppMgrService::DumpFfrt(const std::vector& args, std::string& result) +{ + TAG_LOGD(AAFwkTag::APPMGR, "Called. AppMgrService::DumpFfrt start"); + if (args.size() != VALID_DUMP_FFRT_ARG_SIZE) { + result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INVALILD_NUM_ARGS, strlen(MSG_DUMP_FAIL_REASON_INVALILD_NUM_ARGS)); + TAG_LOGE(AAFwkTag::APPMGR, "invalid number of arguments"); + return DumpErrorCode::ERR_INVALID_NUM_ARGS_ERROR; + } + auto isHidumperServiceCall = (IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID); + if (!isHidumperServiceCall) { + result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_PERMISSION_DENY, strlen(MSG_DUMP_FAIL_REASON_PERMISSION_DENY)); + TAG_LOGE(AAFwkTag::APPMGR, "Permission deny."); + return DumpErrorCode::ERR_PERMISSION_DENY_ERROR; + } + + std::string pidsRaw = Str16ToStr8(args[INDEX_PID]); + TAG_LOGD(AAFwkTag::APPMGR, "pids:%{public}s", pidsRaw.c_str()); + + return DumpFfrtInner(pidsRaw, result); +} + int AppMgrService::DumpIpcAllStart(std::string& result) { TAG_LOGD(AAFwkTag::APPMGR, "Called."); diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index ae85a281b06..af83cde9307 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -6030,9 +6030,9 @@ int AppMgrServiceInner::DumpIpcAllStart(std::string& result) { TAG_LOGD(AAFwkTag::APPMGR, "Called."); if (!appRunningManager_) { - result.append(MSG_DUMP_IPC_START_STAT) - .append(MSG_DUMP_IPC_FAIL) - .append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_IPC_START_STAT, strlen(MSG_DUMP_IPC_START_STAT)) + .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ is null"); return DumpErrorCode::ERR_INTERNAL_ERROR; } @@ -6043,9 +6043,9 @@ int AppMgrServiceInner::DumpIpcAllStop(std::string& result) { TAG_LOGD(AAFwkTag::APPMGR, "Called."); if (!appRunningManager_) { - result.append(MSG_DUMP_IPC_STOP_STAT) - .append(MSG_DUMP_IPC_FAIL) - .append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_IPC_STOP_STAT, strlen(MSG_DUMP_IPC_STOP_STAT)) + .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ is null"); return DumpErrorCode::ERR_INTERNAL_ERROR; } @@ -6056,9 +6056,9 @@ int AppMgrServiceInner::DumpIpcAllStat(std::string& result) { TAG_LOGD(AAFwkTag::APPMGR, "Called."); if (!appRunningManager_) { - result.append(MSG_DUMP_IPC_STAT) - .append(MSG_DUMP_IPC_FAIL) - .append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_IPC_STAT, strlen(MSG_DUMP_IPC_STAT)) + .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ is null"); return DumpErrorCode::ERR_INTERNAL_ERROR; } @@ -6069,9 +6069,9 @@ int AppMgrServiceInner::DumpIpcStart(const int32_t pid, std::string& result) { TAG_LOGD(AAFwkTag::APPMGR, "Called."); if (!appRunningManager_) { - result.append(MSG_DUMP_IPC_START_STAT) - .append(MSG_DUMP_IPC_FAIL) - .append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_IPC_START_STAT, strlen(MSG_DUMP_IPC_START_STAT)) + .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ is null"); return DumpErrorCode::ERR_INTERNAL_ERROR; } @@ -6082,9 +6082,9 @@ int AppMgrServiceInner::DumpIpcStop(const int32_t pid, std::string& result) { TAG_LOGD(AAFwkTag::APPMGR, "Called."); if (!appRunningManager_) { - result.append(MSG_DUMP_IPC_STOP_STAT) - .append(MSG_DUMP_IPC_FAIL) - .append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_IPC_STOP_STAT, strlen(MSG_DUMP_IPC_STOP_STAT)) + .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ is null"); return DumpErrorCode::ERR_INTERNAL_ERROR; } @@ -6095,15 +6095,27 @@ int AppMgrServiceInner::DumpIpcStat(const int32_t pid, std::string& result) { TAG_LOGD(AAFwkTag::APPMGR, "Called."); if (!appRunningManager_) { - result.append(MSG_DUMP_IPC_STAT) - .append(MSG_DUMP_IPC_FAIL) - .append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_IPC_STAT, strlen(MSG_DUMP_IPC_STAT)) + .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ is null"); return DumpErrorCode::ERR_INTERNAL_ERROR; } return appRunningManager_->DumpIpcStat(pid, result); } +int AppMgrServiceInner::DumpFfrt(const std::vector& pids, std::string& result) +{ + TAG_LOGD(AAFwkTag::APPMGR, "Called."); + if (!appRunningManager_) { + result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); + TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ is null"); + return DumpErrorCode::ERR_INTERNAL_ERROR; + } + return appRunningManager_->DumpFfrt(pids, result); +} + void AppMgrServiceInner::NotifyAppRunningStatusEvent( const std::string &bundle, int32_t uid, AbilityRuntime::RunningStatus runningStatus) { diff --git a/services/appmgr/src/app_running_manager.cpp b/services/appmgr/src/app_running_manager.cpp index d32ccb46570..ab96eab0312 100644 --- a/services/appmgr/src/app_running_manager.cpp +++ b/services/appmgr/src/app_running_manager.cpp @@ -1430,9 +1430,9 @@ int AppRunningManager::DumpIpcStart(const int32_t pid, std::string& result) TAG_LOGD(AAFwkTag::APPMGR, "Called."); const auto& appRecord = GetAppRunningRecordByPid(pid); if (!appRecord) { - result.append(MSG_DUMP_IPC_START_STAT) - .append(MSG_DUMP_IPC_FAIL) - .append(MSG_DUMP_IPC_FAIL_REASON_INVALILD_PID); + result.append(MSG_DUMP_IPC_START_STAT, strlen(MSG_DUMP_IPC_START_STAT)) + .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INVALILD_PID, strlen(MSG_DUMP_FAIL_REASON_INVALILD_PID)); TAG_LOGE(AAFwkTag::APPMGR, "pid %{public}d does not exist", pid); return DumpErrorCode::ERR_INVALID_PID_ERROR; } @@ -1444,9 +1444,9 @@ int AppRunningManager::DumpIpcStop(const int32_t pid, std::string& result) TAG_LOGD(AAFwkTag::APPMGR, "Called."); const auto& appRecord = GetAppRunningRecordByPid(pid); if (!appRecord) { - result.append(MSG_DUMP_IPC_STOP_STAT) - .append(MSG_DUMP_IPC_FAIL) - .append(MSG_DUMP_IPC_FAIL_REASON_INVALILD_PID); + result.append(MSG_DUMP_IPC_STOP_STAT, strlen(MSG_DUMP_IPC_STOP_STAT)) + .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INVALILD_PID, strlen(MSG_DUMP_FAIL_REASON_INVALILD_PID)); TAG_LOGE(AAFwkTag::APPMGR, "pid %{public}d does not exist", pid); return DumpErrorCode::ERR_INVALID_PID_ERROR; } @@ -1458,13 +1458,44 @@ int AppRunningManager::DumpIpcStat(const int32_t pid, std::string& result) TAG_LOGD(AAFwkTag::APPMGR, "Called."); const auto& appRecord = GetAppRunningRecordByPid(pid); if (!appRecord) { - result.append(MSG_DUMP_IPC_STAT) - .append(MSG_DUMP_IPC_FAIL) - .append(MSG_DUMP_IPC_FAIL_REASON_INVALILD_PID); + result.append(MSG_DUMP_IPC_STAT, strlen(MSG_DUMP_IPC_STAT)) + .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INVALILD_PID, strlen(MSG_DUMP_FAIL_REASON_INVALILD_PID)); TAG_LOGE(AAFwkTag::APPMGR, "pid %{public}d does not exist", pid); return DumpErrorCode::ERR_INVALID_PID_ERROR; } return appRecord->DumpIpcStat(result); } + +int AppRunningManager::DumpFfrt(const std::vector& pids, std::string& result) +{ + TAG_LOGD(AAFwkTag::APPMGR, "Called."); + int errCode = DumpErrorCode::ERR_OK; + size_t count = 0; + for (const auto& pid : pids) { + TAG_LOGD(AAFwkTag::APPMGR, "DumpFfrt current pid:%{public}d", pid); + const auto& appRecord = GetAppRunningRecordByPid(pid); + if (!appRecord) { + TAG_LOGE(AAFwkTag::APPMGR, "pid %{public}d does not exist", pid); + ++count; + continue; + } + std::string currentResult; + errCode = appRecord->DumpFfrt(currentResult); + if (errCode != DumpErrorCode::ERR_OK) { + continue; + } + result += currentResult + "\n"; + } + if (count == pids.size()) { + TAG_LOGE(AAFwkTag::APPMGR, "no valid pid"); + return DumpErrorCode::ERR_INVALID_PID_ERROR; + } + if (result.empty()) { + TAG_LOGE(AAFwkTag::APPMGR, "no ffrt usage is found"); + return DumpErrorCode::ERR_INTERNAL_ERROR; + } + return DumpErrorCode::ERR_OK; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index a15522e5e45..4cc884fe447 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -2111,9 +2111,9 @@ int AppRunningRecord::DumpIpcStart(std::string& result) { TAG_LOGD(AAFwkTag::APPMGR, "Called."); if (appLifeCycleDeal_ == nullptr) { - result.append(MSG_DUMP_IPC_START_STAT) - .append(MSG_DUMP_IPC_FAIL) - .append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_IPC_START_STAT, strlen(MSG_DUMP_IPC_START_STAT)) + .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "appLifeCycleDeal_ is null"); return DumpErrorCode::ERR_INTERNAL_ERROR; } @@ -2124,9 +2124,9 @@ int AppRunningRecord::DumpIpcStop(std::string& result) { TAG_LOGD(AAFwkTag::APPMGR, "Called."); if (appLifeCycleDeal_ == nullptr) { - result.append(MSG_DUMP_IPC_STOP_STAT) - .append(MSG_DUMP_IPC_FAIL) - .append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_IPC_STOP_STAT, strlen(MSG_DUMP_IPC_STOP_STAT)) + .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "appLifeCycleDeal_ is null"); return DumpErrorCode::ERR_INTERNAL_ERROR; } @@ -2137,15 +2137,27 @@ int AppRunningRecord::DumpIpcStat(std::string& result) { TAG_LOGD(AAFwkTag::APPMGR, "Called."); if (appLifeCycleDeal_ == nullptr) { - result.append(MSG_DUMP_IPC_STAT) - .append(MSG_DUMP_IPC_FAIL) - .append(MSG_DUMP_IPC_FAIL_REASON_INTERNAL); + result.append(MSG_DUMP_IPC_STAT, strlen(MSG_DUMP_IPC_STAT)) + .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); TAG_LOGE(AAFwkTag::APPMGR, "appLifeCycleDeal_ is null"); return DumpErrorCode::ERR_INTERNAL_ERROR; } return appLifeCycleDeal_->DumpIpcStat(result); } +int AppRunningRecord::DumpFfrt(std::string& result) +{ + TAG_LOGD(AAFwkTag::APPMGR, "Called."); + if (appLifeCycleDeal_ == nullptr) { + result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); + TAG_LOGE(AAFwkTag::APPMGR, "appLifeCycleDeal_ is null"); + return DumpErrorCode::ERR_INTERNAL_ERROR; + } + return appLifeCycleDeal_->DumpFfrt(result); +} + bool AppRunningRecord::SetSupportedProcessCache(bool isSupport) { TAG_LOGI(AAFwkTag::APPMGR, "Called"); diff --git a/test/fuzztest/appmgrservicefirst_fuzzer/appmgrservicefirst_fuzzer.cpp b/test/fuzztest/appmgrservicefirst_fuzzer/appmgrservicefirst_fuzzer.cpp index 215800a1dd3..a75df1c6b3d 100644 --- a/test/fuzztest/appmgrservicefirst_fuzzer/appmgrservicefirst_fuzzer.cpp +++ b/test/fuzztest/appmgrservicefirst_fuzzer/appmgrservicefirst_fuzzer.cpp @@ -105,7 +105,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) appMgrService->Dump(fd, args); std::string result(data, size); appMgrService->Dump(args, result); - appMgrService->ShowHelp(result); + appMgrService->ShowHelp(args, result); std::string flag(data, size); appMgrService->ScheduleAcceptWantDone(recordId, *want, flag); Configuration config; diff --git a/test/mock/services_appmgr_test/include/mock_app_scheduler.h b/test/mock/services_appmgr_test/include/mock_app_scheduler.h index c3702a01349..8de91fa1c60 100644 --- a/test/mock/services_appmgr_test/include/mock_app_scheduler.h +++ b/test/mock/services_appmgr_test/include/mock_app_scheduler.h @@ -66,6 +66,7 @@ public: MOCK_METHOD1(ScheduleDumpIpcStop, int32_t(std::string &result)); MOCK_METHOD1(ScheduleDumpIpcStat, int32_t(std::string &result)); MOCK_METHOD0(IsMemorySizeSufficent, bool()); + MOCK_METHOD1(ScheduleDumpFfrt, int32_t(std::string& result)); }; } // namespace AppExecFwk } // namespace OHOS diff --git a/test/mock/services_appmgr_test/include/mock_application.h b/test/mock/services_appmgr_test/include/mock_application.h index fbf6cf32c77..5eea0d49deb 100644 --- a/test/mock/services_appmgr_test/include/mock_application.h +++ b/test/mock/services_appmgr_test/include/mock_application.h @@ -60,6 +60,7 @@ public: MOCK_METHOD1(ScheduleDumpIpcStop, int32_t(std::string &result)); MOCK_METHOD1(ScheduleDumpIpcStat, int32_t(std::string &result)); MOCK_METHOD0(IsMemorySizeSufficent, bool()); + MOCK_METHOD1(ScheduleDumpFfrt, int32_t(std::string& result)); void Post() { diff --git a/test/moduletest/common/ams/BUILD.gn b/test/moduletest/common/ams/BUILD.gn index 397ebd424f1..7c2c4c6f931 100644 --- a/test/moduletest/common/ams/BUILD.gn +++ b/test/moduletest/common/ams/BUILD.gn @@ -32,7 +32,6 @@ ohos_source_set("appmgr_mst_source") { public_configs = [ "${ability_runtime_test_path}/moduletest:services_module_test_config", "${ability_runtime_services_path}/appmgr:appmgr_config", - "${ability_runtime_services_path}/appmgr:appmgr_exception_config", "${ability_runtime_test_path}/moduletest:services_mock_ams_config", "${ability_runtime_innerkits_path}/app_manager:appmgr_sdk_config", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy_config", diff --git a/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp b/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp index 2256b915bad..6927f34b61a 100644 --- a/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp +++ b/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp @@ -204,6 +204,11 @@ public: return 0; } + int32_t ScheduleDumpFfrt(std::string& result) override + { + return 0; + } + private: int abilityLaunchTime = 0; int appLaunchTime = 0; diff --git a/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp b/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp index e9f7b75a846..531cc927c6f 100644 --- a/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp +++ b/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp @@ -123,6 +123,11 @@ public: { return 0; } + + int32_t ScheduleDumpFfrt(std::string& result) override + { + return 0; + } }; class AppMgrServiceModuleTest : public testing::Test { public: diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 9621d334bc5..23fd0224e9a 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -19,7 +19,6 @@ import( config("appmgr_test_config") { configs = [ "${ability_runtime_services_path}/appmgr:appmgr_config", - "${ability_runtime_services_path}/appmgr:appmgr_exception_config", "${ability_runtime_innerkits_path}/app_manager:appmgr_sdk_config", "${ability_runtime_test_path}/moduletest:services_mock_ams_config", ] @@ -385,6 +384,7 @@ group("unittest") { "app_lifecycle_deal_test:unittest", "app_mgr_client_test:unittest", "app_mgr_proxy_test:unittest", + "app_mgr_service_dump_ffrt_test:unittest", "app_mgr_service_dump_ipc_test:unittest", "app_mgr_service_dump_test:unittest", "app_mgr_service_event_handler_test:unittest", diff --git a/test/unittest/app_mgr_service_dump_ffrt_test/BUILD.gn b/test/unittest/app_mgr_service_dump_ffrt_test/BUILD.gn new file mode 100644 index 00000000000..957f6ff9b7e --- /dev/null +++ b/test/unittest/app_mgr_service_dump_ffrt_test/BUILD.gn @@ -0,0 +1,67 @@ +# Copyright (c) 2024 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/ability_runtime.gni") + +module_output_path = "ability_runtime/abilitymgr" + +ohos_unittest("app_mgr_service_dump_ffrt_test") { + module_out_path = module_output_path + + include_dirs = [ + "${ability_runtime_test_path}/mock/common/include", + "mock/include", + ] + + sources = [ + "app_mgr_service_dump_ffrt_test.cpp", + "mock/src/mock_ipc_skeleton.cpp", + ] + + configs = [ "${ability_runtime_services_path}/appmgr:appmgr_config" ] + + deps = [ + "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:task_handler_wrap", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:app_manager", + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "appspawn:appspawn_client", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "ffrt:libffrt", + "hilog:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } +} + +group("unittest") { + testonly = true + + deps = [ ":app_mgr_service_dump_ffrt_test" ] +} diff --git a/test/unittest/app_mgr_service_dump_ffrt_test/app_mgr_service_dump_ffrt_test.cpp b/test/unittest/app_mgr_service_dump_ffrt_test/app_mgr_service_dump_ffrt_test.cpp new file mode 100644 index 00000000000..4dbbaedcd76 --- /dev/null +++ b/test/unittest/app_mgr_service_dump_ffrt_test/app_mgr_service_dump_ffrt_test.cpp @@ -0,0 +1,457 @@ +/* + * Copyright (c) 2024 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 + +#include "mock_ipc_skeleton.h" + +#define private public +#include "app_mgr_service.h" +#undef private +#include "hilog_tag_wrapper.h" +#include "hilog_wrapper.h" +#include "mock_app_mgr_service_inner.h" +#include "app_mgr_service_dump_error_code.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace AppExecFwk { +namespace { +const int32_t HIDUMPER_SERVICE_UID = 1212; +const int32_t RANDOM_SERVICE_UID = 1500; +const int32_t NUMBER_VALID_PID_1 = 2000; +const int32_t NUMBER_VALID_PID_2 = 2001; +const int32_t NUMBER_VALID_PID_3 = 2002; +const int32_t NUMBER_VALID_PID_4 = 2003; +const int32_t NUMBER_INVALID_PID_1 = -1001; +const int32_t NUMBER_INVALID_PID_2 = -1002; +const int32_t NUMBER_INVALID_PID_3 = -1003; +const int32_t NUMBER_PID_APP_RUNING_RECORD_NOT_EXIST_1 = 3000; +const int32_t NUMBER_PID_APP_RUNING_RECORD_NOT_EXIST_2 = 3001; +const int32_t NUMBER_PID_APP_RUNING_RECORD_NOT_EXIST_3 = 3002; +const std::string STRING_INVALID_PID_1 = "invalid"; +const std::string STRING_INVALID_PID_2 = "invalid1000"; +const std::string STRING_OPTION_FFRT = "--ffrt"; +} // namespace + +class AppMgrServiceDumpFFRTTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void AppMgrServiceDumpFFRTTest::SetUpTestCase(void) +{} + +void AppMgrServiceDumpFFRTTest::TearDownTestCase(void) +{} + +void AppMgrServiceDumpFFRTTest::SetUp() +{} + +void AppMgrServiceDumpFFRTTest::TearDown() +{} + +/* + * @tc.number : AppMgrServiceDumpFFRT_0100 + * @tc.name : AppMgrService dump + * @tc.desc : 1.Test with args --ffrt + */ +HWTEST_F(AppMgrServiceDumpFFRTTest, AppMgrServiceDumpFFRT_0100, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceDumpFFRT_0100 start"); + + auto appMgrService = std::make_shared(); + EXPECT_NE(appMgrService, nullptr); + appMgrService->taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler(Constants::APP_MGR_SERVICE_NAME); + EXPECT_NE(appMgrService->taskHandler_, nullptr); + auto mockAppMgrServiceInner = std::make_shared(); + EXPECT_NE(mockAppMgrServiceInner, nullptr); + appMgrService->SetInnerService(mockAppMgrServiceInner); + EXPECT_NE(appMgrService->appMgrServiceInner_, nullptr); + appMgrService->eventHandler_ = std::make_shared( + appMgrService->taskHandler_, appMgrService->appMgrServiceInner_); + EXPECT_NE(appMgrService->eventHandler_, nullptr); + + // IsHidumperServiceCall + IPCSkeleton::SetCallingUid(HIDUMPER_SERVICE_UID); + EXPECT_TRUE((IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID)); + + constexpr int fd(1); + std::vector args; + auto arg0 = Str8ToStr16(STRING_OPTION_FFRT); + args.emplace_back(arg0); + auto result = appMgrService->Dump(fd, args); + EXPECT_EQ(result, DumpErrorCode::ERR_INVALID_NUM_ARGS_ERROR); + + TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceDumpFFRT_0100 end"); +} + +/* + * @tc.number : AppMgrServiceDumpFFRT_0200 + * @tc.name : AppMgrService dump + * @tc.desc : 1.Test with args --ffrt without correct permission + */ +HWTEST_F(AppMgrServiceDumpFFRTTest, AppMgrServiceDumpFFRT_0200, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceDumpFFRT_0200 start"); + + auto appMgrService = std::make_shared(); + EXPECT_NE(appMgrService, nullptr); + appMgrService->taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler(Constants::APP_MGR_SERVICE_NAME); + EXPECT_NE(appMgrService->taskHandler_, nullptr); + auto mockAppMgrServiceInner = std::make_shared(); + EXPECT_NE(mockAppMgrServiceInner, nullptr); + appMgrService->SetInnerService(mockAppMgrServiceInner); + EXPECT_NE(appMgrService->appMgrServiceInner_, nullptr); + appMgrService->eventHandler_ = std::make_shared( + appMgrService->taskHandler_, appMgrService->appMgrServiceInner_); + EXPECT_NE(appMgrService->eventHandler_, nullptr); + + // Not HidumperServiceCall + IPCSkeleton::SetCallingUid(RANDOM_SERVICE_UID); + EXPECT_FALSE((IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID)); + + constexpr int fd(1); + std::vector args; + auto arg0 = Str8ToStr16(STRING_OPTION_FFRT); + args.emplace_back(arg0); + auto arg1 = Str8ToStr16(std::to_string(NUMBER_VALID_PID_1)); + args.emplace_back(arg1); + auto result = appMgrService->Dump(fd, args); + EXPECT_EQ(result, DumpErrorCode::ERR_PERMISSION_DENY_ERROR); + + TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceDumpFFRT_0200 end"); +} + +/* + * @tc.number : AppMgrServiceDumpFFRT_0300 + * @tc.name : AppMgrService dump + * @tc.desc : 1.Test with args --ffrt pid1|pid2|pid3 + */ +HWTEST_F(AppMgrServiceDumpFFRTTest, AppMgrServiceDumpFFRT_0300, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceDumpFFRT_0300 start"); + + auto appMgrService = std::make_shared(); + EXPECT_NE(appMgrService, nullptr); + appMgrService->taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler(Constants::APP_MGR_SERVICE_NAME); + EXPECT_NE(appMgrService->taskHandler_, nullptr); + auto mockAppMgrServiceInner = std::make_shared(); + EXPECT_NE(mockAppMgrServiceInner, nullptr); + appMgrService->SetInnerService(mockAppMgrServiceInner); + EXPECT_NE(appMgrService->appMgrServiceInner_, nullptr); + appMgrService->eventHandler_ = std::make_shared( + appMgrService->taskHandler_, appMgrService->appMgrServiceInner_); + EXPECT_NE(appMgrService->eventHandler_, nullptr); + + // IsHidumperServiceCall + IPCSkeleton::SetCallingUid(HIDUMPER_SERVICE_UID); + EXPECT_TRUE((IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID)); + + constexpr int fd(1); + std::vector args; + auto arg0 = Str8ToStr16(STRING_OPTION_FFRT); + args.emplace_back(arg0); + std::string pids; + pids.append(std::to_string(NUMBER_VALID_PID_1)) + .append("|") + .append(std::to_string(NUMBER_VALID_PID_2)) + .append("|") + .append(std::to_string(NUMBER_VALID_PID_3)); + auto arg1 = Str8ToStr16(pids); + args.emplace_back(arg1); + auto result = appMgrService->Dump(fd, args); + EXPECT_EQ(result, DumpErrorCode::ERR_INVALID_PID_ERROR); + + TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceDumpFFRT_0300 end"); +} + +/* + * @tc.number : AppMgrServiceDumpFFRT_0400 + * @tc.name : AppMgrService dump + * @tc.desc : 1.Test with args --ffrt ' ,,' + */ +HWTEST_F(AppMgrServiceDumpFFRTTest, AppMgrServiceDumpFFRT_0400, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceDumpFFRT_0400 start"); + + auto appMgrService = std::make_shared(); + EXPECT_NE(appMgrService, nullptr); + appMgrService->taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler(Constants::APP_MGR_SERVICE_NAME); + EXPECT_NE(appMgrService->taskHandler_, nullptr); + auto mockAppMgrServiceInner = std::make_shared(); + EXPECT_NE(mockAppMgrServiceInner, nullptr); + appMgrService->SetInnerService(mockAppMgrServiceInner); + EXPECT_NE(appMgrService->appMgrServiceInner_, nullptr); + appMgrService->eventHandler_ = std::make_shared( + appMgrService->taskHandler_, appMgrService->appMgrServiceInner_); + EXPECT_NE(appMgrService->eventHandler_, nullptr); + + // IsHidumperServiceCall + IPCSkeleton::SetCallingUid(HIDUMPER_SERVICE_UID); + EXPECT_TRUE((IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID)); + + constexpr int fd(1); + std::vector args; + auto arg0 = Str8ToStr16(STRING_OPTION_FFRT); + args.emplace_back(arg0); + std::string pids; + pids.append(" ,") + .append(std::to_string(NUMBER_INVALID_PID_1)) + .append(",") + .append(STRING_INVALID_PID_2); + auto arg1 = Str8ToStr16(pids); + args.emplace_back(arg1); + auto result = appMgrService->Dump(fd, args); + EXPECT_EQ(result, DumpErrorCode::ERR_INVALID_PID_ERROR); + + TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceDumpFFRT_0400 end"); +} + +/* + * @tc.number : AppMgrServiceDumpFFRT_0500 + * @tc.name : AppMgrService dump + * @tc.desc : 1.Test with args --ffrt ,,, + */ +HWTEST_F(AppMgrServiceDumpFFRTTest, AppMgrServiceDumpFFRT_0500, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceDumpFFRT_0500 start"); + + auto appMgrService = std::make_shared(); + EXPECT_NE(appMgrService, nullptr); + appMgrService->taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler(Constants::APP_MGR_SERVICE_NAME); + EXPECT_NE(appMgrService->taskHandler_, nullptr); + auto mockAppMgrServiceInner = std::make_shared(); + EXPECT_NE(mockAppMgrServiceInner, nullptr); + appMgrService->SetInnerService(mockAppMgrServiceInner); + EXPECT_NE(appMgrService->appMgrServiceInner_, nullptr); + appMgrService->eventHandler_ = std::make_shared( + appMgrService->taskHandler_, appMgrService->appMgrServiceInner_); + EXPECT_NE(appMgrService->eventHandler_, nullptr); + + // IsHidumperServiceCall + IPCSkeleton::SetCallingUid(HIDUMPER_SERVICE_UID); + EXPECT_TRUE((IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID)); + + constexpr int fd(1); + std::vector args; + auto arg0 = Str8ToStr16(STRING_OPTION_FFRT); + args.emplace_back(arg0); + std::string pids; + pids.append(std::to_string(NUMBER_INVALID_PID_1)) + .append(",") + .append(std::to_string(NUMBER_INVALID_PID_2)) + .append(",") + .append(std::to_string(NUMBER_INVALID_PID_3)) + .append(",") + .append(std::to_string(NUMBER_VALID_PID_1)); + auto arg1 = Str8ToStr16(pids); + args.emplace_back(arg1); + auto result = appMgrService->Dump(fd, args); + EXPECT_EQ(result, DumpErrorCode::ERR_INVALID_PID_ERROR); + + TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceDumpFFRT_0500 end"); +} + +/* + * @tc.number : AppMgrServiceDumpFFRT_0600 + * @tc.name : AppMgrService dump + * @tc.desc : 1.Test with args --ffrt --stat + */ +HWTEST_F(AppMgrServiceDumpFFRTTest, AppMgrServiceDumpFFRT_0600, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceDumpFFRT_0600 start"); + + auto appMgrService = std::make_shared(); + EXPECT_NE(appMgrService, nullptr); + appMgrService->taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler(Constants::APP_MGR_SERVICE_NAME); + EXPECT_NE(appMgrService->taskHandler_, nullptr); + auto mockAppMgrServiceInner = std::make_shared(); + EXPECT_NE(mockAppMgrServiceInner, nullptr); + appMgrService->SetInnerService(mockAppMgrServiceInner); + EXPECT_NE(appMgrService->appMgrServiceInner_, nullptr); + appMgrService->eventHandler_ = std::make_shared( + appMgrService->taskHandler_, appMgrService->appMgrServiceInner_); + EXPECT_NE(appMgrService->eventHandler_, nullptr); + + // IsHidumperServiceCall + IPCSkeleton::SetCallingUid(HIDUMPER_SERVICE_UID); + EXPECT_TRUE((IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID)); + + constexpr int fd(1); + std::vector args; + auto arg0 = Str8ToStr16(STRING_OPTION_FFRT); + args.emplace_back(arg0); + std::string pids; + pids.append(std::to_string(NUMBER_PID_APP_RUNING_RECORD_NOT_EXIST_1)) + .append(",") + .append(std::to_string(NUMBER_PID_APP_RUNING_RECORD_NOT_EXIST_2)) + .append(",") + .append(std::to_string(NUMBER_PID_APP_RUNING_RECORD_NOT_EXIST_3)); + auto arg1 = Str8ToStr16(pids); + args.emplace_back(arg1); + EXPECT_CALL(*mockAppMgrServiceInner, DumpFfrt(_, _)) + .Times(1).WillOnce(Return(DumpErrorCode::ERR_INVALID_PID_ERROR)); + auto result = appMgrService->Dump(fd, args); + EXPECT_EQ(result, DumpErrorCode::ERR_INVALID_PID_ERROR); + + TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceDumpFFRT_0600 end"); +} + +/* + * @tc.number : AppMgrServiceDumpFFRT_0700 + * @tc.name : AppMgrService dump + * @tc.desc : 1.Test with args --ffrt pid1,pid2,pid3,pid4 + */ +HWTEST_F(AppMgrServiceDumpFFRTTest, AppMgrServiceDumpFFRT_0700, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceDumpFFRT_0700 start"); + + auto appMgrService = std::make_shared(); + EXPECT_NE(appMgrService, nullptr); + appMgrService->taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler(Constants::APP_MGR_SERVICE_NAME); + EXPECT_NE(appMgrService->taskHandler_, nullptr); + auto mockAppMgrServiceInner = std::make_shared(); + EXPECT_NE(mockAppMgrServiceInner, nullptr); + appMgrService->SetInnerService(mockAppMgrServiceInner); + EXPECT_NE(appMgrService->appMgrServiceInner_, nullptr); + appMgrService->eventHandler_ = std::make_shared( + appMgrService->taskHandler_, appMgrService->appMgrServiceInner_); + EXPECT_NE(appMgrService->eventHandler_, nullptr); + + // IsHidumperServiceCall + IPCSkeleton::SetCallingUid(HIDUMPER_SERVICE_UID); + EXPECT_TRUE((IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID)); + + constexpr int fd(1); + std::vector args; + auto arg0 = Str8ToStr16(STRING_OPTION_FFRT); + args.emplace_back(arg0); + std::string pids; + pids.append(std::to_string(NUMBER_VALID_PID_1)) + .append(",") + .append(std::to_string(NUMBER_VALID_PID_2)) + .append(",") + .append(std::to_string(NUMBER_VALID_PID_3)) + .append(",") + .append(std::to_string(NUMBER_VALID_PID_4)); + auto arg1 = Str8ToStr16(pids); + args.emplace_back(arg1); + std::vector validPids = {NUMBER_VALID_PID_1, NUMBER_VALID_PID_2, NUMBER_VALID_PID_3}; + EXPECT_CALL(*mockAppMgrServiceInner, DumpFfrt(validPids, _)) + .Times(1).WillOnce(Return(DumpErrorCode::ERR_OK)); + auto result = appMgrService->Dump(fd, args); + EXPECT_EQ(result, DumpErrorCode::ERR_OK); + + TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceDumpFFRT_0700 end"); +} + +/* + * @tc.number : AppMgrServiceDumpFFRT_0800 + * @tc.name : AppMgrService dump + * @tc.desc : 1.Test with args --ffrt pid1,,pid2,pid3 + */ +HWTEST_F(AppMgrServiceDumpFFRTTest, AppMgrServiceDumpFFRT_0800, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceDumpFFRT_0800 start"); + + auto appMgrService = std::make_shared(); + EXPECT_NE(appMgrService, nullptr); + appMgrService->taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler(Constants::APP_MGR_SERVICE_NAME); + EXPECT_NE(appMgrService->taskHandler_, nullptr); + auto mockAppMgrServiceInner = std::make_shared(); + EXPECT_NE(mockAppMgrServiceInner, nullptr); + appMgrService->SetInnerService(mockAppMgrServiceInner); + EXPECT_NE(appMgrService->appMgrServiceInner_, nullptr); + appMgrService->eventHandler_ = std::make_shared( + appMgrService->taskHandler_, appMgrService->appMgrServiceInner_); + EXPECT_NE(appMgrService->eventHandler_, nullptr); + + // IsHidumperServiceCall + IPCSkeleton::SetCallingUid(HIDUMPER_SERVICE_UID); + EXPECT_TRUE((IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID)); + + constexpr int fd(1); + std::vector args; + auto arg0 = Str8ToStr16(STRING_OPTION_FFRT); + args.emplace_back(arg0); + std::string pids; + pids.append(std::to_string(NUMBER_VALID_PID_1)) + .append(",") + .append(STRING_INVALID_PID_1) + .append(",") + .append(std::to_string(NUMBER_VALID_PID_2)) + .append(",") + .append(std::to_string(NUMBER_VALID_PID_3)); + auto arg1 = Str8ToStr16(pids); + args.emplace_back(arg1); + std::vector validPids = {NUMBER_VALID_PID_1, NUMBER_VALID_PID_2}; + EXPECT_CALL(*mockAppMgrServiceInner, DumpFfrt(validPids, _)) + .Times(1).WillOnce(Return(DumpErrorCode::ERR_OK)); + auto result = appMgrService->Dump(fd, args); + EXPECT_EQ(result, DumpErrorCode::ERR_OK); + + TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceDumpFFRT_0800 end"); +} + +/* + * @tc.number : AppMgrServiceDumpFFRT_0900 + * @tc.name : AppMgrService dump + * @tc.desc : 1.Test with args --ffrt |pid2|pid3 + */ +HWTEST_F(AppMgrServiceDumpFFRTTest, AppMgrServiceDumpFFRT_0900, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceDumpFFRT_0900 start"); + + auto appMgrService = std::make_shared(); + EXPECT_NE(appMgrService, nullptr); + appMgrService->taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler(Constants::APP_MGR_SERVICE_NAME); + EXPECT_NE(appMgrService->taskHandler_, nullptr); + auto mockAppMgrServiceInner = std::make_shared(); + EXPECT_NE(mockAppMgrServiceInner, nullptr); + appMgrService->SetInnerService(mockAppMgrServiceInner); + EXPECT_NE(appMgrService->appMgrServiceInner_, nullptr); + appMgrService->eventHandler_ = std::make_shared( + appMgrService->taskHandler_, appMgrService->appMgrServiceInner_); + EXPECT_NE(appMgrService->eventHandler_, nullptr); + + // IsHidumperServiceCall + IPCSkeleton::SetCallingUid(HIDUMPER_SERVICE_UID); + EXPECT_TRUE((IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID)); + + constexpr int fd(1); + std::vector args; + auto arg0 = Str8ToStr16(STRING_OPTION_FFRT); + args.emplace_back(arg0); + std::string pids; + pids.append(STRING_INVALID_PID_1) + .append("|") + .append(std::to_string(NUMBER_VALID_PID_2)) + .append("|") + .append(std::to_string(NUMBER_VALID_PID_3)); + auto arg1 = Str8ToStr16(pids); + args.emplace_back(arg1); + auto result = appMgrService->Dump(fd, args); + EXPECT_EQ(result, DumpErrorCode::ERR_INVALID_PID_ERROR); + + TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceDumpFFRT_0900 end"); +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/test/unittest/app_mgr_service_dump_ffrt_test/mock/include/mock_app_mgr_service_inner.h b/test/unittest/app_mgr_service_dump_ffrt_test/mock/include/mock_app_mgr_service_inner.h new file mode 100644 index 00000000000..1e47d2cd2b5 --- /dev/null +++ b/test/unittest/app_mgr_service_dump_ffrt_test/mock/include/mock_app_mgr_service_inner.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 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 MOCK_OHOS_ABILITY_RUNTIME_MOCK_APP_MGR_SERVICE_INNER_H +#define MOCK_OHOS_ABILITY_RUNTIME_MOCK_APP_MGR_SERVICE_INNER_H + +#include "gmock/gmock.h" +#include "app_mgr_service_inner.h" + +namespace OHOS { +namespace AppExecFwk { +class MockAppMgrServiceInner : public AppMgrServiceInner { +public: + MockAppMgrServiceInner() + {} + virtual ~MockAppMgrServiceInner() + {} + + MOCK_METHOD2(DumpFfrt, int(const std::vector& pid, std::string& result)); +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // MOCK_OHOS_ABILITY_RUNTIME_MOCK_APP_MGR_SERVICE_INNER_H diff --git a/test/unittest/app_mgr_service_dump_ffrt_test/mock/include/mock_ipc_skeleton.h b/test/unittest/app_mgr_service_dump_ffrt_test/mock/include/mock_ipc_skeleton.h new file mode 100644 index 00000000000..2c9e4fad3f0 --- /dev/null +++ b/test/unittest/app_mgr_service_dump_ffrt_test/mock/include/mock_ipc_skeleton.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2024 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_IPC_IPC_SKELETON_H +#define OHOS_IPC_IPC_SKELETON_H + +#include "iremote_object.h" + +namespace OHOS { +class IPCSkeleton { +public: + IPCSkeleton() = default; + ~IPCSkeleton() = default; + + // default max is 4, only if you need a customize value + static bool SetMaxWorkThreadNum(int maxThreadNum); + + // join current thread into work loop. + static void JoinWorkThread(); + + // remove current thread from work loop. + static void StopWorkThread(); + + static pid_t GetCallingPid(); + + static pid_t GetCallingUid(); + + static uint32_t GetCallingTokenID(); + + static std::string GetLocalDeviceID(); + + static std::string GetCallingDeviceID(); + + static bool IsLocalCalling(); + + static IPCSkeleton &GetInstance(); + + static sptr GetContextObject(); + + static bool SetContextObject(sptr &object); + + static int FlushCommands(IRemoteObject *object); + + static std::string ResetCallingIdentity(); + + static bool SetCallingIdentity(std::string &identity); + + static void SetCallingUid(pid_t uid); + + static uint32_t SetCallingTokenID(pid_t tokenId); +}; +} // namespace OHOS +#endif // OHOS_IPC_IPC_SKELETON_H diff --git a/test/unittest/app_mgr_service_dump_ipc_test/mock/src/mock_my_flag.cpp b/test/unittest/app_mgr_service_dump_ffrt_test/mock/src/mock_ipc_skeleton.cpp similarity index 56% rename from test/unittest/app_mgr_service_dump_ipc_test/mock/src/mock_my_flag.cpp rename to test/unittest/app_mgr_service_dump_ffrt_test/mock/src/mock_ipc_skeleton.cpp index ce14cafa2cd..548c50482e1 100644 --- a/test/unittest/app_mgr_service_dump_ipc_test/mock/src/mock_my_flag.cpp +++ b/test/unittest/app_mgr_service_dump_ffrt_test/mock/src/mock_ipc_skeleton.cpp @@ -13,10 +13,38 @@ * limitations under the License. */ -#include "mock_my_flag.h" +#include "mock_ipc_skeleton.h" namespace OHOS { -namespace AAFwk { -int MyFlag::flag_ = 0; -} // namespace AAFwk -} // namespace OHOS +#ifdef CONFIG_IPC_SINGLE +using namespace IPC_SINGLE; +#endif + +pid_t uid_ = 0; +pid_t tokenId_ = 0; + +pid_t IPCSkeleton::GetCallingUid() +{ + return uid_; +} + +pid_t IPCSkeleton::GetCallingPid() +{ + return 1; +} + +void IPCSkeleton::SetCallingUid(pid_t uid) +{ + uid_ = uid; +} + +uint32_t IPCSkeleton::GetCallingTokenID() +{ + return tokenId_; +} + +uint32_t IPCSkeleton::SetCallingTokenID(pid_t tokenId) +{ + return tokenId_ = tokenId; +} +} // namespace OHOS diff --git a/test/unittest/app_mgr_service_dump_ipc_test/BUILD.gn b/test/unittest/app_mgr_service_dump_ipc_test/BUILD.gn index 7bfd267254f..cf47e02113a 100644 --- a/test/unittest/app_mgr_service_dump_ipc_test/BUILD.gn +++ b/test/unittest/app_mgr_service_dump_ipc_test/BUILD.gn @@ -27,8 +27,6 @@ ohos_unittest("app_mgr_service_dump_ipc_test") { sources = [ "app_mgr_service_dump_ipc_test.cpp", "mock/src/mock_ipc_skeleton.cpp", - "mock/src/mock_my_flag.cpp", - "mock/src/mock_permission_verification.cpp", ] configs = [ "${ability_runtime_services_path}/appmgr:appmgr_config" ] diff --git a/test/unittest/app_mgr_service_dump_ipc_test/app_mgr_service_dump_ipc_test.cpp b/test/unittest/app_mgr_service_dump_ipc_test/app_mgr_service_dump_ipc_test.cpp index 5b5b25f1e8a..590d52f0c7e 100644 --- a/test/unittest/app_mgr_service_dump_ipc_test/app_mgr_service_dump_ipc_test.cpp +++ b/test/unittest/app_mgr_service_dump_ipc_test/app_mgr_service_dump_ipc_test.cpp @@ -16,7 +16,6 @@ #include #include "mock_ipc_skeleton.h" -#include "mock_permission_verification.h" #define private public #include "app_mgr_service.h" @@ -89,10 +88,6 @@ HWTEST_F(AppMgrServiceDumpIPCTest, AppMgrServiceDumpIPC_0100, TestSize.Level1) IPCSkeleton::SetCallingUid(HIDUMPER_SERVICE_UID); EXPECT_TRUE((IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID)); - // IsShellCall - AAFwk::MyFlag::flag_ = AAFwk::MyFlag::FLAG::IS_SHELL_CALL; - EXPECT_TRUE(AAFwk::PermissionVerification::GetInstance()->IsShellCall()); - constexpr int fd(1); std::vector args; auto arg0 = Str8ToStr16(STRING_OPTION_IPC); @@ -134,10 +129,6 @@ HWTEST_F(AppMgrServiceDumpIPCTest, AppMgrServiceDumpIPC_0200, TestSize.Level1) IPCSkeleton::SetCallingUid(HIDUMPER_SERVICE_UID); EXPECT_TRUE((IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID)); - // IsShellCall - AAFwk::MyFlag::flag_ = AAFwk::MyFlag::FLAG::IS_SHELL_CALL; - EXPECT_TRUE(AAFwk::PermissionVerification::GetInstance()->IsShellCall()); - constexpr int fd(1); std::vector args; auto arg0 = Str8ToStr16(STRING_OPTION_IPC); @@ -178,10 +169,6 @@ HWTEST_F(AppMgrServiceDumpIPCTest, AppMgrServiceDumpIPC_0300, TestSize.Level1) IPCSkeleton::SetCallingUid(HIDUMPER_SERVICE_UID); EXPECT_TRUE((IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID)); - // IsShellCall - AAFwk::MyFlag::flag_ = AAFwk::MyFlag::FLAG::IS_SHELL_CALL; - EXPECT_TRUE(AAFwk::PermissionVerification::GetInstance()->IsShellCall()); - constexpr int fd(1); std::vector args; auto arg0 = Str8ToStr16(STRING_OPTION_IPC); @@ -223,10 +210,6 @@ HWTEST_F(AppMgrServiceDumpIPCTest, AppMgrServiceDumpIPC_0400, TestSize.Level1) IPCSkeleton::SetCallingUid(HIDUMPER_SERVICE_UID); EXPECT_TRUE((IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID)); - // IsShellCall - AAFwk::MyFlag::flag_ = AAFwk::MyFlag::FLAG::IS_SHELL_CALL; - EXPECT_TRUE(AAFwk::PermissionVerification::GetInstance()->IsShellCall()); - constexpr int fd(1); std::vector args; auto arg0 = Str8ToStr16(STRING_OPTION_IPC); @@ -268,10 +251,6 @@ HWTEST_F(AppMgrServiceDumpIPCTest, AppMgrServiceDumpIPC_0500, TestSize.Level1) IPCSkeleton::SetCallingUid(HIDUMPER_SERVICE_UID); EXPECT_TRUE((IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID)); - // IsShellCall - AAFwk::MyFlag::flag_ = AAFwk::MyFlag::FLAG::IS_SHELL_CALL; - EXPECT_TRUE(AAFwk::PermissionVerification::GetInstance()->IsShellCall()); - constexpr int fd(1); std::vector args; auto arg0 = Str8ToStr16(STRING_OPTION_IPC); @@ -312,10 +291,6 @@ HWTEST_F(AppMgrServiceDumpIPCTest, AppMgrServiceDumpIPC_0600, TestSize.Level1) IPCSkeleton::SetCallingUid(HIDUMPER_SERVICE_UID); EXPECT_TRUE((IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID)); - // IsShellCall - AAFwk::MyFlag::flag_ = AAFwk::MyFlag::FLAG::IS_SHELL_CALL; - EXPECT_TRUE(AAFwk::PermissionVerification::GetInstance()->IsShellCall()); - constexpr int fd(1); std::vector args; auto arg0 = Str8ToStr16(STRING_OPTION_IPC); @@ -357,10 +332,6 @@ HWTEST_F(AppMgrServiceDumpIPCTest, AppMgrServiceDumpIPC_0700, TestSize.Level1) IPCSkeleton::SetCallingUid(HIDUMPER_SERVICE_UID); EXPECT_TRUE((IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID)); - // IsShellCall - AAFwk::MyFlag::flag_ = AAFwk::MyFlag::FLAG::IS_SHELL_CALL; - EXPECT_TRUE(AAFwk::PermissionVerification::GetInstance()->IsShellCall()); - constexpr int fd(1); std::vector args; auto arg0 = Str8ToStr16(STRING_OPTION_IPC); @@ -402,10 +373,6 @@ HWTEST_F(AppMgrServiceDumpIPCTest, AppMgrServiceDumpIPC_0800, TestSize.Level1) IPCSkeleton::SetCallingUid(HIDUMPER_SERVICE_UID); EXPECT_TRUE((IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID)); - // IsShellCall - AAFwk::MyFlag::flag_ = AAFwk::MyFlag::FLAG::IS_SHELL_CALL; - EXPECT_TRUE(AAFwk::PermissionVerification::GetInstance()->IsShellCall()); - constexpr int fd(1); std::vector args; auto arg0 = Str8ToStr16(STRING_OPTION_IPC); @@ -447,10 +414,6 @@ HWTEST_F(AppMgrServiceDumpIPCTest, AppMgrServiceDumpIPC_0900, TestSize.Level1) IPCSkeleton::SetCallingUid(HIDUMPER_SERVICE_UID); EXPECT_TRUE((IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID)); - // IsShellCall - AAFwk::MyFlag::flag_ = AAFwk::MyFlag::FLAG::IS_SHELL_CALL; - EXPECT_TRUE(AAFwk::PermissionVerification::GetInstance()->IsShellCall()); - constexpr int fd(1); std::vector args; auto arg0 = Str8ToStr16(STRING_OPTION_IPC); @@ -492,10 +455,6 @@ HWTEST_F(AppMgrServiceDumpIPCTest, AppMgrServiceDumpIPC_1000, TestSize.Level1) IPCSkeleton::SetCallingUid(HIDUMPER_SERVICE_UID); EXPECT_TRUE((IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID)); - // IsShellCall - AAFwk::MyFlag::flag_ = AAFwk::MyFlag::FLAG::IS_SHELL_CALL; - EXPECT_TRUE(AAFwk::PermissionVerification::GetInstance()->IsShellCall()); - constexpr int fd(1); std::vector args; auto arg0 = Str8ToStr16(STRING_OPTION_IPC); @@ -535,10 +494,6 @@ HWTEST_F(AppMgrServiceDumpIPCTest, AppMgrServiceDumpIPC_1100, TestSize.Level1) IPCSkeleton::SetCallingUid(HIDUMPER_SERVICE_UID); EXPECT_TRUE((IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID)); - // IsShellCall - AAFwk::MyFlag::flag_ = AAFwk::MyFlag::FLAG::IS_SHELL_CALL; - EXPECT_TRUE(AAFwk::PermissionVerification::GetInstance()->IsShellCall()); - constexpr int fd(1); std::vector args; auto arg0 = Str8ToStr16(STRING_OPTION_IPC); @@ -578,10 +533,6 @@ HWTEST_F(AppMgrServiceDumpIPCTest, AppMgrServiceDumpIPC_1200, TestSize.Level1) IPCSkeleton::SetCallingUid(HIDUMPER_SERVICE_UID); EXPECT_TRUE((IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID)); - // IsShellCall - AAFwk::MyFlag::flag_ = AAFwk::MyFlag::FLAG::IS_SHELL_CALL; - EXPECT_TRUE(AAFwk::PermissionVerification::GetInstance()->IsShellCall()); - constexpr int fd(1); std::vector args; auto arg0 = Str8ToStr16(STRING_OPTION_IPC); @@ -621,10 +572,6 @@ HWTEST_F(AppMgrServiceDumpIPCTest, AppMgrServiceDumpIPC_1300, TestSize.Level1) IPCSkeleton::SetCallingUid(HIDUMPER_SERVICE_UID); EXPECT_TRUE((IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID)); - // IsShellCall - AAFwk::MyFlag::flag_ = AAFwk::MyFlag::FLAG::IS_SHELL_CALL; - EXPECT_TRUE(AAFwk::PermissionVerification::GetInstance()->IsShellCall()); - constexpr int fd(1); std::vector args; auto arg0 = Str8ToStr16(STRING_OPTION_IPC); @@ -664,10 +611,6 @@ HWTEST_F(AppMgrServiceDumpIPCTest, AppMgrServiceDumpIPC_1400, TestSize.Level1) IPCSkeleton::SetCallingUid(HIDUMPER_SERVICE_UID); EXPECT_TRUE((IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID)); - // IsShellCall - AAFwk::MyFlag::flag_ = AAFwk::MyFlag::FLAG::IS_SHELL_CALL; - EXPECT_TRUE(AAFwk::PermissionVerification::GetInstance()->IsShellCall()); - constexpr int fd(1); std::vector args; auto arg0 = Str8ToStr16(STRING_OPTION_IPC); @@ -705,10 +648,6 @@ HWTEST_F(AppMgrServiceDumpIPCTest, AppMgrServiceDumpIPC_1500, TestSize.Level1) IPCSkeleton::SetCallingUid(RANDOM_SERVICE_UID); EXPECT_FALSE((IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID)); - // Not ShellCall - AAFwk::MyFlag::flag_ = AAFwk::MyFlag::FLAG::IS_INVALID_CALL; - EXPECT_FALSE(AAFwk::PermissionVerification::GetInstance()->IsShellCall()); - constexpr int fd(1); std::vector args; auto arg0 = Str8ToStr16(STRING_OPTION_IPC); diff --git a/test/unittest/app_mgr_service_dump_ipc_test/mock/include/mock_permission_verification.h b/test/unittest/app_mgr_service_dump_ipc_test/mock/include/mock_permission_verification.h deleted file mode 100644 index 14cb3d38eb6..00000000000 --- a/test/unittest/app_mgr_service_dump_ipc_test/mock/include/mock_permission_verification.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_ABILITY_RUNTIME_PERMISSION_VERIFICATION_H -#define OHOS_ABILITY_RUNTIME_PERMISSION_VERIFICATION_H - -#include "mock_ipc_skeleton.h" -#include "mock_my_flag.h" -#include "singleton.h" -#include "want.h" - -namespace OHOS { -namespace AAFwk { -class PermissionVerification : public DelayedSingleton { -public: - struct VerificationInfo { - bool visible = false; - bool isBackgroundCall = true; - bool associatedWakeUp = false; - uint32_t accessTokenId = 0; - int32_t apiTargetVersion = 0; - }; - - PermissionVerification() = default; - ~PermissionVerification() = default; - - bool VerifyCallingPermission(const std::string &permissionName, const uint32_t specifyTokenId = 0) const; - - bool IsSACall() const; - - bool IsShellCall() const; - - bool CheckSpecificSystemAbilityAccessPermission() const; - - bool VerifyRunningInfoPerm() const; - - bool VerifyControllerPerm() const; - - bool VerifyDlpPermission(Want &want) const; - - int VerifyAccountPermission() const; - - bool VerifyMissionPermission() const; - - int VerifyAppStateObserverPermission() const; - - int32_t VerifyUpdateConfigurationPerm() const; - - bool VerifyInstallBundlePermission() const; - - bool VerifyGetBundleInfoPrivilegedPermission() const; - - int CheckCallDataAbilityPermission(const VerificationInfo &verificationInfo, bool isShell) const; - - int CheckCallServiceAbilityPermission(const VerificationInfo &verificationInfo) const; - - int CheckCallAbilityPermission(const VerificationInfo &verificationInfo) const; - - int CheckCallServiceExtensionPermission(const VerificationInfo &verificationInfo) const; - - int CheckStartByCallPermission(const VerificationInfo &verificationInfo) const; - - unsigned int GetCallingTokenID() const; - - bool JudgeStartInvisibleAbility(const uint32_t accessTokenId, const bool visible) const; - - bool JudgeStartAbilityFromBackground(const bool isBackgroundCall) const; - - bool JudgeAssociatedWakeUp(const uint32_t accessTokenId, const bool associatedWakeUp) const; - - int JudgeInvisibleAndBackground(const VerificationInfo &verificationInfo) const; - - inline bool IsCallFromSameAccessToken(const uint32_t accessTokenId) const - { - return IPCSkeleton::GetCallingTokenID() == accessTokenId; - } - - bool JudgeCallerIsAllowedToUseSystemAPI() const; - bool IsSystemAppCall() const; -}; -} // namespace AAFwk -} // namespace OHOS -#endif // OHOS_ABILITY_RUNTIME_PERMISSION_VERIFICATION_H \ No newline at end of file diff --git a/test/unittest/app_mgr_service_dump_ipc_test/mock/src/mock_permission_verification.cpp b/test/unittest/app_mgr_service_dump_ipc_test/mock/src/mock_permission_verification.cpp deleted file mode 100644 index 132a9401362..00000000000 --- a/test/unittest/app_mgr_service_dump_ipc_test/mock/src/mock_permission_verification.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2024 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 "mock_permission_verification.h" - -namespace OHOS { -namespace AAFwk { -bool PermissionVerification::VerifyCallingPermission( - const std::string &permissionName, const uint32_t specifyTokenId) const -{ - return !!(MyFlag::flag_); -} -bool PermissionVerification::IsSACall() const -{ - return (MyFlag::flag_ & MyFlag::FLAG::IS_SA_CALL); -} -bool PermissionVerification::IsShellCall() const -{ - return (MyFlag::flag_ & MyFlag::FLAG::IS_SHELL_CALL); -} -bool PermissionVerification::CheckSpecificSystemAbilityAccessPermission() const -{ - return !!(MyFlag::flag_); -} -bool PermissionVerification::VerifyRunningInfoPerm() const -{ - return !!(MyFlag::flag_); -} -bool PermissionVerification::VerifyControllerPerm() const -{ - return !!(MyFlag::flag_); -} -bool PermissionVerification::VerifyDlpPermission(Want &want) const -{ - return !!(MyFlag::flag_); -} -int PermissionVerification::VerifyAccountPermission() const -{ - return MyFlag::flag_; -} -bool PermissionVerification::VerifyMissionPermission() const -{ - return !!(MyFlag::flag_); -} -int PermissionVerification::VerifyAppStateObserverPermission() const -{ - return MyFlag::flag_; -} -int32_t PermissionVerification::VerifyUpdateConfigurationPerm() const -{ - return static_cast(MyFlag::flag_); -} -bool PermissionVerification::VerifyInstallBundlePermission() const -{ - return !!(MyFlag::flag_); -} -bool PermissionVerification::VerifyGetBundleInfoPrivilegedPermission() const -{ - return !!(MyFlag::flag_); -} -int PermissionVerification::CheckCallDataAbilityPermission(const VerificationInfo &verificationInfo, bool isShell) const -{ - return MyFlag::flag_; -} -int PermissionVerification::CheckCallServiceAbilityPermission(const VerificationInfo &verificationInfo) const -{ - return MyFlag::flag_; -} -int PermissionVerification::CheckCallAbilityPermission(const VerificationInfo &verificationInfo) const -{ - return MyFlag::flag_; -} -int PermissionVerification::CheckCallServiceExtensionPermission(const VerificationInfo &verificationInfo) const -{ - return MyFlag::flag_; -} -int PermissionVerification::CheckStartByCallPermission(const VerificationInfo &verificationInfo) const -{ - return MyFlag::flag_; -} -unsigned int PermissionVerification::GetCallingTokenID() const -{ - return static_cast(MyFlag::flag_); -} -bool PermissionVerification::JudgeStartInvisibleAbility(const uint32_t accessTokenId, const bool visible) const -{ - return !!(MyFlag::flag_); -} -bool PermissionVerification::JudgeStartAbilityFromBackground(const bool isBackgroundCall) const -{ - return !!(MyFlag::flag_); -} -bool PermissionVerification::JudgeAssociatedWakeUp(const uint32_t accessTokenId, const bool associatedWakeUp) const -{ - return !!(MyFlag::flag_); -} -int PermissionVerification::JudgeInvisibleAndBackground(const VerificationInfo &verificationInfo) const -{ - return MyFlag::flag_; -} -bool PermissionVerification::JudgeCallerIsAllowedToUseSystemAPI() const -{ - return true; -} -bool PermissionVerification::IsSystemAppCall() const -{ - return !!(MyFlag::flag_); -} -} // namespace AAFwk -} // namespace OHOS -- Gitee