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