Since: API level 25
public class

DexManager

extends Object
java.lang.Object
   ↳ com.samsung.android.knox.dex.DexManager

Class Overview

This class provides APIs to control the Dex mode. API functions include disabling and enabling Dex mode, making configurations, and querying the current status of Dex mode

Since
API level 25
KNOX 3.1

Summary

Constants
int DEX_APP_ALREADY_SET_POLICY Flag to indicate that API failed because of already set the policy.
int DEX_APP_NOT_INSTALLED Flag to Dex application API failed because of application is not installed.
int DEX_APP_NOT_SET_POLICY Flag to indicate that API failed because this application has not set a policy.
int DEX_POLICY_FAIL Flag to Dex application API failed because any exception.
int DEX_POLICY_SUCCESS Flag to Dex application API success.
Public Methods
int addPackageToDisableList(String packageName)
API to add a application package name to Dex mode disable list.
int addShortcut(int x, int y, ComponentName component)
This method adds an application shortcut to the Dex launcher at the specified position.
int addURLShortcut(int x, int y, String title, String url, String imgName, ComponentName component, ParcelFileDescriptor imgFD)
This method adds a new browser shortcut linking the specific url with customized icon to the DeX launcher.
int addURLShortcut(int x, int y, String title, String url, ComponentName component)
This method adds a new browser shortcut linking the specific url to the DeX launcher.
boolean allowScreenTimeoutChange(boolean allow)
API to allow or disallow the user changing the screen time out for Dex mode.
int clearLoadingLogo()
This method clears the logo that is displayed when the phone is starting Dex and restores the default logo.
boolean enforceEthernetOnly(boolean enforced)
API to enforce or release the ethernet only mode.
boolean enforceVirtualMacAddress(boolean use)
API to set use virtual MAC address for Dex mode.
List<String> getForegroundModePackageList()
This method gets a package whitelist of foreground mode from dex.
int getHomeAlignment()
This method gets the DeX alignment mode.
List<String> getPackagesFromDisableList()
API to get the list of disabled application package names for Dex mode.
int getScreenTimeout()
This method gets the Dex mode screen timeout in seconds.
String getVirtualMacAddress()
API to get virtual MAC Address

boolean isDexActivated()
API to check whether Dex mode is activated.
boolean isDexDisabled()
API to check whether Dex mode is enabled.
boolean isEthernetOnlyEnforced()
API to check whether ethernet only mode is enforced.
boolean isScreenTimeoutChangeAllowed()
API to check whether the user is allowed to change the screen time out for Dex mode.
boolean isVirtualMacAddressEnforced()
API to check enforced use of the virtual MAC address for Dex mode.
int removePackageFromDisableList(String packageName)
API to remove the application package name from Dex mode disable list.
int removeShortcut(ComponentName component)
This method removes an application shortcut from the Dex launcher.
int removeURLShortcut(String url, ComponentName component)
This method removes the given shortcut from the DeX launcher.
boolean setDexDisabled(boolean disabled)
API to enable or disable the Dex mode

int setForegroundModePackageList(int state, List<String> pkgList)
This method adds, removes, clears a package whitelist for dex foreground mode.
int setHomeAlignment(int mode)
This method sets the DeX alignment mode.
int setLoadingLogo(ParcelFileDescriptor logoFD)
This method sets the logo that is displayed when the phone is starting Dex.
int setScreenTimeout(int timeout)
This method sets the Dex mode screen timeout to the specified number of seconds.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int DEX_APP_ALREADY_SET_POLICY

Since: API level 25

Flag to indicate that API failed because of already set the policy.

Since
API level 25
KNOX 3.1
Constant Value: 3 (0x00000003)

public static final int DEX_APP_NOT_INSTALLED

Since: API level 25

Flag to Dex application API failed because of application is not installed.

Since
API level 25
KNOX 3.1
Constant Value: 2 (0x00000002)

public static final int DEX_APP_NOT_SET_POLICY

Since: API level 25

Flag to indicate that API failed because this application has not set a policy.

Since
API level 25
KNOX 3.1
Constant Value: 4 (0x00000004)

public static final int DEX_POLICY_FAIL

Since: API level 25

Flag to Dex application API failed because any exception.

Since
API level 25
KNOX 3.1
Constant Value: 1 (0x00000001)

public static final int DEX_POLICY_SUCCESS

Since: API level 25

Flag to Dex application API success.

Since
API level 25
KNOX 3.1
Constant Value: 0 (0x00000000)

Public Methods

public int addPackageToDisableList (String packageName)

Since: API level 25

API to add a application package name to Dex mode disable list.

Parameters
packageName The application package name to be added to disable list for Dex mode.
Throws
SecurityException If caller does not have required permissions
Usage
An administrator can use this API to add application package names to Dex mode disable list.

NOTE: This API works only for owner (User 0) space applications.

 EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
 DexManager dexMgr = edm.getDexManager();
 try {
     int status = dexMgr.addPackageToDisableList("com.test.app");
     // status is operation result
 } 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_DEX" permission which has a protection level of signature.

Since
API level 25
KNOX 3.1
Multiuser Environment
Global Scope

public int addShortcut (int x, int y, ComponentName component)

Since: API level 25

This method adds an application shortcut to the Dex launcher at the specified position.

Parameters
x The x position of the shortcut and it starts from 0.
y The y position of the shortcut and it starts from 0.
component The component name of the required shortcut.
Returns
Throws
SecurityException The calling application does not have the required permission.
Usage
 try {
     CustomDeviceManager cdm = CustomDeviceManager.getInstance();
     DexManager kcdm = cdm.getDexManager();
     ComponentName component = new ComponentName("com.android.chrome", com.google.android.apps.chrome.Main");
     kcdm.addShortcut(0, 0, component);
 } 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_CUSTOM_DEX" permission.
Since
API level 25
KNOX 3.1
Multiuser Environment
Global Scope

public int addURLShortcut (int x, int y, String title, String url, String imgName, ComponentName component, ParcelFileDescriptor imgFD)

Since: API level 26

This method adds a new browser shortcut linking the specific url with customized icon to the DeX launcher.

Parameters
x The x position of the URL shortcut.
y The y position of the URL shortcut.
title The Title of the URL shortcut.
url The URL address of the URL shortcut.
imgName The File name of the icon image.
component The specific component to launch the URL shortcut.
imgFD The File descriptor of the icon image.
Returns
Throws
SecurityException The calling application does not have the required permission.
Usage
 try {
     CustomDeviceManager cdm = CustomDeviceManager.getInstance();
     DexManager kcdm = cdm.getDexManager();
     String url = "http://www.naver.com";
     String imgName = "Firefox.bmp";
     ComponentName component = new ComponentName("com.android.chrome", "com.google.android.apps.chrome.Main");
     ParcelFileDescriptor imgFD = ParcelFileDescriptor.open(new File(logoFile), ParcelFileDescriptor.MODE_READ_ONLY);
     kcdm.addURLShortcut( 0, 0, "shortcut", url, imgName, component, imgFD);
 } 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.CUSTOM_DEX" permission.
Since
API level 26
KNOX 3.2
Multiuser Environment
Global Scope

public int addURLShortcut (int x, int y, String title, String url, ComponentName component)

Since: API level 26

This method adds a new browser shortcut linking the specific url to the DeX launcher.

Parameters
x The x position of the URL shortcut.
y The y position of the URL shortcut.
title The Title of the URL shortcut.
url The URL address of the URL shortcut.
component The specific component to launch the URL shortcut.
Returns
Throws
SecurityException The calling application does not have the required permission.
Usage
 try {
     CustomDeviceManager cdm = CustomDeviceManager.getInstance();
     DexManager kcdm = cdm.getDexManager();
     String url = "http://www.naver.com";
     ComponentName component = new ComponentName("com.android.chrome", "com.google.android.apps.chrome.Main");
     kcdm.addURLShortcut( 0, 0, "shortcut", url, component);
 } 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.CUSTOM_DEX" permission.
Since
API level 26
KNOX 3.2
Multiuser Environment
Global Scope

public boolean allowScreenTimeoutChange (boolean allow)

Since: API level 25

API to allow or disallow the user changing the screen time out for Dex mode.

Parameters
allow true to allow, false to disallow
Returns
  • true if operation is 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 screen time out for Dex mode. If not allowed, the user cannot change the screen time out.

 EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
 DexManager dexMgr = edm.getDexManager();
 // disable
 try {
     if (dexMgr.allowScreenTimeoutChange(false)) {
         // Screen time out change is not allowed.
     } else {
         // failure restricting Dex mode.
     }
     // enable
     if (dexMgr.allowScreenTimeoutChange(true)) {
         // Screen time out change is allowed.
     } else {
         // failure removing restriction of Dex mode.
     }
 } 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_DEX" permission which has a protection level of signature.

Since
API level 25
KNOX 3.1
Multiuser Environment
Global Scope
See Also

public int clearLoadingLogo ()

Since: API level 25

This method clears the logo that is displayed when the phone is starting Dex and restores the default logo.

Returns
  • SUCCESS The Dex loading logo was successfully restored.
Throws
SecurityException The calling application does not have the required permission.
Usage
 try {
     CustomDeviceManager cdm = CustomDeviceManager.getInstance();
     DexManager kcdm = cdm.getDexManager();
     kcdm.clearLoadingLogo();
 } 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_CUSTOM_DEX" permission.
Since
API level 25
KNOX 3.1
Multiuser Environment
Global Scope

public boolean enforceEthernetOnly (boolean enforced)

Since: API level 25

API to enforce or release the ethernet only mode.

Parameters
enforced true to enforce, false to release.
Returns
  • true if operation is successful, else false
Throws
SecurityException If caller does not have required permissions
Usage
An administrator can use this API to enable ethernet only mode without user interaction. Cellular data / wifi / tetherings(wifi, bluetooth, usb) are restricted in Dex mode.

NOTE: setCellularData(), setWifiState(), setWifiTethering(), setUsbTethering(), setBluetoothTethering() will return false when device is in Dex mode under ethernet only mode

 EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
 DexManager dexMgr = edm.getDexManager();
 // enforce
 try {
     if (dexMgr.enforceEthernetOnly(true)) {
         // Ethernet only mode is enabled.
     } else {
         // failure restricting ethernet only mode.
     }
     // release
     if (dexMgr.enforceEthernetOnly(false)) {
         // Ethernet only mode is disabled.
     } else {
         // failure removing restriction of ethernet only mode.
     }
 } 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_DEX" permission which has a protection level of signature.

Since
API level 25
KNOX 3.1
Multiuser Environment
Global Scope

public boolean enforceVirtualMacAddress (boolean use)

Since: API level 25

API to set use virtual MAC address for Dex mode.

Returns
  • true if operation is successful, else false
Throws
SecurityException If caller does not have required permissions
Usage
An administrator can use this API to use the virtual MAC address for Dex mode.

 EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
 DexManager dexMgr = edm.getDexManager();
 // disable
 try {
     if (dexMgr.enforceVirtualMacAddress(false)) {
         // Use phone MAC address
     }
     
     if (dexMgr.enforceVirtualMacAddress(true)) {
         // Use virtual MAC addres
     } 
 } 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_DEX" permission which has a protection level of signature.

Since
API level 25
KNOX 3.1
Multiuser Environment
Global Scope

public List<String> getForegroundModePackageList ()

Since: API level 26

This method gets a package whitelist of foreground mode from dex.

Returns
  • The List of the packages.
Usage
 CustomDeviceManager cdm = CustomDeviceManager.getInstance();
 DexManager kcdm = cdm.getDexManager();
 List foregroundModepackageList = kcdm.getForegroundModePackageList();
 
Since
API level 26
KNOX 3.2
Multiuser Environment
Global Scope

public int getHomeAlignment ()

Since: API level 26

This method gets the DeX alignment mode.

Returns
Throws
SecurityException The calling application does not have the required permission.
Usage
 CustomDeviceManager cdm = CustomDeviceManager.getInstance();
 DexManager kcdm = cdm.getDexManager();
 int alignment = kcdm.getHomeAlignment();
 
Permission
The use of this API requires the caller to have the "com.samsung.android.knox.permission.KNOX_CUSTOM_DEX" permission.
Since
API level 26
KNOX 3.2
Multiuser Environment
Global Scope

public List<String> getPackagesFromDisableList ()

Since: API level 25

API to get the list of disabled application package names for Dex mode.

Returns
  • List of the disabled application package names for Dex mode if it succeeds, else null
Usage
An administrator can use this API to get the list of application package names that are disabled from Dex mode disable list.

 EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
 DexManager dexMgr = edm.getDexManager();
 List blacklist = dexMgr.getPackagesFromDisableList();
 
Since
API level 25
KNOX 3.1
Multiuser Environment
Global Scope

public int getScreenTimeout ()

Since: API level 25

This method gets the Dex mode screen timeout in seconds.

Returns
  • The screen timeout in seconds.
Usage
 CustomDeviceManager cdm = CustomDeviceManager.getInstance();
 DexManager kcdm = cdm.getDexManager();
 int screenTimeout = kcdm.getScreenTimeout();
 
Since
API level 25
KNOX 3.1
Multiuser Environment
Global Scope

public String getVirtualMacAddress ()

Since: API level 25

API to get virtual MAC Address

Returns
  • Virtual MAC address
Usage
An administrator can use this API to get virtual MAC Address

Since
API level 25
KNOX 3.1
Multiuser Environment
Global Scope

public boolean isDexActivated ()

Since: API level 25

API to check whether Dex mode is activated.

Returns
  • true if activated, false if deactivated
Usage
An administrator can use this API to check whether the Dex mode is activated or not.

Since
API level 25
KNOX 3.1
Multiuser Environment
Global Scope

public boolean isDexDisabled ()

Since: API level 25

API to check whether Dex mode is enabled.

Returns
  • true if enabled, false if disabled
Usage
An administrator can use this API to check whether the Dex mode is enabled or not.

Since
API level 25
KNOX 3.1
Multiuser Environment
Global Scope

public boolean isEthernetOnlyEnforced ()

Since: API level 25

API to check whether ethernet only mode is enforced.

Returns
  • true if enforced, false if released
Usage
An administrator can use this API to check whether the ethernet only mode is enforced or not.

Since
API level 25
KNOX 3.1
Multiuser Environment
Global Scope

public boolean isScreenTimeoutChangeAllowed ()

Since: API level 25

API to check whether the user is allowed to change the screen time out for Dex mode.

Returns
  • true if enabled, false if disabled
Usage
An administrator can use this API check whether the user is allowed to change the screen time out. If not allowed, the user cannot change the screen time out.

Since
API level 25
KNOX 3.1
Multiuser Environment
Global Scope

public boolean isVirtualMacAddressEnforced ()

Since: API level 25

API to check enforced use of the virtual MAC address for Dex mode.

Returns
  • true if use virtual MAC address, false if use phone MAC address.
Usage
An administrator can use this API to check whether the virtual MAC address is used in Dex mode.

Since
API level 25
KNOX 3.1
Multiuser Environment
Global Scope

public int removePackageFromDisableList (String packageName)

Since: API level 25

API to remove the application package name from Dex mode disable list.

Parameters
packageName The application package name to be remove from disable list for Dex mode.
Throws
SecurityException If caller does not have required permissions
Usage
An administrator can use this API to remove disabled application package name from Dex mode disable list.

 EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
 DexManager dexMgr = edm.getDexManager();
 try {
     int status = dexMgr.removePackageFromDisableList("com.test.app");
     // status is operation result
 } 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_DEX" permission which has a protection level of signature.
Since
API level 25
KNOX 3.1
Multiuser Environment
Global Scope

public int removeShortcut (ComponentName component)

Since: API level 25

This method removes an application shortcut from the Dex launcher.
NOTE: This method will remove all shortcuts for the specified package.

Parameters
component The component name of the shortcut to be removed.
Returns
Throws
SecurityException The calling application does not have the required permission.
Usage
 try {
     CustomDeviceManager cdm = CustomDeviceManager.getInstance();
     DexManager kcdm = cdm.getDexManager();
     ComponentName component = new ComponentName("com.android.chrome", com.google.android.apps.chrome.Main");
     kcdm.removeShortcut(component);
 } 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_CUSTOM_DEX" permission.
Since
API level 25
KNOX 3.1
Multiuser Environment
Global Scope

public int removeURLShortcut (String url, ComponentName component)

Since: API level 26

This method removes the given shortcut from the DeX launcher.

Parameters
url The URL address of the URL shortcut.
component The component name of the shortcut to be removed.
Returns
Throws
SecurityException The calling application does not have the required permission.
Usage
 try {
     CustomDeviceManager cdm = CustomDeviceManager.getInstance();
     DexManager kcdm = cdm.getDexManager();
     ComponentName component = new ComponentName("com.android.chrome", "com.google.android.apps.chrome.Main");
     kcdm.removeURLShortcut( "http://www.naver.com", component)
 } 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.CUSTOM_DEX" permission.
Since
API level 26
KNOX 3.2
Multiuser Environment
Global Scope

public boolean setDexDisabled (boolean disabled)

Since: API level 25

API to enable or disable the Dex mode

Parameters
disabled true to disable dex, false to enable dex
Returns
  • true if operation is successful, else false
Throws
SecurityException If caller does not have required permissions
Usage
An administrator can use this API to disable Dex mode without user interaction.

 EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
 DexManager dexMgr = edm.getDexManager();
 // disable
 try {
     if (dexMgr.setDexDisabled(false)) {
         // Dex mode is disabled.
     } else {
         // failure restricting Dex mode.
     }
     // enable
     if (dexMgr.setDexDisabled(true)) {
         // Dex mode is enabled.
     } else {
         // failure removing restriction of Dex mode.
     }
 } 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_DEX" permission which has a protection level of signature.

Since
API level 25
KNOX 3.1
Multiuser Environment
Global Scope
See Also

public int setForegroundModePackageList (int state, List<String> pkgList)

Since: API level 26

This method adds, removes, clears a package whitelist for dex foreground mode.

Parameters
state ADD Specify the package to run as foreground when DeX mode starts. REMOVE Remove the package from the current specificed list. CLEAR Clear the current speficied list.
pkgList Specific package list. If the package name is wrong or not installed, it will be ignored.
Returns
Throws
SecurityException The calling application does not have the required permission.
Usage
This API adds, removes, or clears a package whitelist for the DeX foreground mode. An app that is in the foreground will be automatically launched after the device is connected to a monitor.

NOTE: This API works only for owner (User 0) space applications.

 try {
     CustomDeviceManager cdm = CustomDeviceManager.getInstance();
     DexManager kcdm = cdm.getDexManager();
     List pkgList = new List<>{"com.android.chrome"};
     kcdm.setForegroundModePackageList( CustomDeviceManager.ADD, pkgList);
 } 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.CUSTOM_DEX" permission.
Since
API level 26
KNOX 3.2
Multiuser Environment
Global Scope

public int setHomeAlignment (int mode)

Since: API level 26

This method sets the DeX alignment mode.

Parameters
mode CUSTOM_GRID This is the Custom Grid mode for Dex launcher.
ALPHABETIC_GRID This is the Alphabetic Grid mode for Dex launcher.
TYPE_GRID This is the Type Grid mode for Dex launcher.
Returns
Throws
SecurityException The calling application does not have the required permission.
Usage
 CustomDeviceManager cdm = CustomDeviceManager.getInstance();
 DexManager kcdm = cdm.getDexManager();
 int mode = CustomDeviceManager.ALPHABETIC_GRID;
 kcdm.setHomeAlignment(mode);
 
Permission
The use of this API requires the caller to have the "com.samsung.android.knox.permission.KNOX_CUSTOM_DEX" permission.
Since
API level 26
KNOX 3.2
Multiuser Environment
Global Scope

public int setLoadingLogo (ParcelFileDescriptor logoFD)

Since: API level 25

This method sets the logo that is displayed when the phone is starting Dex.

Parameters
logoFD The descriptor of the file to be used as the logo. The logo file must be a png image.
Returns
Throws
SecurityException The calling application does not have the required permission.
Usage
 try {
     CustomDeviceManager cdm = CustomDeviceManager.getInstance();
     DexManager kcdm = cdm.getDexManager();
     ParcelFileDescriptor logoFD = ParcelFileDescriptor.open(new File(logoFile), ParcelFileDescriptor.MODE_READ_ONLY);
     kcdm.setLoadingLogo(logoFD);
 } 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_CUSTOM_DEX" permission.
Since
API level 25
KNOX 3.1
Multiuser Environment
Global Scope

public int setScreenTimeout (int timeout)

Since: API level 25

This method sets the Dex mode screen timeout to the specified number of seconds. Samsung DeX supports 2 modes: Dual View mode and Standalone Mode For 'StandAlone mode',screen timeout for DeX should be set to the Device settings' value. For 'DualView mode', screen timeout for DeX sholuld be set to SettingsProvider for DeX only, not Settings.

Parameters
timeout The new Dex mode screen timeout in seconds.
Returns
Throws
SecurityException The calling application does not have the required permission.
Usage
 try {
     CustomDeviceManager cdm = CustomDeviceManager.getInstance();
     DexManager kcdm = cdm.getDexManager();
     kcdm.setScreenTimeout(1200);
 } 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_DEX" permission.
Since
API level 25
KNOX 3.1
Multiuser Environment
Global Scope