Loading audio/common/all-versions/util/include/common/all-versions/HidlSupport.h 0 → 100644 +34 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef android_hardware_audio_common_HidlSupport_H_ #define android_hardware_audio_common_HidlSupport_H_ #include <hidl/HidlSupport.h> #include <algorithm> namespace android::hardware::audio::common::utils { template <typename Enum> bool isValidHidlEnum(Enum e) { hidl_enum_range<Enum> values; return std::find(values.begin(), values.end(), e) != values.end(); } } // namespace android::hardware::audio::common::utils #endif // android_hardware_audio_common_HidlSupport_H_ audio/core/all-versions/default/StreamIn.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ #include "core/default/StreamIn.h" #include "core/default/Conversions.h" #include "core/default/Util.h" #include "common/all-versions/HidlSupport.h" //#define LOG_NDEBUG 0 #define ATRACE_TAG ATRACE_TAG_AUDIO Loading @@ -27,6 +28,7 @@ #include <hardware/audio.h> #include <utils/Trace.h> #include <memory> #include <cmath> namespace android { namespace hardware { Loading Loading @@ -501,6 +503,10 @@ Return<Result> StreamIn::setMicrophoneDirection(MicrophoneDirection direction) { if (mStream->set_microphone_direction == nullptr) { return Result::NOT_SUPPORTED; } if (!common::utils::isValidHidlEnum(direction)) { ALOGE("%s: Invalid direction %d", __func__, direction); return Result::INVALID_ARGUMENTS; } return Stream::analyzeStatus( "set_microphone_direction", mStream->set_microphone_direction( Loading @@ -511,6 +517,10 @@ Return<Result> StreamIn::setMicrophoneFieldDimension(float zoom) { if (mStream->set_microphone_field_dimension == nullptr) { return Result::NOT_SUPPORTED; } if (std::isnan(zoom) || zoom < -1 || zoom > 1) { ALOGE("%s: Invalid zoom %f", __func__, zoom); return Result::INVALID_ARGUMENTS; } return Stream::analyzeStatus("set_microphone_field_dimension", mStream->set_microphone_field_dimension(mStream, zoom)); } Loading Loading
audio/common/all-versions/util/include/common/all-versions/HidlSupport.h 0 → 100644 +34 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef android_hardware_audio_common_HidlSupport_H_ #define android_hardware_audio_common_HidlSupport_H_ #include <hidl/HidlSupport.h> #include <algorithm> namespace android::hardware::audio::common::utils { template <typename Enum> bool isValidHidlEnum(Enum e) { hidl_enum_range<Enum> values; return std::find(values.begin(), values.end(), e) != values.end(); } } // namespace android::hardware::audio::common::utils #endif // android_hardware_audio_common_HidlSupport_H_
audio/core/all-versions/default/StreamIn.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ #include "core/default/StreamIn.h" #include "core/default/Conversions.h" #include "core/default/Util.h" #include "common/all-versions/HidlSupport.h" //#define LOG_NDEBUG 0 #define ATRACE_TAG ATRACE_TAG_AUDIO Loading @@ -27,6 +28,7 @@ #include <hardware/audio.h> #include <utils/Trace.h> #include <memory> #include <cmath> namespace android { namespace hardware { Loading Loading @@ -501,6 +503,10 @@ Return<Result> StreamIn::setMicrophoneDirection(MicrophoneDirection direction) { if (mStream->set_microphone_direction == nullptr) { return Result::NOT_SUPPORTED; } if (!common::utils::isValidHidlEnum(direction)) { ALOGE("%s: Invalid direction %d", __func__, direction); return Result::INVALID_ARGUMENTS; } return Stream::analyzeStatus( "set_microphone_direction", mStream->set_microphone_direction( Loading @@ -511,6 +517,10 @@ Return<Result> StreamIn::setMicrophoneFieldDimension(float zoom) { if (mStream->set_microphone_field_dimension == nullptr) { return Result::NOT_SUPPORTED; } if (std::isnan(zoom) || zoom < -1 || zoom > 1) { ALOGE("%s: Invalid zoom %f", __func__, zoom); return Result::INVALID_ARGUMENTS; } return Stream::analyzeStatus("set_microphone_field_dimension", mStream->set_microphone_field_dimension(mStream, zoom)); } Loading