-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dumpstate now supports zipped bugreport, whose output is more complete than the flat-file bugreports provided prior to N. The whole workflow is split in different components: - adb supports a 'bugreport -z <ZIP_FILE>' option, which calls a bugreportz binary. - bugreportz starts the dumpstatez service. - dumpstatez starts dumpstate with some flags that opens a socket for control (not output). - Once dumpstate is finished, it prints the bugreport location to stdout. - adb pulls the zip file and renames according to the command-line argument. - bugreport prints a deprecation message. The reason for a new binary (bugreportz) instead of passing arguments to bugreport (like -z) is backward compatibility: pre-N versions of bugreport would ignore such argument and generate a text bugreport, which is not what adb would be expecting. BUG: 27653204 Change-Id: I47f6f677eba11d5fb54818ae5a0b3cab069776ee
- Loading branch information
1 parent
9ffa1a4
commit 2628e9e
Showing
7 changed files
with
162 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
LOCAL_PATH:= $(call my-dir) | ||
include $(CLEAR_VARS) | ||
|
||
LOCAL_SRC_FILES:= bugreportz.cpp | ||
|
||
LOCAL_MODULE:= bugreportz | ||
|
||
LOCAL_CFLAGS := -Wall | ||
|
||
LOCAL_SHARED_LIBRARIES := libcutils | ||
|
||
include $(BUILD_EXECUTABLE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright (C) 2016 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <errno.h> | ||
#include <stdio.h> | ||
#include <sys/socket.h> | ||
#include <sys/types.h> | ||
#include <unistd.h> | ||
|
||
#include <cutils/properties.h> | ||
#include <cutils/sockets.h> | ||
|
||
// TODO: code below was copy-and-pasted from bugreport.cpp (except by the timeout value); | ||
// should be reused instead. | ||
int main() { | ||
|
||
// Start the dumpstatez service. | ||
property_set("ctl.start", "dumpstatez"); | ||
|
||
// Socket will not be available until service starts. | ||
int s; | ||
for (int i = 0; i < 20; i++) { | ||
s = socket_local_client("dumpstate", ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_STREAM); | ||
if (s >= 0) | ||
break; | ||
// Try again in 1 second. | ||
sleep(1); | ||
} | ||
|
||
if (s == -1) { | ||
printf("Failed to connect to dumpstatez service: %s\n", strerror(errno)); | ||
return 1; | ||
} | ||
|
||
// Set a timeout so that if nothing is read in 10 minutes, we'll stop | ||
// reading and quit. No timeout in dumpstate is longer than 60 seconds, | ||
// so this gives lots of leeway in case of unforeseen time outs. | ||
struct timeval tv; | ||
tv.tv_sec = 10 * 60; | ||
tv.tv_usec = 0; | ||
if (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) == -1) { | ||
printf("WARNING: Cannot set socket timeout: %s\n", strerror(errno)); | ||
} | ||
|
||
while (1) { | ||
char buffer[65536]; | ||
ssize_t bytes_read = TEMP_FAILURE_RETRY( | ||
read(s, buffer, sizeof(buffer))); | ||
if (bytes_read == 0) { | ||
break; | ||
} else if (bytes_read == -1) { | ||
// EAGAIN really means time out, so change the errno. | ||
if (errno == EAGAIN) { | ||
errno = ETIMEDOUT; | ||
} | ||
printf("\nBugreport read terminated abnormally (%s).\n", | ||
strerror(errno)); | ||
break; | ||
} | ||
|
||
ssize_t bytes_to_send = bytes_read; | ||
ssize_t bytes_written; | ||
do { | ||
bytes_written = TEMP_FAILURE_RETRY( | ||
write(STDOUT_FILENO, buffer + bytes_read - bytes_to_send, | ||
bytes_to_send)); | ||
if (bytes_written == -1) { | ||
printf( | ||
"Failed to write data to stdout: read %zd, trying to send %zd (%s)\n", | ||
bytes_read, bytes_to_send, strerror(errno)); | ||
return 1; | ||
} | ||
bytes_to_send -= bytes_written; | ||
} while (bytes_written != 0 && bytes_to_send > 0); | ||
} | ||
|
||
close(s); | ||
return 0; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters