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