1 /*
2 * Copyright (C) 2017 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 "chre_api/chre/audio.h"
18
19 #include "chre/core/event_loop_manager.h"
20 #include "chre/util/macros.h"
21 #include "chre/util/system/napp_permissions.h"
22
23 using chre::EventLoopManager;
24 using chre::EventLoopManagerSingleton;
25 using chre::Nanoapp;
26 using chre::NanoappPermissions;
27
chreAudioGetSource(uint32_t handle,struct chreAudioSource * audioSource)28 DLL_EXPORT bool chreAudioGetSource(uint32_t handle,
29 struct chreAudioSource *audioSource) {
30 #ifdef CHRE_AUDIO_SUPPORT_ENABLED
31 bool success = false;
32 if (audioSource != nullptr) {
33 success = EventLoopManagerSingleton::get()
34 ->getAudioRequestManager()
35 .getAudioSource(handle, audioSource);
36 }
37
38 return success;
39 #else
40 UNUSED_VAR(handle);
41 UNUSED_VAR(audioSource);
42 return false;
43 #endif // CHRE_AUDIO_SUPPORT_ENABLED
44 }
45
chreAudioConfigureSource(uint32_t handle,bool enable,uint64_t bufferDuration,uint64_t deliveryInterval)46 DLL_EXPORT bool chreAudioConfigureSource(uint32_t handle, bool enable,
47 uint64_t bufferDuration,
48 uint64_t deliveryInterval) {
49 #ifdef CHRE_AUDIO_SUPPORT_ENABLED
50 Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
51 return nanoapp->permitPermissionUse(NanoappPermissions::CHRE_PERMS_AUDIO) &&
52 EventLoopManagerSingleton::get()
53 ->getAudioRequestManager()
54 .configureSource(nanoapp, handle, enable, bufferDuration,
55 deliveryInterval);
56 #else
57 UNUSED_VAR(handle);
58 UNUSED_VAR(enable);
59 UNUSED_VAR(bufferDuration);
60 UNUSED_VAR(deliveryInterval);
61 return false;
62 #endif // CHRE_AUDIO_SUPPORT_ENABLED
63 }
64
chreAudioGetStatus(uint32_t handle,struct chreAudioSourceStatus * status)65 DLL_EXPORT bool chreAudioGetStatus(uint32_t handle,
66 struct chreAudioSourceStatus *status) {
67 // TODO(b/174590023): either implement or deprecate this API
68 UNUSED_VAR(handle);
69 UNUSED_VAR(status);
70 return false;
71 }
72