use of org.acra.model.ComplexElement in project acra by ACRA.
the class SharedPreferencesCollector method collect.
/**
* Collects all key/value pairs in SharedPreferences.
* The application default SharedPreferences are always
* collected, and the developer can provide additional SharedPreferences
* names in the {@link ReportsCrashes#additionalSharedPreferences()}
* configuration item.
*
* @return the collected key/value pairs.
*/
@NonNull
private Element collect() throws JSONException {
final ComplexElement result = new ComplexElement();
// Include the default SharedPreferences
final Map<String, SharedPreferences> sharedPrefs = new TreeMap<String, SharedPreferences>();
sharedPrefs.put("default", PreferenceManager.getDefaultSharedPreferences(context));
// Add in any additional SharedPreferences
for (final String sharedPrefId : config.additionalSharedPreferences()) {
sharedPrefs.put(sharedPrefId, context.getSharedPreferences(sharedPrefId, Context.MODE_PRIVATE));
}
// Iterate over all included preference files and add the preferences from each.
for (Map.Entry<String, SharedPreferences> entry : sharedPrefs.entrySet()) {
final String sharedPrefId = entry.getKey();
final SharedPreferences prefs = entry.getValue();
final Map<String, ?> prefEntries = prefs.getAll();
// Show that we have no preferences saved for that preference file.
if (prefEntries.isEmpty()) {
result.put(sharedPrefId, "empty");
} else {
for (Iterator<String> iterator = prefEntries.keySet().iterator(); iterator.hasNext(); ) {
if (filteredKey(iterator.next())) {
iterator.remove();
}
}
result.put(sharedPrefId, new JSONObject(prefEntries));
}
}
return result;
}
use of org.acra.model.ComplexElement in project acra by ACRA.
the class JsonUtils method toCrashReportData.
public static CrashReportData toCrashReportData(JSONObject json) {
CrashReportData data = new CrashReportData();
for (Iterator<String> iterator = json.keys(); iterator.hasNext(); ) {
String key = iterator.next();
try {
ReportField field = ReportField.valueOf(key);
Object value = json.get(key);
if (value instanceof JSONObject) {
data.put(field, new ComplexElement((JSONObject) value));
} else if (value instanceof Number) {
data.putNumber(field, (Number) value);
} else if (value instanceof Boolean) {
data.putBoolean(field, (Boolean) value);
} else {
data.putString(field, value.toString());
}
} catch (IllegalArgumentException e) {
Log.w(LOG_TAG, "Unknown report key " + key, e);
} catch (JSONException e) {
Log.w(LOG_TAG, "Unable to read report field " + key, e);
}
}
return data;
}
Aggregations