Mikhail Naganov | 3b125b7 | 2022-10-05 02:12:39 +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 | |
Mikhail Naganov | 3b125b7 | 2022-10-05 02:12:39 +0000 | [diff] [blame] | 17 | #define LOG_TAG "AHAL_Telephony" |
| 18 | #include <android-base/logging.h> |
| 19 | |
Mikhail Naganov | 04ae822 | 2023-01-11 15:48:10 -0800 | [diff] [blame] | 20 | #include <Utils.h> |
Mikhail Naganov | af75a67 | 2023-10-13 23:38:25 +0000 | [diff] [blame] | 21 | #include <android/binder_to_string.h> |
Mikhail Naganov | 04ae822 | 2023-01-11 15:48:10 -0800 | [diff] [blame] | 22 | |
Mikhail Naganov | 3b125b7 | 2022-10-05 02:12:39 +0000 | [diff] [blame] | 23 | #include "core-impl/Telephony.h" |
| 24 | |
Mikhail Naganov | 872d4a6 | 2023-03-09 18:19:01 -0800 | [diff] [blame] | 25 | using aidl::android::hardware::audio::common::isValidAudioMode; |
Mikhail Naganov | 04ae822 | 2023-01-11 15:48:10 -0800 | [diff] [blame] | 26 | using aidl::android::media::audio::common::AudioMode; |
Mikhail Naganov | a7f4e05 | 2022-12-27 20:28:17 +0000 | [diff] [blame] | 27 | using aidl::android::media::audio::common::Boolean; |
| 28 | using aidl::android::media::audio::common::Float; |
| 29 | |
Mikhail Naganov | 3b125b7 | 2022-10-05 02:12:39 +0000 | [diff] [blame] | 30 | namespace aidl::android::hardware::audio::core { |
| 31 | |
Mikhail Naganov | a7f4e05 | 2022-12-27 20:28:17 +0000 | [diff] [blame] | 32 | Telephony::Telephony() { |
| 33 | mTelecomConfig.voiceVolume = Float{TelecomConfig::VOICE_VOLUME_MAX}; |
| 34 | mTelecomConfig.ttyMode = TelecomConfig::TtyMode::OFF; |
| 35 | mTelecomConfig.isHacEnabled = Boolean{false}; |
| 36 | } |
| 37 | |
Mikhail Naganov | 3b125b7 | 2022-10-05 02:12:39 +0000 | [diff] [blame] | 38 | ndk::ScopedAStatus Telephony::getSupportedAudioModes(std::vector<AudioMode>* _aidl_return) { |
| 39 | *_aidl_return = mSupportedAudioModes; |
| 40 | LOG(DEBUG) << __func__ << ": returning " << ::android::internal::ToString(*_aidl_return); |
| 41 | return ndk::ScopedAStatus::ok(); |
| 42 | } |
| 43 | |
| 44 | ndk::ScopedAStatus Telephony::switchAudioMode(AudioMode in_mode) { |
Mikhail Naganov | 04ae822 | 2023-01-11 15:48:10 -0800 | [diff] [blame] | 45 | if (!isValidAudioMode(in_mode)) { |
| 46 | LOG(ERROR) << __func__ << ": invalid mode " << toString(in_mode); |
| 47 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 48 | } |
Mikhail Naganov | 3b125b7 | 2022-10-05 02:12:39 +0000 | [diff] [blame] | 49 | if (std::find(mSupportedAudioModes.begin(), mSupportedAudioModes.end(), in_mode) != |
| 50 | mSupportedAudioModes.end()) { |
| 51 | LOG(DEBUG) << __func__ << ": " << toString(in_mode); |
| 52 | return ndk::ScopedAStatus::ok(); |
| 53 | } |
| 54 | LOG(ERROR) << __func__ << ": unsupported mode " << toString(in_mode); |
| 55 | return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 56 | } |
| 57 | |
Mikhail Naganov | a7f4e05 | 2022-12-27 20:28:17 +0000 | [diff] [blame] | 58 | ndk::ScopedAStatus Telephony::setTelecomConfig(const TelecomConfig& in_config, |
| 59 | TelecomConfig* _aidl_return) { |
| 60 | if (in_config.voiceVolume.has_value() && |
| 61 | (in_config.voiceVolume.value().value < TelecomConfig::VOICE_VOLUME_MIN || |
| 62 | in_config.voiceVolume.value().value > TelecomConfig::VOICE_VOLUME_MAX)) { |
| 63 | LOG(ERROR) << __func__ |
| 64 | << ": voice volume value is invalid: " << in_config.voiceVolume.value().value; |
| 65 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 66 | } |
| 67 | if (in_config.voiceVolume.has_value()) { |
| 68 | mTelecomConfig.voiceVolume = in_config.voiceVolume; |
| 69 | } |
| 70 | if (in_config.ttyMode != TelecomConfig::TtyMode::UNSPECIFIED) { |
| 71 | mTelecomConfig.ttyMode = in_config.ttyMode; |
| 72 | } |
| 73 | if (in_config.isHacEnabled.has_value()) { |
| 74 | mTelecomConfig.isHacEnabled = in_config.isHacEnabled; |
| 75 | } |
| 76 | *_aidl_return = mTelecomConfig; |
| 77 | LOG(DEBUG) << __func__ << ": received " << in_config.toString() << ", returning " |
| 78 | << _aidl_return->toString(); |
| 79 | return ndk::ScopedAStatus::ok(); |
| 80 | } |
| 81 | |
Mikhail Naganov | 3b125b7 | 2022-10-05 02:12:39 +0000 | [diff] [blame] | 82 | } // namespace aidl::android::hardware::audio::core |