Car User Experience Restrictions

Before you continue, review Driving Distraction Guidelines.

This article describes the Car User Experience (UX) Restrictions rules you can use to create multiple UX Restrictions rule configurations (for example, European Union versus Japan) and then determine which set of rules to apply at run time. For more information, see CarUxRestrictions.

The Car UX Restrictions service enables developers to define a new Car UX Restrictions configuration. Should a developer want to modify the restriction rules (such as to comply with local safety standards), the developer can use the API to define the new configuration.

The API to set the configuration persists in the new configuration only. In other words, the configuration does not take effect immediately. Instead, the new configuration is loaded when the UX Restrictions service restarts and the car is in Park. The car service ensures the car is in Park before reloading the new configuration.

In addition to the new UX Restrictions service method, APIs are provided to construct the configuration. The state of gear selection and speed is converted to one of three drivingstates:

  • Parked. Gear in Park.
  • Idling. Gear not in Park and speed is zero.
  • Moving. Gear not in Park and speed is not zero.

To learn how applications consume a car's driving state and the corresponding UX restrictions, see Consuming Car Driving State and UX Restrictions.

Restriction Configuration Based on Drive States

To prevent driver distraction, Android maps the driving state to a set of UX Restriction (UX Restriction) rules (for a list of restrictions, see attrs.xml). Consider these sample rules:

  • Parked. Unrestricted.
  • Idling. No video and no configuration screen.
  • Moving. Fully restricted (all restrictions are required).

The mapping illustrated above is pre-determined and configured as an XML resource. The configuration is recorded in car_ux_restrictions_map. Internally, the CarUxRestrictionsManagerService parses the rules during initialization and then saves the rules in memory. The service then maps the current driving state to UX Restrictions and broadcasts the current restrictions to the entire system.

<!-- No restrictions when car is parked -->
<DrivingState car:state="parked">
    <Restrictions car:requiresDistractionOptimization="false"
                  car:uxr="baseline"/>
</DrivingState>

<!-- Restrictions when car is idling -->
<DrivingState car:state="idling">
    <Restrictions car:requiresDistractionOptimization="true"
                  car:uxr="no_video|no_config"/>
</DrivingState>

<!-- Restrictions for speed >= 0 m/s -->
<DrivingState car:state="moving" car:minSpeed="0.0">
    <Restrictions car:requiresDistractionOptimization="true"
                  car:uxr="fully_restricted"/>
</DrivingState>

CarUxRestrictionsConfiguration APIs

Restrictions with CarUxRestrictionsConfiguration

The new class CarUxRestrictionsConfiguration is mapped 1:1 to the current XML configuration schema. CarUxRestrictionsConfiguration can be constructed with CarUxRestrictions.Builder, which validates the configuration upon build().

new CarUxRestrictionsConfiguration.Builder()
        // Explicitly set restrictions for each driving state.
        .setUxRestrictions(CarDrivingStateEvent.DRIVING_STATE_PARKED,
                /* requiresOptimization= */ false,
                /* restrictions= */ UX_RESTRICTIONS_BASELINE)
        .setUxRestrictions(CarDrivingStateEvent.DRIVING_STATE_IDLING,
                true,
                UX_RESTRICTIONS_NO_VIDEO|UX_RESTRICTIONS_NO_SETUP)
        .setUxRestrictions(CarDrivingStateEvent.DRIVING_STATE_MOVING,
                true,
                UX_RESTRICTIONS_FULLY_RESTRICTED)
        // Set restriction parameters.
        .setMaxStringLength(int max)
        .setMaxCumulativeContentItems(int max)
        .setMaxContentDepth(int max)
        // Build a new CarUxRestrictionsConfiguration.
        .build();

CarUxRestrictionsManager API

Set CarUxRestrictionsConfiguration for the next drive with CarUxRestrictionsManager. This method requires permission, Car.PERMISSION_CAR_UX_RESTRICTIONS_CONFIGURATION.

public synchronized boolean saveUxRestrictionsConfigurationForNextBoot(
        CarUxRestrictionsConfiguration config);

Persist a New UX Restrictions Configuration

When a new configuration is passed in, the UX Restrictions service returns a boolean to indicate whether the new configuration has been successfully saved. This new configuration is only used when the Integrated Head Unit (IHU) restarts and the car is parked. Internally, the UX Restrictions service contains two sets of configurations:

  • Production. While optional, this configuration is often present. The UX Restrictions service reads this configuration when starting.
  • Staged. Also optional, this configuration has no effect on UX Restrictions and is promoted to Production when the car service starts and when the car is parked.

Production configuration

Figure 1. Production configuration

Address Failures

Until driving state information is received from CarPropertyManager (for example, during boot-up), UX Restrictions will not be enforced. The system will perform as if the driving state is parked.

Should reading a saved configuration fail (for example, SettingNotFoundException results), the UX Restrictions service falls back to the hard-coded, fully restricted mode:

// Idling/moving state is fully restricted.
private static CarUxRestrictionsConfiguration generateDefaultConfig() {}

Driving State and User Restrictions

The following content describes the interactions displayed in the following design diagram:

Driving state interactions

Figure 2. Driving state interactions

Properties Used to Derive Driving State

Use the following three VehiclePropertyIds to derive the driving state:

APIs Available to Apps

The code resides in the following locations:

Code Location
CarUxRestrictionsManager
Public APIs to register for UX Restriction changes.
/packages/services/Car/+/master/car-lib/src/android/car/drivingstate/CarUxRestrictionsManager.java
CarUxRestrictions
UX restrictions definition.
/packages/services/Car/+/master/car-lib/src/android/car/drivingstate/CarUxRestrictions.java
CarDrivingStateManager
System APIs to register for driving state changes.
/packages/services/Car/+/master/car-lib/src/android/car/drivingstate/CarDrivingStateManager.java

To simulate driving states, see Testing.