<commit_before>package com.datatheorem.android.trustkit.report;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.preference.PreferenceManager;

import com.datatheorem.android.trustkit.BuildConfig;
import com.datatheorem.android.trustkit.PinValidationResult;
import com.datatheorem.android.trustkit.TrustKit;
import com.datatheorem.android.trustkit.config.ConfigException;
import com.datatheorem.android.trustkit.utils.TrustKitLog;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Date;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.UUID;


/**
 * The BackgroundReporter save a report when a pinning validation fail and send the report
 * to the specific URI.
 */
public final class BackgroundReporter{
    private final String TRUSTKIT_VENDOR_ID = "TRUSTKIT_VENDOR_ID";
    private final String DEFAULT_REPORTING_URL_STRING =
            "https://overmind.datatheorem.com/trustkit/report";
    private final URL DEFAULT_REPORTING_URL;

    // Main application environment information
    private String appPackageName;
    private String appVersion;
    private String appVendorId;
    private String appPlatform;

    // Configuration and Objects managing all the operation done by the BackgroundReporter
    private boolean shouldRateLimitsReports;
    private final PinFailureReportHttpSender pinFailureReportHttpSender;
    private final PinFailureReportInternalSender pinFailureReportInternalSender;


    public BackgroundReporter(boolean shouldRateLimitsReports, String broadcastIdentifier)
            throws MalformedURLException {
        Context appContext = TrustKit.getInstance().getAppContext();
        this.shouldRateLimitsReports = shouldRateLimitsReports;
        this.pinFailureReportHttpSender = new PinFailureReportHttpSender();
        this.pinFailureReportInternalSender = new PinFailureReportInternalSender(appContext,
                broadcastIdentifier);


        this.appPlatform = "ANDROID";
        this.appPackageName = appContext.getPackageName();

        try {
            this.appVersion =
                    appContext.getPackageManager().getPackageInfo(appPackageName, 0).versionName;

        } catch (PackageManager.NameNotFoundException e) {
            this.appVersion = "N/A";
        }

        SharedPreferences trustKitSharedPreferences =
                PreferenceManager.getDefaultSharedPreferences(appContext);
        String appVendorId = trustKitSharedPreferences.getString(TRUSTKIT_VENDOR_ID, "");
        if (!appVendorId.equals("")) {
            this.appVendorId = appVendorId;
        } else {
            this.appVendorId = UUID.randomUUID().toString();<commit_msg>Switch to static initializer for default report URL<commit_after>package com.datatheorem.android.trustkit.report;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.preference.PreferenceManager;

import com.datatheorem.android.trustkit.BuildConfig;
import com.datatheorem.android.trustkit.PinValidationResult;
import com.datatheorem.android.trustkit.TrustKit;
import com.datatheorem.android.trustkit.utils.TrustKitLog;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Date;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.UUID;


/**
 * The BackgroundReporter save a report when a pinning validation fail and send the report
 * to the specific URI.
 */
public final class BackgroundReporter {
    private static final String TRUSTKIT_VENDOR_ID = "TRUSTKIT_VENDOR_ID";
    private static final URL DEFAULT_REPORTING_URL;
    static {
        java.net.URL defaultUrl;
        try {
            defaultUrl = new java.net.URL("https://overmind.datatheorem.com/trustkit/report");
        } catch (java.net.MalformedURLException e) {
            throw new IllegalStateException("Bad DEFAULT_REPORTING_URL");
        }
        DEFAULT_REPORTING_URL = defaultUrl;
    }

    private static final String appPlatform = "ANDROID";

    // Main application environment information
    private String appPackageName;
    private String appVersion;
    private String appVendorId;

    // Configuration and Objects managing all the operation done by the BackgroundReporter
    private boolean shouldRateLimitsReports;
    private final PinFailureReportHttpSender pinFailureReportHttpSender;
    private final PinFailureReportInternalSender pinFailureReportInternalSender;


    public BackgroundReporter(boolean shouldRateLimitsReports, String broadcastIdentifier) {
        Context appContext = TrustKit.getInstance().getAppContext();
        this.shouldRateLimitsReports = shouldRateLimitsReports;
        this.pinFailureReportHttpSender = new PinFailureReportHttpSender();
        this.pinFailureReportInternalSender = new PinFailureReportInternalSender(appContext,
                broadcastIdentifier);

        this.appPackageName = appContext.getPackageName();

        try {
            this.appVersion =
                    appContext.getPackageManager().getPackageInfo(appPackageName, 0).versionName;

        } catch (PackageManager.NameNotFoundException e) {
            this.appVersion = "N/A";
        }

        SharedPreferences trustKitSharedPreferences =
                PreferenceManager.getDefaultSharedPreferences(appContext);
        String appVendorId = trustKitSharedPreferences.getString(TRUSTKIT_VENDOR_ID, "");
        if (!appVendorId.equals("")) {
            this.appVendorId = appVendorId;
        } else {
            this.appVendorId = UUID.randomUUID().toString();
{'fraction_non_alphanumeric': 0.07363872082973207, 'fraction_numerical': 0.00034572169403630077, 'mean_word_length': 3.845896147403685, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5664466', 'n_tokens_mistral': 1527, 'n_tokens_neox': 1488, 'n_words': 326}