1 /*
2  * Copyright (C) 2021 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 #ifndef ANDROID_HARDWARE_AUTOMOTIVE_AUDIOCONTROL_AUDIOCONTROL_H
17 #define ANDROID_HARDWARE_AUTOMOTIVE_AUDIOCONTROL_AUDIOCONTROL_H
18 
19 #include "AudioControlServer.h"
20 
21 #include <aidl/android/hardware/automotive/audiocontrol/AudioFocusChange.h>
22 #include <aidl/android/hardware/automotive/audiocontrol/BnAudioControl.h>
23 #include <aidl/android/hardware/automotive/audiocontrol/DuckingInfo.h>
24 
25 namespace aidl::android::hardware::automotive::audiocontrol {
26 
27 using ::std::shared_ptr;
28 using ::std::unique_ptr;
29 
30 class AudioControl : public BnAudioControl {
31   public:
32     explicit AudioControl(const std::string& audio_control_server_addr);
33 
34     ndk::ScopedAStatus onAudioFocusChange(const std::string& in_usage, int32_t in_zoneId,
35                                           AudioFocusChange in_focusChange) override;
36     ndk::ScopedAStatus onDevicesToDuckChange(
37             const std::vector<DuckingInfo>& in_duckingInfos) override;
38     ndk::ScopedAStatus onDevicesToMuteChange(
39             const std::vector<MutingInfo>& in_mutingInfos) override;
40     ndk::ScopedAStatus registerFocusListener(
41             const shared_ptr<IFocusListener>& in_listener) override;
42     ndk::ScopedAStatus setBalanceTowardRight(float in_value) override;
43     ndk::ScopedAStatus setFadeTowardFront(float in_value) override;
44     binder_status_t dump(int fd, const char** args, uint32_t numArgs) override;
45 
46     bool isHealthy();
47 
48     void start();
49     void join();
50 
51   private:
52     // This focus listener will only be used by this HAL instance to communicate with
53     // a single instance of CarAudioService. As such, it doesn't have explicit serialization.
54     // If a different AudioControl implementation were to have multiple threads leveraging this
55     // listener, then it should also include mutexes or make the listener atomic.
56     shared_ptr<IFocusListener> mFocusListener;
57     unique_ptr<AudioControlServer> mAudioControlServer;
58 };
59 
60 }  // namespace aidl::android::hardware::automotive::audiocontrol
61 
62 #endif  // ANDROID_HARDWARE_AUTOMOTIVE_AUDIOCONTROL_AUDIOCONTROL_H
63