Skip to content

Commit 19d3494

Browse files
Kunduz BaryktabasovaAndroid (Google) Code Review
authored andcommitted
Merge "Copy BR when failed to copy the screenshot." into main
2 parents 8ea4421 + 3a5b65a commit 19d3494

3 files changed

Lines changed: 26 additions & 6 deletions

File tree

cmds/dumpstate/Android.bp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ cc_defaults {
118118
],
119119
}
120120

121+
prebuilt_etc {
122+
name: "default_screenshot",
123+
src: "res/default_screenshot.png",
124+
filename_from_src: true,
125+
}
126+
121127
cc_binary {
122128
name: "dumpstate",
123129
defaults: ["dumpstate_defaults"],
@@ -130,6 +136,7 @@ cc_binary {
130136
required: [
131137
"atrace",
132138
"bugreport_procdump",
139+
"default_screenshot",
133140
"dmabuf_dump",
134141
"ip",
135142
"iptables",

cmds/dumpstate/dumpstate.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ static const std::string ANR_TRACE_FILE_PREFIX = "trace_";
206206
static const std::string SHUTDOWN_CHECKPOINTS_DIR = "/data/system/shutdown-checkpoints/";
207207
static const std::string SHUTDOWN_CHECKPOINTS_FILE_PREFIX = "checkpoints-";
208208

209+
// File path to default screenshot image, that used when failed to capture the real screenshot.
210+
static const std::string DEFAULT_SCREENSHOT_PATH = "/system/etc/default_screenshot.png";
211+
209212
// TODO: temporary variables and functions used during C++ refactoring
210213

211214
#define RETURN_IF_USER_DENIED_CONSENT() \
@@ -765,10 +768,14 @@ android::binder::Status Dumpstate::ConsentCallback::onReportApproved() {
765768

766769
bool copy_succeeded = android::os::CopyFileToFd(ds.screenshot_path_,
767770
ds.options_->screenshot_fd.get());
768-
ds.options_->is_screenshot_copied = copy_succeeded;
769771
if (copy_succeeded) {
770772
android::os::UnlinkAndLogOnError(ds.screenshot_path_);
773+
} else {
774+
MYLOGE("Failed to copy screenshot to a permanent file.\n");
775+
copy_succeeded = android::os::CopyFileToFd(DEFAULT_SCREENSHOT_PATH,
776+
ds.options_->screenshot_fd.get());
771777
}
778+
ds.options_->is_screenshot_copied = copy_succeeded;
772779
return android::binder::Status::ok();
773780
}
774781

@@ -3442,7 +3449,9 @@ Dumpstate::RunStatus Dumpstate::RunInternal(int32_t calling_uid,
34423449
// Do an early return if there were errors. We make an exception for consent
34433450
// timing out because it's possible the user got distracted. In this case the
34443451
// bugreport is not shared but made available for manual retrieval.
3445-
MYLOGI("User denied consent. Returning\n");
3452+
MYLOGI("Bug report generation failed, this could have been due to"
3453+
" several reasons such as BR copy failed, user consent was"
3454+
" not grated etc. Returning\n");
34463455
return status;
34473456
}
34483457
if (status == Dumpstate::RunStatus::USER_CONSENT_TIMED_OUT) {
@@ -3729,12 +3738,16 @@ Dumpstate::RunStatus Dumpstate::CopyBugreportIfUserConsented(int32_t calling_uid
37293738
if (options_->do_screenshot &&
37303739
options_->screenshot_fd.get() != -1 &&
37313740
!options_->is_screenshot_copied) {
3732-
copy_succeeded = android::os::CopyFileToFd(screenshot_path_,
3741+
bool is_screenshot_copied = android::os::CopyFileToFd(screenshot_path_,
37333742
options_->screenshot_fd.get());
3734-
options_->is_screenshot_copied = copy_succeeded;
3735-
if (copy_succeeded) {
3743+
if (is_screenshot_copied) {
37363744
android::os::UnlinkAndLogOnError(screenshot_path_);
3745+
} else {
3746+
MYLOGE("Failed to copy screenshot to a permanent file.\n");
3747+
is_screenshot_copied = android::os::CopyFileToFd(DEFAULT_SCREENSHOT_PATH,
3748+
options_->screenshot_fd.get());
37373749
}
3750+
options_->is_screenshot_copied = is_screenshot_copied;
37383751
}
37393752
}
37403753
return copy_succeeded ? Dumpstate::RunStatus::OK : Dumpstate::RunStatus::ERROR;
@@ -3825,7 +3838,7 @@ DurationReporter::DurationReporter(const std::string& title, bool logcat_only, b
38253838
DurationReporter::~DurationReporter() {
38263839
if (!title_.empty()) {
38273840
float elapsed = (float)(Nanotime() - started_) / NANOS_PER_SEC;
3828-
if (elapsed >= .5f || verbose_) {
3841+
if (elapsed >= 1.0f || verbose_) {
38293842
MYLOGD("Duration of '%s': %.2fs\n", title_.c_str(), elapsed);
38303843
}
38313844
if (!logcat_only_) {
185 Bytes
Loading

0 commit comments

Comments
 (0)