• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


Commit MetaInfo

Révisione2e1a1002692f58630c4313e0bbcc72c29ad12f2 (tree)
l'heure2016-08-05 05:15:18
AuteurFelipe Leme <felipeal@goog...>
Commitergitbuildkicker

Message de Log

Minor improvements on bugreport generation.

- Skipped artificial 100/100 message, since pulling will take care of

the final 100% progress.

- Consolidated unsupported lines in just one message.
- Let user know the bugreport can still be recovered when it could not

be copied to the destination directory.

BUG: 30451114

Change-Id: Icfce9c1e8e7ed407719728b9874679ac40b21eab

Change Summary

Modification

--- a/adb/bugreport.cpp
+++ b/adb/bugreport.cpp
@@ -15,6 +15,7 @@
1515 */
1616
1717 #include <string>
18+#include <vector>
1819
1920 #include <android-base/strings.h>
2021
@@ -31,10 +32,12 @@ class BugreportStandardStreamsCallback : public StandardStreamsCallbackInterface
3132 public:
3233 BugreportStandardStreamsCallback(const std::string& dest_file, bool show_progress, Bugreport* br)
3334 : br_(br),
35+ src_file_(),
3436 dest_file_(dest_file),
3537 line_message_(android::base::StringPrintf("generating %s", dest_file_.c_str())),
38+ invalid_lines_(),
3639 show_progress_(show_progress),
37- status_(-1),
40+ status_(0),
3841 line_() {
3942 }
4043
@@ -54,9 +57,39 @@ class BugreportStandardStreamsCallback : public StandardStreamsCallbackInterface
5457 OnStream(nullptr, stderr, buffer, length);
5558 }
5659 int Done(int unused_) {
57- // Process remaining line, if any...
60+ // Process remaining line, if any.
5861 ProcessLine(line_);
59- // ..then return.
62+
63+ // Warn about invalid lines, if any.
64+ if (!invalid_lines_.empty()) {
65+ fprintf(stderr,
66+ "WARNING: bugreportz generated %zu line(s) with unknown commands, "
67+ "device might not support zipped bugreports:\n",
68+ invalid_lines_.size());
69+ for (const auto& line : invalid_lines_) {
70+ fprintf(stderr, "\t%s\n", line.c_str());
71+ }
72+ fprintf(stderr,
73+ "If the zipped bugreport was not generated, try 'adb bugreport' instead.\n");
74+ }
75+
76+ // Pull the generated bug report.
77+ if (status_ == 0) {
78+ if (src_file_.empty()) {
79+ fprintf(stderr, "bugreportz did not return a '%s' or '%s' line\n", BUGZ_OK_PREFIX,
80+ BUGZ_FAIL_PREFIX);
81+ return -1;
82+ }
83+ std::vector<const char*> srcs{src_file_.c_str()};
84+ status_ = br_->DoSyncPull(srcs, dest_file_.c_str(), true, line_message_.c_str()) ? 0 : 1;
85+ if (status_ != 0) {
86+ fprintf(stderr,
87+ "Bug report finished but could not be copied to '%s'.\n"
88+ "Try to run 'adb pull %s <directory>'\n"
89+ "to copy it to a directory that can be written.\n",
90+ dest_file_.c_str(), src_file_.c_str());
91+ }
92+ }
6093 return status_;
6194 }
6295
@@ -65,17 +98,7 @@ class BugreportStandardStreamsCallback : public StandardStreamsCallbackInterface
6598 if (line.empty()) return;
6699
67100 if (android::base::StartsWith(line, BUGZ_OK_PREFIX)) {
68- if (show_progress_) {
69- // Make sure pull message doesn't conflict with generation message.
70- br_->UpdateProgress(line_message_, 100, 100);
71- }
72-
73- const char* zip_file = &line[strlen(BUGZ_OK_PREFIX)];
74- std::vector<const char*> srcs{zip_file};
75- status_ = br_->DoSyncPull(srcs, dest_file_.c_str(), true, line_message_.c_str()) ? 0 : 1;
76- if (status_ != 0) {
77- fprintf(stderr, "Could not copy file '%s' to '%s'\n", zip_file, dest_file_.c_str());
78- }
101+ src_file_ = &line[strlen(BUGZ_OK_PREFIX)];
79102 } else if (android::base::StartsWith(line, BUGZ_FAIL_PREFIX)) {
80103 const char* error_message = &line[strlen(BUGZ_FAIL_PREFIX)];
81104 fprintf(stderr, "Device failed to take a zipped bugreport: %s\n", error_message);
@@ -91,17 +114,15 @@ class BugreportStandardStreamsCallback : public StandardStreamsCallbackInterface
91114 int total = std::stoi(line.substr(idx2 + 1));
92115 br_->UpdateProgress(dest_file_, progress, total);
93116 } else {
94- fprintf(stderr,
95- "WARNING: unexpected line (%s) returned by bugreportz, "
96- "device probably does not support zipped bugreports.\n"
97- "Try 'adb bugreport' instead.",
98- line.c_str());
117+ invalid_lines_.push_back(line);
99118 }
100119 }
101120
102121 Bugreport* br_;
122+ std::string src_file_;
103123 const std::string dest_file_;
104124 const std::string line_message_;
125+ std::vector<std::string> invalid_lines_;
105126 bool show_progress_;
106127 int status_;
107128
@@ -132,18 +153,15 @@ int Bugreport::DoIt(TransportType transport_type, const char* serial, int argc,
132153 std::string bugz_stderr;
133154 DefaultStandardStreamsCallback version_callback(nullptr, &bugz_stderr);
134155 int status = SendShellCommand(transport_type, serial, "bugreportz -v", false, &version_callback);
156+ std::string bugz_version = android::base::Trim(bugz_stderr);
135157
136- if (status != 0) {
158+ if (status != 0 || bugz_version.empty()) {
137159 fprintf(stderr,
138- "Failed to get bugreportz version: 'bugreport -v' returned '%s' "
139- "(code %d)."
140- "\nIf the device does not support it, try running 'adb bugreport' "
141- "to get a "
142- "flat-file bugreport.",
160+ "Failed to get bugreportz version: 'bugreportz -v' returned '%s' (code %d).\n"
161+ "If the device runs Android M or below, try 'adb bugreport' instead.\n",
143162 bugz_stderr.c_str(), status);
144- return status;
163+ return status != 0 ? status : -1;
145164 }
146- std::string bugz_version = android::base::Trim(bugz_stderr);
147165
148166 bool show_progress = true;
149167 std::string bugz_command = "bugreportz -p";
@@ -153,8 +171,7 @@ int Bugreport::DoIt(TransportType transport_type, const char* serial, int argc,
153171 fprintf(stderr,
154172 "Bugreport is in progress and it could take minutes to complete.\n"
155173 "Please be patient and do not cancel or disconnect your device "
156- "until it completes."
157- "\n");
174+ "until it completes.\n");
158175 show_progress = false;
159176 bugz_command = "bugreportz";
160177 }
--- a/adb/bugreport_test.cpp
+++ b/adb/bugreport_test.cpp
@@ -189,14 +189,14 @@ TEST_F(BugreportTest, Ok) {
189189 ExpectProgress(10, 100);
190190 ExpectProgress(50, 100);
191191 ExpectProgress(99, 100);
192- ExpectProgress(100, 100);
193192 // clang-format off
194193 EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -p", false, _))
194+ // NOTE: DoAll accepts at most 10 arguments, and we have reached that limit...
195195 .WillOnce(DoAll(
196196 // Progress line in one write
197197 WithArg<4>(WriteOnStdout("PROGRESS:1/100\n")),
198198 // Add some bogus lines
199- WithArg<4>(WriteOnStdout("\nDUDE:SWEET\n\n")),
199+ WithArg<4>(WriteOnStdout("\nDUDE:SWEET\n\nBLA\n\nBLA\nBLA\n\n")),
200200 // Multiple progress lines in one write
201201 WithArg<4>(WriteOnStdout("PROGRESS:10/100\nPROGRESS:50/100\n")),
202202 // Progress line in multiple writes
@@ -207,6 +207,7 @@ TEST_F(BugreportTest, Ok) {
207207 WithArg<4>(WriteOnStdout("OK:/device/bugreport")),
208208 WithArg<4>(WriteOnStdout(".zip")),
209209 WithArg<4>(ReturnCallbackDone())));
210+ // clang-format on
210211 EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"),
211212 true, HasSubstr("file.zip")))
212213 .WillOnce(Return(true));
@@ -218,7 +219,6 @@ TEST_F(BugreportTest, Ok) {
218219 // Tests 'adb bugreport file' when it succeeds
219220 TEST_F(BugreportTest, OkNoExtension) {
220221 SetBugreportzVersion("1.1");
221- ExpectProgress(100, 100);
222222 EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -p", false, _))
223223 .WillOnce(DoAll(WithArg<4>(WriteOnStdout("OK:/device/bugreport.zip\n")),
224224 WithArg<4>(ReturnCallbackDone())));
@@ -281,6 +281,14 @@ TEST_F(BugreportTest, BugreportzVersionFailed) {
281281 ASSERT_EQ(666, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args));
282282 }
283283
284+// Tests 'adb bugreport file.zip' when the bugreportz -v returns status 0 but with no output.
285+TEST_F(BugreportTest, BugreportzVersionEmpty) {
286+ SetBugreportzVersion("");
287+
288+ const char* args[1024] = {"bugreport", "file.zip"};
289+ ASSERT_EQ(-1, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args));
290+}
291+
284292 // Tests 'adb bugreport file.zip' when the main bugreportz command failed
285293 TEST_F(BugreportTest, BugreportzFailed) {
286294 SetBugreportzVersion("1.1");
@@ -294,7 +302,6 @@ TEST_F(BugreportTest, BugreportzFailed) {
294302 // Tests 'adb bugreport file.zip' when the bugreport could not be pulled
295303 TEST_F(BugreportTest, PullFails) {
296304 SetBugreportzVersion("1.1");
297- ExpectProgress(100, 100);
298305 EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -p", false, _))
299306 .WillOnce(DoAll(WithArg<4>(WriteOnStdout("OK:/device/bugreport.zip")),
300307 WithArg<4>(ReturnCallbackDone())));