1 /*
2  * Copyright (C) 2022 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 "AHAL_Config"
18 #include <android-base/logging.h>
19 
20 #include <system/audio_config.h>
21 
22 #include "core-impl/AudioPolicyConfigXmlConverter.h"
23 #include "core-impl/Config.h"
24 #include "core-impl/EngineConfigXmlConverter.h"
25 
26 using aidl::android::media::audio::common::AudioHalEngineConfig;
27 
28 namespace aidl::android::hardware::audio::core {
getSurroundSoundConfig(SurroundSoundConfig * _aidl_return)29 ndk::ScopedAStatus Config::getSurroundSoundConfig(SurroundSoundConfig* _aidl_return) {
30     static const auto& func = __func__;
31     static const SurroundSoundConfig surroundSoundConfig = [this]() {
32         SurroundSoundConfig surroundCfg = mAudioPolicyConverter.getSurroundSoundConfig();
33         if (mAudioPolicyConverter.getStatus() != ::android::OK) {
34             LOG(WARNING) << func << ": " << mAudioPolicyConverter.getError();
35         }
36         return surroundCfg;
37     }();
38     *_aidl_return = surroundSoundConfig;
39     LOG(DEBUG) << __func__ << ": returning " << _aidl_return->toString();
40     return ndk::ScopedAStatus::ok();
41 }
42 
getEngineConfig(AudioHalEngineConfig * _aidl_return)43 ndk::ScopedAStatus Config::getEngineConfig(AudioHalEngineConfig* _aidl_return) {
44     static const auto& func = __func__;
45     static const AudioHalEngineConfig returnEngCfg = [this]() {
46         AudioHalEngineConfig engConfig;
47         if (mEngConfigConverter.getStatus() == ::android::OK) {
48             engConfig = mEngConfigConverter.getAidlEngineConfig();
49         } else {
50             LOG(INFO) << func << ": " << mEngConfigConverter.getError();
51             if (mAudioPolicyConverter.getStatus() == ::android::OK) {
52                 engConfig = mAudioPolicyConverter.getAidlEngineConfig();
53             } else {
54                 LOG(WARNING) << func << ": " << mAudioPolicyConverter.getError();
55             }
56         }
57         // Logging full contents of the config is an overkill, just provide statistics.
58         LOG(DEBUG) << func
59                    << ": number of strategies parsed: " << engConfig.productStrategies.size()
60                    << ", default strategy: " << engConfig.defaultProductStrategyId
61                    << ", number of volume groups parsed: " << engConfig.volumeGroups.size();
62         return engConfig;
63     }();
64     *_aidl_return = returnEngCfg;
65     return ndk::ScopedAStatus::ok();
66 }
67 }  // namespace aidl::android::hardware::audio::core
68