blob: 072b89fefb0fb02b68217cf62e62af11d2f1e021 [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
Mikhail Naganov7499a002023-02-27 18:51:44 -080022using aidl::android::hardware::audio::core::VendorParameter;
Mikhail Naganov10c6fe22022-09-30 23:49:17 +000023using aidl::android::media::audio::common::Boolean;
24using aidl::android::media::audio::common::Float;
25using aidl::android::media::audio::common::Int;
26
27namespace aidl::android::hardware::audio::core {
28
29Bluetooth::Bluetooth() {
30 mScoConfig.isEnabled = Boolean{false};
31 mScoConfig.isNrecEnabled = Boolean{false};
32 mScoConfig.mode = ScoConfig::Mode::SCO;
33 mHfpConfig.isEnabled = Boolean{false};
34 mHfpConfig.sampleRate = Int{8000};
35 mHfpConfig.volume = Float{HfpConfig::VOLUME_MAX};
36}
37
38ndk::ScopedAStatus Bluetooth::setScoConfig(const ScoConfig& in_config, ScoConfig* _aidl_return) {
39 if (in_config.isEnabled.has_value()) {
40 mScoConfig.isEnabled = in_config.isEnabled;
41 }
42 if (in_config.isNrecEnabled.has_value()) {
43 mScoConfig.isNrecEnabled = in_config.isNrecEnabled;
44 }
45 if (in_config.mode != ScoConfig::Mode::UNSPECIFIED) {
46 mScoConfig.mode = in_config.mode;
47 }
48 if (in_config.debugName.has_value()) {
49 mScoConfig.debugName = in_config.debugName;
50 }
51 *_aidl_return = mScoConfig;
52 LOG(DEBUG) << __func__ << ": received " << in_config.toString() << ", returning "
53 << _aidl_return->toString();
54 return ndk::ScopedAStatus::ok();
55}
56
57ndk::ScopedAStatus Bluetooth::setHfpConfig(const HfpConfig& in_config, HfpConfig* _aidl_return) {
58 if (in_config.sampleRate.has_value() && in_config.sampleRate.value().value <= 0) {
59 LOG(ERROR) << __func__ << ": invalid sample rate: " << in_config.sampleRate.value().value;
60 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
61 }
62 if (in_config.volume.has_value() && (in_config.volume.value().value < HfpConfig::VOLUME_MIN ||
63 in_config.volume.value().value > HfpConfig::VOLUME_MAX)) {
64 LOG(ERROR) << __func__ << ": invalid volume: " << in_config.volume.value().value;
65 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
66 }
67
68 if (in_config.isEnabled.has_value()) {
69 mHfpConfig.isEnabled = in_config.isEnabled;
70 }
71 if (in_config.sampleRate.has_value()) {
72 mHfpConfig.sampleRate = in_config.sampleRate;
73 }
74 if (in_config.volume.has_value()) {
75 mHfpConfig.volume = in_config.volume;
76 }
77 *_aidl_return = mHfpConfig;
78 LOG(DEBUG) << __func__ << ": received " << in_config.toString() << ", returning "
79 << _aidl_return->toString();
80 return ndk::ScopedAStatus::ok();
81}
82
Mikhail Naganov7499a002023-02-27 18:51:44 -080083ndk::ScopedAStatus BluetoothA2dp::isEnabled(bool* _aidl_return) {
84 *_aidl_return = mEnabled;
Mikhail Naganov7499a002023-02-27 18:51:44 -080085 return ndk::ScopedAStatus::ok();
86}
87
88ndk::ScopedAStatus BluetoothA2dp::setEnabled(bool in_enabled) {
89 mEnabled = in_enabled;
90 LOG(DEBUG) << __func__ << ": " << mEnabled;
Ram Mohan18f0d512023-07-01 00:47:09 +053091 if (mHandler) return mHandler();
Mikhail Naganov7499a002023-02-27 18:51:44 -080092 return ndk::ScopedAStatus::ok();
93}
94
95ndk::ScopedAStatus BluetoothA2dp::supportsOffloadReconfiguration(bool* _aidl_return) {
Ram Mohan18f0d512023-07-01 00:47:09 +053096 *_aidl_return = false;
Mikhail Naganov7499a002023-02-27 18:51:44 -080097 return ndk::ScopedAStatus::ok();
98}
99
100ndk::ScopedAStatus BluetoothA2dp::reconfigureOffload(
101 const std::vector<::aidl::android::hardware::audio::core::VendorParameter>& in_parameters
102 __unused) {
103 LOG(DEBUG) << __func__ << ": " << ::android::internal::ToString(in_parameters);
Ram Mohan18f0d512023-07-01 00:47:09 +0530104 return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
Mikhail Naganov7499a002023-02-27 18:51:44 -0800105}
106
Mikhail Naganovb5647da2023-03-06 14:37:38 -0800107ndk::ScopedAStatus BluetoothLe::isEnabled(bool* _aidl_return) {
108 *_aidl_return = mEnabled;
Mikhail Naganovb5647da2023-03-06 14:37:38 -0800109 return ndk::ScopedAStatus::ok();
110}
111
112ndk::ScopedAStatus BluetoothLe::setEnabled(bool in_enabled) {
113 mEnabled = in_enabled;
Ram Mohan18f0d512023-07-01 00:47:09 +0530114 if (mHandler) return mHandler();
Mikhail Naganovb5647da2023-03-06 14:37:38 -0800115 return ndk::ScopedAStatus::ok();
116}
117
Mikhail Naganovb4f8e672023-03-10 09:19:35 -0800118ndk::ScopedAStatus BluetoothLe::supportsOffloadReconfiguration(bool* _aidl_return) {
Ram Mohan18f0d512023-07-01 00:47:09 +0530119 *_aidl_return = false;
Mikhail Naganovb4f8e672023-03-10 09:19:35 -0800120 return ndk::ScopedAStatus::ok();
121}
122
123ndk::ScopedAStatus BluetoothLe::reconfigureOffload(
124 const std::vector<::aidl::android::hardware::audio::core::VendorParameter>& in_parameters
125 __unused) {
126 LOG(DEBUG) << __func__ << ": " << ::android::internal::ToString(in_parameters);
Ram Mohan18f0d512023-07-01 00:47:09 +0530127 return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
Mikhail Naganovb4f8e672023-03-10 09:19:35 -0800128}
129
Mikhail Naganov10c6fe22022-09-30 23:49:17 +0000130} // namespace aidl::android::hardware::audio::core