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