| java.lang.Object | |
| ↳ | com.datalogic.device.configuration.ProfileManager |
ProfileManager gives the developer the ability to create a profile and to load it explicitly or to associate it to a loading condition to be automatically loaded.
A profile is a set of properties (Property) with their value.
The utility of a profile is that we can collect in it the setting of the properties we need for a
specific purpose and then we can load it explicitly calling loadProfile(String) or automatically when the loading condition is verified.
The loading condition is defined by a profile rule. There are two types of profile rules:
ProfileRuleType: the profile is loaded when an activity comes to
foreground.
The rule associates the profile to be loaded with an activity, or a list of activities, that must be in foreground.
This type of rule is created using the method addProfileRule(StringBuffer, String, String, ArrayList) .
ProfileUrlRuleType: the profile is loaded when a specified URL is loaded by a given activity.
The rule associates the profile to be loaded with an activity, or a list of activities, and a regular expression (regex) that defines a valid URL.
This type of rule is created using the method addProfileUrlRule(StringBuffer, String, String, ArrayList, String) .
PersistenceType that can be:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Profile Description Schema",
"description": "Schema of a profile.",
"type": "object",
"version": "2.0.0",
"definitions": {
"properties": {
"type": "array",
"items": { "$ref": "#/definitions/property" }
},
"property": {
"type": "object",
"properties": {
"id": {
"type": ["integer", "string"],
"description": "Unique integer identifier of the property.
The defining string can be used instead of the numeric value."
},
"value": {
"type": "string",
"description": "Value of the property. It is a string and
it will be parsed according to the specific type of the property.
Value for a CharacterProperty is the unicode format (i.e: \\uFFFF)."
}
},
"required": ["id", "value"]
},
},
"properties": {
"version": {
"type": "string",
"description": "Version of the schema. If you use this the value must be 2.0.0."
} ,
"description": {
"type": "string",
"description": "Short string describing the profile."
},
"properties": {
"$ref": "#/definitions/properties",
"description": "List of properties with their value."
}
}
}
loadProfile(String);
addProfileRule(StringBuffer, String, String, ArrayList) or addProfileUrlRule(StringBuffer, String, String, ArrayList, String) to define a rule that associates the profile to an activation condition.
As soon as the condition is verified, the related profile is automatically loaded.
The previous configuration is restored when that condition is no more satisfied.
loadProfile(String) fails if there is already a profile manually loaded.
ProfileManager(Context);
PropertyID, value} to be set when applying the profile;
createProfile(String, HashMap, String, PersistenceType).
ProfileManager pm = new ProfileManager(this); HashMapTo add a rule that automatically loads the profile profilo_128.json when the application with package name com.datalogic.testprofilo1 comes to the foreground, follow these steps:map = new HashMap (); map.put(PropertyID.CODE128_ENABLE, "true"); // BooleanProperty map.put(PropertyID.CODE128_LENGTH2, "10"); // NumericProperty map.put(PropertyID.CODE128_GS1_USER_ID, String.format ("\\u%04x", (int)'a')); // CharacterProperty map.put(PropertyID.CODE128_LENGTH_CONTROL, LengthControlMode.ONE_FIXED.toString()); // EnumProperty map.put(PropertyID.LABEL_PREFIX, "pippo"); // TextProperty pm.createProfile("profilo_128.json", map, "enable code128, disable datamatrix", PersistenceType.ENTERPRISE_RESET_PERSISTENT);
ProfileManager(Context).
addProfileRule(StringBuffer, String, String, ArrayList) .
ProfileManager pm = new ProfileManager(this);
StringBuffer rule1_name = new StringBuffer("rule_1");
pm.addProfileRule(rule1_name,
"profilo_1.json",
"com.datalogic.testprofilo1",
new ArrayList());
To define a rule that automatically loads the profile profilo_128.json when the app with package name com.datalogic.testprofilo1
comes to the foreground and accesses any URL under "https://www.datalogic.com", follow these steps:
ProfileManager(Context).
addProfileUrlRule(StringBuffer, String, String, ArrayList, String) .
ProfileManager pm = new ProfileManager(this);
StringBuffer rule1_name = new StringBuffer("rule_1");
pm.addProfileUrlRule(rule1_name,
"profilo_1.json",
"com.datalogic.testprofilo1",
new ArrayList(),
"^https://www\\.datalogic\\.com(/.*)?$");
To manually load the profile profilo_128.json follow these steps:
ProfileManager(Context).
loadProfile(String).
ProfileManager pm = new ProfileManager(this);
pm.loadProfile("profilo_1.json");
To get the identifier of the manually loaded profile, if any, follow these steps:
ProfileManager(Context).
getLoadedProfile().
ProfileManager pm = new ProfileManager(this); String profile = pm.getLoadedProfile();To unload the manually loaded profile follow these steps:
ProfileManager(Context).
unloadProfile().
ProfileManager pm = new ProfileManager(this); pm.unloadProfile();To delete the profile profilo_128.json follow these steps:
ProfileManager(Context).
deleteProfile(String).
ProfileManager pm = new ProfileManager(this);
pm.deleteProfile("profilo_1.json");
To remove the rule "rule_1" follow these steps:
ProfileManager(Context).
removeProfileRule(String).
ProfileManager pm = new ProfileManager(this);
pm.removeProfileRule("rule_1");
To get the list of all the profiles saved on the device follow these steps:
ProfileManager(Context).
getProfilesList().
ProfileManager pm = new ProfileManager(this); ArrayList<ProfileType> profileList = pm.getProfilesList();To get the list of all the rules defined on the device follow these steps:
ProfileManager(Context).
getProfileRulesList().
ProfileManager pm = new ProfileManager(this); ArrayList<ProfileRuleType> profileRuleList = pm.getProfileRulesList();
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
This is the constructor of ProfileManager.
| |||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Creates a rule to automatically load the given profile when one of the specified activities comes to foreground.
| |||||||||||
Creates a rule to automatically load the given profile when one of the specified activities comes to foreground loading an url that matches the specified rule in regex format.
| |||||||||||
Creates the profile with the given name and the specified persistence type.
| |||||||||||
Saves the given map as a profile with the specified name, description and persistence type.
| |||||||||||
Deletes the given profile.
| |||||||||||
Returns the name of the manually loaded profile, otherwise an empty string.
| |||||||||||
Gets the list of all the profile rules defined on the device.
| |||||||||||
Gets the list of all the profiles saved on the device.
| |||||||||||
Applies the given profile.
| |||||||||||
Delete the specified rule.
| |||||||||||
Revert the manually loaded profile restoring the values previously set on the device.
| |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
This is the constructor of ProfileManager.
| context | Context context of the caller application |
|---|
| ConfigException | in case of error. |
|---|
Creates a rule to automatically load the given profile when one of the specified activities comes to foreground.
The specified activities must all belong to the same package.
When the activity is no more in foreground the previous configuration is restored.
A rule is uniquely identified by its name which must therefore be unique. In input, through parameter name, you can specify the name to be associated with the rule.
If name is unique it is used, otherwise the method makes it unique adding it a suffix.
The caller can learn the string used to name the rule because the StringBuffer object name is updated.
The profile associated to the rule is the one found with the given name.
There must be only one rule to be loaded when an activity comes to the foreground.
If one of the specified activities already has an associated profile the method fails.
The persistence to reboot of a rule is that of the referred profile. If the referred profile is deleted by reboot all the rules in which it is referred are deleted.
| name | StringBuffer in input an empty string or the preferred name for the rule, in output the unique name assigned
to the rule; if the value in input is unique and not empty is the value used otherwise the method makes it unique adding a suffix. |
|---|---|
| profile | String the name of the profile to be loaded when one of the given activities comes to foreground. |
| packageName | String name of the package containing the given activities. |
| classes | ArrayList list of class names inside of the package for which the profile must be loaded.
If the list is empty it means all the classes of the package. |
SUCCESS in case of success, otherwise a possible error
code, matching one of the ConfigException error constants.| ConfigException | in case of error, when exceptions are enabled through the ErrorManager singleton.
|
|---|
Creates a rule to automatically load the given profile when one of the specified activities comes to foreground loading an url that matches the specified rule in regex format.
The specified activities must all belong to the same package.
When the activity is no more in foreground or the url is unloaded the previous configuration is restored.
Important: This URL-based profile rule feature is only supported for applications that use Android's
Webview component. Applications that use proprietary or custom WebView implementations,
such as Google Chrome or Mozilla Firefox, are not supported. These browsers compile their own
rendering engines (Blink for Chrome, Gecko for Firefox) and do not use the standard Android WebView,
which prevents the system from detecting URL changes within those applications.
A rule is uniquely identified by its name which must therefore be unique. In input, through parameter name, you can specify the name to be associated with the rule.
If name is unique it is used, otherwise the method makes it unique adding it a suffix.
The caller can learn the string used to name the rule because the StringBuffer object name is updated.
The profile associated to the rule is the one found with the given name.
There must be only one rule to be loaded when the activation condition (activity in foreground and url loaded) becomes true.
If the rule doesn't satisfy this condition the method fails.
The persistence to reboot of a rule is that of the referred profile. If the referred profile is deleted by reboot all the rules in which it is referred are deleted.
| name | StringBuffer in input an empty string or the preferred name for the rule, in output the unique name assigned
to the rule; if the value in input is unique and not empty is the value used otherwise the method makes it unique adding a suffix. |
|---|---|
| profile | String the name of the profile to be loaded when one of the given activities comes to foreground. |
| packageName | String name of the package containing the given activities. |
| classes | ArrayList list of class names inside of the package for which the profile must be loaded.
If the list is empty it means all the classes of the package. |
| urlRegex | String regex for the URL. Exact URL string is valid. |
SUCCESS in case of success, otherwise a possible error
code, matching one of the ConfigException error constants.| ConfigException | in case of error, when exceptions are enabled through the ErrorManager singleton.
|
|---|
Creates the profile with the given name and the specified persistence type.
If a profile with the same name is already present the method fails.
The schema of the profile file is:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Profile Description Schema",
"description": "Schema of a profile.",
"type": "object",
"version": "2.0.0",
"definitions": {
"properties": {
"type": "array",
"items": { "$ref": "#/definitions/property" }
},
"property": {
"type": "object",
"properties": {
"id": {
"type": ["integer", "string"],
"description": "Unique integer identifier of the property.
The defining string can be used instead of the numeric value."
},
"value": {
"type": "string",
"description": "Value of the property. It is a string and
it will be parsed according to the specific type of the property.
Value for a CharacterProperty is the unicode format (i.e: \\uFFFF)."
}
},
"required": ["id", "value"]
},
},
"properties": {
"version": {
"type": "string",
"description": "Version of the schema. If you use this the value must be 2.0.0."
} ,
"description": {
"type": "string",
"description": "Short string describing the profile."
},
"properties": {
"$ref": "#/definitions/properties",
"description": "List of properties with their value."
}
}
}
| name | String name to be used to create the profile file.
The name must have the ".json" extension, otherwise it is added by the method. |
|---|---|
| profile | File file of the profile to be saved on the device.
The file must have the schema shown above. |
| persistence | the persistence mode assigned to the profile file to be created.
Only REBOOT_PERSISTENT and ENTERPRISE_RESET_PERSISTENT are allowed.
It is not possible to create a profile with FACTORY_RESET_PERSISTENT persistence.
A Factory Reset Persistent profile can only be preinstalled on the device by an Espresso OTA and cannot be deleted. |
SUCCESS in case of success, otherwise a possible error
code, matching one of the ConfigException error constants.| ConfigException | in case of error, when exceptions are enabled through the ErrorManager singleton.
|
|---|
Saves the given map as a profile with the specified name, description and persistence type.
If a profile with the same name is already present the method fails.
The profile file is a .json file with the schema shown in createProfile(String, File, PersistenceType).
| name | String name to be used to create the profile file.
The name must have the ".json" extension, otherwise it is added. |
|---|---|
| map | HasMap map of properties with their value to be saved as profile. |
| description | String description to be associated to the profile. |
| persistence | the persistence mode to be assigned to the profile.
Only REBOOT_PERSISTENT and ENTERPRISE_RESET_PERSISTENT are allowed.
It is not possible to save a profile with FACTORY_RESET_PERSISTENT persistence. |
SUCCESS in case of success, otherwise a possible error
code, matching one of the ConfigException error constants.| ConfigException | in case of error, when exceptions are enabled through the ErrorManager singleton.
|
|---|
Deletes the given profile.
The method fails if the profile has FACTORY_RESET_PERSISTENT persistence or
it is currently loaded or it is associated to a rule.
| name | String name of the profile file to be deleted. |
|---|
SUCCESS in case of success, otherwise a possible error
code, matching one of the ConfigException error constants.| ConfigException | in case of error, when exceptions are enabled through the ErrorManager singleton.
|
|---|
Returns the name of the manually loaded profile, otherwise an empty string.
Gets the list of all the profile rules defined on the device. See @link{ProfileRuleType} and @link{ProfileRuleUrlType} for more info.
ProfileRuleType> in case of success, otherwise, if exceptions are not enabled, a null pointer.| ConfigException | in case of error, when exceptions are enabled through the ErrorManager singleton.
|
|---|
Gets the list of all the profiles saved on the device.
ProfileType> in case of success, otherwise, if exceptions are not enabled, a null pointer.| ConfigException | in case of error, when exceptions are enabled through the ErrorManager singleton.
|
|---|
Applies the given profile. If there is already a manually loaded profile the method fails.
The properties listed in the profile are set to the values specified in the profile.
The changes done to the configuration loading the profile are persistent to the reboot of the device.
To unload the profile the method unloadProfile() must be invoked.
| name | String name of the profile file to be loaded. |
|---|
SUCCESS in case of success, otherwise a possible error
code, matching one of the ConfigException error constants.| ConfigException | in case of error, when exceptions are enabled through the ErrorManager singleton.
|
|---|
Delete the specified rule.
| name | String name of the rule to be deleted. |
|---|
SUCCESS in case of success, otherwise a possible error
code, matching one of the ConfigException error constants.| ConfigException | in case of error, when exceptions are enabled through the ErrorManager singleton.
|
|---|
Revert the manually loaded profile restoring the values previously set on the device. It fails if there isn't a profile manually loaded.
SUCCESS in case of success, otherwise a possible error
code, matching one of the ConfigException error constants.| ConfigException | in case of error, when exceptions are enabled through the ErrorManager singleton.
|
|---|