summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot2018-04-22 02:28:49 -0500
committerandroid-build-team Robot2018-04-22 02:28:49 -0500
commitd89f95414fc715c0e89b4a5da47aa9bd277736a1 (patch)
tree3b4f0777b35824e0b89ea70d35a7dcf3eb1f8af9 /audio/core
parentcb0ee29e765a3f5076b90019f1c22636979ea2f4 (diff)
parent63abd8fdbc05ba5534141ae93816572e24b33289 (diff)
downloadplatform-hardware-interfaces-d89f95414fc715c0e89b4a5da47aa9bd277736a1.tar.gz
platform-hardware-interfaces-d89f95414fc715c0e89b4a5da47aa9bd277736a1.tar.xz
platform-hardware-interfaces-d89f95414fc715c0e89b4a5da47aa9bd277736a1.zip
Snap for 4736748 from 63abd8fdbc05ba5534141ae93816572e24b33289 to pi-release
Change-Id: Icd5ce28c284b6b7a8f1024158be663861bf10635
Diffstat (limited to 'audio/core')
-rw-r--r--audio/core/2.0/default/Device.cpp2
-rw-r--r--audio/core/2.0/default/ParametersUtil.cpp1
-rw-r--r--audio/core/2.0/default/PrimaryDevice.cpp2
-rw-r--r--audio/core/2.0/default/Stream.cpp1
-rw-r--r--audio/core/2.0/default/StreamIn.cpp2
-rw-r--r--audio/core/2.0/default/StreamOut.cpp2
-rw-r--r--audio/core/2.0/default/include/core/2.0/default/Util.h26
-rw-r--r--audio/core/4.0/default/Device.cpp2
-rw-r--r--audio/core/4.0/default/ParametersUtil.cpp1
-rw-r--r--audio/core/4.0/default/PrimaryDevice.cpp2
-rw-r--r--audio/core/4.0/default/Stream.cpp1
-rw-r--r--audio/core/4.0/default/StreamIn.cpp2
-rw-r--r--audio/core/4.0/default/StreamOut.cpp2
-rw-r--r--audio/core/4.0/default/include/core/4.0/default/Util.h26
-rw-r--r--audio/core/all-versions/default/include/core/all-versions/default/Device.impl.h1
-rw-r--r--audio/core/all-versions/default/include/core/all-versions/default/ParametersUtil.impl.h21
-rw-r--r--audio/core/all-versions/default/include/core/all-versions/default/PrimaryDevice.impl.h4
-rw-r--r--audio/core/all-versions/default/include/core/all-versions/default/Stream.impl.h25
-rw-r--r--audio/core/all-versions/default/include/core/all-versions/default/StreamIn.impl.h2
-rw-r--r--audio/core/all-versions/default/include/core/all-versions/default/StreamOut.impl.h1
-rw-r--r--audio/core/all-versions/default/include/core/all-versions/default/Util.h49
21 files changed, 112 insertions, 63 deletions
diff --git a/audio/core/2.0/default/Device.cpp b/audio/core/2.0/default/Device.cpp
index 221ea5c0..b67203d5 100644
--- a/audio/core/2.0/default/Device.cpp
+++ b/audio/core/2.0/default/Device.cpp
@@ -21,7 +21,7 @@
21#include "core/2.0/default/Conversions.h" 21#include "core/2.0/default/Conversions.h"
22#include "core/2.0/default/StreamIn.h" 22#include "core/2.0/default/StreamIn.h"
23#include "core/2.0/default/StreamOut.h" 23#include "core/2.0/default/StreamOut.h"
24#include "core/all-versions/default/Util.h" 24#include "core/2.0/default/Util.h"
25 25
26#define AUDIO_HAL_VERSION V2_0 26#define AUDIO_HAL_VERSION V2_0
27#include <core/all-versions/default/Device.impl.h> 27#include <core/all-versions/default/Device.impl.h>
diff --git a/audio/core/2.0/default/ParametersUtil.cpp b/audio/core/2.0/default/ParametersUtil.cpp
index 33a3ad9b..963e291d 100644
--- a/audio/core/2.0/default/ParametersUtil.cpp
+++ b/audio/core/2.0/default/ParametersUtil.cpp
@@ -15,6 +15,7 @@
15 */ 15 */
16 16
17#include "core/2.0/default/ParametersUtil.h" 17#include "core/2.0/default/ParametersUtil.h"
18#include "core/2.0/default/Util.h"
18 19
19#define AUDIO_HAL_VERSION V2_0 20#define AUDIO_HAL_VERSION V2_0
20#include <core/all-versions/default/ParametersUtil.impl.h> 21#include <core/all-versions/default/ParametersUtil.impl.h>
diff --git a/audio/core/2.0/default/PrimaryDevice.cpp b/audio/core/2.0/default/PrimaryDevice.cpp
index ce574038..decaa146 100644
--- a/audio/core/2.0/default/PrimaryDevice.cpp
+++ b/audio/core/2.0/default/PrimaryDevice.cpp
@@ -17,7 +17,7 @@
17#define LOG_TAG "PrimaryDeviceHAL" 17#define LOG_TAG "PrimaryDeviceHAL"
18 18
19#include "core/2.0/default/PrimaryDevice.h" 19#include "core/2.0/default/PrimaryDevice.h"
20#include "core/all-versions/default/Util.h" 20#include "core/2.0/default/Util.h"
21 21
22#define AUDIO_HAL_VERSION V2_0 22#define AUDIO_HAL_VERSION V2_0
23#include <core/all-versions/default/PrimaryDevice.impl.h> 23#include <core/all-versions/default/PrimaryDevice.impl.h>
diff --git a/audio/core/2.0/default/Stream.cpp b/audio/core/2.0/default/Stream.cpp
index 69ee6598..0863a7c3 100644
--- a/audio/core/2.0/default/Stream.cpp
+++ b/audio/core/2.0/default/Stream.cpp
@@ -19,6 +19,7 @@
19#include "core/2.0/default/Stream.h" 19#include "core/2.0/default/Stream.h"
20#include "common/all-versions/default/EffectMap.h" 20#include "common/all-versions/default/EffectMap.h"
21#include "core/2.0/default/Conversions.h" 21#include "core/2.0/default/Conversions.h"
22#include "core/2.0/default/Util.h"
22 23
23#define AUDIO_HAL_VERSION V2_0 24#define AUDIO_HAL_VERSION V2_0
24#include <core/all-versions/default/Stream.impl.h> 25#include <core/all-versions/default/Stream.impl.h>
diff --git a/audio/core/2.0/default/StreamIn.cpp b/audio/core/2.0/default/StreamIn.cpp
index 6b8776eb..2021df1c 100644
--- a/audio/core/2.0/default/StreamIn.cpp
+++ b/audio/core/2.0/default/StreamIn.cpp
@@ -17,7 +17,7 @@
17#define LOG_TAG "StreamInHAL" 17#define LOG_TAG "StreamInHAL"
18 18
19#include "core/2.0/default/StreamIn.h" 19#include "core/2.0/default/StreamIn.h"
20#include "core/all-versions/default/Util.h" 20#include "core/2.0/default/Util.h"
21 21
22#define AUDIO_HAL_VERSION V2_0 22#define AUDIO_HAL_VERSION V2_0
23#include <core/all-versions/default/StreamIn.impl.h> 23#include <core/all-versions/default/StreamIn.impl.h>
diff --git a/audio/core/2.0/default/StreamOut.cpp b/audio/core/2.0/default/StreamOut.cpp
index 7f1461ac..940a2512 100644
--- a/audio/core/2.0/default/StreamOut.cpp
+++ b/audio/core/2.0/default/StreamOut.cpp
@@ -17,7 +17,7 @@
17#define LOG_TAG "StreamOutHAL" 17#define LOG_TAG "StreamOutHAL"
18 18
19#include "core/2.0/default/StreamOut.h" 19#include "core/2.0/default/StreamOut.h"
20#include "core/all-versions/default/Util.h" 20#include "core/2.0/default/Util.h"
21 21
22#define AUDIO_HAL_VERSION V2_0 22#define AUDIO_HAL_VERSION V2_0
23#include <core/all-versions/default/StreamOut.impl.h> 23#include <core/all-versions/default/StreamOut.impl.h>
diff --git a/audio/core/2.0/default/include/core/2.0/default/Util.h b/audio/core/2.0/default/include/core/2.0/default/Util.h
new file mode 100644
index 00000000..1f0e284d
--- /dev/null
+++ b/audio/core/2.0/default/include/core/2.0/default/Util.h
@@ -0,0 +1,26 @@
1/*
2 * Copyright (C) 2018 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#ifndef ANDROID_HARDWARE_AUDIO_V2_0_UTIL_H
18#define ANDROID_HARDWARE_AUDIO_V2_0_UTIL_H
19
20#include <android/hardware/audio/2.0/types.h>
21
22#define AUDIO_HAL_VERSION V2_0
23#include <core/all-versions/default/Util.h>
24#undef AUDIO_HAL_VERSION
25
26#endif // ANDROID_HARDWARE_AUDIO_V2_0_UTIL_H
diff --git a/audio/core/4.0/default/Device.cpp b/audio/core/4.0/default/Device.cpp
index 26f9ab4a..b33434ec 100644
--- a/audio/core/4.0/default/Device.cpp
+++ b/audio/core/4.0/default/Device.cpp
@@ -21,7 +21,7 @@
21#include "core/4.0/default/Conversions.h" 21#include "core/4.0/default/Conversions.h"
22#include "core/4.0/default/StreamIn.h" 22#include "core/4.0/default/StreamIn.h"
23#include "core/4.0/default/StreamOut.h" 23#include "core/4.0/default/StreamOut.h"
24#include "core/all-versions/default/Util.h" 24#include "core/4.0/default/Util.h"
25 25
26#define AUDIO_HAL_VERSION V4_0 26#define AUDIO_HAL_VERSION V4_0
27#include <core/all-versions/default/Device.impl.h> 27#include <core/all-versions/default/Device.impl.h>
diff --git a/audio/core/4.0/default/ParametersUtil.cpp b/audio/core/4.0/default/ParametersUtil.cpp
index 5c1b1c4b..2cc9fb56 100644
--- a/audio/core/4.0/default/ParametersUtil.cpp
+++ b/audio/core/4.0/default/ParametersUtil.cpp
@@ -15,6 +15,7 @@
15 */ 15 */
16 16
17#include "core/4.0/default/ParametersUtil.h" 17#include "core/4.0/default/ParametersUtil.h"
18#include "core/4.0/default/Util.h"
18 19
19#define AUDIO_HAL_VERSION V4_0 20#define AUDIO_HAL_VERSION V4_0
20#include <core/all-versions/default/ParametersUtil.impl.h> 21#include <core/all-versions/default/ParametersUtil.impl.h>
diff --git a/audio/core/4.0/default/PrimaryDevice.cpp b/audio/core/4.0/default/PrimaryDevice.cpp
index 0294b4d0..e3e49768 100644
--- a/audio/core/4.0/default/PrimaryDevice.cpp
+++ b/audio/core/4.0/default/PrimaryDevice.cpp
@@ -17,7 +17,7 @@
17#define LOG_TAG "PrimaryDeviceHAL" 17#define LOG_TAG "PrimaryDeviceHAL"
18 18
19#include "core/4.0/default/PrimaryDevice.h" 19#include "core/4.0/default/PrimaryDevice.h"
20#include "core/all-versions/default/Util.h" 20#include "core/4.0/default/Util.h"
21 21
22#define AUDIO_HAL_VERSION V4_0 22#define AUDIO_HAL_VERSION V4_0
23#include <core/all-versions/default/PrimaryDevice.impl.h> 23#include <core/all-versions/default/PrimaryDevice.impl.h>
diff --git a/audio/core/4.0/default/Stream.cpp b/audio/core/4.0/default/Stream.cpp
index 30b34544..b8c71de7 100644
--- a/audio/core/4.0/default/Stream.cpp
+++ b/audio/core/4.0/default/Stream.cpp
@@ -19,6 +19,7 @@
19#include "core/4.0/default/Stream.h" 19#include "core/4.0/default/Stream.h"
20#include "common/all-versions/default/EffectMap.h" 20#include "common/all-versions/default/EffectMap.h"
21#include "core/4.0/default/Conversions.h" 21#include "core/4.0/default/Conversions.h"
22#include "core/4.0/default/Util.h"
22 23
23#define AUDIO_HAL_VERSION V4_0 24#define AUDIO_HAL_VERSION V4_0
24#include <core/all-versions/default/Stream.impl.h> 25#include <core/all-versions/default/Stream.impl.h>
diff --git a/audio/core/4.0/default/StreamIn.cpp b/audio/core/4.0/default/StreamIn.cpp
index 18719b5d..718bd25a 100644
--- a/audio/core/4.0/default/StreamIn.cpp
+++ b/audio/core/4.0/default/StreamIn.cpp
@@ -17,7 +17,7 @@
17#define LOG_TAG "StreamInHAL" 17#define LOG_TAG "StreamInHAL"
18 18
19#include "core/4.0/default/StreamIn.h" 19#include "core/4.0/default/StreamIn.h"
20#include "core/all-versions/default/Util.h" 20#include "core/4.0/default/Util.h"
21 21
22#define AUDIO_HAL_VERSION V4_0 22#define AUDIO_HAL_VERSION V4_0
23#include <core/all-versions/default/StreamIn.impl.h> 23#include <core/all-versions/default/StreamIn.impl.h>
diff --git a/audio/core/4.0/default/StreamOut.cpp b/audio/core/4.0/default/StreamOut.cpp
index 11c8fde6..db88e401 100644
--- a/audio/core/4.0/default/StreamOut.cpp
+++ b/audio/core/4.0/default/StreamOut.cpp
@@ -17,7 +17,7 @@
17#define LOG_TAG "StreamOutHAL" 17#define LOG_TAG "StreamOutHAL"
18 18
19#include "core/4.0/default/StreamOut.h" 19#include "core/4.0/default/StreamOut.h"
20#include "core/all-versions/default/Util.h" 20#include "core/4.0/default/Util.h"
21 21
22#define AUDIO_HAL_VERSION V4_0 22#define AUDIO_HAL_VERSION V4_0
23#include <core/all-versions/default/StreamOut.impl.h> 23#include <core/all-versions/default/StreamOut.impl.h>
diff --git a/audio/core/4.0/default/include/core/4.0/default/Util.h b/audio/core/4.0/default/include/core/4.0/default/Util.h
new file mode 100644
index 00000000..ce31e6f7
--- /dev/null
+++ b/audio/core/4.0/default/include/core/4.0/default/Util.h
@@ -0,0 +1,26 @@
1/*
2 * Copyright (C) 2018 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#ifndef ANDROID_HARDWARE_AUDIO_V4_0_UTIL_H
18#define ANDROID_HARDWARE_AUDIO_V4_0_UTIL_H
19
20#include <android/hardware/audio/4.0/types.h>
21
22#define AUDIO_HAL_VERSION V4_0
23#include <core/all-versions/default/Util.h>
24#undef AUDIO_HAL_VERSION
25
26#endif // ANDROID_HARDWARE_AUDIO_V4_0_UTIL_H
diff --git a/audio/core/all-versions/default/include/core/all-versions/default/Device.impl.h b/audio/core/all-versions/default/include/core/all-versions/default/Device.impl.h
index 581e1dcc..37b7124a 100644
--- a/audio/core/all-versions/default/include/core/all-versions/default/Device.impl.h
+++ b/audio/core/all-versions/default/include/core/all-versions/default/Device.impl.h
@@ -25,7 +25,6 @@
25#include <android/log.h> 25#include <android/log.h>
26 26
27using ::android::hardware::audio::common::AUDIO_HAL_VERSION::HidlUtils; 27using ::android::hardware::audio::common::AUDIO_HAL_VERSION::HidlUtils;
28using ::android::hardware::audio::all_versions::implementation::isGainNormalized;
29 28
30namespace android { 29namespace android {
31namespace hardware { 30namespace hardware {
diff --git a/audio/core/all-versions/default/include/core/all-versions/default/ParametersUtil.impl.h b/audio/core/all-versions/default/include/core/all-versions/default/ParametersUtil.impl.h
index 39072840..afff2b6d 100644
--- a/audio/core/all-versions/default/include/core/all-versions/default/ParametersUtil.impl.h
+++ b/audio/core/all-versions/default/include/core/all-versions/default/ParametersUtil.impl.h
@@ -149,26 +149,7 @@ Result ParametersUtil::setParam(const char* name, const DeviceAddress& address)
149 149
150Result ParametersUtil::setParams(const AudioParameter& param) { 150Result ParametersUtil::setParams(const AudioParameter& param) {
151 int halStatus = halSetParameters(param.toString().string()); 151 int halStatus = halSetParameters(param.toString().string());
152 switch (halStatus) { 152 return util::analyzeStatus(halStatus);
153 case OK:
154 return Result::OK;
155 case -EINVAL:
156 return Result::INVALID_ARGUMENTS;
157 case -ENODATA:
158 return Result::INVALID_STATE;
159 case -ENODEV:
160 return Result::NOT_INITIALIZED;
161 // The rest of the API (*::analyseStatus) returns NOT_SUPPORTED
162 // when the legacy API returns -ENOSYS
163 // However the legacy API explicitly state that for get_paramers,
164 // -ENOSYS should be returned if
165 // "the implementation does not accept a parameter change while the
166 // output is active but the parameter is acceptable otherwise"
167 case -ENOSYS:
168 return Result::INVALID_STATE;
169 default:
170 return Result::INVALID_ARGUMENTS;
171 }
172} 153}
173 154
174} // namespace implementation 155} // namespace implementation
diff --git a/audio/core/all-versions/default/include/core/all-versions/default/PrimaryDevice.impl.h b/audio/core/all-versions/default/include/core/all-versions/default/PrimaryDevice.impl.h
index 9b39d9c9..61ffbe00 100644
--- a/audio/core/all-versions/default/include/core/all-versions/default/PrimaryDevice.impl.h
+++ b/audio/core/all-versions/default/include/core/all-versions/default/PrimaryDevice.impl.h
@@ -160,7 +160,7 @@ Return<Result> PrimaryDevice::setConnectedState(const DeviceAddress& address, bo
160 160
161// Methods from ::android::hardware::audio::AUDIO_HAL_VERSION::IPrimaryDevice follow. 161// Methods from ::android::hardware::audio::AUDIO_HAL_VERSION::IPrimaryDevice follow.
162Return<Result> PrimaryDevice::setVoiceVolume(float volume) { 162Return<Result> PrimaryDevice::setVoiceVolume(float volume) {
163 if (!all_versions::implementation::isGainNormalized(volume)) { 163 if (!isGainNormalized(volume)) {
164 ALOGW("Can not set a voice volume (%f) outside [0,1]", volume); 164 ALOGW("Can not set a voice volume (%f) outside [0,1]", volume);
165 return Result::INVALID_ARGUMENTS; 165 return Result::INVALID_ARGUMENTS;
166 } 166 }
@@ -248,7 +248,7 @@ Return<Result> PrimaryDevice::setBtHfpSampleRate(uint32_t sampleRateHz) {
248 return mDevice->setParam(AUDIO_PARAMETER_KEY_HFP_SET_SAMPLING_RATE, int(sampleRateHz)); 248 return mDevice->setParam(AUDIO_PARAMETER_KEY_HFP_SET_SAMPLING_RATE, int(sampleRateHz));
249} 249}
250Return<Result> PrimaryDevice::setBtHfpVolume(float volume) { 250Return<Result> PrimaryDevice::setBtHfpVolume(float volume) {
251 if (!all_versions::implementation::isGainNormalized(volume)) { 251 if (!isGainNormalized(volume)) {
252 ALOGW("Can not set BT HFP volume (%f) outside [0,1]", volume); 252 ALOGW("Can not set BT HFP volume (%f) outside [0,1]", volume);
253 return Result::INVALID_ARGUMENTS; 253 return Result::INVALID_ARGUMENTS;
254 } 254 }
diff --git a/audio/core/all-versions/default/include/core/all-versions/default/Stream.impl.h b/audio/core/all-versions/default/include/core/all-versions/default/Stream.impl.h
index fa0ef45b..74151125 100644
--- a/audio/core/all-versions/default/include/core/all-versions/default/Stream.impl.h
+++ b/audio/core/all-versions/default/include/core/all-versions/default/Stream.impl.h
@@ -39,35 +39,14 @@ Stream::~Stream() {
39 39
40// static 40// static
41Result Stream::analyzeStatus(const char* funcName, int status) { 41Result Stream::analyzeStatus(const char* funcName, int status) {
42 static const std::vector<int> empty; 42 return util::analyzeStatus("stream", funcName, status);
43 return analyzeStatus(funcName, status, empty);
44} 43}
45 44
46template <typename T>
47inline bool element_in(T e, const std::vector<T>& v) {
48 return std::find(v.begin(), v.end(), e) != v.end();
49}
50 45
51// static 46// static
52Result Stream::analyzeStatus(const char* funcName, int status, 47Result Stream::analyzeStatus(const char* funcName, int status,
53 const std::vector<int>& ignoreErrors) { 48 const std::vector<int>& ignoreErrors) {
54 if (status != 0 && (ignoreErrors.empty() || !element_in(-status, ignoreErrors))) { 49 return util::analyzeStatus("stream", funcName, status, ignoreErrors);
55 ALOGW("Error from HAL stream in function %s: %s", funcName, strerror(-status));
56 }
57 switch (status) {
58 case 0:
59 return Result::OK;
60 case -EINVAL:
61 return Result::INVALID_ARGUMENTS;
62 case -ENODATA:
63 return Result::INVALID_STATE;
64 case -ENODEV:
65 return Result::NOT_INITIALIZED;
66 case -ENOSYS:
67 return Result::NOT_SUPPORTED;
68 default:
69 return Result::INVALID_STATE;
70 }
71} 50}
72 51
73char* Stream::halGetParameters(const char* keys) { 52char* Stream::halGetParameters(const char* keys) {
diff --git a/audio/core/all-versions/default/include/core/all-versions/default/StreamIn.impl.h b/audio/core/all-versions/default/include/core/all-versions/default/StreamIn.impl.h
index 8774be90..64c85ab5 100644
--- a/audio/core/all-versions/default/include/core/all-versions/default/StreamIn.impl.h
+++ b/audio/core/all-versions/default/include/core/all-versions/default/StreamIn.impl.h
@@ -25,9 +25,7 @@
25#include <memory> 25#include <memory>
26 26
27using ::android::hardware::audio::AUDIO_HAL_VERSION::MessageQueueFlagBits; 27using ::android::hardware::audio::AUDIO_HAL_VERSION::MessageQueueFlagBits;
28using ::android::hardware::audio::all_versions::implementation::isGainNormalized;
29#include "Conversions.h" 28#include "Conversions.h"
30#include "Util.h"
31 29
32namespace android { 30namespace android {
33namespace hardware { 31namespace hardware {
diff --git a/audio/core/all-versions/default/include/core/all-versions/default/StreamOut.impl.h b/audio/core/all-versions/default/include/core/all-versions/default/StreamOut.impl.h
index 77098a81..6fb157f7 100644
--- a/audio/core/all-versions/default/include/core/all-versions/default/StreamOut.impl.h
+++ b/audio/core/all-versions/default/include/core/all-versions/default/StreamOut.impl.h
@@ -32,7 +32,6 @@ namespace AUDIO_HAL_VERSION {
32namespace implementation { 32namespace implementation {
33 33
34using ::android::hardware::audio::common::AUDIO_HAL_VERSION::ThreadInfo; 34using ::android::hardware::audio::common::AUDIO_HAL_VERSION::ThreadInfo;
35using ::android::hardware::audio::all_versions::implementation::isGainNormalized;
36 35
37namespace { 36namespace {
38 37
diff --git a/audio/core/all-versions/default/include/core/all-versions/default/Util.h b/audio/core/all-versions/default/include/core/all-versions/default/Util.h
index 39d9dbde..350fd867 100644
--- a/audio/core/all-versions/default/include/core/all-versions/default/Util.h
+++ b/audio/core/all-versions/default/include/core/all-versions/default/Util.h
@@ -14,24 +14,61 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17#ifndef ANDROID_HARDWARE_AUDIO_DEVICE_ALL_VERSIONS_UTIL_H 17#include <common/all-versions/IncludeGuard.h>
18#define ANDROID_HARDWARE_AUDIO_DEVICE_ALL_VERSIONS_UTIL_H 18
19#include <algorithm>
20#include <vector>
21
22#include <system/audio.h>
19 23
20namespace android { 24namespace android {
21namespace hardware { 25namespace hardware {
22namespace audio { 26namespace audio {
23namespace all_versions { 27namespace AUDIO_HAL_VERSION {
24namespace implementation { 28namespace implementation {
25 29
30using ::android::hardware::audio::AUDIO_HAL_VERSION::Result;
31
26/** @return true if gain is between 0 and 1 included. */ 32/** @return true if gain is between 0 and 1 included. */
27constexpr bool isGainNormalized(float gain) { 33constexpr bool isGainNormalized(float gain) {
28 return gain >= 0.0 && gain <= 1.0; 34 return gain >= 0.0 && gain <= 1.0;
29} 35}
30 36
37namespace util {
38
39template <typename T>
40inline bool element_in(T e, const std::vector<T>& v) {
41 return std::find(v.begin(), v.end(), e) != v.end();
42}
43
44static inline Result analyzeStatus(status_t status) {
45 switch (status) {
46 case 0:
47 return Result::OK;
48 case -EINVAL:
49 return Result::INVALID_ARGUMENTS;
50 case -ENODATA:
51 return Result::INVALID_STATE;
52 case -ENODEV:
53 return Result::NOT_INITIALIZED;
54 case -ENOSYS:
55 return Result::NOT_SUPPORTED;
56 default:
57 return Result::INVALID_STATE;
58 }
59}
60
61static inline Result analyzeStatus(const char* className, const char* funcName, status_t status,
62 const std::vector<int>& ignoreErrors = {}) {
63 if (status != 0 && !element_in(-status, ignoreErrors)) {
64 ALOGW("Error from HAL %s in function %s: %s", className, funcName, strerror(-status));
65 }
66 return analyzeStatus(status);
67}
68
69} // namespace util
31} // namespace implementation 70} // namespace implementation
32} // namespace all_versions 71} // namespace AUDIO_HAL_VERSION
33} // namespace audio 72} // namespace audio
34} // namespace hardware 73} // namespace hardware
35} // namespace android 74} // namespace android
36
37#endif // ANDROID_HARDWARE_AUDIO_DEVICE_ALL_VERSIONS_UTIL_H