1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.car.audio.hal; 18 19 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.DUMP_INFO; 20 21 import android.annotation.IntDef; 22 import android.annotation.NonNull; 23 import android.annotation.Nullable; 24 import android.hardware.automotive.audiocontrol.MutingInfo; 25 26 import com.android.car.audio.CarDuckingInfo; 27 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport; 28 import com.android.car.internal.annotation.AttributeUsage; 29 import com.android.car.internal.util.IndentingPrintWriter; 30 31 import java.lang.annotation.Retention; 32 import java.lang.annotation.RetentionPolicy; 33 import java.util.List; 34 35 /** 36 * AudioControlWrapper wraps IAudioControl HAL interface, handling version specific support so that 37 * the rest of CarAudioService doesn't need to know about it. 38 */ 39 public interface AudioControlWrapper { 40 int AUDIOCONTROL_FEATURE_AUDIO_FOCUS = 0; 41 int AUDIOCONTROL_FEATURE_AUDIO_DUCKING = 1; 42 int AUDIOCONTROL_FEATURE_AUDIO_GROUP_MUTING = 2; 43 int AUDIOCONTROL_FEATURE_AUDIO_FOCUS_WITH_METADATA = 3; 44 int AUDIOCONTROL_FEATURE_AUDIO_GAIN_CALLBACK = 4; 45 46 @IntDef({ 47 AUDIOCONTROL_FEATURE_AUDIO_FOCUS, 48 AUDIOCONTROL_FEATURE_AUDIO_DUCKING, 49 AUDIOCONTROL_FEATURE_AUDIO_GROUP_MUTING, 50 AUDIOCONTROL_FEATURE_AUDIO_FOCUS_WITH_METADATA, 51 AUDIOCONTROL_FEATURE_AUDIO_GAIN_CALLBACK, 52 }) 53 @Retention(RetentionPolicy.SOURCE) 54 @interface AudioControlFeature { 55 } 56 57 /** 58 * Closes the focus listener that's registered on the AudioControl HAL 59 */ unregisterFocusListener()60 void unregisterFocusListener(); 61 62 /** 63 * Indicates if HAL can support specified feature 64 * 65 * @param feature to check support for. it's expected to be one of the features defined by 66 * {@link AudioControlWrapper.AudioControlFeature}. 67 * @return boolean indicating whether feature is supported 68 */ supportsFeature(@udioControlFeature int feature)69 boolean supportsFeature(@AudioControlFeature int feature); 70 71 /** 72 * Registers listener for HAL audio focus requests with IAudioControl. Only works if 73 * {@code supportsHalAudioFocus} returns true. 74 * 75 * @param focusListener the listener to register on the IAudioControl HAL. 76 */ registerFocusListener(HalFocusListener focusListener)77 void registerFocusListener(HalFocusListener focusListener); 78 79 /** 80 * Registers callback for HAL audio gain changed notification with IAudioControl. Only works if 81 * {@code supportsHalAudioGainCallback} returns true. 82 * 83 * @param gainCallback the callback to register on the IAudioControl HAL. 84 */ registerAudioGainCallback(@onNull HalAudioGainCallback gainCallback)85 void registerAudioGainCallback(@NonNull HalAudioGainCallback gainCallback); 86 87 /** 88 * Closes the audio gain callback registered on the AudioControl HAL 89 */ unregisterAudioGainCallback()90 void unregisterAudioGainCallback(); 91 92 /** 93 * Notifies HAL of change in audio focus for a request it has made. 94 * 95 * @param usage that the request is associated with. 96 * @param zoneId for the audio zone that the request is associated with. 97 * @param focusChange the new status of the request. 98 */ onAudioFocusChange(@ttributeUsage int usage, int zoneId, int focusChange)99 void onAudioFocusChange(@AttributeUsage int usage, int zoneId, int focusChange); 100 101 /** 102 * dumps the current state of the AudioControlWrapper 103 * 104 * @param writer stream to write current state 105 */ 106 @ExcludeFromCodeCoverageGeneratedReport(reason = DUMP_INFO) dump(IndentingPrintWriter writer)107 void dump(IndentingPrintWriter writer); 108 109 /** 110 * Sets the fade for the vehicle. 111 * 112 * @param value to set for the fade. Positive is towards front. 113 */ setFadeTowardFront(float value)114 void setFadeTowardFront(float value); 115 116 /** 117 * Sets the balance value for the vehicle. 118 * 119 * @param value to set for the balance. Positive is towards the right. 120 */ setBalanceTowardRight(float value)121 void setBalanceTowardRight(float value); 122 123 /** 124 * Notifies HAL of changes in usages holding focus and the corresponding ducking changes for a 125 * given zone. 126 * 127 * @param carDuckingInfos list of information about focus and addresses to duck for each 128 * impacted zone to relay to the HAL. 129 */ onDevicesToDuckChange(@onNull List<CarDuckingInfo> carDuckingInfos)130 void onDevicesToDuckChange(@NonNull List<CarDuckingInfo> carDuckingInfos); 131 132 /** 133 * Notifies HAL of changes in muting changes for all audio zones. 134 * 135 * @param carZonesMutingInfo list of information about addresses to mute to relay to the HAL. 136 */ onDevicesToMuteChange(@onNull List<MutingInfo> carZonesMutingInfo)137 void onDevicesToMuteChange(@NonNull List<MutingInfo> carZonesMutingInfo); 138 139 /** 140 * Registers recipient to be notified if AudioControl HAL service dies. 141 * 142 * @param deathRecipient to be notified upon HAL service death. 143 */ linkToDeath(@ullable AudioControlDeathRecipient deathRecipient)144 void linkToDeath(@Nullable AudioControlDeathRecipient deathRecipient); 145 146 /** 147 * Unregisters recipient for AudioControl HAL service death. 148 */ unlinkToDeath()149 void unlinkToDeath(); 150 151 /** 152 * Recipient to be notified upon death of AudioControl HAL. 153 */ 154 interface AudioControlDeathRecipient { 155 /** 156 * Called if AudioControl HAL dies. 157 */ serviceDied()158 void serviceDied(); 159 } 160 } 161