Audio control HAL supports:
- Fade and balance
- HAL audio focus request
- Device muting and ducking
- Audio device gain changes
- Audio port configuration changes
Audio fade and balance
1 class CarAudioManager { 2 /** 3 * Adjust the relative volume in the front vs back of the vehicle cabin. 4 * 5 * @param value in the range -1.0 to 1.0 for fully toward the back through 6 * fully toward the front. 0.0 means evenly balanced. 7 */ 8 @SystemApi 9 @RequiresPermission(Car.PERMISSION_CAR_CONTROL_AUDIO_VOLUME) 10 public void setFadeTowardFront(float value); 11 12 /** 13 * Adjust the relative volume on the left vs right side of the vehicle cabin. 14 * 15 * @param value in the range -1.0 to 1.0 for fully toward the left through 16 * fully toward the right. 0.0 means evenly balanced. 17 */ 18 @SystemApi 19 @RequiresPermission(Car.PERMISSION_CAR_CONTROL_AUDIO_VOLUME) 20 public void setBalanceTowardRight(float value); 21 }
Audio focus request from HAL
To further expand on the audio focus and to provide a better integration of car specific sounds into the Android experience, the following audio attributes were introduced:
EMERGENCY
SAFETY
VEHICLE_STATUS
ANNOUNCEMENT
1 interface IAudioControl { 2 /** 3 * Notifies HAL of changes in audio focus status for focuses requested 4 * or abandoned by the HAL. 5 * 6 * @param usage The audio usage associated with the focus change 7 * {@code AttributeUsage}. See {@code audioUsage} in 8 * audio_policy_configuration.xsd for the list of allowed values. 9 * @param zoneId The identifier for the audio zone that the HAL is 10 * playing the stream in 11 * @param focusChange the AudioFocusChange that has occurred. 12 */ 13 oneway void onAudioFocusChange(in String usage, in int zoneId, 14 in AudioFocusChange focusChange); 15 /** 16 * Registers focus listener to be used by HAL for requesting and 17 * abandoning audio focus. 18 * @param listener the listener interface. 19 */ 20 oneway void registerFocusListener(in IFocusListener listener); 21 /** 22 * Control the right/left balance setting of the car speakers. 23 */ 24 oneway void setBalanceTowardRight(in float value); 25 /** 26 * Control the fore/aft fade setting of the car speakers. 27 */ 28 oneway void setFadeTowardFront(in float value); 29 30 /** 31 * Notifies HAL of changes in output devices that the HAL should apply 32 * muting to. 33 * 34 * This will be called in response to changes in audio mute state for each 35 * volume group and will include a {@link MutingInfo} object per audio 36 * zone that experienced a mute state event. 37 * 38 * @param mutingInfos an array of {@link MutingInfo} objects for the audio 39 * zones where audio mute state has changed. 40 */ 41 oneway void onDevicesToMuteChange(in MutingInfo[] mutingInfos); 42 }
Volume group muting
AAOS has two different mechanisms for muting, based on:
-
Key events using the audio KEYCODE_VOLUME_MUTE
-
Direct calls to the car audio service using the car audio manager mute API,
CarAudioManager#setVolumeGroupMute
.
When enabled, both mechanisms trigger a call mute to the audio control HAL.
Car audio ducking
1 <!-- Configuration to enable IAudioControl#onDevicesToDuckChange API to 2 inform HAL when to duck. If this is set to true, the API will receive signals 3 indicating which output devices to duck as well as what usages are currently 4 holding focus. If set to false, the API will not be called. --> 5 <bool name="audioUseHalDuckingSignals">true</bool> 6 7 interface IAudioControl { 8 /** 9 * Notifies HAL of changes in output devices that the HAL should apply 10 * ducking to. 11 * 12 * This will be called in response to changes in audio focus, and will 13 * include a {@link DuckingInfo} object per audio zone that experienced 14 * a change in audo focus. 15 * 16 * @param duckingInfos an array of {@link DuckingInfo} objects for the 17 * audio zones where audio focus has changed. 18 */ 19 oneway void onDevicesToDuckChange(in DuckingInfo[] duckingInfos); 20 }
FocusChange with playback track metadata
1 interface IAudioControl { 2 /** 3 * Notifies HAL of changes in audio focus status for focuses requested 4 * or abandoned by the HAL. 5 * 6 * The HAL is not required to wait for a callback of AUDIOFOCUS_GAIN 7 * before playing audio, nor is it required to stop playing audio in the 8 * event of a AUDIOFOCUS_LOSS callback is received. 9 * 10 * @param playbackMetaData The output stream metadata associated with 11 * the focus request 12 * @param zoneId The identifier for the audio zone that the HAL is 13 * playing the stream in 14 * @param focusChange the AudioFocusChange that has occurred. 15 */ 16 oneway void onAudioFocusChangeWithMetaData( in PlaybackTrackMetadata playbackMetaData, in int zoneId, in AudioFocusChange focusChange); 19 }
If HAL developers decide not to support IAudioControl#onAudioFocusChangeWithMetaData
, the method should return results with the UNKNOWN_TRANSACTION
error
The audio service first calls onAudioFocusChangeWithMetaData
and then retries with the onAudioFocusChange
method if a UNKNOWN_TRANSACTION
failure results.
Audio gain callback
To make audio changes below the HAL more visible to the AAOS , we added a mechanism you can use to communicate audio gains changes from the car’s audio system to the car audio service. The mechanism exposes audio gain volume index changes with a respective reason why the gain was changed:
- Blocked or muted restrictions
- Limitations restrictions
- Attenuation restrictions
These changes expose these restrictions from below the HAL to the car audio service and, finally, to a system UI app to inform the user.
This allow for system UI apps to more readily get this information through a volume group information callback mechanism.
1 interface IAudioGainCallback { 2 /** 3 * Used to indicate that one or more audio device port gains have changed, 4 * i.e. initiated by HAL, not by CarAudioService. 5 * This is the counter part of the 6 * {@link onDevicesToDuckChange}, {@link onDevicesToMuteChange} and, 7 * {@link setAudioDeviceGainsChanged} APIs. 8 * 9 * @param reasons List of reasons that triggered the given gains changed. 10 * @param gains List of gains affected by the change. 11 */ 12 void onAudioDeviceGainsChanged(in Reasons[] reasons, 13 in AudioGainConfigInfo[] gains); 14 }
When the API is called from the audio control HAL, the car audio service responds with a corresponding action (such as block, limit, or attenuate gain index) .