Since: API level 6
public class

EnterpriseLicenseManager

extends Object
java.lang.Object
   ↳ com.samsung.android.knox.license.EnterpriseLicenseManager

Class Overview

This class provides APIs to handle Enterprise license (ELM or BCK licenses) on device.

Since
API level 6
MDM 4.0

Summary

Constants
String ACTION_LICENSE_STATUS Broadcast Action : Sent to inform about result of License activation or validation result.
int ERROR_ANOTHER_PROCESS_IN_PLACE The package is already activating/deactivating a license key and must wait the result to try again.
int ERROR_INTERNAL Indicates that an unexpected error occurred during operation.
int ERROR_INTERNAL_SERVER Indicates that an unexpected error occurred in license server during operation.
int ERROR_INVALID_LICENSE Indicates that an invalid license was used in the operation.
int ERROR_INVALID_PACKAGE_NAME Indicates that the license is missing binding to the calling application.
int ERROR_LICENSE_TERMINATED Indicates that the license used in the operation is in the terminated status and could not be used.
int ERROR_NETWORK_DISCONNECTED Indicates whether device network connectivity does not exist.
int ERROR_NETWORK_GENERAL Indicates that a network error occurred during the operation.
int ERROR_NONE Indicates that the operation was successfully performed.
int ERROR_NOT_CURRENT_DATE Indicates that device date is different than current date.
int ERROR_NULL_PARAMS Indicates that some operation parameter is invalid.
int ERROR_SIGNATURE_MISMATCH Indicates that the caller package has an invalid signature.
int ERROR_UNKNOWN Indicates that an unexpected error occurred during operation.
int ERROR_USER_DISAGREES_LICENSE_AGREEMENT Indicates that Knox End User License Agreement was not accepted.
int ERROR_VERSION_CODE_MISMATCH Caller package version code mismatch.
String EXTRA_LICENSE_ATTESTATION_STATUS Deprecated in API level 29
String EXTRA_LICENSE_ERROR_CODE Used as an integer extra field with ACTION_LICENSE_STATUS.
String EXTRA_LICENSE_GRANTED_PERMISSIONS Used as StringArrayList extra field with ACTION_LICENSE_STATUS.
String EXTRA_LICENSE_RESULT_TYPE Used as integer extra field with ACTION_LICENSE_STATUS.
String EXTRA_LICENSE_STATUS Deprecated Not supported since KNOX 3.2. Use EXTRA_LICENSE_ERROR_CODE to check status.
String LICENSE_LOG_API The lookup key for log data in JSON array returned by getApiCallDataByAdmin(String)
String LICENSE_LOG_DATE The lookup key for log date in JSON array returned by getApiCallDataByAdmin(String)
int LICENSE_RESULT_TYPE_ACTIVATION Indicates that this result refers to a Enterprise license activation.
int LICENSE_RESULT_TYPE_VALIDATION Indicates that this result refers to a Enterprise license validation.
int STATUS_ATTESTED Deprecated in API level 29
int STATUS_DEVICE_NOT_SUPPORTED Deprecated in API level 29
int STATUS_NOT_ATTESTED Deprecated in API level 29
int STATUS_UNKNOWN_ERROR Deprecated in API level 29
Public Methods
void activateLicense(String licenseKey, String pkgName, LicenseResultCallback callback)
Deprecated in API level 37
NOTE: Applications can use activateLicense(String, LicenseResultCallback) since Android 14 to achieve the same result of this API.
void activateLicense(String licenseKey)
API to activate an Enterprise license to the calling application with result sent via broadcast.
void activateLicense(String licenseKey, LicenseResultCallback callback)
API to activate an Enterprise license to the calling application with result sent via callback.
void activateLicense(String licenseKey, String pkgName)
Deprecated in API level 37
NOTE: Applications can use activateLicense(String) since Android 14 to achieve the same result of this API.
JSONArray getApiCallDataByAdmin(String packageName)
API to retrieve API call data for the given packagename on device.
static EnterpriseLicenseManager getInstance(Context context)
API to create an instance of EnterpriseLicenseManager class.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String ACTION_LICENSE_STATUS

Since: API level 6

Broadcast Action : Sent to inform about result of License activation or validation result. This targeted broadcast is sent only to the application who called the activateLicense(String) API. Also system does periodic validation of Enterprise license, administrator continuously needs to listen for this intent after activation. The intent will have the following extra value:

EXTRA_LICENSE_STATUS:
"success", "fail".

EXTRA_LICENSE_ERROR_CODE:
ERROR_NONE
ERROR_NULL_PARAMS
ERROR_UNKNOWN
ERROR_INVALID_LICENSE
ERROR_LICENSE_TERMINATED
ERROR_INTERNAL
ERROR_INTERNAL_SERVER
ERROR_NETWORK_DISCONNECTED
ERROR_NETWORK_GENERAL
ERROR_USER_DISAGREES_LICENSE_AGREEMENT
ERROR_INVALID_PACKAGE_NAME
ERROR_NOT_CURRENT_DATE

EXTRA_LICENSE_RESULT_TYPE:
LICENSE_RESULT_TYPE_ACTIVATION
LICENSE_RESULT_TYPE_VALIDATION

EXTRA_LICENSE_GRANTED_PERMISSIONS

EXTRA_LICENSE_ATTESTATION_STATUS:
STATUS_ATTESTED
STATUS_NOT_ATTESTED
STATUS_DEVICE_NOT_SUPPORTED
STATUS_UNKNOWN_ERROR

Since
API level 6
MDM 4.0
Constant Value: "com.samsung.android.knox.intent.action.LICENSE_STATUS"

public static final int ERROR_ANOTHER_PROCESS_IN_PLACE

Since: API level 35

The package is already activating/deactivating a license key and must wait the result to try again.

Since
API level 35
KNOX 3.8
Constant Value: 602 (0x0000025a)

public static final int ERROR_INTERNAL

Since: API level 6

Indicates that an unexpected error occurred during operation.

Since
API level 6
MDM 4.0
Constant Value: 301 (0x0000012d)

public static final int ERROR_INTERNAL_SERVER

Since: API level 6

Indicates that an unexpected error occurred in license server during operation.

Since
API level 6
MDM 4.0
Constant Value: 401 (0x00000191)

public static final int ERROR_INVALID_LICENSE

Since: API level 6

Indicates that an invalid license was used in the operation.

Since
API level 6
MDM 4.0
Constant Value: 201 (0x000000c9)

public static final int ERROR_INVALID_PACKAGE_NAME

Since: API level 9

Indicates that the license is missing binding to the calling application.

Since
API level 9
MDM 4.1
Constant Value: 204 (0x000000cc)

public static final int ERROR_LICENSE_TERMINATED

Since: API level 6

Indicates that the license used in the operation is in the terminated status and could not be used.

Since
API level 6
MDM 4.0
Constant Value: 203 (0x000000cb)

public static final int ERROR_NETWORK_DISCONNECTED

Since: API level 6

Indicates whether device network connectivity does not exist.

Since
API level 6
MDM 4.0
Constant Value: 501 (0x000001f5)

public static final int ERROR_NETWORK_GENERAL

Since: API level 6

Indicates that a network error occurred during the operation.

Since
API level 6
MDM 4.0
Constant Value: 502 (0x000001f6)

public static final int ERROR_NONE

Since: API level 6

Indicates that the operation was successfully performed.

Since
API level 6
MDM 4.0
Constant Value: 0 (0x00000000)

public static final int ERROR_NOT_CURRENT_DATE

Since: API level 9

Indicates that device date is different than current date.

Since
API level 9
MDM 4.1
Constant Value: 205 (0x000000cd)

public static final int ERROR_NULL_PARAMS

Since: API level 6

Indicates that some operation parameter is invalid.

Since
API level 6
MDM 4.0
Constant Value: 101 (0x00000065)

public static final int ERROR_SIGNATURE_MISMATCH

Since: API level 20

Indicates that the caller package has an invalid signature. Check license binding.

Since
API level 20
MDM 5.7
Constant Value: 206 (0x000000ce)

public static final int ERROR_UNKNOWN

Since: API level 6

Indicates that an unexpected error occurred during operation.

Since
API level 6
MDM 4.0
Constant Value: 102 (0x00000066)

public static final int ERROR_USER_DISAGREES_LICENSE_AGREEMENT

Since: API level 6

Indicates that Knox End User License Agreement was not accepted.

Since
API level 6
MDM 4.0
Constant Value: 601 (0x00000259)

public static final int ERROR_VERSION_CODE_MISMATCH

Since: API level 20

Caller package version code mismatch.

Since
API level 20
MDM 5.7
Constant Value: 207 (0x000000cf)

public static final String EXTRA_LICENSE_ATTESTATION_STATUS

Since: API level 20

Deprecated in API level 29

Used as integer extra field with ACTION_LICENSE_STATUS. Contains the Remote Attestation status during license activation.

Since
API level 20
MDM 5.7
Constant Value: "com.samsung.android.knox.intent.extra.LICENSE_ATTESTATION_STATUS"

public static final String EXTRA_LICENSE_ERROR_CODE

Since: API level 6

Used as an integer extra field with ACTION_LICENSE_STATUS. Contains the error code of license activation or validation result. In case of success, this extra will contain ERROR_NONE.

Since
API level 6
MDM 4.0
Constant Value: "com.samsung.android.knox.intent.extra.LICENSE_ERROR_CODE"

public static final String EXTRA_LICENSE_GRANTED_PERMISSIONS

Since: API level 30

Used as StringArrayList extra field with ACTION_LICENSE_STATUS. Contains the list of permissions given after an activation or validation.

Since
API level 30
KNOX 3.4.1
Constant Value: "com.samsung.android.knox.intent.extra.LICENSE_GRANTED_PERMISSIONS"

public static final String EXTRA_LICENSE_RESULT_TYPE

Since: API level 9

Used as integer extra field with ACTION_LICENSE_STATUS. This will tell whether this is activation or validation result.

Since
API level 9
MDM 4.1
Constant Value: "com.samsung.android.knox.intent.extra.LICENSE_RESULT_TYPE"

public static final String EXTRA_LICENSE_STATUS

Since: API level 6

Deprecated Not supported since KNOX 3.2. Use EXTRA_LICENSE_ERROR_CODE to check status.

Used as string extra field with ACTION_LICENSE_STATUS. Contains the result of the license activation or validation result.

Since
API level 6
MDM 4.0
Constant Value: "com.samsung.android.knox.intent.extra.LICENSE_STATUS"

public static final String LICENSE_LOG_API

Since: API level 6

The lookup key for log data in JSON array returned by getApiCallDataByAdmin(String)

Since
API level 6
MDM 4.0
Constant Value: "api_call"

public static final String LICENSE_LOG_DATE

Since: API level 6

The lookup key for log date in JSON array returned by getApiCallDataByAdmin(String)

Since
API level 6
MDM 4.0
Constant Value: "log_date"

public static final int LICENSE_RESULT_TYPE_ACTIVATION

Since: API level 9

Indicates that this result refers to a Enterprise license activation.

Since
API level 9
MDM 4.1
Constant Value: 800 (0x00000320)

public static final int LICENSE_RESULT_TYPE_VALIDATION

Since: API level 9

Indicates that this result refers to a Enterprise license validation.

Since
API level 9
MDM 4.1
Constant Value: 801 (0x00000321)

public static final int STATUS_ATTESTED

Since: API level 20

Deprecated in API level 29

Device is attested.

Since
API level 20
MDM 5.7
Constant Value: 0 (0x00000000)

public static final int STATUS_DEVICE_NOT_SUPPORTED

Since: API level 20

Deprecated in API level 29

Device does not support Attestation

Since
API level 20
MDM 5.7
Constant Value: 2 (0x00000002)

public static final int STATUS_NOT_ATTESTED

Since: API level 20

Deprecated in API level 29

Device is not attested.

Since
API level 20
MDM 5.7
Constant Value: 1 (0x00000001)

public static final int STATUS_UNKNOWN_ERROR

Since: API level 20

Deprecated in API level 29

Attestation unknown error

Since
API level 20
MDM 5.7
Constant Value: 3 (0x00000003)

Public Methods

public void activateLicense (String licenseKey, String pkgName, LicenseResultCallback callback)

Since: API level 35

Deprecated in API level 37
NOTE: Applications can use activateLicense(String, LicenseResultCallback) since Android 14 to achieve the same result of this API.

API to activate an Enterprise license to the calling application with result sent via callback.

 EnterpriseLicenseManager mgr = EnterpriseLicenseManager.getInstance(context);
 String licenseKey = "ELMLICENSEKEY";
 mgr.activateLicense(licenseKey, context.getPackageName(), (licenseResult) -> {
     Log.w("License result arrived.");
 });
 

Parameters
licenseKey provided by the caller application
pkgName package name of the application calling this API.
callback called when results are ready
Since
API level 35
KNOX 3.8

public void activateLicense (String licenseKey)

Since: API level 6

API to activate an Enterprise license to the calling application with result sent via broadcast. This targeted broadcast is sent only to the application who called this API.

 EnterpriseLicenseManager mgr = EnterpriseLicenseManager.getInstance(context);
 String licenseKey = "ELMLICENSEKEY";
 mgr.activateLicense(licenseKey);
 

NOTE:

The result of license activation is then notified through an intent ACTION_LICENSE_STATUS.

Parameters
licenseKey provided by the calling application
Since
API level 6
MDM 4.0

public void activateLicense (String licenseKey, LicenseResultCallback callback)

Since: API level 35

API to activate an Enterprise license to the calling application with result sent via callback.

 EnterpriseLicenseManager mgr = EnterpriseLicenseManager.getInstance(context);
 String licenseKey = "ELMLICENSEKEY";
 mgr.activateLicense(licenseKey, (licenseResult) -> {
     Log.w("License result arrived.");
 });
 

Parameters
licenseKey provided by the caller application
callback called when results are ready
Since
API level 35
KNOX 3.8

public void activateLicense (String licenseKey, String pkgName)

Since: API level 11

Deprecated in API level 37
NOTE: Applications can use activateLicense(String) since Android 14 to achieve the same result of this API.

API to activate an Enterprise license to the calling application with result sent via broadcast. This targeted broadcast is sent only to the application who called this API.

 EnterpriseLicenseManager mgr = EnterpriseLicenseManager.getInstance(context);
 String licenseKey = "ELMLICENSEKEY";
 mgr.activateLicense(licenseKey, context.getPackageName());
 

NOTE:

The result of license activation is then notified through an intent ACTION_LICENSE_STATUS.

Parameters
licenseKey provided by the caller application
pkgName package name of the application calling this API.
Since
API level 11
MDM 5.0

public JSONArray getApiCallDataByAdmin (String packageName)

Since: API level 6

API to retrieve API call data for the given packagename on device.

Parameters
packageName Packagename for which api data to be retrieved
Returns
  • the API Call Data in the form of a JSONObject array corresponding to the given packageName, else null, if no logs exist for that packageName
Usage
Used to get API call data in JSONArray in below key value format.
[{
"log_date" :"DATE1" ,
"api_call" : {"API_1" : "CALLS_VALUE" , ... , "API_n" : "CALLS_VALUE"}
"log_date" :"DATE2" ,
"api_call" : {"API_1" : "CALLS_VALUE" , ... , "API_n" : "CALLS_VALUE"}
}]

 EnterpriseLicenseManager mgr = EnterpriseLicenseManager.getInstance(context);
 String pkgName = "com.xyz.testadmin";
 JSONArray arr = mgr.getApiCallDataByAdmin(pkgName);
 if (arr == null){
    Log.w("EnterpriseLicenseManager.getApiCallDataByAdmin() failed");
    return;
 }
 String result = arr.toString();
 Log.w("EnterpriseLicenseManager.getApiCallDataByAdmin() result = " + result);
 
Permission
The use of this API requires the caller to have the "com.samsung.android.knox.permission.KNOX_LICENSE_LOG" permission which has a protection level of signature.
Since
API level 6
MDM 4.0

public static EnterpriseLicenseManager getInstance (Context context)

Since: API level 6

API to create an instance of EnterpriseLicenseManager class.

Parameters
context context of the application or service using this class
Returns
Usage
Used to get access to EnterpriseLicenseManager object

 EnterpriseLicenseManager mgr = EnterpriseLicenseManager.getInstance(context);
 
Since
API level 6
MDM 4.0