androidmdmmobileironandroid-restrictions

RestrictionManager getRestrictions() is always empty


I'm trying to set-up the remote configuration for my app with MobileIron EMM. I've done everything as described in developer guide: 1. I've set-up the manifest:

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

2. I've described the restriction:

<?xml version="1.0" encoding="utf-8"?>
<restrictions xmlns:android="http://schemas.android.com/apk/res/android">
    <restriction
        android:title="@string/some_title"
        android:key="SOME_KEY"
        android:restrictionType="string"
        android:defaultValue="123"/>
</restrictions>

3. I'm trying to receive it as following:

RestrictionsManager manager = (RestrictionsManager) context.getSystemService(Context.RESTRICTIONS_SERVICE);
        Bundle b = manager.getApplicationRestrictions();
        if(b!=null){
            if(b.containsKey("SOME_KEY")) {
                return b.getString("SOME_KEY");
            }else{
                System.out.println("bundle is not null");
                for (String s: b.keySet()){
                    System.out.println("key in b is : " + s);
                }
                System.out.println(b.isEmpty() + " bundle is empty");
            }
        }else{
            System.out.println("Bundle is null");
        }
        return "";
    }

I've always got the output:

bundle is not null
true bundle is empty

although I've set the default value for the restriction. Why am I not getting at least default value for the restriction? Why am I never get an actual values (at the server side I've set the values with MobileIron Cloud and its AppConnect configuration)? Tried with several devices. What am I missing? Please help. My goal is to remotely set-up some key-value to the app.


Solution

  • If you're not receiving any restrictions at all then it's probably because your app isn't part of a managed profile. App restrictions only work in two scenarios... your device has been provisioned using your EMM console (can only be done after a factory reset) or your device has an Android for Work profile that is managed by your EMM console. You don't actually need to declare each restriction in the manifest, that only allows the EMM to provide that information in their console.

    The easiest way to test your app restrictions on an unprovisioned device is to download the Test DPC app from the google play store. Setting it up will encrypt your device and install a work profile you can use for testing. You can use the DPC app to simulate applying app restrictions, reading the restrictions from manifest, and a number of other things EMMs do. You can install your app on the work profile using adb or by following the developer's guide to tell Android Studio how run the app in your work profile.

    https://developer.android.com/work/guide.html#testing