Search in sources :

Example 6 with ComplexElement

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;
}
Also used : Field(java.lang.reflect.Field) ReportField(org.acra.ReportField) SparseArray(android.util.SparseArray) JSONException(org.json.JSONException) ComplexElement(org.acra.model.ComplexElement) NonNull(android.support.annotation.NonNull)

Example 7 with ComplexElement

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;
}
Also used : PackageManager(android.content.pm.PackageManager) FeatureInfo(android.content.pm.FeatureInfo) ComplexElement(org.acra.model.ComplexElement) NonNull(android.support.annotation.NonNull)

Example 8 with ComplexElement

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;
}
Also used : Field(java.lang.reflect.Field) ReportField(org.acra.ReportField) ComplexElement(org.acra.model.ComplexElement) NonNull(android.support.annotation.NonNull)

Example 9 with ComplexElement

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;
}
Also used : Field(java.lang.reflect.Field) ReportField(org.acra.ReportField) ComplexElement(org.acra.model.ComplexElement) NonNull(android.support.annotation.NonNull)

Example 10 with ComplexElement

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;
}
Also used : Field(java.lang.reflect.Field) ReportField(org.acra.ReportField) ComplexElement(org.acra.model.ComplexElement) NonNull(android.support.annotation.NonNull)

Aggregations

ComplexElement (org.acra.model.ComplexElement)12 NonNull (android.support.annotation.NonNull)11 ReportField (org.acra.ReportField)6 JSONException (org.json.JSONException)5 Field (java.lang.reflect.Field)4 JSONObject (org.json.JSONObject)4 CrashReportData (org.acra.collector.CrashReportData)2 TargetApi (android.annotation.TargetApi)1 SharedPreferences (android.content.SharedPreferences)1 FeatureInfo (android.content.pm.FeatureInfo)1 PackageManager (android.content.pm.PackageManager)1 MediaCodecInfo (android.media.MediaCodecInfo)1 MediaCodecList (android.media.MediaCodecList)1 Build (android.os.Build)1 DropBoxManager (android.os.DropBoxManager)1 SparseArray (android.util.SparseArray)1 BufferedReader (java.io.BufferedReader)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Map (java.util.Map)1