From c5e467d23e15a93e9edfa6c2b2627cfb059d8e8e Mon Sep 17 00:00:00 2001 From: hongtao Date: Thu, 13 Apr 2023 15:57:48 +0800 Subject: [PATCH] Feature: add Startup Debugging, add parameters -N for aa Signed-off-by: hongtao Change-Id: I8de454acb3653eaeb87d9fc49af0fba7a8bf4134 --- services/abilitymgr/src/ability_record.cpp | 11 ++++++----- services/appmgr/include/app_running_record.h | 2 ++ services/appmgr/include/app_spawn_msg_wrapper.h | 1 + services/appmgr/src/app_mgr_service_inner.cpp | 4 ++++ services/appmgr/src/app_running_record.cpp | 8 +++++++- tools/aa/include/ability_command.h | 2 +- tools/aa/src/ability_command.cpp | 12 +++++++++++- 7 files changed, 32 insertions(+), 8 deletions(-) diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 5230c4d488..b3e9340101 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -50,6 +50,7 @@ namespace OHOS { namespace AAFwk { using namespace OHOS::Security; const std::string DEBUG_APP = "debugApp"; +const std::string NATIVE_DEBUG = "nativeDebug"; const std::string DMS_PROCESS_NAME = "distributedsched"; const std::string DMS_MISSION_ID = "dmsMissionId"; const std::string DMS_SRC_NETWORK_ID = "dmsSrcNetworkId"; @@ -673,7 +674,7 @@ void AbilityRecord::StartingWindowTask(bool isRecent, bool isCold, const Ability void AbilityRecord::PostCancelStartingWindowHotTask() { - if (want_.GetBoolParam(DEBUG_APP, false)) { + if (want_.GetBoolParam(DEBUG_APP, false) || want_.GetBoolParam(NATIVE_DEBUG, false)) { HILOG_INFO("PostCancelStartingWindowHotTask was called, debug mode, just return."); return; } @@ -701,7 +702,7 @@ void AbilityRecord::PostCancelStartingWindowHotTask() void AbilityRecord::PostCancelStartingWindowColdTask() { - if (want_.GetBoolParam(DEBUG_APP, false)) { + if (want_.GetBoolParam(DEBUG_APP, false) || want_.GetBoolParam(NATIVE_DEBUG, false)) { HILOG_INFO("PostCancelStartingWindowColdTask was called, debug mode, just return."); return; } @@ -985,7 +986,7 @@ void AbilityRecord::BackgroundAbility(const Closure &task) } auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); if (handler && task) { - if (!want_.GetBoolParam(DEBUG_APP, false)) { + if (!want_.GetBoolParam(DEBUG_APP, false) && !want_.GetBoolParam(NATIVE_DEBUG, false)) { int backgroundTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * BACKGROUND_TIMEOUT_MULTIPLE; handler->PostTask(task, "background_" + std::to_string(recordId_), backgroundTimeout); @@ -1216,7 +1217,7 @@ void AbilityRecord::Terminate(const Closure &task) CHECK_POINTER(lifecycleDeal_); auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); if (handler && task) { - if (!want_.GetBoolParam(DEBUG_APP, false)) { + if (!want_.GetBoolParam(DEBUG_APP, false) && !want_.GetBoolParam(NATIVE_DEBUG, false)) { int terminateTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * TERMINATE_TIMEOUT_MULTIPLE; handler->PostTask(task, "terminate_" + std::to_string(recordId_), terminateTimeout); @@ -1914,7 +1915,7 @@ bool AbilityRecord::IsActiveState() const void AbilityRecord::SendEvent(uint32_t msg, uint32_t timeOut, int32_t param) { - if (want_.GetBoolParam(DEBUG_APP, false)) { + if (want_.GetBoolParam(DEBUG_APP, false) || want_.GetBoolParam(NATIVE_DEBUG, false)) { HILOG_INFO("Is debug mode, no need to handle time out."); return; } diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index 10e442273d..54e782201b 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -550,6 +550,7 @@ public: const AAFwk::Want &GetSpecifiedWant() const; void SetDebugApp(bool isDebugApp); bool IsDebugApp(); + void SetNativeDebug(bool isNativeDebug); void SetRenderRecord(const std::shared_ptr &record); std::shared_ptr GetRenderRecord(); void SetStartMsg(const AppSpawnStartMsg &msg); @@ -694,6 +695,7 @@ private: AAFwk::Want SpecifiedWant_; std::string moduleName_; bool isDebugApp_ = false; + bool isNativeDebug_ = false; int64_t startTimeMillis_ = 0; // The time of app start(CLOCK_MONOTONIC) int64_t restartTimeMillis_ = 0; // The time of last trying app restart diff --git a/services/appmgr/include/app_spawn_msg_wrapper.h b/services/appmgr/include/app_spawn_msg_wrapper.h index d5dd4a9ff8..3b279304c8 100644 --- a/services/appmgr/include/app_spawn_msg_wrapper.h +++ b/services/appmgr/include/app_spawn_msg_wrapper.h @@ -59,6 +59,7 @@ struct StartFlags { static const int DLP_MANAGER = 2; static const int DEBUGGABLE = 3; static const int ASANENABLED = 4; + static const int NATIVEDEBUG = 6; }; union AppSpawnPidMsg { diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 00cff0b87a..7b9d3396af 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -1051,6 +1051,7 @@ std::shared_ptr AppMgrServiceInner::CreateAppRunningRecord(con appRecord->AddModule(appInfo, abilityInfo, token, hapModuleInfo, want); if (want) { appRecord->SetDebugApp(want->GetBoolParam("debugApp", false)); + appRecord->SetNativeDebug(want->GetBoolParam("nativeDebug", false)); if (want->GetBoolParam(COLD_START, false)) { appRecord->SetDebugApp(true); } @@ -3221,6 +3222,9 @@ uint32_t AppMgrServiceInner::BuildStartFlags(const AAFwk::Want &want, const Abil if (abilityInfo.applicationInfo.asanEnabled) { startFlags = startFlags | (AppSpawn::ClientSocket::APPSPAWN_COLD_BOOT << StartFlags::ASANENABLED); } + if (want.GetBoolParam("nativeDebug", false)) { + startFlags = startFlags | (AppSpawn::ClientSocket::APPSPAWN_COLD_BOOT << StartFlags::NATIVEDEBUG); + } return startFlags; } diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index d54bb679b6..90d35f096f 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -1053,7 +1053,7 @@ void AppRunningRecord::SendEvent(uint32_t msg, int64_t timeOut) return; } - if (isDebugApp_) { + if (isDebugApp_ || isNativeDebug_) { HILOG_INFO("Is debug mode, no need to handle time out."); return; } @@ -1334,6 +1334,12 @@ bool AppRunningRecord::IsDebugApp() return isDebugApp_; } +void AppRunningRecord::SetNativeDebug(bool isNativeDebug) +{ + HILOG_INFO("SetNativeDebug, value is %{public}d", isNativeDebug); + isNativeDebug_ = isNativeDebug; +} + void AppRunningRecord::SetAppIndex(const int32_t appIndex) { appIndex_ = appIndex; diff --git a/tools/aa/include/ability_command.h b/tools/aa/include/ability_command.h index 473bb2d4c5..b33a1ad177 100644 --- a/tools/aa/include/ability_command.h +++ b/tools/aa/include/ability_command.h @@ -58,7 +58,7 @@ const std::string HELP_MSG_START = "usage: aa start \n" "options list:\n" " -h, --help list available commands\n" - " [-d ] -a -b [-m ] [-p ] [-D] [-S] " + " [-d ] -a -b [-m ] [-p ] [-D] [-S] [-N] " " start ability with an element name\n"; const std::string HELP_MSG_STOP_SERVICE = diff --git a/tools/aa/src/ability_command.cpp b/tools/aa/src/ability_command.cpp index bfb0b4a30f..82332bf9c7 100644 --- a/tools/aa/src/ability_command.cpp +++ b/tools/aa/src/ability_command.cpp @@ -35,7 +35,7 @@ namespace AAFwk { namespace { size_t paramLength = 1024; -const std::string SHORT_OPTIONS = "ch:d:a:b:p:s:m:CDS"; +const std::string SHORT_OPTIONS = "ch:d:a:b:p:s:m:CDSN"; constexpr struct option LONG_OPTIONS[] = { {"help", no_argument, nullptr, 'h'}, {"device", required_argument, nullptr, 'd'}, @@ -46,6 +46,7 @@ constexpr struct option LONG_OPTIONS[] = { {"module", required_argument, nullptr, 'm'}, {"cold-start", no_argument, nullptr, 'C'}, {"debug", no_argument, nullptr, 'D'}, + {"native-debug", no_argument, nullptr, 'N'}, {nullptr, 0, nullptr, 0}, }; const std::string SHORT_OPTIONS_APPLICATION_NOT_RESPONDING = "hp:"; @@ -940,6 +941,7 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win bool isDebugApp = false; bool isContinuation = false; bool isSanboxApp = false; + bool isNativeDebug = false; while (true) { counter++; @@ -1159,6 +1161,11 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win isContinuation = true; break; } + case 'N': { + // 'aa start -N' + // wait for debug in appspawn + isNativeDebug = true; + } case 0: { break; } @@ -1202,6 +1209,9 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win if (isSanboxApp) { want.SetParam("sanboxApp", isSanboxApp); } + if (isNativeDebug) { + want.SetParam("nativeDebug", isNativeDebug); + } } }