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, |
| 35 | const char *device_name) |
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, |
| 52 | device_address, device_name); |
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, |
| 69 | const char *device_name) |
| 70 | { |
| 71 | if (mAudioPolicyManager == NULL) { |
| 72 | return NO_INIT; |
| 73 | } |
| 74 | if (!settingsAllowed()) { |
| 75 | return PERMISSION_DENIED; |
| 76 | } |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 77 | |
| 78 | ALOGV("handleDeviceConfigChange()"); |
| 79 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 80 | AutoCallerClear acc; |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 81 | return mAudioPolicyManager->handleDeviceConfigChange(device, device_address, |
| 82 | device_name); |
| 83 | } |
| 84 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 85 | status_t AudioPolicyService::setPhoneState(audio_mode_t state) |
| 86 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 87 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 88 | return NO_INIT; |
| 89 | } |
| 90 | if (!settingsAllowed()) { |
| 91 | return PERMISSION_DENIED; |
| 92 | } |
| 93 | if (uint32_t(state) >= AUDIO_MODE_CNT) { |
| 94 | return BAD_VALUE; |
| 95 | } |
| 96 | |
| 97 | ALOGV("setPhoneState()"); |
| 98 | |
Eric Laurent | beb07fe | 2015-09-16 15:49:30 -0700 | [diff] [blame] | 99 | // acquire lock before calling setMode() so that setMode() + setPhoneState() are an atomic |
| 100 | // operation from policy manager standpoint (no other operation (e.g track start or stop) |
| 101 | // can be interleaved). |
| 102 | Mutex::Autolock _l(mLock); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 103 | // TODO: check if it is more appropriate to do it in platform specific policy manager |
| 104 | AudioSystem::setMode(state); |
| 105 | |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 106 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 107 | mAudioPolicyManager->setPhoneState(state); |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 108 | mPhoneState = state; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 109 | return NO_ERROR; |
| 110 | } |
| 111 | |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 112 | audio_mode_t AudioPolicyService::getPhoneState() |
| 113 | { |
| 114 | Mutex::Autolock _l(mLock); |
| 115 | return mPhoneState; |
| 116 | } |
| 117 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 118 | status_t AudioPolicyService::setForceUse(audio_policy_force_use_t usage, |
| 119 | audio_policy_forced_cfg_t config) |
| 120 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 121 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 122 | return NO_INIT; |
| 123 | } |
Eric Laurent | e17378d | 2018-05-09 14:43:01 -0700 | [diff] [blame] | 124 | |
| 125 | if (!modifyAudioRoutingAllowed()) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 126 | return PERMISSION_DENIED; |
| 127 | } |
Eric Laurent | e17378d | 2018-05-09 14:43:01 -0700 | [diff] [blame] | 128 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 129 | if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) { |
| 130 | return BAD_VALUE; |
| 131 | } |
| 132 | if (config < 0 || config >= AUDIO_POLICY_FORCE_CFG_CNT) { |
| 133 | return BAD_VALUE; |
| 134 | } |
| 135 | ALOGV("setForceUse()"); |
| 136 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 137 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 138 | mAudioPolicyManager->setForceUse(usage, config); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 139 | return NO_ERROR; |
| 140 | } |
| 141 | |
| 142 | audio_policy_forced_cfg_t AudioPolicyService::getForceUse(audio_policy_force_use_t usage) |
| 143 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 144 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 145 | return AUDIO_POLICY_FORCE_NONE; |
| 146 | } |
| 147 | if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) { |
| 148 | return AUDIO_POLICY_FORCE_NONE; |
| 149 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 150 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 151 | return mAudioPolicyManager->getForceUse(usage); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 152 | } |
| 153 | |
Eric Laurent | f4e6345 | 2017-11-06 19:31:46 +0000 | [diff] [blame] | 154 | audio_io_handle_t AudioPolicyService::getOutput(audio_stream_type_t stream) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 155 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 156 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 157 | return AUDIO_IO_HANDLE_NONE; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 158 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 159 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 160 | return AUDIO_IO_HANDLE_NONE; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 161 | } |
| 162 | ALOGV("getOutput()"); |
| 163 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 164 | AutoCallerClear acc; |
Eric Laurent | f4e6345 | 2017-11-06 19:31:46 +0000 | [diff] [blame] | 165 | return mAudioPolicyManager->getOutput(stream); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 166 | } |
| 167 | |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 168 | status_t AudioPolicyService::getOutputForAttr(const audio_attributes_t *attr, |
| 169 | audio_io_handle_t *output, |
| 170 | audio_session_t session, |
| 171 | audio_stream_type_t *stream, |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 172 | pid_t pid, |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 173 | uid_t uid, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 174 | const audio_config_t *config, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 175 | audio_output_flags_t flags, |
Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 176 | audio_port_handle_t *selectedDeviceId, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 177 | audio_port_handle_t *portId) |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 178 | { |
| 179 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 180 | return NO_INIT; |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 181 | } |
Eric Laurent | f4e6345 | 2017-11-06 19:31:46 +0000 | [diff] [blame] | 182 | ALOGV("getOutputForAttr()"); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 183 | Mutex::Autolock _l(mLock); |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 184 | |
Marco Nelissen | dcb346b | 2015-09-09 10:47:29 -0700 | [diff] [blame] | 185 | const uid_t callingUid = IPCThreadState::self()->getCallingUid(); |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 186 | if (!isAudioServerOrMediaServerUid(callingUid) || uid == (uid_t)-1) { |
Marco Nelissen | dcb346b | 2015-09-09 10:47:29 -0700 | [diff] [blame] | 187 | ALOGW_IF(uid != (uid_t)-1 && uid != callingUid, |
| 188 | "%s uid %d tried to pass itself off as %d", __FUNCTION__, callingUid, uid); |
| 189 | uid = callingUid; |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 190 | } |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 191 | audio_output_flags_t originalFlags = flags; |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 192 | AutoCallerClear acc; |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 193 | status_t result = mAudioPolicyManager->getOutputForAttr(attr, output, session, stream, uid, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 194 | config, |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 195 | &flags, selectedDeviceId, portId); |
| 196 | |
| 197 | // FIXME: Introduce a way to check for the the telephony device before opening the output |
| 198 | if ((result == NO_ERROR) && |
| 199 | (flags & AUDIO_OUTPUT_FLAG_INCALL_MUSIC) && |
| 200 | !modifyPhoneStateAllowed(pid, uid)) { |
| 201 | // If the app tries to play music through the telephony device and doesn't have permission |
| 202 | // the fallback to the default output device. |
Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 203 | mAudioPolicyManager->releaseOutput(*portId); |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 204 | flags = originalFlags; |
| 205 | *selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 206 | *portId = AUDIO_PORT_HANDLE_NONE; |
| 207 | result = mAudioPolicyManager->getOutputForAttr(attr, output, session, stream, uid, |
| 208 | config, |
| 209 | &flags, selectedDeviceId, portId); |
| 210 | } |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 211 | |
| 212 | if (result == NO_ERROR) { |
| 213 | sp <AudioPlaybackClient> client = |
| 214 | new AudioPlaybackClient(*attr, *output, uid, pid, session, *selectedDeviceId, *stream); |
| 215 | mAudioPlaybackClients.add(*portId, client); |
| 216 | } |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 217 | return result; |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 220 | status_t AudioPolicyService::startOutput(audio_port_handle_t portId) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 221 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 222 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 223 | return NO_INIT; |
| 224 | } |
| 225 | ALOGV("startOutput()"); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 226 | sp<AudioPlaybackClient> client; |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 227 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 228 | { |
| 229 | Mutex::Autolock _l(mLock); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 230 | const ssize_t index = mAudioPlaybackClients.indexOfKey(portId); |
| 231 | if (index < 0) { |
| 232 | ALOGE("%s AudioTrack client not found for portId %d", __FUNCTION__, portId); |
| 233 | return INVALID_OPERATION; |
| 234 | } |
| 235 | client = mAudioPlaybackClients.valueAt(index); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 236 | audioPolicyEffects = mAudioPolicyEffects; |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame] | 237 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 238 | if (audioPolicyEffects != 0) { |
| 239 | // create audio processors according to stream |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 240 | status_t status = audioPolicyEffects->addOutputSessionEffects( |
| 241 | client->io, client->stream, client->session); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 242 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 243 | ALOGW("Failed to add effects on session %d", client->session); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 247 | AutoCallerClear acc; |
Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 248 | status_t status = mAudioPolicyManager->startOutput(portId); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 249 | if (status == NO_ERROR) { |
| 250 | client->active = true; |
| 251 | } |
| 252 | return status; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 253 | } |
| 254 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 255 | status_t AudioPolicyService::stopOutput(audio_port_handle_t portId) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 256 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 257 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 258 | return NO_INIT; |
| 259 | } |
| 260 | ALOGV("stopOutput()"); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 261 | mOutputCommandThread->stopOutputCommand(portId); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 262 | return NO_ERROR; |
| 263 | } |
| 264 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 265 | status_t AudioPolicyService::doStopOutput(audio_port_handle_t portId) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 266 | { |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 267 | ALOGV("doStopOutput"); |
| 268 | sp<AudioPlaybackClient> client; |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 269 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 270 | { |
| 271 | Mutex::Autolock _l(mLock); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 272 | |
| 273 | const ssize_t index = mAudioPlaybackClients.indexOfKey(portId); |
| 274 | if (index < 0) { |
| 275 | ALOGE("%s AudioTrack client not found for portId %d", __FUNCTION__, portId); |
| 276 | return INVALID_OPERATION; |
| 277 | } |
| 278 | client = mAudioPlaybackClients.valueAt(index); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 279 | audioPolicyEffects = mAudioPolicyEffects; |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame] | 280 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 281 | if (audioPolicyEffects != 0) { |
| 282 | // release audio processors from the stream |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 283 | status_t status = audioPolicyEffects->releaseOutputSessionEffects( |
| 284 | client->io, client->stream, client->session); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 285 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 286 | ALOGW("Failed to release effects on session %d", client->session); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 290 | AutoCallerClear acc; |
Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 291 | status_t status = mAudioPolicyManager->stopOutput(portId); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 292 | if (status == NO_ERROR) { |
| 293 | client->active = false; |
| 294 | } |
| 295 | return status; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 296 | } |
| 297 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 298 | void AudioPolicyService::releaseOutput(audio_port_handle_t portId) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 299 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 300 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 301 | return; |
| 302 | } |
| 303 | ALOGV("releaseOutput()"); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 304 | mOutputCommandThread->releaseOutputCommand(portId); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 305 | } |
| 306 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 307 | void AudioPolicyService::doReleaseOutput(audio_port_handle_t portId) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 308 | { |
| 309 | ALOGV("doReleaseOutput from tid %d", gettid()); |
| 310 | Mutex::Autolock _l(mLock); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 311 | const ssize_t index = mAudioPlaybackClients.indexOfKey(portId); |
| 312 | if (index < 0) { |
| 313 | ALOGE("%s AudioTrack client not found for portId %d", __FUNCTION__, portId); |
| 314 | return; |
| 315 | } |
| 316 | sp<AudioPlaybackClient> client = mAudioPlaybackClients.valueAt(index); |
| 317 | mAudioRecordClients.removeItem(portId); |
| 318 | |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 319 | // called from internal thread: no need to clear caller identity |
Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 320 | mAudioPolicyManager->releaseOutput(portId); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 321 | } |
| 322 | |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 323 | status_t AudioPolicyService::getInputForAttr(const audio_attributes_t *attr, |
| 324 | audio_io_handle_t *input, |
| 325 | audio_session_t session, |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 326 | pid_t pid, |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 327 | uid_t uid, |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 328 | const String16& opPackageName, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 329 | const audio_config_base_t *config, |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 330 | audio_input_flags_t flags, |
Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 331 | audio_port_handle_t *selectedDeviceId, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 332 | audio_port_handle_t *portId) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 333 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 334 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 335 | return NO_INIT; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 336 | } |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 337 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 338 | // 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^] | 339 | if ((attr->source < AUDIO_SOURCE_DEFAULT) |
| 340 | || (attr->source >= AUDIO_SOURCE_CNT |
| 341 | && attr->source != AUDIO_SOURCE_HOTWORD |
| 342 | && attr->source != AUDIO_SOURCE_FM_TUNER |
| 343 | && attr->source != AUDIO_SOURCE_ECHO_REFERENCE)) { |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 344 | return BAD_VALUE; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 345 | } |
| 346 | |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 347 | bool updatePid = (pid == -1); |
Marco Nelissen | dcb346b | 2015-09-09 10:47:29 -0700 | [diff] [blame] | 348 | const uid_t callingUid = IPCThreadState::self()->getCallingUid(); |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 349 | if (!isAudioServerOrMediaServerUid(callingUid)) { |
Eric Laurent | 9f39f8d | 2016-05-25 12:34:48 -0700 | [diff] [blame] | 350 | ALOGW_IF(uid != (uid_t)-1 && uid != callingUid, |
Marco Nelissen | dcb346b | 2015-09-09 10:47:29 -0700 | [diff] [blame] | 351 | "%s uid %d tried to pass itself off as %d", __FUNCTION__, callingUid, uid); |
| 352 | uid = callingUid; |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 353 | updatePid = true; |
| 354 | } |
| 355 | |
| 356 | if (updatePid) { |
| 357 | const pid_t callingPid = IPCThreadState::self()->getCallingPid(); |
Eric Laurent | 9f39f8d | 2016-05-25 12:34:48 -0700 | [diff] [blame] | 358 | ALOGW_IF(pid != (pid_t)-1 && pid != callingPid, |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 359 | "%s uid %d pid %d tried to pass itself off as pid %d", |
| 360 | __func__, callingUid, callingPid, pid); |
| 361 | pid = callingPid; |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 364 | // check calling permissions |
| 365 | if (!recordingAllowed(opPackageName, pid, uid)) { |
| 366 | ALOGE("%s permission denied: recording not allowed for uid %d pid %d", |
| 367 | __func__, uid, pid); |
| 368 | return PERMISSION_DENIED; |
| 369 | } |
| 370 | |
Nadav Bar | 744be48 | 2018-05-08 13:26:21 +0300 | [diff] [blame] | 371 | if ((attr->source == AUDIO_SOURCE_VOICE_UPLINK || |
| 372 | attr->source == AUDIO_SOURCE_VOICE_DOWNLINK || |
Eric Laurent | ae4b6ec | 2019-01-15 18:34:38 -0800 | [diff] [blame^] | 373 | attr->source == AUDIO_SOURCE_VOICE_CALL || |
| 374 | attr->source == AUDIO_SOURCE_ECHO_REFERENCE) && |
Nadav Bar | 744be48 | 2018-05-08 13:26:21 +0300 | [diff] [blame] | 375 | !captureAudioOutputAllowed(pid, uid)) { |
| 376 | return PERMISSION_DENIED; |
| 377 | } |
| 378 | |
Eric Laurent | 7504b9e | 2017-08-15 18:17:26 -0700 | [diff] [blame] | 379 | if ((attr->source == AUDIO_SOURCE_HOTWORD) && !captureHotwordAllowed(pid, uid)) { |
| 380 | return BAD_VALUE; |
| 381 | } |
| 382 | |
| 383 | sp<AudioPolicyEffects>audioPolicyEffects; |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 384 | { |
Eric Laurent | 7504b9e | 2017-08-15 18:17:26 -0700 | [diff] [blame] | 385 | status_t status; |
| 386 | AudioPolicyInterface::input_type_t inputType; |
| 387 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 388 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 389 | { |
| 390 | AutoCallerClear acc; |
| 391 | // the audio_in_acoustics_t parameter is ignored by get_input() |
| 392 | status = mAudioPolicyManager->getInputForAttr(attr, input, session, uid, |
| 393 | config, |
| 394 | flags, selectedDeviceId, |
| 395 | &inputType, portId); |
| 396 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 397 | audioPolicyEffects = mAudioPolicyEffects; |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 398 | |
| 399 | if (status == NO_ERROR) { |
| 400 | // enforce permission (if any) required for each type of input |
| 401 | switch (inputType) { |
| 402 | case AudioPolicyInterface::API_INPUT_LEGACY: |
| 403 | break; |
Eric Laurent | 82db269 | 2015-08-07 13:59:42 -0700 | [diff] [blame] | 404 | case AudioPolicyInterface::API_INPUT_TELEPHONY_RX: |
| 405 | // FIXME: use the same permission as for remote submix for now. |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 406 | case AudioPolicyInterface::API_INPUT_MIX_CAPTURE: |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 407 | if (!captureAudioOutputAllowed(pid, uid)) { |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 408 | ALOGE("getInputForAttr() permission denied: capture not allowed"); |
| 409 | status = PERMISSION_DENIED; |
| 410 | } |
| 411 | break; |
| 412 | case AudioPolicyInterface::API_INPUT_MIX_EXT_POLICY_REROUTE: |
| 413 | if (!modifyAudioRoutingAllowed()) { |
| 414 | ALOGE("getInputForAttr() permission denied: modify audio routing not allowed"); |
| 415 | status = PERMISSION_DENIED; |
| 416 | } |
| 417 | break; |
| 418 | case AudioPolicyInterface::API_INPUT_INVALID: |
| 419 | default: |
| 420 | LOG_ALWAYS_FATAL("getInputForAttr() encountered an invalid input type %d", |
| 421 | (int)inputType); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | if (status != NO_ERROR) { |
| 426 | if (status == PERMISSION_DENIED) { |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 427 | AutoCallerClear acc; |
Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 428 | mAudioPolicyManager->releaseInput(*portId); |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 429 | } |
| 430 | return status; |
| 431 | } |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 432 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 433 | sp<AudioRecordClient> client = new AudioRecordClient(*attr, *input, uid, pid, session, |
| 434 | *selectedDeviceId, opPackageName); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 435 | mAudioRecordClients.add(*portId, client); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 436 | } |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 437 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 438 | if (audioPolicyEffects != 0) { |
| 439 | // create audio pre processors according to input source |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 440 | status_t status = audioPolicyEffects->addInputEffects(*input, attr->source, session); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 441 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 442 | ALOGW("Failed to add effects on input %d", *input); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 443 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 444 | } |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 445 | return NO_ERROR; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 446 | } |
| 447 | |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 448 | // this is replicated from frameworks/av/media/libaudioclient/AudioRecord.cpp |
| 449 | // XXX -- figure out how to put it into a common, shared location |
| 450 | |
| 451 | static std::string audioSourceString(audio_source_t value) { |
| 452 | std::string source; |
| 453 | if (SourceTypeConverter::toString(value, source)) { |
| 454 | return source; |
| 455 | } |
| 456 | char rawbuffer[16]; // room for "%d" |
| 457 | snprintf(rawbuffer, sizeof(rawbuffer), "%d", value); |
| 458 | return rawbuffer; |
| 459 | } |
| 460 | |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 461 | std::string AudioPolicyService::getDeviceTypeStrForPortId(audio_port_handle_t portId) { |
| 462 | std::string typeStr; |
| 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) { |
| 467 | deviceToString(port.ext.device.type, typeStr); |
| 468 | } |
| 469 | return typeStr; |
| 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 | |
| 526 | MediaAnalyticsItem *item = new MediaAnalyticsItem(kAudioPolicy); |
| 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, |
| 532 | audioSourceString(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, |
| 552 | audioSourceString(other->attributes.source).c_str()); |
| 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 | |
| 701 | uint32_t AudioPolicyService::getStrategyForStream(audio_stream_type_t stream) |
| 702 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 703 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 704 | return 0; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 705 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 706 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 707 | return 0; |
| 708 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 709 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 710 | return mAudioPolicyManager->getStrategyForStream(stream); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | //audio policy: use audio_device_t appropriately |
| 714 | |
| 715 | audio_devices_t AudioPolicyService::getDevicesForStream(audio_stream_type_t stream) |
| 716 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 717 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 718 | return AUDIO_DEVICE_NONE; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 719 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 720 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 721 | return AUDIO_DEVICE_NONE; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 722 | } |
Haynes Mathew George | dfb9f3b | 2015-10-26 18:22:13 -0700 | [diff] [blame] | 723 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 724 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 725 | return mAudioPolicyManager->getDevicesForStream(stream); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | audio_io_handle_t AudioPolicyService::getOutputForEffect(const effect_descriptor_t *desc) |
| 729 | { |
| 730 | // FIXME change return type to status_t, and return NO_INIT here |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 731 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 732 | return 0; |
| 733 | } |
| 734 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 735 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 736 | return mAudioPolicyManager->getOutputForEffect(desc); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | status_t AudioPolicyService::registerEffect(const effect_descriptor_t *desc, |
| 740 | audio_io_handle_t io, |
| 741 | uint32_t strategy, |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 742 | audio_session_t session, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 743 | int id) |
| 744 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 745 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 746 | return NO_INIT; |
| 747 | } |
Haynes Mathew George | bab7bf4 | 2015-10-30 18:02:23 -0700 | [diff] [blame] | 748 | Mutex::Autolock _l(mEffectsLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 749 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 750 | return mAudioPolicyManager->registerEffect(desc, io, strategy, session, id); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | status_t AudioPolicyService::unregisterEffect(int id) |
| 754 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 755 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 756 | return NO_INIT; |
| 757 | } |
Haynes Mathew George | bab7bf4 | 2015-10-30 18:02:23 -0700 | [diff] [blame] | 758 | Mutex::Autolock _l(mEffectsLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 759 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 760 | return mAudioPolicyManager->unregisterEffect(id); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | status_t AudioPolicyService::setEffectEnabled(int id, bool enabled) |
| 764 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 765 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 766 | return NO_INIT; |
| 767 | } |
Haynes Mathew George | bab7bf4 | 2015-10-30 18:02:23 -0700 | [diff] [blame] | 768 | Mutex::Autolock _l(mEffectsLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 769 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 770 | return mAudioPolicyManager->setEffectEnabled(id, enabled); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | bool AudioPolicyService::isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const |
| 774 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 775 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 776 | return false; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 777 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 778 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 779 | return false; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 780 | } |
| 781 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 782 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 783 | return mAudioPolicyManager->isStreamActive(stream, inPastMs); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | bool AudioPolicyService::isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const |
| 787 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 788 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 789 | return false; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 790 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 791 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 792 | return false; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 793 | } |
| 794 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 795 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 796 | return mAudioPolicyManager->isStreamActiveRemotely(stream, inPastMs); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | bool AudioPolicyService::isSourceActive(audio_source_t source) const |
| 800 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 801 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 802 | return false; |
| 803 | } |
| 804 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 805 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 806 | return mAudioPolicyManager->isSourceActive(source); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 807 | } |
| 808 | |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 809 | status_t AudioPolicyService::getAudioPolicyEffects(sp<AudioPolicyEffects>& audioPolicyEffects) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 810 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 811 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 812 | return NO_INIT; |
| 813 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 814 | { |
| 815 | Mutex::Autolock _l(mLock); |
| 816 | audioPolicyEffects = mAudioPolicyEffects; |
| 817 | } |
| 818 | if (audioPolicyEffects == 0) { |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 819 | return NO_INIT; |
| 820 | } |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 821 | |
| 822 | return OK; |
| 823 | } |
| 824 | |
| 825 | status_t AudioPolicyService::queryDefaultPreProcessing(audio_session_t audioSession, |
| 826 | effect_descriptor_t *descriptors, |
| 827 | uint32_t *count) |
| 828 | { |
| 829 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 830 | status_t status = getAudioPolicyEffects(audioPolicyEffects); |
| 831 | if (status != OK) { |
| 832 | *count = 0; |
| 833 | return status; |
| 834 | } |
Eric Laurent | fb66dd9 | 2016-01-28 18:32:03 -0800 | [diff] [blame] | 835 | return audioPolicyEffects->queryDefaultInputEffects( |
| 836 | (audio_session_t)audioSession, descriptors, count); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 837 | } |
| 838 | |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 839 | status_t AudioPolicyService::addSourceDefaultEffect(const effect_uuid_t *type, |
| 840 | const String16& opPackageName, |
| 841 | const effect_uuid_t *uuid, |
| 842 | int32_t priority, |
| 843 | audio_source_t source, |
| 844 | audio_unique_id_t* id) |
| 845 | { |
| 846 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 847 | status_t status = getAudioPolicyEffects(audioPolicyEffects); |
| 848 | if (status != OK) { |
| 849 | return status; |
| 850 | } |
| 851 | if (!modifyDefaultAudioEffectsAllowed()) { |
| 852 | return PERMISSION_DENIED; |
| 853 | } |
| 854 | return audioPolicyEffects->addSourceDefaultEffect( |
| 855 | type, opPackageName, uuid, priority, source, id); |
| 856 | } |
| 857 | |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 858 | status_t AudioPolicyService::addStreamDefaultEffect(const effect_uuid_t *type, |
| 859 | const String16& opPackageName, |
| 860 | const effect_uuid_t *uuid, |
| 861 | int32_t priority, |
| 862 | audio_usage_t usage, |
| 863 | audio_unique_id_t* id) |
| 864 | { |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 865 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 866 | status_t status = getAudioPolicyEffects(audioPolicyEffects); |
| 867 | if (status != OK) { |
| 868 | return status; |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 869 | } |
| 870 | if (!modifyDefaultAudioEffectsAllowed()) { |
| 871 | return PERMISSION_DENIED; |
| 872 | } |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 873 | return audioPolicyEffects->addStreamDefaultEffect( |
| 874 | type, opPackageName, uuid, priority, usage, id); |
| 875 | } |
| 876 | |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 877 | status_t AudioPolicyService::removeSourceDefaultEffect(audio_unique_id_t id) |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 878 | { |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 879 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 880 | status_t status = getAudioPolicyEffects(audioPolicyEffects); |
| 881 | if (status != OK) { |
| 882 | return status; |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 883 | } |
| 884 | if (!modifyDefaultAudioEffectsAllowed()) { |
| 885 | return PERMISSION_DENIED; |
| 886 | } |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 887 | return audioPolicyEffects->removeSourceDefaultEffect(id); |
| 888 | } |
| 889 | |
| 890 | status_t AudioPolicyService::removeStreamDefaultEffect(audio_unique_id_t id) |
| 891 | { |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 892 | sp<AudioPolicyEffects>audioPolicyEffects; |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 893 | status_t status = getAudioPolicyEffects(audioPolicyEffects); |
| 894 | if (status != OK) { |
| 895 | return status; |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 896 | } |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 897 | if (!modifyDefaultAudioEffectsAllowed()) { |
| 898 | return PERMISSION_DENIED; |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 899 | } |
| 900 | return audioPolicyEffects->removeStreamDefaultEffect(id); |
| 901 | } |
| 902 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 903 | bool AudioPolicyService::isOffloadSupported(const audio_offload_info_t& info) |
| 904 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 905 | if (mAudioPolicyManager == NULL) { |
| 906 | ALOGV("mAudioPolicyManager == NULL"); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 907 | return false; |
| 908 | } |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 909 | Mutex::Autolock _l(mLock); |
Haynes Mathew George | bab7bf4 | 2015-10-30 18:02:23 -0700 | [diff] [blame] | 910 | Mutex::Autolock _le(mEffectsLock); // isOffloadSupported queries for |
| 911 | // non-offloadable effects |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 912 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 913 | return mAudioPolicyManager->isOffloadSupported(info); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 914 | } |
| 915 | |
Michael Chan | a94fbb2 | 2018-04-24 14:31:19 +1000 | [diff] [blame] | 916 | bool AudioPolicyService::isDirectOutputSupported(const audio_config_base_t& config, |
| 917 | const audio_attributes_t& attributes) { |
| 918 | if (mAudioPolicyManager == NULL) { |
| 919 | ALOGV("mAudioPolicyManager == NULL"); |
| 920 | return false; |
| 921 | } |
| 922 | Mutex::Autolock _l(mLock); |
| 923 | return mAudioPolicyManager->isDirectOutputSupported(config, attributes); |
| 924 | } |
| 925 | |
| 926 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 927 | status_t AudioPolicyService::listAudioPorts(audio_port_role_t role, |
| 928 | audio_port_type_t type, |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 929 | unsigned int *num_ports, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 930 | struct audio_port *ports, |
| 931 | unsigned int *generation) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 932 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 933 | Mutex::Autolock _l(mLock); |
| 934 | if (mAudioPolicyManager == NULL) { |
| 935 | return NO_INIT; |
| 936 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 937 | AutoCallerClear acc; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 938 | return mAudioPolicyManager->listAudioPorts(role, type, num_ports, ports, generation); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 939 | } |
| 940 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 941 | status_t AudioPolicyService::getAudioPort(struct audio_port *port) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 942 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 943 | Mutex::Autolock _l(mLock); |
| 944 | if (mAudioPolicyManager == NULL) { |
| 945 | return NO_INIT; |
| 946 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 947 | AutoCallerClear acc; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 948 | return mAudioPolicyManager->getAudioPort(port); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 949 | } |
| 950 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 951 | status_t AudioPolicyService::createAudioPatch(const struct audio_patch *patch, |
| 952 | audio_patch_handle_t *handle) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 953 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 954 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 955 | if(!modifyAudioRoutingAllowed()) { |
| 956 | return PERMISSION_DENIED; |
| 957 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 958 | if (mAudioPolicyManager == NULL) { |
| 959 | return NO_INIT; |
| 960 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 961 | AutoCallerClear acc; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 962 | return mAudioPolicyManager->createAudioPatch(patch, handle, |
| 963 | IPCThreadState::self()->getCallingUid()); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 964 | } |
| 965 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 966 | status_t AudioPolicyService::releaseAudioPatch(audio_patch_handle_t handle) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 967 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 968 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 969 | if(!modifyAudioRoutingAllowed()) { |
| 970 | return PERMISSION_DENIED; |
| 971 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 972 | if (mAudioPolicyManager == NULL) { |
| 973 | return NO_INIT; |
| 974 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 975 | AutoCallerClear acc; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 976 | return mAudioPolicyManager->releaseAudioPatch(handle, |
| 977 | IPCThreadState::self()->getCallingUid()); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | status_t AudioPolicyService::listAudioPatches(unsigned int *num_patches, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 981 | struct audio_patch *patches, |
| 982 | unsigned int *generation) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 983 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 984 | Mutex::Autolock _l(mLock); |
| 985 | if (mAudioPolicyManager == NULL) { |
| 986 | return NO_INIT; |
| 987 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 988 | AutoCallerClear acc; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 989 | return mAudioPolicyManager->listAudioPatches(num_patches, patches, generation); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 990 | } |
| 991 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 992 | status_t AudioPolicyService::setAudioPortConfig(const struct audio_port_config *config) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 993 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 994 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 995 | if(!modifyAudioRoutingAllowed()) { |
| 996 | return PERMISSION_DENIED; |
| 997 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 998 | if (mAudioPolicyManager == NULL) { |
| 999 | return NO_INIT; |
| 1000 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1001 | AutoCallerClear acc; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1002 | return mAudioPolicyManager->setAudioPortConfig(config); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1003 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1004 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1005 | status_t AudioPolicyService::acquireSoundTriggerSession(audio_session_t *session, |
| 1006 | audio_io_handle_t *ioHandle, |
| 1007 | audio_devices_t *device) |
| 1008 | { |
Andy Hung | f759b8c | 2017-08-15 12:48:54 -0700 | [diff] [blame] | 1009 | Mutex::Autolock _l(mLock); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1010 | if (mAudioPolicyManager == NULL) { |
| 1011 | return NO_INIT; |
| 1012 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1013 | AutoCallerClear acc; |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1014 | return mAudioPolicyManager->acquireSoundTriggerSession(session, ioHandle, device); |
| 1015 | } |
| 1016 | |
| 1017 | status_t AudioPolicyService::releaseSoundTriggerSession(audio_session_t session) |
| 1018 | { |
Andy Hung | f759b8c | 2017-08-15 12:48:54 -0700 | [diff] [blame] | 1019 | Mutex::Autolock _l(mLock); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -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 | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1024 | return mAudioPolicyManager->releaseSoundTriggerSession(session); |
| 1025 | } |
| 1026 | |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 1027 | status_t AudioPolicyService::registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration) |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1028 | { |
| 1029 | Mutex::Autolock _l(mLock); |
| 1030 | if(!modifyAudioRoutingAllowed()) { |
| 1031 | return PERMISSION_DENIED; |
| 1032 | } |
| 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 | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1037 | if (registration) { |
| 1038 | return mAudioPolicyManager->registerPolicyMixes(mixes); |
| 1039 | } else { |
| 1040 | return mAudioPolicyManager->unregisterPolicyMixes(mixes); |
| 1041 | } |
| 1042 | } |
| 1043 | |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1044 | status_t AudioPolicyService::setUidDeviceAffinities(uid_t uid, |
| 1045 | const Vector<AudioDeviceTypeAddr>& devices) { |
| 1046 | Mutex::Autolock _l(mLock); |
| 1047 | if(!modifyAudioRoutingAllowed()) { |
| 1048 | return PERMISSION_DENIED; |
| 1049 | } |
| 1050 | if (mAudioPolicyManager == NULL) { |
| 1051 | return NO_INIT; |
| 1052 | } |
| 1053 | AutoCallerClear acc; |
| 1054 | return mAudioPolicyManager->setUidDeviceAffinities(uid, devices); |
| 1055 | } |
| 1056 | |
| 1057 | status_t AudioPolicyService::removeUidDeviceAffinities(uid_t uid) { |
| 1058 | Mutex::Autolock _l(mLock); |
| 1059 | if(!modifyAudioRoutingAllowed()) { |
| 1060 | return PERMISSION_DENIED; |
| 1061 | } |
| 1062 | if (mAudioPolicyManager == NULL) { |
| 1063 | return NO_INIT; |
| 1064 | } |
| 1065 | AutoCallerClear acc; |
| 1066 | return mAudioPolicyManager->removeUidDeviceAffinities(uid); |
| 1067 | } |
| 1068 | |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1069 | status_t AudioPolicyService::startAudioSource(const struct audio_port_config *source, |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 1070 | const audio_attributes_t *attributes, |
| 1071 | audio_port_handle_t *portId) |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1072 | { |
| 1073 | Mutex::Autolock _l(mLock); |
| 1074 | if (mAudioPolicyManager == NULL) { |
| 1075 | return NO_INIT; |
| 1076 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1077 | AutoCallerClear acc; |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 1078 | return mAudioPolicyManager->startAudioSource(source, attributes, portId, |
Eric Laurent | d60560a | 2015-04-10 11:31:20 -0700 | [diff] [blame] | 1079 | IPCThreadState::self()->getCallingUid()); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1080 | } |
| 1081 | |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 1082 | status_t AudioPolicyService::stopAudioSource(audio_port_handle_t portId) |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1083 | { |
| 1084 | Mutex::Autolock _l(mLock); |
| 1085 | if (mAudioPolicyManager == NULL) { |
| 1086 | return NO_INIT; |
| 1087 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1088 | AutoCallerClear acc; |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 1089 | return mAudioPolicyManager->stopAudioSource(portId); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1092 | status_t AudioPolicyService::setMasterMono(bool mono) |
| 1093 | { |
| 1094 | if (mAudioPolicyManager == NULL) { |
| 1095 | return NO_INIT; |
| 1096 | } |
| 1097 | if (!settingsAllowed()) { |
| 1098 | return PERMISSION_DENIED; |
| 1099 | } |
| 1100 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1101 | AutoCallerClear acc; |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1102 | return mAudioPolicyManager->setMasterMono(mono); |
| 1103 | } |
| 1104 | |
| 1105 | status_t AudioPolicyService::getMasterMono(bool *mono) |
| 1106 | { |
| 1107 | if (mAudioPolicyManager == NULL) { |
| 1108 | return NO_INIT; |
| 1109 | } |
| 1110 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1111 | AutoCallerClear acc; |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1112 | return mAudioPolicyManager->getMasterMono(mono); |
| 1113 | } |
| 1114 | |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1115 | |
| 1116 | float AudioPolicyService::getStreamVolumeDB( |
| 1117 | audio_stream_type_t stream, int index, audio_devices_t device) |
| 1118 | { |
| 1119 | if (mAudioPolicyManager == NULL) { |
| 1120 | return NAN; |
| 1121 | } |
| 1122 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1123 | AutoCallerClear acc; |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1124 | return mAudioPolicyManager->getStreamVolumeDB(stream, index, device); |
| 1125 | } |
| 1126 | |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1127 | status_t AudioPolicyService::getSurroundFormats(unsigned int *numSurroundFormats, |
| 1128 | audio_format_t *surroundFormats, |
| 1129 | bool *surroundFormatsEnabled, |
| 1130 | bool reported) |
| 1131 | { |
| 1132 | if (mAudioPolicyManager == NULL) { |
| 1133 | return NO_INIT; |
| 1134 | } |
| 1135 | Mutex::Autolock _l(mLock); |
| 1136 | AutoCallerClear acc; |
| 1137 | return mAudioPolicyManager->getSurroundFormats(numSurroundFormats, surroundFormats, |
| 1138 | surroundFormatsEnabled, reported); |
| 1139 | } |
| 1140 | |
| 1141 | status_t AudioPolicyService::setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled) |
| 1142 | { |
| 1143 | if (mAudioPolicyManager == NULL) { |
| 1144 | return NO_INIT; |
| 1145 | } |
| 1146 | Mutex::Autolock _l(mLock); |
| 1147 | AutoCallerClear acc; |
| 1148 | return mAudioPolicyManager->setSurroundFormatEnabled(audioFormat, enabled); |
| 1149 | } |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1150 | |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1151 | status_t AudioPolicyService::setAssistantUid(uid_t uid) |
| 1152 | { |
| 1153 | Mutex::Autolock _l(mLock); |
| 1154 | mUidPolicy->setAssistantUid(uid); |
| 1155 | return NO_ERROR; |
| 1156 | } |
| 1157 | |
| 1158 | status_t AudioPolicyService::setA11yServicesUids(const std::vector<uid_t>& uids) |
| 1159 | { |
| 1160 | Mutex::Autolock _l(mLock); |
| 1161 | mUidPolicy->setA11yUids(uids); |
| 1162 | return NO_ERROR; |
| 1163 | } |
| 1164 | |
jiabin | 6012f91 | 2018-11-02 17:06:30 -0700 | [diff] [blame] | 1165 | bool AudioPolicyService::isHapticPlaybackSupported() |
| 1166 | { |
| 1167 | if (mAudioPolicyManager == NULL) { |
| 1168 | ALOGW("%s, mAudioPolicyManager == NULL", __func__); |
| 1169 | return false; |
| 1170 | } |
| 1171 | Mutex::Autolock _l(mLock); |
| 1172 | AutoCallerClear acc; |
| 1173 | return mAudioPolicyManager->isHapticPlaybackSupported(); |
| 1174 | } |
| 1175 | |
Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 1176 | } // namespace android |