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; |
Mikhail Naganov | 7499a00 | 2023-02-27 18:51:44 -0800 | [diff] [blame] | 85 | return ndk::ScopedAStatus::ok(); |
| 86 | } |
| 87 | |
| 88 | ndk::ScopedAStatus BluetoothA2dp::setEnabled(bool in_enabled) { |
| 89 | mEnabled = in_enabled; |
| 90 | LOG(DEBUG) << __func__ << ": " << mEnabled; |
Ram Mohan | 18f0d51 | 2023-07-01 00:47:09 +0530 | [diff] [blame] | 91 | if (mHandler) return mHandler(); |
Mikhail Naganov | 7499a00 | 2023-02-27 18:51:44 -0800 | [diff] [blame] | 92 | return ndk::ScopedAStatus::ok(); |
| 93 | } |
| 94 | |
| 95 | ndk::ScopedAStatus BluetoothA2dp::supportsOffloadReconfiguration(bool* _aidl_return) { |
Ram Mohan | 18f0d51 | 2023-07-01 00:47:09 +0530 | [diff] [blame] | 96 | *_aidl_return = false; |
Mikhail Naganov | 7499a00 | 2023-02-27 18:51:44 -0800 | [diff] [blame] | 97 | return ndk::ScopedAStatus::ok(); |
| 98 | } |
| 99 | |
| 100 | ndk::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 Mohan | 18f0d51 | 2023-07-01 00:47:09 +0530 | [diff] [blame] | 104 | return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
Mikhail Naganov | 7499a00 | 2023-02-27 18:51:44 -0800 | [diff] [blame] | 105 | } |
| 106 | |
Mikhail Naganov | b5647da | 2023-03-06 14:37:38 -0800 | [diff] [blame] | 107 | ndk::ScopedAStatus BluetoothLe::isEnabled(bool* _aidl_return) { |
| 108 | *_aidl_return = mEnabled; |
Mikhail Naganov | b5647da | 2023-03-06 14:37:38 -0800 | [diff] [blame] | 109 | return ndk::ScopedAStatus::ok(); |
| 110 | } |
| 111 | |
| 112 | ndk::ScopedAStatus BluetoothLe::setEnabled(bool in_enabled) { |
| 113 | mEnabled = in_enabled; |
Ram Mohan | 18f0d51 | 2023-07-01 00:47:09 +0530 | [diff] [blame] | 114 | if (mHandler) return mHandler(); |
Mikhail Naganov | b5647da | 2023-03-06 14:37:38 -0800 | [diff] [blame] | 115 | return ndk::ScopedAStatus::ok(); |
| 116 | } |
| 117 | |
Mikhail Naganov | b4f8e67 | 2023-03-10 09:19:35 -0800 | [diff] [blame] | 118 | ndk::ScopedAStatus BluetoothLe::supportsOffloadReconfiguration(bool* _aidl_return) { |
Ram Mohan | 18f0d51 | 2023-07-01 00:47:09 +0530 | [diff] [blame] | 119 | *_aidl_return = false; |
Mikhail Naganov | b4f8e67 | 2023-03-10 09:19:35 -0800 | [diff] [blame] | 120 | return ndk::ScopedAStatus::ok(); |
| 121 | } |
| 122 | |
| 123 | ndk::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 Mohan | 18f0d51 | 2023-07-01 00:47:09 +0530 | [diff] [blame] | 127 | return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
Mikhail Naganov | b4f8e67 | 2023-03-10 09:19:35 -0800 | [diff] [blame] | 128 | } |
| 129 | |
Mikhail Naganov | 10c6fe2 | 2022-09-30 23:49:17 +0000 | [diff] [blame] | 130 | } // namespace aidl::android::hardware::audio::core |