CarOccupantZoneManager

public class CarOccupantZoneManager
extends Object

java.lang.Object
   ↳ android.car.CarOccupantZoneManager


API to get information on displays and users in the car.

From car version CarVersion.VERSION_CODES#UPSIDE_DOWN_CAKE_0, system without the driver zone is allowed and the current user will not be the driver.

Summary

Nested classes

interface CarOccupantZoneManager.OccupantZoneConfigChangeListener

Listener to monitor any Occupant Zone configuration change. 

class CarOccupantZoneManager.OccupantZoneInfo

Represents an occupant zone in a car. 

Constants

int DISPLAY_TYPE_AUXILIARY

Auxiliary display which can provide additional screen for DISPLAY_TYPE_MAIN.

int DISPLAY_TYPE_HUD

Head Up Display.

int DISPLAY_TYPE_INPUT

Dedicated display for showing IME for DISPLAY_TYPE_MAIN

int DISPLAY_TYPE_INSTRUMENT_CLUSTER

Instrument cluster display.

int DISPLAY_TYPE_MAIN

Main display users are interacting with.

int DISPLAY_TYPE_UNKNOWN

Display type is not known.

int INVALID_USER_ID

Invalid user ID.

int OCCUPANT_TYPE_DRIVER

Represents the driver.

int OCCUPANT_TYPE_FRONT_PASSENGER

Represents front passengers who sit in front side of car.

int OCCUPANT_TYPE_REAR_PASSENGER

Represents passengers in rear seats.

int ZONE_CONFIG_CHANGE_FLAG_AUDIO

Zone config change caused by audio zone change.

int ZONE_CONFIG_CHANGE_FLAG_DISPLAY

Zone config change caused by display changes.

int ZONE_CONFIG_CHANGE_FLAG_USER

Zone config change caused by user change.

Public methods

List<Display> getAllDisplaysForOccupant(CarOccupantZoneManager.OccupantZoneInfo occupantZone)

Returns all displays assigned for the given occupant zone.

List<CarOccupantZoneManager.OccupantZoneInfo> getAllOccupantZones()

Returns all available occupants in the system.

Display getDisplayForOccupant(CarOccupantZoneManager.OccupantZoneInfo occupantZone, int displayType)

Gets the display for the occupant for the specified display type, or returns null if no display matches the requirements.

int getDisplayType(Display display)

Returns assigned display type for the display.

CarOccupantZoneManager.OccupantZoneInfo getMyOccupantZone()

Returns OccupantZoneInfo for the calling process's android user.

CarOccupantZoneManager.OccupantZoneInfo getOccupantZone(int occupantType, int seat)

Finds OccupantZoneInfo for the given occupant type and seat.

CarOccupantZoneManager.OccupantZoneInfo getOccupantZoneForUser(UserHandle user)

Returns OccupantZoneInfo associated with the given UserHandle.

List<Integer> getSupportedInputTypes(CarOccupantZoneManager.OccupantZoneInfo occupantZoneInfo, int displayType)

Returns the supported input types for the occupant zone info and display type passed as the argument.

int getUserForDisplayId(int displayId)

Returns assigned user id for the given display id.

int getUserForOccupant(CarOccupantZoneManager.OccupantZoneInfo occupantZone)

Returns android user id assigned for the given zone.

boolean hasDriverZone()

Returns true if the system has a driver zone.

boolean hasPassengerZones()

Returns true if the system has front or rear passenger zones.

void registerOccupantZoneConfigChangeListener(CarOccupantZoneManager.OccupantZoneConfigChangeListener listener)

Registers the listener for occupant zone config change.

void unregisterOccupantZoneConfigChangeListener(CarOccupantZoneManager.OccupantZoneConfigChangeListener listener)

Unregisters the listener.

Inherited methods

Constants

DISPLAY_TYPE_AUXILIARY

Added in API level 30
public static final int DISPLAY_TYPE_AUXILIARY

Auxiliary display which can provide additional screen for DISPLAY_TYPE_MAIN. Activity running in DISPLAY_TYPE_MAIN may use Presentation to show additional information.

Constant Value: 5 (0x00000005)

DISPLAY_TYPE_HUD

Added in API level 30
public static final int DISPLAY_TYPE_HUD

Head Up Display. This may exist only for driver.

Constant Value: 3 (0x00000003)

DISPLAY_TYPE_INPUT

Added in API level 30
public static final int DISPLAY_TYPE_INPUT

Dedicated display for showing IME for DISPLAY_TYPE_MAIN

Constant Value: 4 (0x00000004)

DISPLAY_TYPE_INSTRUMENT_CLUSTER

Added in API level 30
public static final int DISPLAY_TYPE_INSTRUMENT_CLUSTER

Instrument cluster display. This may exist only for driver.

Constant Value: 2 (0x00000002)

DISPLAY_TYPE_MAIN

Added in API level 30
public static final int DISPLAY_TYPE_MAIN

Main display users are interacting with. UI for the user will be launched to this display by default. Display#DEFAULT_DISPLAY will be always have this type. But there can be multiple of this type as each passenger can have their own main display.

Constant Value: 1 (0x00000001)

DISPLAY_TYPE_UNKNOWN

Added in API level 30
public static final int DISPLAY_TYPE_UNKNOWN

Display type is not known. In some system, some displays may be just public display without any additional information and such displays will be treated as unknown.

Constant Value: 0 (0x00000000)

INVALID_USER_ID

Added in API level 34
public static final int INVALID_USER_ID

Invalid user ID. Zone with this user ID has no allocated user. Should have the same value with UserHandle#USER_NULL.

Constant Value: -10000 (0xffffd8f0)

OCCUPANT_TYPE_DRIVER

Added in API level 30
public static final int OCCUPANT_TYPE_DRIVER

Represents the driver. There can be one or zero driver for the system. Zero driver situation can happen if the system is configured to support only passengers.

Constant Value: 0 (0x00000000)

OCCUPANT_TYPE_FRONT_PASSENGER

Added in API level 30
public static final int OCCUPANT_TYPE_FRONT_PASSENGER

Represents front passengers who sit in front side of car. Most cars will have only one passenger of this type but this can be multiple.

Constant Value: 1 (0x00000001)

OCCUPANT_TYPE_REAR_PASSENGER

Added in API level 30
public static final int OCCUPANT_TYPE_REAR_PASSENGER

Represents passengers in rear seats. There can be multiple passengers of this type.

Constant Value: 2 (0x00000002)

ZONE_CONFIG_CHANGE_FLAG_AUDIO

Added in API level 30
public static final int ZONE_CONFIG_CHANGE_FLAG_AUDIO

Zone config change caused by audio zone change. Assigned audio zone for passenger zones have changed.

Constant Value: 4 (0x00000004)

ZONE_CONFIG_CHANGE_FLAG_DISPLAY

Added in API level 30
public static final int ZONE_CONFIG_CHANGE_FLAG_DISPLAY

Zone config change caused by display changes. A display could have been added / removed. Besides change in display itself. this can lead into removal / addition of passenger zones.

Constant Value: 1 (0x00000001)

ZONE_CONFIG_CHANGE_FLAG_USER

Added in API level 30
public static final int ZONE_CONFIG_CHANGE_FLAG_USER

Zone config change caused by user change. Assigned user for passenger zones have changed.

Constant Value: 2 (0x00000002)

Public methods

getAllDisplaysForOccupant

Added in API level 30
public List<Display> getAllDisplaysForOccupant (CarOccupantZoneManager.OccupantZoneInfo occupantZone)

Returns all displays assigned for the given occupant zone. If no display is available for the passenger, it will return empty list.

Parameters
occupantZone CarOccupantZoneManager.OccupantZoneInfo

Returns
List<Display>

getAllOccupantZones

Added in API level 30
public List<CarOccupantZoneManager.OccupantZoneInfo> getAllOccupantZones ()

Returns all available occupants in the system. If no occupant zone is defined in the system or none is available at the moment, it will return empty list.

Returns
List<CarOccupantZoneManager.OccupantZoneInfo>

getDisplayForOccupant

Added in API level 30
public Display getDisplayForOccupant (CarOccupantZoneManager.OccupantZoneInfo occupantZone, 
                int displayType)

Gets the display for the occupant for the specified display type, or returns null if no display matches the requirements.

Parameters
occupantZone CarOccupantZoneManager.OccupantZoneInfo

displayType int: This should be a valid display type and passing DISPLAY_TYPE_UNKNOWN will always lead into null return. Value is DISPLAY_TYPE_UNKNOWN, DISPLAY_TYPE_MAIN, DISPLAY_TYPE_INSTRUMENT_CLUSTER, DISPLAY_TYPE_HUD, DISPLAY_TYPE_INPUT, DISPLAY_TYPE_AUXILIARY, android.car.CarOccupantZoneManager.DISPLAY_TYPE_AUXILIARY_2, android.car.CarOccupantZoneManager.DISPLAY_TYPE_AUXILIARY_3, android.car.CarOccupantZoneManager.DISPLAY_TYPE_AUXILIARY_4, or android.car.CarOccupantZoneManager.DISPLAY_TYPE_AUXILIARY_5

Returns
Display

getDisplayType

Added in API level 30
public int getDisplayType (Display display)

Returns assigned display type for the display. It will return DISPLAY_TYPE_UNKNOWN if type is not specified or if display is no longer available.

Parameters
display Display

Returns
int Value is DISPLAY_TYPE_UNKNOWN, DISPLAY_TYPE_MAIN, DISPLAY_TYPE_INSTRUMENT_CLUSTER, DISPLAY_TYPE_HUD, DISPLAY_TYPE_INPUT, DISPLAY_TYPE_AUXILIARY, android.car.CarOccupantZoneManager.DISPLAY_TYPE_AUXILIARY_2, android.car.CarOccupantZoneManager.DISPLAY_TYPE_AUXILIARY_3, android.car.CarOccupantZoneManager.DISPLAY_TYPE_AUXILIARY_4, or android.car.CarOccupantZoneManager.DISPLAY_TYPE_AUXILIARY_5

getMyOccupantZone

Added in API level 34
public CarOccupantZoneManager.OccupantZoneInfo getMyOccupantZone ()

Returns OccupantZoneInfo for the calling process's android user. It will return null if there is no occupant zone assigned for the user.

When there is no occupant zone allocated for the user, most likely the user is not allowed to run Activity or play audio, which are the main use cases to get the zone. So apps should not try such tasks when null OccupantZoneInfo is returned. There can be an exception for system user running under Headless System User Mode: The system user apps may show UI even if there is no zone allocated.

Returns
CarOccupantZoneManager.OccupantZoneInfo

getOccupantZone

Added in API level 34
public CarOccupantZoneManager.OccupantZoneInfo getOccupantZone (int occupantType, 
                int seat)

Finds OccupantZoneInfo for the given occupant type and seat.

ForOCCUPANT_TYPE_DRIVER and OCCUPANT_TYPE_FRONT_PASSENGER, seat argument will be ignored.

Parameters
occupantType int: should be one of OCCUPANT_TYPE_DRIVER, OCCUPANT_TYPE_FRONT_PASSENGER, OCCUPANT_TYPE_FRONT_PASSENGER Value is OCCUPANT_TYPE_DRIVER, OCCUPANT_TYPE_FRONT_PASSENGER, or OCCUPANT_TYPE_REAR_PASSENGER

seat int: Seat of the occupant. This is necessary for OCCUPANT_TYPE_REAR_PASSENGER. Value is VehicleAreaSeat.SEAT_UNKNOWN, VehicleAreaSeat.SEAT_ROW_1_LEFT, VehicleAreaSeat.SEAT_ROW_1_CENTER, VehicleAreaSeat.SEAT_ROW_1_RIGHT, VehicleAreaSeat.SEAT_ROW_2_LEFT, VehicleAreaSeat.SEAT_ROW_2_CENTER, VehicleAreaSeat.SEAT_ROW_2_RIGHT, VehicleAreaSeat.SEAT_ROW_3_LEFT, VehicleAreaSeat.SEAT_ROW_3_CENTER, or VehicleAreaSeat.SEAT_ROW_3_RIGHT

Returns
CarOccupantZoneManager.OccupantZoneInfo Matching occupant zone or null if such zone does not exist.

getOccupantZoneForUser

Added in API level 34
public CarOccupantZoneManager.OccupantZoneInfo getOccupantZoneForUser (UserHandle user)

Returns OccupantZoneInfo associated with the given UserHandle. In the case that the user is associated with multiple zones, this API returns the first matched zone.

Parameters
user UserHandle: The user to find.

Returns
CarOccupantZoneManager.OccupantZoneInfo Matching occupant zone or null if the user is not assigned or user has a userId of UserHandle#USER_NULL.

getSupportedInputTypes

Added in API level 34
public List<Integer> getSupportedInputTypes (CarOccupantZoneManager.OccupantZoneInfo occupantZoneInfo, 
                int displayType)

Returns the supported input types for the occupant zone info and display type passed as the argument.

It returns an empty list if the input type is unknown. Starting in Android Build.VERSION_CODES.UPSIDE_DOWN_CAKE, all associated occupant zones and display types in config_occupant_display_mapping must define at least one input type.

If the display doesn't have any input type associated, then it should return a list containing CarInputManager.INPUT_TYPE_NONE only.

This is the list of all available input types this method may return:

Parameters
occupantZoneInfo CarOccupantZoneManager.OccupantZoneInfo: the occupant zone info of the supported input types to find

displayType int: the display type of the supported input types to find Value is DISPLAY_TYPE_UNKNOWN, DISPLAY_TYPE_MAIN, DISPLAY_TYPE_INSTRUMENT_CLUSTER, DISPLAY_TYPE_HUD, DISPLAY_TYPE_INPUT, DISPLAY_TYPE_AUXILIARY, android.car.CarOccupantZoneManager.DISPLAY_TYPE_AUXILIARY_2, android.car.CarOccupantZoneManager.DISPLAY_TYPE_AUXILIARY_3, android.car.CarOccupantZoneManager.DISPLAY_TYPE_AUXILIARY_4, or android.car.CarOccupantZoneManager.DISPLAY_TYPE_AUXILIARY_5

Returns
List<Integer> the supported input types for the occupant zone info and display type passed in as the argument (see the full list of supported input types in the above)

getUserForDisplayId

Added in API level 34
public int getUserForDisplayId (int displayId)

Returns assigned user id for the given display id.

Parameters
displayId int: Should be valid display id. Passing invalid display id will lead into getting INVALID_USER_ID result.

Returns
int Valid user id or INVALID_USER_ID if no user is assigned for the display.

getUserForOccupant

Added in API level 30
public int getUserForOccupant (CarOccupantZoneManager.OccupantZoneInfo occupantZone)

Returns android user id assigned for the given zone. It will return INVALID_USER_ID if user is not assigned or if zone is not available.

Parameters
occupantZone CarOccupantZoneManager.OccupantZoneInfo

Returns
int

hasDriverZone

Added in API level 34
public boolean hasDriverZone ()

Returns true if the system has a driver zone. It will return false for system with only passenger zones.

Note that at least one zone must be present and following system configurations are possible:

  • One driver zone only.
  • One driver zone with at least one passenger zone.
  • At least one passenger zone.

Returns
boolean

hasPassengerZones

Added in API level 34
public boolean hasPassengerZones ()

Returns true if the system has front or rear passenger zones. Check hasDriverZone() for possible system configurations.

Returns
boolean

registerOccupantZoneConfigChangeListener

Added in API level 30
public void registerOccupantZoneConfigChangeListener (CarOccupantZoneManager.OccupantZoneConfigChangeListener listener)

Registers the listener for occupant zone config change. Registering multiple listeners are allowed.

Parameters
listener CarOccupantZoneManager.OccupantZoneConfigChangeListener

unregisterOccupantZoneConfigChangeListener

Added in API level 30
public void unregisterOccupantZoneConfigChangeListener (CarOccupantZoneManager.OccupantZoneConfigChangeListener listener)

Unregisters the listener. Listeners not registered before will be ignored.

Parameters
listener CarOccupantZoneManager.OccupantZoneConfigChangeListener