Bot Manager SDK

Integrating with Android Apps

This section describes the overall process used for Android apps. You start by installing and initializing the BMP SDK, and then you’re ready to collect and send sensor data. Then you can determine what actions to take depending on the response codes from the edge.

Installation

The size of the SDK jar file is 65 KB and contains 512 Dex method counts.

Requirements

  • Android Studio

  • Android API 15 (Android 4.0.4) and above

 

  1.  Install the SDK
    Install the SDK by downloading the SDK and copying AkamaiBMP.jar into your libs folder.
  2. Initialize the SDK
    Initialize the SDK by calling CYFMonitor.initialize API from your main activity's onCreate method.
    // Import the class
    import com.akamai.botman.CYFMonitor;

    public class MainActivity extends Activity {

         @Override
         protected void onCreate ( Bundle savedInstanceState) {

              // Initialize Akamai BMP SDK
              CYFMonitor. initialize( getApplication());
         }
    }
  3. Collect Sensor Data
    The BMP SDK’s sensor data contains serialized user behavioral data and device information. However, the device information doesn’t contain any information that will identify this device uniquely.

    You can retrieve sensor data from the SDK by calling the CYFMonitor.getSensorData method. Sensor data should be sent in the REST API request as detailed below.

    // Get the BMP sensor data
    String sensorData = CYFMonitor. getSensorData();

    Important: Call the getSensorData method only on REST API requests to URLs that will be configured for protection in Bot Manager Premier Mobile. Do not call the getSensorData method for non-protected URLs.

  4. Send Sensor Data
    After the sensor data is retrieved from the SDK, it should be sent in X-acf-sensor-data HTTP header as part your applications REST API (HTTP/S) request. We recommend using HTTPS for the REST API request to ensure the integrity of sensor data and prevent eavesdropping. Send the X-acf-sensor-data header ONLY on HTTP requests to URLs configured for protection in Bot Manager Premier Mobile. Do not send the header and sensor data on every HTTP request the app makes.
    // Set the sensor data header
    urlConnection. setRequestProperty(
              "X-acf-sensor-data", CYFMonitor. getSensorData());
  5. Evaluate the Akamai Edge Response
    Akamai edge server inspects sensor data and takes the predefined action on the request if the request is classified as BOT, otherwise Akamai sends the request to the origin server.

 

Sample Code – Getting and Sending Sensor Data

The following code snippet shows how to get the sensor data and send it in the HTTP request.

// Import the class
import com.akamai.botman.CYFMonitor;

public class LoginActivity extends Activity {

  @Override
  protected void onCreate ( Bundle savedInstanceState) {

     // Initialize Akamai BMP SDK
     CYFMonitor. initialize( getApplication());

  }

  protected void loginAction () {

     // Get the BMP sensor data
     String sensorData = CYFMonitor. getSensorData();

     // Initialize HttpURLConnection
     URL url = new URL( "https://bmpapi.akamai.com/samples/v1/login");
     HttpURLConnection urlConnection = ( HttpURLConnection) url. openConnection();

     // Set the sensor data header
     urlConnection. setRequestProperty( "X-acf-sensor-data", sensorData);

     // set the POST body and send the request
  }
}

 

Android API

CYFMonitor

public class CYFMonitor

java.lang.Object

+--> com.akamai.botman.CYFMonitor (added in Version 2.0.0)

CYFMonitor provides methods to access the BMP SDK. All methods in this class are static methods and can be accessed from anywhere without initializing an instance and methods can be invoked from any thread.

See the individual method details for more information.

 

Public Constants

Log Levels

Type

Log Level

int

INFO: Constant to log all messages from the SDK

int

WARN: Constant to log all warning and error messages from the SDK

int

ERROR: Constant to log only error messages from the SDK

int

NONE: Constant to log no messages from the SDK

 

Public Methods

Initialize

static synchronized void initialize ( Application app)

Initialize the Akamai Botman SDK to capture user events for the specified application.

 

getSensorData

static synchronized String getSensorData()

Get the serialized user behavior data, device events and device information to be sent with the REST API that needs to be protected.

 

Returns:

String Serialized sensor data

setLogLevel

static void setLogLevel (int logLevel)

Set the log level for the Akamai BMP SDK. See Logging below for a list of valid values.

 

Parameters:

logLevel int: A valid log level value

 

Logging

Akamai BMP SDK logs some messages at all log levels to verify the SDK initialization. These messages are helpful in identifying any integration issue and ensure the SDK is initialized successfully.

In addition to these messages, the SDK logs additional messages at info, warn and error levels, to verify and debug that the SDK is working correctly. The default log level for the SDK is to log warning and error messages only. This behavior can be changed by calling setLogLevel API.

To set the log level, call CYFMonitor.setLogLevel API with one of the log levels specified below:

  • CYFMonitor.INFO - Print all messages

  • CYFMonitor.WARN - (Default) Print warning and error messages only

  • CYFMonitor.ERROR - Print error messages only

  • CYFMonitor.NONE - Turn off all log messages from the SDK

 

For example, to see all messages:

// Set the log level to Info
CYFMonitor. setLogLevel( CYFMonitor. INFO);