Search in sources :

Example 1 with StartServiceLogFactory

use of com.microsoft.azure.mobile.ingestion.models.json.StartServiceLogFactory in project mobile-center-sdk-android by Microsoft.

the class MobileCenter method instanceConfigure.

/**
     * Internal SDK configuration.
     *
     * @param application application context.
     * @param appSecret   a unique and secret key used to identify the application.
     * @return true if configuration was successful, false otherwise.
     */
/* UncaughtExceptionHandler is used by PowerMock but lint does not detect it. */
@SuppressLint("VisibleForTests")
private synchronized boolean instanceConfigure(Application application, String appSecret) {
    /* Load some global constants. */
    Constants.loadFromContext(application);
    /* Enable a default log level for debuggable applications. */
    if (!mLogLevelConfigured && Constants.APPLICATION_DEBUGGABLE) {
        MobileCenterLog.setLogLevel(Log.WARN);
    }
    /* Parse and store parameters. */
    if (mApplication != null) {
        MobileCenterLog.warn(LOG_TAG, "Mobile Center may only be configured once");
        return false;
    } else if (application == null) {
        MobileCenterLog.error(LOG_TAG, "application may not be null");
    } else if (appSecret == null || appSecret.isEmpty()) {
        MobileCenterLog.error(LOG_TAG, "appSecret may not be null or empty");
    } else {
        /* Store state. */
        mApplication = application;
        mAppSecret = appSecret;
        /* If parameters are valid, init context related resources. */
        StorageHelper.initialize(application);
        /* Remember state to avoid double call PreferencesStorage. */
        boolean enabled = isInstanceEnabled();
        /* Init uncaught exception handler. */
        mUncaughtExceptionHandler = new UncaughtExceptionHandler();
        if (enabled)
            mUncaughtExceptionHandler.register();
        mServices = new HashSet<>();
        /* Init channel. */
        mLogSerializer = new DefaultLogSerializer();
        mLogSerializer.addLogFactory(StartServiceLog.TYPE, new StartServiceLogFactory());
        mLogSerializer.addLogFactory(CustomPropertiesLog.TYPE, new CustomPropertiesLogFactory());
        mChannel = new DefaultChannel(application, appSecret, mLogSerializer);
        mChannel.setEnabled(enabled);
        mChannel.addGroup(CORE_GROUP, DEFAULT_TRIGGER_COUNT, DEFAULT_TRIGGER_INTERVAL, DEFAULT_TRIGGER_MAX_PARALLEL_REQUESTS, null);
        if (mLogUrl != null)
            mChannel.setLogUrl(mLogUrl);
        MobileCenterLog.logAssert(LOG_TAG, "Mobile Center SDK configured successfully.");
        return true;
    }
    MobileCenterLog.logAssert(LOG_TAG, "Mobile Center SDK configuration failed.");
    return false;
}
Also used : StartServiceLogFactory(com.microsoft.azure.mobile.ingestion.models.json.StartServiceLogFactory) CustomPropertiesLogFactory(com.microsoft.azure.mobile.ingestion.models.json.CustomPropertiesLogFactory) DefaultChannel(com.microsoft.azure.mobile.channel.DefaultChannel) DefaultLogSerializer(com.microsoft.azure.mobile.ingestion.models.json.DefaultLogSerializer) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 DefaultChannel (com.microsoft.azure.mobile.channel.DefaultChannel)1 CustomPropertiesLogFactory (com.microsoft.azure.mobile.ingestion.models.json.CustomPropertiesLogFactory)1 DefaultLogSerializer (com.microsoft.azure.mobile.ingestion.models.json.DefaultLogSerializer)1 StartServiceLogFactory (com.microsoft.azure.mobile.ingestion.models.json.StartServiceLogFactory)1