Since: API level 2
public class

ApnSettingsPolicy

extends Object
java.lang.Object
   ↳ com.samsung.android.knox.net.apn.ApnSettingsPolicy

Class Overview

This class provides APIs to create, update, and remove Access Point Name (APN) settings on the device. Use the ApnSettings class to fill up the relevant APN setting details.

Since
API level 2
MDM 2.0

Summary

Public Methods
long createApnSettings(ApnSettings apn)
API to create APN settings.
boolean deleteApn(long apnId)
API to delete particular APN settings.
List<ApnSettings> getApnList()
API to get all APN settings from the device.
ApnSettings getApnSettings(long apnId)
API to get particular APN settings.
ApnSettings getPreferredApnSettings()
API to get preferred APN settings.
boolean setPreferredApn(long apnId)
API to set a preferred APN.
boolean updateApnSettings(ApnSettings apn)
API to update existing APN settings.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public long createApnSettings (ApnSettings apn)

Since: API level 2

API to create APN settings.

Parameters
apn The APN settings to be created.
Returns
  • Unique Id if the APN setting creation is successful, else -1. Use this Id for future reference to this APN setting.
Throws
SecurityException If caller does not have required permissions
Usage
Access Point Name (APN) is a computer protocol that allows a user's computer to access the Internet using the mobile phone network. An administrator can use this API to complete APN information for accessing the data network of a carrier and, using this API, add this item on the device APN list without user interaction.


  EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);

  ApnSettingsPolicy apnSettingsPolicy = edm.getApnSettingsPolicy();

  ApnSettings apnSettings = new ApnSettings();

  

  apnSettings.user = "ApnUser";

  apnSettings.password = "1234";

  apnSettings.server = "ApnServer";

  apnSettings.mmsc = "http://mms.msg.eg.t-mobile.com/mms/wapenc";

  apnSettings.mmsProxy = "127.0.0.0";

  apnSettings.mmsPort = "80";

  apnSettings.mcc = "310";

  apnSettings.mnc = "260";

  apnSettings.type = "default";

  try {

       long ret= apnSettingsPolicy.createApnSettings(apnSettings);

       if (ret != -1) {

           Log.w("APN", "APN created");

       } else {

           Log.w("APN", "APN creation failed");

       }

  } catch (SecurityException e) {

     Log.w(TAG, "SecurityException: " + e);

  }

Permission
The use of this API requires the caller to have the "com.samsung.android.knox.permission.KNOX_APN" permission which has a protection level of signature.

Since
API level 2
MDM 2.0
Multiuser Environment
Global Scope

public boolean deleteApn (long apnId)

Since: API level 2

API to delete particular APN settings.

Parameters
apnId The Id for the APN to be deleted.
Returns
  • true if deletion of APN is successful, else false.
Throws
SecurityException If caller does not have required permissions
Usage
An administrator can use this API to delete an APN from the device without user interaction. Use the unique Id obtained when the APN settings were created to delete the APN settings.


  EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);

  ApnSettingsPolicy apnSettingsPolicy = edm.getApnSettingsPolicy();

 

  try {

      boolean result = apnSettingsPolicy.deleteApn(1);

      if (result == true){

          //APN deletion succeeded

      } else {

         //APN deletion failed.

      }

  } catch(SecurityException e) {

    Log.w(TAG,"SecurityException: " + e);

  } 
Permission
The use of this API requires the caller to have the "com.samsung.android.knox.permission.KNOX_APN" permission which has a protection level of signature.

Since
API level 2
MDM 2.0
Dependency
Must use an existing id value.
Multiuser Environment
Global Scope

public List<ApnSettings> getApnList ()

Since: API level 2

API to get all APN settings from the device.

Returns
  • If successful, a list of all the APN settings present on the device or an empty list if none are found, else null.
Throws
SecurityException If caller does not have required permissions
Usage
An administrator can use this API to get a list of APNs already provisioned on the device and use the ApnSettings object returned to manipulate them. If this API is called and the device does not have a valid SIM card inserted, the API returns all the available APNs on the device. Otherwise, the API return APNs that are specific to the inserted SIM card.


  EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);

  ApnSettingsPolicy apnSettingsPolicy = edm.getApnSettingsPolicy();

  

  try {

      List apnList = apnSettingsPolicy.getApnList();

      if (apnList != null){

           Iterator iApnList = apnList.iterator();

           List infoList = new ArrayList();

           while(iApnList.hasNext()) {

               ApnSettings apnSettings = iApnList.next();

               String tmp = "Id: " + apnSettings.id + "\n" +

                            "Name: " + apnSettings.name + "\n" +

                            "Apn: " + apnSettings.apn + "\n" +

                            "MCC: " + apnSettings.mcc + "\n" +

                            "MNC: " + apnSettings.mnc + "\n" +

                            "User: " + apnSettings.user + "\n" +

                            "Server: " + apnSettings.server + "\n" +

                            "Password: " + apnSettings.password + "\n" +

                            "Proxy: " + apnSettings.proxy + "\n" +

                            "Port: " + apnSettings.port + "\n" +

                            "MmsProxy: " + apnSettings.mmsProxy + "\n" +

                            "MMSC: " + apnSettings.mmsc + "\n" +

                            "Type: " + apnSettings.type + "\n" +

                            "AuthType: " + apnSettings.authType;

               infoList.add(tmp);

           }

           // Log the retrieved APN settings

       }   

  } catch(SecurityException e) {

    Log.w(TAG,"SecurityException: "+e);

  } 

  //Sample Output

  // Id: 2

  // Name: KT

  // Apn: lte.ktfwing.com

  // MCC: 450 

  // MNC: 08 

  // User:  

  // Server: * 

  // Password:  

  // Proxy:

  // Port: -1

  // MmsProxy: 

  // MMSC: http://mmsc.ktwing.com:9082 

  // Type: *

  // AuthType: 1

Permission
The use of this API requires the caller to have the "com.samsung.android.knox.permission.KNOX_APN" permission which has a protection level of signature.

Since
API level 2
MDM 2.0
Multiuser Environment
Global Scope

public ApnSettings getApnSettings (long apnId)

Since: API level 2

API to get particular APN settings.

Parameters
apnId The Id for the APN whose settings are to be retrieved.
Returns
  • APN settings present on the device if successful, else null.
Throws
SecurityException If caller does not have required permissions
Usage
An administrator can use this API to get the APN settings configured on the device.


  EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);

  ApnSettingsPolicy apnSettingsPolicy = edm.getApnSettingsPolicy();

  

  long apnId = 1;

  try {

      ApnSettings apnSettings = apnSettingsPolicy.getApnSettings(apnId);

      if(apnSettings != null){

          String tmp = "Id: " + apnSettings.id + "\n" +

          "Name: " + apnSettings.name + "\n" +

          "Apn: " + apnSettings.apn + "\n" +

          "MCC: " + apnSettings.mcc + "\n" +

          "MNC: " + apnSettings.mnc + "\n" +

          "User: " + apnSettings.user + "\n" +

          "Server: " + apnSettings.server + "\n" +

          "Password: " + apnSettings.password + "\n" +

          "Proxy: " + apnSettings.proxy + "\n" +

          "Port: " + apnSettings.port + "\n" +

          "MmsProxy: " + apnSettings.mmsProxy + "\n" +

          "MMSC: " + apnSettings.mmsc + "\n" +

          "Type: " + apnSettings.type + "\n" +

          "AuthType: " + apnSettings.authType;

          // Log the retrieved APN settings

  } catch(SecurityException e) {

    Log.w(TAG,"SecurityException: "+ e);

  } 

  //Sample Output

  // Id: 2

  // Name: KT

  // Apn: lte.ktfwing.com

  // MCC: 450 

  // MNC: 08 

  // User:  

  // Server: * 

  // Password:  

  // Proxy:

  // Port: -1

  // MmsProxy: 

  // MMSC: http://mmsc.ktwing.com:9082 

  // Type: *

  // AuthType: 1

 

The administrator can use this API to get the APNs already provisioned on the device and use the ApnSettings object returned to manipulate them.

Permission
The use of this API requires the caller to have the "com.samsung.android.knox.permission.KNOX_APN" permission which has a protection level of signature.
Since
API level 2
MDM 2.0
Multiuser Environment
Global Scope

public ApnSettings getPreferredApnSettings ()

Since: API level 2

API to get preferred APN settings.

Returns
  • Preferred APN settings present on the device if successful, else null.
Throws
SecurityException If caller does not have required permissions
Usage
An administrator can use this API to get the preferred (active) APN on the device and use the ApnSettings object returned to manipulate the APN.


  EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);

  ApnSettingsPolicy apnSettingsPolicy = edm.getApnSettingsPolicy();

  

  try {

      ApnSettings apnSettings = apnSettingsPolicy.getPreferredApnSettings();

      if(apnSettings != null){

          String tmp = "Id: " + apnSettings.id + "\n" +

          "Name: " + apnSettings.name + "\n" +

          "Apn: " + apnSettings.apn + "\n" +

          "MCC: " + apnSettings.mcc + "\n" +

          "MNC: " + apnSettings.mnc + "\n" +

          "User: " + apnSettings.user + "\n" +

          "Server: " + apnSettings.server + "\n" +

          "Password: " + apnSettings.password + "\n" +

          "Proxy: " + apnSettings.proxy + "\n" +

          "Port: " + apnSettings.port + "\n" +

          "MmsProxy: " + apnSettings.mmsProxy + "\n" +

          "MMSC: " + apnSettings.mmsc + "\n" +

          "Type: " + apnSettings.type + "\n" +

          "AuthType: " + apnSettings.authType;

          // Log the retrieved APN settings

  } catch(SecurityException e) {

    Log.w(TAG,"SecurityException: "+ e);

  } 

Permission
The use of this API requires the caller to have the "com.samsung.android.knox.permission.KNOX_APN" permission which has a protection level of signature.
Since
API level 2
MDM 2.0
Multiuser Environment
Global Scope

public boolean setPreferredApn (long apnId)

Since: API level 2

API to set a preferred APN.

Parameters
apnId The Id of the preferred ApnSetting.
Returns
  • true if the APN is set successfully as preferred, else false.
Throws
SecurityException If caller does not have required permissions
Usage
The specified APN is preferred when a connection to an APN is requested. If a connection to the preferred APN is not possible, another APN is chosen from the available list. Use the unique Id obtained when the APN settings were created to set the preferred APN.


  EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);

  ApnSettingsPolicy apnSettingsPolicy = edm.getApnSettingsPolicy();

  

  long apnId = 2;

  try {

      boolean result = apnSettingsPolicy.setPreferredApn(apnId);

  } catch (SecurityException e) {

     Log.w(TAG, "SecurityException: " + e);

  } 

Permission
The use of this API requires the caller to have the "com.samsung.android.knox.permission.KNOX_APN" permission which has a protection level of signature.

Since
API level 2
MDM 2.0
Dependency
The APN must have the MCC and MNC set to the same values of the current carrier and Internet type so it can be set as preferred.
Multiuser Environment
Global Scope

public boolean updateApnSettings (ApnSettings apn)

Since: API level 2

API to update existing APN settings.

Parameters
apn The ApnSetting to be updated.
Returns
  • true if APN has updated successfully, else false.
Throws
SecurityException If caller does not have required permissions
Usage
An administrator can use this API to complete APN information for accessing the data network of a carrier and, using this API, update this item on the device APN list without user interaction. Use the unique Id obtained when the APN settings were created to fill the id field when updating a particular APN.


  EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);

  ApnSettingsPolicy apnSettingsPolicy = edm.getApnSettingsPolicy();

  

  long apnId = 2;

  ApnSettings apnSettings = apnSettingsPolicy.getApnSettings(apnId);  

  apnSettings.user = "ApnUser";

  apnSettings.password = "1234";

  apnSettings.server = "ApnServer";

  apnSettings.mmsc = "http://mms.msg.eg.t-mobile.com/mms/wapenc";

  apnSettings.mmsProxy = "127.0.0.0";

  apnSettings.mmsPort = "80";

  apnSettings.mcc = "310";

  apnSettings.mnc = "260";

  apnSettings.type = "default";

  try {

   if(apnSettings.id != -1){

       if(apnSettingsPolicy.updateApnSettings(apnSettings)) {

           Log.w("APN", "APN settings updated");

       } else {

           Log.w("APN", "FAILED: APN settings not updated");

      }

    } 

  } catch (SecurityException e) {

     Log.w(TAG, "SecurityException: " + e);

  } 

Permission
The use of this API requires the caller to have the "com.samsung.android.knox.permission.KNOX_APN" permission which has a protection level of signature.

Since
API level 2
MDM 2.0
Dependency
ApnSettings object must have an existing id value because this is an update operation.
Multiuser Environment
Global Scope