@@ -1570,6 +1570,7 @@ static void DumpstateLimitedOnly() {
15701570 printf (" == ANR Traces\n " );
15711571 printf (" ========================================================\n " );
15721572
1573+ ds.anr_data_ = GetDumpFds (ANR_DIR, ANR_FILE_PREFIX);
15731574 AddAnrTraceFiles ();
15741575
15751576 printf (" ========================================================\n " );
@@ -2979,9 +2980,11 @@ void Dumpstate::DumpOptions::Initialize(BugreportMode bugreport_mode,
29792980 int bugreport_flags,
29802981 const android::base::unique_fd& bugreport_fd_in,
29812982 const android::base::unique_fd& screenshot_fd_in,
2982- bool is_screenshot_requested) {
2983+ bool is_screenshot_requested,
2984+ bool skip_user_consent) {
29832985 this ->use_predumped_ui_data = bugreport_flags & BugreportFlag::BUGREPORT_USE_PREDUMPED_UI_DATA;
29842986 this ->is_consent_deferred = bugreport_flags & BugreportFlag::BUGREPORT_FLAG_DEFER_CONSENT;
2987+ this ->skip_user_consent = skip_user_consent;
29852988 // Duplicate the fds because the passed in fds don't outlive the binder transaction.
29862989 bugreport_fd.reset (fcntl (bugreport_fd_in.get (), F_DUPFD_CLOEXEC, 0 ));
29872990 screenshot_fd.reset (fcntl (screenshot_fd_in.get (), F_DUPFD_CLOEXEC, 0 ));
@@ -3069,46 +3072,52 @@ Dumpstate::RunStatus Dumpstate::Run(int32_t calling_uid, const std::string& call
30693072}
30703073
30713074Dumpstate::RunStatus Dumpstate::Retrieve (int32_t calling_uid, const std::string& calling_package,
3072- const bool keep_bugreport_on_retrieval) {
3075+ const bool keep_bugreport_on_retrieval,
3076+ const bool skip_user_consent) {
30733077 Dumpstate::RunStatus status = RetrieveInternal (calling_uid, calling_package,
3074- keep_bugreport_on_retrieval);
3078+ keep_bugreport_on_retrieval,
3079+ skip_user_consent);
30753080 HandleRunStatus (status);
30763081 return status;
30773082}
30783083
30793084Dumpstate::RunStatus Dumpstate::RetrieveInternal (int32_t calling_uid,
30803085 const std::string& calling_package,
3081- const bool keep_bugreport_on_retrieval) {
3082- consent_callback_ = new ConsentCallback ();
3083- const String16 incidentcompanion (" incidentcompanion" );
3084- sp<android::IBinder> ics (
3085- defaultServiceManager ()->checkService (incidentcompanion));
3086- android::String16 package (calling_package.c_str ());
3087- if (ics != nullptr ) {
3088- MYLOGD (" Checking user consent via incidentcompanion service\n " );
3089- android::interface_cast<android::os::IIncidentCompanion>(ics)->authorizeReport (
3090- calling_uid, package, String16 (), String16 (),
3091- 0x1 /* FLAG_CONFIRMATION_DIALOG */ , consent_callback_.get ());
3092- } else {
3093- MYLOGD (
3094- " Unable to check user consent; incidentcompanion service unavailable\n " );
3095- return RunStatus::USER_CONSENT_TIMED_OUT;
3096- }
3097- UserConsentResult consent_result = consent_callback_->getResult ();
3098- int timeout_ms = 30 * 1000 ;
3099- while (consent_result == UserConsentResult::UNAVAILABLE &&
3100- consent_callback_->getElapsedTimeMs () < timeout_ms) {
3101- sleep (1 );
3102- consent_result = consent_callback_->getResult ();
3103- }
3104- if (consent_result == UserConsentResult::DENIED) {
3105- return RunStatus::USER_CONSENT_DENIED;
3106- }
3107- if (consent_result == UserConsentResult::UNAVAILABLE) {
3108- MYLOGD (" Canceling user consent request via incidentcompanion service\n " );
3109- android::interface_cast<android::os::IIncidentCompanion>(ics)->cancelAuthorization (
3110- consent_callback_.get ());
3111- return RunStatus::USER_CONSENT_TIMED_OUT;
3086+ const bool keep_bugreport_on_retrieval,
3087+ const bool skip_user_consent) {
3088+ if (!android::app::admin::flags::onboarding_consentless_bugreports () || !skip_user_consent) {
3089+ consent_callback_ = new ConsentCallback ();
3090+ const String16 incidentcompanion (" incidentcompanion" );
3091+ sp<android::IBinder> ics (
3092+ defaultServiceManager ()->checkService (incidentcompanion));
3093+ android::String16 package (calling_package.c_str ());
3094+ if (ics != nullptr ) {
3095+ MYLOGD (" Checking user consent via incidentcompanion service\n " );
3096+
3097+ android::interface_cast<android::os::IIncidentCompanion>(ics)->authorizeReport (
3098+ calling_uid, package, String16 (), String16 (),
3099+ 0x1 /* FLAG_CONFIRMATION_DIALOG */ , consent_callback_.get ());
3100+ } else {
3101+ MYLOGD (
3102+ " Unable to check user consent; incidentcompanion service unavailable\n " );
3103+ return RunStatus::USER_CONSENT_TIMED_OUT;
3104+ }
3105+ UserConsentResult consent_result = consent_callback_->getResult ();
3106+ int timeout_ms = 30 * 1000 ;
3107+ while (consent_result == UserConsentResult::UNAVAILABLE &&
3108+ consent_callback_->getElapsedTimeMs () < timeout_ms) {
3109+ sleep (1 );
3110+ consent_result = consent_callback_->getResult ();
3111+ }
3112+ if (consent_result == UserConsentResult::DENIED) {
3113+ return RunStatus::USER_CONSENT_DENIED;
3114+ }
3115+ if (consent_result == UserConsentResult::UNAVAILABLE) {
3116+ MYLOGD (" Canceling user consent request via incidentcompanion service\n " );
3117+ android::interface_cast<android::os::IIncidentCompanion>(ics)->cancelAuthorization (
3118+ consent_callback_.get ());
3119+ return RunStatus::USER_CONSENT_TIMED_OUT;
3120+ }
31123121 }
31133122
31143123 bool copy_succeeded =
@@ -3357,6 +3366,12 @@ Dumpstate::RunStatus Dumpstate::RunInternal(int32_t calling_uid,
33573366 // duration is logged into MYLOG instead.
33583367 PrintHeader ();
33593368
3369+ bool system_trace_exists = access (SYSTEM_TRACE_SNAPSHOT, F_OK) == 0 ;
3370+ if (options_->use_predumped_ui_data && !system_trace_exists) {
3371+ MYLOGW (" Ignoring 'use predumped data' flag because no predumped data is available" );
3372+ options_->use_predumped_ui_data = false ;
3373+ }
3374+
33603375 std::future<std::string> snapshot_system_trace;
33613376
33623377 bool is_dumpstate_restricted =
@@ -3581,7 +3596,9 @@ void Dumpstate::onUiIntensiveBugreportDumpsFinished(int32_t calling_uid) {
35813596
35823597void Dumpstate::MaybeCheckUserConsent (int32_t calling_uid, const std::string& calling_package) {
35833598 if (multiuser_get_app_id (calling_uid) == AID_SHELL ||
3584- !CalledByApi () || options_->is_consent_deferred ) {
3599+ !CalledByApi () || options_->is_consent_deferred ||
3600+ (android::app::admin::flags::onboarding_consentless_bugreports () &&
3601+ options_->skip_user_consent )) {
35853602 // No need to get consent for shell triggered dumpstates, or not
35863603 // through bugreporting API (i.e. no fd to copy back), or when consent
35873604 // is deferred.
@@ -3667,7 +3684,8 @@ Dumpstate::RunStatus Dumpstate::CopyBugreportIfUserConsented(int32_t calling_uid
36673684 // If the caller has asked to copy the bugreport over to their directory, we need explicit
36683685 // user consent (unless the caller is Shell).
36693686 UserConsentResult consent_result;
3670- if (multiuser_get_app_id (calling_uid) == AID_SHELL) {
3687+ if (multiuser_get_app_id (calling_uid) == AID_SHELL || (options_->skip_user_consent
3688+ && android::app::admin::flags::onboarding_consentless_bugreports ())) {
36713689 consent_result = UserConsentResult::APPROVED;
36723690 } else {
36733691 consent_result = consent_callback_->getResult ();
0 commit comments