# Configure apps

Some apps designed for enterprises include built-in settings called **managed
configurations** that IT admins can configure remotely. For example, an app may
have the option to only sync data when a device is connected to Wi-Fi. Providing
IT admins the ability to specify managed configurations and apply them to
devices is a requirement for all [solution sets](https://developers.google.com/android/work/requirements).

The diagram below illustrates some of the key stages of managed configuration
management with an overview of the options available through the Google Play EMM
API.

## Check if an app supports managed configurations

Use
[`Products.getAppRestrictionsSchema`](https://developers.google.com/android/work/play/emm-api/v1/products/getAppRestrictionsSchema)
to determine whether an app supports managed configurations. Here's an example
that uses the
[Google Play EMM API Client Library for Java](https://developers.google.com/api-client-library/java/apis/androidenterprise/v1).

    public AppRestrictionsSchema getAppRestrictionsSchema(String enterpriseId,
        String productId, String language) throws IOException {
      return androidEnterprise
         .product()
         .getAppRestrictionsSchema(enterpriseId, productId, language)
         .execute();
    }

All apps return an app restrictions (managed configurations) schema. If the call
returns an empty schema, then the app doesn't support manage configurations. If
the call returns a schema containing a set of restrictions, then the app
supports managed configurations. For example, an app that has a property for
enabling remote printing over a VPN could return the following response to
`Products.getAppRestrictionsSchema`.

        {
          "kind": "androidenterprise#appRestrictionsSchema",
          "restrictions": [
            {
              "key": "printing_enabled",
              "title": "Enable printing",
              "restrictionType": "bool",
              "description": "Allow user to print from the app",
              "defaultValue": {
                "type": "bool",
                "valueBool": true,
              }
            },
            {
              "key": "vpn_configurations",
              "title": "VPN configurations",
              "restrictionType": "bundle_array",
              "description": "List of VPN configurations",
              "nestedRestriction": [
                {
                  "key": "vpn_configuration",
                  "title": "VPN configuration",
                  "restrictionType": "bundle",
                  "nestedRestrictions": [
                    {
                      "key": "server",
                      "title": "VPN server host",
                      "restrictionType": "string"
                    },
                    {
                      "key": "username",
                      "title": "VPN account username",
                      "restrictionType": "string"
                    }
                  ]
                }
              ]
            }
          ]
        }

## Specify managed configurations

For apps that support managed configurations, you can enable IT admins to set
them from your EMM console by embedding the managed configurations iframe or by
developing your own UI.

### Option 1: Embed the managed configurations iframe

The easiest way to support managed configurations is to embed the managed
configurations iframe into your EMM console. The iframe retrieves the managed
configurations schema for a specified app, and allows IT admins to save, edit,
and delete custom configuration profiles. You can use the Play EMM API to apply
custom profiles to user's devices. To learn more about the iframe and how to add
it to your console, see
[managed configurations iframe](https://developers.google.com/android/work/play/emm-api/managed-configurations-iframe).

### Option 2: Create your own UI

Using the configurations returned from `Products.getAppRestrictionsSchema`, you
can create your own UI that allows IT admins to manage app configurations.

## Apply managed configurations

> [!NOTE]
> **Note:** You can only apply managed configurations to apps published to production. Managed configurations are not compatible with apps distributed to [closed
> tracks](https://developers.google.com/android/work/play/emm-api/distribute#distribute_apps_for_closed_testing).

In order to apply managed configurations to devices, your DPC must be integrated
with the DPC Support Library, as detailed in [Build a device policy
controller](https://developer.android.com/work/dpc/build-dpc.html).
The [DPC Support Library](https://developers.google.com/android/work/dpc/build-dpc#dpc_support_library)
transparently handles the delegation to Google Play to apply managed
configurations.

You can apply managed configurations to a device by setting
`policy.productPolicy.managedConfiguration` in the
[`Device`](https://developers.google.com/android/work/play/emm-api/v1/devices)'s `policy`.

### Using an mcmId

> [!NOTE]
> **Note:** This option is only available if you support the [managed configurations
> iframe](https://developers.google.com/android/work/play/emm-api/managed-configurations-iframe).

Each time an IT admin saves a new configuration profile from the managed
configurations iframe, the iframe returns a unique identifier called `mcmId`. An
`mcmId` has no limit on the number of devices it can be applied on and it does
not have an expiration time.

To apply a configuration profile to a device, set
`policy.productPolicy.managedConfiguration.configurationVariables.mcmId` in the
[`Device`](https://developers.google.com/android/work/play/emm-api/v1/devices)'s `policy`.

If you want to allow your IT admins to use variable in the managed
configurations iframe (such as $FirstName, $LastName), you need to define any
variables contained in the profile using
`policy.productPolicy[].managedConfiguration.configurationVariables.mcmId.variableSet[]`.

### Using a list of managed properties

You can also include a set of managed properties by setting
`policy.productPolicy.managedConfiguration.managedProperty[]` in the
[`Device`](https://developers.google.com/android/work/play/emm-api/v1/devices)'s `policy`.

The example below shows how to define a configuration. This configuration
contains a `bundle_array` (a list) that's made up of two bundle properties (a
group of related properties, in this case, properties for a VPN).

        ManagedConfiguration managedConfiguration = new ManagedConfiguration()
          .setManagedProperty(
            ImmutableList.of(
                new ManagedProperty()
                    .setKey("printing_enabled")
                    .setValueBool(true),
                new ManagedProperty()
                    .setKey("vpn_configurations")
                    .setValueBundleArray(
                        ImmutableList.of(
                            new ManagedPropertyBundle().setManagedProperty(
                                ImmutableList.of(
                                    new ManagedProperty()
                                        .setKey("server")
                                        .setValueString("vpn1.example.com"),
                                    new ManagedProperty()
                                        .setKey("username")
                                        .setValueString("john.doe"))),
                            new ManagedPropertyBundle().setManagedProperty(
                                ImmutableList.of(
                                    new ManagedProperty()
                                        .setKey("server")
                                        .setValueString("vpn2.example.com"),
                                    new ManagedProperty()
                                        .setKey("username")
                                        .setValueString("jane.doe")))))));

> [!NOTE]
> **Note:** `bundle_array` and `bundle` are only supported on Android 6.0+. Google Play silently drops these properties on older versions of Android. As an EMM provider, you should inform administrators about this constraint if there are any Android 5.0 (or below) devices in their environment.

For more information on the different configuration properties that an app can
support, see [Define Managed
Configurations](https://developer.android.com/work/managed-configurations.html#define-configuration).

## List an app's configuration profiles

> [!NOTE]
> **Note:** This feature is only available if you support the [managed configurations iframe](https://developers.google.com/android/work/play/emm-api/managed-configurations-iframe).

Depending on how you design your solution, you may want to display a list of
saved configurations profiles for an app. To retrieve this list, call
[`Managedconfigurationssettings.list`](https://developers.google.com/android/work/play/emm-api/v1/managedconfigurationssettings).