blob: f12ce5d806f7a18f3f2aae06653c29395ea17670 [file] [log] [blame]
Vlad Popa83a21462022-12-08 14:24:12 +01001/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "AHAL_SoundDose"
18
19#include "core-impl/SoundDose.h"
20
21#include <android-base/logging.h>
22
Vlad Popac88ea612022-12-28 17:04:58 +010023namespace aidl::android::hardware::audio::core::sounddose {
Vlad Popa83a21462022-12-08 14:24:12 +010024
Vlad Popa34f4c1d2023-03-16 18:43:53 +010025ndk::ScopedAStatus SoundDose::setOutputRs2UpperBound(float in_rs2ValueDbA) {
Vlad Popa83a21462022-12-08 14:24:12 +010026 if (in_rs2ValueDbA < MIN_RS2 || in_rs2ValueDbA > DEFAULT_MAX_RS2) {
27 LOG(ERROR) << __func__ << ": RS2 value is invalid: " << in_rs2ValueDbA;
28 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
29 }
30
31 mRs2Value = in_rs2ValueDbA;
32 return ndk::ScopedAStatus::ok();
33}
34
Vlad Popa34f4c1d2023-03-16 18:43:53 +010035ndk::ScopedAStatus SoundDose::getOutputRs2UpperBound(float* _aidl_return) {
Vlad Popa83a21462022-12-08 14:24:12 +010036 *_aidl_return = mRs2Value;
37 LOG(DEBUG) << __func__ << ": returning " << *_aidl_return;
38 return ndk::ScopedAStatus::ok();
39}
40
41ndk::ScopedAStatus SoundDose::registerSoundDoseCallback(
42 const std::shared_ptr<ISoundDose::IHalSoundDoseCallback>& in_callback) {
43 if (in_callback.get() == nullptr) {
44 LOG(ERROR) << __func__ << ": Callback is nullptr";
45 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
46 }
47 if (mCallback != nullptr) {
48 LOG(ERROR) << __func__ << ": Sound dose callback was already registered";
49 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
50 }
51
52 mCallback = in_callback;
53 LOG(DEBUG) << __func__ << ": Registered sound dose callback ";
54 return ndk::ScopedAStatus::ok();
55}
56
Vlad Popac88ea612022-12-28 17:04:58 +010057} // namespace aidl::android::hardware::audio::core::sounddose