Skip to content

Commit

Permalink
Add BuildConfig collector
Browse files Browse the repository at this point in the history
Add a new collector the reports the values of the constants defined on the application's BuildConfig class. This class contains customizable information with the new gradle build system.
  • Loading branch information
npombourcq committed Jan 21, 2014
1 parent a1e32f3 commit a0d54cc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 70 deletions.
35 changes: 3 additions & 32 deletions src/main/java/org/acra/ACRAConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,10 @@
*/
package org.acra;

import static org.acra.ReportField.ANDROID_VERSION;
import static org.acra.ReportField.APP_VERSION_CODE;
import static org.acra.ReportField.APP_VERSION_NAME;
import static org.acra.ReportField.AVAILABLE_MEM_SIZE;
import static org.acra.ReportField.BRAND;
import static org.acra.ReportField.BUILD;
import static org.acra.ReportField.CRASH_CONFIGURATION;
import static org.acra.ReportField.CUSTOM_DATA;
import static org.acra.ReportField.DEVICE_FEATURES;
import static org.acra.ReportField.DISPLAY;
import static org.acra.ReportField.DUMPSYS_MEMINFO;
import static org.acra.ReportField.ENVIRONMENT;
import static org.acra.ReportField.FILE_PATH;
import static org.acra.ReportField.INITIAL_CONFIGURATION;
import static org.acra.ReportField.INSTALLATION_ID;
import static org.acra.ReportField.IS_SILENT;
import static org.acra.ReportField.LOGCAT;
import static org.acra.ReportField.PACKAGE_NAME;
import static org.acra.ReportField.PHONE_MODEL;
import static org.acra.ReportField.PRODUCT;
import static org.acra.ReportField.REPORT_ID;
import static org.acra.ReportField.SETTINGS_GLOBAL;
import static org.acra.ReportField.SETTINGS_SECURE;
import static org.acra.ReportField.SETTINGS_SYSTEM;
import static org.acra.ReportField.SHARED_PREFERENCES;
import static org.acra.ReportField.STACK_TRACE;
import static org.acra.ReportField.TOTAL_MEM_SIZE;
import static org.acra.ReportField.USER_APP_START_DATE;
import static org.acra.ReportField.USER_COMMENT;
import static org.acra.ReportField.USER_CRASH_DATE;
import static org.acra.ReportField.USER_EMAIL;
import android.content.Context;

import static org.acra.ReportField.*;

/**
* Responsible for collating those constants shared among the ACRA components.
* <p/>
Expand Down Expand Up @@ -161,7 +132,7 @@ public final class ACRAConstants {
*/
public static final ReportField[] DEFAULT_REPORT_FIELDS = { REPORT_ID, APP_VERSION_CODE, APP_VERSION_NAME,
PACKAGE_NAME, FILE_PATH, PHONE_MODEL, BRAND, PRODUCT, ANDROID_VERSION, BUILD, TOTAL_MEM_SIZE,
AVAILABLE_MEM_SIZE, CUSTOM_DATA, IS_SILENT, STACK_TRACE, INITIAL_CONFIGURATION, CRASH_CONFIGURATION,
AVAILABLE_MEM_SIZE, BUILD_CONFIG, CUSTOM_DATA, IS_SILENT, STACK_TRACE, INITIAL_CONFIGURATION, CRASH_CONFIGURATION,
DISPLAY, USER_COMMENT, USER_EMAIL, USER_APP_START_DATE, USER_CRASH_DATE, DUMPSYS_MEMINFO, LOGCAT,
INSTALLATION_ID, DEVICE_FEATURES, ENVIRONMENT, SHARED_PREFERENCES, SETTINGS_SYSTEM, SETTINGS_SECURE,
SETTINGS_GLOBAL };
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/acra/ReportField.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ public boolean containsKeyValuePairs() {
* Estimation of the available device memory size based on filesystem stats.
*/
AVAILABLE_MEM_SIZE,
/**
* Contains key = value pairs defined by the application developer during
* the application build.
*/
BUILD_CONFIG {
@Override
public boolean containsKeyValuePairs() {
return true;
}
},
/**
* Contains key = value pairs defined by the application developer during
* the application execution.
Expand Down
47 changes: 10 additions & 37 deletions src/main/java/org/acra/collector/CrashReportDataFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,7 @@
package org.acra.collector;

import static org.acra.ACRA.LOG_TAG;
import static org.acra.ReportField.ANDROID_VERSION;
import static org.acra.ReportField.APPLICATION_LOG;
import static org.acra.ReportField.APP_VERSION_CODE;
import static org.acra.ReportField.APP_VERSION_NAME;
import static org.acra.ReportField.AVAILABLE_MEM_SIZE;
import static org.acra.ReportField.BRAND;
import static org.acra.ReportField.BUILD;
import static org.acra.ReportField.CRASH_CONFIGURATION;
import static org.acra.ReportField.CUSTOM_DATA;
import static org.acra.ReportField.DEVICE_FEATURES;
import static org.acra.ReportField.DEVICE_ID;
import static org.acra.ReportField.DISPLAY;
import static org.acra.ReportField.DROPBOX;
import static org.acra.ReportField.DUMPSYS_MEMINFO;
import static org.acra.ReportField.ENVIRONMENT;
import static org.acra.ReportField.EVENTSLOG;
import static org.acra.ReportField.FILE_PATH;
import static org.acra.ReportField.INITIAL_CONFIGURATION;
import static org.acra.ReportField.INSTALLATION_ID;
import static org.acra.ReportField.IS_SILENT;
import static org.acra.ReportField.LOGCAT;
import static org.acra.ReportField.MEDIA_CODEC_LIST;
import static org.acra.ReportField.PACKAGE_NAME;
import static org.acra.ReportField.PHONE_MODEL;
import static org.acra.ReportField.PRODUCT;
import static org.acra.ReportField.RADIOLOG;
import static org.acra.ReportField.REPORT_ID;
import static org.acra.ReportField.SETTINGS_SECURE;
import static org.acra.ReportField.SETTINGS_SYSTEM;
import static org.acra.ReportField.SETTINGS_GLOBAL;
import static org.acra.ReportField.SHARED_PREFERENCES;
import static org.acra.ReportField.STACK_TRACE;
import static org.acra.ReportField.THREAD_DETAILS;
import static org.acra.ReportField.TOTAL_MEM_SIZE;
import static org.acra.ReportField.USER_CRASH_DATE;
import static org.acra.ReportField.USER_EMAIL;
import static org.acra.ReportField.USER_IP;
import static org.acra.ReportField.*;

import java.io.FileNotFoundException;
import java.io.IOException;
Expand Down Expand Up @@ -257,6 +221,15 @@ public CrashReportData createCrashData(Throwable th, boolean isSilentReport, Thr
crashReportData.put(CUSTOM_DATA, createCustomInfoString());
}

if (crashReportFields.contains(BUILD_CONFIG)) {
String className = context.getPackageName() + ".BuildConfig";
try {
Class<?> buildConfig = Class.forName(className);
crashReportData.put(BUILD_CONFIG, ReflectionCollector.collectConstants(buildConfig));
} catch (ClassNotFoundException e) {
}
}

// Add user email address, if set in the app's preferences
if (crashReportFields.contains(USER_EMAIL)) {
crashReportData.put(USER_EMAIL, prefs.getString(ACRA.PREF_USER_EMAIL_ADDRESS, "N/A"));
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/acra/collector/ReflectionCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public static String collectConstants(Class<?> someClass, String prefix) {
}
result.append(field.getName()).append("=");
try {
result.append(field.get(null).toString());
Object value = field.get(null);
if (value != null)
result.append(value.toString());
} catch (IllegalArgumentException e) {
result.append("N/A");
} catch (IllegalAccessException e) {
Expand Down

0 comments on commit a0d54cc

Please sign in to comment.