CarAudioManager

public final class CarAudioManager
extends Object

java.lang.Object
   ↳ android.car.media.CarAudioManager


APIs for handling car specific audio stuff.

Summary

Public methods

CarAudioPatchHandle createAudioPatch(String sourceAddress, int usage, int gainInMillibels)

Given an input port identified by getExternalSources(), request that it's audio signal be routed below the HAL to the output port associated with the given usage.

String[] getExternalSources()

Queries the system configuration in order to report the available, non-microphone audio input devices.

int getGroupMaxVolume(int groupId)

Returns the maximum volume index for a volume group.

int getGroupMinVolume(int groupId)

Returns the minimum volume index for a volume group.

int getGroupVolume(int groupId)

Returns the current volume index for a volume group.

int[] getUsagesForVolumeGroupId(int groupId)

Gets array of AudioAttributes usages for a given volume group id.

int getVolumeGroupCount()

Gets the count of available volume groups in the system.

int getVolumeGroupIdForUsage(int usage)

Gets the volume group id for a given AudioAttributes usage.

static String getVolumeSettingsKeyForGroup(int groupId)
void registerVolumeCallback(IBinder binder)

Register ERROR(/ICarVolumeCallback) to receive the volume key events Requires Car.PERMISSION_CAR_CONTROL_AUDIO_VOLUME permission.

void registerVolumeChangeObserver(ContentObserver observer)

Registers a ContentObserver to listen for volume group changes.

void releaseAudioPatch(CarAudioPatchHandle patch)

Removes the association between an input port and an output port identified by the provided handle.

void setBalanceTowardRight(float value)

Adjust the relative volume on the left vs right side of the vehicle cabin.

void setFadeTowardFront(float value)

Adjust the relative volume in the front vs back of the vehicle cabin.

void setGroupVolume(int groupId, int index, int flags)

Sets the volume index for a volume group.

void unregisterVolumeCallback(IBinder binder)

Unregister ERROR(/ICarVolumeCallback) from receiving volume key events Requires Car.PERMISSION_CAR_CONTROL_AUDIO_VOLUME permission.

void unregisterVolumeChangeObserver(ContentObserver observer)

Unregisters the ContentObserver which listens for volume group changes.

Inherited methods

Public methods

createAudioPatch

public CarAudioPatchHandle createAudioPatch (String sourceAddress, 
                int usage, 
                int gainInMillibels)

Given an input port identified by getExternalSources(), request that it's audio signal be routed below the HAL to the output port associated with the given usage. For example, The output of a tuner might be routed directly to the output buss associated with AudioAttributes.USAGE_MEDIA while the tuner is playing. Requires ERROR(/android.car.Car#PERMISSION_CAR_CONTROL_AUDIO_SETTINGS) permission.

Parameters
sourceAddress String: the input port name obtained from getExternalSources().

usage int: the type of audio represented by this source (usually USAGE_MEDIA).

gainInMillibels int: How many steps above the minimum value defined for the source port to set the gain when creating the patch. This may be used for source balancing without affecting the user controlled volumes applied to the destination ports. A value of 0 indicates no gain change is requested.

Returns
CarAudioPatchHandle A handle for the created patch which can be used to later remove it.

Throws
CarNotConnectedException

getExternalSources

public String[] getExternalSources ()

Queries the system configuration in order to report the available, non-microphone audio input devices. Requires ERROR(/android.car.Car#PERMISSION_CAR_CONTROL_AUDIO_SETTINGS) permission.

Returns
String[] An array of strings representing the available input ports. Each port is identified by it's "address" tag in the audioPolicyConfiguration xml file. Empty array if we find nothing.

Throws
CarNotConnectedException

getGroupMaxVolume

public int getGroupMaxVolume (int groupId)

Returns the maximum volume index for a volume group. Requires Car.PERMISSION_CAR_CONTROL_AUDIO_VOLUME permission.

Parameters
groupId int: The volume group id whose maximum volume index is returned.

Returns
int The maximum valid volume index for the given group.

Throws
CarNotConnectedException

getGroupMinVolume

public int getGroupMinVolume (int groupId)

Returns the minimum volume index for a volume group. Requires Car.PERMISSION_CAR_CONTROL_AUDIO_VOLUME permission.

Parameters
groupId int: The volume group id whose minimum volume index is returned.

Returns
int The minimum valid volume index for the given group, non-negative

Throws
CarNotConnectedException

getGroupVolume

public int getGroupVolume (int groupId)

Returns the current volume index for a volume group. Requires Car.PERMISSION_CAR_CONTROL_AUDIO_VOLUME permission.

Parameters
groupId int: The volume group id whose volume index is returned.

Returns
int The current volume index for the given group.

Throws
CarNotConnectedException

getUsagesForVolumeGroupId

public int[] getUsagesForVolumeGroupId (int groupId)

Gets array of AudioAttributes usages for a given volume group id. Requires Car.PERMISSION_CAR_CONTROL_AUDIO_VOLUME permission.

Parameters
groupId int: The volume group id whose associated audio usages is returned.

Returns
int[] Array of AudioAttributes usages for a given volume group id

Throws
CarNotConnectedException

getVolumeGroupCount

public int getVolumeGroupCount ()

Gets the count of available volume groups in the system. Requires Car.PERMISSION_CAR_CONTROL_AUDIO_VOLUME permission.

Returns
int Count of volume groups

Throws
CarNotConnectedException

getVolumeGroupIdForUsage

public int getVolumeGroupIdForUsage (int usage)

Gets the volume group id for a given AudioAttributes usage. Requires Car.PERMISSION_CAR_CONTROL_AUDIO_VOLUME permission.

Parameters
usage int: The AudioAttributes usage to get a volume group from.

Returns
int The volume group id where the usage belongs to

Throws
CarNotConnectedException

getVolumeSettingsKeyForGroup

public static String getVolumeSettingsKeyForGroup (int groupId)

Parameters
groupId int: The volume group id

Returns
String Key to persist volume index for volume group in Settings.Global

registerVolumeCallback

public void registerVolumeCallback (IBinder binder)

Register ERROR(/ICarVolumeCallback) to receive the volume key events Requires Car.PERMISSION_CAR_CONTROL_AUDIO_VOLUME permission.

Parameters
binder IBinder: IBinder instance of ERROR(/ICarVolumeCallback) to receive volume key event callbacks

Throws
CarNotConnectedException

registerVolumeChangeObserver

public void registerVolumeChangeObserver (ContentObserver observer)

Registers a ContentObserver to listen for volume group changes. Note that this observer is valid for bus based car audio stack only. ContentObserver.onChange(boolean) will be called on every group volume change.

Parameters
observer ContentObserver: The ContentObserver instance to register, non-null

releaseAudioPatch

public void releaseAudioPatch (CarAudioPatchHandle patch)

Removes the association between an input port and an output port identified by the provided handle. Requires ERROR(/android.car.Car#PERMISSION_CAR_CONTROL_AUDIO_SETTINGS) permission.

Parameters
patch CarAudioPatchHandle: CarAudioPatchHandle returned from createAudioPatch().

Throws
CarNotConnectedException

setBalanceTowardRight

public void setBalanceTowardRight (float value)

Adjust the relative volume on the left vs right side of the vehicle cabin. Requires Car.PERMISSION_CAR_CONTROL_AUDIO_VOLUME permission.

Parameters
value float: in the range -1.0 to 1.0 for fully toward the left through fully toward the right. 0.0 means evenly balanced.

Throws
CarNotConnectedException

setFadeTowardFront

public void setFadeTowardFront (float value)

Adjust the relative volume in the front vs back of the vehicle cabin. Requires Car.PERMISSION_CAR_CONTROL_AUDIO_VOLUME permission.

Parameters
value float: in the range -1.0 to 1.0 for fully toward the back through fully toward the front. 0.0 means evenly balanced.

Throws
CarNotConnectedException

setGroupVolume

public void setGroupVolume (int groupId, 
                int index, 
                int flags)

Sets the volume index for a volume group. Requires Car.PERMISSION_CAR_CONTROL_AUDIO_VOLUME permission.

Parameters
groupId int: The volume group id whose volume index should be set.

index int: The volume index to set. See getGroupMaxVolume(int) for the largest valid value.

flags int: One or more flags (e.g., AudioManager.FLAG_SHOW_UI, AudioManager.FLAG_PLAY_SOUND)

Throws
CarNotConnectedException

unregisterVolumeCallback

public void unregisterVolumeCallback (IBinder binder)

Unregister ERROR(/ICarVolumeCallback) from receiving volume key events Requires Car.PERMISSION_CAR_CONTROL_AUDIO_VOLUME permission.

Parameters
binder IBinder: IBinder instance of ERROR(/ICarVolumeCallback) to stop receiving volume key event callbacks

Throws
CarNotConnectedException

unregisterVolumeChangeObserver

public void unregisterVolumeChangeObserver (ContentObserver observer)

Unregisters the ContentObserver which listens for volume group changes.

Parameters
observer ContentObserver: The ContentObserver instance to unregister, non-null