Skip to content

Commit 60d226f

Browse files
committed
Merge 24Q3 to AOSP main
Bug: 357762254 Merged-In: Ibe9b06e590ed420f29c790188dee11674fca5a2e Change-Id: Ib27f6f1e35c80ef5ac6adec6353609004ed6ed5d
2 parents 69ec43c + 98858ea commit 60d226f

628 files changed

Lines changed: 32478 additions & 32813 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmds/dumpstate/DumpstateService.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct DumpstateInfo {
3939
std::string calling_package;
4040
int32_t user_id = -1;
4141
bool keep_bugreport_on_retrieval = false;
42+
bool skip_user_consent = false;
4243
};
4344

4445
static binder::Status exception(uint32_t code, const std::string& msg,
@@ -62,7 +63,8 @@ static binder::Status exception(uint32_t code, const std::string& msg,
6263

6364
[[noreturn]] static void* dumpstate_thread_retrieve(void* data) {
6465
std::unique_ptr<DumpstateInfo> ds_info(static_cast<DumpstateInfo*>(data));
65-
ds_info->ds->Retrieve(ds_info->calling_uid, ds_info->calling_package, ds_info->keep_bugreport_on_retrieval);
66+
ds_info->ds->Retrieve(ds_info->calling_uid, ds_info->calling_package,
67+
ds_info->keep_bugreport_on_retrieval, ds_info->skip_user_consent);
6668
MYLOGD("Finished retrieving a bugreport. Exiting.\n");
6769
exit(0);
6870
}
@@ -116,7 +118,8 @@ binder::Status DumpstateService::startBugreport(int32_t calling_uid,
116118
int bugreport_mode,
117119
int bugreport_flags,
118120
const sp<IDumpstateListener>& listener,
119-
bool is_screenshot_requested) {
121+
bool is_screenshot_requested,
122+
bool skip_user_consent) {
120123
MYLOGI("startBugreport() with mode: %d\n", bugreport_mode);
121124

122125
// Ensure there is only one bugreport in progress at a time.
@@ -151,7 +154,7 @@ binder::Status DumpstateService::startBugreport(int32_t calling_uid,
151154

152155
std::unique_ptr<Dumpstate::DumpOptions> options = std::make_unique<Dumpstate::DumpOptions>();
153156
options->Initialize(static_cast<Dumpstate::BugreportMode>(bugreport_mode), bugreport_flags,
154-
bugreport_fd, screenshot_fd, is_screenshot_requested);
157+
bugreport_fd, screenshot_fd, is_screenshot_requested, skip_user_consent);
155158

156159
if (bugreport_fd.get() == -1 || (options->do_screenshot && screenshot_fd.get() == -1)) {
157160
MYLOGE("Invalid filedescriptor");
@@ -207,6 +210,7 @@ binder::Status DumpstateService::retrieveBugreport(
207210
android::base::unique_fd bugreport_fd,
208211
const std::string& bugreport_file,
209212
const bool keep_bugreport_on_retrieval,
213+
const bool skip_user_consent,
210214
const sp<IDumpstateListener>& listener) {
211215

212216
ds_ = &(Dumpstate::GetInstance());
@@ -216,14 +220,15 @@ binder::Status DumpstateService::retrieveBugreport(
216220
ds_info->calling_package = calling_package;
217221
ds_info->user_id = user_id;
218222
ds_info->keep_bugreport_on_retrieval = keep_bugreport_on_retrieval;
223+
ds_info->skip_user_consent = skip_user_consent;
219224
ds_->listener_ = listener;
220225
std::unique_ptr<Dumpstate::DumpOptions> options = std::make_unique<Dumpstate::DumpOptions>();
221226
// Use a /dev/null FD when initializing options since none is provided.
222227
android::base::unique_fd devnull_fd(
223228
TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY | O_CLOEXEC)));
224229

225230
options->Initialize(Dumpstate::BugreportMode::BUGREPORT_DEFAULT,
226-
0, bugreport_fd, devnull_fd, false);
231+
0, bugreport_fd, devnull_fd, false, skip_user_consent);
227232

228233
if (bugreport_fd.get() == -1) {
229234
MYLOGE("Invalid filedescriptor");

cmds/dumpstate/DumpstateService.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ class DumpstateService : public BinderService<DumpstateService>, public BnDumpst
4444
android::base::unique_fd bugreport_fd,
4545
android::base::unique_fd screenshot_fd, int bugreport_mode,
4646
int bugreport_flags, const sp<IDumpstateListener>& listener,
47-
bool is_screenshot_requested) override;
47+
bool is_screenshot_requested, bool skip_user_consent) override;
4848

4949
binder::Status retrieveBugreport(int32_t calling_uid,
5050
const std::string& calling_package,
5151
int32_t user_id,
5252
android::base::unique_fd bugreport_fd,
5353
const std::string& bugreport_file,
5454
const bool keep_bugreport_on_retrieval,
55+
const bool skip_user_consent,
5556
const sp<IDumpstateListener>& listener)
5657
override;
5758

cmds/dumpstate/binder/android/os/IDumpstate.aidl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ interface IDumpstate {
9696
void startBugreport(int callingUid, @utf8InCpp String callingPackage,
9797
FileDescriptor bugreportFd, FileDescriptor screenshotFd,
9898
int bugreportMode, int bugreportFlags,
99-
IDumpstateListener listener, boolean isScreenshotRequested);
99+
IDumpstateListener listener, boolean isScreenshotRequested,
100+
boolean skipUserConsent);
100101

101102
/**
102103
* Cancels the bugreport currently in progress.
@@ -130,5 +131,6 @@ interface IDumpstate {
130131
FileDescriptor bugreportFd,
131132
@utf8InCpp String bugreportFile,
132133
boolean keepBugreportOnRetrieval,
134+
boolean skipUserConsent,
133135
IDumpstateListener listener);
134136
}

cmds/dumpstate/dumpstate.cpp

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -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

30713074
Dumpstate::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

30793084
Dumpstate::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

35823597
void 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();

cmds/dumpstate/dumpstate.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ class Dumpstate {
364364
* Initialize() dumpstate before calling this method.
365365
*/
366366
RunStatus Retrieve(int32_t calling_uid, const std::string& calling_package,
367-
const bool keep_bugreport_on_retrieval);
367+
const bool keep_bugreport_on_retrieval, const bool skip_user_consent);
368368

369369

370370

@@ -412,6 +412,7 @@ class Dumpstate {
412412
bool do_screenshot = false;
413413
bool is_screenshot_copied = false;
414414
bool is_consent_deferred = false;
415+
bool skip_user_consent = false;
415416
bool is_remote_mode = false;
416417
bool show_header_only = false;
417418
bool telephony_only = false;
@@ -448,7 +449,8 @@ class Dumpstate {
448449
void Initialize(BugreportMode bugreport_mode, int bugreport_flags,
449450
const android::base::unique_fd& bugreport_fd,
450451
const android::base::unique_fd& screenshot_fd,
451-
bool is_screenshot_requested);
452+
bool is_screenshot_requested,
453+
bool skip_user_consent);
452454

453455
/* Returns true if the options set so far are consistent. */
454456
bool ValidateOptions() const;
@@ -564,7 +566,8 @@ class Dumpstate {
564566
private:
565567
RunStatus RunInternal(int32_t calling_uid, const std::string& calling_package);
566568
RunStatus RetrieveInternal(int32_t calling_uid, const std::string& calling_package,
567-
const bool keep_bugreport_on_retrieval);
569+
const bool keep_bugreport_on_retrieval,
570+
const bool skip_user_consent);
568571

569572
RunStatus DumpstateDefaultAfterCritical();
570573
RunStatus dumpstate();

cmds/dumpstate/tests/dumpstate_smoke_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ TEST_F(DumpstateBinderTest, Baseline) {
507507
ds_binder->startBugreport(123, "com.example.package", std::move(bugreport_fd),
508508
std::move(screenshot_fd),
509509
Dumpstate::BugreportMode::BUGREPORT_INTERACTIVE, flags, listener,
510-
true);
510+
true, false);
511511
// startBugreport is an async call. Verify binder call succeeded first, then wait till listener
512512
// gets expected callbacks.
513513
EXPECT_TRUE(status.isOk());
@@ -545,7 +545,7 @@ TEST_F(DumpstateBinderTest, ServiceDies_OnInvalidInput) {
545545
android::binder::Status status =
546546
ds_binder->startBugreport(123, "com.example.package", std::move(bugreport_fd),
547547
std::move(screenshot_fd), 2000, // invalid bugreport mode
548-
flags, listener, false);
548+
flags, listener, false, false);
549549
EXPECT_EQ(listener->getErrorCode(), IDumpstateListener::BUGREPORT_ERROR_INVALID_INPUT);
550550

551551
// The service should have died, freeing itself up for a new invocation.
@@ -579,15 +579,15 @@ TEST_F(DumpstateBinderTest, SimultaneousBugreportsNotAllowed) {
579579
ds_binder->startBugreport(123, "com.example.package", std::move(bugreport_fd),
580580
std::move(screenshot_fd),
581581
Dumpstate::BugreportMode::BUGREPORT_INTERACTIVE, flags, listener1,
582-
true);
582+
true, false);
583583
EXPECT_TRUE(status.isOk());
584584

585585
// try to make another call to startBugreport. This should fail.
586586
sp<DumpstateListener> listener2(new DumpstateListener(dup(fileno(stdout))));
587587
status = ds_binder->startBugreport(123, "com.example.package", std::move(bugreport_fd2),
588588
std::move(screenshot_fd2),
589589
Dumpstate::BugreportMode::BUGREPORT_INTERACTIVE, flags,
590-
listener2, true);
590+
listener2, true, false);
591591
EXPECT_FALSE(status.isOk());
592592
WaitTillExecutionComplete(listener2.get());
593593
EXPECT_EQ(listener2->getErrorCode(),

cmds/dumpstate/tests/dumpstate_test.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ TEST_F(DumpOptionsTest, InitializeAdbShellBugreport) {
239239
}
240240

241241
TEST_F(DumpOptionsTest, InitializeFullBugReport) {
242-
options_.Initialize(Dumpstate::BugreportMode::BUGREPORT_FULL, 0, fd, fd, true);
242+
options_.Initialize(Dumpstate::BugreportMode::BUGREPORT_FULL, 0, fd, fd, true, false);
243243
EXPECT_TRUE(options_.do_screenshot);
244244

245245
// Other options retain default values
@@ -253,7 +253,7 @@ TEST_F(DumpOptionsTest, InitializeFullBugReport) {
253253
}
254254

255255
TEST_F(DumpOptionsTest, InitializeInteractiveBugReport) {
256-
options_.Initialize(Dumpstate::BugreportMode::BUGREPORT_INTERACTIVE, 0, fd, fd, true);
256+
options_.Initialize(Dumpstate::BugreportMode::BUGREPORT_INTERACTIVE, 0, fd, fd, true, false);
257257
EXPECT_TRUE(options_.do_progress_updates);
258258
EXPECT_TRUE(options_.do_screenshot);
259259

@@ -267,7 +267,7 @@ TEST_F(DumpOptionsTest, InitializeInteractiveBugReport) {
267267
}
268268

269269
TEST_F(DumpOptionsTest, InitializeRemoteBugReport) {
270-
options_.Initialize(Dumpstate::BugreportMode::BUGREPORT_REMOTE, 0, fd, fd, false);
270+
options_.Initialize(Dumpstate::BugreportMode::BUGREPORT_REMOTE, 0, fd, fd, false, false);
271271
EXPECT_TRUE(options_.is_remote_mode);
272272
EXPECT_FALSE(options_.do_vibrate);
273273
EXPECT_FALSE(options_.do_screenshot);
@@ -281,7 +281,7 @@ TEST_F(DumpOptionsTest, InitializeRemoteBugReport) {
281281
}
282282

283283
TEST_F(DumpOptionsTest, InitializeWearBugReport) {
284-
options_.Initialize(Dumpstate::BugreportMode::BUGREPORT_WEAR, 0, fd, fd, true);
284+
options_.Initialize(Dumpstate::BugreportMode::BUGREPORT_WEAR, 0, fd, fd, true, false);
285285
EXPECT_TRUE(options_.do_screenshot);
286286
EXPECT_TRUE(options_.do_progress_updates);
287287

@@ -296,7 +296,7 @@ TEST_F(DumpOptionsTest, InitializeWearBugReport) {
296296
}
297297

298298
TEST_F(DumpOptionsTest, InitializeTelephonyBugReport) {
299-
options_.Initialize(Dumpstate::BugreportMode::BUGREPORT_TELEPHONY, 0, fd, fd, false);
299+
options_.Initialize(Dumpstate::BugreportMode::BUGREPORT_TELEPHONY, 0, fd, fd, false, false);
300300
EXPECT_FALSE(options_.do_screenshot);
301301
EXPECT_TRUE(options_.telephony_only);
302302
EXPECT_TRUE(options_.do_progress_updates);
@@ -311,7 +311,7 @@ TEST_F(DumpOptionsTest, InitializeTelephonyBugReport) {
311311
}
312312

313313
TEST_F(DumpOptionsTest, InitializeWifiBugReport) {
314-
options_.Initialize(Dumpstate::BugreportMode::BUGREPORT_WIFI, 0, fd, fd, false);
314+
options_.Initialize(Dumpstate::BugreportMode::BUGREPORT_WIFI, 0, fd, fd, false, false);
315315
EXPECT_FALSE(options_.do_screenshot);
316316
EXPECT_TRUE(options_.wifi_only);
317317

@@ -491,12 +491,12 @@ TEST_F(DumpOptionsTest, InitializeBugreportFlags) {
491491
int flags = Dumpstate::BugreportFlag::BUGREPORT_USE_PREDUMPED_UI_DATA |
492492
Dumpstate::BugreportFlag::BUGREPORT_FLAG_DEFER_CONSENT;
493493
options_.Initialize(
494-
Dumpstate::BugreportMode::BUGREPORT_FULL, flags, fd, fd, true);
494+
Dumpstate::BugreportMode::BUGREPORT_FULL, flags, fd, fd, true, false);
495495
EXPECT_TRUE(options_.is_consent_deferred);
496496
EXPECT_TRUE(options_.use_predumped_ui_data);
497497

498498
options_.Initialize(
499-
Dumpstate::BugreportMode::BUGREPORT_FULL, 0, fd, fd, true);
499+
Dumpstate::BugreportMode::BUGREPORT_FULL, 0, fd, fd, true, false);
500500
EXPECT_FALSE(options_.is_consent_deferred);
501501
EXPECT_FALSE(options_.use_predumped_ui_data);
502502
}

0 commit comments

Comments
 (0)