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 android.hardware.automotive.audiocontrol.V2_0.IFocusListener;
20 import android.media.AudioAttributes.AttributeUsage;
21 
22 import androidx.annotation.Nullable;
23 
24 import java.io.PrintWriter;
25 
26 /**
27  * AudioControlWrapper wraps IAudioControl HAL interface, handling version specific support so that
28  * the rest of CarAudioService doesn't need to know about it.
29  */
30 public interface AudioControlWrapper {
31 
32     /**
33      * Closes the focus listener that's registered on the AudioControl HAL
34      */
unregisterFocusListener()35     void unregisterFocusListener();
36 
37     /**
38      * Indicates if HAL can support making and abandoning audio focus requests.
39      */
supportsHalAudioFocus()40     boolean supportsHalAudioFocus();
41 
42     /**
43      * Registers listener for HAL audio focus requests with IAudioControl. Only works if
44      * {@code supportsHalAudioFocus} returns true.
45      *
46      * @param focusListener the listener to register on the IAudioControl HAL.
47      */
registerFocusListener(IFocusListener focusListener)48     void registerFocusListener(IFocusListener focusListener);
49 
50     /**
51      * Notifies HAL of change in audio focus for a request it has made.
52      *
53      * @param usage that the request is associated with.
54      * @param zoneId for the audio zone that the request is associated with.
55      * @param focusChange the new status of the request.
56      */
onAudioFocusChange(@ttributeUsage int usage, int zoneId, int focusChange)57     void onAudioFocusChange(@AttributeUsage int usage, int zoneId, int focusChange);
58 
59     /**
60      * dumps the current state of the AudioControlWrapper
61      *
62      * @param indent indent to append to each new line
63      * @param writer stream to write current state
64      */
dump(String indent, PrintWriter writer)65     void dump(String indent, PrintWriter writer);
66 
67     /**
68      * Sets the fade for the vehicle.
69      *
70      * @param value to set for the fade. Positive is towards front.
71      */
setFadeTowardFront(float value)72     void setFadeTowardFront(float value);
73 
74     /**
75      * Sets the balance value for the vehicle.
76      *
77      * @param value to set for the balance. Positive is towards the right.
78      */
setBalanceTowardRight(float value)79     void setBalanceTowardRight(float value);
80 
81     /**
82      * Registers recipient to be notified if AudioControl HAL service dies.
83      * @param deathRecipient to be notified upon HAL service death.
84      */
linkToDeath(@ullable AudioControlDeathRecipient deathRecipient)85     void linkToDeath(@Nullable AudioControlDeathRecipient deathRecipient);
86 
87     /**
88      * Unregisters recipient for AudioControl HAL service death.
89      */
unlinkToDeath()90     void unlinkToDeath();
91 
92     /**
93      * Recipient to be notified upon death of AudioControl HAL.
94      */
95     interface AudioControlDeathRecipient {
96         /**
97          * Called if AudioControl HAL dies.
98          */
serviceDied()99         void serviceDied();
100     }
101 }
102