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 #ifndef ANDROID_HARDWARE_AUTOMOTIVE_AUDIOCONTROL_V2_0_AUDIOCONTROL_H
18 #define ANDROID_HARDWARE_AUTOMOTIVE_AUDIOCONTROL_V2_0_AUDIOCONTROL_H
19 
20 #include <android/hardware/audio/common/6.0/types.h>
21 #include <android/hardware/automotive/audiocontrol/2.0/IAudioControl.h>
22 #include <android/hardware/automotive/audiocontrol/2.0/ICloseHandle.h>
23 #include <hidl/MQDescriptor.h>
24 #include <hidl/Status.h>
25 
26 using android::hardware::audio::common::V6_0::AudioUsage;
27 
28 namespace android::hardware::automotive::audiocontrol::V2_0::implementation {
29 
30 class AudioControl : public IAudioControl {
31   public:
32     // Methods from ::android::hardware::automotive::audiocontrol::V2_0::IAudioControl follow.
33     Return<sp<ICloseHandle>> registerFocusListener(const sp<IFocusListener>& listener);
34     Return<void> onAudioFocusChange(hidl_bitfield<AudioUsage> usage, int zoneId,
35                                     hidl_bitfield<AudioFocusChange> focusChange);
36     Return<void> setBalanceTowardRight(float value) override;
37     Return<void> setFadeTowardFront(float value) override;
38     Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& options) override;
39 
40     // Implementation details
41     AudioControl();
42 
43   private:
44     sp<IFocusListener> mFocusListener;
45 
46     static bool checkArgumentsSize(int fd, const hidl_vec<hidl_string>& options, size_t minSize);
47     static bool checkCallerHasWritePermissions(int fd);
48     static bool isValidValue(float value);
49     static bool safelyParseInt(std::string s, int* out);
50 
51     void cmdDump(int fd, const hidl_vec<hidl_string>& options);
52     void cmdHelp(int fd) const;
53     void cmdRequestFocus(int fd, const hidl_vec<hidl_string>& options);
54     void cmdAbandonFocus(int fd, const hidl_vec<hidl_string>& options);
55     void dump(int fd);
56 };
57 
58 }  // namespace android::hardware::automotive::audiocontrol::V2_0::implementation
59 
60 #endif  // ANDROID_HARDWARE_AUTOMOTIVE_AUDIOCONTROL_V2_0_AUDIOCONTROL_H
61