Initialization

The access point to all the features provided by Malwarelytics for Android is the AppProtection class. Before using AppProtection an instance has to obtained with AppProtection.getInstance(). The next step is to initialize it with a desired configuration. There are two initialization methods provided - synchronous initialize(AppProtectionConfig) and asynchronous initializeAsync(AppProtectionConfig, InitializationObserver).

Synchronous Initialization

Synchronous initialization has to be called from a background thread, calling it on the main thread would cause ANR (Application Not Responding).

val appProtection = AppProtection.getInstance()
val appProtectionConfig = AppProtectionConfig.Builder(appContext)
    // add desired configuration here
    .build()
// this has to be called on a background thread only
val initializationResult = appProtection.initialize(appProtectionConfig)
// the result value should be checked
// now it's possible to start using Malwarelytics for Android

Asynchronous Initialization

Asynchronous initialization can be called from any thread.

val appProtection = AppProtection.getInstance()
val appProtectionConfig = AppProtectionConfig.Builder(appContext)
    // add desired configuration here
    .build()
appProtection.initializeAsync(appProtectionConfig, object : AppProtection.InitializationObserver {
    override fun onInitialized(initializationResult: AppProtection.InitializationResult) {
        // the result value should be checked
        // now it's possible to start using Malwarelytics for Android
    }
})

Initialization Result

Initialization returns a value from InitializationResult enum, indicating whether the SDK can be fully used with all features or in a limited offline mode. Possible initialization return values are: SUCCESS, TEMPORARY_OFFLINE_MODE and PERMANENT_OFFLINE_MODE.

Result value Description
SUCCESS The SDK was successfully initialized into full online mode.
TEMPORARY_OFFLINE_MODE There was a communication problem with the remote server. The communication might get reestablished later.
PERMANENT_OFFLINE_MODE The SDK is misconfigured, communication with the remote server is not possible.

When Malwarelytics for Android is initialized into an offline mode, no communication with the remote server is happening. All features use only built in detection data.

User Identifier

When Malwarelytics for Android initialize with initialization result SUCCESS an internal identifier provided by the remote server becomes available. This internal ID called avUid can be obtained by calling:

val avUid = appProtection.getAvUid()

Other Identifiers

Malwarelytics for Android offers API for two other identifiers - clientAppUserId and clientAppDeviceId. Values for these identifiers are provided by the app integrating Malwarelytics for Android. The values are send to remote server where they allow to find the desired user or device.

Identifier Description
clientAppUserId App’s user ID. Typically app’s internal user ID or its derivative.
clientAppDeviceId App’s device ID. Typically an activation ID or its derivative.

These identifiers can be either set in configuration or later after initialization via API.

Setting of these values during the Malwarelytics initialization phase:

val config = AppProtectionConfig.Builder(appContext)
    .clientAppUserId(INTERNAL_CLIENT_USER_ID) // Use if internal user ID is available at config time
    .clientAppDeviceId(INTERNAL_CLIENT_DEVICE_ID) // Use if internal device ID is available at config time
    // other configuration items
    .build()

Setting or updating of these values after the Malwarelytics initialization phase:

val appProtection = AppProtection.getInstance()
// these methods cannot be called before the SDK is initialized
appProtection.updateClientAppUserId("NEW_VALUE_FOR_CLIENT_APP_USER_ID")
appProtection.updateClientAppDeviceId("NEW_VALUE_FOR_CLIENT_APP_DEVICE_ID")

Obtaining previously set values after the Malwarelytics initialization phase:

val appProtection = AppProtection.getInstance()
// these methods cannot be called before the SDK is initialized
val clientAppUserId = appProtection.getClientAppUserId()
val clientAppDeviceId = appProtection.getClientAppDeviceId()

Releasing

When the features provided by Malwarelytics for Android are not needed anymore, for example when the user opts-out from its usage, or to allow for a configuration change, AppProtection instance can be released.

AppProtection instance can be released by calling:

val appProtection = AppProtection.getInstance()
appProtection.release()

or by calling

val appProtection = AppProtection.getInstance()
appProtection.releaseAndResetAvUid()

Calling release() method just releases the instance. Calling releaseAndResetAvUid() releases the instance and resets the avUid identifier, then a new value for the identifier is obtained from the remote server during the subsequent initialization.

Malwarelytics for Android cannot be used after release. It has to be re-initialized first.

Last updated on May 15, 2023 (16:20) View product
Search

0.24.x

Malwarelytics for Android