Datami Android VPN SDK
Datami Android VPN SDK
Introduction
Assumptions
Compatibility
Integration Steps
Obfuscation
Social media or Streaming usage
When building an Android App Bundle
1 Getting started with 'initSponsoredData' API
1.1 Add required compile option and dependencies in app level build.gradle file
1.2 Call 'initSponsoredData' API for sponsoring data over App vpn connection
1.3 Call 'initSponsoredData' API for initialization without setting VPN
1.4 Call 'initSponsoredData' API for sponsoring data over App vpn connection with custom retry.
1.5 Call 'initSponsoredData' API for sponsoring data over App vpn connection with controlled VPN permission display to user.
1.6 Add below configuration to support latest android version
1.7 Call 'startSponsoredData' API
1.8 Call 'stopSponsoredData' API
1.9 Call 'vpnHealthCheck' API
1.10 Call 'isVpnPermissionAccepted' API
1.11 Setup a listener for Sponsored Data state changes in your Application class (Optional)
1.12 Call 'initSponsoredData' API for initialization with user-tags
1.13 Using 'updateUserTag' API
2. API Reference
2.1 API for sponsoring entire application traffic through VPN
2.2 VPN API initialization without setting VPN
2.3 VPN API initialization with customised retry count
2.4 VPN API initialization with controlled VPN permission
2.5 VPN API to get the VPN connection state
2.6 VPN API to get the VPN permission status
2.7 VPN API initialization with user-tags
2.8 Update User Tags API
3 Testing and Verification
3.1 Initial Integration Testing
3.2 Sponsored Data Testing
4 Performance
4.1 Initialization Overhead
4.2 Runtime Overhead
Introduction
Datami VPN SDK for Android provides class libraries, code samples and documentation to help developers building Sponsored Data enabled
applications using VPN.
Assumptions
1. An SDK API access key is provisioned in Datami and provided to the application for integration with Datami SDK.
2. A sponsored data campaign is configured in the Datami portal for testing the application with Datami SDK.
3. Application developer has a physical Android device with a SIM that works on the mobile network which is integrated with Datami.
Compatibility
The Datami Android SDK is compatible with Android 4.4 (API Level 19) or higher.
Integration Steps
Datami will provide an API key required for the integration. Use the API key to activate the SDK through the API.
To sponsor all the VPN traffic to/from the App
1. Include the Datami Android SDK library (vpnsdk-android.aar) in your project.
2. Configure proguard/dexguard properties (See 'Obfuscation' section below)
3. Set the compile options and dependencies in the app level build.gradle file (See Section 1.1).
4. If app is targeting API 28+ (Android 9 Pie), please include the changes as per Android 9 Pie Support (See below)
Obfuscation
Datami Android SDK library is obfuscated using ProGuard/DexGuard tool. If your app uses obfuscation, please add the following lines into your
proguard/dexguard configuration file.
proguard
-dontwarn com.datami.**
# Keep classes under smisdk
-keep class com.datami.** {
*;
}
If application allow navigation to any social media or streaming links like Facebook, Instagram, Twitter, Youtube. These will get
sponsored as part of application and allow users to consume the social network sites with free data. This may lead to high sponsored data
usage for the applications.
Since it is part of the application – Datami will be considering this as sponsored data usage. If that is not the intention, please take steps to
block these links when the application is being sponsored. Please let us know if we can help.
gradle.properties
android.bundle.enableUncompressedNativeLibs=false
1.1 Add required compile option and dependencies in app level build.gradle file
b. Multidex support
build.gradle
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
...
multiDexEnabled true
...
}
}
dependencies {
...
compile 'com.android.support:multidex:+'
...
}
c. Multidex support for 4.4 android versions- Application class must be derived from MultiDexApplication
MyApplication.java
...
}
1.2 Call 'initSponsoredData' API for sponsoring data over App vpn connection
initSponsoredData()
import com.datami.smi.SmiVpnSdk;
import com.datami.smi.internal.MessagingType;
..
This api is just for initialization without setting VPN. Later VPN can be set/reset using startSponsoredData()/stopSponsredData() apis.
initSponsoredData()
import com.datami.smi.SmiVpnSdk;
import com.datami.smi.internal.MessagingType;
..
1.4 Call 'initSponsoredData' API for sponsoring data over App vpn connection with custom retry.
This api is for initialization of app with customised retry count. The initialization can be done with or without setting of VPN.
initSponsoredData()
import com.datami.smi.SmiVpnSdk;
import com.datami.smi.internal.MessagingType;
..
This api is for initialization of app with controlled vpn permission. The initialization should be done without setting of VPN and the system
Permission popup will be accessible on startSponsoredData() API.
initSponsoredData()
import com.datami.smi.SmiVpnSdk;
import com.datami.smi.internal.MessagingType;
..
b. If you are pinning the SSL certificates then in the res/xml/network_security_config.xml add the rules to allow HTTP
connections to cloudmi.datami.com and vpn.status.internal.datami domain.
4. If you're migrating to AndroidX. Make your project use Jetifier and write below code in gradle.properties.
gradle.properties
android.enableJetifier=true
android.useAndroidX=true
This api can be used to start sponsor data by starting the VPN if it has not started by initSponsoredData() api as mentioned in section 1.3 or
previously stopped by calling stopSponsoredData() api as mentioned in section 1.5.
startSponsoredData()
import com.datami.smi.SmiVpnSdk;
..
try{
SmiVpnSdk.startSponsoredData();
}catch(Exception e){
...
}
This api can be used to stop sponsor data by stopping the VPN if it has already started by calling initSponsoredData() api or startSponsoredData()
api.
stopSponsoredData()
import com.datami.smi.SmiVpnSdk;
..
SmiVpnSdk.stopSponsoredData();
This api can be used to get the VPN connection state. This api is non-blocking api and can be called from any thread.
vpnHealthCheck()
import com.datami.smi.SmiVpnSdk;
..
isVpnPermissionAccepted()
import com.datami.smi.SmiVpnSdk;
..
1.11 Setup a listener for Sponsored Data state changes in your Application class (Optional)
Datami Android SDK provides SdStateChangeListener interface to receive sponsored data state changes while application is running. The
application will use current sponsored data state to display appropriate custom message to its users.
OnChange listener
This api is for initialization of app with user-tags. Using this API the sponsorship can be controlled to specific user base.
initSponsoredData()
import com.datami.smi.SmiVpnSdk;
import com.datami.smi.internal.MessagingType;
..
Apps can pass a list of tags to the SDK for segmentation. These can then be updated as per requirement.
SDK will always keep recent tags and will replace the old tag/tags if any.
NOTE:
updateUserTag()
....
SmiVpnSdk.updateUserTag(tags);
....
2. API Reference
This API is used for sponsoring all VPN traffic to/from an application on cellular networks. The API signature is as follows:
void initSponsoredData (String sdkKey, Context context, int iconId, MessagingType messagingType);
iconId int The iconId for notification icon in notification bar and notification drawer. It can be -1. M
When it is provided, the SDK displays the icon in notification bar and drawer when data is
sponsored.
ex.R.drawable.ic_launcher. Or -1
This API is used for VPN api initialization and VPN can be set/reset using startSponsoredData()/stopSponsoredData() apis. The API signature is
as follows:
void initSponsoredData (String sdkKey, Context context, int iconId, MessagingType messagingType, boolean startVPN);
iconId int The iconId for notification icon in notification bar and notification drawer. It can be -1. M
When it is provided, the SDK displays the icon in notification bar and drawer when data is
sponsored.
ex.R.drawable.ic_launcher. Or -1
This API is used for sponsoring all VPN traffic to/from an application on cellular networks with customised retry count. The initialization can be
done with or without setting of VPN. The API signature is as follows:
void initSponsoredData (String sdkKey, Context context, int iconId, MessagingType messagingType, boolean startVPN, int
vpnConnectRetry);
iconId int The iconId for notification icon in notification bar and notification drawer. It can be -1. M
When it is provided, the SDK displays the icon in notification bar and drawer when data is
sponsored.
ex.R.drawable.ic_launcher. Or -1
This API is used for sponsoring all VPN traffic to/from an application on cellular networks with controlled VPN permission. The initialization should
be done without setting of VPN. The API signature is as follows:
void initSponsoredData (String sdkKey, Context context, int iconId, MessagingType messagingType, boolean startVPN, int
vpnConnectRetry, boolean controlledVpnConnection);
initSponsoredData API parameter details:
iconId int The iconId for notification icon in notification bar and notification drawer. It can be -1. M
When it is provided, the SDK displays the icon in notification bar and drawer when data is
sponsored.
ex.R.drawable.ic_launcher. Or -1
controlledVpnConnect Boolean TRUE - Show system vpn popup only on call of startSponsoredData() API. M
ion
This API is used for VPN to get the current connection state. The API signature is as follows:
0 Poor Connection
-1 Failed
This API is used to get whether user has accepted the permission or not. If not then we can setup vpn once again on user acceptance.
Return values boolean TRUE User has already accepted the permission M
This API is used for sponsoring all VPN traffic to/from an application on cellular networks with user tags. The API signature is as follows:
void initSponsoredData (String sdkKey, Context context, int iconId, MessagingType messagingType, boolean startVPN, int
vpnConnectRetry, boolean controlledVpnConnection, List<String> userTags);
iconId int The iconId for notification icon in notification bar and notification drawer. It can be -1. M
When it is provided, the SDK displays the icon in notification bar and drawer when data is
sponsored.
ex.R.drawable.ic_launcher. Or -1
controlledVpnConnect Boolean TRUE - Show system vpn popup only on call of startSponsoredData() API. M
ion
FALSE - The standard way.
This API is used to update the tags in the SDK. The API signature is as follows:
void updateUserTag(List<String> tags);
When SDK integration is complete, the following basic tests should be done by an application developer (before an active sponsored data
campaign is configured in Datami Portal):
1. Open the application in WiFi and verify that the SDK returns the SmiResult with sdState = SdState.WIFI.
2. Open the application in cellular mode and verify that the SDK returns the SmiResult with sdState = SdState.SD_NOT_AVAILABLE and
sdReason = SdReason. SD_NOT_AVAILABLE_PROMOTION_NOT_FOUND as there is no active campaign for your app at this time
3. Switch between WiFi and cellular, and verify that the SDK notifies the sdState accordingly.
The following tests can be carried out when SDK integration is complete and there is an active campaign configured in the Datami Portal:
1. Open the application in cellular mode and verify that the SDK returns the SmiResult with sdState = SdState.SD_AVAILABLE.
2. Use the application in cellular and verify that the data usage in Datami portal increases for the campaign.
3. Use the application in WIFI and verify the data usage in Datami portal doesn’t increase for the campaign.
Note: The integrated application needs to be shared with Datami and cellular operator for complete testing and verification, including zero rating
verification.
4 Performance
The 'initSponsoredData' API is asynchronous and it doesn’t block the calling application.
4.2 Runtime Overhead
The Datami SDK routes the traffic through Datami Gateway which can add a minor latency from 25 ms to 50 ms to the data path. The Datami
gateway(s) are deployed either within or close to wireless carrier core network to minimize the delays. However, Datami offers different
deployment models to minimize network latencies. The application developer can request for testing the correct integration from Datami.