• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "AHAL_SoundDose"
18 
19 #include "core-impl/SoundDose.h"
20 
21 #include <android-base/logging.h>
22 
23 namespace aidl::android::hardware::audio::core::sounddose {
24 
setOutputRs2UpperBound(float in_rs2ValueDbA)25 ndk::ScopedAStatus SoundDose::setOutputRs2UpperBound(float in_rs2ValueDbA) {
26     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 
getOutputRs2UpperBound(float * _aidl_return)35 ndk::ScopedAStatus SoundDose::getOutputRs2UpperBound(float* _aidl_return) {
36     *_aidl_return = mRs2Value;
37     LOG(DEBUG) << __func__ << ": returning " << *_aidl_return;
38     return ndk::ScopedAStatus::ok();
39 }
40 
registerSoundDoseCallback(const std::shared_ptr<ISoundDose::IHalSoundDoseCallback> & in_callback)41 ndk::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 
57 }  // namespace aidl::android::hardware::audio::core::sounddose
58