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