How to find an app's available restrictions for DevicePolicyManager.setApplicationRestrictions
Asked Answered
B

1

13

The new Android Lollipop API provides a new pair of methods for getting and setting restrictions on other apps: DevicePolicyManager.getApplicationRestrictions and DevicePolicyManager.setApplicationRestrictions

There's an example of them being used in the BasicManagedProfile sample app to set restrictions on the Chrome app by passing a set of key/value pairs that seem to correlate to the Chrome's published policy list. This works perfectly for me.

But I can't find any documentation on any other apps that can be restricted in this way. Does anyone know of any other apps that can be restricted with these methods, and the keys that can be set?

DevicePolicyManager.getApplicationRestrictions only seems to return the restrictions you've already set for that app, not a list of all available restrictions. I also tried using RestrictionsManager.getManifestRestrictions on Chrome but this returns an empty list, so I think this is something different.

Bracci answered 1/11, 2014 at 13:9 Comment(6)
I'm also facing same issue. No help :(Dituri
I also tried with Bundle appRestrictions=manager.getApplicationRestrictions(BasicDeviceAdminReceiver.getComponentName(getActivity()), "com.adobe.reader"); Log.d("","*$%^"+appRestrictions.toString()); that prints 'Bundle[EMPTY_PARCEL]'Dituri
hey @javedsalat did you ever figure out what was causing the call to getApplicationRestrictions return an empty parcel? I'm having the same issue right now, I should see restrictions, but it comes emptyReinwald
i was looking into MDM and came across your question, and read about chrome policy .... i found the list hereRogers
Has anyone managed to retrieve the app restrictions bundle. I always get Bundle[EMPTY_PARCEL]Grammalogue
I found out what the issue was. I use Test DPC to test the app restriction functionality. However when I try to debug my app, it was debugging the unmanaged version of the app, rather than the managed version. Once I tested it with the managed version of my app, I could access the application restrictions. So the lesson is that the app restrictions are only available if you app is being managed.Grammalogue
U
3

I suggest reading Google's documentation for building a Work policy controller.

A managed application will include restrictions file that is declared in the manifest. Enterprise mobile management partner can retrieve this information using Google play APIs. Read Implementing App Restrictions

Following steps could be used to find available restrictions in an Android application:

  • Get the apk from the device. Example: Use these steps:

    $ adb shell pm path com.android.chrome
    package:/data/app/com.android.chrome-2/base.apk
    $ adb pull /data/app/com.android.chrome-2/base.apk
    4722 KB/s (32575247 bytes in 6.735s)
    
  • Unzip apk file. Look for app_restrictions.xml file in res/ folder.

  • Use aapt tool to retrieve content of this file from apk. Example:

    aapt d xmltree DivideProductivity_1.2_RC05_6-1.apk res/xml/app_restrictions.xml
    aapt d xmltree base.apk res/xml-v21/app_restrictions.xml
    

Note that with this mechanism, you can only view the restriction keys. You will need restriction type and other details to actually set restrictions on a managed application. The proper way is using Google play APIs from server.

Urquhart answered 23/6, 2015 at 2:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.