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 "AudioPolicyIntefaceImpl" |
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" |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 21 | #include "TypeConverter.h" |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 22 | #include <media/MediaAnalyticsItem.h> |
| 23 | #include <mediautils/ServiceUtilities.h> |
Kevin Rocard | be20185 | 2019-02-20 22:33:28 -0800 | [diff] [blame] | 24 | #include <media/AudioPolicy.h> |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 25 | #include <utils/Log.h> |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 26 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 27 | namespace android { |
| 28 | |
| 29 | |
| 30 | // ---------------------------------------------------------------------------- |
| 31 | |
| 32 | status_t AudioPolicyService::setDeviceConnectionState(audio_devices_t device, |
| 33 | audio_policy_dev_state_t state, |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 34 | const char *device_address, |
Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 35 | const char *device_name, |
| 36 | audio_format_t encodedFormat) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 37 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 38 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 39 | return NO_INIT; |
| 40 | } |
| 41 | if (!settingsAllowed()) { |
| 42 | return PERMISSION_DENIED; |
| 43 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 44 | if (state != AUDIO_POLICY_DEVICE_STATE_AVAILABLE && |
| 45 | state != AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) { |
| 46 | return BAD_VALUE; |
| 47 | } |
| 48 | |
| 49 | ALOGV("setDeviceConnectionState()"); |
| 50 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 51 | AutoCallerClear acc; |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 52 | return mAudioPolicyManager->setDeviceConnectionState(device, state, |
Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 53 | device_address, device_name, encodedFormat); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | audio_policy_dev_state_t AudioPolicyService::getDeviceConnectionState( |
| 57 | audio_devices_t device, |
| 58 | const char *device_address) |
| 59 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 60 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 61 | return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE; |
| 62 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 63 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 64 | return mAudioPolicyManager->getDeviceConnectionState(device, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 65 | device_address); |
| 66 | } |
| 67 | |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 68 | status_t AudioPolicyService::handleDeviceConfigChange(audio_devices_t device, |
| 69 | const char *device_address, |
Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 70 | const char *device_name, |
| 71 | audio_format_t encodedFormat) |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 72 | { |
| 73 | if (mAudioPolicyManager == NULL) { |
| 74 | return NO_INIT; |
| 75 | } |
| 76 | if (!settingsAllowed()) { |
| 77 | return PERMISSION_DENIED; |
| 78 | } |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 79 | |
| 80 | ALOGV("handleDeviceConfigChange()"); |
| 81 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 82 | AutoCallerClear acc; |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 83 | return mAudioPolicyManager->handleDeviceConfigChange(device, device_address, |
Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 84 | device_name, encodedFormat); |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 85 | } |
| 86 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 87 | status_t AudioPolicyService::setPhoneState(audio_mode_t state) |
| 88 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 89 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 90 | return NO_INIT; |
| 91 | } |
| 92 | if (!settingsAllowed()) { |
| 93 | return PERMISSION_DENIED; |
| 94 | } |
| 95 | if (uint32_t(state) >= AUDIO_MODE_CNT) { |
| 96 | return BAD_VALUE; |
| 97 | } |
| 98 | |
| 99 | ALOGV("setPhoneState()"); |
| 100 | |
Eric Laurent | beb07fe | 2015-09-16 15:49:30 -0700 | [diff] [blame] | 101 | // acquire lock before calling setMode() so that setMode() + setPhoneState() are an atomic |
| 102 | // operation from policy manager standpoint (no other operation (e.g track start or stop) |
| 103 | // can be interleaved). |
| 104 | Mutex::Autolock _l(mLock); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 105 | // TODO: check if it is more appropriate to do it in platform specific policy manager |
| 106 | AudioSystem::setMode(state); |
| 107 | |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 108 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 109 | mAudioPolicyManager->setPhoneState(state); |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 110 | mPhoneState = state; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 111 | return NO_ERROR; |
| 112 | } |
| 113 | |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 114 | audio_mode_t AudioPolicyService::getPhoneState() |
| 115 | { |
| 116 | Mutex::Autolock _l(mLock); |
| 117 | return mPhoneState; |
| 118 | } |
| 119 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 120 | status_t AudioPolicyService::setForceUse(audio_policy_force_use_t usage, |
| 121 | audio_policy_forced_cfg_t config) |
| 122 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 123 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 124 | return NO_INIT; |
| 125 | } |
Eric Laurent | e17378d | 2018-05-09 14:43:01 -0700 | [diff] [blame] | 126 | |
| 127 | if (!modifyAudioRoutingAllowed()) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 128 | return PERMISSION_DENIED; |
| 129 | } |
Eric Laurent | e17378d | 2018-05-09 14:43:01 -0700 | [diff] [blame] | 130 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 131 | if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) { |
| 132 | return BAD_VALUE; |
| 133 | } |
| 134 | if (config < 0 || config >= AUDIO_POLICY_FORCE_CFG_CNT) { |
| 135 | return BAD_VALUE; |
| 136 | } |
| 137 | ALOGV("setForceUse()"); |
| 138 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 139 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 140 | mAudioPolicyManager->setForceUse(usage, config); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 141 | return NO_ERROR; |
| 142 | } |
| 143 | |
| 144 | audio_policy_forced_cfg_t AudioPolicyService::getForceUse(audio_policy_force_use_t usage) |
| 145 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 146 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 147 | return AUDIO_POLICY_FORCE_NONE; |
| 148 | } |
| 149 | if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) { |
| 150 | return AUDIO_POLICY_FORCE_NONE; |
| 151 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 152 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 153 | return mAudioPolicyManager->getForceUse(usage); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 154 | } |
| 155 | |
Eric Laurent | f4e6345 | 2017-11-06 19:31:46 +0000 | [diff] [blame] | 156 | audio_io_handle_t AudioPolicyService::getOutput(audio_stream_type_t stream) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 157 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 158 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 159 | return AUDIO_IO_HANDLE_NONE; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 160 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 161 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 162 | return AUDIO_IO_HANDLE_NONE; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 163 | } |
| 164 | ALOGV("getOutput()"); |
| 165 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 166 | AutoCallerClear acc; |
Eric Laurent | f4e6345 | 2017-11-06 19:31:46 +0000 | [diff] [blame] | 167 | return mAudioPolicyManager->getOutput(stream); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 170 | status_t AudioPolicyService::getOutputForAttr(const audio_attributes_t *attr, |
| 171 | audio_io_handle_t *output, |
| 172 | audio_session_t session, |
| 173 | audio_stream_type_t *stream, |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 174 | pid_t pid, |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 175 | uid_t uid, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 176 | const audio_config_t *config, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 177 | audio_output_flags_t flags, |
Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 178 | audio_port_handle_t *selectedDeviceId, |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 179 | audio_port_handle_t *portId, |
| 180 | std::vector<audio_io_handle_t> *secondaryOutputs) |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 181 | { |
| 182 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 183 | return NO_INIT; |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 184 | } |
Eric Laurent | f4e6345 | 2017-11-06 19:31:46 +0000 | [diff] [blame] | 185 | ALOGV("getOutputForAttr()"); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 186 | Mutex::Autolock _l(mLock); |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 187 | |
Marco Nelissen | dcb346b | 2015-09-09 10:47:29 -0700 | [diff] [blame] | 188 | const uid_t callingUid = IPCThreadState::self()->getCallingUid(); |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 189 | if (!isAudioServerOrMediaServerUid(callingUid) || uid == (uid_t)-1) { |
Marco Nelissen | dcb346b | 2015-09-09 10:47:29 -0700 | [diff] [blame] | 190 | ALOGW_IF(uid != (uid_t)-1 && uid != callingUid, |
| 191 | "%s uid %d tried to pass itself off as %d", __FUNCTION__, callingUid, uid); |
| 192 | uid = callingUid; |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 193 | } |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 194 | audio_output_flags_t originalFlags = flags; |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 195 | AutoCallerClear acc; |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 196 | status_t result = mAudioPolicyManager->getOutputForAttr(attr, output, session, stream, uid, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 197 | config, |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 198 | &flags, selectedDeviceId, portId, |
| 199 | secondaryOutputs); |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 200 | |
| 201 | // FIXME: Introduce a way to check for the the telephony device before opening the output |
| 202 | if ((result == NO_ERROR) && |
| 203 | (flags & AUDIO_OUTPUT_FLAG_INCALL_MUSIC) && |
| 204 | !modifyPhoneStateAllowed(pid, uid)) { |
| 205 | // If the app tries to play music through the telephony device and doesn't have permission |
| 206 | // the fallback to the default output device. |
Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 207 | mAudioPolicyManager->releaseOutput(*portId); |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 208 | flags = originalFlags; |
| 209 | *selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 210 | *portId = AUDIO_PORT_HANDLE_NONE; |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 211 | secondaryOutputs->clear(); |
| 212 | result = mAudioPolicyManager->getOutputForAttr(attr, output, session, stream, uid, config, |
| 213 | &flags, selectedDeviceId, portId, |
| 214 | secondaryOutputs); |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 215 | } |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 216 | |
| 217 | if (result == NO_ERROR) { |
| 218 | sp <AudioPlaybackClient> client = |
| 219 | new AudioPlaybackClient(*attr, *output, uid, pid, session, *selectedDeviceId, *stream); |
| 220 | mAudioPlaybackClients.add(*portId, client); |
| 221 | } |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 222 | return result; |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 223 | } |
| 224 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 225 | status_t AudioPolicyService::startOutput(audio_port_handle_t portId) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 226 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 227 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 228 | return NO_INIT; |
| 229 | } |
| 230 | ALOGV("startOutput()"); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 231 | sp<AudioPlaybackClient> client; |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 232 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 233 | { |
| 234 | Mutex::Autolock _l(mLock); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 235 | const ssize_t index = mAudioPlaybackClients.indexOfKey(portId); |
| 236 | if (index < 0) { |
| 237 | ALOGE("%s AudioTrack client not found for portId %d", __FUNCTION__, portId); |
| 238 | return INVALID_OPERATION; |
| 239 | } |
| 240 | client = mAudioPlaybackClients.valueAt(index); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 241 | audioPolicyEffects = mAudioPolicyEffects; |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame] | 242 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 243 | if (audioPolicyEffects != 0) { |
| 244 | // create audio processors according to stream |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 245 | status_t status = audioPolicyEffects->addOutputSessionEffects( |
| 246 | client->io, client->stream, client->session); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 247 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 248 | ALOGW("Failed to add effects on session %d", client->session); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 252 | AutoCallerClear acc; |
Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 253 | status_t status = mAudioPolicyManager->startOutput(portId); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 254 | if (status == NO_ERROR) { |
| 255 | client->active = true; |
| 256 | } |
| 257 | return status; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 258 | } |
| 259 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 260 | status_t AudioPolicyService::stopOutput(audio_port_handle_t portId) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 261 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 262 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 263 | return NO_INIT; |
| 264 | } |
| 265 | ALOGV("stopOutput()"); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 266 | mOutputCommandThread->stopOutputCommand(portId); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 267 | return NO_ERROR; |
| 268 | } |
| 269 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 270 | status_t AudioPolicyService::doStopOutput(audio_port_handle_t portId) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 271 | { |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 272 | ALOGV("doStopOutput"); |
| 273 | sp<AudioPlaybackClient> client; |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 274 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 275 | { |
| 276 | Mutex::Autolock _l(mLock); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 277 | |
| 278 | const ssize_t index = mAudioPlaybackClients.indexOfKey(portId); |
| 279 | if (index < 0) { |
| 280 | ALOGE("%s AudioTrack client not found for portId %d", __FUNCTION__, portId); |
| 281 | return INVALID_OPERATION; |
| 282 | } |
| 283 | client = mAudioPlaybackClients.valueAt(index); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 284 | audioPolicyEffects = mAudioPolicyEffects; |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame] | 285 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 286 | if (audioPolicyEffects != 0) { |
| 287 | // release audio processors from the stream |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 288 | status_t status = audioPolicyEffects->releaseOutputSessionEffects( |
| 289 | client->io, client->stream, client->session); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 290 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 291 | ALOGW("Failed to release effects on session %d", client->session); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 295 | AutoCallerClear acc; |
Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 296 | status_t status = mAudioPolicyManager->stopOutput(portId); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 297 | if (status == NO_ERROR) { |
| 298 | client->active = false; |
| 299 | } |
| 300 | return status; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 301 | } |
| 302 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 303 | void AudioPolicyService::releaseOutput(audio_port_handle_t portId) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 304 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 305 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 306 | return; |
| 307 | } |
| 308 | ALOGV("releaseOutput()"); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 309 | mOutputCommandThread->releaseOutputCommand(portId); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 310 | } |
| 311 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 312 | void AudioPolicyService::doReleaseOutput(audio_port_handle_t portId) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 313 | { |
| 314 | ALOGV("doReleaseOutput from tid %d", gettid()); |
| 315 | Mutex::Autolock _l(mLock); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 316 | const ssize_t index = mAudioPlaybackClients.indexOfKey(portId); |
| 317 | if (index < 0) { |
| 318 | ALOGE("%s AudioTrack client not found for portId %d", __FUNCTION__, portId); |
| 319 | return; |
| 320 | } |
| 321 | sp<AudioPlaybackClient> client = mAudioPlaybackClients.valueAt(index); |
| 322 | mAudioRecordClients.removeItem(portId); |
| 323 | |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 324 | // called from internal thread: no need to clear caller identity |
Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 325 | mAudioPolicyManager->releaseOutput(portId); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 326 | } |
| 327 | |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 328 | status_t AudioPolicyService::getInputForAttr(const audio_attributes_t *attr, |
| 329 | audio_io_handle_t *input, |
| 330 | audio_session_t session, |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 331 | pid_t pid, |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 332 | uid_t uid, |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 333 | const String16& opPackageName, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 334 | const audio_config_base_t *config, |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 335 | audio_input_flags_t flags, |
Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 336 | audio_port_handle_t *selectedDeviceId, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 337 | audio_port_handle_t *portId) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 338 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 339 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 340 | return NO_INIT; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 341 | } |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 342 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 343 | // already checked by client, but double-check in case the client wrapper is bypassed |
Eric Laurent | ae4b6ec | 2019-01-15 18:34:38 -0800 | [diff] [blame] | 344 | if ((attr->source < AUDIO_SOURCE_DEFAULT) |
| 345 | || (attr->source >= AUDIO_SOURCE_CNT |
| 346 | && attr->source != AUDIO_SOURCE_HOTWORD |
| 347 | && attr->source != AUDIO_SOURCE_FM_TUNER |
| 348 | && attr->source != AUDIO_SOURCE_ECHO_REFERENCE)) { |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 349 | return BAD_VALUE; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 350 | } |
| 351 | |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 352 | bool updatePid = (pid == -1); |
Marco Nelissen | dcb346b | 2015-09-09 10:47:29 -0700 | [diff] [blame] | 353 | const uid_t callingUid = IPCThreadState::self()->getCallingUid(); |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 354 | if (!isAudioServerOrMediaServerUid(callingUid)) { |
Eric Laurent | 9f39f8d | 2016-05-25 12:34:48 -0700 | [diff] [blame] | 355 | ALOGW_IF(uid != (uid_t)-1 && uid != callingUid, |
Marco Nelissen | dcb346b | 2015-09-09 10:47:29 -0700 | [diff] [blame] | 356 | "%s uid %d tried to pass itself off as %d", __FUNCTION__, callingUid, uid); |
| 357 | uid = callingUid; |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 358 | updatePid = true; |
| 359 | } |
| 360 | |
| 361 | if (updatePid) { |
| 362 | const pid_t callingPid = IPCThreadState::self()->getCallingPid(); |
Eric Laurent | 9f39f8d | 2016-05-25 12:34:48 -0700 | [diff] [blame] | 363 | ALOGW_IF(pid != (pid_t)-1 && pid != callingPid, |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 364 | "%s uid %d pid %d tried to pass itself off as pid %d", |
| 365 | __func__, callingUid, callingPid, pid); |
| 366 | pid = callingPid; |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 369 | // check calling permissions |
| 370 | if (!recordingAllowed(opPackageName, pid, uid)) { |
| 371 | ALOGE("%s permission denied: recording not allowed for uid %d pid %d", |
| 372 | __func__, uid, pid); |
| 373 | return PERMISSION_DENIED; |
| 374 | } |
| 375 | |
Nadav Bar | 744be48 | 2018-05-08 13:26:21 +0300 | [diff] [blame] | 376 | if ((attr->source == AUDIO_SOURCE_VOICE_UPLINK || |
| 377 | attr->source == AUDIO_SOURCE_VOICE_DOWNLINK || |
Eric Laurent | ae4b6ec | 2019-01-15 18:34:38 -0800 | [diff] [blame] | 378 | attr->source == AUDIO_SOURCE_VOICE_CALL || |
| 379 | attr->source == AUDIO_SOURCE_ECHO_REFERENCE) && |
Nadav Bar | 744be48 | 2018-05-08 13:26:21 +0300 | [diff] [blame] | 380 | !captureAudioOutputAllowed(pid, uid)) { |
| 381 | return PERMISSION_DENIED; |
| 382 | } |
| 383 | |
Eric Laurent | 7504b9e | 2017-08-15 18:17:26 -0700 | [diff] [blame] | 384 | if ((attr->source == AUDIO_SOURCE_HOTWORD) && !captureHotwordAllowed(pid, uid)) { |
| 385 | return BAD_VALUE; |
| 386 | } |
| 387 | |
| 388 | sp<AudioPolicyEffects>audioPolicyEffects; |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 389 | { |
Eric Laurent | 7504b9e | 2017-08-15 18:17:26 -0700 | [diff] [blame] | 390 | status_t status; |
| 391 | AudioPolicyInterface::input_type_t inputType; |
| 392 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 393 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 394 | { |
| 395 | AutoCallerClear acc; |
| 396 | // the audio_in_acoustics_t parameter is ignored by get_input() |
| 397 | status = mAudioPolicyManager->getInputForAttr(attr, input, session, uid, |
| 398 | config, |
| 399 | flags, selectedDeviceId, |
| 400 | &inputType, portId); |
| 401 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 402 | audioPolicyEffects = mAudioPolicyEffects; |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 403 | |
| 404 | if (status == NO_ERROR) { |
| 405 | // enforce permission (if any) required for each type of input |
| 406 | switch (inputType) { |
| 407 | case AudioPolicyInterface::API_INPUT_LEGACY: |
| 408 | break; |
Eric Laurent | 82db269 | 2015-08-07 13:59:42 -0700 | [diff] [blame] | 409 | case AudioPolicyInterface::API_INPUT_TELEPHONY_RX: |
| 410 | // FIXME: use the same permission as for remote submix for now. |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 411 | case AudioPolicyInterface::API_INPUT_MIX_CAPTURE: |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 412 | if (!captureAudioOutputAllowed(pid, uid)) { |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 413 | ALOGE("getInputForAttr() permission denied: capture not allowed"); |
| 414 | status = PERMISSION_DENIED; |
| 415 | } |
| 416 | break; |
| 417 | case AudioPolicyInterface::API_INPUT_MIX_EXT_POLICY_REROUTE: |
| 418 | if (!modifyAudioRoutingAllowed()) { |
| 419 | ALOGE("getInputForAttr() permission denied: modify audio routing not allowed"); |
| 420 | status = PERMISSION_DENIED; |
| 421 | } |
| 422 | break; |
| 423 | case AudioPolicyInterface::API_INPUT_INVALID: |
| 424 | default: |
| 425 | LOG_ALWAYS_FATAL("getInputForAttr() encountered an invalid input type %d", |
| 426 | (int)inputType); |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | if (status != NO_ERROR) { |
| 431 | if (status == PERMISSION_DENIED) { |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 432 | AutoCallerClear acc; |
Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 433 | mAudioPolicyManager->releaseInput(*portId); |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 434 | } |
| 435 | return status; |
| 436 | } |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 437 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 438 | sp<AudioRecordClient> client = new AudioRecordClient(*attr, *input, uid, pid, session, |
| 439 | *selectedDeviceId, opPackageName); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 440 | mAudioRecordClients.add(*portId, client); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 441 | } |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 442 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 443 | if (audioPolicyEffects != 0) { |
| 444 | // create audio pre processors according to input source |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 445 | status_t status = audioPolicyEffects->addInputEffects(*input, attr->source, session); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 446 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 447 | ALOGW("Failed to add effects on input %d", *input); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 448 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 449 | } |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 450 | return NO_ERROR; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 451 | } |
| 452 | |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 453 | std::string AudioPolicyService::getDeviceTypeStrForPortId(audio_port_handle_t portId) { |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 454 | struct audio_port port = {}; |
| 455 | port.id = portId; |
| 456 | status_t status = mAudioPolicyManager->getAudioPort(&port); |
| 457 | if (status == NO_ERROR && port.type == AUDIO_PORT_TYPE_DEVICE) { |
Andy Hung | 9b18195 | 2019-02-25 14:53:36 -0800 | [diff] [blame] | 458 | return toString(port.ext.device.type); |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 459 | } |
Andy Hung | 9b18195 | 2019-02-25 14:53:36 -0800 | [diff] [blame] | 460 | return {}; |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 463 | status_t AudioPolicyService::startInput(audio_port_handle_t portId) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 464 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 465 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 466 | return NO_INIT; |
| 467 | } |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 468 | sp<AudioRecordClient> client; |
| 469 | { |
| 470 | Mutex::Autolock _l(mLock); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 471 | |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 472 | ssize_t index = mAudioRecordClients.indexOfKey(portId); |
| 473 | if (index < 0) { |
| 474 | return INVALID_OPERATION; |
| 475 | } |
| 476 | client = mAudioRecordClients.valueAt(index); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 477 | } |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 478 | |
| 479 | // check calling permissions |
Svet Ganov | 6e64137 | 2018-03-02 09:21:30 -0800 | [diff] [blame] | 480 | if (!startRecording(client->opPackageName, client->pid, client->uid)) { |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 481 | ALOGE("%s permission denied: recording not allowed for uid %d pid %d", |
| 482 | __func__, client->uid, client->pid); |
| 483 | return PERMISSION_DENIED; |
| 484 | } |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 485 | |
Eric Laurent | df62892 | 2018-12-06 21:45:51 +0000 | [diff] [blame] | 486 | Mutex::Autolock _l(mLock); |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 487 | |
| 488 | client->active = true; |
| 489 | client->startTimeNs = systemTime(); |
| 490 | updateUidStates_l(); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 491 | |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 492 | status_t status; |
| 493 | { |
| 494 | AutoCallerClear acc; |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 495 | status = mAudioPolicyManager->startInput(portId); |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 496 | |
| 497 | } |
| 498 | |
Ray Essick | f6a57cd | 2018-05-22 16:20:54 -0700 | [diff] [blame] | 499 | // including successes gets very verbose |
| 500 | if (status != NO_ERROR) { |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 501 | |
| 502 | static constexpr char kAudioPolicy[] = "audiopolicy"; |
| 503 | |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 504 | static constexpr char kAudioPolicyStatus[] = "android.media.audiopolicy.status"; |
| 505 | static constexpr char kAudioPolicyRqstSrc[] = "android.media.audiopolicy.rqst.src"; |
| 506 | static constexpr char kAudioPolicyRqstPkg[] = "android.media.audiopolicy.rqst.pkg"; |
| 507 | static constexpr char kAudioPolicyRqstSession[] = "android.media.audiopolicy.rqst.session"; |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 508 | static constexpr char kAudioPolicyRqstDevice[] = |
| 509 | "android.media.audiopolicy.rqst.device"; |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 510 | static constexpr char kAudioPolicyActiveSrc[] = "android.media.audiopolicy.active.src"; |
| 511 | static constexpr char kAudioPolicyActivePkg[] = "android.media.audiopolicy.active.pkg"; |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 512 | static constexpr char kAudioPolicyActiveSession[] = |
| 513 | "android.media.audiopolicy.active.session"; |
| 514 | static constexpr char kAudioPolicyActiveDevice[] = |
| 515 | "android.media.audiopolicy.active.device"; |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 516 | |
Ray Essick | 6a30522 | 2019-01-28 20:33:18 -0800 | [diff] [blame] | 517 | MediaAnalyticsItem *item = MediaAnalyticsItem::create(kAudioPolicy); |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 518 | if (item != NULL) { |
| 519 | |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 520 | item->setInt32(kAudioPolicyStatus, status); |
| 521 | |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 522 | item->setCString(kAudioPolicyRqstSrc, |
Andy Hung | 9b18195 | 2019-02-25 14:53:36 -0800 | [diff] [blame] | 523 | toString(client->attributes.source).c_str()); |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 524 | item->setInt32(kAudioPolicyRqstSession, client->session); |
Ray Essick | 5186695 | 2018-05-30 11:22:27 -0700 | [diff] [blame] | 525 | if (client->opPackageName.size() != 0) { |
| 526 | item->setCString(kAudioPolicyRqstPkg, |
| 527 | std::string(String8(client->opPackageName).string()).c_str()); |
| 528 | } else { |
Kevin Rocard | fbdfebe | 2018-06-18 12:30:40 -0700 | [diff] [blame] | 529 | item->setCString(kAudioPolicyRqstPkg, std::to_string(client->uid).c_str()); |
Ray Essick | 5186695 | 2018-05-30 11:22:27 -0700 | [diff] [blame] | 530 | } |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 531 | item->setCString( |
| 532 | kAudioPolicyRqstDevice, getDeviceTypeStrForPortId(client->deviceId).c_str()); |
| 533 | |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 534 | int count = mAudioRecordClients.size(); |
| 535 | for (int i = 0; i < count ; i++) { |
| 536 | if (portId == mAudioRecordClients.keyAt(i)) { |
| 537 | continue; |
| 538 | } |
| 539 | sp<AudioRecordClient> other = mAudioRecordClients.valueAt(i); |
| 540 | if (other->active) { |
| 541 | // keeps the last of the clients marked active |
| 542 | item->setCString(kAudioPolicyActiveSrc, |
Andy Hung | 9b18195 | 2019-02-25 14:53:36 -0800 | [diff] [blame] | 543 | toString(other->attributes.source).c_str()); |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 544 | item->setInt32(kAudioPolicyActiveSession, other->session); |
| 545 | if (other->opPackageName.size() != 0) { |
| 546 | item->setCString(kAudioPolicyActivePkg, |
| 547 | std::string(String8(other->opPackageName).string()).c_str()); |
| 548 | } else { |
| 549 | item->setCString(kAudioPolicyRqstPkg, |
| 550 | std::to_string(other->uid).c_str()); |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 551 | } |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 552 | item->setCString(kAudioPolicyActiveDevice, |
| 553 | getDeviceTypeStrForPortId(other->deviceId).c_str()); |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | item->selfrecord(); |
| 557 | delete item; |
| 558 | item = NULL; |
| 559 | } |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 560 | client->active = false; |
| 561 | client->startTimeNs = 0; |
| 562 | updateUidStates_l(); |
Svet Ganov | 6e64137 | 2018-03-02 09:21:30 -0800 | [diff] [blame] | 563 | finishRecording(client->opPackageName, client->uid); |
Eric Laurent | fb66dd9 | 2016-01-28 18:32:03 -0800 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | return status; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 567 | } |
| 568 | |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 569 | status_t AudioPolicyService::stopInput(audio_port_handle_t portId) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 570 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 571 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 572 | return NO_INIT; |
| 573 | } |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 574 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 575 | Mutex::Autolock _l(mLock); |
| 576 | |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 577 | ssize_t index = mAudioRecordClients.indexOfKey(portId); |
| 578 | if (index < 0) { |
| 579 | return INVALID_OPERATION; |
| 580 | } |
| 581 | sp<AudioRecordClient> client = mAudioRecordClients.valueAt(index); |
| 582 | |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 583 | client->active = false; |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 584 | client->startTimeNs = 0; |
| 585 | |
| 586 | updateUidStates_l(); |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 587 | |
Svet Ganov | 6e64137 | 2018-03-02 09:21:30 -0800 | [diff] [blame] | 588 | // finish the recording app op |
| 589 | finishRecording(client->opPackageName, client->uid); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 590 | AutoCallerClear acc; |
Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 591 | return mAudioPolicyManager->stopInput(portId); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 592 | } |
| 593 | |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 594 | void AudioPolicyService::releaseInput(audio_port_handle_t portId) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 595 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 596 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 597 | return; |
| 598 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 599 | sp<AudioPolicyEffects>audioPolicyEffects; |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 600 | sp<AudioRecordClient> client; |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 601 | { |
| 602 | Mutex::Autolock _l(mLock); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 603 | audioPolicyEffects = mAudioPolicyEffects; |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 604 | ssize_t index = mAudioRecordClients.indexOfKey(portId); |
| 605 | if (index < 0) { |
| 606 | return; |
| 607 | } |
| 608 | client = mAudioRecordClients.valueAt(index); |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 609 | |
| 610 | if (client->active) { |
| 611 | ALOGW("%s releasing active client portId %d", __FUNCTION__, portId); |
| 612 | client->active = false; |
| 613 | client->startTimeNs = 0; |
| 614 | updateUidStates_l(); |
| 615 | } |
| 616 | |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 617 | mAudioRecordClients.removeItem(portId); |
| 618 | } |
| 619 | if (client == 0) { |
| 620 | return; |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 621 | } |
| 622 | if (audioPolicyEffects != 0) { |
| 623 | // release audio processors from the input |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 624 | status_t status = audioPolicyEffects->releaseInputEffects(client->io, client->session); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 625 | if(status != NO_ERROR) { |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 626 | ALOGW("Failed to release effects on input %d", client->io); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 627 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 628 | } |
Eric Laurent | f10c709 | 2016-12-06 17:09:56 -0800 | [diff] [blame] | 629 | { |
| 630 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 631 | AutoCallerClear acc; |
Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 632 | mAudioPolicyManager->releaseInput(portId); |
Eric Laurent | f10c709 | 2016-12-06 17:09:56 -0800 | [diff] [blame] | 633 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | status_t AudioPolicyService::initStreamVolume(audio_stream_type_t stream, |
| 637 | int indexMin, |
| 638 | int indexMax) |
| 639 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 640 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 641 | return NO_INIT; |
| 642 | } |
| 643 | if (!settingsAllowed()) { |
| 644 | return PERMISSION_DENIED; |
| 645 | } |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 646 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 647 | return BAD_VALUE; |
| 648 | } |
| 649 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 650 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 651 | mAudioPolicyManager->initStreamVolume(stream, indexMin, indexMax); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 652 | return NO_ERROR; |
| 653 | } |
| 654 | |
| 655 | status_t AudioPolicyService::setStreamVolumeIndex(audio_stream_type_t stream, |
| 656 | int index, |
| 657 | audio_devices_t device) |
| 658 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 659 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 660 | return NO_INIT; |
| 661 | } |
| 662 | if (!settingsAllowed()) { |
| 663 | return PERMISSION_DENIED; |
| 664 | } |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 665 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 666 | return BAD_VALUE; |
| 667 | } |
| 668 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 669 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 670 | return mAudioPolicyManager->setStreamVolumeIndex(stream, |
| 671 | index, |
| 672 | device); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | status_t AudioPolicyService::getStreamVolumeIndex(audio_stream_type_t stream, |
| 676 | int *index, |
| 677 | audio_devices_t device) |
| 678 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 679 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 680 | return NO_INIT; |
| 681 | } |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 682 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 683 | return BAD_VALUE; |
| 684 | } |
| 685 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 686 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 687 | return mAudioPolicyManager->getStreamVolumeIndex(stream, |
| 688 | index, |
| 689 | device); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 690 | } |
| 691 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 692 | status_t AudioPolicyService::setVolumeIndexForAttributes(const audio_attributes_t &attributes, |
| 693 | int index, audio_devices_t device) |
| 694 | { |
| 695 | if (mAudioPolicyManager == NULL) { |
| 696 | return NO_INIT; |
| 697 | } |
| 698 | if (!settingsAllowed()) { |
| 699 | return PERMISSION_DENIED; |
| 700 | } |
| 701 | Mutex::Autolock _l(mLock); |
| 702 | AutoCallerClear acc; |
| 703 | return mAudioPolicyManager->setVolumeIndexForAttributes(attributes, index, device); |
| 704 | } |
| 705 | |
| 706 | status_t AudioPolicyService::getVolumeIndexForAttributes(const audio_attributes_t &attributes, |
| 707 | int &index, audio_devices_t device) |
| 708 | { |
| 709 | if (mAudioPolicyManager == NULL) { |
| 710 | return NO_INIT; |
| 711 | } |
| 712 | Mutex::Autolock _l(mLock); |
| 713 | AutoCallerClear acc; |
| 714 | return mAudioPolicyManager->getVolumeIndexForAttributes(attributes, index, device); |
| 715 | } |
| 716 | |
| 717 | status_t AudioPolicyService::getMinVolumeIndexForAttributes(const audio_attributes_t &attributes, |
| 718 | int &index) |
| 719 | { |
| 720 | if (mAudioPolicyManager == NULL) { |
| 721 | return NO_INIT; |
| 722 | } |
| 723 | Mutex::Autolock _l(mLock); |
| 724 | AutoCallerClear acc; |
| 725 | return mAudioPolicyManager->getMinVolumeIndexForAttributes(attributes, index); |
| 726 | } |
| 727 | |
| 728 | status_t AudioPolicyService::getMaxVolumeIndexForAttributes(const audio_attributes_t &attributes, |
| 729 | int &index) |
| 730 | { |
| 731 | if (mAudioPolicyManager == NULL) { |
| 732 | return NO_INIT; |
| 733 | } |
| 734 | Mutex::Autolock _l(mLock); |
| 735 | AutoCallerClear acc; |
| 736 | return mAudioPolicyManager->getMaxVolumeIndexForAttributes(attributes, index); |
| 737 | } |
| 738 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 739 | uint32_t AudioPolicyService::getStrategyForStream(audio_stream_type_t stream) |
| 740 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 741 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 742 | return PRODUCT_STRATEGY_NONE; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 743 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 744 | if (mAudioPolicyManager == NULL) { |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 745 | return PRODUCT_STRATEGY_NONE; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 746 | } |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 747 | // DO NOT LOCK, may be called from AudioFlinger with lock held, reaching deadlock |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 748 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 749 | return mAudioPolicyManager->getStrategyForStream(stream); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | //audio policy: use audio_device_t appropriately |
| 753 | |
| 754 | audio_devices_t AudioPolicyService::getDevicesForStream(audio_stream_type_t stream) |
| 755 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 756 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 757 | return AUDIO_DEVICE_NONE; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 758 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 759 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 760 | return AUDIO_DEVICE_NONE; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 761 | } |
Haynes Mathew George | dfb9f3b | 2015-10-26 18:22:13 -0700 | [diff] [blame] | 762 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 763 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 764 | return mAudioPolicyManager->getDevicesForStream(stream); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | audio_io_handle_t AudioPolicyService::getOutputForEffect(const effect_descriptor_t *desc) |
| 768 | { |
| 769 | // FIXME change return type to status_t, and return NO_INIT here |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 770 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 771 | return 0; |
| 772 | } |
| 773 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 774 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 775 | return mAudioPolicyManager->getOutputForEffect(desc); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | status_t AudioPolicyService::registerEffect(const effect_descriptor_t *desc, |
| 779 | audio_io_handle_t io, |
| 780 | uint32_t strategy, |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 781 | audio_session_t session, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 782 | int id) |
| 783 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 784 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 785 | return NO_INIT; |
| 786 | } |
Haynes Mathew George | bab7bf4 | 2015-10-30 18:02:23 -0700 | [diff] [blame] | 787 | Mutex::Autolock _l(mEffectsLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 788 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 789 | return mAudioPolicyManager->registerEffect(desc, io, strategy, session, id); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | status_t AudioPolicyService::unregisterEffect(int id) |
| 793 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 794 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 795 | return NO_INIT; |
| 796 | } |
Haynes Mathew George | bab7bf4 | 2015-10-30 18:02:23 -0700 | [diff] [blame] | 797 | Mutex::Autolock _l(mEffectsLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 798 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 799 | return mAudioPolicyManager->unregisterEffect(id); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | status_t AudioPolicyService::setEffectEnabled(int id, bool enabled) |
| 803 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 804 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 805 | return NO_INIT; |
| 806 | } |
Haynes Mathew George | bab7bf4 | 2015-10-30 18:02:23 -0700 | [diff] [blame] | 807 | Mutex::Autolock _l(mEffectsLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 808 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 809 | return mAudioPolicyManager->setEffectEnabled(id, enabled); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | bool AudioPolicyService::isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const |
| 813 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 814 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 815 | return false; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 816 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 817 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 818 | return false; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 819 | } |
| 820 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 821 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 822 | return mAudioPolicyManager->isStreamActive(stream, inPastMs); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | bool AudioPolicyService::isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const |
| 826 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 827 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 828 | return false; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 829 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 830 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 831 | return false; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 832 | } |
| 833 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 834 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 835 | return mAudioPolicyManager->isStreamActiveRemotely(stream, inPastMs); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | bool AudioPolicyService::isSourceActive(audio_source_t source) const |
| 839 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 840 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 841 | return false; |
| 842 | } |
| 843 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 844 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 845 | return mAudioPolicyManager->isSourceActive(source); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 846 | } |
| 847 | |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 848 | status_t AudioPolicyService::getAudioPolicyEffects(sp<AudioPolicyEffects>& audioPolicyEffects) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 849 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 850 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 851 | return NO_INIT; |
| 852 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 853 | { |
| 854 | Mutex::Autolock _l(mLock); |
| 855 | audioPolicyEffects = mAudioPolicyEffects; |
| 856 | } |
| 857 | if (audioPolicyEffects == 0) { |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 858 | return NO_INIT; |
| 859 | } |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 860 | |
| 861 | return OK; |
| 862 | } |
| 863 | |
| 864 | status_t AudioPolicyService::queryDefaultPreProcessing(audio_session_t audioSession, |
| 865 | effect_descriptor_t *descriptors, |
| 866 | uint32_t *count) |
| 867 | { |
| 868 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 869 | status_t status = getAudioPolicyEffects(audioPolicyEffects); |
| 870 | if (status != OK) { |
| 871 | *count = 0; |
| 872 | return status; |
| 873 | } |
Eric Laurent | fb66dd9 | 2016-01-28 18:32:03 -0800 | [diff] [blame] | 874 | return audioPolicyEffects->queryDefaultInputEffects( |
| 875 | (audio_session_t)audioSession, descriptors, count); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 876 | } |
| 877 | |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 878 | status_t AudioPolicyService::addSourceDefaultEffect(const effect_uuid_t *type, |
| 879 | const String16& opPackageName, |
| 880 | const effect_uuid_t *uuid, |
| 881 | int32_t priority, |
| 882 | audio_source_t source, |
| 883 | audio_unique_id_t* id) |
| 884 | { |
| 885 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 886 | status_t status = getAudioPolicyEffects(audioPolicyEffects); |
| 887 | if (status != OK) { |
| 888 | return status; |
| 889 | } |
| 890 | if (!modifyDefaultAudioEffectsAllowed()) { |
| 891 | return PERMISSION_DENIED; |
| 892 | } |
| 893 | return audioPolicyEffects->addSourceDefaultEffect( |
| 894 | type, opPackageName, uuid, priority, source, id); |
| 895 | } |
| 896 | |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 897 | status_t AudioPolicyService::addStreamDefaultEffect(const effect_uuid_t *type, |
| 898 | const String16& opPackageName, |
| 899 | const effect_uuid_t *uuid, |
| 900 | int32_t priority, |
| 901 | audio_usage_t usage, |
| 902 | audio_unique_id_t* id) |
| 903 | { |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 904 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 905 | status_t status = getAudioPolicyEffects(audioPolicyEffects); |
| 906 | if (status != OK) { |
| 907 | return status; |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 908 | } |
| 909 | if (!modifyDefaultAudioEffectsAllowed()) { |
| 910 | return PERMISSION_DENIED; |
| 911 | } |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 912 | return audioPolicyEffects->addStreamDefaultEffect( |
| 913 | type, opPackageName, uuid, priority, usage, id); |
| 914 | } |
| 915 | |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 916 | status_t AudioPolicyService::removeSourceDefaultEffect(audio_unique_id_t id) |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 917 | { |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 918 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 919 | status_t status = getAudioPolicyEffects(audioPolicyEffects); |
| 920 | if (status != OK) { |
| 921 | return status; |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 922 | } |
| 923 | if (!modifyDefaultAudioEffectsAllowed()) { |
| 924 | return PERMISSION_DENIED; |
| 925 | } |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 926 | return audioPolicyEffects->removeSourceDefaultEffect(id); |
| 927 | } |
| 928 | |
| 929 | status_t AudioPolicyService::removeStreamDefaultEffect(audio_unique_id_t id) |
| 930 | { |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 931 | sp<AudioPolicyEffects>audioPolicyEffects; |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 932 | status_t status = getAudioPolicyEffects(audioPolicyEffects); |
| 933 | if (status != OK) { |
| 934 | return status; |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 935 | } |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 936 | if (!modifyDefaultAudioEffectsAllowed()) { |
| 937 | return PERMISSION_DENIED; |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 938 | } |
| 939 | return audioPolicyEffects->removeStreamDefaultEffect(id); |
| 940 | } |
| 941 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 942 | bool AudioPolicyService::isOffloadSupported(const audio_offload_info_t& info) |
| 943 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 944 | if (mAudioPolicyManager == NULL) { |
| 945 | ALOGV("mAudioPolicyManager == NULL"); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 946 | return false; |
| 947 | } |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 948 | Mutex::Autolock _l(mLock); |
Haynes Mathew George | bab7bf4 | 2015-10-30 18:02:23 -0700 | [diff] [blame] | 949 | Mutex::Autolock _le(mEffectsLock); // isOffloadSupported queries for |
| 950 | // non-offloadable effects |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 951 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 952 | return mAudioPolicyManager->isOffloadSupported(info); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 953 | } |
| 954 | |
Michael Chan | a94fbb2 | 2018-04-24 14:31:19 +1000 | [diff] [blame] | 955 | bool AudioPolicyService::isDirectOutputSupported(const audio_config_base_t& config, |
| 956 | const audio_attributes_t& attributes) { |
| 957 | if (mAudioPolicyManager == NULL) { |
| 958 | ALOGV("mAudioPolicyManager == NULL"); |
| 959 | return false; |
| 960 | } |
| 961 | Mutex::Autolock _l(mLock); |
| 962 | return mAudioPolicyManager->isDirectOutputSupported(config, attributes); |
| 963 | } |
| 964 | |
| 965 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 966 | status_t AudioPolicyService::listAudioPorts(audio_port_role_t role, |
| 967 | audio_port_type_t type, |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 968 | unsigned int *num_ports, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 969 | struct audio_port *ports, |
| 970 | unsigned int *generation) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 971 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 972 | Mutex::Autolock _l(mLock); |
| 973 | if (mAudioPolicyManager == NULL) { |
| 974 | return NO_INIT; |
| 975 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 976 | AutoCallerClear acc; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 977 | return mAudioPolicyManager->listAudioPorts(role, type, num_ports, ports, generation); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 978 | } |
| 979 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 980 | status_t AudioPolicyService::getAudioPort(struct audio_port *port) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 981 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 982 | Mutex::Autolock _l(mLock); |
| 983 | if (mAudioPolicyManager == NULL) { |
| 984 | return NO_INIT; |
| 985 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 986 | AutoCallerClear acc; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 987 | return mAudioPolicyManager->getAudioPort(port); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 988 | } |
| 989 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 990 | status_t AudioPolicyService::createAudioPatch(const struct audio_patch *patch, |
| 991 | audio_patch_handle_t *handle) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 992 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 993 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 994 | if(!modifyAudioRoutingAllowed()) { |
| 995 | return PERMISSION_DENIED; |
| 996 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 997 | if (mAudioPolicyManager == NULL) { |
| 998 | return NO_INIT; |
| 999 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1000 | AutoCallerClear acc; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1001 | return mAudioPolicyManager->createAudioPatch(patch, handle, |
| 1002 | IPCThreadState::self()->getCallingUid()); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1005 | status_t AudioPolicyService::releaseAudioPatch(audio_patch_handle_t handle) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1006 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1007 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 1008 | if(!modifyAudioRoutingAllowed()) { |
| 1009 | return PERMISSION_DENIED; |
| 1010 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1011 | if (mAudioPolicyManager == NULL) { |
| 1012 | return NO_INIT; |
| 1013 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1014 | AutoCallerClear acc; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1015 | return mAudioPolicyManager->releaseAudioPatch(handle, |
| 1016 | IPCThreadState::self()->getCallingUid()); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | status_t AudioPolicyService::listAudioPatches(unsigned int *num_patches, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1020 | struct audio_patch *patches, |
| 1021 | unsigned int *generation) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1022 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1023 | Mutex::Autolock _l(mLock); |
| 1024 | if (mAudioPolicyManager == NULL) { |
| 1025 | return NO_INIT; |
| 1026 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1027 | AutoCallerClear acc; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1028 | return mAudioPolicyManager->listAudioPatches(num_patches, patches, generation); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1029 | } |
| 1030 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1031 | status_t AudioPolicyService::setAudioPortConfig(const struct audio_port_config *config) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1032 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1033 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 1034 | if(!modifyAudioRoutingAllowed()) { |
| 1035 | return PERMISSION_DENIED; |
| 1036 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1037 | if (mAudioPolicyManager == NULL) { |
| 1038 | return NO_INIT; |
| 1039 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1040 | AutoCallerClear acc; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1041 | return mAudioPolicyManager->setAudioPortConfig(config); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1042 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1043 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1044 | status_t AudioPolicyService::acquireSoundTriggerSession(audio_session_t *session, |
| 1045 | audio_io_handle_t *ioHandle, |
| 1046 | audio_devices_t *device) |
| 1047 | { |
Andy Hung | f759b8c | 2017-08-15 12:48:54 -0700 | [diff] [blame] | 1048 | Mutex::Autolock _l(mLock); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1049 | if (mAudioPolicyManager == NULL) { |
| 1050 | return NO_INIT; |
| 1051 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1052 | AutoCallerClear acc; |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1053 | return mAudioPolicyManager->acquireSoundTriggerSession(session, ioHandle, device); |
| 1054 | } |
| 1055 | |
| 1056 | status_t AudioPolicyService::releaseSoundTriggerSession(audio_session_t session) |
| 1057 | { |
Andy Hung | f759b8c | 2017-08-15 12:48:54 -0700 | [diff] [blame] | 1058 | Mutex::Autolock _l(mLock); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1059 | if (mAudioPolicyManager == NULL) { |
| 1060 | return NO_INIT; |
| 1061 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1062 | AutoCallerClear acc; |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1063 | return mAudioPolicyManager->releaseSoundTriggerSession(session); |
| 1064 | } |
| 1065 | |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 1066 | status_t AudioPolicyService::registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration) |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1067 | { |
| 1068 | Mutex::Autolock _l(mLock); |
Kevin Rocard | be20185 | 2019-02-20 22:33:28 -0800 | [diff] [blame] | 1069 | |
| 1070 | // loopback|render only need a MediaProjection (checked in caller AudioService.java) |
| 1071 | bool needModifyAudioRouting = std::any_of(mixes.begin(), mixes.end(), [](auto& mix) { |
| 1072 | return !is_mix_loopback_render(mix.mRouteFlags); }); |
| 1073 | if (needModifyAudioRouting && !modifyAudioRoutingAllowed()) { |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1074 | return PERMISSION_DENIED; |
| 1075 | } |
Kevin Rocard | be20185 | 2019-02-20 22:33:28 -0800 | [diff] [blame] | 1076 | |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1077 | if (mAudioPolicyManager == NULL) { |
| 1078 | return NO_INIT; |
| 1079 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1080 | AutoCallerClear acc; |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1081 | if (registration) { |
| 1082 | return mAudioPolicyManager->registerPolicyMixes(mixes); |
| 1083 | } else { |
| 1084 | return mAudioPolicyManager->unregisterPolicyMixes(mixes); |
| 1085 | } |
| 1086 | } |
| 1087 | |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1088 | status_t AudioPolicyService::setUidDeviceAffinities(uid_t uid, |
| 1089 | const Vector<AudioDeviceTypeAddr>& devices) { |
| 1090 | Mutex::Autolock _l(mLock); |
| 1091 | if(!modifyAudioRoutingAllowed()) { |
| 1092 | return PERMISSION_DENIED; |
| 1093 | } |
| 1094 | if (mAudioPolicyManager == NULL) { |
| 1095 | return NO_INIT; |
| 1096 | } |
| 1097 | AutoCallerClear acc; |
| 1098 | return mAudioPolicyManager->setUidDeviceAffinities(uid, devices); |
| 1099 | } |
| 1100 | |
| 1101 | status_t AudioPolicyService::removeUidDeviceAffinities(uid_t uid) { |
| 1102 | Mutex::Autolock _l(mLock); |
| 1103 | if(!modifyAudioRoutingAllowed()) { |
| 1104 | return PERMISSION_DENIED; |
| 1105 | } |
| 1106 | if (mAudioPolicyManager == NULL) { |
| 1107 | return NO_INIT; |
| 1108 | } |
| 1109 | AutoCallerClear acc; |
| 1110 | return mAudioPolicyManager->removeUidDeviceAffinities(uid); |
| 1111 | } |
| 1112 | |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1113 | status_t AudioPolicyService::startAudioSource(const struct audio_port_config *source, |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 1114 | const audio_attributes_t *attributes, |
| 1115 | audio_port_handle_t *portId) |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1116 | { |
| 1117 | Mutex::Autolock _l(mLock); |
| 1118 | if (mAudioPolicyManager == NULL) { |
| 1119 | return NO_INIT; |
| 1120 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1121 | AutoCallerClear acc; |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 1122 | return mAudioPolicyManager->startAudioSource(source, attributes, portId, |
Eric Laurent | d60560a | 2015-04-10 11:31:20 -0700 | [diff] [blame] | 1123 | IPCThreadState::self()->getCallingUid()); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1124 | } |
| 1125 | |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 1126 | status_t AudioPolicyService::stopAudioSource(audio_port_handle_t portId) |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1127 | { |
| 1128 | Mutex::Autolock _l(mLock); |
| 1129 | if (mAudioPolicyManager == NULL) { |
| 1130 | return NO_INIT; |
| 1131 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1132 | AutoCallerClear acc; |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 1133 | return mAudioPolicyManager->stopAudioSource(portId); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1136 | status_t AudioPolicyService::setMasterMono(bool mono) |
| 1137 | { |
| 1138 | if (mAudioPolicyManager == NULL) { |
| 1139 | return NO_INIT; |
| 1140 | } |
| 1141 | if (!settingsAllowed()) { |
| 1142 | return PERMISSION_DENIED; |
| 1143 | } |
| 1144 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1145 | AutoCallerClear acc; |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1146 | return mAudioPolicyManager->setMasterMono(mono); |
| 1147 | } |
| 1148 | |
| 1149 | status_t AudioPolicyService::getMasterMono(bool *mono) |
| 1150 | { |
| 1151 | if (mAudioPolicyManager == NULL) { |
| 1152 | return NO_INIT; |
| 1153 | } |
| 1154 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1155 | AutoCallerClear acc; |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1156 | return mAudioPolicyManager->getMasterMono(mono); |
| 1157 | } |
| 1158 | |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1159 | |
| 1160 | float AudioPolicyService::getStreamVolumeDB( |
| 1161 | audio_stream_type_t stream, int index, audio_devices_t device) |
| 1162 | { |
| 1163 | if (mAudioPolicyManager == NULL) { |
| 1164 | return NAN; |
| 1165 | } |
| 1166 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1167 | AutoCallerClear acc; |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1168 | return mAudioPolicyManager->getStreamVolumeDB(stream, index, device); |
| 1169 | } |
| 1170 | |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1171 | status_t AudioPolicyService::getSurroundFormats(unsigned int *numSurroundFormats, |
| 1172 | audio_format_t *surroundFormats, |
| 1173 | bool *surroundFormatsEnabled, |
| 1174 | bool reported) |
| 1175 | { |
| 1176 | if (mAudioPolicyManager == NULL) { |
| 1177 | return NO_INIT; |
| 1178 | } |
| 1179 | Mutex::Autolock _l(mLock); |
| 1180 | AutoCallerClear acc; |
| 1181 | return mAudioPolicyManager->getSurroundFormats(numSurroundFormats, surroundFormats, |
| 1182 | surroundFormatsEnabled, reported); |
| 1183 | } |
| 1184 | |
Arun Mirpuri | 11029ad | 2018-12-19 20:45:19 -0800 | [diff] [blame] | 1185 | status_t AudioPolicyService::getHwOffloadEncodingFormatsSupportedForA2DP( |
| 1186 | std::vector<audio_format_t> *formats) |
| 1187 | { |
| 1188 | if (mAudioPolicyManager == NULL) { |
| 1189 | return NO_INIT; |
| 1190 | } |
| 1191 | Mutex::Autolock _l(mLock); |
| 1192 | AutoCallerClear acc; |
| 1193 | return mAudioPolicyManager->getHwOffloadEncodingFormatsSupportedForA2DP(formats); |
| 1194 | } |
| 1195 | |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1196 | status_t AudioPolicyService::setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled) |
| 1197 | { |
| 1198 | if (mAudioPolicyManager == NULL) { |
| 1199 | return NO_INIT; |
| 1200 | } |
| 1201 | Mutex::Autolock _l(mLock); |
| 1202 | AutoCallerClear acc; |
| 1203 | return mAudioPolicyManager->setSurroundFormatEnabled(audioFormat, enabled); |
| 1204 | } |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1205 | |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1206 | status_t AudioPolicyService::setAssistantUid(uid_t uid) |
| 1207 | { |
| 1208 | Mutex::Autolock _l(mLock); |
| 1209 | mUidPolicy->setAssistantUid(uid); |
| 1210 | return NO_ERROR; |
| 1211 | } |
| 1212 | |
| 1213 | status_t AudioPolicyService::setA11yServicesUids(const std::vector<uid_t>& uids) |
| 1214 | { |
| 1215 | Mutex::Autolock _l(mLock); |
| 1216 | mUidPolicy->setA11yUids(uids); |
| 1217 | return NO_ERROR; |
| 1218 | } |
| 1219 | |
jiabin | 6012f91 | 2018-11-02 17:06:30 -0700 | [diff] [blame] | 1220 | bool AudioPolicyService::isHapticPlaybackSupported() |
| 1221 | { |
| 1222 | if (mAudioPolicyManager == NULL) { |
| 1223 | ALOGW("%s, mAudioPolicyManager == NULL", __func__); |
| 1224 | return false; |
| 1225 | } |
| 1226 | Mutex::Autolock _l(mLock); |
| 1227 | AutoCallerClear acc; |
| 1228 | return mAudioPolicyManager->isHapticPlaybackSupported(); |
| 1229 | } |
| 1230 | |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1231 | status_t AudioPolicyService::listAudioProductStrategies(AudioProductStrategyVector &strategies) |
| 1232 | { |
| 1233 | if (mAudioPolicyManager == NULL) { |
| 1234 | return NO_INIT; |
| 1235 | } |
| 1236 | Mutex::Autolock _l(mLock); |
| 1237 | return mAudioPolicyManager->listAudioProductStrategies(strategies); |
| 1238 | } |
| 1239 | |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1240 | status_t AudioPolicyService::getProductStrategyFromAudioAttributes( |
| 1241 | const AudioAttributes &aa, product_strategy_t &productStrategy) |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1242 | { |
| 1243 | if (mAudioPolicyManager == NULL) { |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1244 | return NO_INIT; |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1245 | } |
| 1246 | Mutex::Autolock _l(mLock); |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1247 | return mAudioPolicyManager->getProductStrategyFromAudioAttributes(aa, productStrategy); |
| 1248 | } |
| 1249 | |
| 1250 | status_t AudioPolicyService::listAudioVolumeGroups(AudioVolumeGroupVector &groups) |
| 1251 | { |
| 1252 | if (mAudioPolicyManager == NULL) { |
| 1253 | return NO_INIT; |
| 1254 | } |
| 1255 | Mutex::Autolock _l(mLock); |
| 1256 | return mAudioPolicyManager->listAudioVolumeGroups(groups); |
| 1257 | } |
| 1258 | |
| 1259 | status_t AudioPolicyService::getVolumeGroupFromAudioAttributes(const AudioAttributes &aa, |
| 1260 | volume_group_t &volumeGroup) |
| 1261 | { |
| 1262 | if (mAudioPolicyManager == NULL) { |
| 1263 | return NO_INIT; |
| 1264 | } |
| 1265 | Mutex::Autolock _l(mLock); |
| 1266 | return mAudioPolicyManager->getVolumeGroupFromAudioAttributes(aa, volumeGroup); |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1267 | } |
Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 1268 | } // namespace android |