system/corennnnn
修訂 | f7c38b4c03d75c9cb27610acab96f4e7f4169de8 (tree) |
---|---|
時間 | 2016-07-29 04:13:57 |
作者 | Felipe Leme <felipeal@goog...> |
Commiter | Felipe Leme |
Removed extra 'pulling file' message.
Taking a zip bugreport has 2 phases: generating the bugreport and
pulling the file.
Initially adb was printing 2 messages, but since the latter is almost
instantaneously, it could be confusing to have 2 lines...
Fixes: 30451250
Change-Id: I1c6cc6163492c1fb6064667dfdb7aaf6ed4c4c6f
@@ -30,7 +30,12 @@ static constexpr char BUGZ_PROGRESS_SEPARATOR[] = "/"; | ||
30 | 30 | class BugreportStandardStreamsCallback : public StandardStreamsCallbackInterface { |
31 | 31 | public: |
32 | 32 | BugreportStandardStreamsCallback(const std::string& dest_file, bool show_progress, Bugreport* br) |
33 | - : br_(br), dest_file_(dest_file), show_progress_(show_progress), status_(-1), line_() { | |
33 | + : br_(br), | |
34 | + dest_file_(dest_file), | |
35 | + line_message_(android::base::StringPrintf("generating %s", dest_file_.c_str())), | |
36 | + show_progress_(show_progress), | |
37 | + status_(-1), | |
38 | + line_() { | |
34 | 39 | } |
35 | 40 | |
36 | 41 | void OnStdout(const char* buffer, int length) { |
@@ -62,12 +67,12 @@ class BugreportStandardStreamsCallback : public StandardStreamsCallbackInterface | ||
62 | 67 | if (android::base::StartsWith(line, BUGZ_OK_PREFIX)) { |
63 | 68 | if (show_progress_) { |
64 | 69 | // Make sure pull message doesn't conflict with generation message. |
65 | - br_->UpdateProgress(dest_file_, 100, 100, true); | |
70 | + br_->UpdateProgress(line_message_, 100, 100); | |
66 | 71 | } |
67 | 72 | |
68 | 73 | const char* zip_file = &line[strlen(BUGZ_OK_PREFIX)]; |
69 | 74 | std::vector<const char*> srcs{zip_file}; |
70 | - status_ = br_->DoSyncPull(srcs, dest_file_.c_str(), true, dest_file_.c_str()) ? 0 : 1; | |
75 | + status_ = br_->DoSyncPull(srcs, dest_file_.c_str(), true, line_message_.c_str()) ? 0 : 1; | |
71 | 76 | if (status_ != 0) { |
72 | 77 | fprintf(stderr, "Could not copy file '%s' to '%s'\n", zip_file, dest_file_.c_str()); |
73 | 78 | } |
@@ -96,6 +101,7 @@ class BugreportStandardStreamsCallback : public StandardStreamsCallbackInterface | ||
96 | 101 | |
97 | 102 | Bugreport* br_; |
98 | 103 | const std::string dest_file_; |
104 | + const std::string line_message_; | |
99 | 105 | bool show_progress_; |
100 | 106 | int status_; |
101 | 107 |
@@ -156,15 +162,11 @@ int Bugreport::DoIt(TransportType transport_type, const char* serial, int argc, | ||
156 | 162 | return SendShellCommand(transport_type, serial, bugz_command, false, &bugz_callback); |
157 | 163 | } |
158 | 164 | |
159 | -void Bugreport::UpdateProgress(const std::string& file_name, int progress, int total, | |
160 | - bool keep_info_line) { | |
165 | +void Bugreport::UpdateProgress(const std::string& message, int progress, int total) { | |
161 | 166 | int progress_percentage = (progress * 100 / total); |
162 | - line_printer_.Print(android::base::StringPrintf("[%3d%%] generating %s", progress_percentage, | |
163 | - file_name.c_str()), | |
164 | - LinePrinter::INFO); | |
165 | - if (keep_info_line) { | |
166 | - line_printer_.KeepInfoLine(); | |
167 | - } | |
167 | + line_printer_.Print( | |
168 | + android::base::StringPrintf("[%3d%%] %s", progress_percentage, message.c_str()), | |
169 | + LinePrinter::INFO); | |
168 | 170 | } |
169 | 171 | |
170 | 172 | int Bugreport::SendShellCommand(TransportType transport_type, const char* serial, |
@@ -43,8 +43,7 @@ class Bugreport { | ||
43 | 43 | const char* name); |
44 | 44 | |
45 | 45 | private: |
46 | - virtual void UpdateProgress(const std::string& file_name, int progress, int total, | |
47 | - bool keep_info_line = false); | |
46 | + virtual void UpdateProgress(const std::string& file_name, int progress, int total); | |
48 | 47 | LinePrinter line_printer_; |
49 | 48 | DISALLOW_COPY_AND_ASSIGN(Bugreport); |
50 | 49 | }; |
@@ -117,7 +117,7 @@ class BugreportMock : public Bugreport { | ||
117 | 117 | bool disable_shell_protocol, StandardStreamsCallbackInterface* callback)); |
118 | 118 | MOCK_METHOD4(DoSyncPull, bool(const std::vector<const char*>& srcs, const char* dst, |
119 | 119 | bool copy_attrs, const char* name)); |
120 | - MOCK_METHOD4(UpdateProgress, void(const std::string&, int, int, bool)); | |
120 | + MOCK_METHOD3(UpdateProgress, void(const std::string&, int, int)); | |
121 | 121 | }; |
122 | 122 | |
123 | 123 | class BugreportTest : public ::testing::Test { |
@@ -129,8 +129,8 @@ class BugreportTest : public ::testing::Test { | ||
129 | 129 | WithArg<4>(ReturnCallbackDone(0)))); |
130 | 130 | } |
131 | 131 | |
132 | - void ExpectProgress(int progress, int total, bool keep_info_line = false) { | |
133 | - EXPECT_CALL(br_, UpdateProgress(StrEq("file.zip"), progress, total, keep_info_line)); | |
132 | + void ExpectProgress(int progress, int total) { | |
133 | + EXPECT_CALL(br_, UpdateProgress(HasSubstr("file.zip"), progress, total)); | |
134 | 134 | } |
135 | 135 | |
136 | 136 | BugreportMock br_; |
@@ -159,7 +159,7 @@ TEST_F(BugreportTest, OkLegacy) { | ||
159 | 159 | .WillOnce(DoAll(WithArg<4>(WriteOnStdout("OK:/device/bugreport.zip")), |
160 | 160 | WithArg<4>(ReturnCallbackDone()))); |
161 | 161 | EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"), |
162 | - true, StrEq("file.zip"))) | |
162 | + true, HasSubstr("file.zip"))) | |
163 | 163 | .WillOnce(Return(true)); |
164 | 164 | |
165 | 165 | const char* args[1024] = {"bugreport", "file.zip"}; |
@@ -175,7 +175,7 @@ TEST_F(BugreportTest, OkLegacySplitBuffer) { | ||
175 | 175 | WithArg<4>(WriteOnStdout("/bugreport.zip")), |
176 | 176 | WithArg<4>(ReturnCallbackDone()))); |
177 | 177 | EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"), |
178 | - true, StrEq("file.zip"))) | |
178 | + true, HasSubstr("file.zip"))) | |
179 | 179 | .WillOnce(Return(true)); |
180 | 180 | |
181 | 181 | const char* args[1024] = {"bugreport", "file.zip"}; |
@@ -189,7 +189,7 @@ TEST_F(BugreportTest, Ok) { | ||
189 | 189 | ExpectProgress(10, 100); |
190 | 190 | ExpectProgress(50, 100); |
191 | 191 | ExpectProgress(99, 100); |
192 | - ExpectProgress(100, 100, true); | |
192 | + ExpectProgress(100, 100); | |
193 | 193 | // clang-format off |
194 | 194 | EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -p", false, _)) |
195 | 195 | .WillOnce(DoAll( |
@@ -208,7 +208,7 @@ TEST_F(BugreportTest, Ok) { | ||
208 | 208 | WithArg<4>(WriteOnStdout(".zip")), |
209 | 209 | WithArg<4>(ReturnCallbackDone()))); |
210 | 210 | EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"), |
211 | - true, StrEq("file.zip"))) | |
211 | + true, HasSubstr("file.zip"))) | |
212 | 212 | .WillOnce(Return(true)); |
213 | 213 | |
214 | 214 | const char* args[1024] = {"bugreport", "file.zip"}; |
@@ -218,12 +218,12 @@ TEST_F(BugreportTest, Ok) { | ||
218 | 218 | // Tests 'adb bugreport file' when it succeeds |
219 | 219 | TEST_F(BugreportTest, OkNoExtension) { |
220 | 220 | SetBugreportzVersion("1.1"); |
221 | - ExpectProgress(100, 100, true); | |
221 | + ExpectProgress(100, 100); | |
222 | 222 | EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -p", false, _)) |
223 | 223 | .WillOnce(DoAll(WithArg<4>(WriteOnStdout("OK:/device/bugreport.zip\n")), |
224 | 224 | WithArg<4>(ReturnCallbackDone()))); |
225 | 225 | EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"), |
226 | - true, StrEq("file.zip"))) | |
226 | + true, HasSubstr("file.zip"))) | |
227 | 227 | .WillOnce(Return(true)); |
228 | 228 | |
229 | 229 | const char* args[1024] = {"bugreport", "file"}; |
@@ -294,12 +294,12 @@ TEST_F(BugreportTest, BugreportzFailed) { | ||
294 | 294 | // Tests 'adb bugreport file.zip' when the bugreport could not be pulled |
295 | 295 | TEST_F(BugreportTest, PullFails) { |
296 | 296 | SetBugreportzVersion("1.1"); |
297 | - ExpectProgress(100, 100, true); | |
297 | + ExpectProgress(100, 100); | |
298 | 298 | EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -p", false, _)) |
299 | 299 | .WillOnce(DoAll(WithArg<4>(WriteOnStdout("OK:/device/bugreport.zip")), |
300 | 300 | WithArg<4>(ReturnCallbackDone()))); |
301 | 301 | EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"), |
302 | - true, StrEq("file.zip"))) | |
302 | + true, HasSubstr("file.zip"))) | |
303 | 303 | .WillOnce(Return(false)); |
304 | 304 | |
305 | 305 | const char* args[1024] = {"bugreport", "file.zip"}; |