5959#include < vector>
6060
6161#include < aidl/android/hardware/dumpstate/IDumpstateDevice.h>
62+ #include < android_app_admin_flags.h>
6263#include < android-base/file.h>
6364#include < android-base/properties.h>
6465#include < android-base/scopeguard.h>
@@ -1088,8 +1089,14 @@ static void MaybeAddSystemTraceToZip() {
10881089 // This function copies into the .zip the system trace that was snapshotted
10891090 // by the early call to MaybeSnapshotSystemTrace(), if any background
10901091 // tracing was happening.
1091- if (!ds.has_system_trace_ ) {
1092- // No background trace was happening at the time dumpstate was invoked.
1092+ bool system_trace_exists = access (SYSTEM_TRACE_SNAPSHOT, F_OK) == 0 ;
1093+ if (!system_trace_exists) {
1094+ // No background trace was happening at the time MaybeSnapshotSystemTrace() was invoked.
1095+ if (!PropertiesHelper::IsUserBuild ()) {
1096+ MYLOGI (
1097+ " No system traces found. Check for previously uploaded traces by looking for "
1098+ " go/trace-uuid in logcat" )
1099+ }
10931100 return ;
10941101 }
10951102 ds.AddZipEntry (
@@ -1653,8 +1660,6 @@ Dumpstate::RunStatus Dumpstate::dumpstate() {
16531660 dump_board = ds.dump_pool_ ->enqueueTaskWithFd (
16541661 DUMP_BOARD_TASK, &Dumpstate::DumpstateBoard, &ds, _1);
16551662 dump_checkins = ds.dump_pool_ ->enqueueTaskWithFd (DUMP_CHECKINS_TASK, &DumpCheckins, _1);
1656- post_process_ui_traces = ds.dump_pool_ ->enqueueTask (
1657- POST_PROCESS_UI_TRACES_TASK, &Dumpstate::MaybePostProcessUiTraces, &ds);
16581663 }
16591664
16601665 // Dump various things. Note that anything that takes "long" (i.e. several seconds) should
@@ -1864,12 +1869,6 @@ Dumpstate::RunStatus Dumpstate::dumpstate() {
18641869 DumpIncidentReport);
18651870 }
18661871
1867- if (ds.dump_pool_ ) {
1868- WaitForTask (std::move (post_process_ui_traces));
1869- } else {
1870- RUN_SLOW_FUNCTION_AND_LOG (POST_PROCESS_UI_TRACES_TASK, MaybePostProcessUiTraces);
1871- }
1872-
18731872 MaybeAddUiTracesToZip ();
18741873
18751874 return Dumpstate::RunStatus::OK;
@@ -2178,6 +2177,11 @@ static void DumpstateWifiOnly() {
21782177 printf (" ========================================================\n " );
21792178}
21802179
2180+ // Collects a lightweight dumpstate to be used for debugging onboarding related flows.
2181+ static void DumpstateOnboardingOnly () {
2182+ ds.AddDir (LOGPERSIST_DATA_DIR, false );
2183+ }
2184+
21812185Dumpstate::RunStatus Dumpstate::DumpTraces (const char ** path) {
21822186 const std::string temp_file_pattern = ds.bugreport_internal_dir_ + " /dumptrace_XXXXXX" ;
21832187 const size_t buf_size = temp_file_pattern.length () + 1 ;
@@ -2310,6 +2314,7 @@ static dumpstate_hal_hidl::DumpstateMode GetDumpstateHalModeHidl(
23102314 return dumpstate_hal_hidl::DumpstateMode::CONNECTIVITY;
23112315 case Dumpstate::BugreportMode::BUGREPORT_WIFI:
23122316 return dumpstate_hal_hidl::DumpstateMode::WIFI;
2317+ case Dumpstate::BugreportMode::BUGREPORT_ONBOARDING:
23132318 case Dumpstate::BugreportMode::BUGREPORT_DEFAULT:
23142319 return dumpstate_hal_hidl::DumpstateMode::DEFAULT;
23152320 }
@@ -2331,6 +2336,7 @@ static dumpstate_hal_aidl::IDumpstateDevice::DumpstateMode GetDumpstateHalModeAi
23312336 return dumpstate_hal_aidl::IDumpstateDevice::DumpstateMode::CONNECTIVITY;
23322337 case Dumpstate::BugreportMode::BUGREPORT_WIFI:
23332338 return dumpstate_hal_aidl::IDumpstateDevice::DumpstateMode::WIFI;
2339+ case Dumpstate::BugreportMode::BUGREPORT_ONBOARDING:
23342340 case Dumpstate::BugreportMode::BUGREPORT_DEFAULT:
23352341 return dumpstate_hal_aidl::IDumpstateDevice::DumpstateMode::DEFAULT;
23362342 }
@@ -2814,6 +2820,8 @@ static inline const char* ModeToString(Dumpstate::BugreportMode mode) {
28142820 return " BUGREPORT_TELEPHONY" ;
28152821 case Dumpstate::BugreportMode::BUGREPORT_WIFI:
28162822 return " BUGREPORT_WIFI" ;
2823+ case Dumpstate::BugreportMode::BUGREPORT_ONBOARDING:
2824+ return " BUGREPORT_ONBOARDING" ;
28172825 case Dumpstate::BugreportMode::BUGREPORT_DEFAULT:
28182826 return " BUGREPORT_DEFAULT" ;
28192827 }
@@ -2859,6 +2867,10 @@ static void SetOptionsFromMode(Dumpstate::BugreportMode mode, Dumpstate::DumpOpt
28592867 options->wifi_only = true ;
28602868 options->do_screenshot = false ;
28612869 break ;
2870+ case Dumpstate::BugreportMode::BUGREPORT_ONBOARDING:
2871+ options->onboarding_only = true ;
2872+ options->do_screenshot = false ;
2873+ break ;
28622874 case Dumpstate::BugreportMode::BUGREPORT_DEFAULT:
28632875 break ;
28642876 }
@@ -2971,14 +2983,17 @@ Dumpstate::RunStatus Dumpstate::Run(int32_t calling_uid, const std::string& call
29712983 return status;
29722984}
29732985
2974- Dumpstate::RunStatus Dumpstate::Retrieve (int32_t calling_uid, const std::string& calling_package) {
2975- Dumpstate::RunStatus status = RetrieveInternal (calling_uid, calling_package);
2986+ Dumpstate::RunStatus Dumpstate::Retrieve (int32_t calling_uid, const std::string& calling_package,
2987+ const bool keep_bugreport_on_retrieval) {
2988+ Dumpstate::RunStatus status = RetrieveInternal (calling_uid, calling_package,
2989+ keep_bugreport_on_retrieval);
29762990 HandleRunStatus (status);
29772991 return status;
29782992}
29792993
29802994Dumpstate::RunStatus Dumpstate::RetrieveInternal (int32_t calling_uid,
2981- const std::string& calling_package) {
2995+ const std::string& calling_package,
2996+ const bool keep_bugreport_on_retrieval) {
29822997 consent_callback_ = new ConsentCallback ();
29832998 const String16 incidentcompanion (" incidentcompanion" );
29842999 sp<android::IBinder> ics (
@@ -3013,9 +3028,12 @@ Dumpstate::RunStatus Dumpstate::RetrieveInternal(int32_t calling_uid,
30133028
30143029 bool copy_succeeded =
30153030 android::os::CopyFileToFd (path_, options_->bugreport_fd .get ());
3016- if (copy_succeeded) {
3017- android::os::UnlinkAndLogOnError (path_);
3031+
3032+ if (copy_succeeded && (!android::app::admin::flags::onboarding_bugreport_v2_enabled ()
3033+ || !keep_bugreport_on_retrieval)) {
3034+ android::os::UnlinkAndLogOnError (path_);
30183035 }
3036+
30193037 return copy_succeeded ? Dumpstate::RunStatus::OK
30203038 : Dumpstate::RunStatus::ERROR;
30213039}
@@ -3066,6 +3084,7 @@ void Dumpstate::Cancel() {
30663084}
30673085
30683086void Dumpstate::PreDumpUiData () {
3087+ MaybeSnapshotSystemTrace ();
30693088 MaybeSnapshotUiTraces ();
30703089}
30713090
@@ -3252,25 +3271,23 @@ Dumpstate::RunStatus Dumpstate::RunInternal(int32_t calling_uid,
32523271 // duration is logged into MYLOG instead.
32533272 PrintHeader ();
32543273
3255- bool is_dumpstate_restricted = options_->telephony_only
3256- || options_->wifi_only
3257- || options_->limited_only ;
3258- if (!is_dumpstate_restricted) {
3259- // Invoke critical dumpsys first to preserve system state, before doing anything else.
3260- RunDumpsysCritical ();
3261- }
3262- MaybeTakeEarlyScreenshot ();
3263-
3274+ bool is_dumpstate_restricted =
3275+ options_->telephony_only || options_->wifi_only || options_->limited_only ;
32643276 if (!is_dumpstate_restricted) {
32653277 // Snapshot the system trace now (if running) to avoid that dumpstate's
32663278 // own activity pushes out interesting data from the trace ring buffer.
32673279 // The trace file is added to the zip by MaybeAddSystemTraceToZip().
32683280 MaybeSnapshotSystemTrace ();
32693281
3282+ // Invoke critical dumpsys to preserve system state, before doing anything else.
3283+ RunDumpsysCritical ();
3284+
32703285 // Snapshot the UI traces now (if running).
32713286 // The trace files will be added to bugreport later.
32723287 MaybeSnapshotUiTraces ();
32733288 }
3289+
3290+ MaybeTakeEarlyScreenshot ();
32743291 onUiIntensiveBugreportDumpsFinished (calling_uid);
32753292 MaybeCheckUserConsent (calling_uid, calling_package);
32763293 if (options_->telephony_only ) {
@@ -3279,6 +3296,8 @@ Dumpstate::RunStatus Dumpstate::RunInternal(int32_t calling_uid,
32793296 DumpstateWifiOnly ();
32803297 } else if (options_->limited_only ) {
32813298 DumpstateLimitedOnly ();
3299+ } else if (options_->onboarding_only ) {
3300+ DumpstateOnboardingOnly ();
32823301 } else {
32833302 // Dump state for the default case. This also drops root.
32843303 RunStatus s = DumpstateDefaultAfterCritical ();
@@ -3366,21 +3385,28 @@ void Dumpstate::MaybeTakeEarlyScreenshot() {
33663385}
33673386
33683387void Dumpstate::MaybeSnapshotSystemTrace () {
3388+ // When capturing traces via bugreport handler (BH), this function will be invoked twice:
3389+ // 1) When BH invokes IDumpstate::PreDumpUiData()
3390+ // 2) When BH invokes IDumpstate::startBugreport(flags = BUGREPORT_USE_PREDUMPED_UI_DATA)
3391+ // In this case we don't want to re-invoke perfetto in step 2.
3392+ // In all other standard invocation states, this function is invoked once
3393+ // without the flag BUGREPORT_USE_PREDUMPED_UI_DATA.
3394+ if (options_->use_predumped_ui_data ) {
3395+ return ;
3396+ }
3397+
3398+ // If a stale file exists already, remove it.
3399+ unlink (SYSTEM_TRACE_SNAPSHOT);
3400+
33693401 // If a background system trace is happening and is marked as "suitable for
33703402 // bugreport" (i.e. bugreport_score > 0 in the trace config), this command
33713403 // will stop it and serialize into SYSTEM_TRACE_SNAPSHOT. In the (likely)
33723404 // case that no trace is ongoing, this command is a no-op.
33733405 // Note: this should not be enqueued as we need to freeze the trace before
33743406 // dumpstate starts. Otherwise the trace ring buffers will contain mostly
33753407 // the dumpstate's own activity which is irrelevant.
3376- int res = RunCommand (
3377- " SERIALIZE PERFETTO TRACE" ,
3378- {" perfetto" , " --save-for-bugreport" },
3379- CommandOptions::WithTimeout (10 )
3380- .DropRoot ()
3381- .CloseAllFileDescriptorsOnExec ()
3382- .Build ());
3383- has_system_trace_ = res == 0 ;
3408+ RunCommand (" SERIALIZE PERFETTO TRACE" , {" perfetto" , " --save-for-bugreport" },
3409+ CommandOptions::WithTimeout (10 ).DropRoot ().CloseAllFileDescriptorsOnExec ().Build ());
33843410 // MaybeAddSystemTraceToZip() will take care of copying the trace in the zip
33853411 // file in the later stages.
33863412}
@@ -3407,33 +3433,6 @@ void Dumpstate::MaybeSnapshotUiTraces() {
34073433 " " , command,
34083434 CommandOptions::WithTimeout (10 ).Always ().DropRoot ().RedirectStderr ().Build ());
34093435 }
3410-
3411- // This command needs to be run as root
3412- static const auto SURFACEFLINGER_COMMAND_SAVE_ALL_TRACES = std::vector<std::string> {
3413- " service" , " call" , " SurfaceFlinger" , " 1042"
3414- };
3415- // Empty name because it's not intended to be classified as a bugreport section.
3416- // Actual tracing files can be found in "/data/misc/wmtrace/" in the bugreport.
3417- RunCommand (
3418- " " , SURFACEFLINGER_COMMAND_SAVE_ALL_TRACES,
3419- CommandOptions::WithTimeout (10 ).Always ().AsRoot ().RedirectStderr ().Build ());
3420- }
3421-
3422- void Dumpstate::MaybePostProcessUiTraces () {
3423- if (PropertiesHelper::IsUserBuild ()) {
3424- return ;
3425- }
3426-
3427- RunCommand (
3428- // Empty name because it's not intended to be classified as a bugreport section.
3429- // Actual tracing files can be found in "/data/misc/wmtrace/" in the bugreport.
3430- " " , {
3431- " /system/xbin/su" , " system" ,
3432- " /system/bin/layertracegenerator" ,
3433- " /data/misc/wmtrace/transactions_trace.winscope" ,
3434- " /data/misc/wmtrace/layers_trace_from_transactions.winscope"
3435- },
3436- CommandOptions::WithTimeout (120 ).Always ().RedirectStderr ().Build ());
34373436}
34383437
34393438void Dumpstate::MaybeAddUiTracesToZip () {
0 commit comments