1 /* 2 * Copyright (C) 2022 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 android.annotation.IntDef; 20 import android.hardware.automotive.audiocontrol.AudioGainConfigInfo; 21 import android.hardware.automotive.audiocontrol.Reasons; 22 23 import com.android.car.audio.CarAudioGainConfigInfo; 24 25 import java.lang.annotation.Retention; 26 import java.lang.annotation.RetentionPolicy; 27 import java.util.List; 28 29 /** 30 * Audio Gain Callback interface to abstract away the specific HAL version 31 */ 32 public interface HalAudioGainCallback { 33 @Retention(RetentionPolicy.SOURCE) 34 @IntDef( 35 value = { 36 Reasons.FORCED_MASTER_MUTE, 37 Reasons.REMOTE_MUTE, 38 Reasons.TCU_MUTE, 39 Reasons.ADAS_DUCKING, 40 Reasons.NAV_DUCKING, 41 Reasons.PROJECTION_DUCKING, 42 Reasons.THERMAL_LIMITATION, 43 Reasons.SUSPEND_EXIT_VOL_LIMITATION, 44 Reasons.EXTERNAL_AMP_VOL_FEEDBACK, 45 Reasons.OTHER 46 }) 47 public @interface HalReason {} 48 49 /** Determines if the {@code HalReason} is valid */ isReasonValid(@alReason int reason)50 static boolean isReasonValid(@HalReason int reason) { 51 switch (reason) { 52 case Reasons.FORCED_MASTER_MUTE: 53 case Reasons.REMOTE_MUTE: 54 case Reasons.TCU_MUTE: 55 case Reasons.ADAS_DUCKING: 56 case Reasons.NAV_DUCKING: 57 case Reasons.PROJECTION_DUCKING: 58 case Reasons.THERMAL_LIMITATION: 59 case Reasons.SUSPEND_EXIT_VOL_LIMITATION: 60 case Reasons.EXTERNAL_AMP_VOL_FEEDBACK: 61 case Reasons.OTHER: 62 return true; 63 default: 64 return false; 65 } 66 } 67 68 /** Converts the {@code HalReason} to String */ reasonToString(@alReason int reason)69 static String reasonToString(@HalReason int reason) { 70 switch (reason) { 71 case Reasons.FORCED_MASTER_MUTE: 72 return "FORCED_MASTER_MUTE"; 73 case Reasons.REMOTE_MUTE: 74 return "REMOTE_MUTE"; 75 case Reasons.TCU_MUTE: 76 return "TCU_MUTE"; 77 case Reasons.ADAS_DUCKING: 78 return "ADAS_DUCKING"; 79 case Reasons.NAV_DUCKING: 80 return "NAV_DUCKING"; 81 case Reasons.PROJECTION_DUCKING: 82 return "PROJECTION_DUCKING"; 83 case Reasons.THERMAL_LIMITATION: 84 return "THERMAL_LIMITATION"; 85 case Reasons.SUSPEND_EXIT_VOL_LIMITATION: 86 return "SUSPEND_EXIT_VOL_LIMITATION"; 87 case Reasons.EXTERNAL_AMP_VOL_FEEDBACK: 88 return "EXTERNAL_AMP_VOL_FEEDBACK"; 89 case Reasons.OTHER: 90 return "OTHER"; 91 default: 92 return "Unsupported reason int " + reason; 93 } 94 } 95 96 /** 97 * Converts the {@code AudioGainConfigInfo} to its string representation 98 */ gainToString(AudioGainConfigInfo audioGainConfigInfo)99 static String gainToString(AudioGainConfigInfo audioGainConfigInfo) { 100 // Java toString helper missing at aidl side 101 return "zone: " 102 + audioGainConfigInfo.zoneId 103 + ", address: " 104 + audioGainConfigInfo.devicePortAddress 105 + ", Volume Index: " 106 + audioGainConfigInfo.volumeIndex; 107 } 108 109 /** 110 * Notify of Audio Gain changed for given {@code halReasons} for the given {@code gains}. 111 */ onAudioDeviceGainsChanged(List<Integer> halReasons, List<CarAudioGainConfigInfo> gains)112 void onAudioDeviceGainsChanged(List<Integer> halReasons, List<CarAudioGainConfigInfo> gains); 113 } 114