Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move logcat collection to prevent pollution during crash data gathering #339

Merged
merged 1 commit into from
Dec 16, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 44 additions & 43 deletions src/main/java/org/acra/collector/CrashReportDataFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,49 @@ public CrashReportData createCrashData(String msg, Throwable th, Map<String, Str
ACRA.log.e(LOG_TAG, "Error while retrieving STACK_TRACE data", e);
}

// Collect DropBox and logcat. This is done first because some ROMs spam the log with every get on
// Settings.
final PackageManagerWrapper pm = new PackageManagerWrapper(context);

// Before JellyBean, this required the READ_LOGS permission
// Since JellyBean, READ_LOGS is not granted to third-party apps anymore for security reasons.
// Though, we can call logcat without any permission and still get traces related to our app.
final boolean hasReadLogsPermission = pm.hasPermission(Manifest.permission.READ_LOGS) || (Compatibility.getAPILevel() >= Compatibility.VERSION_CODES.JELLY_BEAN);
if (prefs.getBoolean(ACRA.PREF_ENABLE_SYSTEM_LOGS, true) && hasReadLogsPermission) {
ACRA.log.i(LOG_TAG, "READ_LOGS granted! ACRA can include LogCat and DropBox data.");
if (crashReportFields.contains(LOGCAT)) {
try {
crashReportData.put(LOGCAT, LogCatCollector.collectLogCat(null));
} catch (RuntimeException e){
ACRA.log.e(LOG_TAG, "Error while retrieving LOGCAT data", e);
}
}
if (crashReportFields.contains(EVENTSLOG)) {
try {
crashReportData.put(EVENTSLOG, LogCatCollector.collectLogCat("events"));
} catch (RuntimeException e){
ACRA.log.e(LOG_TAG, "Error while retrieving EVENTSLOG data", e);
}
}
if (crashReportFields.contains(RADIOLOG)) {
try {
crashReportData.put(RADIOLOG, LogCatCollector.collectLogCat("radio"));
} catch (RuntimeException e){
ACRA.log.e(LOG_TAG, "Error while retrieving RADIOLOG data", e);
}
}
if (crashReportFields.contains(DROPBOX)) {
try {
crashReportData.put(DROPBOX,
DropBoxCollector.read(context, ACRA.getConfig().additionalDropBoxTags()));
} catch (RuntimeException e){
ACRA.log.e(LOG_TAG, "Error while retrieving DROPBOX data", e);
}
}
} else {
ACRA.log.i(LOG_TAG, "READ_LOGS not allowed. ACRA will not include LogCat and DropBox data.");
}

try {
crashReportData.put(ReportField.USER_APP_START_DATE, ReportUtils.getTimeString(appStartDate));
} catch (RuntimeException e){
Expand Down Expand Up @@ -389,10 +432,8 @@ public CrashReportData createCrashData(String msg, Throwable th, Map<String, Str
}
}

// Now get all the crash data that relies on the PackageManager
// Now get all the crash data that relies on the PackageManager.getPackageInfo()
// (which may or may not be here).
final PackageManagerWrapper pm = new PackageManagerWrapper(context);

try {
final PackageInfo pi = pm.getPackageInfo();
if (pi != null) {
Expand Down Expand Up @@ -424,46 +465,6 @@ public CrashReportData createCrashData(String msg, Throwable th, Map<String, Str
}
}

// Collect DropBox and logcat
// Before JellyBean, this required the READ_LOGS permission
// Since JellyBean, READ_LOGS is not granted to third-party apps anymore for security reasons.
// Though, we can call logcat without any permission and still get traces related to our app.
final boolean hasReadLogsPermission = pm.hasPermission(Manifest.permission.READ_LOGS) || (Compatibility.getAPILevel() >= Compatibility.VERSION_CODES.JELLY_BEAN);
if (prefs.getBoolean(ACRA.PREF_ENABLE_SYSTEM_LOGS, true) && hasReadLogsPermission) {
ACRA.log.i(LOG_TAG, "READ_LOGS granted! ACRA can include LogCat and DropBox data.");
if (crashReportFields.contains(LOGCAT)) {
try {
crashReportData.put(LOGCAT, LogCatCollector.collectLogCat(null));
} catch (RuntimeException e){
ACRA.log.e(LOG_TAG, "Error while retrieving LOGCAT data", e);
}
}
if (crashReportFields.contains(EVENTSLOG)) {
try {
crashReportData.put(EVENTSLOG, LogCatCollector.collectLogCat("events"));
} catch (RuntimeException e){
ACRA.log.e(LOG_TAG, "Error while retrieving EVENTSLOG data", e);
}
}
if (crashReportFields.contains(RADIOLOG)) {
try {
crashReportData.put(RADIOLOG, LogCatCollector.collectLogCat("radio"));
} catch (RuntimeException e){
ACRA.log.e(LOG_TAG, "Error while retrieving RADIOLOG data", e);
}
}
if (crashReportFields.contains(DROPBOX)) {
try {
crashReportData.put(DROPBOX,
DropBoxCollector.read(context, ACRA.getConfig().additionalDropBoxTags()));
} catch (RuntimeException e){
ACRA.log.e(LOG_TAG, "Error while retrieving DROPBOX data", e);
}
}
} else {
ACRA.log.i(LOG_TAG, "READ_LOGS not allowed. ACRA will not include LogCat and DropBox data.");
}

// Application specific log file
if (crashReportFields.contains(APPLICATION_LOG)) {
try {
Expand Down