• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifdef CHRE_AUDIO_SUPPORT_ENABLED
24 #include "chre/platform/platform_audio.h"
25 #endif  // CHRE_AUDIO_SUPPORT_ENABLED
26 
27 using chre::EventLoopManager;
28 using chre::EventLoopManagerSingleton;
29 using chre::Nanoapp;
30 using chre::NanoappPermissions;
31 
chreAudioGetSource(uint32_t handle,struct chreAudioSource * audioSource)32 DLL_EXPORT bool chreAudioGetSource(uint32_t handle,
33                                    struct chreAudioSource *audioSource) {
34 #ifdef CHRE_AUDIO_SUPPORT_ENABLED
35   bool success = false;
36   if (audioSource != nullptr) {
37     success = EventLoopManagerSingleton::get()
38                   ->getAudioRequestManager()
39                   .getAudioSource(handle, audioSource);
40   }
41 
42   return success;
43 #else
44   return false;
45 #endif  // CHRE_AUDIO_SUPPORT_ENABLED
46 }
47 
chreAudioConfigureSource(uint32_t handle,bool enable,uint64_t bufferDuration,uint64_t deliveryInterval)48 DLL_EXPORT bool chreAudioConfigureSource(uint32_t handle, bool enable,
49                                          uint64_t bufferDuration,
50                                          uint64_t deliveryInterval) {
51 #ifdef CHRE_AUDIO_SUPPORT_ENABLED
52   Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
53   return nanoapp->permitPermissionUse(NanoappPermissions::CHRE_PERMS_AUDIO) &&
54          EventLoopManagerSingleton::get()
55              ->getAudioRequestManager()
56              .configureSource(nanoapp, handle, enable, bufferDuration,
57                               deliveryInterval);
58 #else
59   return false;
60 #endif  // CHRE_AUDIO_SUPPORT_ENABLED
61 }
62