diff options
Diffstat (limited to 'cmds/dumpstate/dumpstate.cpp')
-rw-r--r-- | cmds/dumpstate/dumpstate.cpp | 117 |
1 files changed, 58 insertions, 59 deletions
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp index 326f927862..befb5d4b5b 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -59,6 +59,7 @@ #include <vector> #include <aidl/android/hardware/dumpstate/IDumpstateDevice.h> +#include <android_app_admin_flags.h> #include <android-base/file.h> #include <android-base/properties.h> #include <android-base/scopeguard.h> @@ -1088,8 +1089,14 @@ static void MaybeAddSystemTraceToZip() { // This function copies into the .zip the system trace that was snapshotted // by the early call to MaybeSnapshotSystemTrace(), if any background // tracing was happening. - if (!ds.has_system_trace_) { - // No background trace was happening at the time dumpstate was invoked. + bool system_trace_exists = access(SYSTEM_TRACE_SNAPSHOT, F_OK) == 0; + if (!system_trace_exists) { + // No background trace was happening at the time MaybeSnapshotSystemTrace() was invoked. + if (!PropertiesHelper::IsUserBuild()) { + MYLOGI( + "No system traces found. Check for previously uploaded traces by looking for " + "go/trace-uuid in logcat") + } return; } ds.AddZipEntry( @@ -1653,8 +1660,6 @@ Dumpstate::RunStatus Dumpstate::dumpstate() { dump_board = ds.dump_pool_->enqueueTaskWithFd( DUMP_BOARD_TASK, &Dumpstate::DumpstateBoard, &ds, _1); dump_checkins = ds.dump_pool_->enqueueTaskWithFd(DUMP_CHECKINS_TASK, &DumpCheckins, _1); - post_process_ui_traces = ds.dump_pool_->enqueueTask( - POST_PROCESS_UI_TRACES_TASK, &Dumpstate::MaybePostProcessUiTraces, &ds); } // Dump various things. Note that anything that takes "long" (i.e. several seconds) should @@ -1864,12 +1869,6 @@ Dumpstate::RunStatus Dumpstate::dumpstate() { DumpIncidentReport); } - if (ds.dump_pool_) { - WaitForTask(std::move(post_process_ui_traces)); - } else { - RUN_SLOW_FUNCTION_AND_LOG(POST_PROCESS_UI_TRACES_TASK, MaybePostProcessUiTraces); - } - MaybeAddUiTracesToZip(); return Dumpstate::RunStatus::OK; @@ -2178,6 +2177,11 @@ static void DumpstateWifiOnly() { printf("========================================================\n"); } +// Collects a lightweight dumpstate to be used for debugging onboarding related flows. +static void DumpstateOnboardingOnly() { + ds.AddDir(LOGPERSIST_DATA_DIR, false); +} + Dumpstate::RunStatus Dumpstate::DumpTraces(const char** path) { const std::string temp_file_pattern = ds.bugreport_internal_dir_ + "/dumptrace_XXXXXX"; const size_t buf_size = temp_file_pattern.length() + 1; @@ -2310,6 +2314,7 @@ static dumpstate_hal_hidl::DumpstateMode GetDumpstateHalModeHidl( return dumpstate_hal_hidl::DumpstateMode::CONNECTIVITY; case Dumpstate::BugreportMode::BUGREPORT_WIFI: return dumpstate_hal_hidl::DumpstateMode::WIFI; + case Dumpstate::BugreportMode::BUGREPORT_ONBOARDING: case Dumpstate::BugreportMode::BUGREPORT_DEFAULT: return dumpstate_hal_hidl::DumpstateMode::DEFAULT; } @@ -2331,6 +2336,7 @@ static dumpstate_hal_aidl::IDumpstateDevice::DumpstateMode GetDumpstateHalModeAi return dumpstate_hal_aidl::IDumpstateDevice::DumpstateMode::CONNECTIVITY; case Dumpstate::BugreportMode::BUGREPORT_WIFI: return dumpstate_hal_aidl::IDumpstateDevice::DumpstateMode::WIFI; + case Dumpstate::BugreportMode::BUGREPORT_ONBOARDING: case Dumpstate::BugreportMode::BUGREPORT_DEFAULT: return dumpstate_hal_aidl::IDumpstateDevice::DumpstateMode::DEFAULT; } @@ -2814,6 +2820,8 @@ static inline const char* ModeToString(Dumpstate::BugreportMode mode) { return "BUGREPORT_TELEPHONY"; case Dumpstate::BugreportMode::BUGREPORT_WIFI: return "BUGREPORT_WIFI"; + case Dumpstate::BugreportMode::BUGREPORT_ONBOARDING: + return "BUGREPORT_ONBOARDING"; case Dumpstate::BugreportMode::BUGREPORT_DEFAULT: return "BUGREPORT_DEFAULT"; } @@ -2859,6 +2867,10 @@ static void SetOptionsFromMode(Dumpstate::BugreportMode mode, Dumpstate::DumpOpt options->wifi_only = true; options->do_screenshot = false; break; + case Dumpstate::BugreportMode::BUGREPORT_ONBOARDING: + options->onboarding_only = true; + options->do_screenshot = false; + break; case Dumpstate::BugreportMode::BUGREPORT_DEFAULT: break; } @@ -2971,14 +2983,17 @@ Dumpstate::RunStatus Dumpstate::Run(int32_t calling_uid, const std::string& call return status; } -Dumpstate::RunStatus Dumpstate::Retrieve(int32_t calling_uid, const std::string& calling_package) { - Dumpstate::RunStatus status = RetrieveInternal(calling_uid, calling_package); +Dumpstate::RunStatus Dumpstate::Retrieve(int32_t calling_uid, const std::string& calling_package, + const bool keep_bugreport_on_retrieval) { + Dumpstate::RunStatus status = RetrieveInternal(calling_uid, calling_package, + keep_bugreport_on_retrieval); HandleRunStatus(status); return status; } Dumpstate::RunStatus Dumpstate::RetrieveInternal(int32_t calling_uid, - const std::string& calling_package) { + const std::string& calling_package, + const bool keep_bugreport_on_retrieval) { consent_callback_ = new ConsentCallback(); const String16 incidentcompanion("incidentcompanion"); sp<android::IBinder> ics( @@ -3013,9 +3028,12 @@ Dumpstate::RunStatus Dumpstate::RetrieveInternal(int32_t calling_uid, bool copy_succeeded = android::os::CopyFileToFd(path_, options_->bugreport_fd.get()); - if (copy_succeeded) { - android::os::UnlinkAndLogOnError(path_); + + if (copy_succeeded && (!android::app::admin::flags::onboarding_bugreport_v2_enabled() + || !keep_bugreport_on_retrieval)) { + android::os::UnlinkAndLogOnError(path_); } + return copy_succeeded ? Dumpstate::RunStatus::OK : Dumpstate::RunStatus::ERROR; } @@ -3066,6 +3084,7 @@ void Dumpstate::Cancel() { } void Dumpstate::PreDumpUiData() { + MaybeSnapshotSystemTrace(); MaybeSnapshotUiTraces(); } @@ -3252,25 +3271,23 @@ Dumpstate::RunStatus Dumpstate::RunInternal(int32_t calling_uid, // duration is logged into MYLOG instead. PrintHeader(); - bool is_dumpstate_restricted = options_->telephony_only - || options_->wifi_only - || options_->limited_only; - if (!is_dumpstate_restricted) { - // Invoke critical dumpsys first to preserve system state, before doing anything else. - RunDumpsysCritical(); - } - MaybeTakeEarlyScreenshot(); - + bool is_dumpstate_restricted = + options_->telephony_only || options_->wifi_only || options_->limited_only; if (!is_dumpstate_restricted) { // Snapshot the system trace now (if running) to avoid that dumpstate's // own activity pushes out interesting data from the trace ring buffer. // The trace file is added to the zip by MaybeAddSystemTraceToZip(). MaybeSnapshotSystemTrace(); + // Invoke critical dumpsys to preserve system state, before doing anything else. + RunDumpsysCritical(); + // Snapshot the UI traces now (if running). // The trace files will be added to bugreport later. MaybeSnapshotUiTraces(); } + + MaybeTakeEarlyScreenshot(); onUiIntensiveBugreportDumpsFinished(calling_uid); MaybeCheckUserConsent(calling_uid, calling_package); if (options_->telephony_only) { @@ -3279,6 +3296,8 @@ Dumpstate::RunStatus Dumpstate::RunInternal(int32_t calling_uid, DumpstateWifiOnly(); } else if (options_->limited_only) { DumpstateLimitedOnly(); + } else if (options_->onboarding_only) { + DumpstateOnboardingOnly(); } else { // Dump state for the default case. This also drops root. RunStatus s = DumpstateDefaultAfterCritical(); @@ -3366,6 +3385,19 @@ void Dumpstate::MaybeTakeEarlyScreenshot() { } void Dumpstate::MaybeSnapshotSystemTrace() { + // When capturing traces via bugreport handler (BH), this function will be invoked twice: + // 1) When BH invokes IDumpstate::PreDumpUiData() + // 2) When BH invokes IDumpstate::startBugreport(flags = BUGREPORT_USE_PREDUMPED_UI_DATA) + // In this case we don't want to re-invoke perfetto in step 2. + // In all other standard invocation states, this function is invoked once + // without the flag BUGREPORT_USE_PREDUMPED_UI_DATA. + if (options_->use_predumped_ui_data) { + return; + } + + // If a stale file exists already, remove it. + unlink(SYSTEM_TRACE_SNAPSHOT); + // If a background system trace is happening and is marked as "suitable for // bugreport" (i.e. bugreport_score > 0 in the trace config), this command // will stop it and serialize into SYSTEM_TRACE_SNAPSHOT. In the (likely) @@ -3373,14 +3405,8 @@ void Dumpstate::MaybeSnapshotSystemTrace() { // Note: this should not be enqueued as we need to freeze the trace before // dumpstate starts. Otherwise the trace ring buffers will contain mostly // the dumpstate's own activity which is irrelevant. - int res = RunCommand( - "SERIALIZE PERFETTO TRACE", - {"perfetto", "--save-for-bugreport"}, - CommandOptions::WithTimeout(10) - .DropRoot() - .CloseAllFileDescriptorsOnExec() - .Build()); - has_system_trace_ = res == 0; + RunCommand("SERIALIZE PERFETTO TRACE", {"perfetto", "--save-for-bugreport"}, + CommandOptions::WithTimeout(10).DropRoot().CloseAllFileDescriptorsOnExec().Build()); // MaybeAddSystemTraceToZip() will take care of copying the trace in the zip // file in the later stages. } @@ -3407,33 +3433,6 @@ void Dumpstate::MaybeSnapshotUiTraces() { "", command, CommandOptions::WithTimeout(10).Always().DropRoot().RedirectStderr().Build()); } - - // This command needs to be run as root - static const auto SURFACEFLINGER_COMMAND_SAVE_ALL_TRACES = std::vector<std::string> { - "service", "call", "SurfaceFlinger", "1042" - }; - // Empty name because it's not intended to be classified as a bugreport section. - // Actual tracing files can be found in "/data/misc/wmtrace/" in the bugreport. - RunCommand( - "", SURFACEFLINGER_COMMAND_SAVE_ALL_TRACES, - CommandOptions::WithTimeout(10).Always().AsRoot().RedirectStderr().Build()); -} - -void Dumpstate::MaybePostProcessUiTraces() { - if (PropertiesHelper::IsUserBuild()) { - return; - } - - RunCommand( - // Empty name because it's not intended to be classified as a bugreport section. - // Actual tracing files can be found in "/data/misc/wmtrace/" in the bugreport. - "", { - "/system/xbin/su", "system", - "/system/bin/layertracegenerator", - "/data/misc/wmtrace/transactions_trace.winscope", - "/data/misc/wmtrace/layers_trace_from_transactions.winscope" - }, - CommandOptions::WithTimeout(120).Always().RedirectStderr().Build()); } void Dumpstate::MaybeAddUiTracesToZip() { |