Minor changes on dumpstate refactoring:
- Moved more attributes into Dumpstate class.
- Created a GetPath() method that encapsulates bugreportDir_.
- Moved TakeScreenshot() into Dumpstate class.
- Uses DropRoot() on TakeScreenshot().
BUG: 26379932
Test: mmm -j32 frameworks/native/cmds/dumpstate/ && adb push ${ANDROID_PRODUCT_OUT}/data/nativetest/dumpstate_test* /data/nativetest && adb shell /data/nativetest/dumpstate_test/dumpstate_test
Change-Id: I2d96460f9244d4e257a215e2fb1f00dfd466e059
diff --git a/cmds/dumpstate/utils.cpp b/cmds/dumpstate/utils.cpp
index fc1f721..83fcf21 100644
--- a/cmds/dumpstate/utils.cpp
+++ b/cmds/dumpstate/utils.cpp
@@ -163,7 +163,7 @@
}
Dumpstate::Dumpstate(bool dryRun, const std::string& buildType)
- : dryRun_(dryRun), buildType_(buildType) {
+ : now_(time(nullptr)), dryRun_(dryRun), buildType_(buildType) {
}
Dumpstate& Dumpstate::GetInstance() {
@@ -208,6 +208,10 @@
return "user" == buildType_;
}
+std::string Dumpstate::GetPath(const std::string& suffix) {
+ return bugreportDir_ + "/" + baseName_ + "-" + suffix_ + suffix;
+}
+
void for_each_userid(void (*func)(int), const char *header) {
if (IsDryRun()) return;
@@ -1342,9 +1346,16 @@
}
}
-void take_screenshot(const std::string& path) {
- RunCommand("", {"/system/bin/screencap", "-p", path},
- CommandOptions::WithTimeout(10).Always().RedirectStderr().Build());
+void Dumpstate::TakeScreenshot(const std::string& path) {
+ const std::string& realPath = path.empty() ? screenshotPath_ : path;
+ int status =
+ RunCommand("", {"/system/bin/screencap", "-p", realPath},
+ CommandOptions::WithTimeout(10).Always().DropRoot().RedirectStderr().Build());
+ if (status == 0) {
+ MYLOGD("Screenshot saved on %s\n", realPath.c_str());
+ } else {
+ MYLOGE("Failed to take screenshot on %s\n", realPath.c_str());
+ }
}
void vibrate(FILE* vibrator, int ms) {