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