Mikhail Naganov | 10c6fe2 | 2022-09-30 23:49:17 +0000 | [diff] [blame] | 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_Bluetooth" |
| 18 | #include <android-base/logging.h> |
| 19 | |
| 20 | #include "core-impl/Bluetooth.h" |
| 21 | |
Mikhail Naganov | 7499a00 | 2023-02-27 18:51:44 -0800 | [diff] [blame] | 22 | using aidl::android::hardware::audio::core::VendorParameter; |
Mikhail Naganov | 10c6fe2 | 2022-09-30 23:49:17 +0000 | [diff] [blame] | 23 | using aidl::android::media::audio::common::Boolean; |
| 24 | using aidl::android::media::audio::common::Float; |
| 25 | using aidl::android::media::audio::common::Int; |
| 26 | |
| 27 | namespace aidl::android::hardware::audio::core { |
| 28 | |
| 29 | Bluetooth::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 | |
| 38 | ndk::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 | |
| 57 | ndk::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 Naganov | 7499a00 | 2023-02-27 18:51:44 -0800 | [diff] [blame] | 83 | ndk::ScopedAStatus BluetoothA2dp::isEnabled(bool* _aidl_return) { |
| 84 | *_aidl_return = mEnabled; |
| 85 | LOG(DEBUG) << __func__ << ": returning " << *_aidl_return; |
| 86 | return ndk::ScopedAStatus::ok(); |
| 87 | } |
| 88 | |
| 89 | ndk::ScopedAStatus BluetoothA2dp::setEnabled(bool in_enabled) { |
| 90 | mEnabled = in_enabled; |
| 91 | LOG(DEBUG) << __func__ << ": " << mEnabled; |
| 92 | return ndk::ScopedAStatus::ok(); |
| 93 | } |
| 94 | |
| 95 | ndk::ScopedAStatus BluetoothA2dp::supportsOffloadReconfiguration(bool* _aidl_return) { |
| 96 | *_aidl_return = true; |
| 97 | LOG(DEBUG) << __func__ << ": returning " << *_aidl_return; |
| 98 | return ndk::ScopedAStatus::ok(); |
| 99 | } |
| 100 | |
| 101 | ndk::ScopedAStatus BluetoothA2dp::reconfigureOffload( |
| 102 | const std::vector<::aidl::android::hardware::audio::core::VendorParameter>& in_parameters |
| 103 | __unused) { |
| 104 | LOG(DEBUG) << __func__ << ": " << ::android::internal::ToString(in_parameters); |
| 105 | return ndk::ScopedAStatus::ok(); |
| 106 | } |
| 107 | |
Mikhail Naganov | b5647da | 2023-03-06 14:37:38 -0800 | [diff] [blame] | 108 | ndk::ScopedAStatus BluetoothLe::isEnabled(bool* _aidl_return) { |
| 109 | *_aidl_return = mEnabled; |
| 110 | LOG(DEBUG) << __func__ << ": returning " << *_aidl_return; |
| 111 | return ndk::ScopedAStatus::ok(); |
| 112 | } |
| 113 | |
| 114 | ndk::ScopedAStatus BluetoothLe::setEnabled(bool in_enabled) { |
| 115 | mEnabled = in_enabled; |
| 116 | LOG(DEBUG) << __func__ << ": " << mEnabled; |
| 117 | return ndk::ScopedAStatus::ok(); |
| 118 | } |
| 119 | |
Mikhail Naganov | b4f8e67 | 2023-03-10 09:19:35 -0800 | [diff] [blame] | 120 | ndk::ScopedAStatus BluetoothLe::supportsOffloadReconfiguration(bool* _aidl_return) { |
| 121 | *_aidl_return = true; |
| 122 | LOG(DEBUG) << __func__ << ": returning " << *_aidl_return; |
| 123 | return ndk::ScopedAStatus::ok(); |
| 124 | } |
| 125 | |
| 126 | ndk::ScopedAStatus BluetoothLe::reconfigureOffload( |
| 127 | const std::vector<::aidl::android::hardware::audio::core::VendorParameter>& in_parameters |
| 128 | __unused) { |
| 129 | LOG(DEBUG) << __func__ << ": " << ::android::internal::ToString(in_parameters); |
| 130 | return ndk::ScopedAStatus::ok(); |
| 131 | } |
| 132 | |
Mikhail Naganov | 10c6fe2 | 2022-09-30 23:49:17 +0000 | [diff] [blame] | 133 | } // namespace aidl::android::hardware::audio::core |