summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Abhijeet Kaur <abkaur@google.com> 2019-03-25 12:04:16 +0000
committer Abhijeet Kaur <abkaur@google.com> 2019-03-27 10:11:17 +0000
commitd3cca0d842e94104dfcadec19f0e54f43001f727 (patch)
tree486e30bdfcb146aa3914d9be2a5f12d9f26bc536
parent873f49999447c705dac1e1c7537d0a9bdf4d27c0 (diff)
Lite bugreports(wifi/telephony) don't need screenshots
Set do_fb to false for lite bugreports to not take screenshots. Also, add a nonempty check for screenshot files before broadcasting to notification. This way while sharing or uploading to drive/gmail by clicking the "Share" button would not show empty file (Not able to upload) error. Update unit tests to check for do_fb set to false for wifi/telephony. Bug: 128546970 Test: Manually take a wifi bugreport: * adb root * adb shell setprop dumpstate.options bugreportwifi * adb shell dumpstate * share bugreport from the notification to the drive * No upload failures (previously screenshot would show "Upload was unsuccessful" notification.) Test: * adb shell mkdir /data/nativetest64 * mmm -j frameworks/native/cmds/dumpstate/ && adb push ${OUT}/data/nativetest64/dumpstate_test* /data/nativetest64 && adb shell /data/nativetest64/dumpstate_test/dumpstate_test && printf "\n\n#### ALL TESTS PASSED ####\n" Change-Id: I0d2fe2a64f91dee7d090d5f8353e86d51ed5fb94
-rw-r--r--cmds/dumpstate/dumpstate.cpp16
-rw-r--r--cmds/dumpstate/tests/dumpstate_test.cpp4
2 files changed, 15 insertions, 5 deletions
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index 51b230748e..a66a8c16b2 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -34,6 +34,7 @@
#include <unistd.h>
#include <chrono>
+#include <fstream>
#include <functional>
#include <future>
#include <memory>
@@ -181,6 +182,15 @@ static bool UnlinkAndLogOnError(const std::string& file) {
return true;
}
+static bool IsFileEmpty(const std::string& file_path) {
+ std::ifstream file(file_path, std::ios::binary | std::ios::ate);
+ if(file.bad()) {
+ MYLOGE("Cannot open file: %s\n", file_path.c_str());
+ return true;
+ }
+ return file.tellg() <= 0;
+}
+
} // namespace
} // namespace os
} // namespace android
@@ -2085,7 +2095,7 @@ static void SendBugreportFinishedBroadcast() {
"--es", "android.intent.extra.DUMPSTATE_LOG", ds.log_path_
};
// clang-format on
- if (ds.options_->do_fb) {
+ if (ds.options_->do_fb && !android::os::IsFileEmpty(ds.screenshot_path_)) {
am_args.push_back("--es");
am_args.push_back("android.intent.extra.SCREENSHOT");
am_args.push_back(ds.screenshot_path_);
@@ -2161,13 +2171,13 @@ static void SetOptionsFromMode(Dumpstate::BugreportMode mode, Dumpstate::DumpOpt
break;
case Dumpstate::BugreportMode::BUGREPORT_TELEPHONY:
options->telephony_only = true;
- options->do_fb = true;
+ options->do_fb = false;
options->do_broadcast = true;
break;
case Dumpstate::BugreportMode::BUGREPORT_WIFI:
options->wifi_only = true;
options->do_zip_file = true;
- options->do_fb = true;
+ options->do_fb = false;
options->do_broadcast = true;
break;
case Dumpstate::BugreportMode::BUGREPORT_DEFAULT:
diff --git a/cmds/dumpstate/tests/dumpstate_test.cpp b/cmds/dumpstate/tests/dumpstate_test.cpp
index eb73d41dc4..e6a7735d60 100644
--- a/cmds/dumpstate/tests/dumpstate_test.cpp
+++ b/cmds/dumpstate/tests/dumpstate_test.cpp
@@ -373,7 +373,7 @@ TEST_F(DumpOptionsTest, InitializeTelephonyBugReport) {
EXPECT_EQ(status, Dumpstate::RunStatus::OK);
EXPECT_TRUE(options_.do_add_date);
- EXPECT_TRUE(options_.do_fb);
+ EXPECT_FALSE(options_.do_fb);
EXPECT_TRUE(options_.do_broadcast);
EXPECT_TRUE(options_.do_zip_file);
EXPECT_TRUE(options_.telephony_only);
@@ -404,7 +404,7 @@ TEST_F(DumpOptionsTest, InitializeWifiBugReport) {
EXPECT_EQ(status, Dumpstate::RunStatus::OK);
EXPECT_TRUE(options_.do_add_date);
- EXPECT_TRUE(options_.do_fb);
+ EXPECT_FALSE(options_.do_fb);
EXPECT_TRUE(options_.do_broadcast);
EXPECT_TRUE(options_.do_zip_file);
EXPECT_TRUE(options_.wifi_only);