RestrictionsManager not able to get policy managed configurations in Android

37 Views Asked by At

While creating a managed device, we are sending some data in key-value pairs using managedConfiguration while creating a policy.

While creating a policy for fully-managed device then we are getting the data using the restrictionsManager inside a custom managed application that is marked as required for setup.

We're able to get the data like in the app like this as per the official documentation:

val restrictionManager = getSystemService(Context.RESTRICTIONS_SERVICE) as RestrictionsManager
val appRestrictions = restrictionManager.applicationRestrictions

if (appRestrictions != null){
    val toId = appRestrictions.getString(AppDataStoreKey.ToId.key)
    val link = appRestrictions.getString(AppDataStoreKey.Link.key)
    val userName = appRestrictions.getString(AppDataStoreKey.UserName.key)

    Log.d(TAG, "onCreate: Restrictions Data: \nToID: $toId \nLink: $link \nUserName: $userName")
}            

But while creating a policy for work-profile then the above snippet returns null values while extracting the data using the keys. Additionally, if we update the same data with any change in the managedConfigurations then the restrictions manager broadcast receiver gets the data and closing and re-opening the app now works as expected.

So we face this issue in the work-profile for the first time trying to get the managed configuration data.

Why is that and how to resolve it.

0

There are 0 best solutions below