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