<commit_before>package sc.shortcut.sdk.android.deeplinking;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.IntDef;
import android.util.Log;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import sc.shortcut.deeplinkingsdk.R;

/**
 * This class holds the configuration details for the SDK.
 */
public class SCConfig {

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({ENVIRONMENT_SANDBOX, ENVIRONMENT_PRODUCTION})
    public @interface Environment {}

    // Environment constants
    public static final int ENVIRONMENT_SANDBOX = 0;
    public static final int ENVIRONMENT_PRODUCTION = 1;

    private static final String AUTH_TOKEN_KEY = "sc.shortcut.sdk.deeplinking.authToken";
    private static final String ENVIRONMENT_KEY = "sc.shortcut.sdk.deeplinking.environment";
    private static final String LOG_LEVEL_KEY = "sc.shortcut.sdk.deeplinking.logLevel";

    private String mAuthToken;
    private @Environment int mEnvironment = ENVIRONMENT_PRODUCTION;
    private @SCLogger.LogLevel int mLogLevel = SCLogger.LOG_LEVEL_INFO;



    public SCConfig(String authToken) {
        mAuthToken = authToken;

        // Set default values
        if (mEnvironment == ENVIRONMENT_SANDBOX) {
            mLogLevel = SCLogger.LOG_LEVEL_DEBUG;
        }
    }

    public @SCLogger.LogLevel int getLogLevel() {
        return mLogLevel;
    }

    public void setLogLevel(@SCLogger.LogLevel int logLevel) {
        mLogLevel = logLevel;
    }

    public @Environment int getEnvironment() {
        return mEnvironment;
    }

    public void setEnvironment(@Environment int environment) {
        mEnvironment = environment;
    }

    public String getAuthToken() {
        return mAuthToken;
    }

    public void setAuthToken(String authToken) {
        mAuthToken = authToken;
    }

    public static SCConfig initFromManifest(Context context) {
        try {
            ApplicationInfo ai = context.getPackageManager().getApplicationInfo(
                    context.getPackageName(), PackageManager.GET_META_DATA);
            Bundle bundle = ai.metaData;
            String authToken = bundle.getString(AUTH_TOKEN_KEY);
            if (authToken == null) {
                Log.w(SCLogger.LOG_TAG, context.getString(R.string.sc_access_token_not_found));
                return null;
            }

            SCConfig config = new SCConfig(authToken);

            String environment = bundle.getString(ENVIRONMENT_KEY);
            if (environment != null) {
                switch (environment) {
                    case "production":
                        config.setEnvironment(ENVIRONMENT_PRODUCTION);
                        break;
                    case "sandbox":
                        config.setEnvironment(ENVIRONMENT_SANDBOX);
                }
            }

            int logLevel = SCLogger.fromString(bundle.getString(LOG_LEVEL_KEY));
            if (logLevel > -1) {
                //noinspection ResourceType
                config.setLogLevel(logLevel);<commit_msg>fix: fail with better error when auth token missing<commit_after>package sc.shortcut.sdk.android.deeplinking;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.IntDef;
import android.util.Log;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import sc.shortcut.deeplinkingsdk.R;

/**
 * This class holds the configuration details for the SDK.
 */
public class SCConfig {

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({ENVIRONMENT_SANDBOX, ENVIRONMENT_PRODUCTION})
    public @interface Environment {}

    // Environment constants
    public static final int ENVIRONMENT_SANDBOX = 0;
    public static final int ENVIRONMENT_PRODUCTION = 1;

    private static final String AUTH_TOKEN_KEY = "sc.shortcut.sdk.deeplinking.authToken";
    private static final String ENVIRONMENT_KEY = "sc.shortcut.sdk.deeplinking.environment";
    private static final String LOG_LEVEL_KEY = "sc.shortcut.sdk.deeplinking.logLevel";

    private String mAuthToken;
    private @Environment int mEnvironment = ENVIRONMENT_PRODUCTION;
    private @SCLogger.LogLevel int mLogLevel = SCLogger.LOG_LEVEL_INFO;



    public SCConfig(String authToken) {
        mAuthToken = authToken;

        // Set default values
        if (mEnvironment == ENVIRONMENT_SANDBOX) {
            mLogLevel = SCLogger.LOG_LEVEL_DEBUG;
        }
    }

    public @SCLogger.LogLevel int getLogLevel() {
        return mLogLevel;
    }

    public void setLogLevel(@SCLogger.LogLevel int logLevel) {
        mLogLevel = logLevel;
    }

    public @Environment int getEnvironment() {
        return mEnvironment;
    }

    public void setEnvironment(@Environment int environment) {
        mEnvironment = environment;
    }

    public String getAuthToken() {
        return mAuthToken;
    }

    public void setAuthToken(String authToken) {
        mAuthToken = authToken;
    }

    public static SCConfig initFromManifest(Context context) {
        try {
            ApplicationInfo ai = context.getPackageManager().getApplicationInfo(
                    context.getPackageName(), PackageManager.GET_META_DATA);
            Bundle bundle = ai.metaData;
            if (bundle == null) { // no metadata
                Log.e(SCLogger.LOG_TAG, context.getString(R.string.sc_access_token_not_found));
                return null;
            }

            String authToken = bundle.getString(AUTH_TOKEN_KEY);
            if (authToken == null) {
                Log.e(SCLogger.LOG_TAG, context.getString(R.string.sc_access_token_not_found));
                return null;
            }

            SCConfig config = new SCConfig(authToken);

            String environment = bundle.getString(ENVIRONMENT_KEY);
            if (environment != null) {
                switch (environment) {
                    case "production":
                        config.setEnvironment(ENVIRONMENT_PRODUCTION);
                        break;
                    case "sandbox":
                        config.setEnvironment(ENVIRONMENT_SANDBOX);
                }
            }

            int logLevel = SCLogger.fromString(bundle.getString(LOG_LEVEL_KEY));
            if (logLevel > -1) {
                //noinspection ResourceType
                config.setLogLevel(logLevel);
{'fraction_non_alphanumeric': 0.08022530065458974, 'fraction_numerical': 0.0009133810321205663, 'mean_word_length': 2.4725158562367864, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 5, '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': '7592722', 'n_tokens_mistral': 1848, 'n_tokens_neox': 1776, 'n_words': 386}