Fix parsing enum types in incident report tool as well as adding

some additional loggings

Test: manually flashed to device and test calling IncidentManager.java
functions
Change-Id: I69610414edde865b20ba632837f037fbe43f99db
This commit is contained in:
Yi Jin
2017-08-11 15:00:49 -07:00
parent ef2d2c6060
commit f32af48069
6 changed files with 37 additions and 33 deletions

View File

@@ -54,9 +54,7 @@ LOCAL_SHARED_LIBRARIES := \
libservices \
libutils
ifeq (BUILD_WITH_INCIDENTD_RC,true)
LOCAL_INIT_RC := incidentd.rc
endif
include $(BUILD_EXECUTABLE)

View File

@@ -225,9 +225,8 @@ Reporter::runReport()
// and report to those that care that we're doing it.
for (const Section** section=SECTION_LIST; *section; section++) {
const int id = (*section)->id;
ALOGD("Taking incident report section %d '%s'", id, (*section)->name.string());
if (this->batch.containsSection(id)) {
ALOGD("Taking incident report section %d '%s'", id, (*section)->name.string());
// Notify listener of starting
for (ReportRequestSet::iterator it=batch.begin(); it!=batch.end(); it++) {
if ((*it)->listener != NULL && (*it)->args.containsSection(id)) {
@@ -251,6 +250,7 @@ Reporter::runReport()
IIncidentReportStatusListener::STATUS_FINISHED);
}
}
ALOGD("Finish incident report section %d '%s'", id, (*section)->name.string());
}
}
@@ -324,6 +324,7 @@ Reporter::upload_backlog()
struct stat st;
status_t err;
ALOGD("Start uploading backlogs in %s", INCIDENT_DIRECTORY);
if ((err = create_directory(INCIDENT_DIRECTORY)) != NO_ERROR) {
ALOGE("directory doesn't exist: %s", strerror(-err));
return REPORT_FINISHED;
@@ -337,6 +338,7 @@ Reporter::upload_backlog()
sp<DropBoxManager> dropbox = new DropBoxManager();
// Enumerate, count and add up size
int count = 0;
while ((entry = readdir(dir)) != NULL) {
if (entry->d_name[0] == '.') {
continue;
@@ -360,8 +362,9 @@ Reporter::upload_backlog()
// boot or the next checkin. If the directory gets too big older files will
// be rotated out.
unlink(filename.string());
count++;
}
ALOGD("Successfully uploaded %d files to Dropbox.", count);
closedir(dir);
return REPORT_FINISHED;

View File

@@ -21,8 +21,6 @@ import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.content.Context;
import android.os.IIncidentManager;
import android.os.ServiceManager;
import android.provider.Settings;
import android.util.Slog;
@@ -37,7 +35,7 @@ import android.util.Slog;
public class IncidentManager {
private static final String TAG = "incident";
private Context mContext;
private final Context mContext;
/**
* @hide
@@ -54,18 +52,7 @@ public class IncidentManager {
android.Manifest.permission.PACKAGE_USAGE_STATS
})
public void reportIncident(IncidentReportArgs args) {
final IIncidentManager service = IIncidentManager.Stub.asInterface(
ServiceManager.getService("incident"));
if (service == null) {
Slog.e(TAG, "reportIncident can't find incident binder service");
return;
}
try {
service.reportIncident(args);
} catch (RemoteException ex) {
Slog.e(TAG, "reportIncident failed", ex);
}
reportIncidentInternal(args);
}
/**
@@ -89,7 +76,7 @@ public class IncidentManager {
})
public void reportIncident(String settingName, byte[] headerProto) {
// Sections
String setting = Settings.System.getString(mContext.getContentResolver(), settingName);
String setting = Settings.Global.getString(mContext.getContentResolver(), settingName);
IncidentReportArgs args;
try {
args = IncidentReportArgs.parseSetting(setting);
@@ -98,23 +85,25 @@ public class IncidentManager {
return;
}
if (args == null) {
Slog.i(TAG, "Incident report requested but disabled: " + settingName);
Slog.i(TAG, String.format("Incident report requested but disabled with "
+ "settings [name: %s, value: %s]", settingName, setting));
return;
}
// Header
args.addHeader(headerProto);
// Look up the service
Slog.i(TAG, "Taking incident report: " + settingName);
reportIncidentInternal(args);
}
private void reportIncidentInternal(IncidentReportArgs args) {
final IIncidentManager service = IIncidentManager.Stub.asInterface(
ServiceManager.getService("incident"));
ServiceManager.getService(Context.INCIDENT_SERVICE));
if (service == null) {
Slog.e(TAG, "reportIncident can't find incident binder service");
return;
}
// Call the service
Slog.i(TAG, "Taking incident report: " + settingName);
try {
service.reportIncident(args);
} catch (RemoteException ex) {

View File

@@ -18,7 +18,6 @@ package android.os;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.content.Intent;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.IntArray;
@@ -50,10 +49,12 @@ public final class IncidentReportArgs implements Parcelable {
readFromParcel(in);
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeInt(mAll ? 1 : 0);
@@ -100,6 +101,7 @@ public final class IncidentReportArgs implements Parcelable {
/**
* Print this report as a string.
*/
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("Incident(");
if (mAll) {
@@ -131,10 +133,11 @@ public final class IncidentReportArgs implements Parcelable {
}
/**
* Add this section to the incident report.
* Add this section to the incident report. Skip if the input is smaller than 2 since section
* id are only valid for positive integer as Protobuf field id. Here 1 is reserved for Header.
*/
public void addSection(int section) {
if (!mAll) {
if (!mAll && section > 1) {
mSections.add(section);
}
}

View File

@@ -1842,7 +1842,7 @@ public final class SystemServer {
// TODO: Switch from checkService to getService once it's always
// in the build and should reliably be there.
final IIncidentManager incident = IIncidentManager.Stub.asInterface(
ServiceManager.checkService("incident"));
ServiceManager.getService(Context.INCIDENT_SERVICE));
if (incident != null) incident.systemRunning();
} catch (Throwable e) {
reportWtf("Notifying incident daemon running", e);

View File

@@ -97,6 +97,8 @@ read_message(CodedInputStream* in, Descriptor const* descriptor, GenericMessage*
message->addInt64(fieldId, value64);
break;
} else {
fprintf(stderr, "bad VARINT: 0x%x (%d) at index %d\n", tag, tag,
in->CurrentPosition());
return false;
}
case WireFormatLite::WIRETYPE_FIXED64:
@@ -104,10 +106,14 @@ read_message(CodedInputStream* in, Descriptor const* descriptor, GenericMessage*
message->addInt64(fieldId, value64);
break;
} else {
fprintf(stderr, "bad VARINT: 0x%x (%d) at index %d\n", tag, tag,
in->CurrentPosition());
return false;
}
case WireFormatLite::WIRETYPE_LENGTH_DELIMITED:
if (!read_length_delimited(in, fieldId, descriptor, message)) {
fprintf(stderr, "bad LENGTH_DELIMITED: 0x%x (%d) at index %d\n",
tag, tag, in->CurrentPosition());
return false;
}
break;
@@ -116,6 +122,8 @@ read_message(CodedInputStream* in, Descriptor const* descriptor, GenericMessage*
message->addInt32(fieldId, value32);
break;
} else {
fprintf(stderr, "bad FIXED32: 0x%x (%d) at index %d\n", tag, tag,
in->CurrentPosition());
return false;
}
default:
@@ -146,7 +154,7 @@ print_value(Out* out, FieldDescriptor const* field, GenericMessage::Node const&
out->printf("%f", *(float*)&node.value32);
break;
default:
out->printf("(unexpected value %d (0x%x)", node.value32, node.value32);
out->printf("(unexpected value32 %d (0x%x)", node.value32, node.value32);
break;
}
break;
@@ -177,8 +185,11 @@ print_value(Out* out, FieldDescriptor const* field, GenericMessage::Node const&
}
break;
case FieldDescriptor::TYPE_ENUM:
out->printf("%s", field->enum_type()->FindValueByNumber((int)node.value64)
->name().c_str());
break;
default:
out->printf("(unexpected value %ld (0x%x))", node.value64, node.value64);
out->printf("(unexpected value64 %ld (0x%x))", node.value64, node.value64);
break;
}
break;