• 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évision9a882a3ef38c487eaa26dee845bb738997d5023d (tree)
l'heure2016-08-05 05:12:39
AuteurFelipe Leme <felipeal@goog...>
CommiterFelipe Leme

Message de Log

Ignore bugreportz output when it's not supported.

On devices running M or below, calling 'bugreportz -v' writes
'/system/bin/sh: bugreportz: not found' in the stdout output, which must
be redirected to stderr so it's not shown in the flat-file bugreport,
above the bugreport header.

BUG: 30451114

Change-Id: I942c92fdf6ae85e0cde7b9f94b9eb0b1fecad77a

Change Summary

Modification

--- a/adb/bugreport.cpp
+++ b/adb/bugreport.cpp
@@ -14,6 +14,8 @@
1414 * limitations under the License.
1515 */
1616
17+#define TRACE_TAG ADB
18+
1719 #include "bugreport.h"
1820
1921 #include <string>
@@ -187,22 +189,30 @@ int Bugreport::DoIt(TransportType transport_type, const char* serial, int argc,
187189 if (argc > 2) return usage();
188190
189191 // Gets bugreportz version.
190- std::string bugz_stderr;
191- DefaultStandardStreamsCallback version_callback(nullptr, &bugz_stderr);
192+ std::string bugz_stdout, bugz_stderr;
193+ DefaultStandardStreamsCallback version_callback(&bugz_stdout, &bugz_stderr);
192194 int status = SendShellCommand(transport_type, serial, "bugreportz -v", false, &version_callback);
193195 std::string bugz_version = android::base::Trim(bugz_stderr);
196+ std::string bugz_output = android::base::Trim(bugz_stdout);
194197
195198 if (status != 0 || bugz_version.empty()) {
196- // Device does not support bugreportz: if called as 'adb bugreport', just falls out to the
197- // flat-file version
198- if (argc == 1) return SendShellCommand(transport_type, serial, "bugreport", false);
199+ D("'bugreportz' -v results: status=%d, stdout='%s', stderr='%s'", status,
200+ bugz_output.c_str(), bugz_version.c_str());
201+ if (argc == 1) {
202+ // Device does not support bugreportz: if called as 'adb bugreport', just falls out to
203+ // the flat-file version.
204+ fprintf(stderr,
205+ "Failed to get bugreportz version, which is only available on devices "
206+ "running Android 7.0 or later.\nTrying a plain-text bug report instead.\n");
207+ return SendShellCommand(transport_type, serial, "bugreport", false);
208+ }
199209
200210 // But if user explicitly asked for a zipped bug report, fails instead (otherwise calling
201- // 'bugreport' would generate a lot of output the user might not be prepared to handle)
211+ // 'bugreport' would generate a lot of output the user might not be prepared to handle).
202212 fprintf(stderr,
203213 "Failed to get bugreportz version: 'bugreportz -v' returned '%s' (code %d).\n"
204- "If the device runs Android M or below, try 'adb bugreport' instead.\n",
205- bugz_stderr.c_str(), status);
214+ "If the device does not run Android 7.0 or above, try 'adb bugreport' instead.\n",
215+ bugz_output.c_str(), status);
206216 return status != 0 ? status : -1;
207217 }
208218
--- a/adb/bugreport_test.cpp
+++ b/adb/bugreport_test.cpp
@@ -36,7 +36,9 @@ using ::testing::Return;
3636 using ::testing::StrEq;
3737 using ::testing::WithArg;
3838 using ::testing::internal::CaptureStderr;
39+using ::testing::internal::CaptureStdout;
3940 using ::testing::internal::GetCapturedStderr;
41+using ::testing::internal::GetCapturedStdout;
4042
4143 // Empty function so tests don't need to be linked against file_sync_service.cpp, which requires
4244 // SELinux and its transitive dependencies...
@@ -152,19 +154,28 @@ class BugreportTest : public ::testing::Test {
152154
153155 // Tests when called with invalid number of arguments
154156 TEST_F(BugreportTest, InvalidNumberArgs) {
155- const char* args[1024] = {"bugreport", "to", "principal"};
157+ const char* args[] = {"bugreport", "to", "principal"};
156158 ASSERT_EQ(-42, br_.DoIt(kTransportLocal, "HannibalLecter", 3, args));
157159 }
158160
159161 // Tests the 'adb bugreport' option when the device does not support 'bugreportz' - it falls back
160162 // to the flat-file format ('bugreport' binary on device)
161163 TEST_F(BugreportTest, NoArgumentsPreNDevice) {
162- ExpectBugreportzVersion("");
164+ // clang-format off
165+ EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -v", false, _))
166+ .WillOnce(DoAll(WithArg<4>(WriteOnStderr("")),
167+ // Write some bogus output on stdout to make sure it's ignored
168+ WithArg<4>(WriteOnStdout("Dude, where is my bugreportz?")),
169+ WithArg<4>(ReturnCallbackDone(0))));
170+ // clang-format on
171+ std::string bugreport = "Reported the bug was.";
172+ CaptureStdout();
163173 EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreport", false, _))
164- .WillOnce(Return(0));
174+ .WillOnce(DoAll(WithArg<4>(WriteOnStdout(bugreport)), Return(0)));
165175
166- const char* args[1024] = {"bugreport"};
176+ const char* args[] = {"bugreport"};
167177 ASSERT_EQ(0, br_.DoIt(kTransportLocal, "HannibalLecter", 1, args));
178+ ASSERT_THAT(GetCapturedStdout(), StrEq(bugreport));
168179 }
169180
170181 // Tests the 'adb bugreport' option when the device supports 'bugreportz' version 1.0 - it will
@@ -181,7 +192,7 @@ TEST_F(BugreportTest, NoArgumentsNDevice) {
181192 true, StrEq("generating da_bugreport.zip")))
182193 .WillOnce(Return(true));
183194
184- const char* args[1024] = {"bugreport"};
195+ const char* args[] = {"bugreport"};
185196 ASSERT_EQ(0, br_.DoIt(kTransportLocal, "HannibalLecter", 1, args));
186197 }
187198
@@ -201,7 +212,7 @@ TEST_F(BugreportTest, NoArgumentsPostNDevice) {
201212 true, StrEq("generating da_bugreport.zip")))
202213 .WillOnce(Return(true));
203214
204- const char* args[1024] = {"bugreport"};
215+ const char* args[] = {"bugreport"};
205216 ASSERT_EQ(0, br_.DoIt(kTransportLocal, "HannibalLecter", 1, args));
206217 }
207218
@@ -215,7 +226,7 @@ TEST_F(BugreportTest, OkNDevice) {
215226 true, StrEq("generating file.zip")))
216227 .WillOnce(Return(true));
217228
218- const char* args[1024] = {"bugreport", "file.zip"};
229+ const char* args[] = {"bugreport", "file.zip"};
219230 ASSERT_EQ(0, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args));
220231 }
221232
@@ -231,7 +242,7 @@ TEST_F(BugreportTest, OkNDeviceSplitBuffer) {
231242 true, StrEq("generating file.zip")))
232243 .WillOnce(Return(true));
233244
234- const char* args[1024] = {"bugreport", "file.zip"};
245+ const char* args[] = {"bugreport", "file.zip"};
235246 ASSERT_EQ(0, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args));
236247 }
237248
@@ -267,7 +278,7 @@ TEST_F(BugreportTest, OkProgress) {
267278 true, StrEq("generating file.zip")))
268279 .WillOnce(Return(true));
269280
270- const char* args[1024] = {"bugreport", "file.zip"};
281+ const char* args[] = {"bugreport", "file.zip"};
271282 ASSERT_EQ(0, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args));
272283 }
273284
@@ -286,7 +297,7 @@ TEST_F(BugreportTest, OkDirectory) {
286297 true, StrEq("generating da_bugreport.zip")))
287298 .WillOnce(Return(true));
288299
289- const char* args[1024] = {"bugreport", td.path};
300+ const char* args[] = {"bugreport", td.path};
290301 ASSERT_EQ(0, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args));
291302 }
292303
@@ -300,7 +311,7 @@ TEST_F(BugreportTest, OkNoExtension) {
300311 true, StrEq("generating file.zip")))
301312 .WillOnce(Return(true));
302313
303- const char* args[1024] = {"bugreport", "file"};
314+ const char* args[] = {"bugreport", "file"};
304315 ASSERT_EQ(0, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args));
305316 }
306317
@@ -319,7 +330,7 @@ TEST_F(BugreportTest, OkNDeviceDirectory) {
319330 true, StrEq("generating da_bugreport.zip")))
320331 .WillOnce(Return(true));
321332
322- const char* args[1024] = {"bugreport", td.path};
333+ const char* args[] = {"bugreport", td.path};
323334 ASSERT_EQ(0, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args));
324335 }
325336
@@ -331,7 +342,7 @@ TEST_F(BugreportTest, BugreportzReturnedFail) {
331342 DoAll(WithArg<4>(WriteOnStdout("FAIL:D'OH!\n")), WithArg<4>(ReturnCallbackDone())));
332343
333344 CaptureStderr();
334- const char* args[1024] = {"bugreport", "file.zip"};
345+ const char* args[] = {"bugreport", "file.zip"};
335346 ASSERT_EQ(-1, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args));
336347 ASSERT_THAT(GetCapturedStderr(), HasSubstr("D'OH!"));
337348 }
@@ -346,7 +357,7 @@ TEST_F(BugreportTest, BugreportzReturnedFailSplitBuffer) {
346357 WithArg<4>(ReturnCallbackDone())));
347358
348359 CaptureStderr();
349- const char* args[1024] = {"bugreport", "file.zip"};
360+ const char* args[] = {"bugreport", "file.zip"};
350361 ASSERT_EQ(-1, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args));
351362 ASSERT_THAT(GetCapturedStderr(), HasSubstr("D'OH!"));
352363 }
@@ -360,7 +371,7 @@ TEST_F(BugreportTest, BugreportzReturnedUnsupported) {
360371 WithArg<4>(ReturnCallbackDone())));
361372
362373 CaptureStderr();
363- const char* args[1024] = {"bugreport", "file.zip"};
374+ const char* args[] = {"bugreport", "file.zip"};
364375 ASSERT_EQ(-1, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args));
365376 ASSERT_THAT(GetCapturedStderr(), HasSubstr("bugreportz? What am I, a zombie?"));
366377 }
@@ -370,7 +381,7 @@ TEST_F(BugreportTest, BugreportzVersionFailed) {
370381 EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -v", false, _))
371382 .WillOnce(Return(666));
372383
373- const char* args[1024] = {"bugreport", "file.zip"};
384+ const char* args[] = {"bugreport", "file.zip"};
374385 ASSERT_EQ(666, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args));
375386 }
376387
@@ -378,7 +389,7 @@ TEST_F(BugreportTest, BugreportzVersionFailed) {
378389 TEST_F(BugreportTest, BugreportzVersionEmpty) {
379390 ExpectBugreportzVersion("");
380391
381- const char* args[1024] = {"bugreport", "file.zip"};
392+ const char* args[] = {"bugreport", "file.zip"};
382393 ASSERT_EQ(-1, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args));
383394 }
384395
@@ -388,7 +399,7 @@ TEST_F(BugreportTest, BugreportzFailed) {
388399 EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -p", false, _))
389400 .WillOnce(Return(666));
390401
391- const char* args[1024] = {"bugreport", "file.zip"};
402+ const char* args[] = {"bugreport", "file.zip"};
392403 ASSERT_EQ(666, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args));
393404 }
394405
@@ -402,6 +413,6 @@ TEST_F(BugreportTest, PullFails) {
402413 true, HasSubstr("file.zip")))
403414 .WillOnce(Return(false));
404415
405- const char* args[1024] = {"bugreport", "file.zip"};
416+ const char* args[] = {"bugreport", "file.zip"};
406417 ASSERT_EQ(1, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args));
407418 }