How can work the app restriction for deploy android app with a MDM config

Viewed 29

I need to implement an android config by a MDM (like Intunes). So I find the app_restictions. To do this, I did this in AndroidManifest.xml:

<meta-data android:name="android.content.APP_RESTRICTIONS"
            android:resource="@xml/app_restrictions" />

And this in app_restrictions.xml:

<?xml version="1.0" encoding="utf-8"?>
<restrictions xmlns:android="http://schemas.android.com/apk/res/android">

    <restriction
        android:key="domain"
        android:title="Server domain"
        android:restrictionType="string"/>

</restrictions>

So, when I put this piece of code I have a bad result:

val myRestrictionsMgr: RestrictionsManager = this.getSystemService(Context.RESTRICTIONS_SERVICE) as RestrictionsManager
val appRestrictions: Bundle = myRestrictionsMgr.applicationRestrictions

Log.e(TAG, appRestrictions.hasFileDescriptors().toString()) // "False"
val domain: String? =
    if (appRestrictions.containsKey("domain")) {
        appRestrictions.getString("domain")
    } else {
        "NOP"
    }
Log.e(TAG, domain.toString()) // "NOP"

And to finish, when I try to deploy my app by a MDM, the configuration doesn't not appear.

1 Answers

In my case, I can see app restrictions only when I deploy it through an MDM through a private (or public) Play Store. When we do this, we have access to the application restriction configuration.

To solve this problem, I decided to duplicate the restriction of my application in my metadata (for dev env only). In my service (which get the app restrictions), I check if I am in prod or dev env (by a MetaData), if I'm:

  • in dev: I take MetaData
  • in prod: I take AppRestriction

Here is my new function (simplify):

private fun genericFunction(dataKey: String): String?
{
    var value: String? = null

    if (this.isDevEnv) {        // If dev env, take meta data

        value = this.metaData.getString(dataKey)

    } else {                    // If not dev env, take restrictions data
        
        value = this.appRestrictions.getString(dataKey)
         
    }

    return value
}

-- OR if you prefer the compact way --

private fun genericFunction(dataKey: String): String?
{
    return this.isDevEnv ? this.metaData.getString(dataKey) : this.appRestrictions.getString(dataKey)
}
Related