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

@@ -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);
}
}