blob: 38e0c21ea8abce2e8638ac6aae68077e1bfc8573 [file] [log] [blame]
Mikhail Naganov10c6fe22022-09-30 23:49:17 +00001/*
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_Bluetooth"
18#include <android-base/logging.h>
19
20#include "core-impl/Bluetooth.h"
21
22using aidl::android::media::audio::common::Boolean;
23using aidl::android::media::audio::common::Float;
24using aidl::android::media::audio::common::Int;
25
26namespace aidl::android::hardware::audio::core {
27
28Bluetooth::Bluetooth() {
29 mScoConfig.isEnabled = Boolean{false};
30 mScoConfig.isNrecEnabled = Boolean{false};
31 mScoConfig.mode = ScoConfig::Mode::SCO;
32 mHfpConfig.isEnabled = Boolean{false};
33 mHfpConfig.sampleRate = Int{8000};
34 mHfpConfig.volume = Float{HfpConfig::VOLUME_MAX};
35}
36
37ndk::ScopedAStatus Bluetooth::setScoConfig(const ScoConfig& in_config, ScoConfig* _aidl_return) {
38 if (in_config.isEnabled.has_value()) {
39 mScoConfig.isEnabled = in_config.isEnabled;
40 }
41 if (in_config.isNrecEnabled.has_value()) {
42 mScoConfig.isNrecEnabled = in_config.isNrecEnabled;
43 }
44 if (in_config.mode != ScoConfig::Mode::UNSPECIFIED) {
45 mScoConfig.mode = in_config.mode;
46 }
47 if (in_config.debugName.has_value()) {
48 mScoConfig.debugName = in_config.debugName;
49 }
50 *_aidl_return = mScoConfig;
51 LOG(DEBUG) << __func__ << ": received " << in_config.toString() << ", returning "
52 << _aidl_return->toString();
53 return ndk::ScopedAStatus::ok();
54}
55
56ndk::ScopedAStatus Bluetooth::setHfpConfig(const HfpConfig& in_config, HfpConfig* _aidl_return) {
57 if (in_config.sampleRate.has_value() && in_config.sampleRate.value().value <= 0) {
58 LOG(ERROR) << __func__ << ": invalid sample rate: " << in_config.sampleRate.value().value;
59 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
60 }
61 if (in_config.volume.has_value() && (in_config.volume.value().value < HfpConfig::VOLUME_MIN ||
62 in_config.volume.value().value > HfpConfig::VOLUME_MAX)) {
63 LOG(ERROR) << __func__ << ": invalid volume: " << in_config.volume.value().value;
64 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
65 }
66
67 if (in_config.isEnabled.has_value()) {
68 mHfpConfig.isEnabled = in_config.isEnabled;
69 }
70 if (in_config.sampleRate.has_value()) {
71 mHfpConfig.sampleRate = in_config.sampleRate;
72 }
73 if (in_config.volume.has_value()) {
74 mHfpConfig.volume = in_config.volume;
75 }
76 *_aidl_return = mHfpConfig;
77 LOG(DEBUG) << __func__ << ": received " << in_config.toString() << ", returning "
78 << _aidl_return->toString();
79 return ndk::ScopedAStatus::ok();
80}
81
82} // namespace aidl::android::hardware::audio::core