Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [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 | |
| 17 | #define LOG_TAG "AudioPolicyService" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | |
Glenn Kasten | 153b9fe | 2013-07-15 11:23:36 -0700 | [diff] [blame] | 20 | #include "Configuration.h" |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 21 | #undef __STRICT_ANSI__ |
| 22 | #define __STDINT_LIMITS |
| 23 | #define __STDC_LIMIT_MACROS |
| 24 | #include <stdint.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 25 | #include <sys/time.h> |
Mikhail Naganov | 959e2d0 | 2019-03-28 11:08:19 -0700 | [diff] [blame] | 26 | |
| 27 | #include <audio_utils/clock.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 28 | #include <binder/IServiceManager.h> |
| 29 | #include <utils/Log.h> |
| 30 | #include <cutils/properties.h> |
| 31 | #include <binder/IPCThreadState.h> |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 32 | #include <binder/ActivityManager.h> |
| 33 | #include <binder/PermissionController.h> |
| 34 | #include <binder/IResultReceiver.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 35 | #include <utils/String16.h> |
| 36 | #include <utils/threads.h> |
| 37 | #include "AudioPolicyService.h" |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 38 | #include <hardware_legacy/power.h> |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 39 | #include <media/AudioEffect.h> |
Chih-Hung Hsieh | c84d9d2 | 2014-11-14 13:33:34 -0800 | [diff] [blame] | 40 | #include <media/AudioParameter.h> |
Andy Hung | ab7ef30 | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 41 | #include <mediautils/ServiceUtilities.h> |
Michael Groover | cfd2830 | 2018-12-11 19:16:46 -0800 | [diff] [blame] | 42 | #include <sensorprivacy/SensorPrivacyManager.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 43 | |
Dima Zavin | 6476024 | 2011-05-11 14:15:23 -0700 | [diff] [blame] | 44 | #include <system/audio.h> |
Dima Zavin | 7394a4f | 2011-06-13 18:16:26 -0700 | [diff] [blame] | 45 | #include <system/audio_policy.h> |
Mikhail Naganov | 61a4fac | 2016-10-13 14:44:18 -0700 | [diff] [blame] | 46 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 47 | namespace android { |
| 48 | |
Glenn Kasten | 8dad0e3 | 2012-01-09 08:41:22 -0800 | [diff] [blame] | 49 | static const char kDeadlockedString[] = "AudioPolicyService may be deadlocked\n"; |
| 50 | static const char kCmdDeadlockedString[] = "AudioPolicyService command thread may be deadlocked\n"; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 51 | |
Mikhail Naganov | 959e2d0 | 2019-03-28 11:08:19 -0700 | [diff] [blame] | 52 | static const int kDumpLockTimeoutNs = 1 * NANOS_PER_SECOND; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 53 | |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 54 | static const nsecs_t kAudioCommandTimeoutNs = seconds(3); // 3 seconds |
Christer Fletcher | 5fa8c4b | 2013-01-18 15:27:03 +0100 | [diff] [blame] | 55 | |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 56 | static const String16 sManageAudioPolicyPermission("android.permission.MANAGE_AUDIO_POLICY"); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 57 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 58 | // ---------------------------------------------------------------------------- |
| 59 | |
| 60 | AudioPolicyService::AudioPolicyService() |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 61 | : BnAudioPolicyService(), mpAudioPolicyDev(NULL), mpAudioPolicy(NULL), |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 62 | mAudioPolicyManager(NULL), mAudioPolicyClient(NULL), mPhoneState(AUDIO_MODE_INVALID) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 63 | { |
Eric Laurent | f5ada6e | 2014-10-09 17:49:00 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | void AudioPolicyService::onFirstRef() |
| 67 | { |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 68 | { |
| 69 | Mutex::Autolock _l(mLock); |
Eric Laurent | 9357520 | 2011-01-18 18:39:02 -0800 | [diff] [blame] | 70 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 71 | // start audio commands thread |
| 72 | mAudioCommandThread = new AudioCommandThread(String8("ApmAudio"), this); |
| 73 | // start output activity command thread |
| 74 | mOutputCommandThread = new AudioCommandThread(String8("ApmOutput"), this); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 75 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 76 | mAudioPolicyClient = new AudioPolicyClient(this); |
| 77 | mAudioPolicyManager = createAudioPolicyManager(mAudioPolicyClient); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 78 | } |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame] | 79 | // load audio processing modules |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 80 | sp<AudioPolicyEffects>audioPolicyEffects = new AudioPolicyEffects(); |
| 81 | { |
| 82 | Mutex::Autolock _l(mLock); |
| 83 | mAudioPolicyEffects = audioPolicyEffects; |
| 84 | } |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 85 | |
| 86 | mUidPolicy = new UidPolicy(this); |
| 87 | mUidPolicy->registerSelf(); |
Michael Groover | cfd2830 | 2018-12-11 19:16:46 -0800 | [diff] [blame] | 88 | |
| 89 | mSensorPrivacyPolicy = new SensorPrivacyPolicy(this); |
| 90 | mSensorPrivacyPolicy->registerSelf(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | AudioPolicyService::~AudioPolicyService() |
| 94 | { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 95 | mAudioCommandThread->exit(); |
Eric Laurent | 657ff61 | 2014-05-07 11:58:24 -0700 | [diff] [blame] | 96 | mOutputCommandThread->exit(); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 97 | |
Eric Laurent | f269b8e | 2014-06-09 20:01:29 -0700 | [diff] [blame] | 98 | destroyAudioPolicyManager(mAudioPolicyManager); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 99 | delete mAudioPolicyClient; |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 100 | |
| 101 | mNotificationClients.clear(); |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame] | 102 | mAudioPolicyEffects.clear(); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 103 | |
| 104 | mUidPolicy->unregisterSelf(); |
| 105 | mUidPolicy.clear(); |
Michael Groover | cfd2830 | 2018-12-11 19:16:46 -0800 | [diff] [blame] | 106 | |
| 107 | mSensorPrivacyPolicy->unregisterSelf(); |
| 108 | mSensorPrivacyPolicy.clear(); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | // A notification client is always registered by AudioSystem when the client process |
| 112 | // connects to AudioPolicyService. |
| 113 | void AudioPolicyService::registerClient(const sp<IAudioPolicyServiceClient>& client) |
| 114 | { |
Eric Laurent | 1259025 | 2015-08-21 18:40:20 -0700 | [diff] [blame] | 115 | if (client == 0) { |
| 116 | ALOGW("%s got NULL client", __FUNCTION__); |
| 117 | return; |
| 118 | } |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 119 | Mutex::Autolock _l(mNotificationClientsLock); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 120 | |
| 121 | uid_t uid = IPCThreadState::self()->getCallingUid(); |
luochaojiang | 908c7d7 | 2018-06-21 14:58:04 +0800 | [diff] [blame] | 122 | pid_t pid = IPCThreadState::self()->getCallingPid(); |
| 123 | int64_t token = ((int64_t)uid<<32) | pid; |
| 124 | |
| 125 | if (mNotificationClients.indexOfKey(token) < 0) { |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 126 | sp<NotificationClient> notificationClient = new NotificationClient(this, |
| 127 | client, |
luochaojiang | 908c7d7 | 2018-06-21 14:58:04 +0800 | [diff] [blame] | 128 | uid, |
| 129 | pid); |
| 130 | ALOGV("registerClient() client %p, uid %d pid %d", client.get(), uid, pid); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 131 | |
luochaojiang | 908c7d7 | 2018-06-21 14:58:04 +0800 | [diff] [blame] | 132 | mNotificationClients.add(token, notificationClient); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 133 | |
Marco Nelissen | f888020 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 134 | sp<IBinder> binder = IInterface::asBinder(client); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 135 | binder->linkToDeath(notificationClient); |
| 136 | } |
| 137 | } |
| 138 | |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 139 | void AudioPolicyService::setAudioPortCallbacksEnabled(bool enabled) |
| 140 | { |
| 141 | Mutex::Autolock _l(mNotificationClientsLock); |
| 142 | |
| 143 | uid_t uid = IPCThreadState::self()->getCallingUid(); |
luochaojiang | 908c7d7 | 2018-06-21 14:58:04 +0800 | [diff] [blame] | 144 | pid_t pid = IPCThreadState::self()->getCallingPid(); |
| 145 | int64_t token = ((int64_t)uid<<32) | pid; |
| 146 | |
| 147 | if (mNotificationClients.indexOfKey(token) < 0) { |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 148 | return; |
| 149 | } |
luochaojiang | 908c7d7 | 2018-06-21 14:58:04 +0800 | [diff] [blame] | 150 | mNotificationClients.valueFor(token)->setAudioPortCallbacksEnabled(enabled); |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 151 | } |
| 152 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 153 | void AudioPolicyService::setAudioVolumeGroupCallbacksEnabled(bool enabled) |
| 154 | { |
| 155 | Mutex::Autolock _l(mNotificationClientsLock); |
| 156 | |
| 157 | uid_t uid = IPCThreadState::self()->getCallingUid(); |
| 158 | pid_t pid = IPCThreadState::self()->getCallingPid(); |
| 159 | int64_t token = ((int64_t)uid<<32) | pid; |
| 160 | |
| 161 | if (mNotificationClients.indexOfKey(token) < 0) { |
| 162 | return; |
| 163 | } |
| 164 | mNotificationClients.valueFor(token)->setAudioVolumeGroupCallbacksEnabled(enabled); |
| 165 | } |
| 166 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 167 | // removeNotificationClient() is called when the client process dies. |
luochaojiang | 908c7d7 | 2018-06-21 14:58:04 +0800 | [diff] [blame] | 168 | void AudioPolicyService::removeNotificationClient(uid_t uid, pid_t pid) |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 169 | { |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 170 | { |
| 171 | Mutex::Autolock _l(mNotificationClientsLock); |
luochaojiang | 908c7d7 | 2018-06-21 14:58:04 +0800 | [diff] [blame] | 172 | int64_t token = ((int64_t)uid<<32) | pid; |
| 173 | mNotificationClients.removeItem(token); |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 174 | } |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 175 | { |
| 176 | Mutex::Autolock _l(mLock); |
luochaojiang | 908c7d7 | 2018-06-21 14:58:04 +0800 | [diff] [blame] | 177 | bool hasSameUid = false; |
| 178 | for (size_t i = 0; i < mNotificationClients.size(); i++) { |
| 179 | if (mNotificationClients.valueAt(i)->uid() == uid) { |
| 180 | hasSameUid = true; |
| 181 | break; |
| 182 | } |
| 183 | } |
| 184 | if (mAudioPolicyManager && !hasSameUid) { |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 185 | // called from binder death notification: no need to clear caller identity |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 186 | mAudioPolicyManager->releaseResourcesForUid(uid); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 187 | } |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 188 | } |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | void AudioPolicyService::onAudioPortListUpdate() |
| 192 | { |
| 193 | mOutputCommandThread->updateAudioPortListCommand(); |
| 194 | } |
| 195 | |
| 196 | void AudioPolicyService::doOnAudioPortListUpdate() |
| 197 | { |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 198 | Mutex::Autolock _l(mNotificationClientsLock); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 199 | for (size_t i = 0; i < mNotificationClients.size(); i++) { |
| 200 | mNotificationClients.valueAt(i)->onAudioPortListUpdate(); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | void AudioPolicyService::onAudioPatchListUpdate() |
| 205 | { |
| 206 | mOutputCommandThread->updateAudioPatchListCommand(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 209 | void AudioPolicyService::doOnAudioPatchListUpdate() |
| 210 | { |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 211 | Mutex::Autolock _l(mNotificationClientsLock); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 212 | for (size_t i = 0; i < mNotificationClients.size(); i++) { |
| 213 | mNotificationClients.valueAt(i)->onAudioPatchListUpdate(); |
| 214 | } |
| 215 | } |
| 216 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 217 | void AudioPolicyService::onAudioVolumeGroupChanged(volume_group_t group, int flags) |
| 218 | { |
| 219 | mOutputCommandThread->changeAudioVolumeGroupCommand(group, flags); |
| 220 | } |
| 221 | |
| 222 | void AudioPolicyService::doOnAudioVolumeGroupChanged(volume_group_t group, int flags) |
| 223 | { |
| 224 | Mutex::Autolock _l(mNotificationClientsLock); |
| 225 | for (size_t i = 0; i < mNotificationClients.size(); i++) { |
| 226 | mNotificationClients.valueAt(i)->onAudioVolumeGroupChanged(group, flags); |
| 227 | } |
| 228 | } |
| 229 | |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 230 | void AudioPolicyService::onDynamicPolicyMixStateUpdate(const String8& regId, int32_t state) |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 231 | { |
| 232 | ALOGV("AudioPolicyService::onDynamicPolicyMixStateUpdate(%s, %d)", |
| 233 | regId.string(), state); |
| 234 | mOutputCommandThread->dynamicPolicyMixStateUpdateCommand(regId, state); |
| 235 | } |
| 236 | |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 237 | void AudioPolicyService::doOnDynamicPolicyMixStateUpdate(const String8& regId, int32_t state) |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 238 | { |
| 239 | Mutex::Autolock _l(mNotificationClientsLock); |
| 240 | for (size_t i = 0; i < mNotificationClients.size(); i++) { |
| 241 | mNotificationClients.valueAt(i)->onDynamicPolicyMixStateUpdate(regId, state); |
| 242 | } |
| 243 | } |
| 244 | |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 245 | void AudioPolicyService::onRecordingConfigurationUpdate( |
| 246 | int event, |
| 247 | const record_client_info_t *clientInfo, |
| 248 | const audio_config_base_t *clientConfig, |
| 249 | std::vector<effect_descriptor_t> clientEffects, |
| 250 | const audio_config_base_t *deviceConfig, |
| 251 | std::vector<effect_descriptor_t> effects, |
| 252 | audio_patch_handle_t patchHandle, |
| 253 | audio_source_t source) |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 254 | { |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 255 | mOutputCommandThread->recordingConfigurationUpdateCommand(event, clientInfo, |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 256 | clientConfig, clientEffects, deviceConfig, effects, patchHandle, source); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 257 | } |
| 258 | |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 259 | void AudioPolicyService::doOnRecordingConfigurationUpdate( |
| 260 | int event, |
| 261 | const record_client_info_t *clientInfo, |
| 262 | const audio_config_base_t *clientConfig, |
| 263 | std::vector<effect_descriptor_t> clientEffects, |
| 264 | const audio_config_base_t *deviceConfig, |
| 265 | std::vector<effect_descriptor_t> effects, |
| 266 | audio_patch_handle_t patchHandle, |
| 267 | audio_source_t source) |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 268 | { |
| 269 | Mutex::Autolock _l(mNotificationClientsLock); |
| 270 | for (size_t i = 0; i < mNotificationClients.size(); i++) { |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 271 | mNotificationClients.valueAt(i)->onRecordingConfigurationUpdate(event, clientInfo, |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 272 | clientConfig, clientEffects, deviceConfig, effects, patchHandle, source); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 273 | } |
| 274 | } |
| 275 | |
| 276 | status_t AudioPolicyService::clientCreateAudioPatch(const struct audio_patch *patch, |
| 277 | audio_patch_handle_t *handle, |
| 278 | int delayMs) |
| 279 | { |
| 280 | return mAudioCommandThread->createAudioPatchCommand(patch, handle, delayMs); |
| 281 | } |
| 282 | |
| 283 | status_t AudioPolicyService::clientReleaseAudioPatch(audio_patch_handle_t handle, |
| 284 | int delayMs) |
| 285 | { |
| 286 | return mAudioCommandThread->releaseAudioPatchCommand(handle, delayMs); |
| 287 | } |
| 288 | |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 289 | status_t AudioPolicyService::clientSetAudioPortConfig(const struct audio_port_config *config, |
| 290 | int delayMs) |
| 291 | { |
| 292 | return mAudioCommandThread->setAudioPortConfigCommand(config, delayMs); |
| 293 | } |
| 294 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 295 | AudioPolicyService::NotificationClient::NotificationClient(const sp<AudioPolicyService>& service, |
| 296 | const sp<IAudioPolicyServiceClient>& client, |
luochaojiang | 908c7d7 | 2018-06-21 14:58:04 +0800 | [diff] [blame] | 297 | uid_t uid, |
| 298 | pid_t pid) |
| 299 | : mService(service), mUid(uid), mPid(pid), mAudioPolicyServiceClient(client), |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 300 | mAudioPortCallbacksEnabled(false), mAudioVolumeGroupCallbacksEnabled(false) |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 301 | { |
| 302 | } |
| 303 | |
| 304 | AudioPolicyService::NotificationClient::~NotificationClient() |
| 305 | { |
| 306 | } |
| 307 | |
| 308 | void AudioPolicyService::NotificationClient::binderDied(const wp<IBinder>& who __unused) |
| 309 | { |
| 310 | sp<NotificationClient> keep(this); |
| 311 | sp<AudioPolicyService> service = mService.promote(); |
| 312 | if (service != 0) { |
luochaojiang | 908c7d7 | 2018-06-21 14:58:04 +0800 | [diff] [blame] | 313 | service->removeNotificationClient(mUid, mPid); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | |
| 317 | void AudioPolicyService::NotificationClient::onAudioPortListUpdate() |
| 318 | { |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 319 | if (mAudioPolicyServiceClient != 0 && mAudioPortCallbacksEnabled) { |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 320 | mAudioPolicyServiceClient->onAudioPortListUpdate(); |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | void AudioPolicyService::NotificationClient::onAudioPatchListUpdate() |
| 325 | { |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 326 | if (mAudioPolicyServiceClient != 0 && mAudioPortCallbacksEnabled) { |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 327 | mAudioPolicyServiceClient->onAudioPatchListUpdate(); |
| 328 | } |
| 329 | } |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 330 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 331 | void AudioPolicyService::NotificationClient::onAudioVolumeGroupChanged(volume_group_t group, |
| 332 | int flags) |
| 333 | { |
| 334 | if (mAudioPolicyServiceClient != 0 && mAudioVolumeGroupCallbacksEnabled) { |
| 335 | mAudioPolicyServiceClient->onAudioVolumeGroupChanged(group, flags); |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 340 | void AudioPolicyService::NotificationClient::onDynamicPolicyMixStateUpdate( |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 341 | const String8& regId, int32_t state) |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 342 | { |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 343 | if (mAudioPolicyServiceClient != 0 && isServiceUid(mUid)) { |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 344 | mAudioPolicyServiceClient->onDynamicPolicyMixStateUpdate(regId, state); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | void AudioPolicyService::NotificationClient::onRecordingConfigurationUpdate( |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 349 | int event, |
| 350 | const record_client_info_t *clientInfo, |
| 351 | const audio_config_base_t *clientConfig, |
| 352 | std::vector<effect_descriptor_t> clientEffects, |
| 353 | const audio_config_base_t *deviceConfig, |
| 354 | std::vector<effect_descriptor_t> effects, |
| 355 | audio_patch_handle_t patchHandle, |
| 356 | audio_source_t source) |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 357 | { |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 358 | if (mAudioPolicyServiceClient != 0 && isServiceUid(mUid)) { |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 359 | mAudioPolicyServiceClient->onRecordingConfigurationUpdate(event, clientInfo, |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 360 | clientConfig, clientEffects, deviceConfig, effects, patchHandle, source); |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 361 | } |
| 362 | } |
| 363 | |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 364 | void AudioPolicyService::NotificationClient::setAudioPortCallbacksEnabled(bool enabled) |
| 365 | { |
| 366 | mAudioPortCallbacksEnabled = enabled; |
| 367 | } |
| 368 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 369 | void AudioPolicyService::NotificationClient::setAudioVolumeGroupCallbacksEnabled(bool enabled) |
| 370 | { |
| 371 | mAudioVolumeGroupCallbacksEnabled = enabled; |
| 372 | } |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 373 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 374 | void AudioPolicyService::binderDied(const wp<IBinder>& who) { |
Glenn Kasten | 411e447 | 2012-11-02 10:00:06 -0700 | [diff] [blame] | 375 | ALOGW("binderDied() %p, calling pid %d", who.unsafe_get(), |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 376 | IPCThreadState::self()->getCallingPid()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Mikhail Naganov | 959e2d0 | 2019-03-28 11:08:19 -0700 | [diff] [blame] | 379 | static bool dumpTryLock(Mutex& mutex) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 380 | { |
Mikhail Naganov | 959e2d0 | 2019-03-28 11:08:19 -0700 | [diff] [blame] | 381 | status_t err = mutex.timedLock(kDumpLockTimeoutNs); |
| 382 | return err == NO_ERROR; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | status_t AudioPolicyService::dumpInternals(int fd) |
| 386 | { |
| 387 | const size_t SIZE = 256; |
| 388 | char buffer[SIZE]; |
| 389 | String8 result; |
| 390 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 391 | snprintf(buffer, SIZE, "AudioPolicyManager: %p\n", mAudioPolicyManager); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 392 | result.append(buffer); |
| 393 | snprintf(buffer, SIZE, "Command Thread: %p\n", mAudioCommandThread.get()); |
| 394 | result.append(buffer); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 395 | |
| 396 | write(fd, result.string(), result.size()); |
| 397 | return NO_ERROR; |
| 398 | } |
| 399 | |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 400 | void AudioPolicyService::updateUidStates() |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 401 | { |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 402 | Mutex::Autolock _l(mLock); |
| 403 | updateUidStates_l(); |
| 404 | } |
| 405 | |
| 406 | void AudioPolicyService::updateUidStates_l() |
| 407 | { |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 408 | // Go over all active clients and allow capture (does not force silence) in the |
| 409 | // following cases: |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 410 | // Another client in the same UID has already been allowed to capture |
| 411 | // OR The client is the assistant |
Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame^] | 412 | // AND an accessibility service is on TOP or a RTT call is active |
Eric Laurent | a46bedb | 2018-12-07 18:01:26 -0800 | [diff] [blame] | 413 | // AND the source is VOICE_RECOGNITION or HOTWORD |
Eric Laurent | a171e35 | 2019-05-07 13:04:45 -0700 | [diff] [blame] | 414 | // OR uses VOICE_RECOGNITION AND is on TOP |
Eric Laurent | a46bedb | 2018-12-07 18:01:26 -0800 | [diff] [blame] | 415 | // OR uses HOTWORD |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 416 | // AND there is no active privacy sensitive capture or call |
| 417 | // OR client has CAPTURE_AUDIO_OUTPUT privileged permission |
Eric Laurent | a46bedb | 2018-12-07 18:01:26 -0800 | [diff] [blame] | 418 | // OR The client is an accessibility service |
Eric Laurent | a171e35 | 2019-05-07 13:04:45 -0700 | [diff] [blame] | 419 | // AND is on TOP |
Eric Laurent | a46bedb | 2018-12-07 18:01:26 -0800 | [diff] [blame] | 420 | // AND the source is VOICE_RECOGNITION or HOTWORD |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 421 | // OR the client source is virtual (remote submix, call audio TX or RX...) |
Eric Laurent | a171e35 | 2019-05-07 13:04:45 -0700 | [diff] [blame] | 422 | // OR Any client |
Eric Laurent | a46bedb | 2018-12-07 18:01:26 -0800 | [diff] [blame] | 423 | // AND The assistant is not on TOP |
Eric Laurent | a171e35 | 2019-05-07 13:04:45 -0700 | [diff] [blame] | 424 | // AND is on TOP or latest started |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 425 | // AND there is no active privacy sensitive capture or call |
| 426 | // OR client has CAPTURE_AUDIO_OUTPUT privileged permission |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 427 | |
| 428 | sp<AudioRecordClient> topActive; |
| 429 | sp<AudioRecordClient> latestActive; |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 430 | sp<AudioRecordClient> latestSensitiveActive; |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 431 | |
Eric Laurent | a46bedb | 2018-12-07 18:01:26 -0800 | [diff] [blame] | 432 | nsecs_t topStartNs = 0; |
| 433 | nsecs_t latestStartNs = 0; |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 434 | nsecs_t latestSensitiveStartNs = 0; |
| 435 | bool isA11yOnTop = mUidPolicy->isA11yOnTop(); |
| 436 | bool isAssistantOnTop = false; |
| 437 | bool isSensitiveActive = false; |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 438 | bool isInCall = mPhoneState == AUDIO_MODE_IN_CALL; |
Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame^] | 439 | bool rttCallActive = |
| 440 | (mPhoneState == AUDIO_MODE_IN_CALL || mPhoneState == AUDIO_MODE_IN_COMMUNICATION) |
| 441 | && mUidPolicy->isRttEnabled(); |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 442 | |
Michael Groover | cfd2830 | 2018-12-11 19:16:46 -0800 | [diff] [blame] | 443 | // if Sensor Privacy is enabled then all recordings should be silenced. |
| 444 | if (mSensorPrivacyPolicy->isSensorPrivacyEnabled()) { |
| 445 | silenceAllRecordings_l(); |
| 446 | return; |
| 447 | } |
| 448 | |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 449 | for (size_t i =0; i < mAudioRecordClients.size(); i++) { |
| 450 | sp<AudioRecordClient> current = mAudioRecordClients[i]; |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 451 | if (!current->active) { |
| 452 | continue; |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 453 | } |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 454 | |
| 455 | app_state_t appState = apmStatFromAmState(mUidPolicy->getUidState(current->uid)); |
| 456 | // clients which app is in IDLE state are not eligible for top active or |
| 457 | // latest active |
| 458 | if (appState == APP_STATE_IDLE) { |
| 459 | continue; |
| 460 | } |
| 461 | |
| 462 | if (appState == APP_STATE_TOP) { |
Eric Laurent | a46bedb | 2018-12-07 18:01:26 -0800 | [diff] [blame] | 463 | if (current->startTimeNs > topStartNs) { |
| 464 | topActive = current; |
| 465 | topStartNs = current->startTimeNs; |
| 466 | } |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 467 | if (mUidPolicy->isAssistantUid(current->uid)) { |
| 468 | isAssistantOnTop = true; |
| 469 | } |
| 470 | } |
| 471 | if (current->startTimeNs > latestStartNs) { |
| 472 | latestActive = current; |
| 473 | latestStartNs = current->startTimeNs; |
| 474 | } |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 475 | if (isPrivacySensitiveSource(current->attributes.source)) { |
| 476 | if (current->startTimeNs > latestSensitiveStartNs) { |
| 477 | latestSensitiveActive = current; |
| 478 | latestSensitiveStartNs = current->startTimeNs; |
| 479 | } |
| 480 | isSensitiveActive = true; |
| 481 | } |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 482 | } |
| 483 | |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 484 | // if no active client with UI on Top, consider latest active as top |
| 485 | if (topActive == nullptr) { |
| 486 | topActive = latestActive; |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 487 | } |
| 488 | |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 489 | std::vector<uid_t> enabledUids; |
Eric Laurent | a46bedb | 2018-12-07 18:01:26 -0800 | [diff] [blame] | 490 | |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 491 | for (size_t i =0; i < mAudioRecordClients.size(); i++) { |
| 492 | sp<AudioRecordClient> current = mAudioRecordClients[i]; |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 493 | if (!current->active) { |
| 494 | continue; |
| 495 | } |
| 496 | |
| 497 | // keep capture allowed if another client with the same UID has already |
| 498 | // been allowed to capture |
| 499 | if (std::find(enabledUids.begin(), enabledUids.end(), current->uid) |
| 500 | != enabledUids.end()) { |
| 501 | continue; |
| 502 | } |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 503 | |
| 504 | audio_source_t source = current->attributes.source; |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 505 | bool isTopOrLatestActive = topActive == nullptr ? false : current->uid == topActive->uid; |
| 506 | bool isLatestSensitive = latestSensitiveActive == nullptr ? |
| 507 | false : current->uid == latestSensitiveActive->uid; |
| 508 | |
| 509 | // By default allow capture if: |
| 510 | // The assistant is not on TOP |
Eric Laurent | a171e35 | 2019-05-07 13:04:45 -0700 | [diff] [blame] | 511 | // AND is on TOP or latest started |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 512 | // AND there is no active privacy sensitive capture or call |
| 513 | // OR client has CAPTURE_AUDIO_OUTPUT privileged permission |
| 514 | bool allowCapture = !isAssistantOnTop |
Eric Laurent | a171e35 | 2019-05-07 13:04:45 -0700 | [diff] [blame] | 515 | && ((isTopOrLatestActive && !isLatestSensitive) || isLatestSensitive) |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 516 | && !(isSensitiveActive && !(isLatestSensitive || current->canCaptureOutput)) |
| 517 | && !(isInCall && !current->canCaptureOutput); |
Eric Laurent | 2dc962b | 2019-03-01 08:25:25 -0800 | [diff] [blame] | 518 | |
| 519 | if (isVirtualSource(source)) { |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 520 | // Allow capture for virtual (remote submix, call audio TX or RX...) sources |
| 521 | allowCapture = true; |
Eric Laurent | 2dc962b | 2019-03-01 08:25:25 -0800 | [diff] [blame] | 522 | } else if (mUidPolicy->isAssistantUid(current->uid)) { |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 523 | // For assistant allow capture if: |
Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame^] | 524 | // An accessibility service is on TOP or a RTT call is active |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 525 | // AND the source is VOICE_RECOGNITION or HOTWORD |
Eric Laurent | a171e35 | 2019-05-07 13:04:45 -0700 | [diff] [blame] | 526 | // OR is on TOP AND uses VOICE_RECOGNITION |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 527 | // OR uses HOTWORD |
| 528 | // AND there is no active privacy sensitive capture or call |
| 529 | // OR client has CAPTURE_AUDIO_OUTPUT privileged permission |
Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame^] | 530 | if (isA11yOnTop || rttCallActive) { |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 531 | if (source == AUDIO_SOURCE_HOTWORD || source == AUDIO_SOURCE_VOICE_RECOGNITION) { |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 532 | allowCapture = true; |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 533 | } |
| 534 | } else { |
Eric Laurent | a171e35 | 2019-05-07 13:04:45 -0700 | [diff] [blame] | 535 | if (((isAssistantOnTop && source == AUDIO_SOURCE_VOICE_RECOGNITION) || |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 536 | source == AUDIO_SOURCE_HOTWORD) && |
| 537 | (!(isSensitiveActive || isInCall) || current->canCaptureOutput)) { |
| 538 | allowCapture = true; |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 539 | } |
| 540 | } |
| 541 | } else if (mUidPolicy->isA11yUid(current->uid)) { |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 542 | // For accessibility service allow capture if: |
Eric Laurent | a171e35 | 2019-05-07 13:04:45 -0700 | [diff] [blame] | 543 | // Is on TOP |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 544 | // AND the source is VOICE_RECOGNITION or HOTWORD |
Eric Laurent | a171e35 | 2019-05-07 13:04:45 -0700 | [diff] [blame] | 545 | if (isA11yOnTop && |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 546 | (source == AUDIO_SOURCE_VOICE_RECOGNITION || source == AUDIO_SOURCE_HOTWORD)) { |
| 547 | allowCapture = true; |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 548 | } |
| 549 | } |
| 550 | setAppState_l(current->uid, |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 551 | allowCapture ? apmStatFromAmState(mUidPolicy->getUidState(current->uid)) : |
| 552 | APP_STATE_IDLE); |
| 553 | if (allowCapture) { |
| 554 | enabledUids.push_back(current->uid); |
| 555 | } |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 556 | } |
| 557 | } |
| 558 | |
Michael Groover | cfd2830 | 2018-12-11 19:16:46 -0800 | [diff] [blame] | 559 | void AudioPolicyService::silenceAllRecordings_l() { |
| 560 | for (size_t i = 0; i < mAudioRecordClients.size(); i++) { |
| 561 | sp<AudioRecordClient> current = mAudioRecordClients[i]; |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 562 | if (!isVirtualSource(current->attributes.source)) { |
| 563 | setAppState_l(current->uid, APP_STATE_IDLE); |
| 564 | } |
Michael Groover | cfd2830 | 2018-12-11 19:16:46 -0800 | [diff] [blame] | 565 | } |
| 566 | } |
| 567 | |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 568 | /* static */ |
| 569 | app_state_t AudioPolicyService::apmStatFromAmState(int amState) { |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 570 | |
| 571 | if (amState == ActivityManager::PROCESS_STATE_UNKNOWN) { |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 572 | return APP_STATE_IDLE; |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 573 | } else if (amState <= ActivityManager::PROCESS_STATE_TOP) { |
| 574 | // include persistent services |
| 575 | return APP_STATE_TOP; |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 576 | } |
| 577 | return APP_STATE_FOREGROUND; |
| 578 | } |
| 579 | |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 580 | /* static */ |
Eric Laurent | 2dc962b | 2019-03-01 08:25:25 -0800 | [diff] [blame] | 581 | bool AudioPolicyService::isPrivacySensitiveSource(audio_source_t source) |
| 582 | { |
| 583 | switch (source) { |
| 584 | case AUDIO_SOURCE_CAMCORDER: |
| 585 | case AUDIO_SOURCE_VOICE_COMMUNICATION: |
| 586 | return true; |
| 587 | default: |
| 588 | break; |
| 589 | } |
| 590 | return false; |
| 591 | } |
| 592 | |
| 593 | /* static */ |
| 594 | bool AudioPolicyService::isVirtualSource(audio_source_t source) |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 595 | { |
| 596 | switch (source) { |
| 597 | case AUDIO_SOURCE_VOICE_UPLINK: |
| 598 | case AUDIO_SOURCE_VOICE_DOWNLINK: |
| 599 | case AUDIO_SOURCE_VOICE_CALL: |
Eric Laurent | 2dc962b | 2019-03-01 08:25:25 -0800 | [diff] [blame] | 600 | case AUDIO_SOURCE_REMOTE_SUBMIX: |
| 601 | case AUDIO_SOURCE_FM_TUNER: |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 602 | return true; |
| 603 | default: |
| 604 | break; |
| 605 | } |
| 606 | return false; |
| 607 | } |
| 608 | |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 609 | void AudioPolicyService::setAppState_l(uid_t uid, app_state_t state) |
| 610 | { |
| 611 | AutoCallerClear acc; |
| 612 | |
| 613 | if (mAudioPolicyManager) { |
| 614 | mAudioPolicyManager->setAppState(uid, state); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 615 | } |
| 616 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 617 | if (af) { |
Eric Laurent | f32108e | 2018-10-04 17:22:04 -0700 | [diff] [blame] | 618 | bool silenced = state == APP_STATE_IDLE; |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 619 | af->setRecordSilenced(uid, silenced); |
| 620 | } |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 621 | } |
| 622 | |
Glenn Kasten | 0f11b51 | 2014-01-31 16:18:54 -0800 | [diff] [blame] | 623 | status_t AudioPolicyService::dump(int fd, const Vector<String16>& args __unused) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 624 | { |
Glenn Kasten | 44deb05 | 2012-02-05 18:09:08 -0800 | [diff] [blame] | 625 | if (!dumpAllowed()) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 626 | dumpPermissionDenial(fd); |
| 627 | } else { |
Mikhail Naganov | 959e2d0 | 2019-03-28 11:08:19 -0700 | [diff] [blame] | 628 | bool locked = dumpTryLock(mLock); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 629 | if (!locked) { |
| 630 | String8 result(kDeadlockedString); |
| 631 | write(fd, result.string(), result.size()); |
| 632 | } |
| 633 | |
| 634 | dumpInternals(fd); |
Glenn Kasten | 9d1f02d | 2012-02-08 17:47:58 -0800 | [diff] [blame] | 635 | if (mAudioCommandThread != 0) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 636 | mAudioCommandThread->dump(fd); |
| 637 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 638 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 639 | if (mAudioPolicyManager) { |
| 640 | mAudioPolicyManager->dump(fd); |
| 641 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 642 | |
Kevin Rocard | 8be9497 | 2019-02-22 13:26:25 -0800 | [diff] [blame] | 643 | mPackageManager.dump(fd); |
| 644 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 645 | if (locked) mLock.unlock(); |
| 646 | } |
| 647 | return NO_ERROR; |
| 648 | } |
| 649 | |
| 650 | status_t AudioPolicyService::dumpPermissionDenial(int fd) |
| 651 | { |
| 652 | const size_t SIZE = 256; |
| 653 | char buffer[SIZE]; |
| 654 | String8 result; |
| 655 | snprintf(buffer, SIZE, "Permission Denial: " |
| 656 | "can't dump AudioPolicyService from pid=%d, uid=%d\n", |
| 657 | IPCThreadState::self()->getCallingPid(), |
| 658 | IPCThreadState::self()->getCallingUid()); |
| 659 | result.append(buffer); |
| 660 | write(fd, result.string(), result.size()); |
| 661 | return NO_ERROR; |
| 662 | } |
| 663 | |
| 664 | status_t AudioPolicyService::onTransact( |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 665 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { |
| 666 | switch (code) { |
| 667 | case SHELL_COMMAND_TRANSACTION: { |
| 668 | int in = data.readFileDescriptor(); |
| 669 | int out = data.readFileDescriptor(); |
| 670 | int err = data.readFileDescriptor(); |
| 671 | int argc = data.readInt32(); |
| 672 | Vector<String16> args; |
| 673 | for (int i = 0; i < argc && data.dataAvail() > 0; i++) { |
| 674 | args.add(data.readString16()); |
| 675 | } |
| 676 | sp<IBinder> unusedCallback; |
| 677 | sp<IResultReceiver> resultReceiver; |
| 678 | status_t status; |
| 679 | if ((status = data.readNullableStrongBinder(&unusedCallback)) != NO_ERROR) { |
| 680 | return status; |
| 681 | } |
| 682 | if ((status = data.readNullableStrongBinder(&resultReceiver)) != NO_ERROR) { |
| 683 | return status; |
| 684 | } |
| 685 | status = shellCommand(in, out, err, args); |
| 686 | if (resultReceiver != nullptr) { |
| 687 | resultReceiver->send(status); |
| 688 | } |
| 689 | return NO_ERROR; |
| 690 | } |
| 691 | } |
| 692 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 693 | return BnAudioPolicyService::onTransact(code, data, reply, flags); |
| 694 | } |
| 695 | |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 696 | // ------------------- Shell command implementation ------------------- |
| 697 | |
| 698 | // NOTE: This is a remote API - make sure all args are validated |
| 699 | status_t AudioPolicyService::shellCommand(int in, int out, int err, Vector<String16>& args) { |
| 700 | if (!checkCallingPermission(sManageAudioPolicyPermission, nullptr, nullptr)) { |
| 701 | return PERMISSION_DENIED; |
| 702 | } |
| 703 | if (in == BAD_TYPE || out == BAD_TYPE || err == BAD_TYPE) { |
| 704 | return BAD_VALUE; |
| 705 | } |
| 706 | if (args.size() == 3 && args[0] == String16("set-uid-state")) { |
| 707 | return handleSetUidState(args, err); |
| 708 | } else if (args.size() == 2 && args[0] == String16("reset-uid-state")) { |
| 709 | return handleResetUidState(args, err); |
| 710 | } else if (args.size() == 2 && args[0] == String16("get-uid-state")) { |
| 711 | return handleGetUidState(args, out, err); |
| 712 | } else if (args.size() == 1 && args[0] == String16("help")) { |
| 713 | printHelp(out); |
| 714 | return NO_ERROR; |
| 715 | } |
| 716 | printHelp(err); |
| 717 | return BAD_VALUE; |
| 718 | } |
| 719 | |
| 720 | status_t AudioPolicyService::handleSetUidState(Vector<String16>& args, int err) { |
| 721 | PermissionController pc; |
| 722 | int uid = pc.getPackageUid(args[1], 0); |
| 723 | if (uid <= 0) { |
| 724 | ALOGE("Unknown package: '%s'", String8(args[1]).string()); |
| 725 | dprintf(err, "Unknown package: '%s'\n", String8(args[1]).string()); |
| 726 | return BAD_VALUE; |
| 727 | } |
| 728 | bool active = false; |
| 729 | if (args[2] == String16("active")) { |
| 730 | active = true; |
| 731 | } else if ((args[2] != String16("idle"))) { |
| 732 | ALOGE("Expected active or idle but got: '%s'", String8(args[2]).string()); |
| 733 | return BAD_VALUE; |
| 734 | } |
| 735 | mUidPolicy->addOverrideUid(uid, active); |
| 736 | return NO_ERROR; |
| 737 | } |
| 738 | |
| 739 | status_t AudioPolicyService::handleResetUidState(Vector<String16>& args, int err) { |
| 740 | PermissionController pc; |
| 741 | int uid = pc.getPackageUid(args[1], 0); |
| 742 | if (uid < 0) { |
| 743 | ALOGE("Unknown package: '%s'", String8(args[1]).string()); |
| 744 | dprintf(err, "Unknown package: '%s'\n", String8(args[1]).string()); |
| 745 | return BAD_VALUE; |
| 746 | } |
| 747 | mUidPolicy->removeOverrideUid(uid); |
| 748 | return NO_ERROR; |
| 749 | } |
| 750 | |
| 751 | status_t AudioPolicyService::handleGetUidState(Vector<String16>& args, int out, int err) { |
| 752 | PermissionController pc; |
| 753 | int uid = pc.getPackageUid(args[1], 0); |
| 754 | if (uid < 0) { |
| 755 | ALOGE("Unknown package: '%s'", String8(args[1]).string()); |
| 756 | dprintf(err, "Unknown package: '%s'\n", String8(args[1]).string()); |
| 757 | return BAD_VALUE; |
| 758 | } |
| 759 | if (mUidPolicy->isUidActive(uid)) { |
| 760 | return dprintf(out, "active\n"); |
| 761 | } else { |
| 762 | return dprintf(out, "idle\n"); |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | status_t AudioPolicyService::printHelp(int out) { |
| 767 | return dprintf(out, "Audio policy service commands:\n" |
| 768 | " get-uid-state <PACKAGE> gets the uid state\n" |
| 769 | " set-uid-state <PACKAGE> <active|idle> overrides the uid state\n" |
| 770 | " reset-uid-state <PACKAGE> clears the uid state override\n" |
| 771 | " help print this message\n"); |
| 772 | } |
| 773 | |
| 774 | // ----------- AudioPolicyService::UidPolicy implementation ---------- |
| 775 | |
| 776 | void AudioPolicyService::UidPolicy::registerSelf() { |
| 777 | ActivityManager am; |
| 778 | am.registerUidObserver(this, ActivityManager::UID_OBSERVER_GONE |
| 779 | | ActivityManager::UID_OBSERVER_IDLE |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 780 | | ActivityManager::UID_OBSERVER_ACTIVE |
| 781 | | ActivityManager::UID_OBSERVER_PROCSTATE, |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 782 | ActivityManager::PROCESS_STATE_UNKNOWN, |
| 783 | String16("audioserver")); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 784 | status_t res = am.linkToDeath(this); |
| 785 | if (!res) { |
| 786 | Mutex::Autolock _l(mLock); |
| 787 | mObserverRegistered = true; |
| 788 | } else { |
| 789 | ALOGE("UidPolicy::registerSelf linkToDeath failed: %d", res); |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 790 | |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 791 | am.unregisterUidObserver(this); |
| 792 | } |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | void AudioPolicyService::UidPolicy::unregisterSelf() { |
| 796 | ActivityManager am; |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 797 | am.unlinkToDeath(this); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 798 | am.unregisterUidObserver(this); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 799 | Mutex::Autolock _l(mLock); |
| 800 | mObserverRegistered = false; |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 801 | } |
| 802 | |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 803 | void AudioPolicyService::UidPolicy::binderDied(__unused const wp<IBinder> &who) { |
| 804 | Mutex::Autolock _l(mLock); |
| 805 | mCachedUids.clear(); |
| 806 | mObserverRegistered = false; |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 807 | } |
| 808 | |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 809 | void AudioPolicyService::UidPolicy::checkRegistered() { |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 810 | bool needToReregister = false; |
| 811 | { |
| 812 | Mutex::Autolock _l(mLock); |
| 813 | needToReregister = !mObserverRegistered; |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 814 | } |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 815 | if (needToReregister) { |
| 816 | // Looks like ActivityManager has died previously, attempt to re-register. |
| 817 | registerSelf(); |
| 818 | } |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | bool AudioPolicyService::UidPolicy::isUidActive(uid_t uid) { |
| 822 | if (isServiceUid(uid)) return true; |
| 823 | checkRegistered(); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 824 | { |
| 825 | Mutex::Autolock _l(mLock); |
| 826 | auto overrideIter = mOverrideUids.find(uid); |
| 827 | if (overrideIter != mOverrideUids.end()) { |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 828 | return overrideIter->second.first; |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 829 | } |
| 830 | // In an absense of the ActivityManager, assume everything to be active. |
| 831 | if (!mObserverRegistered) return true; |
| 832 | auto cacheIter = mCachedUids.find(uid); |
Mikhail Naganov | eba668a | 2018-04-05 08:13:15 -0700 | [diff] [blame] | 833 | if (cacheIter != mCachedUids.end()) { |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 834 | return cacheIter->second.first; |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 835 | } |
| 836 | } |
| 837 | ActivityManager am; |
| 838 | bool active = am.isUidActive(uid, String16("audioserver")); |
| 839 | { |
| 840 | Mutex::Autolock _l(mLock); |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 841 | mCachedUids.insert(std::pair<uid_t, |
| 842 | std::pair<bool, int>>(uid, std::pair<bool, int>(active, |
| 843 | ActivityManager::PROCESS_STATE_UNKNOWN))); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 844 | } |
| 845 | return active; |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 846 | } |
| 847 | |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 848 | int AudioPolicyService::UidPolicy::getUidState(uid_t uid) { |
| 849 | if (isServiceUid(uid)) { |
| 850 | return ActivityManager::PROCESS_STATE_TOP; |
| 851 | } |
| 852 | checkRegistered(); |
| 853 | { |
| 854 | Mutex::Autolock _l(mLock); |
| 855 | auto overrideIter = mOverrideUids.find(uid); |
| 856 | if (overrideIter != mOverrideUids.end()) { |
| 857 | if (overrideIter->second.first) { |
| 858 | if (overrideIter->second.second != ActivityManager::PROCESS_STATE_UNKNOWN) { |
| 859 | return overrideIter->second.second; |
| 860 | } else { |
| 861 | auto cacheIter = mCachedUids.find(uid); |
| 862 | if (cacheIter != mCachedUids.end()) { |
| 863 | return cacheIter->second.second; |
| 864 | } |
| 865 | } |
| 866 | } |
| 867 | return ActivityManager::PROCESS_STATE_UNKNOWN; |
| 868 | } |
| 869 | // In an absense of the ActivityManager, assume everything to be active. |
| 870 | if (!mObserverRegistered) { |
| 871 | return ActivityManager::PROCESS_STATE_TOP; |
| 872 | } |
| 873 | auto cacheIter = mCachedUids.find(uid); |
| 874 | if (cacheIter != mCachedUids.end()) { |
| 875 | if (cacheIter->second.first) { |
| 876 | return cacheIter->second.second; |
| 877 | } else { |
| 878 | return ActivityManager::PROCESS_STATE_UNKNOWN; |
| 879 | } |
| 880 | } |
| 881 | } |
| 882 | ActivityManager am; |
| 883 | bool active = am.isUidActive(uid, String16("audioserver")); |
| 884 | int state = ActivityManager::PROCESS_STATE_UNKNOWN; |
| 885 | if (active) { |
| 886 | state = am.getUidProcessState(uid, String16("audioserver")); |
| 887 | } |
| 888 | { |
| 889 | Mutex::Autolock _l(mLock); |
| 890 | mCachedUids.insert(std::pair<uid_t, |
| 891 | std::pair<bool, int>>(uid, std::pair<bool, int>(active, state))); |
| 892 | } |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 893 | |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 894 | return state; |
| 895 | } |
| 896 | |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 897 | void AudioPolicyService::UidPolicy::onUidActive(uid_t uid) { |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 898 | updateUid(&mCachedUids, uid, true, ActivityManager::PROCESS_STATE_UNKNOWN, true); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | void AudioPolicyService::UidPolicy::onUidGone(uid_t uid, __unused bool disabled) { |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 902 | updateUid(&mCachedUids, uid, false, ActivityManager::PROCESS_STATE_UNKNOWN, false); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | void AudioPolicyService::UidPolicy::onUidIdle(uid_t uid, __unused bool disabled) { |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 906 | updateUid(&mCachedUids, uid, false, ActivityManager::PROCESS_STATE_UNKNOWN, true); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 907 | } |
| 908 | |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 909 | void AudioPolicyService::UidPolicy::onUidStateChanged(uid_t uid, |
| 910 | int32_t procState, |
| 911 | int64_t procStateSeq __unused) { |
| 912 | if (procState != ActivityManager::PROCESS_STATE_UNKNOWN) { |
| 913 | updateUid(&mCachedUids, uid, true, procState, true); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 914 | } |
| 915 | } |
| 916 | |
| 917 | void AudioPolicyService::UidPolicy::updateOverrideUid(uid_t uid, bool active, bool insert) { |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 918 | updateUid(&mOverrideUids, uid, active, ActivityManager::PROCESS_STATE_UNKNOWN, insert); |
| 919 | } |
| 920 | |
| 921 | void AudioPolicyService::UidPolicy::notifyService() { |
| 922 | sp<AudioPolicyService> service = mService.promote(); |
| 923 | if (service != nullptr) { |
| 924 | service->updateUidStates(); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 925 | } |
| 926 | } |
| 927 | |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 928 | void AudioPolicyService::UidPolicy::updateUid(std::unordered_map<uid_t, |
| 929 | std::pair<bool, int>> *uids, |
| 930 | uid_t uid, |
| 931 | bool active, |
| 932 | int state, |
| 933 | bool insert) { |
| 934 | if (isServiceUid(uid)) { |
| 935 | return; |
| 936 | } |
| 937 | bool wasActive = isUidActive(uid); |
| 938 | int previousState = getUidState(uid); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 939 | { |
| 940 | Mutex::Autolock _l(mLock); |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 941 | updateUidLocked(uids, uid, active, state, insert); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 942 | } |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 943 | if (wasActive != isUidActive(uid) || state != previousState) { |
| 944 | notifyService(); |
| 945 | } |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 946 | } |
| 947 | |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 948 | void AudioPolicyService::UidPolicy::updateUidLocked(std::unordered_map<uid_t, |
| 949 | std::pair<bool, int>> *uids, |
| 950 | uid_t uid, |
| 951 | bool active, |
| 952 | int state, |
| 953 | bool insert) { |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 954 | auto it = uids->find(uid); |
| 955 | if (it != uids->end()) { |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 956 | if (insert) { |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 957 | if (state == ActivityManager::PROCESS_STATE_UNKNOWN) { |
| 958 | it->second.first = active; |
| 959 | } |
| 960 | if (it->second.first) { |
| 961 | it->second.second = state; |
| 962 | } else { |
| 963 | it->second.second = ActivityManager::PROCESS_STATE_UNKNOWN; |
| 964 | } |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 965 | } else { |
| 966 | uids->erase(it); |
| 967 | } |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 968 | } else if (insert && (state == ActivityManager::PROCESS_STATE_UNKNOWN)) { |
| 969 | uids->insert(std::pair<uid_t, std::pair<bool, int>>(uid, |
| 970 | std::pair<bool, int>(active, state))); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 971 | } |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 972 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 973 | |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 974 | bool AudioPolicyService::UidPolicy::isA11yOnTop() { |
| 975 | for (const auto &uid : mCachedUids) { |
| 976 | std::vector<uid_t>::iterator it = find(mA11yUids.begin(), mA11yUids.end(), uid.first); |
| 977 | if (it == mA11yUids.end()) { |
| 978 | continue; |
| 979 | } |
Amith Yamasani | bcbb300 | 2019-01-23 13:53:33 -0800 | [diff] [blame] | 980 | if (uid.second.second >= ActivityManager::PROCESS_STATE_TOP |
| 981 | && uid.second.second <= ActivityManager::PROCESS_STATE_BOUND_FOREGROUND_SERVICE) { |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 982 | return true; |
| 983 | } |
| 984 | } |
| 985 | return false; |
| 986 | } |
| 987 | |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 988 | bool AudioPolicyService::UidPolicy::isA11yUid(uid_t uid) |
| 989 | { |
| 990 | std::vector<uid_t>::iterator it = find(mA11yUids.begin(), mA11yUids.end(), uid); |
| 991 | return it != mA11yUids.end(); |
| 992 | } |
| 993 | |
Michael Groover | cfd2830 | 2018-12-11 19:16:46 -0800 | [diff] [blame] | 994 | // ----------- AudioPolicyService::SensorPrivacyService implementation ---------- |
| 995 | void AudioPolicyService::SensorPrivacyPolicy::registerSelf() { |
| 996 | SensorPrivacyManager spm; |
| 997 | mSensorPrivacyEnabled = spm.isSensorPrivacyEnabled(); |
| 998 | spm.addSensorPrivacyListener(this); |
| 999 | } |
| 1000 | |
| 1001 | void AudioPolicyService::SensorPrivacyPolicy::unregisterSelf() { |
| 1002 | SensorPrivacyManager spm; |
| 1003 | spm.removeSensorPrivacyListener(this); |
| 1004 | } |
| 1005 | |
| 1006 | bool AudioPolicyService::SensorPrivacyPolicy::isSensorPrivacyEnabled() { |
| 1007 | return mSensorPrivacyEnabled; |
| 1008 | } |
| 1009 | |
| 1010 | binder::Status AudioPolicyService::SensorPrivacyPolicy::onSensorPrivacyChanged(bool enabled) { |
| 1011 | mSensorPrivacyEnabled = enabled; |
| 1012 | sp<AudioPolicyService> service = mService.promote(); |
| 1013 | if (service != nullptr) { |
| 1014 | service->updateUidStates(); |
| 1015 | } |
| 1016 | return binder::Status::ok(); |
| 1017 | } |
| 1018 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1019 | // ----------- AudioPolicyService::AudioCommandThread implementation ---------- |
| 1020 | |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1021 | AudioPolicyService::AudioCommandThread::AudioCommandThread(String8 name, |
| 1022 | const wp<AudioPolicyService>& service) |
| 1023 | : Thread(false), mName(name), mService(service) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1024 | { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | |
| 1028 | AudioPolicyService::AudioCommandThread::~AudioCommandThread() |
| 1029 | { |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1030 | if (!mAudioCommands.isEmpty()) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1031 | release_wake_lock(mName.string()); |
| 1032 | } |
| 1033 | mAudioCommands.clear(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | void AudioPolicyService::AudioCommandThread::onFirstRef() |
| 1037 | { |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1038 | run(mName.string(), ANDROID_PRIORITY_AUDIO); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | bool AudioPolicyService::AudioCommandThread::threadLoop() |
| 1042 | { |
Eric Laurent | d7eda8d | 2016-02-02 17:18:39 -0800 | [diff] [blame] | 1043 | nsecs_t waitTime = -1; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1044 | |
| 1045 | mLock.lock(); |
| 1046 | while (!exitPending()) |
| 1047 | { |
Eric Laurent | 59a8923 | 2014-06-08 14:14:17 -0700 | [diff] [blame] | 1048 | sp<AudioPolicyService> svc; |
| 1049 | while (!mAudioCommands.isEmpty() && !exitPending()) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1050 | nsecs_t curTime = systemTime(); |
| 1051 | // commands are sorted by increasing time stamp: execute them from index 0 and up |
| 1052 | if (mAudioCommands[0]->mTime <= curTime) { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1053 | sp<AudioCommand> command = mAudioCommands[0]; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1054 | mAudioCommands.removeAt(0); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1055 | mLastCommand = command; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1056 | |
| 1057 | switch (command->mCommand) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1058 | case SET_VOLUME: { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1059 | VolumeData *data = (VolumeData *)command->mParam.get(); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1060 | ALOGV("AudioCommandThread() processing set volume stream %d, \ |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1061 | volume %f, output %d", data->mStream, data->mVolume, data->mIO); |
Andy Hung | fe726a6 | 2018-09-27 15:17:25 -0700 | [diff] [blame] | 1062 | mLock.unlock(); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1063 | command->mStatus = AudioSystem::setStreamVolume(data->mStream, |
| 1064 | data->mVolume, |
| 1065 | data->mIO); |
Andy Hung | fe726a6 | 2018-09-27 15:17:25 -0700 | [diff] [blame] | 1066 | mLock.lock(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1067 | }break; |
| 1068 | case SET_PARAMETERS: { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1069 | ParametersData *data = (ParametersData *)command->mParam.get(); |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 1070 | ALOGV("AudioCommandThread() processing set parameters string %s, io %d", |
| 1071 | data->mKeyValuePairs.string(), data->mIO); |
Andy Hung | fe726a6 | 2018-09-27 15:17:25 -0700 | [diff] [blame] | 1072 | mLock.unlock(); |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 1073 | command->mStatus = AudioSystem::setParameters(data->mIO, data->mKeyValuePairs); |
Andy Hung | fe726a6 | 2018-09-27 15:17:25 -0700 | [diff] [blame] | 1074 | mLock.lock(); |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 1075 | }break; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1076 | case SET_VOICE_VOLUME: { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1077 | VoiceVolumeData *data = (VoiceVolumeData *)command->mParam.get(); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1078 | ALOGV("AudioCommandThread() processing set voice volume volume %f", |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1079 | data->mVolume); |
Andy Hung | fe726a6 | 2018-09-27 15:17:25 -0700 | [diff] [blame] | 1080 | mLock.unlock(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1081 | command->mStatus = AudioSystem::setVoiceVolume(data->mVolume); |
Andy Hung | fe726a6 | 2018-09-27 15:17:25 -0700 | [diff] [blame] | 1082 | mLock.lock(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1083 | }break; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1084 | case STOP_OUTPUT: { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1085 | StopOutputData *data = (StopOutputData *)command->mParam.get(); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1086 | ALOGV("AudioCommandThread() processing stop output portId %d", |
| 1087 | data->mPortId); |
Eric Laurent | 59a8923 | 2014-06-08 14:14:17 -0700 | [diff] [blame] | 1088 | svc = mService.promote(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1089 | if (svc == 0) { |
| 1090 | break; |
| 1091 | } |
| 1092 | mLock.unlock(); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1093 | svc->doStopOutput(data->mPortId); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1094 | mLock.lock(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1095 | }break; |
| 1096 | case RELEASE_OUTPUT: { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1097 | ReleaseOutputData *data = (ReleaseOutputData *)command->mParam.get(); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1098 | ALOGV("AudioCommandThread() processing release output portId %d", |
| 1099 | data->mPortId); |
Eric Laurent | 59a8923 | 2014-06-08 14:14:17 -0700 | [diff] [blame] | 1100 | svc = mService.promote(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1101 | if (svc == 0) { |
| 1102 | break; |
| 1103 | } |
| 1104 | mLock.unlock(); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1105 | svc->doReleaseOutput(data->mPortId); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1106 | mLock.lock(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1107 | }break; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 1108 | case CREATE_AUDIO_PATCH: { |
| 1109 | CreateAudioPatchData *data = (CreateAudioPatchData *)command->mParam.get(); |
| 1110 | ALOGV("AudioCommandThread() processing create audio patch"); |
| 1111 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 1112 | if (af == 0) { |
| 1113 | command->mStatus = PERMISSION_DENIED; |
| 1114 | } else { |
Andy Hung | fe726a6 | 2018-09-27 15:17:25 -0700 | [diff] [blame] | 1115 | mLock.unlock(); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 1116 | command->mStatus = af->createAudioPatch(&data->mPatch, &data->mHandle); |
Andy Hung | fe726a6 | 2018-09-27 15:17:25 -0700 | [diff] [blame] | 1117 | mLock.lock(); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 1118 | } |
| 1119 | } break; |
| 1120 | case RELEASE_AUDIO_PATCH: { |
| 1121 | ReleaseAudioPatchData *data = (ReleaseAudioPatchData *)command->mParam.get(); |
| 1122 | ALOGV("AudioCommandThread() processing release audio patch"); |
| 1123 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 1124 | if (af == 0) { |
| 1125 | command->mStatus = PERMISSION_DENIED; |
| 1126 | } else { |
Andy Hung | fe726a6 | 2018-09-27 15:17:25 -0700 | [diff] [blame] | 1127 | mLock.unlock(); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 1128 | command->mStatus = af->releaseAudioPatch(data->mHandle); |
Andy Hung | fe726a6 | 2018-09-27 15:17:25 -0700 | [diff] [blame] | 1129 | mLock.lock(); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 1130 | } |
| 1131 | } break; |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 1132 | case UPDATE_AUDIOPORT_LIST: { |
| 1133 | ALOGV("AudioCommandThread() processing update audio port list"); |
Eric Laurent | 59a8923 | 2014-06-08 14:14:17 -0700 | [diff] [blame] | 1134 | svc = mService.promote(); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 1135 | if (svc == 0) { |
| 1136 | break; |
| 1137 | } |
| 1138 | mLock.unlock(); |
| 1139 | svc->doOnAudioPortListUpdate(); |
| 1140 | mLock.lock(); |
| 1141 | }break; |
| 1142 | case UPDATE_AUDIOPATCH_LIST: { |
| 1143 | ALOGV("AudioCommandThread() processing update audio patch list"); |
Eric Laurent | 59a8923 | 2014-06-08 14:14:17 -0700 | [diff] [blame] | 1144 | svc = mService.promote(); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 1145 | if (svc == 0) { |
| 1146 | break; |
| 1147 | } |
| 1148 | mLock.unlock(); |
| 1149 | svc->doOnAudioPatchListUpdate(); |
| 1150 | mLock.lock(); |
| 1151 | }break; |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1152 | case CHANGED_AUDIOVOLUMEGROUP: { |
| 1153 | AudioVolumeGroupData *data = |
| 1154 | static_cast<AudioVolumeGroupData *>(command->mParam.get()); |
| 1155 | ALOGV("AudioCommandThread() processing update audio volume group"); |
| 1156 | svc = mService.promote(); |
| 1157 | if (svc == 0) { |
| 1158 | break; |
| 1159 | } |
| 1160 | mLock.unlock(); |
| 1161 | svc->doOnAudioVolumeGroupChanged(data->mGroup, data->mFlags); |
| 1162 | mLock.lock(); |
| 1163 | }break; |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 1164 | case SET_AUDIOPORT_CONFIG: { |
| 1165 | SetAudioPortConfigData *data = (SetAudioPortConfigData *)command->mParam.get(); |
| 1166 | ALOGV("AudioCommandThread() processing set port config"); |
| 1167 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 1168 | if (af == 0) { |
| 1169 | command->mStatus = PERMISSION_DENIED; |
| 1170 | } else { |
Andy Hung | fe726a6 | 2018-09-27 15:17:25 -0700 | [diff] [blame] | 1171 | mLock.unlock(); |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 1172 | command->mStatus = af->setAudioPortConfig(&data->mConfig); |
Andy Hung | fe726a6 | 2018-09-27 15:17:25 -0700 | [diff] [blame] | 1173 | mLock.lock(); |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 1174 | } |
| 1175 | } break; |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 1176 | case DYN_POLICY_MIX_STATE_UPDATE: { |
| 1177 | DynPolicyMixStateUpdateData *data = |
| 1178 | (DynPolicyMixStateUpdateData *)command->mParam.get(); |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 1179 | ALOGV("AudioCommandThread() processing dyn policy mix state update %s %d", |
| 1180 | data->mRegId.string(), data->mState); |
| 1181 | svc = mService.promote(); |
| 1182 | if (svc == 0) { |
| 1183 | break; |
| 1184 | } |
| 1185 | mLock.unlock(); |
| 1186 | svc->doOnDynamicPolicyMixStateUpdate(data->mRegId, data->mState); |
| 1187 | mLock.lock(); |
| 1188 | } break; |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 1189 | case RECORDING_CONFIGURATION_UPDATE: { |
| 1190 | RecordingConfigurationUpdateData *data = |
| 1191 | (RecordingConfigurationUpdateData *)command->mParam.get(); |
| 1192 | ALOGV("AudioCommandThread() processing recording configuration update"); |
| 1193 | svc = mService.promote(); |
| 1194 | if (svc == 0) { |
| 1195 | break; |
| 1196 | } |
| 1197 | mLock.unlock(); |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 1198 | svc->doOnRecordingConfigurationUpdate(data->mEvent, &data->mClientInfo, |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 1199 | &data->mClientConfig, data->mClientEffects, |
| 1200 | &data->mDeviceConfig, data->mEffects, |
| 1201 | data->mPatchHandle, data->mSource); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 1202 | mLock.lock(); |
| 1203 | } break; |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 1204 | case SET_EFFECT_SUSPENDED: { |
| 1205 | SetEffectSuspendedData *data = (SetEffectSuspendedData *)command->mParam.get(); |
| 1206 | ALOGV("AudioCommandThread() processing set effect suspended"); |
| 1207 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 1208 | if (af != 0) { |
| 1209 | mLock.unlock(); |
| 1210 | af->setEffectSuspended(data->mEffectId, data->mSessionId, data->mSuspended); |
| 1211 | mLock.lock(); |
| 1212 | } |
| 1213 | } break; |
| 1214 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1215 | default: |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 1216 | ALOGW("AudioCommandThread() unknown command %d", command->mCommand); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1217 | } |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1218 | { |
| 1219 | Mutex::Autolock _l(command->mLock); |
| 1220 | if (command->mWaitStatus) { |
| 1221 | command->mWaitStatus = false; |
| 1222 | command->mCond.signal(); |
| 1223 | } |
| 1224 | } |
Eric Laurent | d7eda8d | 2016-02-02 17:18:39 -0800 | [diff] [blame] | 1225 | waitTime = -1; |
Zach Jang | a754b4f | 2015-10-27 01:29:34 +0000 | [diff] [blame] | 1226 | // release mLock before releasing strong reference on the service as |
| 1227 | // AudioPolicyService destructor calls AudioCommandThread::exit() which |
| 1228 | // acquires mLock. |
| 1229 | mLock.unlock(); |
| 1230 | svc.clear(); |
| 1231 | mLock.lock(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1232 | } else { |
| 1233 | waitTime = mAudioCommands[0]->mTime - curTime; |
| 1234 | break; |
| 1235 | } |
| 1236 | } |
Zach Jang | a754b4f | 2015-10-27 01:29:34 +0000 | [diff] [blame] | 1237 | |
| 1238 | // release delayed commands wake lock if the queue is empty |
| 1239 | if (mAudioCommands.isEmpty()) { |
Ricardo Garcia | 05f2fdc | 2014-07-24 15:48:24 -0700 | [diff] [blame] | 1240 | release_wake_lock(mName.string()); |
Zach Jang | a754b4f | 2015-10-27 01:29:34 +0000 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | // At this stage we have either an empty command queue or the first command in the queue |
| 1244 | // has a finite delay. So unless we are exiting it is safe to wait. |
| 1245 | if (!exitPending()) { |
Eric Laurent | 59a8923 | 2014-06-08 14:14:17 -0700 | [diff] [blame] | 1246 | ALOGV("AudioCommandThread() going to sleep"); |
Eric Laurent | d7eda8d | 2016-02-02 17:18:39 -0800 | [diff] [blame] | 1247 | if (waitTime == -1) { |
| 1248 | mWaitWorkCV.wait(mLock); |
| 1249 | } else { |
| 1250 | mWaitWorkCV.waitRelative(mLock, waitTime); |
| 1251 | } |
Eric Laurent | 59a8923 | 2014-06-08 14:14:17 -0700 | [diff] [blame] | 1252 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1253 | } |
Ricardo Garcia | 05f2fdc | 2014-07-24 15:48:24 -0700 | [diff] [blame] | 1254 | // release delayed commands wake lock before quitting |
| 1255 | if (!mAudioCommands.isEmpty()) { |
| 1256 | release_wake_lock(mName.string()); |
| 1257 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1258 | mLock.unlock(); |
| 1259 | return false; |
| 1260 | } |
| 1261 | |
| 1262 | status_t AudioPolicyService::AudioCommandThread::dump(int fd) |
| 1263 | { |
| 1264 | const size_t SIZE = 256; |
| 1265 | char buffer[SIZE]; |
| 1266 | String8 result; |
| 1267 | |
| 1268 | snprintf(buffer, SIZE, "AudioCommandThread %p Dump\n", this); |
| 1269 | result.append(buffer); |
| 1270 | write(fd, result.string(), result.size()); |
| 1271 | |
Mikhail Naganov | 959e2d0 | 2019-03-28 11:08:19 -0700 | [diff] [blame] | 1272 | bool locked = dumpTryLock(mLock); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1273 | if (!locked) { |
| 1274 | String8 result2(kCmdDeadlockedString); |
| 1275 | write(fd, result2.string(), result2.size()); |
| 1276 | } |
| 1277 | |
| 1278 | snprintf(buffer, SIZE, "- Commands:\n"); |
| 1279 | result = String8(buffer); |
| 1280 | result.append(" Command Time Wait pParam\n"); |
Glenn Kasten | 8d6a244 | 2012-02-08 14:04:28 -0800 | [diff] [blame] | 1281 | for (size_t i = 0; i < mAudioCommands.size(); i++) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1282 | mAudioCommands[i]->dump(buffer, SIZE); |
| 1283 | result.append(buffer); |
| 1284 | } |
| 1285 | result.append(" Last Command\n"); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1286 | if (mLastCommand != 0) { |
| 1287 | mLastCommand->dump(buffer, SIZE); |
| 1288 | result.append(buffer); |
| 1289 | } else { |
| 1290 | result.append(" none\n"); |
| 1291 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1292 | |
| 1293 | write(fd, result.string(), result.size()); |
| 1294 | |
| 1295 | if (locked) mLock.unlock(); |
| 1296 | |
| 1297 | return NO_ERROR; |
| 1298 | } |
| 1299 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 1300 | status_t AudioPolicyService::AudioCommandThread::volumeCommand(audio_stream_type_t stream, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1301 | float volume, |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1302 | audio_io_handle_t output, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1303 | int delayMs) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1304 | { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1305 | sp<AudioCommand> command = new AudioCommand(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1306 | command->mCommand = SET_VOLUME; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1307 | sp<VolumeData> data = new VolumeData(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1308 | data->mStream = stream; |
| 1309 | data->mVolume = volume; |
| 1310 | data->mIO = output; |
| 1311 | command->mParam = data; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1312 | command->mWaitStatus = true; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1313 | ALOGV("AudioCommandThread() adding set volume stream %d, volume %f, output %d", |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1314 | stream, volume, output); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1315 | return sendCommand(command, delayMs); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1318 | status_t AudioPolicyService::AudioCommandThread::parametersCommand(audio_io_handle_t ioHandle, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1319 | const char *keyValuePairs, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1320 | int delayMs) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1321 | { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1322 | sp<AudioCommand> command = new AudioCommand(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1323 | command->mCommand = SET_PARAMETERS; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1324 | sp<ParametersData> data = new ParametersData(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1325 | data->mIO = ioHandle; |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1326 | data->mKeyValuePairs = String8(keyValuePairs); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1327 | command->mParam = data; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1328 | command->mWaitStatus = true; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1329 | ALOGV("AudioCommandThread() adding set parameter string %s, io %d ,delay %d", |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1330 | keyValuePairs, ioHandle, delayMs); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1331 | return sendCommand(command, delayMs); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | status_t AudioPolicyService::AudioCommandThread::voiceVolumeCommand(float volume, int delayMs) |
| 1335 | { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1336 | sp<AudioCommand> command = new AudioCommand(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1337 | command->mCommand = SET_VOICE_VOLUME; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1338 | sp<VoiceVolumeData> data = new VoiceVolumeData(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1339 | data->mVolume = volume; |
| 1340 | command->mParam = data; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1341 | command->mWaitStatus = true; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1342 | ALOGV("AudioCommandThread() adding set voice volume volume %f", volume); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1343 | return sendCommand(command, delayMs); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1344 | } |
| 1345 | |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 1346 | void AudioPolicyService::AudioCommandThread::setEffectSuspendedCommand(int effectId, |
| 1347 | audio_session_t sessionId, |
| 1348 | bool suspended) |
| 1349 | { |
| 1350 | sp<AudioCommand> command = new AudioCommand(); |
| 1351 | command->mCommand = SET_EFFECT_SUSPENDED; |
| 1352 | sp<SetEffectSuspendedData> data = new SetEffectSuspendedData(); |
| 1353 | data->mEffectId = effectId; |
| 1354 | data->mSessionId = sessionId; |
| 1355 | data->mSuspended = suspended; |
| 1356 | command->mParam = data; |
| 1357 | ALOGV("AudioCommandThread() adding set suspended effectId %d sessionId %d suspended %d", |
| 1358 | effectId, sessionId, suspended); |
| 1359 | sendCommand(command); |
| 1360 | } |
| 1361 | |
| 1362 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1363 | void AudioPolicyService::AudioCommandThread::stopOutputCommand(audio_port_handle_t portId) |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1364 | { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1365 | sp<AudioCommand> command = new AudioCommand(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1366 | command->mCommand = STOP_OUTPUT; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1367 | sp<StopOutputData> data = new StopOutputData(); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1368 | data->mPortId = portId; |
Jesper Tragardh | 48412dc | 2014-03-24 14:12:43 +0100 | [diff] [blame] | 1369 | command->mParam = data; |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1370 | ALOGV("AudioCommandThread() adding stop output portId %d", portId); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1371 | sendCommand(command); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1372 | } |
| 1373 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1374 | void AudioPolicyService::AudioCommandThread::releaseOutputCommand(audio_port_handle_t portId) |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1375 | { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1376 | sp<AudioCommand> command = new AudioCommand(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1377 | command->mCommand = RELEASE_OUTPUT; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1378 | sp<ReleaseOutputData> data = new ReleaseOutputData(); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1379 | data->mPortId = portId; |
Jesper Tragardh | 48412dc | 2014-03-24 14:12:43 +0100 | [diff] [blame] | 1380 | command->mParam = data; |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1381 | ALOGV("AudioCommandThread() adding release output portId %d", portId); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1382 | sendCommand(command); |
| 1383 | } |
| 1384 | |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 1385 | status_t AudioPolicyService::AudioCommandThread::createAudioPatchCommand( |
| 1386 | const struct audio_patch *patch, |
| 1387 | audio_patch_handle_t *handle, |
| 1388 | int delayMs) |
| 1389 | { |
| 1390 | status_t status = NO_ERROR; |
| 1391 | |
| 1392 | sp<AudioCommand> command = new AudioCommand(); |
| 1393 | command->mCommand = CREATE_AUDIO_PATCH; |
| 1394 | CreateAudioPatchData *data = new CreateAudioPatchData(); |
| 1395 | data->mPatch = *patch; |
| 1396 | data->mHandle = *handle; |
| 1397 | command->mParam = data; |
| 1398 | command->mWaitStatus = true; |
| 1399 | ALOGV("AudioCommandThread() adding create patch delay %d", delayMs); |
| 1400 | status = sendCommand(command, delayMs); |
| 1401 | if (status == NO_ERROR) { |
| 1402 | *handle = data->mHandle; |
| 1403 | } |
| 1404 | return status; |
| 1405 | } |
| 1406 | |
| 1407 | status_t AudioPolicyService::AudioCommandThread::releaseAudioPatchCommand(audio_patch_handle_t handle, |
| 1408 | int delayMs) |
| 1409 | { |
| 1410 | sp<AudioCommand> command = new AudioCommand(); |
| 1411 | command->mCommand = RELEASE_AUDIO_PATCH; |
| 1412 | ReleaseAudioPatchData *data = new ReleaseAudioPatchData(); |
| 1413 | data->mHandle = handle; |
| 1414 | command->mParam = data; |
| 1415 | command->mWaitStatus = true; |
| 1416 | ALOGV("AudioCommandThread() adding release patch delay %d", delayMs); |
| 1417 | return sendCommand(command, delayMs); |
| 1418 | } |
| 1419 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 1420 | void AudioPolicyService::AudioCommandThread::updateAudioPortListCommand() |
| 1421 | { |
| 1422 | sp<AudioCommand> command = new AudioCommand(); |
| 1423 | command->mCommand = UPDATE_AUDIOPORT_LIST; |
| 1424 | ALOGV("AudioCommandThread() adding update audio port list"); |
| 1425 | sendCommand(command); |
| 1426 | } |
| 1427 | |
| 1428 | void AudioPolicyService::AudioCommandThread::updateAudioPatchListCommand() |
| 1429 | { |
| 1430 | sp<AudioCommand>command = new AudioCommand(); |
| 1431 | command->mCommand = UPDATE_AUDIOPATCH_LIST; |
| 1432 | ALOGV("AudioCommandThread() adding update audio patch list"); |
| 1433 | sendCommand(command); |
| 1434 | } |
| 1435 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1436 | void AudioPolicyService::AudioCommandThread::changeAudioVolumeGroupCommand(volume_group_t group, |
| 1437 | int flags) |
| 1438 | { |
| 1439 | sp<AudioCommand>command = new AudioCommand(); |
| 1440 | command->mCommand = CHANGED_AUDIOVOLUMEGROUP; |
| 1441 | AudioVolumeGroupData *data= new AudioVolumeGroupData(); |
| 1442 | data->mGroup = group; |
| 1443 | data->mFlags = flags; |
| 1444 | command->mParam = data; |
| 1445 | ALOGV("AudioCommandThread() adding audio volume group changed"); |
| 1446 | sendCommand(command); |
| 1447 | } |
| 1448 | |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 1449 | status_t AudioPolicyService::AudioCommandThread::setAudioPortConfigCommand( |
| 1450 | const struct audio_port_config *config, int delayMs) |
| 1451 | { |
| 1452 | sp<AudioCommand> command = new AudioCommand(); |
| 1453 | command->mCommand = SET_AUDIOPORT_CONFIG; |
| 1454 | SetAudioPortConfigData *data = new SetAudioPortConfigData(); |
| 1455 | data->mConfig = *config; |
| 1456 | command->mParam = data; |
| 1457 | command->mWaitStatus = true; |
| 1458 | ALOGV("AudioCommandThread() adding set port config delay %d", delayMs); |
| 1459 | return sendCommand(command, delayMs); |
| 1460 | } |
| 1461 | |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 1462 | void AudioPolicyService::AudioCommandThread::dynamicPolicyMixStateUpdateCommand( |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 1463 | const String8& regId, int32_t state) |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 1464 | { |
| 1465 | sp<AudioCommand> command = new AudioCommand(); |
| 1466 | command->mCommand = DYN_POLICY_MIX_STATE_UPDATE; |
| 1467 | DynPolicyMixStateUpdateData *data = new DynPolicyMixStateUpdateData(); |
| 1468 | data->mRegId = regId; |
| 1469 | data->mState = state; |
| 1470 | command->mParam = data; |
| 1471 | ALOGV("AudioCommandThread() sending dynamic policy mix (id=%s) state update to %d", |
| 1472 | regId.string(), state); |
| 1473 | sendCommand(command); |
| 1474 | } |
| 1475 | |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 1476 | void AudioPolicyService::AudioCommandThread::recordingConfigurationUpdateCommand( |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 1477 | int event, |
| 1478 | const record_client_info_t *clientInfo, |
| 1479 | const audio_config_base_t *clientConfig, |
| 1480 | std::vector<effect_descriptor_t> clientEffects, |
| 1481 | const audio_config_base_t *deviceConfig, |
| 1482 | std::vector<effect_descriptor_t> effects, |
| 1483 | audio_patch_handle_t patchHandle, |
| 1484 | audio_source_t source) |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 1485 | { |
| 1486 | sp<AudioCommand>command = new AudioCommand(); |
| 1487 | command->mCommand = RECORDING_CONFIGURATION_UPDATE; |
| 1488 | RecordingConfigurationUpdateData *data = new RecordingConfigurationUpdateData(); |
| 1489 | data->mEvent = event; |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 1490 | data->mClientInfo = *clientInfo; |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 1491 | data->mClientConfig = *clientConfig; |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 1492 | data->mClientEffects = clientEffects; |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 1493 | data->mDeviceConfig = *deviceConfig; |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 1494 | data->mEffects = effects; |
Jean-Michel Trivi | 8c7cf3b | 2016-02-25 17:08:24 -0800 | [diff] [blame] | 1495 | data->mPatchHandle = patchHandle; |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 1496 | data->mSource = source; |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 1497 | command->mParam = data; |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 1498 | ALOGV("AudioCommandThread() adding recording configuration update event %d, source %d uid %u", |
| 1499 | event, clientInfo->source, clientInfo->uid); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 1500 | sendCommand(command); |
| 1501 | } |
| 1502 | |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1503 | status_t AudioPolicyService::AudioCommandThread::sendCommand(sp<AudioCommand>& command, int delayMs) |
| 1504 | { |
| 1505 | { |
| 1506 | Mutex::Autolock _l(mLock); |
| 1507 | insertCommand_l(command, delayMs); |
| 1508 | mWaitWorkCV.signal(); |
| 1509 | } |
| 1510 | Mutex::Autolock _l(command->mLock); |
| 1511 | while (command->mWaitStatus) { |
| 1512 | nsecs_t timeOutNs = kAudioCommandTimeoutNs + milliseconds(delayMs); |
| 1513 | if (command->mCond.waitRelative(command->mLock, timeOutNs) != NO_ERROR) { |
| 1514 | command->mStatus = TIMED_OUT; |
| 1515 | command->mWaitStatus = false; |
| 1516 | } |
| 1517 | } |
| 1518 | return command->mStatus; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1519 | } |
| 1520 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1521 | // insertCommand_l() must be called with mLock held |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1522 | void AudioPolicyService::AudioCommandThread::insertCommand_l(sp<AudioCommand>& command, int delayMs) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1523 | { |
Glenn Kasten | 8d6a244 | 2012-02-08 14:04:28 -0800 | [diff] [blame] | 1524 | ssize_t i; // not size_t because i will count down to -1 |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1525 | Vector < sp<AudioCommand> > removedCommands; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1526 | command->mTime = systemTime() + milliseconds(delayMs); |
| 1527 | |
| 1528 | // acquire wake lock to make sure delayed commands are processed |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1529 | if (mAudioCommands.isEmpty()) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1530 | acquire_wake_lock(PARTIAL_WAKE_LOCK, mName.string()); |
| 1531 | } |
| 1532 | |
| 1533 | // check same pending commands with later time stamps and eliminate them |
Ivan Lozano | 5ff158f | 2017-10-30 09:06:24 -0700 | [diff] [blame] | 1534 | for (i = (ssize_t)mAudioCommands.size()-1; i >= 0; i--) { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1535 | sp<AudioCommand> command2 = mAudioCommands[i]; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1536 | // commands are sorted by increasing time stamp: no need to scan the rest of mAudioCommands |
| 1537 | if (command2->mTime <= command->mTime) break; |
Eric Laurent | e45b48a | 2014-09-04 16:40:57 -0700 | [diff] [blame] | 1538 | |
| 1539 | // create audio patch or release audio patch commands are equivalent |
| 1540 | // with regard to filtering |
| 1541 | if ((command->mCommand == CREATE_AUDIO_PATCH) || |
| 1542 | (command->mCommand == RELEASE_AUDIO_PATCH)) { |
| 1543 | if ((command2->mCommand != CREATE_AUDIO_PATCH) && |
| 1544 | (command2->mCommand != RELEASE_AUDIO_PATCH)) { |
| 1545 | continue; |
| 1546 | } |
| 1547 | } else if (command2->mCommand != command->mCommand) continue; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1548 | |
| 1549 | switch (command->mCommand) { |
| 1550 | case SET_PARAMETERS: { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1551 | ParametersData *data = (ParametersData *)command->mParam.get(); |
| 1552 | ParametersData *data2 = (ParametersData *)command2->mParam.get(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1553 | if (data->mIO != data2->mIO) break; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1554 | ALOGV("Comparing parameter command %s to new command %s", |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1555 | data2->mKeyValuePairs.string(), data->mKeyValuePairs.string()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1556 | AudioParameter param = AudioParameter(data->mKeyValuePairs); |
| 1557 | AudioParameter param2 = AudioParameter(data2->mKeyValuePairs); |
| 1558 | for (size_t j = 0; j < param.size(); j++) { |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 1559 | String8 key; |
| 1560 | String8 value; |
| 1561 | param.getAt(j, key, value); |
| 1562 | for (size_t k = 0; k < param2.size(); k++) { |
| 1563 | String8 key2; |
| 1564 | String8 value2; |
| 1565 | param2.getAt(k, key2, value2); |
| 1566 | if (key2 == key) { |
| 1567 | param2.remove(key2); |
| 1568 | ALOGV("Filtering out parameter %s", key2.string()); |
| 1569 | break; |
| 1570 | } |
| 1571 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1572 | } |
| 1573 | // if all keys have been filtered out, remove the command. |
| 1574 | // otherwise, update the key value pairs |
| 1575 | if (param2.size() == 0) { |
| 1576 | removedCommands.add(command2); |
| 1577 | } else { |
| 1578 | data2->mKeyValuePairs = param2.toString(); |
| 1579 | } |
Eric Laurent | 21e5456 | 2013-09-23 12:08:05 -0700 | [diff] [blame] | 1580 | command->mTime = command2->mTime; |
| 1581 | // force delayMs to non 0 so that code below does not request to wait for |
| 1582 | // command status as the command is now delayed |
| 1583 | delayMs = 1; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1584 | } break; |
| 1585 | |
| 1586 | case SET_VOLUME: { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1587 | VolumeData *data = (VolumeData *)command->mParam.get(); |
| 1588 | VolumeData *data2 = (VolumeData *)command2->mParam.get(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1589 | if (data->mIO != data2->mIO) break; |
| 1590 | if (data->mStream != data2->mStream) break; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1591 | ALOGV("Filtering out volume command on output %d for stream %d", |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1592 | data->mIO, data->mStream); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1593 | removedCommands.add(command2); |
Eric Laurent | 21e5456 | 2013-09-23 12:08:05 -0700 | [diff] [blame] | 1594 | command->mTime = command2->mTime; |
| 1595 | // force delayMs to non 0 so that code below does not request to wait for |
| 1596 | // command status as the command is now delayed |
| 1597 | delayMs = 1; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1598 | } break; |
Eric Laurent | e45b48a | 2014-09-04 16:40:57 -0700 | [diff] [blame] | 1599 | |
Eric Laurent | baf35fe | 2016-07-27 15:36:53 -0700 | [diff] [blame] | 1600 | case SET_VOICE_VOLUME: { |
| 1601 | VoiceVolumeData *data = (VoiceVolumeData *)command->mParam.get(); |
| 1602 | VoiceVolumeData *data2 = (VoiceVolumeData *)command2->mParam.get(); |
| 1603 | ALOGV("Filtering out voice volume command value %f replaced by %f", |
| 1604 | data2->mVolume, data->mVolume); |
| 1605 | removedCommands.add(command2); |
| 1606 | command->mTime = command2->mTime; |
| 1607 | // force delayMs to non 0 so that code below does not request to wait for |
| 1608 | // command status as the command is now delayed |
| 1609 | delayMs = 1; |
| 1610 | } break; |
| 1611 | |
Eric Laurent | e45b48a | 2014-09-04 16:40:57 -0700 | [diff] [blame] | 1612 | case CREATE_AUDIO_PATCH: |
| 1613 | case RELEASE_AUDIO_PATCH: { |
| 1614 | audio_patch_handle_t handle; |
Haynes Mathew George | a2d4a6d | 2014-10-13 13:05:22 -0700 | [diff] [blame] | 1615 | struct audio_patch patch; |
Eric Laurent | e45b48a | 2014-09-04 16:40:57 -0700 | [diff] [blame] | 1616 | if (command->mCommand == CREATE_AUDIO_PATCH) { |
| 1617 | handle = ((CreateAudioPatchData *)command->mParam.get())->mHandle; |
Haynes Mathew George | a2d4a6d | 2014-10-13 13:05:22 -0700 | [diff] [blame] | 1618 | patch = ((CreateAudioPatchData *)command->mParam.get())->mPatch; |
Eric Laurent | e45b48a | 2014-09-04 16:40:57 -0700 | [diff] [blame] | 1619 | } else { |
| 1620 | handle = ((ReleaseAudioPatchData *)command->mParam.get())->mHandle; |
Mikhail Naganov | 7be71d2 | 2018-05-23 16:51:46 -0700 | [diff] [blame] | 1621 | memset(&patch, 0, sizeof(patch)); |
Eric Laurent | e45b48a | 2014-09-04 16:40:57 -0700 | [diff] [blame] | 1622 | } |
| 1623 | audio_patch_handle_t handle2; |
Haynes Mathew George | a2d4a6d | 2014-10-13 13:05:22 -0700 | [diff] [blame] | 1624 | struct audio_patch patch2; |
Eric Laurent | e45b48a | 2014-09-04 16:40:57 -0700 | [diff] [blame] | 1625 | if (command2->mCommand == CREATE_AUDIO_PATCH) { |
| 1626 | handle2 = ((CreateAudioPatchData *)command2->mParam.get())->mHandle; |
Haynes Mathew George | a2d4a6d | 2014-10-13 13:05:22 -0700 | [diff] [blame] | 1627 | patch2 = ((CreateAudioPatchData *)command2->mParam.get())->mPatch; |
Eric Laurent | e45b48a | 2014-09-04 16:40:57 -0700 | [diff] [blame] | 1628 | } else { |
| 1629 | handle2 = ((ReleaseAudioPatchData *)command2->mParam.get())->mHandle; |
Glenn Kasten | f60b6b6 | 2015-07-06 10:53:26 -0700 | [diff] [blame] | 1630 | memset(&patch2, 0, sizeof(patch2)); |
Eric Laurent | e45b48a | 2014-09-04 16:40:57 -0700 | [diff] [blame] | 1631 | } |
| 1632 | if (handle != handle2) break; |
Haynes Mathew George | a2d4a6d | 2014-10-13 13:05:22 -0700 | [diff] [blame] | 1633 | /* Filter CREATE_AUDIO_PATCH commands only when they are issued for |
| 1634 | same output. */ |
| 1635 | if( (command->mCommand == CREATE_AUDIO_PATCH) && |
| 1636 | (command2->mCommand == CREATE_AUDIO_PATCH) ) { |
| 1637 | bool isOutputDiff = false; |
| 1638 | if (patch.num_sources == patch2.num_sources) { |
| 1639 | for (unsigned count = 0; count < patch.num_sources; count++) { |
| 1640 | if (patch.sources[count].id != patch2.sources[count].id) { |
| 1641 | isOutputDiff = true; |
| 1642 | break; |
| 1643 | } |
| 1644 | } |
| 1645 | if (isOutputDiff) |
| 1646 | break; |
| 1647 | } |
| 1648 | } |
Eric Laurent | e45b48a | 2014-09-04 16:40:57 -0700 | [diff] [blame] | 1649 | ALOGV("Filtering out %s audio patch command for handle %d", |
| 1650 | (command->mCommand == CREATE_AUDIO_PATCH) ? "create" : "release", handle); |
| 1651 | removedCommands.add(command2); |
| 1652 | command->mTime = command2->mTime; |
| 1653 | // force delayMs to non 0 so that code below does not request to wait for |
| 1654 | // command status as the command is now delayed |
| 1655 | delayMs = 1; |
| 1656 | } break; |
| 1657 | |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 1658 | case DYN_POLICY_MIX_STATE_UPDATE: { |
| 1659 | |
| 1660 | } break; |
| 1661 | |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 1662 | case RECORDING_CONFIGURATION_UPDATE: { |
| 1663 | |
| 1664 | } break; |
| 1665 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1666 | default: |
| 1667 | break; |
| 1668 | } |
| 1669 | } |
| 1670 | |
| 1671 | // remove filtered commands |
| 1672 | for (size_t j = 0; j < removedCommands.size(); j++) { |
| 1673 | // removed commands always have time stamps greater than current command |
| 1674 | for (size_t k = i + 1; k < mAudioCommands.size(); k++) { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1675 | if (mAudioCommands[k].get() == removedCommands[j].get()) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1676 | ALOGV("suppressing command: %d", mAudioCommands[k]->mCommand); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1677 | mAudioCommands.removeAt(k); |
| 1678 | break; |
| 1679 | } |
| 1680 | } |
| 1681 | } |
| 1682 | removedCommands.clear(); |
| 1683 | |
Eric Laurent | aa79bef | 2015-01-15 14:33:51 -0800 | [diff] [blame] | 1684 | // Disable wait for status if delay is not 0. |
| 1685 | // Except for create audio patch command because the returned patch handle |
| 1686 | // is needed by audio policy manager |
| 1687 | if (delayMs != 0 && command->mCommand != CREATE_AUDIO_PATCH) { |
Eric Laurent | cec4abb | 2012-07-03 12:23:02 -0700 | [diff] [blame] | 1688 | command->mWaitStatus = false; |
| 1689 | } |
Eric Laurent | cec4abb | 2012-07-03 12:23:02 -0700 | [diff] [blame] | 1690 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1691 | // insert command at the right place according to its time stamp |
Eric Laurent | 1e693b5 | 2014-07-09 15:03:28 -0700 | [diff] [blame] | 1692 | ALOGV("inserting command: %d at index %zd, num commands %zu", |
| 1693 | command->mCommand, i+1, mAudioCommands.size()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1694 | mAudioCommands.insertAt(command, i + 1); |
| 1695 | } |
| 1696 | |
| 1697 | void AudioPolicyService::AudioCommandThread::exit() |
| 1698 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1699 | ALOGV("AudioCommandThread::exit"); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1700 | { |
| 1701 | AutoMutex _l(mLock); |
| 1702 | requestExit(); |
| 1703 | mWaitWorkCV.signal(); |
| 1704 | } |
Zach Jang | a754b4f | 2015-10-27 01:29:34 +0000 | [diff] [blame] | 1705 | // Note that we can call it from the thread loop if all other references have been released |
| 1706 | // but it will safely return WOULD_BLOCK in this case |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1707 | requestExitAndWait(); |
| 1708 | } |
| 1709 | |
| 1710 | void AudioPolicyService::AudioCommandThread::AudioCommand::dump(char* buffer, size_t size) |
| 1711 | { |
| 1712 | snprintf(buffer, size, " %02d %06d.%03d %01u %p\n", |
| 1713 | mCommand, |
| 1714 | (int)ns2s(mTime), |
| 1715 | (int)ns2ms(mTime)%1000, |
| 1716 | mWaitStatus, |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1717 | mParam.get()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1718 | } |
| 1719 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1720 | /******* helpers for the service_ops callbacks defined below *********/ |
| 1721 | void AudioPolicyService::setParameters(audio_io_handle_t ioHandle, |
| 1722 | const char *keyValuePairs, |
| 1723 | int delayMs) |
| 1724 | { |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1725 | mAudioCommandThread->parametersCommand(ioHandle, keyValuePairs, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1726 | delayMs); |
| 1727 | } |
| 1728 | |
| 1729 | int AudioPolicyService::setStreamVolume(audio_stream_type_t stream, |
| 1730 | float volume, |
| 1731 | audio_io_handle_t output, |
| 1732 | int delayMs) |
| 1733 | { |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 1734 | return (int)mAudioCommandThread->volumeCommand(stream, volume, |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1735 | output, delayMs); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1736 | } |
| 1737 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1738 | int AudioPolicyService::setVoiceVolume(float volume, int delayMs) |
| 1739 | { |
| 1740 | return (int)mAudioCommandThread->voiceVolumeCommand(volume, delayMs); |
| 1741 | } |
| 1742 | |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 1743 | void AudioPolicyService::setEffectSuspended(int effectId, |
| 1744 | audio_session_t sessionId, |
| 1745 | bool suspended) |
| 1746 | { |
| 1747 | mAudioCommandThread->setEffectSuspendedCommand(effectId, sessionId, suspended); |
| 1748 | } |
| 1749 | |
| 1750 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1751 | extern "C" { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1752 | audio_module_handle_t aps_load_hw_module(void *service __unused, |
| 1753 | const char *name); |
| 1754 | audio_io_handle_t aps_open_output(void *service __unused, |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 1755 | audio_devices_t *pDevices, |
| 1756 | uint32_t *pSamplingRate, |
| 1757 | audio_format_t *pFormat, |
| 1758 | audio_channel_mask_t *pChannelMask, |
| 1759 | uint32_t *pLatencyMs, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1760 | audio_output_flags_t flags); |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 1761 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1762 | audio_io_handle_t aps_open_output_on_module(void *service __unused, |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 1763 | audio_module_handle_t module, |
| 1764 | audio_devices_t *pDevices, |
| 1765 | uint32_t *pSamplingRate, |
| 1766 | audio_format_t *pFormat, |
| 1767 | audio_channel_mask_t *pChannelMask, |
| 1768 | uint32_t *pLatencyMs, |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 1769 | audio_output_flags_t flags, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1770 | const audio_offload_info_t *offloadInfo); |
| 1771 | audio_io_handle_t aps_open_dup_output(void *service __unused, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1772 | audio_io_handle_t output1, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1773 | audio_io_handle_t output2); |
| 1774 | int aps_close_output(void *service __unused, audio_io_handle_t output); |
| 1775 | int aps_suspend_output(void *service __unused, audio_io_handle_t output); |
| 1776 | int aps_restore_output(void *service __unused, audio_io_handle_t output); |
| 1777 | audio_io_handle_t aps_open_input(void *service __unused, |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 1778 | audio_devices_t *pDevices, |
| 1779 | uint32_t *pSamplingRate, |
| 1780 | audio_format_t *pFormat, |
| 1781 | audio_channel_mask_t *pChannelMask, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1782 | audio_in_acoustics_t acoustics __unused); |
| 1783 | audio_io_handle_t aps_open_input_on_module(void *service __unused, |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 1784 | audio_module_handle_t module, |
| 1785 | audio_devices_t *pDevices, |
| 1786 | uint32_t *pSamplingRate, |
| 1787 | audio_format_t *pFormat, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1788 | audio_channel_mask_t *pChannelMask); |
| 1789 | int aps_close_input(void *service __unused, audio_io_handle_t input); |
| 1790 | int aps_invalidate_stream(void *service __unused, audio_stream_type_t stream); |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 1791 | int aps_move_effects(void *service __unused, audio_session_t session, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1792 | audio_io_handle_t src_output, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1793 | audio_io_handle_t dst_output); |
| 1794 | char * aps_get_parameters(void *service __unused, audio_io_handle_t io_handle, |
| 1795 | const char *keys); |
| 1796 | void aps_set_parameters(void *service, audio_io_handle_t io_handle, |
| 1797 | const char *kv_pairs, int delay_ms); |
| 1798 | int aps_set_stream_volume(void *service, audio_stream_type_t stream, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1799 | float volume, audio_io_handle_t output, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1800 | int delay_ms); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1801 | int aps_set_voice_volume(void *service, float volume, int delay_ms); |
| 1802 | }; |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1803 | |
Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 1804 | } // namespace android |