Allow Shell to trigger bugreports without user consent dialog
Bug: 141442785
Test: Takes interactive/full bugreports as expected.
Test: atest dumpstate_test
Change-Id: Iee09c749bc7f70c94568cd447ea3eece9a59223b
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index e1181a6..dae5c17 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -2526,6 +2526,8 @@
return RunStatus::OK;
}
+ MYLOGD("dumpstate calling_uid = %d ; calling package = %s \n",
+ calling_uid, calling_package.c_str());
if (options_->bugreport_fd.get() != -1) {
// If the output needs to be copied over to the caller's fd, get user consent.
android::String16 package(calling_package.c_str());
@@ -2703,10 +2705,10 @@
FinalizeFile();
}
- // Share the final file with the caller if the user has consented.
+ // Share the final file with the caller if the user has consented or Shell is the caller.
Dumpstate::RunStatus status = Dumpstate::RunStatus::OK;
if (options_->bugreport_fd.get() != -1) {
- status = CopyBugreportIfUserConsented();
+ status = CopyBugreportIfUserConsented(calling_uid);
if (status != Dumpstate::RunStatus::OK &&
status != Dumpstate::RunStatus::USER_CONSENT_TIMED_OUT) {
// Do an early return if there were errors. We make an exception for consent
@@ -2776,6 +2778,9 @@
}
void Dumpstate::CheckUserConsent(int32_t calling_uid, const android::String16& calling_package) {
+ if (calling_uid == AID_SHELL) {
+ return;
+ }
consent_callback_ = new ConsentCallback();
const String16 incidentcompanion("incidentcompanion");
sp<android::IBinder> ics(defaultServiceManager()->getService(incidentcompanion));
@@ -2810,10 +2815,15 @@
return USER_CONSENT_DENIED;
}
-Dumpstate::RunStatus Dumpstate::CopyBugreportIfUserConsented() {
+Dumpstate::RunStatus Dumpstate::CopyBugreportIfUserConsented(int32_t calling_uid) {
// If the caller has asked to copy the bugreport over to their directory, we need explicit
- // user consent.
- UserConsentResult consent_result = consent_callback_->getResult();
+ // user consent (unless the caller is Shell).
+ UserConsentResult consent_result;
+ if (calling_uid == AID_SHELL) {
+ consent_result = UserConsentResult::APPROVED;
+ } else {
+ consent_result = consent_callback_->getResult();
+ }
if (consent_result == UserConsentResult::UNAVAILABLE) {
// User has not responded yet.
uint64_t elapsed_ms = consent_callback_->getElapsedTimeMs();