blob: d9da39f0a8812efb9a965ef5fa872afd21792ddf [file] [log] [blame]
Mikhail Naganov3b125b72022-10-05 02:12:39 +00001/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Mikhail Naganov3b125b72022-10-05 02:12:39 +000017#define LOG_TAG "AHAL_Telephony"
18#include <android-base/logging.h>
Lorena Torres-Huerta394e2522022-12-20 02:21:41 +000019#include <android/binder_to_string.h>
Mikhail Naganov3b125b72022-10-05 02:12:39 +000020
Mikhail Naganov04ae8222023-01-11 15:48:10 -080021#include <Utils.h>
Mikhail Naganov04ae8222023-01-11 15:48:10 -080022
Mikhail Naganov3b125b72022-10-05 02:12:39 +000023#include "core-impl/Telephony.h"
24
Mikhail Naganov872d4a62023-03-09 18:19:01 -080025using aidl::android::hardware::audio::common::isValidAudioMode;
Mikhail Naganov04ae8222023-01-11 15:48:10 -080026using aidl::android::media::audio::common::AudioMode;
Mikhail Naganova7f4e052022-12-27 20:28:17 +000027using aidl::android::media::audio::common::Boolean;
28using aidl::android::media::audio::common::Float;
29
Mikhail Naganov3b125b72022-10-05 02:12:39 +000030namespace aidl::android::hardware::audio::core {
31
Mikhail Naganova7f4e052022-12-27 20:28:17 +000032Telephony::Telephony() {
33 mTelecomConfig.voiceVolume = Float{TelecomConfig::VOICE_VOLUME_MAX};
34 mTelecomConfig.ttyMode = TelecomConfig::TtyMode::OFF;
35 mTelecomConfig.isHacEnabled = Boolean{false};
36}
37
Mikhail Naganov3b125b72022-10-05 02:12:39 +000038ndk::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
44ndk::ScopedAStatus Telephony::switchAudioMode(AudioMode in_mode) {
Mikhail Naganov04ae8222023-01-11 15:48:10 -080045 if (!isValidAudioMode(in_mode)) {
46 LOG(ERROR) << __func__ << ": invalid mode " << toString(in_mode);
47 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
48 }
Mikhail Naganov3b125b72022-10-05 02:12:39 +000049 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 Naganova7f4e052022-12-27 20:28:17 +000058ndk::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 Naganov3b125b72022-10-05 02:12:39 +000082} // namespace aidl::android::hardware::audio::core