<commit_before>package org.adaptlab.chpir.android.participanttracker;

import java.util.List;
import java.util.UUID;

import org.adaptlab.chpir.android.activerecordcloudsync.ActiveRecordCloudSync;
import org.adaptlab.chpir.android.participanttracker.models.AdminSettings;
import org.adaptlab.chpir.android.participanttracker.models.Participant;
import org.adaptlab.chpir.android.participanttracker.models.ParticipantProperty;
import org.adaptlab.chpir.android.participanttracker.models.ParticipantType;
import org.adaptlab.chpir.android.participanttracker.models.Property;
import org.adaptlab.chpir.android.participanttracker.models.Relationship;
import org.adaptlab.chpir.android.participanttracker.models.RelationshipType;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;

import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.app.AlertDialog;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Log;

import com.activeandroid.ActiveAndroid;
import com.crashlytics.android.Crashlytics;

public class AppUtil {
    private final static boolean REQUIRE_SECURITY_CHECKS = true;
	private static final String TAG = "AppUtil";
	private static final boolean SEED_DB = false;
	public static String ADMIN_PASSWORD_HASH;
	public static String ACCESS_TOKEN;

	public static final void appInit(Context context) {
		
		if (AppUtil.REQUIRE_SECURITY_CHECKS) {
			if (!AppUtil.hasPassedDeviceSecurityChecks(context)) {
				return;
			}
		}
		
		ADMIN_PASSWORD_HASH = context.getResources().getString(R.string.admin_password_hash);
		ACCESS_TOKEN = AdminSettings.getInstance().getApiKey();
		
		if (!BuildConfig.DEBUG)
            Crashlytics.start(context);
		
		if (AdminSettings.getInstance().getDeviceIdentifier() == null) {
			AdminSettings.getInstance().setDeviceIdentifier(
					UUID.randomUUID().toString());
		}

		ActiveRecordCloudSync.setAccessToken(ACCESS_TOKEN);
		ActiveRecordCloudSync.setVersionCode(AppUtil.getVersionCode(context));
		ActiveRecordCloudSync.setEndPoint(getAdminSettingsInstanceApiUrl());
		addDataTables();
		seedDb();
	}
	
	public static String getAdminSettingsInstanceApiUrl() {
	    String domainName = AdminSettings.getInstance().getApiUrl();
		return domainName + "api/" + AdminSettings.getInstance().getApiVersion() + "/" ;
	}

	private static boolean hasPassedDeviceSecurityChecks(Context context) {
		DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
		if (devicePolicyManager.getStorageEncryptionStatus() != DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE) {
			new AlertDialog.Builder(context)
            .setTitle(R.string.encryption_required_title)
            .setMessage(R.string.encryption_required_text)
            .setCancelable(false)
            .setPositiveButton(R.string.okay, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    int pid = android.os.Process.myPid(); 
                    android.os.Process.killProcess(pid);
                }
             })
             .show();
            return false;
		}<commit_msg>Add user id and device label to metadata for crashlytics<commit_after>package org.adaptlab.chpir.android.participanttracker;

import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.app.AlertDialog;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Log;

import com.activeandroid.ActiveAndroid;
import com.crashlytics.android.Crashlytics;

import org.adaptlab.chpir.android.activerecordcloudsync.ActiveRecordCloudSync;
import org.adaptlab.chpir.android.participanttracker.models.AdminSettings;
import org.adaptlab.chpir.android.participanttracker.models.Participant;
import org.adaptlab.chpir.android.participanttracker.models.ParticipantProperty;
import org.adaptlab.chpir.android.participanttracker.models.ParticipantType;
import org.adaptlab.chpir.android.participanttracker.models.Property;
import org.adaptlab.chpir.android.participanttracker.models.Relationship;
import org.adaptlab.chpir.android.participanttracker.models.RelationshipType;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;

import java.util.List;
import java.util.UUID;

public class AppUtil {
    private final static boolean REQUIRE_SECURITY_CHECKS = false;
	private static final String TAG = "AppUtil";
	private static final boolean SEED_DB = false;
	public static String ADMIN_PASSWORD_HASH;
	public static String ACCESS_TOKEN;

	public static final void appInit(Context context) {
		
		if (AppUtil.REQUIRE_SECURITY_CHECKS) {
			if (!AppUtil.hasPassedDeviceSecurityChecks(context)) {
				return;
			}
		}
		
		ADMIN_PASSWORD_HASH = context.getResources().getString(R.string.admin_password_hash);
		ACCESS_TOKEN = AdminSettings.getInstance().getApiKey();
		
		if (AdminSettings.getInstance().getDeviceIdentifier() == null) {
			AdminSettings.getInstance().setDeviceIdentifier(
					UUID.randomUUID().toString());
		}
		
        if (!BuildConfig.DEBUG) {
            Crashlytics.start(context);
            Crashlytics.setUserIdentifier(AdminSettings.getInstance().getDeviceIdentifier());
            Crashlytics.setString("device label", AdminSettings.getInstance().getDeviceLabel());
        }

		ActiveRecordCloudSync.setAccessToken(ACCESS_TOKEN);
		ActiveRecordCloudSync.setVersionCode(AppUtil.getVersionCode(context));
		ActiveRecordCloudSync.setEndPoint(getAdminSettingsInstanceApiUrl());
		addDataTables();
		seedDb();
	}
	
	public static String getAdminSettingsInstanceApiUrl() {
	    String domainName = AdminSettings.getInstance().getApiUrl();
		return domainName + "api/" + AdminSettings.getInstance().getApiVersion() + "/" ;
	}

	private static boolean hasPassedDeviceSecurityChecks(Context context) {
		DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
		if (devicePolicyManager.getStorageEncryptionStatus() != DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE) {
			new AlertDialog.Builder(context)
            .setTitle(R.string.encryption_required_title)
            .setMessage(R.string.encryption_required_text)
            .setCancelable(false)
            .setPositiveButton(R.string.okay, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    int pid = android.os.Process.myPid(); 
                    android.os.Process.killProcess(pid);
                }
             })
             .show();
            return false;
		}
{'fraction_non_alphanumeric': 0.09455105757108839, 'fraction_numerical': 0.0, 'mean_word_length': 4.748792270531401, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '5147168', 'n_tokens_mistral': 2156, 'n_tokens_neox': 1981, 'n_words': 315}