Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +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 "DeviceHalAidl" |
Mikhail Naganov | 89a9f74 | 2023-01-30 12:33:18 -0800 | [diff] [blame] | 18 | // #define LOG_NDEBUG 0 |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 19 | |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 20 | #include <algorithm> |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 21 | |
Mikhail Naganov | dfd594e | 2023-02-08 16:59:41 -0800 | [diff] [blame] | 22 | #include <aidl/android/hardware/audio/core/BnStreamCallback.h> |
| 23 | #include <aidl/android/hardware/audio/core/BnStreamOutEventCallback.h> |
Mikhail Naganov | fab697c | 2023-01-11 19:33:13 +0000 | [diff] [blame] | 24 | #include <aidl/android/hardware/audio/core/StreamDescriptor.h> |
| 25 | #include <error/expected_utils.h> |
| 26 | #include <media/AidlConversionCppNdk.h> |
Mikhail Naganov | 25bc9a2 | 2023-04-21 18:48:16 -0700 | [diff] [blame] | 27 | #include <media/AidlConversionNdkCpp.h> |
Mikhail Naganov | fab697c | 2023-01-11 19:33:13 +0000 | [diff] [blame] | 28 | #include <media/AidlConversionUtil.h> |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 29 | #include <mediautils/TimeCheck.h> |
Mikhail Naganov | ae9063d | 2023-11-07 16:43:51 -0800 | [diff] [blame] | 30 | #include <system/audio.h> |
Mikhail Naganov | 89a9f74 | 2023-01-30 12:33:18 -0800 | [diff] [blame] | 31 | #include <Utils.h> |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 32 | #include <utils/Log.h> |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 33 | |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 34 | #include "DeviceHalAidl.h" |
Mikhail Naganov | a82a69d | 2023-06-14 16:31:32 -0700 | [diff] [blame] | 35 | #include "EffectHalAidl.h" |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 36 | #include "StreamHalAidl.h" |
| 37 | |
Mikhail Naganov | fab697c | 2023-01-11 19:33:13 +0000 | [diff] [blame] | 38 | using aidl::android::aidl_utils::statusTFromBinderStatus; |
Mikhail Naganov | ccc8211 | 2023-04-27 18:14:15 -0700 | [diff] [blame] | 39 | using aidl::android::media::audio::common::Boolean; |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 40 | using aidl::android::media::audio::common::AudioConfig; |
| 41 | using aidl::android::media::audio::common::AudioDevice; |
Mikhail Naganov | 89a9f74 | 2023-01-30 12:33:18 -0800 | [diff] [blame] | 42 | using aidl::android::media::audio::common::AudioDeviceType; |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 43 | using aidl::android::media::audio::common::AudioIoFlags; |
Mikhail Naganov | dfd594e | 2023-02-08 16:59:41 -0800 | [diff] [blame] | 44 | using aidl::android::media::audio::common::AudioLatencyMode; |
David Li | 9cf5e62 | 2023-03-21 00:51:10 +0800 | [diff] [blame] | 45 | using aidl::android::media::audio::common::AudioMMapPolicy; |
| 46 | using aidl::android::media::audio::common::AudioMMapPolicyInfo; |
| 47 | using aidl::android::media::audio::common::AudioMMapPolicyType; |
Mikhail Naganov | fab697c | 2023-01-11 19:33:13 +0000 | [diff] [blame] | 48 | using aidl::android::media::audio::common::AudioMode; |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 49 | using aidl::android::media::audio::common::AudioOutputFlags; |
| 50 | using aidl::android::media::audio::common::AudioPort; |
| 51 | using aidl::android::media::audio::common::AudioPortConfig; |
David Li | 9cf5e62 | 2023-03-21 00:51:10 +0800 | [diff] [blame] | 52 | using aidl::android::media::audio::common::AudioPortExt; |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 53 | using aidl::android::media::audio::common::AudioSource; |
Mikhail Naganov | fab697c | 2023-01-11 19:33:13 +0000 | [diff] [blame] | 54 | using aidl::android::media::audio::common::Float; |
David Li | 9cf5e62 | 2023-03-21 00:51:10 +0800 | [diff] [blame] | 55 | using aidl::android::media::audio::common::Int; |
| 56 | using aidl::android::media::audio::common::MicrophoneDynamicInfo; |
| 57 | using aidl::android::media::audio::common::MicrophoneInfo; |
Mikhail Naganov | e7a26ad | 2023-05-25 17:36:48 -0700 | [diff] [blame] | 58 | using aidl::android::media::audio::IHalAdapterVendorExtension; |
Mikhail Naganov | 6352e82 | 2023-03-09 18:22:36 -0800 | [diff] [blame] | 59 | using aidl::android::hardware::audio::common::getFrameSizeInBytes; |
| 60 | using aidl::android::hardware::audio::common::isBitPositionFlagSet; |
David Li | 2128946 | 2024-04-17 01:09:23 +0800 | [diff] [blame] | 61 | using aidl::android::hardware::audio::common::kDumpFromAudioServerArgument; |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 62 | using aidl::android::hardware::audio::common::RecordTrackMetadata; |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 63 | using aidl::android::hardware::audio::core::sounddose::ISoundDose; |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 64 | using aidl::android::hardware::audio::core::AudioPatch; |
Mikhail Naganov | 289468a | 2023-03-29 10:06:15 -0700 | [diff] [blame] | 65 | using aidl::android::hardware::audio::core::AudioRoute; |
Mikhail Naganov | ccc8211 | 2023-04-27 18:14:15 -0700 | [diff] [blame] | 66 | using aidl::android::hardware::audio::core::IBluetooth; |
| 67 | using aidl::android::hardware::audio::core::IBluetoothA2dp; |
| 68 | using aidl::android::hardware::audio::core::IBluetoothLe; |
Mikhail Naganov | fab697c | 2023-01-11 19:33:13 +0000 | [diff] [blame] | 69 | using aidl::android::hardware::audio::core::IModule; |
| 70 | using aidl::android::hardware::audio::core::ITelephony; |
Mikhail Naganov | e93a086 | 2023-03-15 17:06:59 -0700 | [diff] [blame] | 71 | using aidl::android::hardware::audio::core::ModuleDebug; |
Mikhail Naganov | e7a26ad | 2023-05-25 17:36:48 -0700 | [diff] [blame] | 72 | using aidl::android::hardware::audio::core::VendorParameter; |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 73 | |
| 74 | namespace android { |
| 75 | |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 76 | namespace { |
| 77 | |
Mikhail Naganov | f83b974 | 2023-04-24 13:06:04 -0700 | [diff] [blame] | 78 | // Note: these converters are for types defined in different AIDL files. Although these |
| 79 | // AIDL files are copies of each other, however formally these are different types |
| 80 | // thus we don't use a conversion via a parcelable. |
| 81 | ConversionResult<media::AudioRoute> ndk2cpp_AudioRoute(const AudioRoute& ndk) { |
| 82 | media::AudioRoute cpp; |
| 83 | cpp.sourcePortIds.insert( |
| 84 | cpp.sourcePortIds.end(), ndk.sourcePortIds.begin(), ndk.sourcePortIds.end()); |
| 85 | cpp.sinkPortId = ndk.sinkPortId; |
| 86 | cpp.isExclusive = ndk.isExclusive; |
David Li | 9cf5e62 | 2023-03-21 00:51:10 +0800 | [diff] [blame] | 87 | return cpp; |
| 88 | } |
| 89 | |
Mikhail Naganov | 1fba38c | 2023-05-03 17:45:36 -0700 | [diff] [blame] | 90 | template<typename T> |
| 91 | std::shared_ptr<T> retrieveSubInterface(const std::shared_ptr<IModule>& module, |
| 92 | ::ndk::ScopedAStatus (IModule::*getT)(std::shared_ptr<T>*)) { |
| 93 | if (module != nullptr) { |
| 94 | std::shared_ptr<T> instance; |
| 95 | if (auto status = (module.get()->*getT)(&instance); status.isOk()) { |
| 96 | return instance; |
| 97 | } |
| 98 | } |
| 99 | return nullptr; |
| 100 | } |
| 101 | |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 102 | } // namespace |
| 103 | |
Mikhail Naganov | e7a26ad | 2023-05-25 17:36:48 -0700 | [diff] [blame] | 104 | DeviceHalAidl::DeviceHalAidl(const std::string& instance, const std::shared_ptr<IModule>& module, |
| 105 | const std::shared_ptr<IHalAdapterVendorExtension>& vext) |
Mikhail Naganov | 1fba38c | 2023-05-03 17:45:36 -0700 | [diff] [blame] | 106 | : ConversionHelperAidl("DeviceHalAidl"), |
Mikhail Naganov | e7a26ad | 2023-05-25 17:36:48 -0700 | [diff] [blame] | 107 | mInstance(instance), mModule(module), mVendorExt(vext), |
Mikhail Naganov | ccc8211 | 2023-04-27 18:14:15 -0700 | [diff] [blame] | 108 | mTelephony(retrieveSubInterface<ITelephony>(module, &IModule::getTelephony)), |
| 109 | mBluetooth(retrieveSubInterface<IBluetooth>(module, &IModule::getBluetooth)), |
| 110 | mBluetoothA2dp(retrieveSubInterface<IBluetoothA2dp>(module, &IModule::getBluetoothA2dp)), |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 111 | mBluetoothLe(retrieveSubInterface<IBluetoothLe>(module, &IModule::getBluetoothLe)), |
| 112 | mSoundDose(retrieveSubInterface<ISoundDose>(module, &IModule::getSoundDose)), |
| 113 | mMapper(instance, module), mMapperAccessor(mMapper, mLock) { |
Mikhail Naganov | 1fba38c | 2023-05-03 17:45:36 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Mikhail Naganov | f83b974 | 2023-04-24 13:06:04 -0700 | [diff] [blame] | 116 | status_t DeviceHalAidl::getAudioPorts(std::vector<media::audio::common::AudioPort> *ports) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 117 | std::lock_guard l(mLock); |
| 118 | return mMapper.getAudioPorts(ports, ndk2cpp_AudioPort); |
Mikhail Naganov | f83b974 | 2023-04-24 13:06:04 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | status_t DeviceHalAidl::getAudioRoutes(std::vector<media::AudioRoute> *routes) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 122 | std::lock_guard l(mLock); |
| 123 | return mMapper.getAudioRoutes(routes, ndk2cpp_AudioRoute); |
Mikhail Naganov | f83b974 | 2023-04-24 13:06:04 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Mikhail Naganov | 1fba38c | 2023-05-03 17:45:36 -0700 | [diff] [blame] | 126 | status_t DeviceHalAidl::getSupportedModes(std::vector<media::audio::common::AudioMode> *modes) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 127 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | 1fba38c | 2023-05-03 17:45:36 -0700 | [diff] [blame] | 128 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 129 | if (mModule == nullptr) return NO_INIT; |
| 130 | if (mTelephony == nullptr) return INVALID_OPERATION; |
Mikhail Naganov | 1fba38c | 2023-05-03 17:45:36 -0700 | [diff] [blame] | 131 | if (modes == nullptr) { |
| 132 | return BAD_VALUE; |
| 133 | } |
Mikhail Naganov | 1fba38c | 2023-05-03 17:45:36 -0700 | [diff] [blame] | 134 | std::vector<AudioMode> aidlModes; |
| 135 | RETURN_STATUS_IF_ERROR( |
| 136 | statusTFromBinderStatus(mTelephony->getSupportedAudioModes(&aidlModes))); |
| 137 | *modes = VALUE_OR_RETURN_STATUS( |
| 138 | ::aidl::android::convertContainer<std::vector<media::audio::common::AudioMode>>( |
| 139 | aidlModes, ndk2cpp_AudioMode)); |
| 140 | return OK; |
| 141 | } |
| 142 | |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 143 | status_t DeviceHalAidl::getSupportedDevices(uint32_t*) { |
| 144 | // Obsolete. |
| 145 | return INVALID_OPERATION; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | status_t DeviceHalAidl::initCheck() { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 149 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 150 | TIME_CHECK(); |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 151 | if (mModule == nullptr) return NO_INIT; |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 152 | std::lock_guard l(mLock); |
| 153 | return mMapper.initialize(); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | status_t DeviceHalAidl::setVoiceVolume(float volume) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 157 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 158 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 159 | if (mModule == nullptr) return NO_INIT; |
Mikhail Naganov | 1fba38c | 2023-05-03 17:45:36 -0700 | [diff] [blame] | 160 | if (mTelephony == nullptr) return INVALID_OPERATION; |
| 161 | ITelephony::TelecomConfig inConfig{ .voiceVolume = Float{volume} }, outConfig; |
| 162 | RETURN_STATUS_IF_ERROR( |
| 163 | statusTFromBinderStatus(mTelephony->setTelecomConfig(inConfig, &outConfig))); |
| 164 | ALOGW_IF(outConfig.voiceVolume.has_value() && volume != outConfig.voiceVolume.value().value, |
| 165 | "%s: the resulting voice volume %f is not the same as requested %f", |
| 166 | __func__, outConfig.voiceVolume.value().value, volume); |
| 167 | return OK; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | status_t DeviceHalAidl::setMasterVolume(float volume) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 171 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 172 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 173 | if (mModule == nullptr) return NO_INIT; |
Mikhail Naganov | fab697c | 2023-01-11 19:33:13 +0000 | [diff] [blame] | 174 | return statusTFromBinderStatus(mModule->setMasterVolume(volume)); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | status_t DeviceHalAidl::getMasterVolume(float *volume) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 178 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 179 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 180 | if (mModule == nullptr) return NO_INIT; |
| 181 | if (volume == nullptr) { |
| 182 | return BAD_VALUE; |
| 183 | } |
Mikhail Naganov | fab697c | 2023-01-11 19:33:13 +0000 | [diff] [blame] | 184 | return statusTFromBinderStatus(mModule->getMasterVolume(volume)); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Mikhail Naganov | fab697c | 2023-01-11 19:33:13 +0000 | [diff] [blame] | 187 | status_t DeviceHalAidl::setMode(audio_mode_t mode) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 188 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 189 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 190 | if (mModule == nullptr) return NO_INIT; |
Mikhail Naganov | fab697c | 2023-01-11 19:33:13 +0000 | [diff] [blame] | 191 | AudioMode audioMode = VALUE_OR_FATAL(::aidl::android::legacy2aidl_audio_mode_t_AudioMode(mode)); |
Mikhail Naganov | 1fba38c | 2023-05-03 17:45:36 -0700 | [diff] [blame] | 192 | if (mTelephony != nullptr) { |
| 193 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mTelephony->switchAudioMode(audioMode))); |
Mikhail Naganov | fab697c | 2023-01-11 19:33:13 +0000 | [diff] [blame] | 194 | } |
| 195 | return statusTFromBinderStatus(mModule->updateAudioMode(audioMode)); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | status_t DeviceHalAidl::setMicMute(bool state) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 199 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 200 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 201 | if (mModule == nullptr) return NO_INIT; |
Mikhail Naganov | fab697c | 2023-01-11 19:33:13 +0000 | [diff] [blame] | 202 | return statusTFromBinderStatus(mModule->setMicMute(state)); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 203 | } |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 204 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 205 | status_t DeviceHalAidl::getMicMute(bool *state) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 206 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 207 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 208 | if (mModule == nullptr) return NO_INIT; |
| 209 | if (state == nullptr) { |
| 210 | return BAD_VALUE; |
| 211 | } |
Mikhail Naganov | fab697c | 2023-01-11 19:33:13 +0000 | [diff] [blame] | 212 | return statusTFromBinderStatus(mModule->getMicMute(state)); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 213 | } |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 214 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 215 | status_t DeviceHalAidl::setMasterMute(bool state) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 216 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 217 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 218 | if (mModule == nullptr) return NO_INIT; |
Mikhail Naganov | fab697c | 2023-01-11 19:33:13 +0000 | [diff] [blame] | 219 | return statusTFromBinderStatus(mModule->setMasterMute(state)); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 220 | } |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 221 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 222 | status_t DeviceHalAidl::getMasterMute(bool *state) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 223 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 224 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 225 | if (mModule == nullptr) return NO_INIT; |
| 226 | if (state == nullptr) { |
| 227 | return BAD_VALUE; |
| 228 | } |
Mikhail Naganov | fab697c | 2023-01-11 19:33:13 +0000 | [diff] [blame] | 229 | return statusTFromBinderStatus(mModule->getMasterMute(state)); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Mikhail Naganov | ccc8211 | 2023-04-27 18:14:15 -0700 | [diff] [blame] | 232 | status_t DeviceHalAidl::setParameters(const String8& kvPairs) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 233 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
| 234 | TIME_CHECK(); |
| 235 | if (mModule == nullptr) return NO_INIT; |
Mikhail Naganov | ccc8211 | 2023-04-27 18:14:15 -0700 | [diff] [blame] | 236 | AudioParameter parameters(kvPairs); |
| 237 | ALOGD("%s: parameters: \"%s\"", __func__, parameters.toString().c_str()); |
| 238 | |
| 239 | if (status_t status = filterAndUpdateBtA2dpParameters(parameters); status != OK) { |
| 240 | ALOGW("%s: filtering or updating BT A2DP parameters failed: %d", __func__, status); |
| 241 | } |
| 242 | if (status_t status = filterAndUpdateBtHfpParameters(parameters); status != OK) { |
| 243 | ALOGW("%s: filtering or updating BT HFP parameters failed: %d", __func__, status); |
| 244 | } |
| 245 | if (status_t status = filterAndUpdateBtLeParameters(parameters); status != OK) { |
| 246 | ALOGW("%s: filtering or updating BT LE parameters failed: %d", __func__, status); |
| 247 | } |
| 248 | if (status_t status = filterAndUpdateBtScoParameters(parameters); status != OK) { |
| 249 | ALOGW("%s: filtering or updating BT SCO parameters failed: %d", __func__, status); |
| 250 | } |
Mikhail Naganov | e92c34b | 2023-05-31 14:24:48 -0700 | [diff] [blame] | 251 | if (status_t status = filterAndUpdateScreenParameters(parameters); status != OK) { |
| 252 | ALOGW("%s: filtering or updating screen parameters failed: %d", __func__, status); |
| 253 | } |
Mikhail Naganov | b9a8131 | 2023-07-18 13:55:34 -0700 | [diff] [blame] | 254 | if (status_t status = filterAndUpdateTelephonyParameters(parameters); status != OK) { |
| 255 | ALOGW("%s: filtering or updating telephony parameters failed: %d", __func__, status); |
| 256 | } |
Mikhail Naganov | e7a26ad | 2023-05-25 17:36:48 -0700 | [diff] [blame] | 257 | return parseAndSetVendorParameters(mVendorExt, mModule, parameters); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Mikhail Naganov | e7a26ad | 2023-05-25 17:36:48 -0700 | [diff] [blame] | 260 | status_t DeviceHalAidl::getParameters(const String8& keys, String8 *values) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 261 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 262 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 263 | if (mModule == nullptr) return NO_INIT; |
Mikhail Naganov | e7a26ad | 2023-05-25 17:36:48 -0700 | [diff] [blame] | 264 | if (values == nullptr) { |
| 265 | return BAD_VALUE; |
| 266 | } |
| 267 | AudioParameter parameterKeys(keys), result; |
| 268 | if (status_t status = filterAndRetrieveBtA2dpParameters(parameterKeys, &result); status != OK) { |
| 269 | ALOGW("%s: filtering or retrieving BT A2DP parameters failed: %d", __func__, status); |
| 270 | } |
Eric Laurent | 7e3c083 | 2023-11-30 15:04:50 +0100 | [diff] [blame] | 271 | if (status_t status = filterAndRetrieveBtLeParameters(parameterKeys, &result); status != OK) { |
| 272 | ALOGW("%s: filtering or retrieving BT LE parameters failed: %d", __func__, status); |
| 273 | } |
Mikhail Naganov | e7a26ad | 2023-05-25 17:36:48 -0700 | [diff] [blame] | 274 | *values = result.toString(); |
| 275 | return parseAndGetVendorParameters(mVendorExt, mModule, parameterKeys, values); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 276 | } |
| 277 | |
Mikhail Naganov | d5b643f | 2024-02-15 11:51:26 -0800 | [diff] [blame] | 278 | status_t DeviceHalAidl::getInputBufferSize(struct audio_config* config, size_t* size) { |
Mikhail Naganov | 89a9f74 | 2023-01-30 12:33:18 -0800 | [diff] [blame] | 279 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | 89a9f74 | 2023-01-30 12:33:18 -0800 | [diff] [blame] | 280 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 281 | if (mModule == nullptr) return NO_INIT; |
| 282 | if (config == nullptr || size == nullptr) { |
| 283 | return BAD_VALUE; |
| 284 | } |
Mikhail Naganov | d5b643f | 2024-02-15 11:51:26 -0800 | [diff] [blame] | 285 | constexpr bool isInput = true; |
Mikhail Naganov | 89a9f74 | 2023-01-30 12:33:18 -0800 | [diff] [blame] | 286 | AudioConfig aidlConfig = VALUE_OR_RETURN_STATUS( |
Mikhail Naganov | d5b643f | 2024-02-15 11:51:26 -0800 | [diff] [blame] | 287 | ::aidl::android::legacy2aidl_audio_config_t_AudioConfig(*config, isInput)); |
Mikhail Naganov | 89a9f74 | 2023-01-30 12:33:18 -0800 | [diff] [blame] | 288 | AudioDevice aidlDevice; |
| 289 | aidlDevice.type.type = AudioDeviceType::IN_DEFAULT; |
Mikhail Naganov | d8d01f7 | 2023-03-09 16:24:40 -0800 | [diff] [blame] | 290 | AudioSource aidlSource = AudioSource::DEFAULT; |
Mikhail Naganov | 89a9f74 | 2023-01-30 12:33:18 -0800 | [diff] [blame] | 291 | AudioIoFlags aidlFlags = AudioIoFlags::make<AudioIoFlags::Tag::input>(0); |
| 292 | AudioPortConfig mixPortConfig; |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 293 | Hal2AidlMapper::Cleanups cleanups(mMapperAccessor); |
Mikhail Naganov | e93a086 | 2023-03-15 17:06:59 -0700 | [diff] [blame] | 294 | AudioPatch aidlPatch; |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 295 | { |
| 296 | std::lock_guard l(mLock); |
| 297 | RETURN_STATUS_IF_ERROR(mMapper.prepareToOpenStream( |
| 298 | 0 /*handle*/, aidlDevice, aidlFlags, aidlSource, |
| 299 | &cleanups, &aidlConfig, &mixPortConfig, &aidlPatch)); |
| 300 | } |
Mikhail Naganov | d5b643f | 2024-02-15 11:51:26 -0800 | [diff] [blame] | 301 | *config = VALUE_OR_RETURN_STATUS( |
| 302 | ::aidl::android::aidl2legacy_AudioConfig_audio_config_t(aidlConfig, isInput)); |
| 303 | if (mixPortConfig.id == 0) return BAD_VALUE; // HAL suggests a different config. |
Mikhail Naganov | 89a9f74 | 2023-01-30 12:33:18 -0800 | [diff] [blame] | 304 | *size = aidlConfig.frameCount * |
| 305 | getFrameSizeInBytes(aidlConfig.base.format, aidlConfig.base.channelMask); |
| 306 | // Do not disarm cleanups to release temporary port configs. |
| 307 | return OK; |
| 308 | } |
| 309 | |
Mikhail Naganov | dfd594e | 2023-02-08 16:59:41 -0800 | [diff] [blame] | 310 | namespace { |
| 311 | |
| 312 | class StreamCallbackBase { |
| 313 | protected: |
| 314 | explicit StreamCallbackBase(const sp<CallbackBroker>& broker) : mBroker(broker) {} |
| 315 | public: |
| 316 | void* getCookie() const { return mCookie; } |
| 317 | void setCookie(void* cookie) { mCookie = cookie; } |
| 318 | sp<CallbackBroker> getBroker() const { |
| 319 | if (void* cookie = mCookie; cookie != nullptr) return mBroker.promote(); |
| 320 | return nullptr; |
| 321 | } |
| 322 | private: |
| 323 | const wp<CallbackBroker> mBroker; |
| 324 | std::atomic<void*> mCookie; |
| 325 | }; |
| 326 | |
| 327 | template<class C> |
| 328 | class StreamCallbackBaseHelper { |
| 329 | protected: |
| 330 | explicit StreamCallbackBaseHelper(const StreamCallbackBase& base) : mBase(base) {} |
| 331 | sp<C> getCb(const sp<CallbackBroker>& broker, void* cookie); |
| 332 | using CbRef = const sp<C>&; |
| 333 | ndk::ScopedAStatus runCb(const std::function<void(CbRef cb)>& f) { |
| 334 | if (auto cb = getCb(mBase.getBroker(), mBase.getCookie()); cb != nullptr) f(cb); |
| 335 | return ndk::ScopedAStatus::ok(); |
| 336 | } |
| 337 | private: |
| 338 | const StreamCallbackBase& mBase; |
| 339 | }; |
| 340 | |
| 341 | template<> |
| 342 | sp<StreamOutHalInterfaceCallback> StreamCallbackBaseHelper<StreamOutHalInterfaceCallback>::getCb( |
| 343 | const sp<CallbackBroker>& broker, void* cookie) { |
| 344 | if (broker != nullptr) return broker->getStreamOutCallback(cookie); |
| 345 | return nullptr; |
| 346 | } |
| 347 | |
| 348 | template<> |
| 349 | sp<StreamOutHalInterfaceEventCallback> |
| 350 | StreamCallbackBaseHelper<StreamOutHalInterfaceEventCallback>::getCb( |
| 351 | const sp<CallbackBroker>& broker, void* cookie) { |
| 352 | if (broker != nullptr) return broker->getStreamOutEventCallback(cookie); |
| 353 | return nullptr; |
| 354 | } |
| 355 | |
| 356 | template<> |
| 357 | sp<StreamOutHalInterfaceLatencyModeCallback> |
| 358 | StreamCallbackBaseHelper<StreamOutHalInterfaceLatencyModeCallback>::getCb( |
| 359 | const sp<CallbackBroker>& broker, void* cookie) { |
| 360 | if (broker != nullptr) return broker->getStreamOutLatencyModeCallback(cookie); |
| 361 | return nullptr; |
| 362 | } |
| 363 | |
| 364 | /* |
| 365 | Note on the callback ownership. |
| 366 | |
| 367 | In the Binder ownership model, the server implementation is kept alive |
| 368 | as long as there is any client (proxy object) alive. This is done by |
| 369 | incrementing the refcount of the server-side object by the Binder framework. |
| 370 | When it detects that the last client is gone, it decrements the refcount back. |
| 371 | |
| 372 | Thus, it is not needed to keep any references to StreamCallback on our |
| 373 | side (after we have sent an instance to the client), because we are |
| 374 | the server-side. The callback object will be kept alive as long as the HAL server |
| 375 | holds a strong ref to IStreamCallback proxy. |
| 376 | */ |
| 377 | |
| 378 | class OutputStreamCallbackAidl : public StreamCallbackBase, |
| 379 | public StreamCallbackBaseHelper<StreamOutHalInterfaceCallback>, |
| 380 | public ::aidl::android::hardware::audio::core::BnStreamCallback { |
| 381 | public: |
| 382 | explicit OutputStreamCallbackAidl(const sp<CallbackBroker>& broker) |
| 383 | : StreamCallbackBase(broker), |
| 384 | StreamCallbackBaseHelper<StreamOutHalInterfaceCallback>( |
| 385 | *static_cast<StreamCallbackBase*>(this)) {} |
| 386 | ndk::ScopedAStatus onTransferReady() override { |
| 387 | return runCb([](CbRef cb) { cb->onWriteReady(); }); |
| 388 | } |
| 389 | ndk::ScopedAStatus onError() override { |
Mikhail Naganov | bf203ce | 2024-05-23 16:27:59 -0700 | [diff] [blame^] | 390 | return runCb([](CbRef cb) { cb->onError(true /*isHardError*/); }); |
Mikhail Naganov | dfd594e | 2023-02-08 16:59:41 -0800 | [diff] [blame] | 391 | } |
| 392 | ndk::ScopedAStatus onDrainReady() override { |
| 393 | return runCb([](CbRef cb) { cb->onDrainReady(); }); |
| 394 | } |
| 395 | }; |
| 396 | |
| 397 | class OutputStreamEventCallbackAidl : |
| 398 | public StreamCallbackBase, |
| 399 | public StreamCallbackBaseHelper<StreamOutHalInterfaceEventCallback>, |
| 400 | public StreamCallbackBaseHelper<StreamOutHalInterfaceLatencyModeCallback>, |
| 401 | public ::aidl::android::hardware::audio::core::BnStreamOutEventCallback { |
| 402 | public: |
| 403 | explicit OutputStreamEventCallbackAidl(const sp<CallbackBroker>& broker) |
| 404 | : StreamCallbackBase(broker), |
| 405 | StreamCallbackBaseHelper<StreamOutHalInterfaceEventCallback>( |
| 406 | *static_cast<StreamCallbackBase*>(this)), |
| 407 | StreamCallbackBaseHelper<StreamOutHalInterfaceLatencyModeCallback>( |
| 408 | *static_cast<StreamCallbackBase*>(this)) {} |
Ryan Prichard | 78c5e45 | 2024-02-08 16:16:57 -0800 | [diff] [blame] | 409 | ndk::ScopedAStatus onCodecFormatChanged(const std::vector<uint8_t>& halMetadata) override { |
Mikhail Naganov | dfd594e | 2023-02-08 16:59:41 -0800 | [diff] [blame] | 410 | return StreamCallbackBaseHelper<StreamOutHalInterfaceEventCallback>::runCb( |
| 411 | [&halMetadata](auto cb) { cb->onCodecFormatChanged(halMetadata); }); |
| 412 | } |
| 413 | ndk::ScopedAStatus onRecommendedLatencyModeChanged( |
| 414 | const std::vector<AudioLatencyMode>& in_modes) override { |
| 415 | auto halModes = VALUE_OR_FATAL( |
| 416 | ::aidl::android::convertContainer<std::vector<audio_latency_mode_t>>( |
| 417 | in_modes, |
| 418 | ::aidl::android::aidl2legacy_AudioLatencyMode_audio_latency_mode_t)); |
| 419 | return StreamCallbackBaseHelper<StreamOutHalInterfaceLatencyModeCallback>::runCb( |
| 420 | [&halModes](auto cb) { cb->onRecommendedLatencyModeChanged(halModes); }); |
| 421 | } |
| 422 | }; |
| 423 | |
| 424 | } // namespace |
| 425 | |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 426 | status_t DeviceHalAidl::openOutputStream( |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 427 | audio_io_handle_t handle, audio_devices_t devices, |
| 428 | audio_output_flags_t flags, struct audio_config* config, |
| 429 | const char* address, |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 430 | sp<StreamOutHalInterface>* outStream) { |
Mikhail Naganov | 89a9f74 | 2023-01-30 12:33:18 -0800 | [diff] [blame] | 431 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 432 | TIME_CHECK(); |
| 433 | if (mModule == nullptr) return NO_INIT; |
| 434 | if (outStream == nullptr || config == nullptr) { |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 435 | return BAD_VALUE; |
| 436 | } |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 437 | constexpr bool isInput = false; |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 438 | int32_t aidlHandle = VALUE_OR_RETURN_STATUS( |
| 439 | ::aidl::android::legacy2aidl_audio_io_handle_t_int32_t(handle)); |
| 440 | AudioConfig aidlConfig = VALUE_OR_RETURN_STATUS( |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 441 | ::aidl::android::legacy2aidl_audio_config_t_AudioConfig(*config, isInput)); |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 442 | AudioDevice aidlDevice = VALUE_OR_RETURN_STATUS( |
| 443 | ::aidl::android::legacy2aidl_audio_device_AudioDevice(devices, address)); |
| 444 | int32_t aidlOutputFlags = VALUE_OR_RETURN_STATUS( |
| 445 | ::aidl::android::legacy2aidl_audio_output_flags_t_int32_t_mask(flags)); |
| 446 | AudioIoFlags aidlFlags = AudioIoFlags::make<AudioIoFlags::Tag::output>(aidlOutputFlags); |
| 447 | AudioPortConfig mixPortConfig; |
Mikhail Naganov | e93a086 | 2023-03-15 17:06:59 -0700 | [diff] [blame] | 448 | AudioPatch aidlPatch; |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 449 | Hal2AidlMapper::Cleanups cleanups(mMapperAccessor); |
| 450 | { |
| 451 | std::lock_guard l(mLock); |
| 452 | RETURN_STATUS_IF_ERROR(mMapper.prepareToOpenStream(aidlHandle, aidlDevice, aidlFlags, |
| 453 | AudioSource::SYS_RESERVED_INVALID /*only needed for input*/, |
| 454 | &cleanups, &aidlConfig, &mixPortConfig, &aidlPatch)); |
| 455 | } |
| 456 | *config = VALUE_OR_RETURN_STATUS( |
| 457 | ::aidl::android::aidl2legacy_AudioConfig_audio_config_t(aidlConfig, isInput)); |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 458 | if (mixPortConfig.id == 0) return BAD_VALUE; // HAL suggests a different config. |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 459 | ::aidl::android::hardware::audio::core::IModule::OpenOutputStreamArguments args; |
| 460 | args.portConfigId = mixPortConfig.id; |
Mikhail Naganov | dfd594e | 2023-02-08 16:59:41 -0800 | [diff] [blame] | 461 | const bool isOffload = isBitPositionFlagSet( |
| 462 | aidlOutputFlags, AudioOutputFlags::COMPRESS_OFFLOAD); |
| 463 | std::shared_ptr<OutputStreamCallbackAidl> streamCb; |
| 464 | if (isOffload) { |
| 465 | streamCb = ndk::SharedRefBase::make<OutputStreamCallbackAidl>(this); |
| 466 | } |
| 467 | auto eventCb = ndk::SharedRefBase::make<OutputStreamEventCallbackAidl>(this); |
| 468 | if (isOffload) { |
| 469 | args.offloadInfo = aidlConfig.offloadInfo; |
| 470 | args.callback = streamCb; |
| 471 | } |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 472 | args.bufferSizeFrames = aidlConfig.frameCount; |
Mikhail Naganov | dfd594e | 2023-02-08 16:59:41 -0800 | [diff] [blame] | 473 | args.eventCallback = eventCb; |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 474 | ::aidl::android::hardware::audio::core::IModule::OpenOutputStreamReturn ret; |
| 475 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mModule->openOutputStream(args, &ret))); |
Mikhail Naganov | 712d71b | 2023-02-23 17:57:16 -0800 | [diff] [blame] | 476 | StreamContextAidl context(ret.desc, isOffload); |
Mikhail Naganov | 89a9f74 | 2023-01-30 12:33:18 -0800 | [diff] [blame] | 477 | if (!context.isValid()) { |
| 478 | ALOGE("%s: Failed to created a valid stream context from the descriptor: %s", |
| 479 | __func__, ret.desc.toString().c_str()); |
| 480 | return NO_INIT; |
| 481 | } |
Mikhail Naganov | 8065bfd | 2024-03-25 14:59:49 -0700 | [diff] [blame] | 482 | auto stream = sp<StreamOutHalAidl>::make(*config, std::move(context), aidlPatch.latenciesMs[0], |
Mikhail Naganov | e7a26ad | 2023-05-25 17:36:48 -0700 | [diff] [blame] | 483 | std::move(ret.stream), mVendorExt, this /*callbackBroker*/); |
Mikhail Naganov | 8065bfd | 2024-03-25 14:59:49 -0700 | [diff] [blame] | 484 | *outStream = stream; |
| 485 | /* StreamOutHalInterface* */ void* cbCookie = (*outStream).get(); |
Mikhail Naganov | dfd594e | 2023-02-08 16:59:41 -0800 | [diff] [blame] | 486 | { |
| 487 | std::lock_guard l(mLock); |
| 488 | mCallbacks.emplace(cbCookie, Callbacks{}); |
Mikhail Naganov | 78f7f9a | 2023-11-16 15:49:23 -0800 | [diff] [blame] | 489 | mMapper.addStream(*outStream, mixPortConfig.id, aidlPatch.id); |
Mikhail Naganov | dfd594e | 2023-02-08 16:59:41 -0800 | [diff] [blame] | 490 | } |
Mikhail Naganov | 8065bfd | 2024-03-25 14:59:49 -0700 | [diff] [blame] | 491 | if (streamCb) { |
| 492 | streamCb->setCookie(cbCookie); |
| 493 | // Although StreamOutHalAidl implements StreamOutHalInterfaceCallback, |
| 494 | // we always go via the CallbackBroker for consistency. |
| 495 | setStreamOutCallback(cbCookie, stream); |
| 496 | } |
Mikhail Naganov | dfd594e | 2023-02-08 16:59:41 -0800 | [diff] [blame] | 497 | eventCb->setCookie(cbCookie); |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 498 | cleanups.disarmAll(); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 499 | return OK; |
| 500 | } |
| 501 | |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 502 | status_t DeviceHalAidl::openInputStream( |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 503 | audio_io_handle_t handle, audio_devices_t devices, |
| 504 | struct audio_config* config, audio_input_flags_t flags, |
| 505 | const char* address, audio_source_t source, |
| 506 | audio_devices_t outputDevice, const char* outputDeviceAddress, |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 507 | sp<StreamInHalInterface>* inStream) { |
Mikhail Naganov | 89a9f74 | 2023-01-30 12:33:18 -0800 | [diff] [blame] | 508 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 509 | TIME_CHECK(); |
| 510 | if (mModule == nullptr) return NO_INIT; |
| 511 | if (inStream == nullptr || config == nullptr) { |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 512 | return BAD_VALUE; |
| 513 | } |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 514 | constexpr bool isInput = true; |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 515 | int32_t aidlHandle = VALUE_OR_RETURN_STATUS( |
| 516 | ::aidl::android::legacy2aidl_audio_io_handle_t_int32_t(handle)); |
| 517 | AudioConfig aidlConfig = VALUE_OR_RETURN_STATUS( |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 518 | ::aidl::android::legacy2aidl_audio_config_t_AudioConfig(*config, isInput)); |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 519 | AudioDevice aidlDevice = VALUE_OR_RETURN_STATUS( |
| 520 | ::aidl::android::legacy2aidl_audio_device_AudioDevice(devices, address)); |
| 521 | int32_t aidlInputFlags = VALUE_OR_RETURN_STATUS( |
| 522 | ::aidl::android::legacy2aidl_audio_input_flags_t_int32_t_mask(flags)); |
| 523 | AudioIoFlags aidlFlags = AudioIoFlags::make<AudioIoFlags::Tag::input>(aidlInputFlags); |
| 524 | AudioSource aidlSource = VALUE_OR_RETURN_STATUS( |
| 525 | ::aidl::android::legacy2aidl_audio_source_t_AudioSource(source)); |
| 526 | AudioPortConfig mixPortConfig; |
Mikhail Naganov | e93a086 | 2023-03-15 17:06:59 -0700 | [diff] [blame] | 527 | AudioPatch aidlPatch; |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 528 | Hal2AidlMapper::Cleanups cleanups(mMapperAccessor); |
| 529 | { |
| 530 | std::lock_guard l(mLock); |
| 531 | RETURN_STATUS_IF_ERROR(mMapper.prepareToOpenStream( |
| 532 | aidlHandle, aidlDevice, aidlFlags, aidlSource, |
| 533 | &cleanups, &aidlConfig, &mixPortConfig, &aidlPatch)); |
| 534 | } |
| 535 | *config = VALUE_OR_RETURN_STATUS( |
| 536 | ::aidl::android::aidl2legacy_AudioConfig_audio_config_t(aidlConfig, isInput)); |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 537 | if (mixPortConfig.id == 0) return BAD_VALUE; // HAL suggests a different config. |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 538 | ::aidl::android::hardware::audio::core::IModule::OpenInputStreamArguments args; |
| 539 | args.portConfigId = mixPortConfig.id; |
| 540 | RecordTrackMetadata aidlTrackMetadata{ |
| 541 | .source = aidlSource, .gain = 1, .channelMask = aidlConfig.base.channelMask }; |
| 542 | if (outputDevice != AUDIO_DEVICE_NONE) { |
| 543 | aidlTrackMetadata.destinationDevice = VALUE_OR_RETURN_STATUS( |
| 544 | ::aidl::android::legacy2aidl_audio_device_AudioDevice( |
| 545 | outputDevice, outputDeviceAddress)); |
| 546 | } |
| 547 | args.sinkMetadata.tracks.push_back(std::move(aidlTrackMetadata)); |
| 548 | args.bufferSizeFrames = aidlConfig.frameCount; |
| 549 | ::aidl::android::hardware::audio::core::IModule::OpenInputStreamReturn ret; |
| 550 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mModule->openInputStream(args, &ret))); |
Mikhail Naganov | 712d71b | 2023-02-23 17:57:16 -0800 | [diff] [blame] | 551 | StreamContextAidl context(ret.desc, false /*isAsynchronous*/); |
Mikhail Naganov | 89a9f74 | 2023-01-30 12:33:18 -0800 | [diff] [blame] | 552 | if (!context.isValid()) { |
| 553 | ALOGE("%s: Failed to created a valid stream context from the descriptor: %s", |
| 554 | __func__, ret.desc.toString().c_str()); |
| 555 | return NO_INIT; |
| 556 | } |
Mikhail Naganov | e93a086 | 2023-03-15 17:06:59 -0700 | [diff] [blame] | 557 | *inStream = sp<StreamInHalAidl>::make(*config, std::move(context), aidlPatch.latenciesMs[0], |
Mikhail Naganov | e7a26ad | 2023-05-25 17:36:48 -0700 | [diff] [blame] | 558 | std::move(ret.stream), mVendorExt, this /*micInfoProvider*/); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 559 | { |
| 560 | std::lock_guard l(mLock); |
Mikhail Naganov | 78f7f9a | 2023-11-16 15:49:23 -0800 | [diff] [blame] | 561 | mMapper.addStream(*inStream, mixPortConfig.id, aidlPatch.id); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 562 | } |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 563 | cleanups.disarmAll(); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 564 | return OK; |
| 565 | } |
| 566 | |
| 567 | status_t DeviceHalAidl::supportsAudioPatches(bool* supportsPatches) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 568 | if (supportsPatches == nullptr) { |
| 569 | return BAD_VALUE; |
| 570 | } |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 571 | *supportsPatches = true; |
| 572 | return OK; |
| 573 | } |
| 574 | |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 575 | status_t DeviceHalAidl::createAudioPatch(unsigned int num_sources, |
| 576 | const struct audio_port_config* sources, |
| 577 | unsigned int num_sinks, |
| 578 | const struct audio_port_config* sinks, |
| 579 | audio_patch_handle_t* patch) { |
Mikhail Naganov | 89a9f74 | 2023-01-30 12:33:18 -0800 | [diff] [blame] | 580 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 581 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 582 | if (mModule == nullptr) return NO_INIT; |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 583 | if (num_sinks > AUDIO_PATCH_PORTS_MAX || num_sources > AUDIO_PATCH_PORTS_MAX || |
| 584 | sources == nullptr || sinks == nullptr || patch == nullptr) { |
| 585 | return BAD_VALUE; |
| 586 | } |
Mikhail Naganov | 47d1d73 | 2023-02-23 15:16:04 -0800 | [diff] [blame] | 587 | // When the patch handle (*patch) is AUDIO_PATCH_HANDLE_NONE, it means |
| 588 | // the framework wants to create a new patch. The handle has to be generated |
| 589 | // by the HAL. Since handles generated this way can only be unique within |
| 590 | // a HAL module, the framework generates a globally unique handle, and maps |
| 591 | // it on the <HAL module, patch handle> pair. |
| 592 | // When the patch handle is set, it meant the framework intends to update |
| 593 | // an existing patch. |
| 594 | // |
| 595 | // This behavior corresponds to HAL module behavior, with the only difference |
| 596 | // that the HAL module uses `int32_t` for patch IDs. The following assert ensures |
| 597 | // that both the framework and the HAL use the same value for "no ID": |
| 598 | static_assert(AUDIO_PATCH_HANDLE_NONE == 0); |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 599 | |
| 600 | // Upon conversion, mix port configs contain audio configuration, while |
| 601 | // device port configs contain device address. This data is used to find |
| 602 | // or create HAL configs. |
| 603 | std::vector<AudioPortConfig> aidlSources, aidlSinks; |
| 604 | for (unsigned int i = 0; i < num_sources; ++i) { |
| 605 | bool isInput = VALUE_OR_RETURN_STATUS(::aidl::android::portDirection( |
| 606 | sources[i].role, sources[i].type)) == |
| 607 | ::aidl::android::AudioPortDirection::INPUT; |
| 608 | aidlSources.push_back(VALUE_OR_RETURN_STATUS( |
| 609 | ::aidl::android::legacy2aidl_audio_port_config_AudioPortConfig( |
| 610 | sources[i], isInput, 0))); |
| 611 | } |
| 612 | for (unsigned int i = 0; i < num_sinks; ++i) { |
| 613 | bool isInput = VALUE_OR_RETURN_STATUS(::aidl::android::portDirection( |
| 614 | sinks[i].role, sinks[i].type)) == |
| 615 | ::aidl::android::AudioPortDirection::INPUT; |
| 616 | aidlSinks.push_back(VALUE_OR_RETURN_STATUS( |
| 617 | ::aidl::android::legacy2aidl_audio_port_config_AudioPortConfig( |
| 618 | sinks[i], isInput, 0))); |
| 619 | } |
Mikhail Naganov | 6b5da72 | 2024-03-14 12:59:32 -0700 | [diff] [blame] | 620 | int32_t aidlPatchId = static_cast<int32_t>(*patch); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 621 | Hal2AidlMapper::Cleanups cleanups(mMapperAccessor); |
| 622 | { |
| 623 | std::lock_guard l(mLock); |
Mikhail Naganov | 6b5da72 | 2024-03-14 12:59:32 -0700 | [diff] [blame] | 624 | // Check for patches that only exist for the framework, or have different HAL patch ID. |
| 625 | if (int32_t aidlHalPatchId = mMapper.findFwkPatch(aidlPatchId); aidlHalPatchId != 0) { |
| 626 | if (aidlHalPatchId == aidlPatchId) { |
| 627 | // This patch was previously released by the HAL. Thus we need to pass '0' |
| 628 | // to the HAL to obtain a new patch. |
| 629 | int32_t newAidlPatchId = 0; |
| 630 | RETURN_STATUS_IF_ERROR(mMapper.createOrUpdatePatch( |
| 631 | aidlSources, aidlSinks, &newAidlPatchId, &cleanups)); |
| 632 | mMapper.updateFwkPatch(aidlPatchId, newAidlPatchId); |
| 633 | } else { |
| 634 | RETURN_STATUS_IF_ERROR(mMapper.createOrUpdatePatch( |
| 635 | aidlSources, aidlSinks, &aidlHalPatchId, &cleanups)); |
| 636 | } |
| 637 | } else { |
| 638 | RETURN_STATUS_IF_ERROR(mMapper.createOrUpdatePatch( |
| 639 | aidlSources, aidlSinks, &aidlPatchId, &cleanups)); |
| 640 | } |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 641 | } |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 642 | *patch = static_cast<audio_patch_handle_t>(aidlPatchId); |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 643 | cleanups.disarmAll(); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 644 | return OK; |
| 645 | } |
| 646 | |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 647 | status_t DeviceHalAidl::releaseAudioPatch(audio_patch_handle_t patch) { |
Mikhail Naganov | 89a9f74 | 2023-01-30 12:33:18 -0800 | [diff] [blame] | 648 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 649 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 650 | if (mModule == nullptr) return NO_INIT; |
Mikhail Naganov | 47d1d73 | 2023-02-23 15:16:04 -0800 | [diff] [blame] | 651 | static_assert(AUDIO_PATCH_HANDLE_NONE == 0); |
| 652 | if (patch == AUDIO_PATCH_HANDLE_NONE) { |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame] | 653 | return BAD_VALUE; |
| 654 | } |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 655 | std::lock_guard l(mLock); |
Mikhail Naganov | 6b5da72 | 2024-03-14 12:59:32 -0700 | [diff] [blame] | 656 | // Check for patches that only exist for the framework, or have different HAL patch ID. |
| 657 | int32_t aidlPatchId = static_cast<int32_t>(patch); |
| 658 | if (int32_t aidlHalPatchId = mMapper.findFwkPatch(aidlPatchId); aidlHalPatchId != 0) { |
| 659 | if (aidlHalPatchId == aidlPatchId) { |
| 660 | // This patch was previously released by the HAL, just need to finish its removal. |
| 661 | mMapper.eraseFwkPatch(aidlPatchId); |
| 662 | return OK; |
| 663 | } else { |
| 664 | // This patch has a HAL patch ID which is different |
| 665 | aidlPatchId = aidlHalPatchId; |
| 666 | } |
| 667 | } |
| 668 | RETURN_STATUS_IF_ERROR(mMapper.releaseAudioPatch(aidlPatchId)); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 669 | return OK; |
| 670 | } |
| 671 | |
Mikhail Naganov | e93a086 | 2023-03-15 17:06:59 -0700 | [diff] [blame] | 672 | status_t DeviceHalAidl::getAudioPort(struct audio_port* port) { |
Mikhail Naganov | e93a086 | 2023-03-15 17:06:59 -0700 | [diff] [blame] | 673 | if (port == nullptr) { |
| 674 | return BAD_VALUE; |
| 675 | } |
| 676 | audio_port_v7 portV7; |
| 677 | audio_populate_audio_port_v7(port, &portV7); |
| 678 | RETURN_STATUS_IF_ERROR(getAudioPort(&portV7)); |
| 679 | return audio_populate_audio_port(&portV7, port) ? OK : BAD_VALUE; |
| 680 | } |
| 681 | |
| 682 | status_t DeviceHalAidl::getAudioPort(struct audio_port_v7 *port) { |
| 683 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
| 684 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 685 | if (mModule == nullptr) return NO_INIT; |
Mikhail Naganov | e93a086 | 2023-03-15 17:06:59 -0700 | [diff] [blame] | 686 | if (port == nullptr) { |
| 687 | return BAD_VALUE; |
| 688 | } |
| 689 | bool isInput = VALUE_OR_RETURN_STATUS(::aidl::android::portDirection(port->role, port->type)) == |
| 690 | ::aidl::android::AudioPortDirection::INPUT; |
| 691 | auto aidlPort = VALUE_OR_RETURN_STATUS( |
| 692 | ::aidl::android::legacy2aidl_audio_port_v7_AudioPort(*port, isInput)); |
| 693 | if (aidlPort.ext.getTag() != AudioPortExt::device) { |
| 694 | ALOGE("%s: provided port is not a device port (module %s): %s", |
| 695 | __func__, mInstance.c_str(), aidlPort.toString().c_str()); |
| 696 | return BAD_VALUE; |
| 697 | } |
| 698 | const auto& matchDevice = aidlPort.ext.get<AudioPortExt::device>().device; |
| 699 | // It seems that we don't have to call HAL since all valid ports have been added either |
| 700 | // during initialization, or while handling connection of an external device. |
Mikhail Naganov | e93a086 | 2023-03-15 17:06:59 -0700 | [diff] [blame] | 701 | const int32_t fwkId = aidlPort.id; |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 702 | { |
| 703 | std::lock_guard l(mLock); |
| 704 | RETURN_STATUS_IF_ERROR(mMapper.getAudioPortCached(matchDevice, &aidlPort)); |
| 705 | } |
Mikhail Naganov | e93a086 | 2023-03-15 17:06:59 -0700 | [diff] [blame] | 706 | aidlPort.id = fwkId; |
| 707 | *port = VALUE_OR_RETURN_STATUS(::aidl::android::aidl2legacy_AudioPort_audio_port_v7( |
| 708 | aidlPort, isInput)); |
| 709 | return OK; |
| 710 | } |
| 711 | |
jiabin | 12537fc | 2023-10-12 17:56:08 +0000 | [diff] [blame] | 712 | status_t DeviceHalAidl::getAudioMixPort(const struct audio_port_v7 *devicePort, |
| 713 | struct audio_port_v7 *mixPort) { |
| 714 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 715 | TIME_CHECK(); |
| 716 | if (mModule == nullptr) return NO_INIT; |
| 717 | if (devicePort == nullptr || mixPort == nullptr || |
| 718 | devicePort->type != AUDIO_PORT_TYPE_DEVICE || mixPort->type != AUDIO_PORT_TYPE_MIX) { |
jiabin | 12537fc | 2023-10-12 17:56:08 +0000 | [diff] [blame] | 719 | return BAD_VALUE; |
| 720 | } |
| 721 | const int32_t aidlHandle = VALUE_OR_RETURN_STATUS( |
| 722 | ::aidl::android::legacy2aidl_audio_io_handle_t_int32_t(mixPort->ext.mix.handle)); |
jiabin | 12537fc | 2023-10-12 17:56:08 +0000 | [diff] [blame] | 723 | AudioPort port; |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 724 | { |
| 725 | std::lock_guard l(mLock); |
| 726 | RETURN_STATUS_IF_ERROR(mMapper.getAudioMixPort(aidlHandle, &port)); |
jiabin | 12537fc | 2023-10-12 17:56:08 +0000 | [diff] [blame] | 727 | } |
| 728 | const bool isInput = VALUE_OR_RETURN_STATUS(::aidl::android::portDirection( |
| 729 | mixPort->role, mixPort->type)) == ::aidl::android::AudioPortDirection::INPUT; |
| 730 | *mixPort = VALUE_OR_RETURN_STATUS(::aidl::android::aidl2legacy_AudioPort_audio_port_v7( |
| 731 | port, isInput)); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 732 | return OK; |
jiabin | 12537fc | 2023-10-12 17:56:08 +0000 | [diff] [blame] | 733 | } |
| 734 | |
Mikhail Naganov | e93a086 | 2023-03-15 17:06:59 -0700 | [diff] [blame] | 735 | status_t DeviceHalAidl::setAudioPortConfig(const struct audio_port_config* config) { |
| 736 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
| 737 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 738 | if (mModule == nullptr) return NO_INIT; |
Mikhail Naganov | e93a086 | 2023-03-15 17:06:59 -0700 | [diff] [blame] | 739 | if (config == nullptr) { |
| 740 | return BAD_VALUE; |
| 741 | } |
| 742 | bool isInput = VALUE_OR_RETURN_STATUS(::aidl::android::portDirection( |
| 743 | config->role, config->type)) == ::aidl::android::AudioPortDirection::INPUT; |
| 744 | AudioPortConfig requestedPortConfig = VALUE_OR_RETURN_STATUS( |
| 745 | ::aidl::android::legacy2aidl_audio_port_config_AudioPortConfig( |
| 746 | *config, isInput, 0 /*portId*/)); |
| 747 | AudioPortConfig portConfig; |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 748 | std::lock_guard l(mLock); |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 749 | return mMapper.setPortConfig(requestedPortConfig, std::set<int32_t>(), &portConfig); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 750 | } |
| 751 | |
Mikhail Naganov | cad0afe | 2023-03-10 14:25:57 -0800 | [diff] [blame] | 752 | MicrophoneInfoProvider::Info const* DeviceHalAidl::getMicrophoneInfo() { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 753 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
| 754 | TIME_CHECK(); |
| 755 | if (!mModule) return {}; |
| 756 | std::lock_guard l(mLock); |
Mikhail Naganov | cad0afe | 2023-03-10 14:25:57 -0800 | [diff] [blame] | 757 | if (mMicrophones.status == Microphones::Status::UNKNOWN) { |
| 758 | TIME_CHECK(); |
| 759 | std::vector<MicrophoneInfo> aidlInfo; |
| 760 | status_t status = statusTFromBinderStatus(mModule->getMicrophones(&aidlInfo)); |
| 761 | if (status == OK) { |
| 762 | mMicrophones.status = Microphones::Status::QUERIED; |
| 763 | mMicrophones.info = std::move(aidlInfo); |
| 764 | } else if (status == INVALID_OPERATION) { |
| 765 | mMicrophones.status = Microphones::Status::NOT_SUPPORTED; |
| 766 | } else { |
| 767 | ALOGE("%s: Unexpected status from 'IModule.getMicrophones': %d", __func__, status); |
| 768 | return {}; |
| 769 | } |
| 770 | } |
| 771 | if (mMicrophones.status == Microphones::Status::QUERIED) { |
| 772 | return &mMicrophones.info; |
| 773 | } |
| 774 | return {}; // NOT_SUPPORTED |
| 775 | } |
| 776 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 777 | status_t DeviceHalAidl::getMicrophones( |
Mikhail Naganov | cad0afe | 2023-03-10 14:25:57 -0800 | [diff] [blame] | 778 | std::vector<audio_microphone_characteristic_t>* microphones) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 779 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
| 780 | TIME_CHECK(); |
| 781 | if (mModule == nullptr) return NO_INIT; |
| 782 | if (microphones == nullptr) { |
Mikhail Naganov | cad0afe | 2023-03-10 14:25:57 -0800 | [diff] [blame] | 783 | return BAD_VALUE; |
| 784 | } |
Mikhail Naganov | cad0afe | 2023-03-10 14:25:57 -0800 | [diff] [blame] | 785 | auto staticInfo = getMicrophoneInfo(); |
| 786 | if (!staticInfo) return INVALID_OPERATION; |
| 787 | std::vector<MicrophoneDynamicInfo> emptyDynamicInfo; |
| 788 | emptyDynamicInfo.reserve(staticInfo->size()); |
| 789 | std::transform(staticInfo->begin(), staticInfo->end(), std::back_inserter(emptyDynamicInfo), |
| 790 | [](const auto& info) { return MicrophoneDynamicInfo{ .id = info.id }; }); |
| 791 | *microphones = VALUE_OR_RETURN_STATUS( |
| 792 | ::aidl::android::convertContainers<std::vector<audio_microphone_characteristic_t>>( |
| 793 | *staticInfo, emptyDynamicInfo, |
| 794 | ::aidl::android::aidl2legacy_MicrophoneInfos_audio_microphone_characteristic_t) |
| 795 | ); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 796 | return OK; |
| 797 | } |
| 798 | |
Mikhail Naganov | a82a69d | 2023-06-14 16:31:32 -0700 | [diff] [blame] | 799 | status_t DeviceHalAidl::addDeviceEffect( |
| 800 | const struct audio_port_config *device, sp<EffectHalInterface> effect) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 801 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | a82a69d | 2023-06-14 16:31:32 -0700 | [diff] [blame] | 802 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 803 | if (mModule == nullptr) return NO_INIT; |
| 804 | if (device == nullptr || effect == nullptr) { |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 805 | return BAD_VALUE; |
| 806 | } |
Mikhail Naganov | a82a69d | 2023-06-14 16:31:32 -0700 | [diff] [blame] | 807 | bool isInput = VALUE_OR_RETURN_STATUS(::aidl::android::portDirection( |
| 808 | device->role, device->type)) == ::aidl::android::AudioPortDirection::INPUT; |
| 809 | auto requestedPortConfig = VALUE_OR_RETURN_STATUS( |
| 810 | ::aidl::android::legacy2aidl_audio_port_config_AudioPortConfig( |
| 811 | *device, isInput, 0)); |
| 812 | if (requestedPortConfig.ext.getTag() != AudioPortExt::Tag::device) { |
| 813 | ALOGE("%s: provided port config is not a device port config: %s", |
| 814 | __func__, requestedPortConfig.toString().c_str()); |
| 815 | return BAD_VALUE; |
| 816 | } |
| 817 | AudioPortConfig devicePortConfig; |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 818 | Hal2AidlMapper::Cleanups cleanups(mMapperAccessor); |
| 819 | { |
| 820 | std::lock_guard l(mLock); |
Mikhail Naganov | ca92a5c | 2023-12-07 14:00:48 -0800 | [diff] [blame] | 821 | RETURN_STATUS_IF_ERROR(mMapper.setPortConfig( |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 822 | requestedPortConfig, {} /*destinationPortIds*/, &devicePortConfig, &cleanups)); |
Mikhail Naganov | a82a69d | 2023-06-14 16:31:32 -0700 | [diff] [blame] | 823 | } |
| 824 | auto aidlEffect = sp<effect::EffectHalAidl>::cast(effect); |
| 825 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mModule->addDeviceEffect( |
| 826 | devicePortConfig.id, aidlEffect->getIEffect()))); |
| 827 | cleanups.disarmAll(); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 828 | return OK; |
| 829 | } |
Mikhail Naganov | a82a69d | 2023-06-14 16:31:32 -0700 | [diff] [blame] | 830 | status_t DeviceHalAidl::removeDeviceEffect( |
| 831 | const struct audio_port_config *device, sp<EffectHalInterface> effect) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 832 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | a82a69d | 2023-06-14 16:31:32 -0700 | [diff] [blame] | 833 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 834 | if (mModule == nullptr) return NO_INIT; |
| 835 | if (device == nullptr || effect == nullptr) { |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 836 | return BAD_VALUE; |
| 837 | } |
Mikhail Naganov | a82a69d | 2023-06-14 16:31:32 -0700 | [diff] [blame] | 838 | bool isInput = VALUE_OR_RETURN_STATUS(::aidl::android::portDirection( |
| 839 | device->role, device->type)) == ::aidl::android::AudioPortDirection::INPUT; |
| 840 | auto requestedPortConfig = VALUE_OR_RETURN_STATUS( |
| 841 | ::aidl::android::legacy2aidl_audio_port_config_AudioPortConfig( |
| 842 | *device, isInput, 0)); |
| 843 | if (requestedPortConfig.ext.getTag() != AudioPortExt::Tag::device) { |
| 844 | ALOGE("%s: provided port config is not a device port config: %s", |
| 845 | __func__, requestedPortConfig.toString().c_str()); |
| 846 | return BAD_VALUE; |
| 847 | } |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 848 | AudioPortConfig devicePortConfig; |
| 849 | { |
| 850 | std::lock_guard l(mLock); |
| 851 | RETURN_STATUS_IF_ERROR(mMapper.findPortConfig( |
| 852 | requestedPortConfig.ext.get<AudioPortExt::Tag::device>().device, |
| 853 | &devicePortConfig)); |
Mikhail Naganov | a82a69d | 2023-06-14 16:31:32 -0700 | [diff] [blame] | 854 | } |
| 855 | auto aidlEffect = sp<effect::EffectHalAidl>::cast(effect); |
| 856 | return statusTFromBinderStatus(mModule->removeDeviceEffect( |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 857 | devicePortConfig.id, aidlEffect->getIEffect())); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | status_t DeviceHalAidl::getMmapPolicyInfos( |
David Li | 9cf5e62 | 2023-03-21 00:51:10 +0800 | [diff] [blame] | 861 | media::audio::common::AudioMMapPolicyType policyType, |
| 862 | std::vector<media::audio::common::AudioMMapPolicyInfo>* policyInfos) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 863 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 864 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 865 | if (mModule == nullptr) return NO_INIT; |
Mikhail Naganov | 25bc9a2 | 2023-04-21 18:48:16 -0700 | [diff] [blame] | 866 | AudioMMapPolicyType mmapPolicyType = VALUE_OR_RETURN_STATUS( |
| 867 | cpp2ndk_AudioMMapPolicyType(policyType)); |
David Li | 9cf5e62 | 2023-03-21 00:51:10 +0800 | [diff] [blame] | 868 | |
| 869 | std::vector<AudioMMapPolicyInfo> mmapPolicyInfos; |
| 870 | |
| 871 | if (status_t status = statusTFromBinderStatus( |
| 872 | mModule->getMmapPolicyInfos(mmapPolicyType, &mmapPolicyInfos)); status != OK) { |
| 873 | return status; |
| 874 | } |
| 875 | |
| 876 | *policyInfos = VALUE_OR_RETURN_STATUS( |
| 877 | convertContainer<std::vector<media::audio::common::AudioMMapPolicyInfo>>( |
| 878 | mmapPolicyInfos, ndk2cpp_AudioMMapPolicyInfo)); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 879 | return OK; |
| 880 | } |
| 881 | |
| 882 | int32_t DeviceHalAidl::getAAudioMixerBurstCount() { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 883 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 884 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 885 | if (mModule == nullptr) return NO_INIT; |
David Li | 9cf5e62 | 2023-03-21 00:51:10 +0800 | [diff] [blame] | 886 | int32_t mixerBurstCount = 0; |
| 887 | if (mModule->getAAudioMixerBurstCount(&mixerBurstCount).isOk()) { |
| 888 | return mixerBurstCount; |
| 889 | } |
| 890 | return 0; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | int32_t DeviceHalAidl::getAAudioHardwareBurstMinUsec() { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 894 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 895 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 896 | if (mModule == nullptr) return NO_INIT; |
David Li | 9cf5e62 | 2023-03-21 00:51:10 +0800 | [diff] [blame] | 897 | int32_t hardwareBurstMinUsec = 0; |
| 898 | if (mModule->getAAudioHardwareBurstMinUsec(&hardwareBurstMinUsec).isOk()) { |
| 899 | return hardwareBurstMinUsec; |
| 900 | } |
| 901 | return 0; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | error::Result<audio_hw_sync_t> DeviceHalAidl::getHwAvSync() { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 905 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 906 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 907 | if (mModule == nullptr) return NO_INIT; |
Mikhail Naganov | 08a62ab | 2023-03-14 17:11:51 -0700 | [diff] [blame] | 908 | int32_t aidlHwAvSync; |
| 909 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mModule->generateHwAvSyncId(&aidlHwAvSync))); |
| 910 | return VALUE_OR_RETURN_STATUS( |
| 911 | ::aidl::android::aidl2legacy_int32_t_audio_hw_sync_t(aidlHwAvSync)); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 912 | } |
| 913 | |
Mikhail Naganov | fab697c | 2023-01-11 19:33:13 +0000 | [diff] [blame] | 914 | status_t DeviceHalAidl::dump(int fd, const Vector<String16>& args) { |
| 915 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 916 | if (mModule == nullptr) return NO_INIT; |
David Li | 2128946 | 2024-04-17 01:09:23 +0800 | [diff] [blame] | 917 | Vector<String16> newArgs = args; |
| 918 | newArgs.push(String16(kDumpFromAudioServerArgument)); |
| 919 | return mModule->dump(fd, Args(newArgs).args(), newArgs.size()); |
David Li | 9cf5e62 | 2023-03-21 00:51:10 +0800 | [diff] [blame] | 920 | } |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 921 | |
Eric Laurent | 7af6ee7 | 2023-06-29 11:44:54 +0200 | [diff] [blame] | 922 | status_t DeviceHalAidl::supportsBluetoothVariableLatency(bool* supports) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 923 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 924 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 925 | if (mModule == nullptr) return NO_INIT; |
Mikhail Naganov | 3ac95c9 | 2023-04-12 13:14:30 -0700 | [diff] [blame] | 926 | if (supports == nullptr) { |
| 927 | return BAD_VALUE; |
| 928 | } |
| 929 | return statusTFromBinderStatus(mModule->supportsVariableLatency(supports)); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 930 | } |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 931 | |
Vlad Popa | 03bd5bc | 2023-01-17 16:16:51 +0100 | [diff] [blame] | 932 | status_t DeviceHalAidl::getSoundDoseInterface(const std::string& module, |
| 933 | ::ndk::SpAIBinder* soundDoseBinder) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 934 | if (soundDoseBinder == nullptr) { |
| 935 | return BAD_VALUE; |
| 936 | } |
Vlad Popa | 03bd5bc | 2023-01-17 16:16:51 +0100 | [diff] [blame] | 937 | if (mSoundDose == nullptr) { |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 938 | ALOGE("%s failed to retrieve the sound dose interface for module %s", |
| 939 | __func__, module.c_str()); |
| 940 | return BAD_VALUE; |
Vlad Popa | 03bd5bc | 2023-01-17 16:16:51 +0100 | [diff] [blame] | 941 | } |
Vlad Popa | e1f3390 | 2023-10-30 19:48:25 -0700 | [diff] [blame] | 942 | |
| 943 | if (mSoundDose == nullptr) { |
| 944 | ALOGE("%s failed to return the sound dose interface for module %s: not implemented", |
| 945 | __func__, |
| 946 | module.c_str()); |
| 947 | return NO_INIT; |
| 948 | } |
| 949 | |
Vlad Popa | 03bd5bc | 2023-01-17 16:16:51 +0100 | [diff] [blame] | 950 | *soundDoseBinder = mSoundDose->asBinder(); |
| 951 | ALOGI("%s using audio AIDL HAL sound dose interface", __func__); |
Vlad Popa | 03bd5bc | 2023-01-17 16:16:51 +0100 | [diff] [blame] | 952 | return OK; |
| 953 | } |
jiabin | 872de70 | 2023-04-27 22:04:31 +0000 | [diff] [blame] | 954 | |
| 955 | status_t DeviceHalAidl::prepareToDisconnectExternalDevice(const struct audio_port_v7* port) { |
jiabin | 62750c2 | 2023-12-21 22:06:07 +0000 | [diff] [blame] | 956 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
| 957 | TIME_CHECK(); |
| 958 | if (mModule == nullptr) return NO_INIT; |
| 959 | if (port == nullptr) { |
| 960 | return BAD_VALUE; |
| 961 | } |
| 962 | const bool isInput = VALUE_OR_RETURN_STATUS( |
| 963 | ::aidl::android::portDirection(port->role, port->type)) == |
| 964 | ::aidl::android::AudioPortDirection::INPUT; |
| 965 | AudioPort aidlPort = VALUE_OR_RETURN_STATUS( |
| 966 | ::aidl::android::legacy2aidl_audio_port_v7_AudioPort(*port, isInput)); |
| 967 | if (aidlPort.ext.getTag() != AudioPortExt::device) { |
| 968 | ALOGE("%s: provided port is not a device port (module %s): %s", |
| 969 | __func__, mInstance.c_str(), aidlPort.toString().c_str()); |
| 970 | return BAD_VALUE; |
| 971 | } |
| 972 | status_t status = NO_ERROR; |
| 973 | { |
| 974 | std::lock_guard l(mLock); |
| 975 | status = mMapper.prepareToDisconnectExternalDevice(aidlPort); |
| 976 | } |
| 977 | if (status == UNKNOWN_TRANSACTION) { |
| 978 | // If there is not AIDL API defined for `prepareToDisconnectExternalDevice`. |
| 979 | // Call `setConnectedState` instead. |
| 980 | RETURN_STATUS_IF_ERROR(setConnectedState(port, false /*connected*/)); |
| 981 | std::lock_guard l(mLock); |
| 982 | mDeviceDisconnectionNotified.insert(port->id); |
| 983 | // Return that there was no error as otherwise the disconnection procedure will not be |
| 984 | // considered complete for upper layers, and 'setConnectedState' will not be called again |
| 985 | return OK; |
| 986 | } else { |
| 987 | return status; |
| 988 | } |
jiabin | 872de70 | 2023-04-27 22:04:31 +0000 | [diff] [blame] | 989 | } |
| 990 | |
Mikhail Naganov | e93a086 | 2023-03-15 17:06:59 -0700 | [diff] [blame] | 991 | status_t DeviceHalAidl::setConnectedState(const struct audio_port_v7 *port, bool connected) { |
Mikhail Naganov | ae9063d | 2023-11-07 16:43:51 -0800 | [diff] [blame] | 992 | ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); |
Mikhail Naganov | e93a086 | 2023-03-15 17:06:59 -0700 | [diff] [blame] | 993 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 994 | if (mModule == nullptr) return NO_INIT; |
Mikhail Naganov | e93a086 | 2023-03-15 17:06:59 -0700 | [diff] [blame] | 995 | if (port == nullptr) { |
| 996 | return BAD_VALUE; |
| 997 | } |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 998 | if (!connected) { |
| 999 | std::lock_guard l(mLock); |
| 1000 | if (mDeviceDisconnectionNotified.erase(port->id) > 0) { |
| 1001 | // For device disconnection, APM will first call `prepareToDisconnectExternalDevice` |
jiabin | 62750c2 | 2023-12-21 22:06:07 +0000 | [diff] [blame] | 1002 | // and then call `setConnectedState`. If `prepareToDisconnectExternalDevice` doesn't |
| 1003 | // exit, `setConnectedState` will be called when calling |
| 1004 | // `prepareToDisconnectExternalDevice`. Do not call to the HAL if previous call is |
| 1005 | // successful. Also remove the cache here to avoid a large cache after a long run. |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 1006 | return OK; |
| 1007 | } |
jiabin | 872de70 | 2023-04-27 22:04:31 +0000 | [diff] [blame] | 1008 | } |
Mikhail Naganov | e93a086 | 2023-03-15 17:06:59 -0700 | [diff] [blame] | 1009 | bool isInput = VALUE_OR_RETURN_STATUS(::aidl::android::portDirection(port->role, port->type)) == |
| 1010 | ::aidl::android::AudioPortDirection::INPUT; |
| 1011 | AudioPort aidlPort = VALUE_OR_RETURN_STATUS( |
| 1012 | ::aidl::android::legacy2aidl_audio_port_v7_AudioPort(*port, isInput)); |
| 1013 | if (aidlPort.ext.getTag() != AudioPortExt::device) { |
| 1014 | ALOGE("%s: provided port is not a device port (module %s): %s", |
| 1015 | __func__, mInstance.c_str(), aidlPort.toString().c_str()); |
| 1016 | return BAD_VALUE; |
| 1017 | } |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 1018 | std::lock_guard l(mLock); |
| 1019 | return mMapper.setDevicePortConnectedState(aidlPort, connected); |
Mikhail Naganov | e93a086 | 2023-03-15 17:06:59 -0700 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | status_t DeviceHalAidl::setSimulateDeviceConnections(bool enabled) { |
| 1023 | TIME_CHECK(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 1024 | if (mModule == nullptr) return NO_INIT; |
| 1025 | { |
| 1026 | std::lock_guard l(mLock); |
Mikhail Naganov | 6b5da72 | 2024-03-14 12:59:32 -0700 | [diff] [blame] | 1027 | mMapper.resetUnusedPatchesAndPortConfigs(); |
Mikhail Naganov | ac9d4e7 | 2023-10-23 12:00:09 -0700 | [diff] [blame] | 1028 | } |
Mikhail Naganov | e93a086 | 2023-03-15 17:06:59 -0700 | [diff] [blame] | 1029 | ModuleDebug debug{ .simulateDeviceConnections = enabled }; |
| 1030 | status_t status = statusTFromBinderStatus(mModule->setModuleDebug(debug)); |
| 1031 | // This is important to log as it affects HAL behavior. |
| 1032 | if (status == OK) { |
| 1033 | ALOGI("%s: set enabled: %d", __func__, enabled); |
| 1034 | } else { |
| 1035 | ALOGW("%s: set enabled to %d failed: %d", __func__, enabled, status); |
| 1036 | } |
| 1037 | return status; |
| 1038 | } |
| 1039 | |
Mikhail Naganov | e7a26ad | 2023-05-25 17:36:48 -0700 | [diff] [blame] | 1040 | status_t DeviceHalAidl::filterAndRetrieveBtA2dpParameters( |
| 1041 | AudioParameter &keys, AudioParameter *result) { |
Mikhail Naganov | e7a26ad | 2023-05-25 17:36:48 -0700 | [diff] [blame] | 1042 | if (String8 key = String8(AudioParameter::keyReconfigA2dpSupported); keys.containsKey(key)) { |
| 1043 | keys.remove(key); |
David Li | a7761ed | 2023-11-03 17:22:07 +0000 | [diff] [blame] | 1044 | if (mBluetoothA2dp != nullptr) { |
| 1045 | bool supports; |
| 1046 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1047 | mBluetoothA2dp->supportsOffloadReconfiguration(&supports))); |
| 1048 | result->addInt(key, supports ? 1 : 0); |
| 1049 | } else { |
| 1050 | ALOGI("%s: no IBluetoothA2dp on %s", __func__, mInstance.c_str()); |
| 1051 | result->addInt(key, 0); |
| 1052 | } |
Mikhail Naganov | e7a26ad | 2023-05-25 17:36:48 -0700 | [diff] [blame] | 1053 | } |
| 1054 | return OK; |
| 1055 | } |
| 1056 | |
Eric Laurent | 7e3c083 | 2023-11-30 15:04:50 +0100 | [diff] [blame] | 1057 | status_t DeviceHalAidl::filterAndRetrieveBtLeParameters( |
| 1058 | AudioParameter &keys, AudioParameter *result) { |
| 1059 | if (String8 key = String8(AudioParameter::keyReconfigLeSupported); keys.containsKey(key)) { |
| 1060 | keys.remove(key); |
| 1061 | if (mBluetoothLe != nullptr) { |
| 1062 | bool supports; |
| 1063 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1064 | mBluetoothLe->supportsOffloadReconfiguration(&supports))); |
| 1065 | result->addInt(key, supports ? 1 : 0); |
| 1066 | } else { |
| 1067 | ALOGI("%s: no mBluetoothLe on %s", __func__, mInstance.c_str()); |
| 1068 | result->addInt(key, 0); |
| 1069 | } |
| 1070 | } |
| 1071 | return OK; |
| 1072 | } |
| 1073 | |
Mikhail Naganov | ccc8211 | 2023-04-27 18:14:15 -0700 | [diff] [blame] | 1074 | status_t DeviceHalAidl::filterAndUpdateBtA2dpParameters(AudioParameter ¶meters) { |
Mikhail Naganov | ccc8211 | 2023-04-27 18:14:15 -0700 | [diff] [blame] | 1075 | std::optional<bool> a2dpEnabled; |
Mikhail Naganov | e7a26ad | 2023-05-25 17:36:48 -0700 | [diff] [blame] | 1076 | std::optional<std::vector<VendorParameter>> reconfigureOffload; |
Mikhail Naganov | ccc8211 | 2023-04-27 18:14:15 -0700 | [diff] [blame] | 1077 | (void)VALUE_OR_RETURN_STATUS(filterOutAndProcessParameter<String8>( |
| 1078 | parameters, String8(AudioParameter::keyBtA2dpSuspended), |
| 1079 | [&a2dpEnabled](const String8& trueOrFalse) { |
| 1080 | if (trueOrFalse == AudioParameter::valueTrue) { |
| 1081 | a2dpEnabled = false; // 'suspended' == true |
| 1082 | return OK; |
| 1083 | } else if (trueOrFalse == AudioParameter::valueFalse) { |
| 1084 | a2dpEnabled = true; // 'suspended' == false |
| 1085 | return OK; |
| 1086 | } |
| 1087 | ALOGE("setParameters: parameter key \"%s\" has invalid value \"%s\"", |
| 1088 | AudioParameter::keyBtA2dpSuspended, trueOrFalse.c_str()); |
| 1089 | return BAD_VALUE; |
| 1090 | })); |
Mikhail Naganov | e7a26ad | 2023-05-25 17:36:48 -0700 | [diff] [blame] | 1091 | (void)VALUE_OR_RETURN_STATUS(filterOutAndProcessParameter<String8>( |
| 1092 | parameters, String8(AudioParameter::keyReconfigA2dp), |
| 1093 | [&](const String8& value) -> status_t { |
Mikhail Naganov | e501100 | 2024-01-26 10:57:19 -0800 | [diff] [blame] | 1094 | std::vector<VendorParameter> result; |
| 1095 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1096 | mVendorExt->parseBluetoothA2dpReconfigureOffload( |
| 1097 | std::string(value.c_str()), &result))); |
| 1098 | reconfigureOffload = std::move(result); |
Mikhail Naganov | e7a26ad | 2023-05-25 17:36:48 -0700 | [diff] [blame] | 1099 | return OK; |
| 1100 | })); |
Mikhail Naganov | ccc8211 | 2023-04-27 18:14:15 -0700 | [diff] [blame] | 1101 | if (mBluetoothA2dp != nullptr && a2dpEnabled.has_value()) { |
| 1102 | return statusTFromBinderStatus(mBluetoothA2dp->setEnabled(a2dpEnabled.value())); |
| 1103 | } |
Mikhail Naganov | e7a26ad | 2023-05-25 17:36:48 -0700 | [diff] [blame] | 1104 | if (mBluetoothA2dp != nullptr && reconfigureOffload.has_value()) { |
| 1105 | return statusTFromBinderStatus(mBluetoothA2dp->reconfigureOffload( |
| 1106 | reconfigureOffload.value())); |
| 1107 | } |
Mikhail Naganov | ccc8211 | 2023-04-27 18:14:15 -0700 | [diff] [blame] | 1108 | return OK; |
| 1109 | } |
| 1110 | |
| 1111 | status_t DeviceHalAidl::filterAndUpdateBtHfpParameters(AudioParameter ¶meters) { |
Mikhail Naganov | ccc8211 | 2023-04-27 18:14:15 -0700 | [diff] [blame] | 1112 | IBluetooth::HfpConfig hfpConfig; |
| 1113 | (void)VALUE_OR_RETURN_STATUS(filterOutAndProcessParameter<String8>( |
| 1114 | parameters, String8(AudioParameter::keyBtHfpEnable), |
| 1115 | [&hfpConfig](const String8& trueOrFalse) { |
| 1116 | if (trueOrFalse == AudioParameter::valueTrue) { |
| 1117 | hfpConfig.isEnabled = Boolean{ .value = true }; |
| 1118 | return OK; |
| 1119 | } else if (trueOrFalse == AudioParameter::valueFalse) { |
| 1120 | hfpConfig.isEnabled = Boolean{ .value = false }; |
| 1121 | return OK; |
| 1122 | } |
| 1123 | ALOGE("setParameters: parameter key \"%s\" has invalid value \"%s\"", |
| 1124 | AudioParameter::keyBtHfpEnable, trueOrFalse.c_str()); |
| 1125 | return BAD_VALUE; |
| 1126 | })); |
| 1127 | (void)VALUE_OR_RETURN_STATUS(filterOutAndProcessParameter<int>( |
| 1128 | parameters, String8(AudioParameter::keyBtHfpSamplingRate), |
| 1129 | [&hfpConfig](int sampleRate) { |
| 1130 | return sampleRate > 0 ? |
| 1131 | hfpConfig.sampleRate = Int{ .value = sampleRate }, OK : BAD_VALUE; |
| 1132 | })); |
| 1133 | (void)VALUE_OR_RETURN_STATUS(filterOutAndProcessParameter<int>( |
| 1134 | parameters, String8(AudioParameter::keyBtHfpVolume), |
| 1135 | [&hfpConfig](int volume0to15) { |
| 1136 | if (volume0to15 >= 0 && volume0to15 <= 15) { |
| 1137 | hfpConfig.volume = Float{ .value = volume0to15 / 15.0f }; |
| 1138 | return OK; |
| 1139 | } |
| 1140 | return BAD_VALUE; |
| 1141 | })); |
| 1142 | if (mBluetooth != nullptr && hfpConfig != IBluetooth::HfpConfig{}) { |
| 1143 | IBluetooth::HfpConfig newHfpConfig; |
| 1144 | return statusTFromBinderStatus(mBluetooth->setHfpConfig(hfpConfig, &newHfpConfig)); |
| 1145 | } |
| 1146 | return OK; |
| 1147 | } |
| 1148 | |
| 1149 | status_t DeviceHalAidl::filterAndUpdateBtLeParameters(AudioParameter ¶meters) { |
Mikhail Naganov | ccc8211 | 2023-04-27 18:14:15 -0700 | [diff] [blame] | 1150 | std::optional<bool> leEnabled; |
Eric Laurent | 7e3c083 | 2023-11-30 15:04:50 +0100 | [diff] [blame] | 1151 | std::optional<std::vector<VendorParameter>> reconfigureOffload; |
Mikhail Naganov | ccc8211 | 2023-04-27 18:14:15 -0700 | [diff] [blame] | 1152 | (void)VALUE_OR_RETURN_STATUS(filterOutAndProcessParameter<String8>( |
| 1153 | parameters, String8(AudioParameter::keyBtLeSuspended), |
| 1154 | [&leEnabled](const String8& trueOrFalse) { |
| 1155 | if (trueOrFalse == AudioParameter::valueTrue) { |
| 1156 | leEnabled = false; // 'suspended' == true |
| 1157 | return OK; |
| 1158 | } else if (trueOrFalse == AudioParameter::valueFalse) { |
| 1159 | leEnabled = true; // 'suspended' == false |
| 1160 | return OK; |
| 1161 | } |
| 1162 | ALOGE("setParameters: parameter key \"%s\" has invalid value \"%s\"", |
| 1163 | AudioParameter::keyBtLeSuspended, trueOrFalse.c_str()); |
| 1164 | return BAD_VALUE; |
| 1165 | })); |
Eric Laurent | 7e3c083 | 2023-11-30 15:04:50 +0100 | [diff] [blame] | 1166 | (void)VALUE_OR_RETURN_STATUS(filterOutAndProcessParameter<String8>( |
| 1167 | parameters, String8(AudioParameter::keyReconfigLe), |
| 1168 | [&](const String8& value) -> status_t { |
| 1169 | if (mVendorExt != nullptr) { |
| 1170 | std::vector<VendorParameter> result; |
| 1171 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1172 | mVendorExt->parseBluetoothLeReconfigureOffload( |
| 1173 | std::string(value.c_str()), &result))); |
| 1174 | reconfigureOffload = std::move(result); |
| 1175 | } else { |
| 1176 | reconfigureOffload = std::vector<VendorParameter>(); |
| 1177 | } |
| 1178 | return OK; |
| 1179 | })); |
Mikhail Naganov | ccc8211 | 2023-04-27 18:14:15 -0700 | [diff] [blame] | 1180 | if (mBluetoothLe != nullptr && leEnabled.has_value()) { |
| 1181 | return statusTFromBinderStatus(mBluetoothLe->setEnabled(leEnabled.value())); |
| 1182 | } |
Eric Laurent | 7e3c083 | 2023-11-30 15:04:50 +0100 | [diff] [blame] | 1183 | if (mBluetoothLe != nullptr && reconfigureOffload.has_value()) { |
| 1184 | return statusTFromBinderStatus(mBluetoothLe->reconfigureOffload( |
| 1185 | reconfigureOffload.value())); |
| 1186 | } |
Mikhail Naganov | ccc8211 | 2023-04-27 18:14:15 -0700 | [diff] [blame] | 1187 | return OK; |
| 1188 | } |
| 1189 | |
| 1190 | status_t DeviceHalAidl::filterAndUpdateBtScoParameters(AudioParameter ¶meters) { |
Mikhail Naganov | ccc8211 | 2023-04-27 18:14:15 -0700 | [diff] [blame] | 1191 | IBluetooth::ScoConfig scoConfig; |
| 1192 | (void)VALUE_OR_RETURN_STATUS(filterOutAndProcessParameter<String8>( |
| 1193 | parameters, String8(AudioParameter::keyBtSco), |
| 1194 | [&scoConfig](const String8& onOrOff) { |
| 1195 | if (onOrOff == AudioParameter::valueOn) { |
| 1196 | scoConfig.isEnabled = Boolean{ .value = true }; |
| 1197 | return OK; |
| 1198 | } else if (onOrOff == AudioParameter::valueOff) { |
| 1199 | scoConfig.isEnabled = Boolean{ .value = false }; |
| 1200 | return OK; |
| 1201 | } |
| 1202 | ALOGE("setParameters: parameter key \"%s\" has invalid value \"%s\"", |
| 1203 | AudioParameter::keyBtSco, onOrOff.c_str()); |
| 1204 | return BAD_VALUE; |
| 1205 | })); |
| 1206 | (void)VALUE_OR_RETURN_STATUS(filterOutAndProcessParameter<String8>( |
| 1207 | parameters, String8(AudioParameter::keyBtScoHeadsetName), |
| 1208 | [&scoConfig](const String8& name) { |
| 1209 | scoConfig.debugName = name; |
| 1210 | return OK; |
| 1211 | })); |
| 1212 | (void)VALUE_OR_RETURN_STATUS(filterOutAndProcessParameter<String8>( |
| 1213 | parameters, String8(AudioParameter::keyBtNrec), |
| 1214 | [&scoConfig](const String8& onOrOff) { |
| 1215 | if (onOrOff == AudioParameter::valueOn) { |
| 1216 | scoConfig.isNrecEnabled = Boolean{ .value = true }; |
| 1217 | return OK; |
| 1218 | } else if (onOrOff == AudioParameter::valueOff) { |
| 1219 | scoConfig.isNrecEnabled = Boolean{ .value = false }; |
| 1220 | return OK; |
| 1221 | } |
| 1222 | ALOGE("setParameters: parameter key \"%s\" has invalid value \"%s\"", |
| 1223 | AudioParameter::keyBtNrec, onOrOff.c_str()); |
| 1224 | return BAD_VALUE; |
| 1225 | })); |
| 1226 | (void)VALUE_OR_RETURN_STATUS(filterOutAndProcessParameter<String8>( |
| 1227 | parameters, String8(AudioParameter::keyBtScoWb), |
| 1228 | [&scoConfig](const String8& onOrOff) { |
| 1229 | if (onOrOff == AudioParameter::valueOn) { |
| 1230 | scoConfig.mode = IBluetooth::ScoConfig::Mode::SCO_WB; |
| 1231 | return OK; |
| 1232 | } else if (onOrOff == AudioParameter::valueOff) { |
| 1233 | scoConfig.mode = IBluetooth::ScoConfig::Mode::SCO; |
| 1234 | return OK; |
| 1235 | } |
| 1236 | ALOGE("setParameters: parameter key \"%s\" has invalid value \"%s\"", |
| 1237 | AudioParameter::keyBtScoWb, onOrOff.c_str()); |
| 1238 | return BAD_VALUE; |
| 1239 | })); |
| 1240 | if (mBluetooth != nullptr && scoConfig != IBluetooth::ScoConfig{}) { |
| 1241 | IBluetooth::ScoConfig newScoConfig; |
| 1242 | return statusTFromBinderStatus(mBluetooth->setScoConfig(scoConfig, &newScoConfig)); |
| 1243 | } |
| 1244 | return OK; |
| 1245 | } |
| 1246 | |
Mikhail Naganov | e92c34b | 2023-05-31 14:24:48 -0700 | [diff] [blame] | 1247 | status_t DeviceHalAidl::filterAndUpdateScreenParameters(AudioParameter ¶meters) { |
Mikhail Naganov | e92c34b | 2023-05-31 14:24:48 -0700 | [diff] [blame] | 1248 | (void)VALUE_OR_RETURN_STATUS(filterOutAndProcessParameter<String8>( |
| 1249 | parameters, String8(AudioParameter::keyScreenState), |
| 1250 | [&](const String8& onOrOff) -> status_t { |
| 1251 | std::optional<bool> isTurnedOn; |
| 1252 | if (onOrOff == AudioParameter::valueOn) { |
| 1253 | isTurnedOn = true; |
| 1254 | } else if (onOrOff == AudioParameter::valueOff) { |
| 1255 | isTurnedOn = false; |
| 1256 | } |
| 1257 | if (!isTurnedOn.has_value()) { |
| 1258 | ALOGE("setParameters: parameter key \"%s\" has invalid value \"%s\"", |
| 1259 | AudioParameter::keyScreenState, onOrOff.c_str()); |
| 1260 | return BAD_VALUE; |
| 1261 | } |
| 1262 | return statusTFromBinderStatus( |
| 1263 | mModule->updateScreenState(isTurnedOn.value())); |
| 1264 | })); |
| 1265 | (void)VALUE_OR_RETURN_STATUS(filterOutAndProcessParameter<int>( |
| 1266 | parameters, String8(AudioParameter::keyScreenRotation), |
| 1267 | [&](int rotationDegrees) -> status_t { |
| 1268 | IModule::ScreenRotation rotation; |
| 1269 | switch (rotationDegrees) { |
| 1270 | case 0: rotation = IModule::ScreenRotation::DEG_0; break; |
| 1271 | case 90: rotation = IModule::ScreenRotation::DEG_90; break; |
| 1272 | case 180: rotation = IModule::ScreenRotation::DEG_180; break; |
| 1273 | case 270: rotation = IModule::ScreenRotation::DEG_270; break; |
| 1274 | default: |
| 1275 | ALOGE("setParameters: parameter key \"%s\" has invalid value %d", |
| 1276 | AudioParameter::keyScreenRotation, rotationDegrees); |
| 1277 | return BAD_VALUE; |
| 1278 | } |
| 1279 | return statusTFromBinderStatus(mModule->updateScreenRotation(rotation)); |
| 1280 | })); |
| 1281 | return OK; |
| 1282 | } |
| 1283 | |
Mikhail Naganov | b9a8131 | 2023-07-18 13:55:34 -0700 | [diff] [blame] | 1284 | status_t DeviceHalAidl::filterAndUpdateTelephonyParameters(AudioParameter ¶meters) { |
Mikhail Naganov | b9a8131 | 2023-07-18 13:55:34 -0700 | [diff] [blame] | 1285 | using TtyMode = ITelephony::TelecomConfig::TtyMode; |
| 1286 | ITelephony::TelecomConfig telConfig; |
| 1287 | (void)VALUE_OR_RETURN_STATUS(filterOutAndProcessParameter<String8>( |
| 1288 | parameters, String8(AudioParameter::keyTtyMode), |
| 1289 | [&telConfig](const String8& mode) { |
| 1290 | if (mode == AudioParameter::valueTtyModeOff) { |
| 1291 | telConfig.ttyMode = TtyMode::OFF; |
| 1292 | return OK; |
| 1293 | } else if (mode == AudioParameter::valueTtyModeFull) { |
| 1294 | telConfig.ttyMode = TtyMode::FULL; |
| 1295 | return OK; |
| 1296 | } else if (mode == AudioParameter::valueTtyModeHco) { |
| 1297 | telConfig.ttyMode = TtyMode::HCO; |
| 1298 | return OK; |
| 1299 | } else if (mode == AudioParameter::valueTtyModeVco) { |
| 1300 | telConfig.ttyMode = TtyMode::VCO; |
| 1301 | return OK; |
| 1302 | } |
| 1303 | ALOGE("setParameters: parameter key \"%s\" has invalid value \"%s\"", |
| 1304 | AudioParameter::keyTtyMode, mode.c_str()); |
| 1305 | return BAD_VALUE; |
| 1306 | })); |
| 1307 | (void)VALUE_OR_RETURN_STATUS(filterOutAndProcessParameter<String8>( |
| 1308 | parameters, String8(AudioParameter::keyHacSetting), |
| 1309 | [&telConfig](const String8& onOrOff) { |
| 1310 | if (onOrOff == AudioParameter::valueHacOn) { |
| 1311 | telConfig.isHacEnabled = Boolean{ .value = true }; |
| 1312 | return OK; |
| 1313 | } else if (onOrOff == AudioParameter::valueHacOff) { |
| 1314 | telConfig.isHacEnabled = Boolean{ .value = false }; |
| 1315 | return OK; |
| 1316 | } |
| 1317 | ALOGE("setParameters: parameter key \"%s\" has invalid value \"%s\"", |
| 1318 | AudioParameter::keyHacSetting, onOrOff.c_str()); |
| 1319 | return BAD_VALUE; |
| 1320 | })); |
| 1321 | if (mTelephony != nullptr && telConfig != ITelephony::TelecomConfig{}) { |
| 1322 | ITelephony::TelecomConfig newTelConfig; |
| 1323 | return statusTFromBinderStatus( |
| 1324 | mTelephony->setTelecomConfig(telConfig, &newTelConfig)); |
| 1325 | } |
| 1326 | return OK; |
| 1327 | } |
| 1328 | |
Mikhail Naganov | dfd594e | 2023-02-08 16:59:41 -0800 | [diff] [blame] | 1329 | void DeviceHalAidl::clearCallbacks(void* cookie) { |
| 1330 | std::lock_guard l(mLock); |
| 1331 | mCallbacks.erase(cookie); |
| 1332 | } |
| 1333 | |
| 1334 | sp<StreamOutHalInterfaceCallback> DeviceHalAidl::getStreamOutCallback(void* cookie) { |
| 1335 | return getCallbackImpl(cookie, &Callbacks::out); |
| 1336 | } |
| 1337 | |
| 1338 | void DeviceHalAidl::setStreamOutCallback( |
| 1339 | void* cookie, const sp<StreamOutHalInterfaceCallback>& cb) { |
| 1340 | setCallbackImpl(cookie, &Callbacks::out, cb); |
| 1341 | } |
| 1342 | |
| 1343 | sp<StreamOutHalInterfaceEventCallback> DeviceHalAidl::getStreamOutEventCallback( |
| 1344 | void* cookie) { |
| 1345 | return getCallbackImpl(cookie, &Callbacks::event); |
| 1346 | } |
| 1347 | |
| 1348 | void DeviceHalAidl::setStreamOutEventCallback( |
| 1349 | void* cookie, const sp<StreamOutHalInterfaceEventCallback>& cb) { |
| 1350 | setCallbackImpl(cookie, &Callbacks::event, cb); |
| 1351 | } |
| 1352 | |
| 1353 | sp<StreamOutHalInterfaceLatencyModeCallback> DeviceHalAidl::getStreamOutLatencyModeCallback( |
| 1354 | void* cookie) { |
| 1355 | return getCallbackImpl(cookie, &Callbacks::latency); |
| 1356 | } |
| 1357 | |
| 1358 | void DeviceHalAidl::setStreamOutLatencyModeCallback( |
| 1359 | void* cookie, const sp<StreamOutHalInterfaceLatencyModeCallback>& cb) { |
| 1360 | setCallbackImpl(cookie, &Callbacks::latency, cb); |
| 1361 | } |
| 1362 | |
| 1363 | template<class C> |
| 1364 | sp<C> DeviceHalAidl::getCallbackImpl(void* cookie, wp<C> DeviceHalAidl::Callbacks::* field) { |
| 1365 | std::lock_guard l(mLock); |
| 1366 | if (auto it = mCallbacks.find(cookie); it != mCallbacks.end()) { |
| 1367 | return ((it->second).*field).promote(); |
| 1368 | } |
| 1369 | return nullptr; |
| 1370 | } |
| 1371 | template<class C> |
| 1372 | void DeviceHalAidl::setCallbackImpl( |
| 1373 | void* cookie, wp<C> DeviceHalAidl::Callbacks::* field, const sp<C>& cb) { |
| 1374 | std::lock_guard l(mLock); |
| 1375 | if (auto it = mCallbacks.find(cookie); it != mCallbacks.end()) { |
| 1376 | (it->second).*field = cb; |
| 1377 | } |
| 1378 | } |
| 1379 | |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 1380 | } // namespace android |