blob: d873178a002b191a8a67e73bee42468533594c4f [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
17#include <android/binder_to_string.h>
18#define LOG_TAG "AHAL_Telephony"
19#include <android-base/logging.h>
20
21#include "core-impl/Telephony.h"
22
Mikhail Naganova7f4e052022-12-27 20:28:17 +000023using aidl::android::media::audio::common::Boolean;
24using aidl::android::media::audio::common::Float;
25
Mikhail Naganov3b125b72022-10-05 02:12:39 +000026namespace aidl::android::hardware::audio::core {
27
Mikhail Naganova7f4e052022-12-27 20:28:17 +000028Telephony::Telephony() {
29 mTelecomConfig.voiceVolume = Float{TelecomConfig::VOICE_VOLUME_MAX};
30 mTelecomConfig.ttyMode = TelecomConfig::TtyMode::OFF;
31 mTelecomConfig.isHacEnabled = Boolean{false};
32}
33
Mikhail Naganov3b125b72022-10-05 02:12:39 +000034ndk::ScopedAStatus Telephony::getSupportedAudioModes(std::vector<AudioMode>* _aidl_return) {
35 *_aidl_return = mSupportedAudioModes;
36 LOG(DEBUG) << __func__ << ": returning " << ::android::internal::ToString(*_aidl_return);
37 return ndk::ScopedAStatus::ok();
38}
39
40ndk::ScopedAStatus Telephony::switchAudioMode(AudioMode in_mode) {
41 if (std::find(mSupportedAudioModes.begin(), mSupportedAudioModes.end(), in_mode) !=
42 mSupportedAudioModes.end()) {
43 LOG(DEBUG) << __func__ << ": " << toString(in_mode);
44 return ndk::ScopedAStatus::ok();
45 }
46 LOG(ERROR) << __func__ << ": unsupported mode " << toString(in_mode);
47 return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
48}
49
Mikhail Naganova7f4e052022-12-27 20:28:17 +000050ndk::ScopedAStatus Telephony::setTelecomConfig(const TelecomConfig& in_config,
51 TelecomConfig* _aidl_return) {
52 if (in_config.voiceVolume.has_value() &&
53 (in_config.voiceVolume.value().value < TelecomConfig::VOICE_VOLUME_MIN ||
54 in_config.voiceVolume.value().value > TelecomConfig::VOICE_VOLUME_MAX)) {
55 LOG(ERROR) << __func__
56 << ": voice volume value is invalid: " << in_config.voiceVolume.value().value;
57 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
58 }
59 if (in_config.voiceVolume.has_value()) {
60 mTelecomConfig.voiceVolume = in_config.voiceVolume;
61 }
62 if (in_config.ttyMode != TelecomConfig::TtyMode::UNSPECIFIED) {
63 mTelecomConfig.ttyMode = in_config.ttyMode;
64 }
65 if (in_config.isHacEnabled.has_value()) {
66 mTelecomConfig.isHacEnabled = in_config.isHacEnabled;
67 }
68 *_aidl_return = mTelecomConfig;
69 LOG(DEBUG) << __func__ << ": received " << in_config.toString() << ", returning "
70 << _aidl_return->toString();
71 return ndk::ScopedAStatus::ok();
72}
73
Mikhail Naganov3b125b72022-10-05 02:12:39 +000074} // namespace aidl::android::hardware::audio::core