| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2009 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 |  | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 17 | #define LOG_TAG "AudioPolicyClientImpl" | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 18 | //#define LOG_NDEBUG 0 | 
 | 19 |  | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 20 | #include "AudioPolicyService.h" | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 21 |  | 
| Ytai Ben-Tsvi | 74cd6b0 | 2019-10-25 10:06:40 -0700 | [diff] [blame] | 22 | #include <utils/Log.h> | 
 | 23 |  | 
 | 24 | #include "BinderProxy.h" | 
 | 25 |  | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 26 | namespace android { | 
 | 27 |  | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 28 | /* implementation of the client interface from the policy manager */ | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 29 |  | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 30 | audio_module_handle_t AudioPolicyService::AudioPolicyClient::loadHwModule(const char *name) | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 31 | { | 
 | 32 |     sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); | 
 | 33 |     if (af == 0) { | 
 | 34 |         ALOGW("%s: could not get AudioFlinger", __func__); | 
| Glenn Kasten | a13cde9 | 2016-03-28 15:26:02 -0700 | [diff] [blame] | 35 |         return AUDIO_MODULE_HANDLE_NONE; | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 36 |     } | 
 | 37 |  | 
 | 38 |     return af->loadHwModule(name); | 
 | 39 | } | 
 | 40 |  | 
| Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 41 | status_t AudioPolicyService::AudioPolicyClient::openOutput(audio_module_handle_t module, | 
 | 42 |                                                            audio_io_handle_t *output, | 
 | 43 |                                                            audio_config_t *config, | 
| jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 44 |                                                            const sp<DeviceDescriptorBase>& device, | 
| Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 45 |                                                            uint32_t *latencyMs, | 
 | 46 |                                                            audio_output_flags_t flags) | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 47 | { | 
 | 48 |     sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); | 
 | 49 |     if (af == 0) { | 
 | 50 |         ALOGW("%s: could not get AudioFlinger", __func__); | 
| Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 51 |         return PERMISSION_DENIED; | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 52 |     } | 
| jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 53 |     return af->openOutput(module, output, config, device, latencyMs, flags); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 54 | } | 
 | 55 |  | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 56 | audio_io_handle_t AudioPolicyService::AudioPolicyClient::openDuplicateOutput( | 
 | 57 |                                                                 audio_io_handle_t output1, | 
 | 58 |                                                                 audio_io_handle_t output2) | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 59 | { | 
 | 60 |     sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); | 
 | 61 |     if (af == 0) { | 
 | 62 |         ALOGW("%s: could not get AudioFlinger", __func__); | 
 | 63 |         return 0; | 
 | 64 |     } | 
 | 65 |     return af->openDuplicateOutput(output1, output2); | 
 | 66 | } | 
 | 67 |  | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 68 | status_t AudioPolicyService::AudioPolicyClient::closeOutput(audio_io_handle_t output) | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 69 | { | 
 | 70 |     sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); | 
 | 71 |     if (af == 0) { | 
 | 72 |         return PERMISSION_DENIED; | 
 | 73 |     } | 
 | 74 |  | 
 | 75 |     return af->closeOutput(output); | 
 | 76 | } | 
 | 77 |  | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 78 | status_t AudioPolicyService::AudioPolicyClient::suspendOutput(audio_io_handle_t output) | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 79 | { | 
 | 80 |     sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); | 
 | 81 |     if (af == 0) { | 
 | 82 |         ALOGW("%s: could not get AudioFlinger", __func__); | 
 | 83 |         return PERMISSION_DENIED; | 
 | 84 |     } | 
 | 85 |  | 
 | 86 |     return af->suspendOutput(output); | 
 | 87 | } | 
 | 88 |  | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 89 | status_t AudioPolicyService::AudioPolicyClient::restoreOutput(audio_io_handle_t output) | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 90 | { | 
 | 91 |     sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); | 
 | 92 |     if (af == 0) { | 
 | 93 |         ALOGW("%s: could not get AudioFlinger", __func__); | 
 | 94 |         return PERMISSION_DENIED; | 
 | 95 |     } | 
 | 96 |  | 
 | 97 |     return af->restoreOutput(output); | 
 | 98 | } | 
 | 99 |  | 
| Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 100 | status_t AudioPolicyService::AudioPolicyClient::openInput(audio_module_handle_t module, | 
 | 101 |                                                           audio_io_handle_t *input, | 
 | 102 |                                                           audio_config_t *config, | 
 | 103 |                                                           audio_devices_t *device, | 
 | 104 |                                                           const String8& address, | 
 | 105 |                                                           audio_source_t source, | 
 | 106 |                                                           audio_input_flags_t flags) | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 107 | { | 
 | 108 |     sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); | 
 | 109 |     if (af == 0) { | 
 | 110 |         ALOGW("%s: could not get AudioFlinger", __func__); | 
| Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 111 |         return PERMISSION_DENIED; | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 112 |     } | 
 | 113 |  | 
| Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 114 |     return af->openInput(module, input, config, device, address, source, flags); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 115 | } | 
 | 116 |  | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 117 | status_t AudioPolicyService::AudioPolicyClient::closeInput(audio_io_handle_t input) | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 118 | { | 
 | 119 |     sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); | 
 | 120 |     if (af == 0) { | 
 | 121 |         return PERMISSION_DENIED; | 
 | 122 |     } | 
 | 123 |  | 
 | 124 |     return af->closeInput(input); | 
 | 125 | } | 
 | 126 |  | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 127 | status_t AudioPolicyService::AudioPolicyClient::setStreamVolume(audio_stream_type_t stream, | 
 | 128 |                      float volume, audio_io_handle_t output, | 
 | 129 |                      int delay_ms) | 
 | 130 | { | 
 | 131 |     return mAudioPolicyService->setStreamVolume(stream, volume, output, | 
 | 132 |                                                delay_ms); | 
 | 133 | } | 
 | 134 |  | 
 | 135 | status_t AudioPolicyService::AudioPolicyClient::invalidateStream(audio_stream_type_t stream) | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 136 | { | 
 | 137 |     sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); | 
 | 138 |     if (af == 0) { | 
 | 139 |         return PERMISSION_DENIED; | 
 | 140 |     } | 
 | 141 |  | 
 | 142 |     return af->invalidateStream(stream); | 
 | 143 | } | 
 | 144 |  | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 145 | void AudioPolicyService::AudioPolicyClient::setParameters(audio_io_handle_t io_handle, | 
 | 146 |                    const String8& keyValuePairs, | 
 | 147 |                    int delay_ms) | 
 | 148 | { | 
 | 149 |     mAudioPolicyService->setParameters(io_handle, keyValuePairs.string(), delay_ms); | 
 | 150 | } | 
 | 151 |  | 
 | 152 | String8 AudioPolicyService::AudioPolicyClient::getParameters(audio_io_handle_t io_handle, | 
 | 153 |                       const String8& keys) | 
 | 154 | { | 
 | 155 |     String8 result = AudioSystem::getParameters(io_handle, keys); | 
 | 156 |     return result; | 
 | 157 | } | 
 | 158 |  | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 159 | status_t AudioPolicyService::AudioPolicyClient::setVoiceVolume(float volume, int delay_ms) | 
 | 160 | { | 
 | 161 |     return mAudioPolicyService->setVoiceVolume(volume, delay_ms); | 
 | 162 | } | 
 | 163 |  | 
| Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 164 | status_t AudioPolicyService::AudioPolicyClient::moveEffects(audio_session_t session, | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 165 |                         audio_io_handle_t src_output, | 
 | 166 |                         audio_io_handle_t dst_output) | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 167 | { | 
 | 168 |     sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); | 
 | 169 |     if (af == 0) { | 
 | 170 |         return PERMISSION_DENIED; | 
 | 171 |     } | 
 | 172 |  | 
 | 173 |     return af->moveEffects(session, src_output, dst_output); | 
 | 174 | } | 
 | 175 |  | 
| Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 176 | void AudioPolicyService::AudioPolicyClient::setEffectSuspended(int effectId, | 
 | 177 |                                 audio_session_t sessionId, | 
 | 178 |                                 bool suspended) | 
 | 179 | { | 
 | 180 |     mAudioPolicyService->setEffectSuspended(effectId, sessionId, suspended); | 
 | 181 | } | 
 | 182 |  | 
| Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 183 | status_t AudioPolicyService::AudioPolicyClient::createAudioPatch(const struct audio_patch *patch, | 
 | 184 |                                                                   audio_patch_handle_t *handle, | 
 | 185 |                                                                   int delayMs) | 
 | 186 | { | 
 | 187 |     return mAudioPolicyService->clientCreateAudioPatch(patch, handle, delayMs); | 
 | 188 | } | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 189 |  | 
| Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 190 | status_t AudioPolicyService::AudioPolicyClient::releaseAudioPatch(audio_patch_handle_t handle, | 
 | 191 |                                                                   int delayMs) | 
 | 192 | { | 
 | 193 |     return mAudioPolicyService->clientReleaseAudioPatch(handle, delayMs); | 
 | 194 | } | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 195 |  | 
| Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 196 | status_t AudioPolicyService::AudioPolicyClient::setAudioPortConfig( | 
 | 197 |                                                         const struct audio_port_config *config, | 
 | 198 |                                                         int delayMs) | 
 | 199 | { | 
 | 200 |     return mAudioPolicyService->clientSetAudioPortConfig(config, delayMs); | 
 | 201 | } | 
 | 202 |  | 
| Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 203 | void AudioPolicyService::AudioPolicyClient::onAudioPortListUpdate() | 
 | 204 | { | 
 | 205 |     mAudioPolicyService->onAudioPortListUpdate(); | 
 | 206 | } | 
 | 207 |  | 
 | 208 | void AudioPolicyService::AudioPolicyClient::onAudioPatchListUpdate() | 
 | 209 | { | 
 | 210 |     mAudioPolicyService->onAudioPatchListUpdate(); | 
 | 211 | } | 
 | 212 |  | 
| Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 213 | void AudioPolicyService::AudioPolicyClient::onDynamicPolicyMixStateUpdate( | 
 | 214 |         String8 regId, int32_t state) | 
 | 215 | { | 
 | 216 |     mAudioPolicyService->onDynamicPolicyMixStateUpdate(regId, state); | 
 | 217 | } | 
 | 218 |  | 
| Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 219 | void AudioPolicyService::AudioPolicyClient::onRecordingConfigurationUpdate( | 
| Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 220 |                                                     int event, | 
 | 221 |                                                     const record_client_info_t *clientInfo, | 
 | 222 |                                                     const audio_config_base_t *clientConfig, | 
 | 223 |                                                     std::vector<effect_descriptor_t> clientEffects, | 
 | 224 |                                                     const audio_config_base_t *deviceConfig, | 
 | 225 |                                                     std::vector<effect_descriptor_t> effects, | 
 | 226 |                                                     audio_patch_handle_t patchHandle, | 
 | 227 |                                                     audio_source_t source) | 
| Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 228 | { | 
| Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 229 |     mAudioPolicyService->onRecordingConfigurationUpdate(event, clientInfo, | 
| Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 230 |             clientConfig, clientEffects, deviceConfig, effects, patchHandle, source); | 
| Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 231 | } | 
 | 232 |  | 
| François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 233 | void AudioPolicyService::AudioPolicyClient::onAudioVolumeGroupChanged(volume_group_t group, | 
 | 234 |                                                                       int flags) | 
 | 235 | { | 
 | 236 |     mAudioPolicyService->onAudioVolumeGroupChanged(group, flags); | 
 | 237 | } | 
 | 238 |  | 
| Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 239 | audio_unique_id_t AudioPolicyService::AudioPolicyClient::newAudioUniqueId(audio_unique_id_use_t use) | 
| Eric Laurent | de3f839 | 2014-07-27 18:38:22 -0700 | [diff] [blame] | 240 | { | 
| Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 241 |     return AudioSystem::newAudioUniqueId(use); | 
| Eric Laurent | de3f839 | 2014-07-27 18:38:22 -0700 | [diff] [blame] | 242 | } | 
 | 243 |  | 
| Ytai Ben-Tsvi | 85093d5 | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 244 | void AudioPolicyService::AudioPolicyClient::setSoundTriggerCaptureState(bool active) | 
 | 245 | { | 
 | 246 |     mAudioPolicyService->mCaptureStateNotifier.setCaptureState(active); | 
| Ytai Ben-Tsvi | 74cd6b0 | 2019-10-25 10:06:40 -0700 | [diff] [blame] | 247 | } | 
 | 248 |  | 
| Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 249 | } // namespace android |