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