Add command line utilites to set the reason field in incident report header
am: 5dfe3dfeb8
Change-Id: I8ac51459fc605d5128ed736077a3b093cc3950a0
This commit is contained in:
@@ -30,7 +30,7 @@ cc_binary {
|
|||||||
],
|
],
|
||||||
|
|
||||||
static_libs: [
|
static_libs: [
|
||||||
"libplatformprotos",
|
"libprotoutil",
|
||||||
],
|
],
|
||||||
|
|
||||||
cflags: [
|
cflags: [
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include <android/os/BnIncidentReportStatusListener.h>
|
#include <android/os/BnIncidentReportStatusListener.h>
|
||||||
#include <android/os/IIncidentManager.h>
|
#include <android/os/IIncidentManager.h>
|
||||||
#include <android/os/IncidentReportArgs.h>
|
#include <android/os/IncidentReportArgs.h>
|
||||||
|
#include <android/util/ProtoOutputStream.h>
|
||||||
#include <binder/IPCThreadState.h>
|
#include <binder/IPCThreadState.h>
|
||||||
#include <binder/IServiceManager.h>
|
#include <binder/IServiceManager.h>
|
||||||
#include <utils/Looper.h>
|
#include <utils/Looper.h>
|
||||||
@@ -36,6 +37,9 @@ using namespace android;
|
|||||||
using namespace android::base;
|
using namespace android::base;
|
||||||
using namespace android::binder;
|
using namespace android::binder;
|
||||||
using namespace android::os;
|
using namespace android::os;
|
||||||
|
using android::util::FIELD_COUNT_SINGLE;
|
||||||
|
using android::util::FIELD_TYPE_STRING;
|
||||||
|
using android::util::ProtoOutputStream;
|
||||||
|
|
||||||
// ================================================================================
|
// ================================================================================
|
||||||
class StatusListener : public BnIncidentReportStatusListener {
|
class StatusListener : public BnIncidentReportStatusListener {
|
||||||
@@ -208,6 +212,7 @@ usage(FILE* out)
|
|||||||
fprintf(out, "and one of these destinations:\n");
|
fprintf(out, "and one of these destinations:\n");
|
||||||
fprintf(out, " -b (default) print the report to stdout (in proto format)\n");
|
fprintf(out, " -b (default) print the report to stdout (in proto format)\n");
|
||||||
fprintf(out, " -d send the report into dropbox\n");
|
fprintf(out, " -d send the report into dropbox\n");
|
||||||
|
fprintf(out, " -r REASON human readable description of why the report is taken.\n");
|
||||||
fprintf(out, " -s PKG/CLS send broadcast to the broadcast receiver.\n");
|
fprintf(out, " -s PKG/CLS send broadcast to the broadcast receiver.\n");
|
||||||
fprintf(out, "\n");
|
fprintf(out, "\n");
|
||||||
fprintf(out, " SECTION the field numbers of the incident report fields to include\n");
|
fprintf(out, " SECTION the field numbers of the incident report fields to include\n");
|
||||||
@@ -221,11 +226,12 @@ main(int argc, char** argv)
|
|||||||
IncidentReportArgs args;
|
IncidentReportArgs args;
|
||||||
enum { DEST_UNSET, DEST_DROPBOX, DEST_STDOUT, DEST_BROADCAST } destination = DEST_UNSET;
|
enum { DEST_UNSET, DEST_DROPBOX, DEST_STDOUT, DEST_BROADCAST } destination = DEST_UNSET;
|
||||||
int privacyPolicy = PRIVACY_POLICY_AUTOMATIC;
|
int privacyPolicy = PRIVACY_POLICY_AUTOMATIC;
|
||||||
|
string reason;
|
||||||
string receiverArg;
|
string receiverArg;
|
||||||
|
|
||||||
// Parse the args
|
// Parse the args
|
||||||
int opt;
|
int opt;
|
||||||
while ((opt = getopt(argc, argv, "bhdlp:s:")) != -1) {
|
while ((opt = getopt(argc, argv, "bhdlp:r:s:")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'h':
|
case 'h':
|
||||||
usage(stdout);
|
usage(stdout);
|
||||||
@@ -250,6 +256,13 @@ main(int argc, char** argv)
|
|||||||
case 'p':
|
case 'p':
|
||||||
privacyPolicy = get_privacy_policy(optarg);
|
privacyPolicy = get_privacy_policy(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'r':
|
||||||
|
if (reason.size() > 0) {
|
||||||
|
usage(stderr);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
reason = optarg;
|
||||||
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
if (destination != DEST_UNSET) {
|
if (destination != DEST_UNSET) {
|
||||||
usage(stderr);
|
usage(stderr);
|
||||||
@@ -301,6 +314,14 @@ main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
args.setPrivacyPolicy(privacyPolicy);
|
args.setPrivacyPolicy(privacyPolicy);
|
||||||
|
|
||||||
|
if (reason.size() > 0) {
|
||||||
|
ProtoOutputStream proto;
|
||||||
|
proto.write(/* reason field id */ 2 | FIELD_TYPE_STRING | FIELD_COUNT_SINGLE, reason);
|
||||||
|
vector<uint8_t> header;
|
||||||
|
proto.serializeToVector(&header);
|
||||||
|
args.addHeader(header);
|
||||||
|
}
|
||||||
|
|
||||||
// Start the thread pool.
|
// Start the thread pool.
|
||||||
sp<ProcessState> ps(ProcessState::self());
|
sp<ProcessState> ps(ProcessState::self());
|
||||||
ps->startThreadPool();
|
ps->startThreadPool();
|
||||||
|
|||||||
@@ -292,6 +292,7 @@ usage(FILE* out)
|
|||||||
fprintf(out, "Take an incident report over adb (which must be in the PATH).\n");
|
fprintf(out, "Take an incident report over adb (which must be in the PATH).\n");
|
||||||
fprintf(out, " -b output the incident report raw protobuf format\n");
|
fprintf(out, " -b output the incident report raw protobuf format\n");
|
||||||
fprintf(out, " -o OUTPUT the output file. OUTPUT may be '-' or omitted to use stdout\n");
|
fprintf(out, " -o OUTPUT the output file. OUTPUT may be '-' or omitted to use stdout\n");
|
||||||
|
fprintf(out, " -r REASON human readable description of why the report is taken.\n");
|
||||||
fprintf(out, " -s SERIAL sent to adb to choose which device, instead of $ANDROID_SERIAL\n");
|
fprintf(out, " -s SERIAL sent to adb to choose which device, instead of $ANDROID_SERIAL\n");
|
||||||
fprintf(out, " -t output the incident report in pretty-printed text format\n");
|
fprintf(out, " -t output the incident report in pretty-printed text format\n");
|
||||||
fprintf(out, "\n");
|
fprintf(out, "\n");
|
||||||
@@ -307,13 +308,14 @@ main(int argc, char** argv)
|
|||||||
enum { OUTPUT_TEXT, OUTPUT_PROTO } outputFormat = OUTPUT_TEXT;
|
enum { OUTPUT_TEXT, OUTPUT_PROTO } outputFormat = OUTPUT_TEXT;
|
||||||
const char* inFilename = NULL;
|
const char* inFilename = NULL;
|
||||||
const char* outFilename = NULL;
|
const char* outFilename = NULL;
|
||||||
|
const char* reason = NULL;
|
||||||
const char* adbSerial = NULL;
|
const char* adbSerial = NULL;
|
||||||
pid_t childPid = -1;
|
pid_t childPid = -1;
|
||||||
vector<string> sections;
|
vector<string> sections;
|
||||||
const char* privacy = NULL;
|
const char* privacy = NULL;
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
while ((opt = getopt(argc, argv, "bhi:o:s:twp:")) != -1) {
|
while ((opt = getopt(argc, argv, "bhi:o:r:s:twp:")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'b':
|
case 'b':
|
||||||
outputFormat = OUTPUT_PROTO;
|
outputFormat = OUTPUT_PROTO;
|
||||||
@@ -324,6 +326,9 @@ main(int argc, char** argv)
|
|||||||
case 'o':
|
case 'o':
|
||||||
outFilename = optarg;
|
outFilename = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'r':
|
||||||
|
reason = optarg;
|
||||||
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
adbSerial = optarg;
|
adbSerial = optarg;
|
||||||
break;
|
break;
|
||||||
@@ -376,7 +381,7 @@ main(int argc, char** argv)
|
|||||||
dup2(pfd[1], STDOUT_FILENO);
|
dup2(pfd[1], STDOUT_FILENO);
|
||||||
close(pfd[0]);
|
close(pfd[0]);
|
||||||
close(pfd[1]);
|
close(pfd[1]);
|
||||||
char const** args = (char const**)malloc(sizeof(char*) * (8 + sections.size()));
|
char const** args = (char const**)malloc(sizeof(char*) * (10 + sections.size()));
|
||||||
int argpos = 0;
|
int argpos = 0;
|
||||||
args[argpos++] = "adb";
|
args[argpos++] = "adb";
|
||||||
if (adbSerial != NULL) {
|
if (adbSerial != NULL) {
|
||||||
@@ -389,6 +394,10 @@ main(int argc, char** argv)
|
|||||||
args[argpos++] = "-p";
|
args[argpos++] = "-p";
|
||||||
args[argpos++] = privacy;
|
args[argpos++] = privacy;
|
||||||
}
|
}
|
||||||
|
if (reason != NULL) {
|
||||||
|
args[argpos++] = "-r";
|
||||||
|
args[argpos++] = reason;
|
||||||
|
}
|
||||||
for (vector<string>::const_iterator it=sections.begin(); it!=sections.end(); it++) {
|
for (vector<string>::const_iterator it=sections.begin(); it!=sections.end(); it++) {
|
||||||
args[argpos++] = it->c_str();
|
args[argpos++] = it->c_str();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user