Since: API level 2
public class

LocationPolicy

extends Object
java.lang.Object
   ↳ com.samsung.android.knox.location.LocationPolicy

Class Overview

This class provides APIs to control the settings related to location services.

Since
API level 2
MDM 2.0

Summary

Public Methods
List<String> getAllLocationProviders()
Deprecated in API level 27
NOTE: This API is not available since Android 10.
boolean getLocationProviderState(String provider)
Deprecated in API level 27
NOTE: This API is not available since Android 10.
boolean isGPSOn()
Deprecated in API level 27
boolean isGPSStateChangeAllowed()
Deprecated in API level 35
boolean setGPSStateChangeAllowed(boolean allow)
Deprecated in API level 35

boolean setLocationProviderState(String provider, boolean enable)
Deprecated in API level 27
NOTE: This API is not available since Android 10.
boolean startGPS(boolean start)
Deprecated in API level 27
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public List<String> getAllLocationProviders ()

Since: API level 2

Deprecated in API level 27
NOTE: This API is not available since Android 10.

API to get all available location services on the device.

Returns
  • A list containing the names of the location services if successful, else false.
Throws
SecurityException If caller does not have required permissions
Usage
An administrator can use this API to get the different location services available (e.g., gps, network, passive) on the device.

 EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
 LocationPolicy locationPolicy = edm.getLocationPolicy();
 try {
 	List list = locationPolicy.getAllLocationProviders();
 	if (list != null) {
 		// getting all available location provider has succeeded
 	} else {
 		// getting all available location provider has failed
 	}
 } catch (SecurityException e) {
 	Log.w(TAG, "SecurityException: " + e);
 }
 // Sample Output
 // gps
 // network
 // passive
 
For Container:
 // When you create container successfully, containerID will be
 // returned via intent.
 // Use this containerID in below API.
 EnterpriseKnoxManager ekm = EnterpriseKnoxManager.getInstance(context);
 KnoxContainerManager kcm = ekm.getKnoxContainerManager(containerID);
 LocationPolicy locationPolicy = kcm.getLocationPolicy();
 try {
 	List list = locationPolicy.getAllLocationProviders();
 	if (list != null) {
 		// getting all available location provider has succeeded
 	} else {
 		// getting all available location provider has failed
 	}
 } catch (SecurityException e) {
 	Log.w(TAG, "SecurityException: " + e);
 }
 // Sample Output
 // gps
 // network
 // passive
 

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

Since
API level 2
MDM 2.0
Multiuser Environment
User Scope

public boolean getLocationProviderState (String provider)

Since: API level 2

Deprecated in API level 27
NOTE: This API is not available since Android 10.

API to get the enabled or disabled state of a given location provider.

Parameters
provider The case sensitive location provider name. Sample values are gps, network, passive.
Returns
  • true if the location provider is enabled, false if the location provider is disabled.
Throws
SecurityException If caller does not have required permissions
Usage
An administrator can use this API to get the enabled or disabled state of a location provider. All available location providers on the device can be obtained by using getAllLocationProviders().

 EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
 LocationPolicy locationPolicy = edm.getLocationPolicy();
 String gpsProvider  = "gps";//case sensitive
  try {
      boolean result = locationPolicy.getLocationProviderState(gpsProvider);
      if(result == true){
          Log.d(TAG,"GPS location provider is not blocked, and user is
          allowed to modify.");
      }else{
          Log.d(TAG,"GPS location provider is disabled by administrator. User not
          allowed to modify.");
      }
  }catch(SecurityException e) {
      Log.w(TAG,"SecurityException: "+e);
  }
 
For Container:
 // When you create container successfully, containerID will be returned via intent.
 // Use this containerID in below API.
 EnterpriseKnoxManager ekm = EnterpriseKnoxManager.getInstance(context);
 KnoxContainerManager kcm = ekm.getKnoxContainerManager(containerID);
  LocationPolicy locationPolicy = kcm.getLocationPolicy();
  String gpsProvider  = "gps";//case sensitive
  try {
      boolean result = locationPolicy.getLocationProviderState(gpsProvider);
      if(result == true){
          Log.d(TAG,"GPS location provider is not blocked, and user is
          allowed to modify.");
      }else{
          Log.d(TAG,"GPS location provider is disabled by administrator. User not
          allowed to modify.");
      }
  }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_LOCATION" permission which has a protection level of signature

Since
API level 2
MDM 2.0
Multiuser Environment
User Scope

public boolean isGPSOn ()

Since: API level 5

Deprecated in API level 27

API to check whether GPS is ON or OFF on the device.

Returns
  • true if GPS is ON, else false.
Throws
SecurityException If caller does not have required permissions
Permission
The use of this API requires the caller to have the "com.samsung.android.knox.permission.KNOX_LOCATION" permission which has a protection level of signature
Note: Since MDM 5.4, caller does not need to have "com.samsung.android.knox.permission.KNOX_LOCATION" permission to call this API.
Since
API level 5
MDM 3.0
Multiuser Environment
User Scope

public boolean isGPSStateChangeAllowed ()

Since: API level 5

Deprecated in API level 35

API to check whether the user is allowed to change the state of GPS on the device.

Returns
  • true if allowed, else false.
Throws
SecurityException If caller does not have required permissions
Usage
An administrator can use this API check whether the user is allowed to change the GPS state. If not allowed, the user cannot change GPS UI settings.

Permission
The use of this API requires the caller to have the "com.samsung.android.knox.permission.KNOX_LOCATION" permission which has a protection level of signature.
Note: Since MDM 5.4, caller does not need to have "com.samsung.android.knox.permission.KNOX_LOCATION" permission to call this API.
Since
API level 5
MDM 3.0
Multiuser Environment
User Scope

public boolean setGPSStateChangeAllowed (boolean allow)

Since: API level 5

Deprecated in API level 35

API to allow or disallow the user changing the state of GPS on the device.

Parameters
allow true to allow user to change state of GPS, false to disallow it.
Returns
  • true if successful, else false.
Throws
SecurityException If caller does not have required permissions
Usage
An administrator can use this API to allow or disallow the user changing the state of GPS. If not allowed, the user cannot change GPS UI settings.

Note:
There is no difference between existing "setLocationProviderState("gps", true)" and "setGPSStateChangeAllowed(true)".
There is one difference between existing "setLocationProviderState("gps", false)" and "setGPSStateChangeAllowed(false)".
When GPS in ON in device.
a) calling "setLocationProviderState("gps", false)" stops GPS and disables it from user change.
b) calling "setGPSStateChangeAllowed(false)" disables GPS to user change but does not stop GPS.

 EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
 LocationPolicy locationPolicy = edm.getLocationPolicy();
 try {
 	boolean result = locationPolicy.setGPSStateChangeAllowed(false);
 	if (result == true) {
 		Log.d(TAG, "User is not allowed to change state of GPS");
 	}
 } catch (SecurityException e) {
 	Log.w(TAG, "SecurityException: " + e);
 }
 
For Container:

NOTE: Since MDM 5.3, only Android users (Owner/Guest user) administrator can call this API. For container, API will return false.

 // When you create container successfully, containerID will be
 // returned via intent.
 // Use this containerID in below API.
 EnterpriseKnoxManager ekm = EnterpriseKnoxManager.getInstance(context);
 KnoxContainerManager kcm = ekm.getKnoxContainerManager(containerID);
 LocationPolicy locationPolicy = kcm.getLocationPolicy();
 try {
 	boolean result = locationPolicy.setGPSStateChangeAllowed(false);
 	if (result == true) {
 		Log.d(TAG, "User is not allowed to change state of GPS");
 	}
 } 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_LOCATION" permission which has a protection level of signature

Since
API level 5
MDM 3.0
Multiuser Environment
User Scope

public boolean setLocationProviderState (String provider, boolean enable)

Since: API level 2

Deprecated in API level 27
NOTE: This API is not available since Android 10.

API to enable or disable a given location provider.

Parameters
provider The case sensitive location provider name. Sample values are gps, network, passive.
enable true to enable the location provider, false to disable the provider.
Returns
  • true if set location service is successful, else false.
Throws
SecurityException If caller does not have required permissions
IllegalArgumentException If provider name is invalid or empty
Usage
An administrator can use this API to enable or disable a location provider. If set to false, given location provider control is disabled, and the user cannot turn it on until the administrator enables it again. If set to true, given location provider control is enabled. Enabling a given location provider enables the corresponding UI setting for user change but does not enable the location provider itself. Please note some UI settings may require more than one location provider enabled so they can be available for user changes. All available location providers on the device can be obtained by using getAllLocationProviders().

 EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
 LocationPolicy locationPolicy = edm.getLocationPolicy();
 String gpsProvider = "gps";// case sensitive
 try {
 	boolean result = locationPolicy.setLocationProviderState(gpsProvider, false);
 	if (result == true) {
 		Log.d(TAG, " GPS location provider is disabled !!!");
 	} else {
 		Log.d(TAG, "GPS location provider disable failed !!!");
 	}
 } catch (SecurityException e) {
 	Log.w(TAG, "SecurityException: " + e);
 }
 
For Container:

NOTE: Since MDM 5.3, only Android users (Owner/Guest user) administrator can call this API. For container, API will return false.

 // When you create container successfully, containerID will be
 // returned via intent.
 // Use this containerID in below API.
 EnterpriseKnoxManager ekm = EnterpriseKnoxManager.getInstance(context);
 KnoxContainerManager kcm = ekm.getKnoxContainerManager(containerID);
 LocationPolicy locationPolicy = kcm.getLocationPolicy();
 String gpsProvider = "gps";// case sensitive
 try {
 	boolean result = locationPolicy.setLocationProviderState(gpsProvider, false);
 	if (result == true) {
 		Log.d(TAG, " GPS location provider is disabled !!!");
 	} else {
 		Log.d(TAG, "GPS location provider disable 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_LOCATION" permission which has a protection level of signature

Since
API level 2
MDM 2.0
Multiuser Environment
User Scope

public boolean startGPS (boolean start)

Since: API level 5

Deprecated in API level 27

API to start or stop GPS on the device.

Parameters
start true to start GPS, false to stop.
Returns
  • true if start or stop GPS is successful, else false.
Throws
SecurityException If caller does not have required permissions
Usage
An administrator can use this API to start or stop GPS on the device. If set to true, GPS is started. If set to false, GPS is stopped.

 EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
 LocationPolicy locationPolicy = edm.getLocationPolicy();
 try {
 	boolean result = locationPolicy.startGPS(true);
 	if (result == true) {
 		Log.d(TAG, "Start GPS success !!!");
 	} else {
 		Log.d(TAG, "Start GPS success fail !!!");
 	}
 } catch (SecurityException e) {
 	Log.w(TAG, "SecurityException: " + e);
 }
 
For Container:
 // When you create container successfully, containerID will be
 // returned via intent.
 // Use this containerID in below API.
 EnterpriseKnoxManager ekm = EnterpriseKnoxManager.getInstance(context);
 KnoxContainerManager kcm = ekm.getKnoxContainerManager(containerID);
 LocationPolicy locationPolicy = kcm.getLocationPolicy();
 try {
 	boolean result = locationPolicy.startGPS(true);
 	if (result == true) {
 		Log.d(TAG, "Start GPS success !!!");
 	} else {
 		Log.d(TAG, "Start GPS success fail !!!");
 	}
 } 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_LOCATION" permission which has a protection level of signature

Since
API level 5
MDM 3.0
Multiuser Environment
User Scope
See Also