use of org.acra.model.ComplexElement in project acra by ACRA.
the class ConfigurationCollector method configToElement.
/**
* Creates an Element listing all values human readable
* from the provided Configuration instance.
*
* @param conf The Configuration to be described.
* @return An Element describing all the fields of the given Configuration,
* with values replaced by constant names.
*/
@NonNull
private static Element configToElement(@NonNull Configuration conf) {
final ComplexElement result = new ComplexElement();
Map<String, SparseArray<String>> valueArrays = getValueArrays();
for (final Field f : conf.getClass().getFields()) {
try {
if (!Modifier.isStatic(f.getModifiers())) {
final String fieldName = f.getName();
try {
if (f.getType().equals(int.class)) {
result.put(fieldName, getFieldValueName(valueArrays, conf, f));
} else if (f.get(conf) != null) {
result.put(fieldName, f.get(conf));
}
} catch (JSONException e) {
ACRA.log.w(LOG_TAG, "Could not collect configuration field " + fieldName, e);
}
}
} catch (@NonNull IllegalArgumentException e) {
ACRA.log.e(LOG_TAG, "Error while inspecting device configuration: ", e);
} catch (@NonNull IllegalAccessException e) {
ACRA.log.e(LOG_TAG, "Error while inspecting device configuration: ", e);
}
}
return result;
}
use of org.acra.model.ComplexElement in project acra by ACRA.
the class DeviceFeaturesCollector method collect.
/**
* collects device features
*
* @param reportField the ReportField to collect
* @param reportBuilder the current reportBuilder
* @return Element of all device feature names
*/
@NonNull
@Override
Element collect(ReportField reportField, ReportBuilder reportBuilder) {
final ComplexElement result = new ComplexElement();
try {
final PackageManager pm = context.getPackageManager();
final FeatureInfo[] features = pm.getSystemAvailableFeatures();
for (final FeatureInfo feature : features) {
final String featureName = feature.name;
if (featureName != null) {
result.put(featureName, true);
} else {
result.put("glEsVersion", feature.getGlEsVersion());
}
}
} catch (Throwable e) {
ACRA.log.w(LOG_TAG, "Couldn't retrieve DeviceFeatures for " + context.getPackageName(), e);
}
return result;
}
use of org.acra.model.ComplexElement in project acra by ACRA.
the class SettingsCollector method collectGlobalSettings.
/**
* Collect data from {@link Global}. This
* collector uses reflection to be sure to always get the most accurate data
* whatever Android API level it runs on.
*
* @return collected key-value pairs.
*/
@NonNull
private Element collectGlobalSettings() throws JSONException {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
return ACRAConstants.NOT_AVAILABLE;
}
final ComplexElement result = new ComplexElement();
final Field[] keys = Global.class.getFields();
for (final Field key : keys) {
if (!key.isAnnotationPresent(Deprecated.class) && key.getType() == String.class && isAuthorized(key)) {
try {
final Object value = Global.getString(context.getContentResolver(), (String) key.get(null));
if (value != null) {
result.put(key.getName(), value);
}
} catch (@NonNull IllegalArgumentException e) {
ACRA.log.w(LOG_TAG, ERROR, e);
} catch (@NonNull SecurityException e) {
ACRA.log.w(LOG_TAG, ERROR, e);
} catch (@NonNull IllegalAccessException e) {
ACRA.log.w(LOG_TAG, ERROR, e);
}
}
}
return result;
}
use of org.acra.model.ComplexElement in project acra by ACRA.
the class SettingsCollector method collectSystemSettings.
/**
* Collect data from {@link System}. This
* collector uses reflection to be sure to always get the most accurate data
* whatever Android API level it runs on.
*
* @return collected key-value pairs.
*/
@NonNull
private Element collectSystemSettings() throws JSONException {
final ComplexElement result = new ComplexElement();
final Field[] keys = System.class.getFields();
for (final Field key : keys) {
// logcat.
if (!key.isAnnotationPresent(Deprecated.class) && key.getType() == String.class) {
try {
final Object value = System.getString(context.getContentResolver(), (String) key.get(null));
if (value != null) {
result.put(key.getName(), value);
}
} catch (@NonNull IllegalArgumentException e) {
ACRA.log.w(LOG_TAG, ERROR, e);
} catch (@NonNull IllegalAccessException e) {
ACRA.log.w(LOG_TAG, ERROR, e);
}
}
}
return result;
}
use of org.acra.model.ComplexElement in project acra by ACRA.
the class SettingsCollector method collectSecureSettings.
/**
* Collect data from {@link Secure}. This
* collector uses reflection to be sure to always get the most accurate data
* whatever Android API level it runs on.
*
* @return collected key-value pairs.
*/
@NonNull
private Element collectSecureSettings() throws JSONException {
final ComplexElement result = new ComplexElement();
final Field[] keys = Secure.class.getFields();
for (final Field key : keys) {
if (!key.isAnnotationPresent(Deprecated.class) && key.getType() == String.class && isAuthorized(key)) {
try {
final Object value = Secure.getString(context.getContentResolver(), (String) key.get(null));
if (value != null) {
result.put(key.getName(), value);
}
} catch (@NonNull IllegalArgumentException e) {
ACRA.log.w(LOG_TAG, ERROR, e);
} catch (@NonNull IllegalAccessException e) {
ACRA.log.w(LOG_TAG, ERROR, e);
}
}
}
return result;
}
Aggregations