Implement custom user types

Android 11 has introduced the concept of well-defined user types, representing all the different types of users allowed by the Android Multi-user feature. With this feature, OEMs can customize predefined AOSP user types and define new profile types. See the section on user types for more information.

This page details the implementation guidelines needed to customize user types.

Customization

In order to customize AOSP user types and to define new profile types, the OEM must overlay config_user_types.xml with the preferred customizations. The config_user_types.xml file contains a reference implementation and a comprehensive list of configurable attributes.

Any attribute, such as default-restrictions, that is specified in the config_user_types.xml file, overwrites the AOSP default. Any attribute that is not specified, obeys the AOSP default. Changing most attributes, such as a profile type's badge attributes, affects pre-existing users of that user type. However, because default-restrictions are only applied at the time a user is created, modifying this particular attribute, in the event the config_user_types.xml file is changed by OTA, has no effect on pre-existing users. Similarly, specifying the maximum number of users only applies when creating new users; existing users aren't removed.

Current customization restrictions for each user type are as follows:

  • Profiles can be fully customized and defined. In this case, the OEM is responsible for making platform modifications as required for their custom profile to be supported in Android, since AOSP only supports the predefined AOSP user-types.
  • Full users cannot be defined and only their default-restrictions attribute can be customized.
  • The system user cannot be customized using this mechanism. In this case, default-restrictions can be set using com.android.internal.R.array.config_defaultFirstUserRestrictions. See config.xml for more information.

Modify existing user types

Existing user types can be customized by overriding their attributes as shown in the following code sample:

<user-types version="0">
    <full-type name="android.os.usertype.full.SECONDARY" >
        <default-restrictions no_sms="true" />
    </full-type>

    <profile-type
        name='android.os.usertype.profile.MANAGED'
        max-allowed-per-parent='2'
        icon-badge='@android:drawable/ic_corp_icon_badge_case'
        badge-plain='@android:drawable/ic_corp_badge_case'
        badge-no-background='@android:drawable/ic_corp_badge_no_background' >
        <badge-labels>
            <item res='@android:string/managed_profile_label_badge' />
            <item res='@android:string/managed_profile_label_badge_2' />
        </badge-labels>
        <badge-colors>
            <item res='@android:color/profile_badge_1' />
            <item res='@android:color/profile_badge_2' />
        </badge-colors>
        <default-restrictions no_sms="true" no_outgoing_calls="true" />
    </profile-type>
</user-types>

In this code sample, the following AOSP user types are customized by modifying the supported properties:

  • Full user android.os.usertype.full.SECONDARY:

    • The default restriction of no_sms is set to true by specifying default-restrictions no_sms="true".
  • Profile user android.os.usertype.profile.MANAGED:

    • Two profiles are allowed for each parent user by setting max-allowed-per-parent='2'.
    • Badge attributes are set to chosen values using icon-badge, badge-plain, badge-no-background, badge-labels, badge-colors.
    • The default restrictions of no_sms and no_outgoing_calls are set to true by specifying default-restrictions no_sms="true" no_outgoing_calls="true".

Refer to UserTypeFactory.java and UserTypeDetails.java for the meaning and default values of these properties.

Define custom profile types

The following code sample shows how new, custom profile types are defined:

<user-types version="1">
    <profile-type
        name="com.example.profilename"
        max-allowed-per-parent="2" />

    <change-user-type
        from="android.os.usertype.profile.MANAGED"
        to="com.example.profilename"
        whenVersionLeq="1" />
</user-types>

In this code sample, the com.example.profilename profile type is defined as follows:

  • max-allowed-per-parents is set to 2 for two profiles per parent user.

  • change-user-type: converts all existing managed profiles of the type android.os.usertype.profile.MANAGED to the new com.example.profilename type when upgrading the device from a user-type version of <= 1 through OTA.