I will be using Managed Configurations in an app I am developing.
After getting some help with this answer, I do not understand how default values are used in Managed Configurations. My reference is this link.
In my reference under "Note", Google says, "The managed configurations Bundle contains one item for every configuration that has been explicitly set by a managed configurations provider. However, you cannot assume that a configuration will be present in the bundle just because you defined a default value in the managed configurations XML file."
I understand that if an item has not been explicitly set by a managed configurations provider, then that item will not be in the Bundle. But the next (last) line is not clear to me.
My main question is "what is the purpose of the defaultValue in the managed configurations XML file"? But I'm hoping the answer will also help answer or guide me to answering these questions too:
- Who can read the defaultValue?
- Can the managed app read it? If so, how?
- Can the managed configurations provider read it? If so, how?
- Why can't I assume that a configuration will be present in a bundle if it has a default value? Is the managed configurations provider responsible for reading the defaultValue and then explicitly setting it?
You can use the
defaultValue
field to explain how your app behaves if the property is not explicitly set by the managing app.The XML file referenced in the manifest is meant to be used by the MDM to display a UI in their console so the IT admin can configure your app. If you set a
defaultValue
for a property the MDM pre-populates the corresponding field when your app is configured for the first time (e.g. display a checked checkbox for a boolean property that default totrue
).For the admin, not configuring your app should be the same as configuring it with the default configuration. Therefore, to be consistent, your app should behave the same way whether a property is unset or set to the
defaultValue
.To see how your configuration will look like in an MDM console you can use the Android Management Experience demo.
Edit: More details on how the restriction schema and
defaultValue
can be retrievedThe app's restriction schema defined in the XML file can be retrieved either
defaultValue
s for each restrictionRestrictionEntry
s have their values set to thedefaultValue
if specified in the XML file, or to a generic default value otherwise (0
forTYPE_INTEGER
,false
forTYPE_BOOLEAN
, etc). You can read the full logic of this method in AOSP's RestrictionManager.java, and see how it is used in TestDPC's ManageAppRestrictionsFragment.java.