• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 import android.media.AudioAttributes.AttributeUsage;
26 import android.util.IndentingPrintWriter;
27 
28 import com.android.car.audio.CarDuckingInfo;
29 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport;
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 
44     @IntDef({
45             AUDIOCONTROL_FEATURE_AUDIO_FOCUS,
46             AUDIOCONTROL_FEATURE_AUDIO_DUCKING,
47             AUDIOCONTROL_FEATURE_AUDIO_GROUP_MUTING
48     })
49     @Retention(RetentionPolicy.SOURCE)
50     @interface AudioControlFeature {
51     }
52 
53     /**
54      * Closes the focus listener that's registered on the AudioControl HAL
55      */
unregisterFocusListener()56     void unregisterFocusListener();
57 
58     /**
59      * Indicates if HAL can support specified feature
60      *
61      * @param feature to check support for. it's expected to be one of the features defined by
62      * {@link AudioControlWrapper.AudioControlFeature}.
63      * @return boolean indicating whether feature is supported
64      */
supportsFeature(@udioControlFeature int feature)65     boolean supportsFeature(@AudioControlFeature int feature);
66 
67     /**
68      * Registers listener for HAL audio focus requests with IAudioControl. Only works if
69      * {@code supportsHalAudioFocus} returns true.
70      *
71      * @param focusListener the listener to register on the IAudioControl HAL.
72      */
registerFocusListener(HalFocusListener focusListener)73     void registerFocusListener(HalFocusListener focusListener);
74 
75     /**
76      * Notifies HAL of change in audio focus for a request it has made.
77      *
78      * @param usage that the request is associated with.
79      * @param zoneId for the audio zone that the request is associated with.
80      * @param focusChange the new status of the request.
81      */
onAudioFocusChange(@ttributeUsage int usage, int zoneId, int focusChange)82     void onAudioFocusChange(@AttributeUsage int usage, int zoneId, int focusChange);
83 
84     /**
85      * dumps the current state of the AudioControlWrapper
86      *
87      * @param writer stream to write current state
88      */
89     @ExcludeFromCodeCoverageGeneratedReport(reason = DUMP_INFO)
dump(IndentingPrintWriter writer)90     void dump(IndentingPrintWriter writer);
91 
92     /**
93      * Sets the fade for the vehicle.
94      *
95      * @param value to set for the fade. Positive is towards front.
96      */
setFadeTowardFront(float value)97     void setFadeTowardFront(float value);
98 
99     /**
100      * Sets the balance value for the vehicle.
101      *
102      * @param value to set for the balance. Positive is towards the right.
103      */
setBalanceTowardRight(float value)104     void setBalanceTowardRight(float value);
105 
106     /**
107      * Notifies HAL of changes in usages holding focus and the corresponding ducking changes for a
108      * given zone.
109      *
110      * @param carDuckingInfos list of information about focus and addresses to duck for each
111      * impacted zone to relay to the HAL.
112      */
onDevicesToDuckChange(@onNull List<CarDuckingInfo> carDuckingInfos)113     void onDevicesToDuckChange(@NonNull List<CarDuckingInfo> carDuckingInfos);
114 
115     /**
116      * Notifies HAL of changes in muting changes for all audio zones.
117      *
118      * @param carZonesMutingInfo list of information about addresses to mute to relay to the HAL.
119      */
onDevicesToMuteChange(@onNull List<MutingInfo> carZonesMutingInfo)120     void onDevicesToMuteChange(@NonNull List<MutingInfo> carZonesMutingInfo);
121 
122     /**
123      * Registers recipient to be notified if AudioControl HAL service dies.
124      *
125      * @param deathRecipient to be notified upon HAL service death.
126      */
linkToDeath(@ullable AudioControlDeathRecipient deathRecipient)127     void linkToDeath(@Nullable AudioControlDeathRecipient deathRecipient);
128 
129     /**
130      * Unregisters recipient for AudioControl HAL service death.
131      */
unlinkToDeath()132     void unlinkToDeath();
133 
134     /**
135      * Recipient to be notified upon death of AudioControl HAL.
136      */
137     interface AudioControlDeathRecipient {
138         /**
139          * Called if AudioControl HAL dies.
140          */
serviceDied()141         void serviceDied();
142     }
143 }
144