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