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 #define LOG_TAG "[email protected]"
18 
19 #include "AudioControl.h"
20 
21 #include <android-base/logging.h>
22 #include <hidl/HidlTransportSupport.h>
23 
24 #include "CloseHandle.h"
25 
26 namespace android::hardware::automotive::audiocontrol::V2_0::implementation {
27 
28 using ::android::hardware::hidl_handle;
29 using ::android::hardware::hidl_string;
30 
AudioControl(const std::string & audio_control_server_addr)31 AudioControl::AudioControl(const std::string& audio_control_server_addr)
32     : mAudioControlServer(MakeAudioControlServer(audio_control_server_addr)) {}
33 
registerFocusListener(const sp<IFocusListener> & listener)34 Return<sp<ICloseHandle>> AudioControl::registerFocusListener(const sp<IFocusListener>& listener) {
35     LOG(DEBUG) << "registering focus listener";
36     sp<ICloseHandle> closeHandle(nullptr);
37 
38     if (listener) {
39         closeHandle = new CloseHandle(mAudioControlServer->RegisterFocusListener(listener));
40     } else {
41         LOG(ERROR) << "Unexpected nullptr for listener resulting in no-op.";
42     }
43 
44     return closeHandle;
45 }
46 
setBalanceTowardRight(float)47 Return<void> AudioControl::setBalanceTowardRight(float) {
48     return Void();
49 }
50 
setFadeTowardFront(float)51 Return<void> AudioControl::setFadeTowardFront(float) {
52     return Void();
53 }
54 
onAudioFocusChange(hidl_bitfield<AudioUsage> usage,int zoneId,hidl_bitfield<AudioFocusChange> focusChange)55 Return<void> AudioControl::onAudioFocusChange(hidl_bitfield<AudioUsage> usage, int zoneId,
56                                               hidl_bitfield<AudioFocusChange> focusChange) {
57     LOG(INFO) << "Focus changed: " << toString(static_cast<AudioUsage>(focusChange))
58               << " for usage " << toString(static_cast<AudioFocusChange>(usage)) << " in zone "
59               << zoneId;
60     return Void();
61 }
62 
debug(const hidl_handle &,const hidl_vec<hidl_string> &)63 Return<void> AudioControl::debug(const hidl_handle&, const hidl_vec<hidl_string>&) {
64     return Void();
65 }
66 
isHealthy()67 bool AudioControl::isHealthy() {
68     // TODO(egranata, chenhaosjtuacm): fill this in with a real check
69     // e.g. add a heartbeat message to remote side
70     return true;
71 }
72 
ServerStart()73 void AudioControl::ServerStart() {
74     mAudioControlServer->Start();
75 }
76 
ServerJoin()77 void AudioControl::ServerJoin() {
78     mAudioControlServer->Join();
79 }
80 
81 }  // namespace android::hardware::automotive::audiocontrol::V2_0::implementation
82