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> |
Jaideep Sharma | ba9053b | 2021-01-25 21:24:26 +0530 | [diff] [blame] | 26 | #include <dlfcn.h> |
Mikhail Naganov | 959e2d0 | 2019-03-28 11:08:19 -0700 | [diff] [blame] | 27 | |
| 28 | #include <audio_utils/clock.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 29 | #include <binder/IServiceManager.h> |
| 30 | #include <utils/Log.h> |
| 31 | #include <cutils/properties.h> |
| 32 | #include <binder/IPCThreadState.h> |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 33 | #include <binder/PermissionController.h> |
| 34 | #include <binder/IResultReceiver.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 35 | #include <utils/String16.h> |
| 36 | #include <utils/threads.h> |
| 37 | #include "AudioPolicyService.h" |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 38 | #include <hardware_legacy/power.h> |
Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 39 | #include <media/AidlConversion.h> |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 40 | #include <media/AudioEffect.h> |
Chih-Hung Hsieh | c84d9d2 | 2014-11-14 13:33:34 -0800 | [diff] [blame] | 41 | #include <media/AudioParameter.h> |
Andy Hung | ab7ef30 | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 42 | #include <mediautils/ServiceUtilities.h> |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 43 | #include <mediautils/TimeCheck.h> |
Michael Groover | cfd2830 | 2018-12-11 19:16:46 -0800 | [diff] [blame] | 44 | #include <sensorprivacy/SensorPrivacyManager.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 45 | |
Dima Zavin | 6476024 | 2011-05-11 14:15:23 -0700 | [diff] [blame] | 46 | #include <system/audio.h> |
Dima Zavin | 7394a4f | 2011-06-13 18:16:26 -0700 | [diff] [blame] | 47 | #include <system/audio_policy.h> |
Jaideep Sharma | ba9053b | 2021-01-25 21:24:26 +0530 | [diff] [blame] | 48 | #include <AudioPolicyManager.h> |
Mikhail Naganov | 61a4fac | 2016-10-13 14:44:18 -0700 | [diff] [blame] | 49 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 50 | namespace android { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 51 | using binder::Status; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 52 | |
Glenn Kasten | 8dad0e3 | 2012-01-09 08:41:22 -0800 | [diff] [blame] | 53 | static const char kDeadlockedString[] = "AudioPolicyService may be deadlocked\n"; |
| 54 | static const char kCmdDeadlockedString[] = "AudioPolicyService command thread may be deadlocked\n"; |
Jaideep Sharma | ba9053b | 2021-01-25 21:24:26 +0530 | [diff] [blame] | 55 | static const char kAudioPolicyManagerCustomPath[] = "libaudiopolicymanagercustom.so"; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 56 | |
Mikhail Naganov | 959e2d0 | 2019-03-28 11:08:19 -0700 | [diff] [blame] | 57 | static const int kDumpLockTimeoutNs = 1 * NANOS_PER_SECOND; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 58 | |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 59 | static const nsecs_t kAudioCommandTimeoutNs = seconds(3); // 3 seconds |
Christer Fletcher | 5fa8c4b | 2013-01-18 15:27:03 +0100 | [diff] [blame] | 60 | |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 61 | static const String16 sManageAudioPolicyPermission("android.permission.MANAGE_AUDIO_POLICY"); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 62 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 63 | // ---------------------------------------------------------------------------- |
| 64 | |
Jaideep Sharma | ba9053b | 2021-01-25 21:24:26 +0530 | [diff] [blame] | 65 | static AudioPolicyInterface* createAudioPolicyManager(AudioPolicyClientInterface *clientInterface) |
| 66 | { |
| 67 | AudioPolicyManager *apm = new AudioPolicyManager(clientInterface); |
| 68 | status_t status = apm->initialize(); |
| 69 | if (status != NO_ERROR) { |
| 70 | delete apm; |
| 71 | apm = nullptr; |
| 72 | } |
| 73 | return apm; |
| 74 | } |
| 75 | |
| 76 | static void destroyAudioPolicyManager(AudioPolicyInterface *interface) |
| 77 | { |
| 78 | delete interface; |
| 79 | } |
| 80 | // ---------------------------------------------------------------------------- |
| 81 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 82 | AudioPolicyService::AudioPolicyService() |
Ytai Ben-Tsvi | 85093d5 | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 83 | : BnAudioPolicyService(), |
Ytai Ben-Tsvi | 85093d5 | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 84 | mAudioPolicyManager(NULL), |
| 85 | mAudioPolicyClient(NULL), |
| 86 | mPhoneState(AUDIO_MODE_INVALID), |
Jaideep Sharma | ba9053b | 2021-01-25 21:24:26 +0530 | [diff] [blame] | 87 | mCaptureStateNotifier(false), |
| 88 | mCreateAudioPolicyManager(createAudioPolicyManager), |
| 89 | mDestroyAudioPolicyManager(destroyAudioPolicyManager) { |
| 90 | } |
| 91 | |
| 92 | void AudioPolicyService::loadAudioPolicyManager() |
| 93 | { |
| 94 | mLibraryHandle = dlopen(kAudioPolicyManagerCustomPath, RTLD_NOW); |
| 95 | if (mLibraryHandle != nullptr) { |
| 96 | ALOGI("%s loading %s", __func__, kAudioPolicyManagerCustomPath); |
| 97 | mCreateAudioPolicyManager = reinterpret_cast<CreateAudioPolicyManagerInstance> |
| 98 | (dlsym(mLibraryHandle, "createAudioPolicyManager")); |
| 99 | const char *lastError = dlerror(); |
| 100 | ALOGW_IF(mCreateAudioPolicyManager == nullptr, "%s createAudioPolicyManager is null %s", |
| 101 | __func__, lastError != nullptr ? lastError : "no error"); |
| 102 | |
| 103 | mDestroyAudioPolicyManager = reinterpret_cast<DestroyAudioPolicyManagerInstance>( |
| 104 | dlsym(mLibraryHandle, "destroyAudioPolicyManager")); |
| 105 | lastError = dlerror(); |
| 106 | ALOGW_IF(mDestroyAudioPolicyManager == nullptr, "%s destroyAudioPolicyManager is null %s", |
| 107 | __func__, lastError != nullptr ? lastError : "no error"); |
| 108 | if (mCreateAudioPolicyManager == nullptr || mDestroyAudioPolicyManager == nullptr){ |
| 109 | unloadAudioPolicyManager(); |
| 110 | LOG_ALWAYS_FATAL("could not find audiopolicymanager interface methods"); |
| 111 | } |
| 112 | } |
Eric Laurent | f5ada6e | 2014-10-09 17:49:00 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | void AudioPolicyService::onFirstRef() |
| 116 | { |
Andy Hung | d47aca2 | 2022-03-15 11:50:51 -0700 | [diff] [blame] | 117 | // Log an AudioPolicy "constructor" mediametrics event on first ref. |
| 118 | // This records the time it takes to load the audio modules and devices. |
| 119 | mediametrics::Defer defer([beginNs = systemTime()] { |
| 120 | mediametrics::LogItem(AMEDIAMETRICS_KEY_AUDIO_POLICY) |
| 121 | .set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_CTOR) |
| 122 | .set(AMEDIAMETRICS_PROP_EXECUTIONTIMENS, (int64_t)(systemTime() - beginNs)) |
| 123 | .record(); }); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 124 | { |
| 125 | Mutex::Autolock _l(mLock); |
Eric Laurent | 9357520 | 2011-01-18 18:39:02 -0800 | [diff] [blame] | 126 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 127 | // start audio commands thread |
| 128 | mAudioCommandThread = new AudioCommandThread(String8("ApmAudio"), this); |
| 129 | // start output activity command thread |
| 130 | mOutputCommandThread = new AudioCommandThread(String8("ApmOutput"), this); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 131 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 132 | mAudioPolicyClient = new AudioPolicyClient(this); |
Jaideep Sharma | ba9053b | 2021-01-25 21:24:26 +0530 | [diff] [blame] | 133 | |
| 134 | loadAudioPolicyManager(); |
| 135 | mAudioPolicyManager = mCreateAudioPolicyManager(mAudioPolicyClient); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 136 | } |
Eric Laurent | d66d7a1 | 2021-07-13 13:35:32 +0200 | [diff] [blame] | 137 | |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame] | 138 | // load audio processing modules |
Mikhail Naganov | 12b716c | 2020-04-30 22:37:43 +0000 | [diff] [blame] | 139 | sp<AudioPolicyEffects> audioPolicyEffects = new AudioPolicyEffects(); |
| 140 | sp<UidPolicy> uidPolicy = new UidPolicy(this); |
| 141 | sp<SensorPrivacyPolicy> sensorPrivacyPolicy = new SensorPrivacyPolicy(this); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 142 | { |
| 143 | Mutex::Autolock _l(mLock); |
| 144 | mAudioPolicyEffects = audioPolicyEffects; |
Mikhail Naganov | 12b716c | 2020-04-30 22:37:43 +0000 | [diff] [blame] | 145 | mUidPolicy = uidPolicy; |
| 146 | mSensorPrivacyPolicy = sensorPrivacyPolicy; |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 147 | } |
Mikhail Naganov | 12b716c | 2020-04-30 22:37:43 +0000 | [diff] [blame] | 148 | uidPolicy->registerSelf(); |
| 149 | sensorPrivacyPolicy->registerSelf(); |
Eric Laurent | d66d7a1 | 2021-07-13 13:35:32 +0200 | [diff] [blame] | 150 | |
Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 151 | // Create spatializer if supported |
Eric Laurent | 52b0bd5 | 2021-09-27 15:25:40 +0200 | [diff] [blame] | 152 | if (mAudioPolicyManager != nullptr) { |
| 153 | Mutex::Autolock _l(mLock); |
| 154 | const audio_attributes_t attr = attributes_initializer(AUDIO_USAGE_MEDIA); |
| 155 | AudioDeviceTypeAddrVector devices; |
| 156 | bool hasSpatializer = mAudioPolicyManager->canBeSpatialized(&attr, nullptr, devices); |
| 157 | if (hasSpatializer) { |
| 158 | mSpatializer = Spatializer::create(this); |
| 159 | } |
Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 160 | } |
Eric Laurent | d66d7a1 | 2021-07-13 13:35:32 +0200 | [diff] [blame] | 161 | AudioSystem::audioPolicyReady(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Jaideep Sharma | ba9053b | 2021-01-25 21:24:26 +0530 | [diff] [blame] | 164 | void AudioPolicyService::unloadAudioPolicyManager() |
| 165 | { |
| 166 | ALOGV("%s ", __func__); |
| 167 | if (mLibraryHandle != nullptr) { |
| 168 | dlclose(mLibraryHandle); |
| 169 | } |
| 170 | mLibraryHandle = nullptr; |
| 171 | mCreateAudioPolicyManager = nullptr; |
| 172 | mDestroyAudioPolicyManager = nullptr; |
| 173 | } |
| 174 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 175 | AudioPolicyService::~AudioPolicyService() |
| 176 | { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 177 | mAudioCommandThread->exit(); |
Eric Laurent | 657ff61 | 2014-05-07 11:58:24 -0700 | [diff] [blame] | 178 | mOutputCommandThread->exit(); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 179 | |
Jaideep Sharma | ba9053b | 2021-01-25 21:24:26 +0530 | [diff] [blame] | 180 | mDestroyAudioPolicyManager(mAudioPolicyManager); |
| 181 | unloadAudioPolicyManager(); |
| 182 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 183 | delete mAudioPolicyClient; |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 184 | |
| 185 | mNotificationClients.clear(); |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame] | 186 | mAudioPolicyEffects.clear(); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 187 | |
| 188 | mUidPolicy->unregisterSelf(); |
Michael Groover | cfd2830 | 2018-12-11 19:16:46 -0800 | [diff] [blame] | 189 | mSensorPrivacyPolicy->unregisterSelf(); |
Mikhail Naganov | 12b716c | 2020-04-30 22:37:43 +0000 | [diff] [blame] | 190 | |
| 191 | mUidPolicy.clear(); |
Michael Groover | cfd2830 | 2018-12-11 19:16:46 -0800 | [diff] [blame] | 192 | mSensorPrivacyPolicy.clear(); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | // A notification client is always registered by AudioSystem when the client process |
| 196 | // connects to AudioPolicyService. |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 197 | Status AudioPolicyService::registerClient(const sp<media::IAudioPolicyServiceClient>& client) |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 198 | { |
Eric Laurent | 1259025 | 2015-08-21 18:40:20 -0700 | [diff] [blame] | 199 | if (client == 0) { |
| 200 | ALOGW("%s got NULL client", __FUNCTION__); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 201 | return Status::ok(); |
Eric Laurent | 1259025 | 2015-08-21 18:40:20 -0700 | [diff] [blame] | 202 | } |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 203 | Mutex::Autolock _l(mNotificationClientsLock); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 204 | |
| 205 | uid_t uid = IPCThreadState::self()->getCallingUid(); |
luochaojiang | 908c7d7 | 2018-06-21 14:58:04 +0800 | [diff] [blame] | 206 | pid_t pid = IPCThreadState::self()->getCallingPid(); |
| 207 | int64_t token = ((int64_t)uid<<32) | pid; |
| 208 | |
| 209 | if (mNotificationClients.indexOfKey(token) < 0) { |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 210 | sp<NotificationClient> notificationClient = new NotificationClient(this, |
| 211 | client, |
luochaojiang | 908c7d7 | 2018-06-21 14:58:04 +0800 | [diff] [blame] | 212 | uid, |
| 213 | pid); |
| 214 | ALOGV("registerClient() client %p, uid %d pid %d", client.get(), uid, pid); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 215 | |
luochaojiang | 908c7d7 | 2018-06-21 14:58:04 +0800 | [diff] [blame] | 216 | mNotificationClients.add(token, notificationClient); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 217 | |
Marco Nelissen | f888020 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 218 | sp<IBinder> binder = IInterface::asBinder(client); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 219 | binder->linkToDeath(notificationClient); |
| 220 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 221 | return Status::ok(); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 224 | Status AudioPolicyService::setAudioPortCallbacksEnabled(bool enabled) |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 225 | { |
| 226 | Mutex::Autolock _l(mNotificationClientsLock); |
| 227 | |
| 228 | uid_t uid = IPCThreadState::self()->getCallingUid(); |
luochaojiang | 908c7d7 | 2018-06-21 14:58:04 +0800 | [diff] [blame] | 229 | pid_t pid = IPCThreadState::self()->getCallingPid(); |
| 230 | int64_t token = ((int64_t)uid<<32) | pid; |
| 231 | |
| 232 | if (mNotificationClients.indexOfKey(token) < 0) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 233 | return Status::ok(); |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 234 | } |
luochaojiang | 908c7d7 | 2018-06-21 14:58:04 +0800 | [diff] [blame] | 235 | mNotificationClients.valueFor(token)->setAudioPortCallbacksEnabled(enabled); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 236 | return Status::ok(); |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 239 | Status AudioPolicyService::setAudioVolumeGroupCallbacksEnabled(bool enabled) |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 240 | { |
| 241 | Mutex::Autolock _l(mNotificationClientsLock); |
| 242 | |
| 243 | uid_t uid = IPCThreadState::self()->getCallingUid(); |
| 244 | pid_t pid = IPCThreadState::self()->getCallingPid(); |
| 245 | int64_t token = ((int64_t)uid<<32) | pid; |
| 246 | |
| 247 | if (mNotificationClients.indexOfKey(token) < 0) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 248 | return Status::ok(); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 249 | } |
| 250 | mNotificationClients.valueFor(token)->setAudioVolumeGroupCallbacksEnabled(enabled); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 251 | return Status::ok(); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 252 | } |
| 253 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 254 | // removeNotificationClient() is called when the client process dies. |
luochaojiang | 908c7d7 | 2018-06-21 14:58:04 +0800 | [diff] [blame] | 255 | void AudioPolicyService::removeNotificationClient(uid_t uid, pid_t pid) |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 256 | { |
Mikhail Naganov | 12b716c | 2020-04-30 22:37:43 +0000 | [diff] [blame] | 257 | bool hasSameUid = false; |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 258 | { |
| 259 | Mutex::Autolock _l(mNotificationClientsLock); |
luochaojiang | 908c7d7 | 2018-06-21 14:58:04 +0800 | [diff] [blame] | 260 | int64_t token = ((int64_t)uid<<32) | pid; |
| 261 | mNotificationClients.removeItem(token); |
luochaojiang | 908c7d7 | 2018-06-21 14:58:04 +0800 | [diff] [blame] | 262 | for (size_t i = 0; i < mNotificationClients.size(); i++) { |
| 263 | if (mNotificationClients.valueAt(i)->uid() == uid) { |
| 264 | hasSameUid = true; |
| 265 | break; |
| 266 | } |
| 267 | } |
Mikhail Naganov | 12b716c | 2020-04-30 22:37:43 +0000 | [diff] [blame] | 268 | } |
| 269 | { |
| 270 | Mutex::Autolock _l(mLock); |
luochaojiang | 908c7d7 | 2018-06-21 14:58:04 +0800 | [diff] [blame] | 271 | if (mAudioPolicyManager && !hasSameUid) { |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 272 | // called from binder death notification: no need to clear caller identity |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 273 | mAudioPolicyManager->releaseResourcesForUid(uid); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 274 | } |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 275 | } |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | void AudioPolicyService::onAudioPortListUpdate() |
| 279 | { |
| 280 | mOutputCommandThread->updateAudioPortListCommand(); |
| 281 | } |
| 282 | |
| 283 | void AudioPolicyService::doOnAudioPortListUpdate() |
| 284 | { |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 285 | Mutex::Autolock _l(mNotificationClientsLock); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 286 | for (size_t i = 0; i < mNotificationClients.size(); i++) { |
| 287 | mNotificationClients.valueAt(i)->onAudioPortListUpdate(); |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | void AudioPolicyService::onAudioPatchListUpdate() |
| 292 | { |
| 293 | mOutputCommandThread->updateAudioPatchListCommand(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 296 | void AudioPolicyService::doOnAudioPatchListUpdate() |
| 297 | { |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 298 | Mutex::Autolock _l(mNotificationClientsLock); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 299 | for (size_t i = 0; i < mNotificationClients.size(); i++) { |
| 300 | mNotificationClients.valueAt(i)->onAudioPatchListUpdate(); |
| 301 | } |
| 302 | } |
| 303 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 304 | void AudioPolicyService::onAudioVolumeGroupChanged(volume_group_t group, int flags) |
| 305 | { |
| 306 | mOutputCommandThread->changeAudioVolumeGroupCommand(group, flags); |
| 307 | } |
| 308 | |
| 309 | void AudioPolicyService::doOnAudioVolumeGroupChanged(volume_group_t group, int flags) |
| 310 | { |
| 311 | Mutex::Autolock _l(mNotificationClientsLock); |
| 312 | for (size_t i = 0; i < mNotificationClients.size(); i++) { |
| 313 | mNotificationClients.valueAt(i)->onAudioVolumeGroupChanged(group, flags); |
| 314 | } |
| 315 | } |
| 316 | |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 317 | void AudioPolicyService::onDynamicPolicyMixStateUpdate(const String8& regId, int32_t state) |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 318 | { |
| 319 | ALOGV("AudioPolicyService::onDynamicPolicyMixStateUpdate(%s, %d)", |
| 320 | regId.string(), state); |
| 321 | mOutputCommandThread->dynamicPolicyMixStateUpdateCommand(regId, state); |
| 322 | } |
| 323 | |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 324 | void AudioPolicyService::doOnDynamicPolicyMixStateUpdate(const String8& regId, int32_t state) |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 325 | { |
| 326 | Mutex::Autolock _l(mNotificationClientsLock); |
| 327 | for (size_t i = 0; i < mNotificationClients.size(); i++) { |
| 328 | mNotificationClients.valueAt(i)->onDynamicPolicyMixStateUpdate(regId, state); |
| 329 | } |
| 330 | } |
| 331 | |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 332 | void AudioPolicyService::onRecordingConfigurationUpdate( |
| 333 | int event, |
| 334 | const record_client_info_t *clientInfo, |
| 335 | const audio_config_base_t *clientConfig, |
| 336 | std::vector<effect_descriptor_t> clientEffects, |
| 337 | const audio_config_base_t *deviceConfig, |
| 338 | std::vector<effect_descriptor_t> effects, |
| 339 | audio_patch_handle_t patchHandle, |
| 340 | audio_source_t source) |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 341 | { |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 342 | mOutputCommandThread->recordingConfigurationUpdateCommand(event, clientInfo, |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 343 | clientConfig, clientEffects, deviceConfig, effects, patchHandle, source); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 344 | } |
| 345 | |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 346 | void AudioPolicyService::doOnRecordingConfigurationUpdate( |
| 347 | int event, |
| 348 | const record_client_info_t *clientInfo, |
| 349 | const audio_config_base_t *clientConfig, |
| 350 | std::vector<effect_descriptor_t> clientEffects, |
| 351 | const audio_config_base_t *deviceConfig, |
| 352 | std::vector<effect_descriptor_t> effects, |
| 353 | audio_patch_handle_t patchHandle, |
| 354 | audio_source_t source) |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 355 | { |
| 356 | Mutex::Autolock _l(mNotificationClientsLock); |
| 357 | for (size_t i = 0; i < mNotificationClients.size(); i++) { |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 358 | mNotificationClients.valueAt(i)->onRecordingConfigurationUpdate(event, clientInfo, |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 359 | clientConfig, clientEffects, deviceConfig, effects, patchHandle, source); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 360 | } |
| 361 | } |
| 362 | |
Jean-Michel Trivi | 9a6b9ad | 2020-10-22 16:46:43 -0700 | [diff] [blame] | 363 | void AudioPolicyService::onRoutingUpdated() |
| 364 | { |
| 365 | mOutputCommandThread->routingChangedCommand(); |
| 366 | } |
| 367 | |
| 368 | void AudioPolicyService::doOnRoutingUpdated() |
| 369 | { |
| 370 | Mutex::Autolock _l(mNotificationClientsLock); |
| 371 | for (size_t i = 0; i < mNotificationClients.size(); i++) { |
| 372 | mNotificationClients.valueAt(i)->onRoutingUpdated(); |
| 373 | } |
| 374 | } |
| 375 | |
Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 376 | void AudioPolicyService::onCheckSpatializer() |
| 377 | { |
| 378 | Mutex::Autolock _l(mLock); |
Eric Laurent | 3909598 | 2021-08-24 18:29:27 +0200 | [diff] [blame] | 379 | onCheckSpatializer_l(); |
| 380 | } |
| 381 | |
| 382 | void AudioPolicyService::onCheckSpatializer_l() |
| 383 | { |
| 384 | if (mSpatializer != nullptr) { |
| 385 | mOutputCommandThread->checkSpatializerCommand(); |
| 386 | } |
Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | void AudioPolicyService::doOnCheckSpatializer() |
| 390 | { |
Eric Laurent | 3909598 | 2021-08-24 18:29:27 +0200 | [diff] [blame] | 391 | Mutex::Autolock _l(mLock); |
Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 392 | |
Eric Laurent | 3909598 | 2021-08-24 18:29:27 +0200 | [diff] [blame] | 393 | if (mSpatializer != nullptr) { |
Eric Laurent | 52b0bd5 | 2021-09-27 15:25:40 +0200 | [diff] [blame] | 394 | // Note: mSpatializer != nullptr => mAudioPolicyManager != nullptr |
Eric Laurent | 3909598 | 2021-08-24 18:29:27 +0200 | [diff] [blame] | 395 | if (mSpatializer->getLevel() != media::SpatializationLevel::NONE) { |
| 396 | audio_io_handle_t currentOutput = mSpatializer->getOutput(); |
| 397 | audio_io_handle_t newOutput; |
| 398 | const audio_attributes_t attr = attributes_initializer(AUDIO_USAGE_MEDIA); |
| 399 | audio_config_base_t config = mSpatializer->getAudioInConfig(); |
| 400 | status_t status = |
| 401 | mAudioPolicyManager->getSpatializerOutput(&config, &attr, &newOutput); |
Eric Laurent | b4f42a9 | 2022-01-17 17:37:31 +0100 | [diff] [blame] | 402 | ALOGV("%s currentOutput %d newOutput %d channel_mask %#x", |
| 403 | __func__, currentOutput, newOutput, config.channel_mask); |
Eric Laurent | 3909598 | 2021-08-24 18:29:27 +0200 | [diff] [blame] | 404 | if (status == NO_ERROR && currentOutput == newOutput) { |
| 405 | return; |
| 406 | } |
Eric Laurent | 1590359 | 2022-02-24 20:44:36 +0100 | [diff] [blame] | 407 | size_t numActiveTracks = countActiveClientsOnOutput_l(newOutput); |
Eric Laurent | 3909598 | 2021-08-24 18:29:27 +0200 | [diff] [blame] | 408 | mLock.unlock(); |
| 409 | // It is OK to call detachOutput() is none is already attached. |
| 410 | mSpatializer->detachOutput(); |
| 411 | if (status != NO_ERROR || newOutput == AUDIO_IO_HANDLE_NONE) { |
Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 412 | mLock.lock(); |
Eric Laurent | 3909598 | 2021-08-24 18:29:27 +0200 | [diff] [blame] | 413 | return; |
| 414 | } |
Eric Laurent | 1590359 | 2022-02-24 20:44:36 +0100 | [diff] [blame] | 415 | status = mSpatializer->attachOutput(newOutput, numActiveTracks); |
Eric Laurent | 3909598 | 2021-08-24 18:29:27 +0200 | [diff] [blame] | 416 | mLock.lock(); |
| 417 | if (status != NO_ERROR) { |
| 418 | mAudioPolicyManager->releaseSpatializerOutput(newOutput); |
| 419 | } |
| 420 | } else if (mSpatializer->getLevel() == media::SpatializationLevel::NONE |
| 421 | && mSpatializer->getOutput() != AUDIO_IO_HANDLE_NONE) { |
| 422 | mLock.unlock(); |
| 423 | audio_io_handle_t output = mSpatializer->detachOutput(); |
| 424 | mLock.lock(); |
| 425 | if (output != AUDIO_IO_HANDLE_NONE) { |
| 426 | mAudioPolicyManager->releaseSpatializerOutput(output); |
Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | } |
| 430 | } |
| 431 | |
Eric Laurent | 1590359 | 2022-02-24 20:44:36 +0100 | [diff] [blame] | 432 | size_t AudioPolicyService::countActiveClientsOnOutput_l(audio_io_handle_t output) REQUIRES(mLock) { |
| 433 | size_t count = 0; |
| 434 | for (size_t i = 0; i < mAudioPlaybackClients.size(); i++) { |
| 435 | auto client = mAudioPlaybackClients.valueAt(i); |
| 436 | if (client->io == output && client->active) { |
| 437 | count++; |
| 438 | } |
| 439 | } |
| 440 | return count; |
| 441 | } |
| 442 | |
| 443 | void AudioPolicyService::onUpdateActiveSpatializerTracks_l() { |
| 444 | if (mSpatializer == nullptr) { |
| 445 | return; |
| 446 | } |
| 447 | mOutputCommandThread->updateActiveSpatializerTracksCommand(); |
| 448 | } |
| 449 | |
| 450 | void AudioPolicyService::doOnUpdateActiveSpatializerTracks() |
| 451 | { |
| 452 | Mutex::Autolock _l(mLock); |
| 453 | if (mSpatializer == nullptr) { |
| 454 | return; |
| 455 | } |
| 456 | mSpatializer->updateActiveTracks(countActiveClientsOnOutput_l(mSpatializer->getOutput())); |
| 457 | } |
| 458 | |
| 459 | |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 460 | status_t AudioPolicyService::clientCreateAudioPatch(const struct audio_patch *patch, |
| 461 | audio_patch_handle_t *handle, |
| 462 | int delayMs) |
| 463 | { |
| 464 | return mAudioCommandThread->createAudioPatchCommand(patch, handle, delayMs); |
| 465 | } |
| 466 | |
| 467 | status_t AudioPolicyService::clientReleaseAudioPatch(audio_patch_handle_t handle, |
| 468 | int delayMs) |
| 469 | { |
| 470 | return mAudioCommandThread->releaseAudioPatchCommand(handle, delayMs); |
| 471 | } |
| 472 | |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 473 | status_t AudioPolicyService::clientSetAudioPortConfig(const struct audio_port_config *config, |
| 474 | int delayMs) |
| 475 | { |
| 476 | return mAudioCommandThread->setAudioPortConfigCommand(config, delayMs); |
| 477 | } |
| 478 | |
Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 479 | AudioPolicyService::NotificationClient::NotificationClient( |
| 480 | const sp<AudioPolicyService>& service, |
| 481 | const sp<media::IAudioPolicyServiceClient>& client, |
| 482 | uid_t uid, |
| 483 | pid_t pid) |
luochaojiang | 908c7d7 | 2018-06-21 14:58:04 +0800 | [diff] [blame] | 484 | : mService(service), mUid(uid), mPid(pid), mAudioPolicyServiceClient(client), |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 485 | mAudioPortCallbacksEnabled(false), mAudioVolumeGroupCallbacksEnabled(false) |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 486 | { |
| 487 | } |
| 488 | |
| 489 | AudioPolicyService::NotificationClient::~NotificationClient() |
| 490 | { |
| 491 | } |
| 492 | |
| 493 | void AudioPolicyService::NotificationClient::binderDied(const wp<IBinder>& who __unused) |
| 494 | { |
| 495 | sp<NotificationClient> keep(this); |
| 496 | sp<AudioPolicyService> service = mService.promote(); |
| 497 | if (service != 0) { |
luochaojiang | 908c7d7 | 2018-06-21 14:58:04 +0800 | [diff] [blame] | 498 | service->removeNotificationClient(mUid, mPid); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 499 | } |
| 500 | } |
| 501 | |
| 502 | void AudioPolicyService::NotificationClient::onAudioPortListUpdate() |
| 503 | { |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 504 | if (mAudioPolicyServiceClient != 0 && mAudioPortCallbacksEnabled) { |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 505 | mAudioPolicyServiceClient->onAudioPortListUpdate(); |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | void AudioPolicyService::NotificationClient::onAudioPatchListUpdate() |
| 510 | { |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 511 | if (mAudioPolicyServiceClient != 0 && mAudioPortCallbacksEnabled) { |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 512 | mAudioPolicyServiceClient->onAudioPatchListUpdate(); |
| 513 | } |
| 514 | } |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 515 | |
Patty | dd80758 | 2021-11-04 21:01:03 +0800 | [diff] [blame] | 516 | void AudioPolicyService::NotificationClient::onAudioVolumeGroupChanged(volume_group_t group, |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 517 | int flags) |
| 518 | { |
| 519 | if (mAudioPolicyServiceClient != 0 && mAudioVolumeGroupCallbacksEnabled) { |
| 520 | mAudioPolicyServiceClient->onAudioVolumeGroupChanged(group, flags); |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 525 | void AudioPolicyService::NotificationClient::onDynamicPolicyMixStateUpdate( |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 526 | const String8& regId, int32_t state) |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 527 | { |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 528 | if (mAudioPolicyServiceClient != 0 && isServiceUid(mUid)) { |
Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 529 | mAudioPolicyServiceClient->onDynamicPolicyMixStateUpdate( |
| 530 | legacy2aidl_String8_string(regId).value(), state); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 531 | } |
| 532 | } |
| 533 | |
| 534 | void AudioPolicyService::NotificationClient::onRecordingConfigurationUpdate( |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 535 | int event, |
| 536 | const record_client_info_t *clientInfo, |
| 537 | const audio_config_base_t *clientConfig, |
| 538 | std::vector<effect_descriptor_t> clientEffects, |
| 539 | const audio_config_base_t *deviceConfig, |
| 540 | std::vector<effect_descriptor_t> effects, |
| 541 | audio_patch_handle_t patchHandle, |
| 542 | audio_source_t source) |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 543 | { |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 544 | if (mAudioPolicyServiceClient != 0 && isServiceUid(mUid)) { |
Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 545 | status_t status = [&]() -> status_t { |
| 546 | int32_t eventAidl = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(event)); |
| 547 | media::RecordClientInfo clientInfoAidl = VALUE_OR_RETURN_STATUS( |
| 548 | legacy2aidl_record_client_info_t_RecordClientInfo(*clientInfo)); |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 549 | AudioConfigBase clientConfigAidl = VALUE_OR_RETURN_STATUS( |
Mikhail Naganov | de3fa18 | 2021-07-30 15:06:42 -0700 | [diff] [blame] | 550 | legacy2aidl_audio_config_base_t_AudioConfigBase( |
| 551 | *clientConfig, true /*isInput*/)); |
Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 552 | std::vector<media::EffectDescriptor> clientEffectsAidl = VALUE_OR_RETURN_STATUS( |
| 553 | convertContainer<std::vector<media::EffectDescriptor>>( |
| 554 | clientEffects, |
| 555 | legacy2aidl_effect_descriptor_t_EffectDescriptor)); |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 556 | AudioConfigBase deviceConfigAidl = VALUE_OR_RETURN_STATUS( |
Mikhail Naganov | de3fa18 | 2021-07-30 15:06:42 -0700 | [diff] [blame] | 557 | legacy2aidl_audio_config_base_t_AudioConfigBase( |
| 558 | *deviceConfig, true /*isInput*/)); |
Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 559 | std::vector<media::EffectDescriptor> effectsAidl = VALUE_OR_RETURN_STATUS( |
| 560 | convertContainer<std::vector<media::EffectDescriptor>>( |
| 561 | effects, |
| 562 | legacy2aidl_effect_descriptor_t_EffectDescriptor)); |
| 563 | int32_t patchHandleAidl = VALUE_OR_RETURN_STATUS( |
| 564 | legacy2aidl_audio_patch_handle_t_int32_t(patchHandle)); |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 565 | media::audio::common::AudioSource sourceAidl = VALUE_OR_RETURN_STATUS( |
| 566 | legacy2aidl_audio_source_t_AudioSource(source)); |
Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 567 | return aidl_utils::statusTFromBinderStatus( |
| 568 | mAudioPolicyServiceClient->onRecordingConfigurationUpdate(eventAidl, |
| 569 | clientInfoAidl, |
| 570 | clientConfigAidl, |
| 571 | clientEffectsAidl, |
| 572 | deviceConfigAidl, |
| 573 | effectsAidl, |
| 574 | patchHandleAidl, |
| 575 | sourceAidl)); |
| 576 | }(); |
| 577 | ALOGW_IF(status != OK, "onRecordingConfigurationUpdate() failed: %d", status); |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 578 | } |
| 579 | } |
| 580 | |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 581 | void AudioPolicyService::NotificationClient::setAudioPortCallbacksEnabled(bool enabled) |
| 582 | { |
| 583 | mAudioPortCallbacksEnabled = enabled; |
| 584 | } |
| 585 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 586 | void AudioPolicyService::NotificationClient::setAudioVolumeGroupCallbacksEnabled(bool enabled) |
| 587 | { |
| 588 | mAudioVolumeGroupCallbacksEnabled = enabled; |
| 589 | } |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 590 | |
Jean-Michel Trivi | 9a6b9ad | 2020-10-22 16:46:43 -0700 | [diff] [blame] | 591 | void AudioPolicyService::NotificationClient::onRoutingUpdated() |
| 592 | { |
| 593 | if (mAudioPolicyServiceClient != 0 && isServiceUid(mUid)) { |
| 594 | mAudioPolicyServiceClient->onRoutingUpdated(); |
| 595 | } |
| 596 | } |
| 597 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 598 | void AudioPolicyService::binderDied(const wp<IBinder>& who) { |
Glenn Kasten | 411e447 | 2012-11-02 10:00:06 -0700 | [diff] [blame] | 599 | ALOGW("binderDied() %p, calling pid %d", who.unsafe_get(), |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 600 | IPCThreadState::self()->getCallingPid()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 601 | } |
| 602 | |
Mikhail Naganov | 12b716c | 2020-04-30 22:37:43 +0000 | [diff] [blame] | 603 | static bool dumpTryLock(Mutex& mutex) ACQUIRE(mutex) NO_THREAD_SAFETY_ANALYSIS |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 604 | { |
Mikhail Naganov | 12b716c | 2020-04-30 22:37:43 +0000 | [diff] [blame] | 605 | return mutex.timedLock(kDumpLockTimeoutNs) == NO_ERROR; |
| 606 | } |
| 607 | |
| 608 | static void dumpReleaseLock(Mutex& mutex, bool locked) RELEASE(mutex) NO_THREAD_SAFETY_ANALYSIS |
| 609 | { |
| 610 | if (locked) mutex.unlock(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | status_t AudioPolicyService::dumpInternals(int fd) |
| 614 | { |
| 615 | const size_t SIZE = 256; |
| 616 | char buffer[SIZE]; |
| 617 | String8 result; |
| 618 | |
Mikhail Naganov | b3bcb4f | 2022-02-23 23:46:56 +0000 | [diff] [blame] | 619 | snprintf(buffer, SIZE, "Supported System Usages:\n "); |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 620 | result.append(buffer); |
Mikhail Naganov | b3bcb4f | 2022-02-23 23:46:56 +0000 | [diff] [blame] | 621 | std::stringstream msg; |
| 622 | size_t i = 0; |
| 623 | for (auto usage : mSupportedSystemUsages) { |
| 624 | if (i++ != 0) msg << ", "; |
| 625 | if (const char* strUsage = audio_usage_to_string(usage); strUsage) { |
| 626 | msg << strUsage; |
| 627 | } else { |
| 628 | msg << usage << " (unknown)"; |
| 629 | } |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 630 | } |
Mikhail Naganov | b3bcb4f | 2022-02-23 23:46:56 +0000 | [diff] [blame] | 631 | if (i == 0) { |
| 632 | msg << "None"; |
| 633 | } |
| 634 | msg << std::endl; |
| 635 | result.append(msg.str().c_str()); |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 636 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 637 | write(fd, result.string(), result.size()); |
Oscar Azucena | 829d90d | 2022-01-28 17:17:56 -0800 | [diff] [blame] | 638 | |
| 639 | mUidPolicy->dumpInternals(fd); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 640 | return NO_ERROR; |
| 641 | } |
| 642 | |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 643 | void AudioPolicyService::updateUidStates() |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 644 | { |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 645 | Mutex::Autolock _l(mLock); |
| 646 | updateUidStates_l(); |
| 647 | } |
| 648 | |
| 649 | void AudioPolicyService::updateUidStates_l() |
| 650 | { |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 651 | // Go over all active clients and allow capture (does not force silence) in the |
| 652 | // following cases: |
Oscar Azucena | c2cdda3 | 2022-01-31 19:10:39 -0800 | [diff] [blame] | 653 | // The client is in the active assistant list |
| 654 | // AND is TOP |
| 655 | // AND an accessibility service is TOP |
| 656 | // AND source is either VOICE_RECOGNITION OR HOTWORD |
| 657 | // OR there is no active privacy sensitive capture or call |
| 658 | // OR client has CAPTURE_AUDIO_OUTPUT privileged permission |
| 659 | // AND source is VOICE_RECOGNITION OR HOTWORD |
| 660 | // The client is an assistant AND active assistant is not being used |
Evan Severson | 1f700cd | 2021-02-10 13:10:37 -0800 | [diff] [blame] | 661 | // 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] | 662 | // AND the source is VOICE_RECOGNITION or HOTWORD |
Oscar Azucena | c2cdda3 | 2022-01-31 19:10:39 -0800 | [diff] [blame] | 663 | // OR there is no active privacy sensitive capture or call |
Evan Severson | 1f700cd | 2021-02-10 13:10:37 -0800 | [diff] [blame] | 664 | // OR client has CAPTURE_AUDIO_OUTPUT privileged permission |
Oscar Azucena | c2cdda3 | 2022-01-31 19:10:39 -0800 | [diff] [blame] | 665 | // AND is TOP most recent assistant and uses VOICE_RECOGNITION or HOTWORD |
| 666 | // OR there is no top recent assistant and source is HOTWORD |
Evan Severson | 1f700cd | 2021-02-10 13:10:37 -0800 | [diff] [blame] | 667 | // OR The client is an accessibility service |
| 668 | // AND Is on TOP |
| 669 | // AND the source is VOICE_RECOGNITION or HOTWORD |
| 670 | // OR The assistant is not on TOP |
Eric Laurent | 589171c | 2019-07-25 18:04:29 -0700 | [diff] [blame] | 671 | // AND there is no active privacy sensitive capture or call |
| 672 | // OR client has CAPTURE_AUDIO_OUTPUT privileged permission |
Evan Severson | 1f700cd | 2021-02-10 13:10:37 -0800 | [diff] [blame] | 673 | // AND is on TOP |
| 674 | // AND the source is VOICE_RECOGNITION or HOTWORD |
| 675 | // OR the client source is virtual (remote submix, call audio TX or RX...) |
| 676 | // OR the client source is HOTWORD |
| 677 | // AND is on TOP |
| 678 | // OR all active clients are using HOTWORD source |
| 679 | // AND no call is active |
| 680 | // OR client has CAPTURE_AUDIO_OUTPUT privileged permission |
| 681 | // OR the client is the current InputMethodService |
| 682 | // AND a RTT call is active AND the source is VOICE_RECOGNITION |
| 683 | // OR Any client |
| 684 | // AND The assistant is not on TOP |
| 685 | // AND is on TOP or latest started |
| 686 | // AND there is no active privacy sensitive capture or call |
| 687 | // OR client has CAPTURE_AUDIO_OUTPUT privileged permission |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 688 | |
Eric Laurent | 4e947da | 2019-10-17 15:24:06 -0700 | [diff] [blame] | 689 | |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 690 | sp<AudioRecordClient> topActive; |
| 691 | sp<AudioRecordClient> latestActive; |
Eric Laurent | c21d569 | 2020-02-25 10:24:36 -0800 | [diff] [blame] | 692 | sp<AudioRecordClient> topSensitiveActive; |
Eric Laurent | b809a75 | 2020-06-29 09:53:13 -0700 | [diff] [blame] | 693 | sp<AudioRecordClient> latestSensitiveActiveOrComm; |
Oscar Azucena | c2cdda3 | 2022-01-31 19:10:39 -0800 | [diff] [blame] | 694 | sp<AudioRecordClient> latestActiveAssistant; |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 695 | |
Eric Laurent | a46bedb | 2018-12-07 18:01:26 -0800 | [diff] [blame] | 696 | nsecs_t topStartNs = 0; |
| 697 | nsecs_t latestStartNs = 0; |
Eric Laurent | c21d569 | 2020-02-25 10:24:36 -0800 | [diff] [blame] | 698 | nsecs_t topSensitiveStartNs = 0; |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 699 | nsecs_t latestSensitiveStartNs = 0; |
Oscar Azucena | c2cdda3 | 2022-01-31 19:10:39 -0800 | [diff] [blame] | 700 | nsecs_t latestAssistantStartNs = 0; |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 701 | bool isA11yOnTop = mUidPolicy->isA11yOnTop(); |
| 702 | bool isAssistantOnTop = false; |
Oscar Azucena | c2cdda3 | 2022-01-31 19:10:39 -0800 | [diff] [blame] | 703 | bool useActiveAssistantList = false; |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 704 | bool isSensitiveActive = false; |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 705 | bool isInCall = mPhoneState == AUDIO_MODE_IN_CALL; |
Eric Laurent | c21d569 | 2020-02-25 10:24:36 -0800 | [diff] [blame] | 706 | bool isInCommunication = mPhoneState == AUDIO_MODE_IN_COMMUNICATION; |
| 707 | bool rttCallActive = (isInCall || isInCommunication) |
Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame] | 708 | && mUidPolicy->isRttEnabled(); |
Eric Laurent | 4e947da | 2019-10-17 15:24:06 -0700 | [diff] [blame] | 709 | bool onlyHotwordActive = true; |
Eric Laurent | b809a75 | 2020-06-29 09:53:13 -0700 | [diff] [blame] | 710 | bool isPhoneStateOwnerActive = false; |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 711 | |
Michael Groover | cfd2830 | 2018-12-11 19:16:46 -0800 | [diff] [blame] | 712 | // if Sensor Privacy is enabled then all recordings should be silenced. |
| 713 | if (mSensorPrivacyPolicy->isSensorPrivacyEnabled()) { |
| 714 | silenceAllRecordings_l(); |
| 715 | return; |
| 716 | } |
| 717 | |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 718 | for (size_t i =0; i < mAudioRecordClients.size(); i++) { |
| 719 | sp<AudioRecordClient> current = mAudioRecordClients[i]; |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 720 | uid_t currentUid = VALUE_OR_FATAL(aidl2legacy_int32_t_uid_t( |
| 721 | current->attributionSource.uid)); |
Evan Severson | 1f700cd | 2021-02-10 13:10:37 -0800 | [diff] [blame] | 722 | if (!current->active) { |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 723 | continue; |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 724 | } |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 725 | |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 726 | app_state_t appState = apmStatFromAmState(mUidPolicy->getUidState(currentUid)); |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 727 | // clients which app is in IDLE state are not eligible for top active or |
| 728 | // latest active |
| 729 | if (appState == APP_STATE_IDLE) { |
| 730 | continue; |
| 731 | } |
| 732 | |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 733 | bool isAccessibility = mUidPolicy->isA11yUid(currentUid); |
Eric Laurent | 14a8863 | 2020-07-16 12:28:30 -0700 | [diff] [blame] | 734 | // Clients capturing for Accessibility services or virtual sources are not considered |
Eric Laurent | c21d569 | 2020-02-25 10:24:36 -0800 | [diff] [blame] | 735 | // for top or latest active to avoid masking regular clients started before |
Eric Laurent | 14a8863 | 2020-07-16 12:28:30 -0700 | [diff] [blame] | 736 | if (!isAccessibility && !isVirtualSource(current->attributes.source)) { |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 737 | bool isAssistant = mUidPolicy->isAssistantUid(currentUid); |
Oscar Azucena | c2cdda3 | 2022-01-31 19:10:39 -0800 | [diff] [blame] | 738 | bool isActiveAssistant = mUidPolicy->isActiveAssistantUid(currentUid); |
Eric Laurent | c21d569 | 2020-02-25 10:24:36 -0800 | [diff] [blame] | 739 | bool isPrivacySensitive = |
| 740 | (current->attributes.flags & AUDIO_FLAG_CAPTURE_PRIVATE) != 0; |
Eric Laurent | b809a75 | 2020-06-29 09:53:13 -0700 | [diff] [blame] | 741 | |
Eric Laurent | c21d569 | 2020-02-25 10:24:36 -0800 | [diff] [blame] | 742 | if (appState == APP_STATE_TOP) { |
| 743 | if (isPrivacySensitive) { |
| 744 | if (current->startTimeNs > topSensitiveStartNs) { |
| 745 | topSensitiveActive = current; |
| 746 | topSensitiveStartNs = current->startTimeNs; |
| 747 | } |
| 748 | } else { |
| 749 | if (current->startTimeNs > topStartNs) { |
| 750 | topActive = current; |
| 751 | topStartNs = current->startTimeNs; |
| 752 | } |
| 753 | } |
| 754 | if (isAssistant) { |
| 755 | isAssistantOnTop = true; |
Oscar Azucena | c2cdda3 | 2022-01-31 19:10:39 -0800 | [diff] [blame] | 756 | if (isActiveAssistant) { |
| 757 | useActiveAssistantList = true; |
| 758 | } else if (!useActiveAssistantList) { |
| 759 | if (current->startTimeNs > latestAssistantStartNs) { |
| 760 | latestActiveAssistant = current; |
| 761 | latestAssistantStartNs = current->startTimeNs; |
| 762 | } |
| 763 | } |
Eric Laurent | c21d569 | 2020-02-25 10:24:36 -0800 | [diff] [blame] | 764 | } |
Eric Laurent | a46bedb | 2018-12-07 18:01:26 -0800 | [diff] [blame] | 765 | } |
Eric Laurent | c21d569 | 2020-02-25 10:24:36 -0800 | [diff] [blame] | 766 | // Clients capturing for HOTWORD are not considered |
| 767 | // for latest active to avoid masking regular clients started before |
| 768 | if (!(current->attributes.source == AUDIO_SOURCE_HOTWORD |
| 769 | || ((isA11yOnTop || rttCallActive) && isAssistant))) { |
| 770 | if (isPrivacySensitive) { |
Eric Laurent | b809a75 | 2020-06-29 09:53:13 -0700 | [diff] [blame] | 771 | // if audio mode is IN_COMMUNICATION, make sure the audio mode owner |
| 772 | // is marked latest sensitive active even if another app qualifies. |
| 773 | if (current->startTimeNs > latestSensitiveStartNs |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 774 | || (isInCommunication && currentUid == mPhoneStateOwnerUid)) { |
Eric Laurent | b809a75 | 2020-06-29 09:53:13 -0700 | [diff] [blame] | 775 | if (!isInCommunication || latestSensitiveActiveOrComm == nullptr |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 776 | || VALUE_OR_FATAL(aidl2legacy_int32_t_uid_t( |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 777 | latestSensitiveActiveOrComm->attributionSource.uid)) |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 778 | != mPhoneStateOwnerUid) { |
Eric Laurent | b809a75 | 2020-06-29 09:53:13 -0700 | [diff] [blame] | 779 | latestSensitiveActiveOrComm = current; |
| 780 | latestSensitiveStartNs = current->startTimeNs; |
| 781 | } |
Eric Laurent | c21d569 | 2020-02-25 10:24:36 -0800 | [diff] [blame] | 782 | } |
| 783 | isSensitiveActive = true; |
| 784 | } else { |
| 785 | if (current->startTimeNs > latestStartNs) { |
| 786 | latestActive = current; |
| 787 | latestStartNs = current->startTimeNs; |
| 788 | } |
| 789 | } |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 790 | } |
| 791 | } |
Eric Laurent | 4e947da | 2019-10-17 15:24:06 -0700 | [diff] [blame] | 792 | if (current->attributes.source != AUDIO_SOURCE_HOTWORD) { |
| 793 | onlyHotwordActive = false; |
| 794 | } |
Eric Laurent | b0eff0f | 2021-11-09 16:05:49 +0100 | [diff] [blame] | 795 | if (currentUid == mPhoneStateOwnerUid && |
| 796 | !isVirtualSource(current->attributes.source)) { |
Eric Laurent | b809a75 | 2020-06-29 09:53:13 -0700 | [diff] [blame] | 797 | isPhoneStateOwnerActive = true; |
| 798 | } |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 799 | } |
| 800 | |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 801 | // if no active client with UI on Top, consider latest active as top |
| 802 | if (topActive == nullptr) { |
| 803 | topActive = latestActive; |
Eric Laurent | c21d569 | 2020-02-25 10:24:36 -0800 | [diff] [blame] | 804 | topStartNs = latestStartNs; |
| 805 | } |
| 806 | if (topSensitiveActive == nullptr) { |
Eric Laurent | b809a75 | 2020-06-29 09:53:13 -0700 | [diff] [blame] | 807 | topSensitiveActive = latestSensitiveActiveOrComm; |
Eric Laurent | c21d569 | 2020-02-25 10:24:36 -0800 | [diff] [blame] | 808 | topSensitiveStartNs = latestSensitiveStartNs; |
Eric Laurent | b809a75 | 2020-06-29 09:53:13 -0700 | [diff] [blame] | 809 | } else if (latestSensitiveActiveOrComm != nullptr) { |
| 810 | // if audio mode is IN_COMMUNICATION, favor audio mode owner over an app with |
| 811 | // foreground UI in case both are capturing with privacy sensitive flag. |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 812 | uid_t latestActiveUid = VALUE_OR_FATAL( |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 813 | aidl2legacy_int32_t_uid_t(latestSensitiveActiveOrComm->attributionSource.uid)); |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 814 | if (isInCommunication && latestActiveUid == mPhoneStateOwnerUid) { |
Eric Laurent | b809a75 | 2020-06-29 09:53:13 -0700 | [diff] [blame] | 815 | topSensitiveActive = latestSensitiveActiveOrComm; |
| 816 | topSensitiveStartNs = latestSensitiveStartNs; |
| 817 | } |
Eric Laurent | c21d569 | 2020-02-25 10:24:36 -0800 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | // If both privacy sensitive and regular capture are active: |
| 821 | // if the regular capture is privileged |
| 822 | // allow concurrency |
| 823 | // else |
| 824 | // favor the privacy sensitive case |
| 825 | if (topActive != nullptr && topSensitiveActive != nullptr |
Ricardo Correa | 57a3769 | 2020-03-23 17:27:25 -0700 | [diff] [blame] | 826 | && !topActive->canCaptureOutput) { |
Eric Laurent | c21d569 | 2020-02-25 10:24:36 -0800 | [diff] [blame] | 827 | topActive = nullptr; |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | for (size_t i =0; i < mAudioRecordClients.size(); i++) { |
| 831 | sp<AudioRecordClient> current = mAudioRecordClients[i]; |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 832 | uid_t currentUid = VALUE_OR_FATAL(aidl2legacy_int32_t_uid_t( |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 833 | current->attributionSource.uid)); |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 834 | if (!current->active) { |
| 835 | continue; |
| 836 | } |
| 837 | |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 838 | audio_source_t source = current->attributes.source; |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 839 | bool isTopOrLatestActive = topActive == nullptr ? false : |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 840 | current->attributionSource.uid == topActive->attributionSource.uid; |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 841 | bool isTopOrLatestSensitive = topSensitiveActive == nullptr ? false : |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 842 | current->attributionSource.uid == topSensitiveActive->attributionSource.uid; |
Oscar Azucena | c2cdda3 | 2022-01-31 19:10:39 -0800 | [diff] [blame] | 843 | bool isTopOrLatestAssistant = latestActiveAssistant == nullptr ? false : |
| 844 | current->attributionSource.uid == latestActiveAssistant->attributionSource.uid; |
Eric Laurent | c21d569 | 2020-02-25 10:24:36 -0800 | [diff] [blame] | 845 | |
Mikhail Naganov | 12b716c | 2020-04-30 22:37:43 +0000 | [diff] [blame] | 846 | auto canCaptureIfInCallOrCommunication = [&](const auto &recordClient) REQUIRES(mLock) { |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 847 | uid_t recordUid = VALUE_OR_FATAL(aidl2legacy_int32_t_uid_t( |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 848 | recordClient->attributionSource.uid)); |
Ricardo Correa | 57a3769 | 2020-03-23 17:27:25 -0700 | [diff] [blame] | 849 | bool canCaptureCall = recordClient->canCaptureOutput; |
Eric Laurent | b809a75 | 2020-06-29 09:53:13 -0700 | [diff] [blame] | 850 | bool canCaptureCommunication = recordClient->canCaptureOutput |
| 851 | || !isPhoneStateOwnerActive |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 852 | || recordUid == mPhoneStateOwnerUid; |
Eric Laurent | b809a75 | 2020-06-29 09:53:13 -0700 | [diff] [blame] | 853 | return !(isInCall && !canCaptureCall) |
| 854 | && !(isInCommunication && !canCaptureCommunication); |
Eric Laurent | c21d569 | 2020-02-25 10:24:36 -0800 | [diff] [blame] | 855 | }; |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 856 | |
| 857 | // By default allow capture if: |
| 858 | // The assistant is not on TOP |
Eric Laurent | a171e35 | 2019-05-07 13:04:45 -0700 | [diff] [blame] | 859 | // AND is on TOP or latest started |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 860 | // AND there is no active privacy sensitive capture or call |
| 861 | // OR client has CAPTURE_AUDIO_OUTPUT privileged permission |
| 862 | bool allowCapture = !isAssistantOnTop |
Eric Laurent | c21d569 | 2020-02-25 10:24:36 -0800 | [diff] [blame] | 863 | && (isTopOrLatestActive || isTopOrLatestSensitive) |
| 864 | && !(isSensitiveActive |
Ricardo Correa | 57a3769 | 2020-03-23 17:27:25 -0700 | [diff] [blame] | 865 | && !(isTopOrLatestSensitive || current->canCaptureOutput)) |
Eric Laurent | c21d569 | 2020-02-25 10:24:36 -0800 | [diff] [blame] | 866 | && canCaptureIfInCallOrCommunication(current); |
Eric Laurent | 2dc962b | 2019-03-01 08:25:25 -0800 | [diff] [blame] | 867 | |
Eric Laurent | ed726cc | 2021-07-01 14:26:41 +0200 | [diff] [blame] | 868 | if (!current->hasOp()) { |
| 869 | // Never allow capture if app op is denied |
| 870 | allowCapture = false; |
| 871 | } else if (isVirtualSource(source)) { |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 872 | // Allow capture for virtual (remote submix, call audio TX or RX...) sources |
| 873 | allowCapture = true; |
Oscar Azucena | c2cdda3 | 2022-01-31 19:10:39 -0800 | [diff] [blame] | 874 | } else if (!useActiveAssistantList && mUidPolicy->isAssistantUid(currentUid)) { |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 875 | // For assistant allow capture if: |
Oscar Azucena | c2cdda3 | 2022-01-31 19:10:39 -0800 | [diff] [blame] | 876 | // Active assistant list is not being used |
| 877 | // AND accessibility service is on TOP or a RTT call is active |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 878 | // AND the source is VOICE_RECOGNITION or HOTWORD |
Oscar Azucena | c2cdda3 | 2022-01-31 19:10:39 -0800 | [diff] [blame] | 879 | // OR there is no active privacy sensitive capture or call |
| 880 | // OR client has CAPTURE_AUDIO_OUTPUT privileged permission |
| 881 | // AND is latest TOP assistant AND |
| 882 | // uses VOICE_RECOGNITION OR uses HOTWORD |
| 883 | // OR there is no TOP assistant and uses HOTWORD |
Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame] | 884 | if (isA11yOnTop || rttCallActive) { |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 885 | if (source == AUDIO_SOURCE_HOTWORD || source == AUDIO_SOURCE_VOICE_RECOGNITION) { |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 886 | allowCapture = true; |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 887 | } |
Oscar Azucena | c2cdda3 | 2022-01-31 19:10:39 -0800 | [diff] [blame] | 888 | } else if (!(isSensitiveActive && !current->canCaptureOutput) |
| 889 | && canCaptureIfInCallOrCommunication(current)) { |
| 890 | if (isTopOrLatestAssistant |
| 891 | && (source == AUDIO_SOURCE_VOICE_RECOGNITION |
| 892 | || source == AUDIO_SOURCE_HOTWORD)) { |
| 893 | allowCapture = true; |
| 894 | } else if (!isAssistantOnTop && (source == AUDIO_SOURCE_HOTWORD)) { |
| 895 | allowCapture = true; |
| 896 | } |
| 897 | } |
| 898 | } else if (useActiveAssistantList && mUidPolicy->isActiveAssistantUid(currentUid)) { |
| 899 | // For assistant on active list and on top allow capture if: |
| 900 | // An accessibility service is on TOP |
| 901 | // AND the source is VOICE_RECOGNITION or HOTWORD |
| 902 | // OR there is no active privacy sensitive capture or call |
| 903 | // OR client has CAPTURE_AUDIO_OUTPUT privileged permission |
| 904 | // AND uses VOICE_RECOGNITION OR uses HOTWORD |
| 905 | if (isA11yOnTop) { |
| 906 | if (source == AUDIO_SOURCE_HOTWORD || source == AUDIO_SOURCE_VOICE_RECOGNITION) { |
| 907 | allowCapture = true; |
| 908 | } |
| 909 | } else if (!(isSensitiveActive && !current->canCaptureOutput) |
Eric Laurent | c21d569 | 2020-02-25 10:24:36 -0800 | [diff] [blame] | 910 | && canCaptureIfInCallOrCommunication(current)) { |
Oscar Azucena | c2cdda3 | 2022-01-31 19:10:39 -0800 | [diff] [blame] | 911 | if ((source == AUDIO_SOURCE_VOICE_RECOGNITION) || (source == AUDIO_SOURCE_HOTWORD)) |
| 912 | { |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 913 | allowCapture = true; |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 914 | } |
| 915 | } |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 916 | } else if (mUidPolicy->isA11yUid(currentUid)) { |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 917 | // For accessibility service allow capture if: |
Eric Laurent | 47670c9 | 2019-08-28 16:59:05 -0700 | [diff] [blame] | 918 | // The assistant is not on TOP |
| 919 | // AND there is no active privacy sensitive capture or call |
Eric Laurent | 589171c | 2019-07-25 18:04:29 -0700 | [diff] [blame] | 920 | // OR client has CAPTURE_AUDIO_OUTPUT privileged permission |
Eric Laurent | 47670c9 | 2019-08-28 16:59:05 -0700 | [diff] [blame] | 921 | // OR |
| 922 | // Is on TOP AND the source is VOICE_RECOGNITION or HOTWORD |
| 923 | if (!isAssistantOnTop |
Ricardo Correa | 57a3769 | 2020-03-23 17:27:25 -0700 | [diff] [blame] | 924 | && !(isSensitiveActive && !current->canCaptureOutput) |
Eric Laurent | c21d569 | 2020-02-25 10:24:36 -0800 | [diff] [blame] | 925 | && canCaptureIfInCallOrCommunication(current)) { |
Eric Laurent | 47670c9 | 2019-08-28 16:59:05 -0700 | [diff] [blame] | 926 | allowCapture = true; |
| 927 | } |
Eric Laurent | 589171c | 2019-07-25 18:04:29 -0700 | [diff] [blame] | 928 | if (isA11yOnTop) { |
| 929 | if (source == AUDIO_SOURCE_VOICE_RECOGNITION || source == AUDIO_SOURCE_HOTWORD) { |
| 930 | allowCapture = true; |
| 931 | } |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 932 | } |
Eric Laurent | 4e947da | 2019-10-17 15:24:06 -0700 | [diff] [blame] | 933 | } else if (source == AUDIO_SOURCE_HOTWORD) { |
| 934 | // For HOTWORD source allow capture when not on TOP if: |
| 935 | // All active clients are using HOTWORD source |
| 936 | // AND no call is active |
| 937 | // OR client has CAPTURE_AUDIO_OUTPUT privileged permission |
Eric Laurent | c21d569 | 2020-02-25 10:24:36 -0800 | [diff] [blame] | 938 | if (onlyHotwordActive |
| 939 | && canCaptureIfInCallOrCommunication(current)) { |
Eric Laurent | 4e947da | 2019-10-17 15:24:06 -0700 | [diff] [blame] | 940 | allowCapture = true; |
| 941 | } |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 942 | } else if (mUidPolicy->isCurrentImeUid(currentUid)) { |
Kohsuke Yatoh | a623a13 | 2020-03-24 20:10:26 -0700 | [diff] [blame] | 943 | // For current InputMethodService allow capture if: |
| 944 | // A RTT call is active AND the source is VOICE_RECOGNITION |
| 945 | if (rttCallActive && source == AUDIO_SOURCE_VOICE_RECOGNITION) { |
| 946 | allowCapture = true; |
| 947 | } |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 948 | } |
Eric Laurent | 8c7ef89 | 2021-06-10 13:32:16 +0200 | [diff] [blame] | 949 | setAppState_l(current, |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 950 | allowCapture ? apmStatFromAmState(mUidPolicy->getUidState(currentUid)) : |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 951 | APP_STATE_IDLE); |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 952 | } |
| 953 | } |
| 954 | |
Michael Groover | cfd2830 | 2018-12-11 19:16:46 -0800 | [diff] [blame] | 955 | void AudioPolicyService::silenceAllRecordings_l() { |
| 956 | for (size_t i = 0; i < mAudioRecordClients.size(); i++) { |
| 957 | sp<AudioRecordClient> current = mAudioRecordClients[i]; |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 958 | if (!isVirtualSource(current->attributes.source)) { |
Eric Laurent | 8c7ef89 | 2021-06-10 13:32:16 +0200 | [diff] [blame] | 959 | setAppState_l(current, APP_STATE_IDLE); |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 960 | } |
Michael Groover | cfd2830 | 2018-12-11 19:16:46 -0800 | [diff] [blame] | 961 | } |
| 962 | } |
| 963 | |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 964 | /* static */ |
| 965 | app_state_t AudioPolicyService::apmStatFromAmState(int amState) { |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 966 | |
| 967 | if (amState == ActivityManager::PROCESS_STATE_UNKNOWN) { |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 968 | return APP_STATE_IDLE; |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 969 | } else if (amState <= ActivityManager::PROCESS_STATE_TOP) { |
| 970 | // include persistent services |
| 971 | return APP_STATE_TOP; |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 972 | } |
| 973 | return APP_STATE_FOREGROUND; |
| 974 | } |
| 975 | |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 976 | /* static */ |
Eric Laurent | 2dc962b | 2019-03-01 08:25:25 -0800 | [diff] [blame] | 977 | bool AudioPolicyService::isVirtualSource(audio_source_t source) |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 978 | { |
| 979 | switch (source) { |
| 980 | case AUDIO_SOURCE_VOICE_UPLINK: |
| 981 | case AUDIO_SOURCE_VOICE_DOWNLINK: |
| 982 | case AUDIO_SOURCE_VOICE_CALL: |
Eric Laurent | 2dc962b | 2019-03-01 08:25:25 -0800 | [diff] [blame] | 983 | case AUDIO_SOURCE_REMOTE_SUBMIX: |
| 984 | case AUDIO_SOURCE_FM_TUNER: |
Eric Laurent | 68eb212 | 2020-04-30 17:40:57 -0700 | [diff] [blame] | 985 | case AUDIO_SOURCE_ECHO_REFERENCE: |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 986 | return true; |
| 987 | default: |
| 988 | break; |
| 989 | } |
| 990 | return false; |
| 991 | } |
| 992 | |
Eric Laurent | ed726cc | 2021-07-01 14:26:41 +0200 | [diff] [blame] | 993 | /* static */ |
| 994 | bool AudioPolicyService::isAppOpSource(audio_source_t source) |
| 995 | { |
| 996 | switch (source) { |
| 997 | case AUDIO_SOURCE_FM_TUNER: |
| 998 | case AUDIO_SOURCE_ECHO_REFERENCE: |
Eric Laurent | 637bd20 | 2021-09-22 11:17:11 +0200 | [diff] [blame] | 999 | case AUDIO_SOURCE_REMOTE_SUBMIX: |
Eric Laurent | ed726cc | 2021-07-01 14:26:41 +0200 | [diff] [blame] | 1000 | return false; |
| 1001 | default: |
| 1002 | break; |
| 1003 | } |
| 1004 | return true; |
| 1005 | } |
| 1006 | |
Eric Laurent | 8c7ef89 | 2021-06-10 13:32:16 +0200 | [diff] [blame] | 1007 | void AudioPolicyService::setAppState_l(sp<AudioRecordClient> client, app_state_t state) |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1008 | { |
| 1009 | AutoCallerClear acc; |
| 1010 | |
| 1011 | if (mAudioPolicyManager) { |
Eric Laurent | 8c7ef89 | 2021-06-10 13:32:16 +0200 | [diff] [blame] | 1012 | mAudioPolicyManager->setAppState(client->portId, state); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1013 | } |
| 1014 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 1015 | if (af) { |
Eric Laurent | f32108e | 2018-10-04 17:22:04 -0700 | [diff] [blame] | 1016 | bool silenced = state == APP_STATE_IDLE; |
Eric Laurent | 8c7ef89 | 2021-06-10 13:32:16 +0200 | [diff] [blame] | 1017 | if (client->silenced != silenced) { |
| 1018 | if (client->active) { |
| 1019 | if (silenced) { |
| 1020 | finishRecording(client->attributionSource, client->attributes.source); |
| 1021 | } else { |
| 1022 | std::stringstream msg; |
| 1023 | msg << "Audio recording un-silenced on session " << client->session; |
| 1024 | if (!startRecording(client->attributionSource, String16(msg.str().c_str()), |
| 1025 | client->attributes.source)) { |
| 1026 | silenced = true; |
| 1027 | } |
| 1028 | } |
| 1029 | } |
| 1030 | af->setRecordSilenced(client->portId, silenced); |
| 1031 | client->silenced = silenced; |
| 1032 | } |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1033 | } |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1034 | } |
| 1035 | |
Glenn Kasten | 0f11b51 | 2014-01-31 16:18:54 -0800 | [diff] [blame] | 1036 | status_t AudioPolicyService::dump(int fd, const Vector<String16>& args __unused) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1037 | { |
Glenn Kasten | 44deb05 | 2012-02-05 18:09:08 -0800 | [diff] [blame] | 1038 | if (!dumpAllowed()) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1039 | dumpPermissionDenial(fd); |
| 1040 | } else { |
Mikhail Naganov | 12b716c | 2020-04-30 22:37:43 +0000 | [diff] [blame] | 1041 | const bool locked = dumpTryLock(mLock); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1042 | if (!locked) { |
| 1043 | String8 result(kDeadlockedString); |
| 1044 | write(fd, result.string(), result.size()); |
| 1045 | } |
| 1046 | |
| 1047 | dumpInternals(fd); |
Mikhail Naganov | 1b22e54 | 2022-02-25 04:24:49 +0000 | [diff] [blame] | 1048 | |
| 1049 | String8 actPtr = String8::format("AudioCommandThread: %p\n", mAudioCommandThread.get()); |
| 1050 | write(fd, actPtr.string(), actPtr.size()); |
Glenn Kasten | 9d1f02d | 2012-02-08 17:47:58 -0800 | [diff] [blame] | 1051 | if (mAudioCommandThread != 0) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1052 | mAudioCommandThread->dump(fd); |
| 1053 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1054 | |
Mikhail Naganov | 1b22e54 | 2022-02-25 04:24:49 +0000 | [diff] [blame] | 1055 | String8 octPtr = String8::format("OutputCommandThread: %p\n", mOutputCommandThread.get()); |
| 1056 | write(fd, octPtr.string(), octPtr.size()); |
| 1057 | if (mOutputCommandThread != 0) { |
| 1058 | mOutputCommandThread->dump(fd); |
| 1059 | } |
| 1060 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1061 | if (mAudioPolicyManager) { |
| 1062 | mAudioPolicyManager->dump(fd); |
Mikhail Naganov | 1b22e54 | 2022-02-25 04:24:49 +0000 | [diff] [blame] | 1063 | } else { |
| 1064 | String8 apmPtr = String8::format("AudioPolicyManager: %p\n", mAudioPolicyManager); |
| 1065 | write(fd, apmPtr.string(), apmPtr.size()); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1066 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1067 | |
Kevin Rocard | 8be9497 | 2019-02-22 13:26:25 -0800 | [diff] [blame] | 1068 | mPackageManager.dump(fd); |
| 1069 | |
Mikhail Naganov | 12b716c | 2020-04-30 22:37:43 +0000 | [diff] [blame] | 1070 | dumpReleaseLock(mLock, locked); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1071 | } |
| 1072 | return NO_ERROR; |
| 1073 | } |
| 1074 | |
| 1075 | status_t AudioPolicyService::dumpPermissionDenial(int fd) |
| 1076 | { |
| 1077 | const size_t SIZE = 256; |
| 1078 | char buffer[SIZE]; |
| 1079 | String8 result; |
| 1080 | snprintf(buffer, SIZE, "Permission Denial: " |
| 1081 | "can't dump AudioPolicyService from pid=%d, uid=%d\n", |
| 1082 | IPCThreadState::self()->getCallingPid(), |
| 1083 | IPCThreadState::self()->getCallingUid()); |
| 1084 | result.append(buffer); |
| 1085 | write(fd, result.string(), result.size()); |
| 1086 | return NO_ERROR; |
| 1087 | } |
| 1088 | |
| 1089 | status_t AudioPolicyService::onTransact( |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1090 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1091 | // make sure transactions reserved to AudioFlinger do not come from other processes |
| 1092 | switch (code) { |
| 1093 | case TRANSACTION_startOutput: |
| 1094 | case TRANSACTION_stopOutput: |
| 1095 | case TRANSACTION_releaseOutput: |
| 1096 | case TRANSACTION_getInputForAttr: |
| 1097 | case TRANSACTION_startInput: |
| 1098 | case TRANSACTION_stopInput: |
| 1099 | case TRANSACTION_releaseInput: |
| 1100 | case TRANSACTION_getOutputForEffect: |
| 1101 | case TRANSACTION_registerEffect: |
| 1102 | case TRANSACTION_unregisterEffect: |
| 1103 | case TRANSACTION_setEffectEnabled: |
| 1104 | case TRANSACTION_getStrategyForStream: |
| 1105 | case TRANSACTION_getOutputForAttr: |
| 1106 | case TRANSACTION_moveEffectsToIo: |
| 1107 | ALOGW("%s: transaction %d received from PID %d", |
| 1108 | __func__, code, IPCThreadState::self()->getCallingPid()); |
| 1109 | return INVALID_OPERATION; |
| 1110 | default: |
| 1111 | break; |
| 1112 | } |
| 1113 | |
| 1114 | // make sure the following transactions come from system components |
| 1115 | switch (code) { |
| 1116 | case TRANSACTION_setDeviceConnectionState: |
| 1117 | case TRANSACTION_handleDeviceConfigChange: |
| 1118 | case TRANSACTION_setPhoneState: |
| 1119 | //FIXME: Allow setForceUse calls from system apps until a better use case routing API is available |
| 1120 | // case TRANSACTION_setForceUse: |
| 1121 | case TRANSACTION_initStreamVolume: |
| 1122 | case TRANSACTION_setStreamVolumeIndex: |
| 1123 | case TRANSACTION_setVolumeIndexForAttributes: |
| 1124 | case TRANSACTION_getStreamVolumeIndex: |
| 1125 | case TRANSACTION_getVolumeIndexForAttributes: |
| 1126 | case TRANSACTION_getMinVolumeIndexForAttributes: |
| 1127 | case TRANSACTION_getMaxVolumeIndexForAttributes: |
| 1128 | case TRANSACTION_isStreamActive: |
| 1129 | case TRANSACTION_isStreamActiveRemotely: |
| 1130 | case TRANSACTION_isSourceActive: |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1131 | case TRANSACTION_registerPolicyMixes: |
| 1132 | case TRANSACTION_setMasterMono: |
| 1133 | case TRANSACTION_getSurroundFormats: |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1134 | case TRANSACTION_getReportedSurroundFormats: |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1135 | case TRANSACTION_setSurroundFormatEnabled: |
Oscar Azucena | 829d90d | 2022-01-28 17:17:56 -0800 | [diff] [blame] | 1136 | case TRANSACTION_setAssistantServicesUids: |
Oscar Azucena | c2cdda3 | 2022-01-31 19:10:39 -0800 | [diff] [blame] | 1137 | case TRANSACTION_setActiveAssistantServicesUids: |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1138 | case TRANSACTION_setA11yServicesUids: |
| 1139 | case TRANSACTION_setUidDeviceAffinities: |
| 1140 | case TRANSACTION_removeUidDeviceAffinities: |
| 1141 | case TRANSACTION_setUserIdDeviceAffinities: |
| 1142 | case TRANSACTION_removeUserIdDeviceAffinities: |
Patty | dd80758 | 2021-11-04 21:01:03 +0800 | [diff] [blame] | 1143 | case TRANSACTION_getHwOffloadFormatsSupportedForBluetoothMedia: |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1144 | case TRANSACTION_listAudioVolumeGroups: |
| 1145 | case TRANSACTION_getVolumeGroupFromAudioAttributes: |
| 1146 | case TRANSACTION_acquireSoundTriggerSession: |
| 1147 | case TRANSACTION_releaseSoundTriggerSession: |
| 1148 | case TRANSACTION_setRttEnabled: |
| 1149 | case TRANSACTION_isCallScreenModeSupported: |
| 1150 | case TRANSACTION_setDevicesRoleForStrategy: |
| 1151 | case TRANSACTION_setSupportedSystemUsages: |
| 1152 | case TRANSACTION_removeDevicesRoleForStrategy: |
| 1153 | case TRANSACTION_getDevicesForRoleAndStrategy: |
| 1154 | case TRANSACTION_getDevicesForAttributes: |
| 1155 | case TRANSACTION_setAllowedCapturePolicy: |
| 1156 | case TRANSACTION_onNewAudioModulesAvailable: |
| 1157 | case TRANSACTION_setCurrentImeUid: |
| 1158 | case TRANSACTION_registerSoundTriggerCaptureStateListener: |
| 1159 | case TRANSACTION_setDevicesRoleForCapturePreset: |
| 1160 | case TRANSACTION_addDevicesRoleForCapturePreset: |
| 1161 | case TRANSACTION_removeDevicesRoleForCapturePreset: |
| 1162 | case TRANSACTION_clearDevicesRoleForCapturePreset: |
Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 1163 | case TRANSACTION_getDevicesForRoleAndCapturePreset: |
| 1164 | case TRANSACTION_getSpatializer: { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1165 | if (!isServiceUid(IPCThreadState::self()->getCallingUid())) { |
| 1166 | ALOGW("%s: transaction %d received from PID %d unauthorized UID %d", |
| 1167 | __func__, code, IPCThreadState::self()->getCallingPid(), |
| 1168 | IPCThreadState::self()->getCallingUid()); |
| 1169 | return INVALID_OPERATION; |
| 1170 | } |
| 1171 | } break; |
| 1172 | default: |
| 1173 | break; |
| 1174 | } |
| 1175 | |
| 1176 | std::string tag("IAudioPolicyService command " + std::to_string(code)); |
Andy Hung | 5c6d68a | 2022-03-09 21:54:59 -0800 | [diff] [blame^] | 1177 | mediautils::TimeCheck check(tag.c_str()); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1178 | |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1179 | switch (code) { |
| 1180 | case SHELL_COMMAND_TRANSACTION: { |
| 1181 | int in = data.readFileDescriptor(); |
| 1182 | int out = data.readFileDescriptor(); |
| 1183 | int err = data.readFileDescriptor(); |
| 1184 | int argc = data.readInt32(); |
| 1185 | Vector<String16> args; |
| 1186 | for (int i = 0; i < argc && data.dataAvail() > 0; i++) { |
| 1187 | args.add(data.readString16()); |
| 1188 | } |
| 1189 | sp<IBinder> unusedCallback; |
| 1190 | sp<IResultReceiver> resultReceiver; |
| 1191 | status_t status; |
| 1192 | if ((status = data.readNullableStrongBinder(&unusedCallback)) != NO_ERROR) { |
| 1193 | return status; |
| 1194 | } |
| 1195 | if ((status = data.readNullableStrongBinder(&resultReceiver)) != NO_ERROR) { |
| 1196 | return status; |
| 1197 | } |
| 1198 | status = shellCommand(in, out, err, args); |
| 1199 | if (resultReceiver != nullptr) { |
| 1200 | resultReceiver->send(status); |
| 1201 | } |
| 1202 | return NO_ERROR; |
| 1203 | } |
| 1204 | } |
| 1205 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1206 | return BnAudioPolicyService::onTransact(code, data, reply, flags); |
| 1207 | } |
| 1208 | |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1209 | // ------------------- Shell command implementation ------------------- |
| 1210 | |
| 1211 | // NOTE: This is a remote API - make sure all args are validated |
| 1212 | status_t AudioPolicyService::shellCommand(int in, int out, int err, Vector<String16>& args) { |
| 1213 | if (!checkCallingPermission(sManageAudioPolicyPermission, nullptr, nullptr)) { |
| 1214 | return PERMISSION_DENIED; |
| 1215 | } |
| 1216 | if (in == BAD_TYPE || out == BAD_TYPE || err == BAD_TYPE) { |
| 1217 | return BAD_VALUE; |
| 1218 | } |
jovanak | be066e1 | 2019-09-02 11:54:39 -0700 | [diff] [blame] | 1219 | if (args.size() >= 3 && args[0] == String16("set-uid-state")) { |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1220 | return handleSetUidState(args, err); |
jovanak | be066e1 | 2019-09-02 11:54:39 -0700 | [diff] [blame] | 1221 | } else if (args.size() >= 2 && args[0] == String16("reset-uid-state")) { |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1222 | return handleResetUidState(args, err); |
jovanak | be066e1 | 2019-09-02 11:54:39 -0700 | [diff] [blame] | 1223 | } else if (args.size() >= 2 && args[0] == String16("get-uid-state")) { |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1224 | return handleGetUidState(args, out, err); |
Eric Laurent | 269acb4 | 2021-04-23 16:53:22 +0200 | [diff] [blame] | 1225 | } else if (args.size() >= 1 && args[0] == String16("purge_permission-cache")) { |
| 1226 | purgePermissionCache(); |
| 1227 | return NO_ERROR; |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1228 | } else if (args.size() == 1 && args[0] == String16("help")) { |
| 1229 | printHelp(out); |
| 1230 | return NO_ERROR; |
| 1231 | } |
| 1232 | printHelp(err); |
| 1233 | return BAD_VALUE; |
| 1234 | } |
| 1235 | |
jovanak | be066e1 | 2019-09-02 11:54:39 -0700 | [diff] [blame] | 1236 | static status_t getUidForPackage(String16 packageName, int userId, /*inout*/uid_t& uid, int err) { |
| 1237 | if (userId < 0) { |
| 1238 | ALOGE("Invalid user: %d", userId); |
| 1239 | dprintf(err, "Invalid user: %d\n", userId); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1240 | return BAD_VALUE; |
| 1241 | } |
jovanak | be066e1 | 2019-09-02 11:54:39 -0700 | [diff] [blame] | 1242 | |
| 1243 | PermissionController pc; |
| 1244 | uid = pc.getPackageUid(packageName, 0); |
| 1245 | if (uid <= 0) { |
| 1246 | ALOGE("Unknown package: '%s'", String8(packageName).string()); |
| 1247 | dprintf(err, "Unknown package: '%s'\n", String8(packageName).string()); |
| 1248 | return BAD_VALUE; |
| 1249 | } |
| 1250 | |
| 1251 | uid = multiuser_get_uid(userId, uid); |
| 1252 | return NO_ERROR; |
| 1253 | } |
| 1254 | |
| 1255 | status_t AudioPolicyService::handleSetUidState(Vector<String16>& args, int err) { |
| 1256 | // Valid arg.size() is 3 or 5, args.size() is 5 with --user option. |
| 1257 | if (!(args.size() == 3 || args.size() == 5)) { |
| 1258 | printHelp(err); |
| 1259 | return BAD_VALUE; |
| 1260 | } |
| 1261 | |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1262 | bool active = false; |
| 1263 | if (args[2] == String16("active")) { |
| 1264 | active = true; |
| 1265 | } else if ((args[2] != String16("idle"))) { |
| 1266 | ALOGE("Expected active or idle but got: '%s'", String8(args[2]).string()); |
| 1267 | return BAD_VALUE; |
| 1268 | } |
jovanak | be066e1 | 2019-09-02 11:54:39 -0700 | [diff] [blame] | 1269 | |
| 1270 | int userId = 0; |
| 1271 | if (args.size() >= 5 && args[3] == String16("--user")) { |
| 1272 | userId = atoi(String8(args[4])); |
| 1273 | } |
| 1274 | |
| 1275 | uid_t uid; |
| 1276 | if (getUidForPackage(args[1], userId, uid, err) == BAD_VALUE) { |
| 1277 | return BAD_VALUE; |
| 1278 | } |
| 1279 | |
Mikhail Naganov | 12b716c | 2020-04-30 22:37:43 +0000 | [diff] [blame] | 1280 | sp<UidPolicy> uidPolicy; |
| 1281 | { |
| 1282 | Mutex::Autolock _l(mLock); |
| 1283 | uidPolicy = mUidPolicy; |
| 1284 | } |
| 1285 | if (uidPolicy) { |
| 1286 | uidPolicy->addOverrideUid(uid, active); |
| 1287 | return NO_ERROR; |
| 1288 | } |
| 1289 | return NO_INIT; |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | status_t AudioPolicyService::handleResetUidState(Vector<String16>& args, int err) { |
jovanak | be066e1 | 2019-09-02 11:54:39 -0700 | [diff] [blame] | 1293 | // Valid arg.size() is 2 or 4, args.size() is 4 with --user option. |
| 1294 | if (!(args.size() == 2 || args.size() == 4)) { |
| 1295 | printHelp(err); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1296 | return BAD_VALUE; |
| 1297 | } |
jovanak | be066e1 | 2019-09-02 11:54:39 -0700 | [diff] [blame] | 1298 | |
| 1299 | int userId = 0; |
| 1300 | if (args.size() >= 4 && args[2] == String16("--user")) { |
| 1301 | userId = atoi(String8(args[3])); |
| 1302 | } |
| 1303 | |
| 1304 | uid_t uid; |
| 1305 | if (getUidForPackage(args[1], userId, uid, err) == BAD_VALUE) { |
| 1306 | return BAD_VALUE; |
| 1307 | } |
| 1308 | |
Mikhail Naganov | 12b716c | 2020-04-30 22:37:43 +0000 | [diff] [blame] | 1309 | sp<UidPolicy> uidPolicy; |
| 1310 | { |
| 1311 | Mutex::Autolock _l(mLock); |
| 1312 | uidPolicy = mUidPolicy; |
| 1313 | } |
| 1314 | if (uidPolicy) { |
| 1315 | uidPolicy->removeOverrideUid(uid); |
| 1316 | return NO_ERROR; |
| 1317 | } |
| 1318 | return NO_INIT; |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | status_t AudioPolicyService::handleGetUidState(Vector<String16>& args, int out, int err) { |
jovanak | be066e1 | 2019-09-02 11:54:39 -0700 | [diff] [blame] | 1322 | // Valid arg.size() is 2 or 4, args.size() is 4 with --user option. |
| 1323 | if (!(args.size() == 2 || args.size() == 4)) { |
| 1324 | printHelp(err); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1325 | return BAD_VALUE; |
| 1326 | } |
jovanak | be066e1 | 2019-09-02 11:54:39 -0700 | [diff] [blame] | 1327 | |
| 1328 | int userId = 0; |
| 1329 | if (args.size() >= 4 && args[2] == String16("--user")) { |
| 1330 | userId = atoi(String8(args[3])); |
| 1331 | } |
| 1332 | |
| 1333 | uid_t uid; |
| 1334 | if (getUidForPackage(args[1], userId, uid, err) == BAD_VALUE) { |
| 1335 | return BAD_VALUE; |
| 1336 | } |
| 1337 | |
Mikhail Naganov | 12b716c | 2020-04-30 22:37:43 +0000 | [diff] [blame] | 1338 | sp<UidPolicy> uidPolicy; |
| 1339 | { |
| 1340 | Mutex::Autolock _l(mLock); |
| 1341 | uidPolicy = mUidPolicy; |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1342 | } |
Mikhail Naganov | 12b716c | 2020-04-30 22:37:43 +0000 | [diff] [blame] | 1343 | if (uidPolicy) { |
| 1344 | return dprintf(out, uidPolicy->isUidActive(uid) ? "active\n" : "idle\n"); |
| 1345 | } |
| 1346 | return NO_INIT; |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | status_t AudioPolicyService::printHelp(int out) { |
| 1350 | return dprintf(out, "Audio policy service commands:\n" |
jovanak | be066e1 | 2019-09-02 11:54:39 -0700 | [diff] [blame] | 1351 | " get-uid-state <PACKAGE> [--user USER_ID] gets the uid state\n" |
| 1352 | " set-uid-state <PACKAGE> <active|idle> [--user USER_ID] overrides the uid state\n" |
| 1353 | " 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] | 1354 | " help print this message\n"); |
| 1355 | } |
| 1356 | |
| 1357 | // ----------- AudioPolicyService::UidPolicy implementation ---------- |
| 1358 | |
| 1359 | void AudioPolicyService::UidPolicy::registerSelf() { |
Steven Moreland | 2f34814 | 2019-07-02 15:59:07 -0700 | [diff] [blame] | 1360 | status_t res = mAm.linkToDeath(this); |
| 1361 | mAm.registerUidObserver(this, ActivityManager::UID_OBSERVER_GONE |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1362 | | ActivityManager::UID_OBSERVER_IDLE |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1363 | | ActivityManager::UID_OBSERVER_ACTIVE |
| 1364 | | ActivityManager::UID_OBSERVER_PROCSTATE, |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1365 | ActivityManager::PROCESS_STATE_UNKNOWN, |
| 1366 | String16("audioserver")); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1367 | if (!res) { |
| 1368 | Mutex::Autolock _l(mLock); |
| 1369 | mObserverRegistered = true; |
| 1370 | } else { |
| 1371 | ALOGE("UidPolicy::registerSelf linkToDeath failed: %d", res); |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 1372 | |
Steven Moreland | 2f34814 | 2019-07-02 15:59:07 -0700 | [diff] [blame] | 1373 | mAm.unregisterUidObserver(this); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1374 | } |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | void AudioPolicyService::UidPolicy::unregisterSelf() { |
Steven Moreland | 2f34814 | 2019-07-02 15:59:07 -0700 | [diff] [blame] | 1378 | mAm.unlinkToDeath(this); |
| 1379 | mAm.unregisterUidObserver(this); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1380 | Mutex::Autolock _l(mLock); |
| 1381 | mObserverRegistered = false; |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1382 | } |
| 1383 | |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1384 | void AudioPolicyService::UidPolicy::binderDied(__unused const wp<IBinder> &who) { |
| 1385 | Mutex::Autolock _l(mLock); |
| 1386 | mCachedUids.clear(); |
| 1387 | mObserverRegistered = false; |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1388 | } |
| 1389 | |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1390 | void AudioPolicyService::UidPolicy::checkRegistered() { |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1391 | bool needToReregister = false; |
| 1392 | { |
| 1393 | Mutex::Autolock _l(mLock); |
| 1394 | needToReregister = !mObserverRegistered; |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1395 | } |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1396 | if (needToReregister) { |
| 1397 | // Looks like ActivityManager has died previously, attempt to re-register. |
| 1398 | registerSelf(); |
| 1399 | } |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | bool AudioPolicyService::UidPolicy::isUidActive(uid_t uid) { |
| 1403 | if (isServiceUid(uid)) return true; |
| 1404 | checkRegistered(); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1405 | { |
| 1406 | Mutex::Autolock _l(mLock); |
| 1407 | auto overrideIter = mOverrideUids.find(uid); |
| 1408 | if (overrideIter != mOverrideUids.end()) { |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1409 | return overrideIter->second.first; |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1410 | } |
| 1411 | // In an absense of the ActivityManager, assume everything to be active. |
| 1412 | if (!mObserverRegistered) return true; |
| 1413 | auto cacheIter = mCachedUids.find(uid); |
Mikhail Naganov | eba668a | 2018-04-05 08:13:15 -0700 | [diff] [blame] | 1414 | if (cacheIter != mCachedUids.end()) { |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1415 | return cacheIter->second.first; |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1416 | } |
| 1417 | } |
| 1418 | ActivityManager am; |
Hui Yu | 12c7ec7 | 2020-05-04 17:40:52 +0000 | [diff] [blame] | 1419 | bool active = am.isUidActive(uid, String16("audioserver")); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1420 | { |
| 1421 | Mutex::Autolock _l(mLock); |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1422 | mCachedUids.insert(std::pair<uid_t, |
| 1423 | std::pair<bool, int>>(uid, std::pair<bool, int>(active, |
| 1424 | ActivityManager::PROCESS_STATE_UNKNOWN))); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1425 | } |
| 1426 | return active; |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1427 | } |
| 1428 | |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1429 | int AudioPolicyService::UidPolicy::getUidState(uid_t uid) { |
| 1430 | if (isServiceUid(uid)) { |
| 1431 | return ActivityManager::PROCESS_STATE_TOP; |
| 1432 | } |
| 1433 | checkRegistered(); |
| 1434 | { |
| 1435 | Mutex::Autolock _l(mLock); |
| 1436 | auto overrideIter = mOverrideUids.find(uid); |
| 1437 | if (overrideIter != mOverrideUids.end()) { |
| 1438 | if (overrideIter->second.first) { |
| 1439 | if (overrideIter->second.second != ActivityManager::PROCESS_STATE_UNKNOWN) { |
| 1440 | return overrideIter->second.second; |
| 1441 | } else { |
| 1442 | auto cacheIter = mCachedUids.find(uid); |
| 1443 | if (cacheIter != mCachedUids.end()) { |
| 1444 | return cacheIter->second.second; |
| 1445 | } |
| 1446 | } |
| 1447 | } |
| 1448 | return ActivityManager::PROCESS_STATE_UNKNOWN; |
| 1449 | } |
| 1450 | // In an absense of the ActivityManager, assume everything to be active. |
| 1451 | if (!mObserverRegistered) { |
| 1452 | return ActivityManager::PROCESS_STATE_TOP; |
| 1453 | } |
| 1454 | auto cacheIter = mCachedUids.find(uid); |
| 1455 | if (cacheIter != mCachedUids.end()) { |
| 1456 | if (cacheIter->second.first) { |
| 1457 | return cacheIter->second.second; |
| 1458 | } else { |
| 1459 | return ActivityManager::PROCESS_STATE_UNKNOWN; |
| 1460 | } |
| 1461 | } |
| 1462 | } |
| 1463 | ActivityManager am; |
Hui Yu | 12c7ec7 | 2020-05-04 17:40:52 +0000 | [diff] [blame] | 1464 | bool active = am.isUidActive(uid, String16("audioserver")); |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1465 | int state = ActivityManager::PROCESS_STATE_UNKNOWN; |
| 1466 | if (active) { |
| 1467 | state = am.getUidProcessState(uid, String16("audioserver")); |
| 1468 | } |
| 1469 | { |
| 1470 | Mutex::Autolock _l(mLock); |
| 1471 | mCachedUids.insert(std::pair<uid_t, |
| 1472 | std::pair<bool, int>>(uid, std::pair<bool, int>(active, state))); |
| 1473 | } |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 1474 | |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1475 | return state; |
| 1476 | } |
| 1477 | |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1478 | void AudioPolicyService::UidPolicy::onUidActive(uid_t uid) { |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1479 | updateUid(&mCachedUids, uid, true, ActivityManager::PROCESS_STATE_UNKNOWN, true); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | void AudioPolicyService::UidPolicy::onUidGone(uid_t uid, __unused bool disabled) { |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1483 | updateUid(&mCachedUids, uid, false, ActivityManager::PROCESS_STATE_UNKNOWN, false); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | void AudioPolicyService::UidPolicy::onUidIdle(uid_t uid, __unused bool disabled) { |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1487 | updateUid(&mCachedUids, uid, false, ActivityManager::PROCESS_STATE_UNKNOWN, true); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1490 | void AudioPolicyService::UidPolicy::onUidStateChanged(uid_t uid, |
| 1491 | int32_t procState, |
Hui Yu | 13ad0eb | 2019-09-09 10:27:07 -0700 | [diff] [blame] | 1492 | int64_t procStateSeq __unused, |
| 1493 | int32_t capability __unused) { |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1494 | if (procState != ActivityManager::PROCESS_STATE_UNKNOWN) { |
| 1495 | updateUid(&mCachedUids, uid, true, procState, true); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1496 | } |
| 1497 | } |
| 1498 | |
| 1499 | void AudioPolicyService::UidPolicy::updateOverrideUid(uid_t uid, bool active, bool insert) { |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1500 | updateUid(&mOverrideUids, uid, active, ActivityManager::PROCESS_STATE_UNKNOWN, insert); |
| 1501 | } |
| 1502 | |
| 1503 | void AudioPolicyService::UidPolicy::notifyService() { |
| 1504 | sp<AudioPolicyService> service = mService.promote(); |
| 1505 | if (service != nullptr) { |
| 1506 | service->updateUidStates(); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1507 | } |
| 1508 | } |
| 1509 | |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1510 | void AudioPolicyService::UidPolicy::updateUid(std::unordered_map<uid_t, |
| 1511 | std::pair<bool, int>> *uids, |
| 1512 | uid_t uid, |
| 1513 | bool active, |
| 1514 | int state, |
| 1515 | bool insert) { |
| 1516 | if (isServiceUid(uid)) { |
| 1517 | return; |
| 1518 | } |
| 1519 | bool wasActive = isUidActive(uid); |
| 1520 | int previousState = getUidState(uid); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1521 | { |
| 1522 | Mutex::Autolock _l(mLock); |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1523 | updateUidLocked(uids, uid, active, state, insert); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1524 | } |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1525 | if (wasActive != isUidActive(uid) || state != previousState) { |
| 1526 | notifyService(); |
| 1527 | } |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1528 | } |
| 1529 | |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1530 | void AudioPolicyService::UidPolicy::updateUidLocked(std::unordered_map<uid_t, |
| 1531 | std::pair<bool, int>> *uids, |
| 1532 | uid_t uid, |
| 1533 | bool active, |
| 1534 | int state, |
| 1535 | bool insert) { |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1536 | auto it = uids->find(uid); |
| 1537 | if (it != uids->end()) { |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1538 | if (insert) { |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1539 | if (state == ActivityManager::PROCESS_STATE_UNKNOWN) { |
| 1540 | it->second.first = active; |
| 1541 | } |
| 1542 | if (it->second.first) { |
| 1543 | it->second.second = state; |
| 1544 | } else { |
| 1545 | it->second.second = ActivityManager::PROCESS_STATE_UNKNOWN; |
| 1546 | } |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1547 | } else { |
| 1548 | uids->erase(it); |
| 1549 | } |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1550 | } else if (insert && (state == ActivityManager::PROCESS_STATE_UNKNOWN)) { |
| 1551 | uids->insert(std::pair<uid_t, std::pair<bool, int>>(uid, |
| 1552 | std::pair<bool, int>(active, state))); |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 1553 | } |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1554 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1555 | |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 1556 | bool AudioPolicyService::UidPolicy::isA11yOnTop() { |
| 1557 | for (const auto &uid : mCachedUids) { |
Eric Laurent | 47670c9 | 2019-08-28 16:59:05 -0700 | [diff] [blame] | 1558 | if (!isA11yUid(uid.first)) { |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 1559 | continue; |
| 1560 | } |
Amith Yamasani | bcbb300 | 2019-01-23 13:53:33 -0800 | [diff] [blame] | 1561 | if (uid.second.second >= ActivityManager::PROCESS_STATE_TOP |
| 1562 | && uid.second.second <= ActivityManager::PROCESS_STATE_BOUND_FOREGROUND_SERVICE) { |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 1563 | return true; |
| 1564 | } |
| 1565 | } |
| 1566 | return false; |
| 1567 | } |
| 1568 | |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1569 | bool AudioPolicyService::UidPolicy::isA11yUid(uid_t uid) |
| 1570 | { |
| 1571 | std::vector<uid_t>::iterator it = find(mA11yUids.begin(), mA11yUids.end(), uid); |
| 1572 | return it != mA11yUids.end(); |
| 1573 | } |
| 1574 | |
Oscar Azucena | 829d90d | 2022-01-28 17:17:56 -0800 | [diff] [blame] | 1575 | void AudioPolicyService::UidPolicy::setAssistantUids(const std::vector<uid_t>& uids) { |
| 1576 | mAssistantUids.clear(); |
| 1577 | mAssistantUids = uids; |
| 1578 | } |
| 1579 | |
| 1580 | bool AudioPolicyService::UidPolicy::isAssistantUid(uid_t uid) |
| 1581 | { |
| 1582 | std::vector<uid_t>::iterator it = find(mAssistantUids.begin(), mAssistantUids.end(), uid); |
| 1583 | return it != mAssistantUids.end(); |
| 1584 | } |
| 1585 | |
Oscar Azucena | c2cdda3 | 2022-01-31 19:10:39 -0800 | [diff] [blame] | 1586 | void AudioPolicyService::UidPolicy::setActiveAssistantUids(const std::vector<uid_t>& activeUids) { |
| 1587 | mActiveAssistantUids = activeUids; |
| 1588 | } |
| 1589 | |
| 1590 | bool AudioPolicyService::UidPolicy::isActiveAssistantUid(uid_t uid) |
| 1591 | { |
| 1592 | std::vector<uid_t>::iterator it = find(mActiveAssistantUids.begin(), |
| 1593 | mActiveAssistantUids.end(), uid); |
| 1594 | return it != mActiveAssistantUids.end(); |
| 1595 | } |
| 1596 | |
Oscar Azucena | 829d90d | 2022-01-28 17:17:56 -0800 | [diff] [blame] | 1597 | void AudioPolicyService::UidPolicy::dumpInternals(int fd) { |
| 1598 | const size_t SIZE = 256; |
| 1599 | char buffer[SIZE]; |
| 1600 | String8 result; |
| 1601 | auto appendUidsToResult = [&](const char* title, const std::vector<uid_t> &uids) { |
| 1602 | snprintf(buffer, SIZE, "\t%s: \n", title); |
| 1603 | result.append(buffer); |
| 1604 | int counter = 0; |
| 1605 | if (uids.empty()) { |
| 1606 | snprintf(buffer, SIZE, "\t\tNo UIDs present.\n"); |
| 1607 | result.append(buffer); |
| 1608 | return; |
| 1609 | } |
| 1610 | for (const auto &uid : uids) { |
| 1611 | snprintf(buffer, SIZE, "\t\tUID[%d]=%d\n", counter++, uid); |
| 1612 | result.append(buffer); |
| 1613 | } |
| 1614 | }; |
| 1615 | |
| 1616 | snprintf(buffer, SIZE, "UID Policy:\n"); |
| 1617 | result.append(buffer); |
| 1618 | snprintf(buffer, SIZE, "\tmObserverRegistered=%s\n",(mObserverRegistered ? "True":"False")); |
| 1619 | result.append(buffer); |
| 1620 | |
| 1621 | appendUidsToResult("Assistants UIDs", mAssistantUids); |
Oscar Azucena | c2cdda3 | 2022-01-31 19:10:39 -0800 | [diff] [blame] | 1622 | appendUidsToResult("Active Assistants UIDs", mActiveAssistantUids); |
Oscar Azucena | 829d90d | 2022-01-28 17:17:56 -0800 | [diff] [blame] | 1623 | |
| 1624 | appendUidsToResult("Accessibility UIDs", mA11yUids); |
| 1625 | |
| 1626 | snprintf(buffer, SIZE, "\tInput Method Service UID=%d\n", mCurrentImeUid); |
| 1627 | result.append(buffer); |
| 1628 | |
| 1629 | snprintf(buffer, SIZE, "\tIs RTT Enabled: %s\n", (mRttEnabled ? "True":"False")); |
| 1630 | result.append(buffer); |
| 1631 | |
| 1632 | write(fd, result.string(), result.size()); |
| 1633 | } |
| 1634 | |
Michael Groover | cfd2830 | 2018-12-11 19:16:46 -0800 | [diff] [blame] | 1635 | // ----------- AudioPolicyService::SensorPrivacyService implementation ---------- |
| 1636 | void AudioPolicyService::SensorPrivacyPolicy::registerSelf() { |
| 1637 | SensorPrivacyManager spm; |
| 1638 | mSensorPrivacyEnabled = spm.isSensorPrivacyEnabled(); |
| 1639 | spm.addSensorPrivacyListener(this); |
| 1640 | } |
| 1641 | |
| 1642 | void AudioPolicyService::SensorPrivacyPolicy::unregisterSelf() { |
| 1643 | SensorPrivacyManager spm; |
| 1644 | spm.removeSensorPrivacyListener(this); |
| 1645 | } |
| 1646 | |
| 1647 | bool AudioPolicyService::SensorPrivacyPolicy::isSensorPrivacyEnabled() { |
| 1648 | return mSensorPrivacyEnabled; |
| 1649 | } |
| 1650 | |
Evan Severson | d8dc683 | 2022-01-27 10:47:03 -0800 | [diff] [blame] | 1651 | binder::Status AudioPolicyService::SensorPrivacyPolicy::onSensorPrivacyChanged( |
| 1652 | int toggleType __unused, int sensor __unused, bool enabled) { |
Michael Groover | cfd2830 | 2018-12-11 19:16:46 -0800 | [diff] [blame] | 1653 | mSensorPrivacyEnabled = enabled; |
| 1654 | sp<AudioPolicyService> service = mService.promote(); |
| 1655 | if (service != nullptr) { |
| 1656 | service->updateUidStates(); |
| 1657 | } |
| 1658 | return binder::Status::ok(); |
| 1659 | } |
| 1660 | |
Eric Laurent | ed726cc | 2021-07-01 14:26:41 +0200 | [diff] [blame] | 1661 | // ----------- AudioPolicyService::OpRecordAudioMonitor implementation ---------- |
| 1662 | |
| 1663 | // static |
| 1664 | sp<AudioPolicyService::OpRecordAudioMonitor> |
| 1665 | AudioPolicyService::OpRecordAudioMonitor::createIfNeeded( |
| 1666 | const AttributionSourceState& attributionSource, const audio_attributes_t& attr, |
| 1667 | wp<AudioCommandThread> commandThread) |
| 1668 | { |
Eric Laurent | 987ce10 | 2021-07-05 12:11:51 +0200 | [diff] [blame] | 1669 | if (isAudioServerOrRootUid(attributionSource.uid)) { |
| 1670 | ALOGV("not silencing record for audio or root source %s", |
Eric Laurent | ed726cc | 2021-07-01 14:26:41 +0200 | [diff] [blame] | 1671 | attributionSource.toString().c_str()); |
| 1672 | return nullptr; |
| 1673 | } |
| 1674 | |
| 1675 | if (!AudioPolicyService::isAppOpSource(attr.source)) { |
| 1676 | ALOGD("not monitoring app op for uid %d and source %d", |
| 1677 | attributionSource.uid, attr.source); |
| 1678 | return nullptr; |
| 1679 | } |
| 1680 | |
| 1681 | if (!attributionSource.packageName.has_value() |
| 1682 | || attributionSource.packageName.value().size() == 0) { |
| 1683 | return nullptr; |
| 1684 | } |
| 1685 | return new OpRecordAudioMonitor(attributionSource, getOpForSource(attr.source), commandThread); |
| 1686 | } |
| 1687 | |
| 1688 | AudioPolicyService::OpRecordAudioMonitor::OpRecordAudioMonitor( |
| 1689 | const AttributionSourceState& attributionSource, int32_t appOp, |
| 1690 | wp<AudioCommandThread> commandThread) : |
| 1691 | mHasOp(true), mAttributionSource(attributionSource), mAppOp(appOp), |
| 1692 | mCommandThread(commandThread) |
| 1693 | { |
| 1694 | } |
| 1695 | |
| 1696 | AudioPolicyService::OpRecordAudioMonitor::~OpRecordAudioMonitor() |
| 1697 | { |
| 1698 | if (mOpCallback != 0) { |
| 1699 | mAppOpsManager.stopWatchingMode(mOpCallback); |
| 1700 | } |
| 1701 | mOpCallback.clear(); |
| 1702 | } |
| 1703 | |
| 1704 | void AudioPolicyService::OpRecordAudioMonitor::onFirstRef() |
| 1705 | { |
| 1706 | checkOp(); |
| 1707 | mOpCallback = new RecordAudioOpCallback(this); |
| 1708 | ALOGV("start watching op %d for %s", mAppOp, mAttributionSource.toString().c_str()); |
| 1709 | // TODO: We need to always watch AppOpsManager::OP_RECORD_AUDIO too |
| 1710 | // since it controls the mic permission for legacy apps. |
| 1711 | mAppOpsManager.startWatchingMode(mAppOp, VALUE_OR_FATAL(aidl2legacy_string_view_String16( |
| 1712 | mAttributionSource.packageName.value_or(""))), |
| 1713 | mOpCallback); |
| 1714 | } |
| 1715 | |
| 1716 | bool AudioPolicyService::OpRecordAudioMonitor::hasOp() const { |
| 1717 | return mHasOp.load(); |
| 1718 | } |
| 1719 | |
| 1720 | // Called by RecordAudioOpCallback when the app op corresponding to this OpRecordAudioMonitor |
| 1721 | // is updated in AppOp callback and in onFirstRef() |
| 1722 | // Note this method is never called (and never to be) for audio server / root track |
| 1723 | // due to the UID in createIfNeeded(). As a result for those record track, it's: |
| 1724 | // - not called from constructor, |
| 1725 | // - not called from RecordAudioOpCallback because the callback is not installed in this case |
| 1726 | void AudioPolicyService::OpRecordAudioMonitor::checkOp(bool updateUidStates) |
| 1727 | { |
| 1728 | // TODO: We need to always check AppOpsManager::OP_RECORD_AUDIO too |
| 1729 | // since it controls the mic permission for legacy apps. |
| 1730 | const int32_t mode = mAppOpsManager.checkOp(mAppOp, |
| 1731 | mAttributionSource.uid, VALUE_OR_FATAL(aidl2legacy_string_view_String16( |
| 1732 | mAttributionSource.packageName.value_or("")))); |
| 1733 | const bool hasIt = (mode == AppOpsManager::MODE_ALLOWED); |
| 1734 | // verbose logging only log when appOp changed |
| 1735 | ALOGI_IF(hasIt != mHasOp.load(), |
| 1736 | "App op %d missing, %ssilencing record %s", |
| 1737 | mAppOp, hasIt ? "un" : "", mAttributionSource.toString().c_str()); |
| 1738 | mHasOp.store(hasIt); |
| 1739 | |
| 1740 | if (updateUidStates) { |
| 1741 | sp<AudioCommandThread> commandThread = mCommandThread.promote(); |
| 1742 | if (commandThread != nullptr) { |
| 1743 | commandThread->updateUidStatesCommand(); |
| 1744 | } |
| 1745 | } |
| 1746 | } |
| 1747 | |
| 1748 | AudioPolicyService::OpRecordAudioMonitor::RecordAudioOpCallback::RecordAudioOpCallback( |
| 1749 | const wp<OpRecordAudioMonitor>& monitor) : mMonitor(monitor) |
| 1750 | { } |
| 1751 | |
| 1752 | void AudioPolicyService::OpRecordAudioMonitor::RecordAudioOpCallback::opChanged(int32_t op, |
| 1753 | const String16& packageName __unused) { |
| 1754 | sp<OpRecordAudioMonitor> monitor = mMonitor.promote(); |
| 1755 | if (monitor != NULL) { |
| 1756 | if (op != monitor->getOp()) { |
| 1757 | return; |
| 1758 | } |
| 1759 | monitor->checkOp(true); |
| 1760 | } |
| 1761 | } |
| 1762 | |
| 1763 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1764 | // ----------- AudioPolicyService::AudioCommandThread implementation ---------- |
| 1765 | |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1766 | AudioPolicyService::AudioCommandThread::AudioCommandThread(String8 name, |
| 1767 | const wp<AudioPolicyService>& service) |
| 1768 | : Thread(false), mName(name), mService(service) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1769 | { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | |
| 1773 | AudioPolicyService::AudioCommandThread::~AudioCommandThread() |
| 1774 | { |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1775 | if (!mAudioCommands.isEmpty()) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1776 | release_wake_lock(mName.string()); |
| 1777 | } |
| 1778 | mAudioCommands.clear(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | void AudioPolicyService::AudioCommandThread::onFirstRef() |
| 1782 | { |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1783 | run(mName.string(), ANDROID_PRIORITY_AUDIO); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1784 | } |
| 1785 | |
| 1786 | bool AudioPolicyService::AudioCommandThread::threadLoop() |
| 1787 | { |
Eric Laurent | d7eda8d | 2016-02-02 17:18:39 -0800 | [diff] [blame] | 1788 | nsecs_t waitTime = -1; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1789 | |
| 1790 | mLock.lock(); |
| 1791 | while (!exitPending()) |
| 1792 | { |
Eric Laurent | 59a8923 | 2014-06-08 14:14:17 -0700 | [diff] [blame] | 1793 | sp<AudioPolicyService> svc; |
| 1794 | while (!mAudioCommands.isEmpty() && !exitPending()) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1795 | nsecs_t curTime = systemTime(); |
| 1796 | // commands are sorted by increasing time stamp: execute them from index 0 and up |
| 1797 | if (mAudioCommands[0]->mTime <= curTime) { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1798 | sp<AudioCommand> command = mAudioCommands[0]; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1799 | mAudioCommands.removeAt(0); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1800 | mLastCommand = command; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1801 | |
| 1802 | switch (command->mCommand) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1803 | case SET_VOLUME: { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1804 | VolumeData *data = (VolumeData *)command->mParam.get(); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1805 | ALOGV("AudioCommandThread() processing set volume stream %d, \ |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1806 | volume %f, output %d", data->mStream, data->mVolume, data->mIO); |
Andy Hung | fe726a6 | 2018-09-27 15:17:25 -0700 | [diff] [blame] | 1807 | mLock.unlock(); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1808 | command->mStatus = AudioSystem::setStreamVolume(data->mStream, |
| 1809 | data->mVolume, |
| 1810 | data->mIO); |
Andy Hung | fe726a6 | 2018-09-27 15:17:25 -0700 | [diff] [blame] | 1811 | mLock.lock(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1812 | }break; |
| 1813 | case SET_PARAMETERS: { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1814 | ParametersData *data = (ParametersData *)command->mParam.get(); |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 1815 | ALOGV("AudioCommandThread() processing set parameters string %s, io %d", |
| 1816 | data->mKeyValuePairs.string(), data->mIO); |
Andy Hung | fe726a6 | 2018-09-27 15:17:25 -0700 | [diff] [blame] | 1817 | mLock.unlock(); |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 1818 | command->mStatus = AudioSystem::setParameters(data->mIO, data->mKeyValuePairs); |
Andy Hung | fe726a6 | 2018-09-27 15:17:25 -0700 | [diff] [blame] | 1819 | mLock.lock(); |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 1820 | }break; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1821 | case SET_VOICE_VOLUME: { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1822 | VoiceVolumeData *data = (VoiceVolumeData *)command->mParam.get(); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1823 | ALOGV("AudioCommandThread() processing set voice volume volume %f", |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1824 | data->mVolume); |
Andy Hung | fe726a6 | 2018-09-27 15:17:25 -0700 | [diff] [blame] | 1825 | mLock.unlock(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1826 | command->mStatus = AudioSystem::setVoiceVolume(data->mVolume); |
Andy Hung | fe726a6 | 2018-09-27 15:17:25 -0700 | [diff] [blame] | 1827 | mLock.lock(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1828 | }break; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1829 | case STOP_OUTPUT: { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1830 | StopOutputData *data = (StopOutputData *)command->mParam.get(); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1831 | ALOGV("AudioCommandThread() processing stop output portId %d", |
| 1832 | data->mPortId); |
Eric Laurent | 59a8923 | 2014-06-08 14:14:17 -0700 | [diff] [blame] | 1833 | svc = mService.promote(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1834 | if (svc == 0) { |
| 1835 | break; |
| 1836 | } |
| 1837 | mLock.unlock(); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1838 | svc->doStopOutput(data->mPortId); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1839 | mLock.lock(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1840 | }break; |
| 1841 | case RELEASE_OUTPUT: { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 1842 | ReleaseOutputData *data = (ReleaseOutputData *)command->mParam.get(); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1843 | ALOGV("AudioCommandThread() processing release output portId %d", |
| 1844 | data->mPortId); |
Eric Laurent | 59a8923 | 2014-06-08 14:14:17 -0700 | [diff] [blame] | 1845 | svc = mService.promote(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1846 | if (svc == 0) { |
| 1847 | break; |
| 1848 | } |
| 1849 | mLock.unlock(); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1850 | svc->doReleaseOutput(data->mPortId); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1851 | mLock.lock(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1852 | }break; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 1853 | case CREATE_AUDIO_PATCH: { |
| 1854 | CreateAudioPatchData *data = (CreateAudioPatchData *)command->mParam.get(); |
| 1855 | ALOGV("AudioCommandThread() processing create audio patch"); |
| 1856 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 1857 | if (af == 0) { |
| 1858 | command->mStatus = PERMISSION_DENIED; |
| 1859 | } else { |
Andy Hung | fe726a6 | 2018-09-27 15:17:25 -0700 | [diff] [blame] | 1860 | mLock.unlock(); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 1861 | command->mStatus = af->createAudioPatch(&data->mPatch, &data->mHandle); |
Andy Hung | fe726a6 | 2018-09-27 15:17:25 -0700 | [diff] [blame] | 1862 | mLock.lock(); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 1863 | } |
| 1864 | } break; |
| 1865 | case RELEASE_AUDIO_PATCH: { |
| 1866 | ReleaseAudioPatchData *data = (ReleaseAudioPatchData *)command->mParam.get(); |
| 1867 | ALOGV("AudioCommandThread() processing release audio patch"); |
| 1868 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 1869 | if (af == 0) { |
| 1870 | command->mStatus = PERMISSION_DENIED; |
| 1871 | } else { |
Andy Hung | fe726a6 | 2018-09-27 15:17:25 -0700 | [diff] [blame] | 1872 | mLock.unlock(); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 1873 | command->mStatus = af->releaseAudioPatch(data->mHandle); |
Andy Hung | fe726a6 | 2018-09-27 15:17:25 -0700 | [diff] [blame] | 1874 | mLock.lock(); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 1875 | } |
| 1876 | } break; |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 1877 | case UPDATE_AUDIOPORT_LIST: { |
| 1878 | ALOGV("AudioCommandThread() processing update audio port list"); |
Eric Laurent | 59a8923 | 2014-06-08 14:14:17 -0700 | [diff] [blame] | 1879 | svc = mService.promote(); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 1880 | if (svc == 0) { |
| 1881 | break; |
| 1882 | } |
| 1883 | mLock.unlock(); |
| 1884 | svc->doOnAudioPortListUpdate(); |
| 1885 | mLock.lock(); |
| 1886 | }break; |
| 1887 | case UPDATE_AUDIOPATCH_LIST: { |
| 1888 | ALOGV("AudioCommandThread() processing update audio patch list"); |
Eric Laurent | 59a8923 | 2014-06-08 14:14:17 -0700 | [diff] [blame] | 1889 | svc = mService.promote(); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 1890 | if (svc == 0) { |
| 1891 | break; |
| 1892 | } |
| 1893 | mLock.unlock(); |
| 1894 | svc->doOnAudioPatchListUpdate(); |
| 1895 | mLock.lock(); |
| 1896 | }break; |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1897 | case CHANGED_AUDIOVOLUMEGROUP: { |
| 1898 | AudioVolumeGroupData *data = |
| 1899 | static_cast<AudioVolumeGroupData *>(command->mParam.get()); |
| 1900 | ALOGV("AudioCommandThread() processing update audio volume group"); |
| 1901 | svc = mService.promote(); |
| 1902 | if (svc == 0) { |
| 1903 | break; |
| 1904 | } |
| 1905 | mLock.unlock(); |
| 1906 | svc->doOnAudioVolumeGroupChanged(data->mGroup, data->mFlags); |
| 1907 | mLock.lock(); |
| 1908 | }break; |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 1909 | case SET_AUDIOPORT_CONFIG: { |
| 1910 | SetAudioPortConfigData *data = (SetAudioPortConfigData *)command->mParam.get(); |
| 1911 | ALOGV("AudioCommandThread() processing set port config"); |
| 1912 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 1913 | if (af == 0) { |
| 1914 | command->mStatus = PERMISSION_DENIED; |
| 1915 | } else { |
Andy Hung | fe726a6 | 2018-09-27 15:17:25 -0700 | [diff] [blame] | 1916 | mLock.unlock(); |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 1917 | command->mStatus = af->setAudioPortConfig(&data->mConfig); |
Andy Hung | fe726a6 | 2018-09-27 15:17:25 -0700 | [diff] [blame] | 1918 | mLock.lock(); |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 1919 | } |
| 1920 | } break; |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 1921 | case DYN_POLICY_MIX_STATE_UPDATE: { |
| 1922 | DynPolicyMixStateUpdateData *data = |
| 1923 | (DynPolicyMixStateUpdateData *)command->mParam.get(); |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 1924 | ALOGV("AudioCommandThread() processing dyn policy mix state update %s %d", |
| 1925 | data->mRegId.string(), data->mState); |
| 1926 | svc = mService.promote(); |
| 1927 | if (svc == 0) { |
| 1928 | break; |
| 1929 | } |
| 1930 | mLock.unlock(); |
| 1931 | svc->doOnDynamicPolicyMixStateUpdate(data->mRegId, data->mState); |
| 1932 | mLock.lock(); |
| 1933 | } break; |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 1934 | case RECORDING_CONFIGURATION_UPDATE: { |
| 1935 | RecordingConfigurationUpdateData *data = |
| 1936 | (RecordingConfigurationUpdateData *)command->mParam.get(); |
| 1937 | ALOGV("AudioCommandThread() processing recording configuration update"); |
| 1938 | svc = mService.promote(); |
| 1939 | if (svc == 0) { |
| 1940 | break; |
| 1941 | } |
| 1942 | mLock.unlock(); |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 1943 | svc->doOnRecordingConfigurationUpdate(data->mEvent, &data->mClientInfo, |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 1944 | &data->mClientConfig, data->mClientEffects, |
| 1945 | &data->mDeviceConfig, data->mEffects, |
| 1946 | data->mPatchHandle, data->mSource); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 1947 | mLock.lock(); |
| 1948 | } break; |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 1949 | case SET_EFFECT_SUSPENDED: { |
| 1950 | SetEffectSuspendedData *data = (SetEffectSuspendedData *)command->mParam.get(); |
| 1951 | ALOGV("AudioCommandThread() processing set effect suspended"); |
| 1952 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 1953 | if (af != 0) { |
| 1954 | mLock.unlock(); |
| 1955 | af->setEffectSuspended(data->mEffectId, data->mSessionId, data->mSuspended); |
| 1956 | mLock.lock(); |
| 1957 | } |
| 1958 | } break; |
Mikhail Naganov | 88b30d2 | 2020-03-09 19:43:13 +0000 | [diff] [blame] | 1959 | case AUDIO_MODULES_UPDATE: { |
| 1960 | ALOGV("AudioCommandThread() processing audio modules update"); |
| 1961 | svc = mService.promote(); |
| 1962 | if (svc == 0) { |
| 1963 | break; |
| 1964 | } |
| 1965 | mLock.unlock(); |
| 1966 | svc->doOnNewAudioModulesAvailable(); |
| 1967 | mLock.lock(); |
| 1968 | } break; |
Jean-Michel Trivi | 9a6b9ad | 2020-10-22 16:46:43 -0700 | [diff] [blame] | 1969 | case ROUTING_UPDATED: { |
| 1970 | ALOGV("AudioCommandThread() processing routing update"); |
| 1971 | svc = mService.promote(); |
| 1972 | if (svc == 0) { |
| 1973 | break; |
| 1974 | } |
| 1975 | mLock.unlock(); |
| 1976 | svc->doOnRoutingUpdated(); |
| 1977 | mLock.lock(); |
| 1978 | } break; |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 1979 | |
Eric Laurent | ed726cc | 2021-07-01 14:26:41 +0200 | [diff] [blame] | 1980 | case UPDATE_UID_STATES: { |
| 1981 | ALOGV("AudioCommandThread() processing updateUID states"); |
| 1982 | svc = mService.promote(); |
| 1983 | if (svc == 0) { |
| 1984 | break; |
| 1985 | } |
| 1986 | mLock.unlock(); |
| 1987 | svc->updateUidStates(); |
| 1988 | mLock.lock(); |
| 1989 | } break; |
| 1990 | |
Eric Laurent | 1590359 | 2022-02-24 20:44:36 +0100 | [diff] [blame] | 1991 | case CHECK_SPATIALIZER_OUTPUT: { |
| 1992 | ALOGV("AudioCommandThread() processing check spatializer"); |
Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 1993 | svc = mService.promote(); |
| 1994 | if (svc == 0) { |
| 1995 | break; |
| 1996 | } |
| 1997 | mLock.unlock(); |
| 1998 | svc->doOnCheckSpatializer(); |
| 1999 | mLock.lock(); |
| 2000 | } break; |
| 2001 | |
Eric Laurent | 1590359 | 2022-02-24 20:44:36 +0100 | [diff] [blame] | 2002 | case UPDATE_ACTIVE_SPATIALIZER_TRACKS: { |
| 2003 | ALOGV("AudioCommandThread() processing update spatializer tracks"); |
| 2004 | svc = mService.promote(); |
| 2005 | if (svc == 0) { |
| 2006 | break; |
| 2007 | } |
| 2008 | mLock.unlock(); |
| 2009 | svc->doOnUpdateActiveSpatializerTracks(); |
| 2010 | mLock.lock(); |
| 2011 | } break; |
| 2012 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2013 | default: |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 2014 | ALOGW("AudioCommandThread() unknown command %d", command->mCommand); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2015 | } |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2016 | { |
| 2017 | Mutex::Autolock _l(command->mLock); |
| 2018 | if (command->mWaitStatus) { |
| 2019 | command->mWaitStatus = false; |
| 2020 | command->mCond.signal(); |
| 2021 | } |
| 2022 | } |
Eric Laurent | d7eda8d | 2016-02-02 17:18:39 -0800 | [diff] [blame] | 2023 | waitTime = -1; |
Zach Jang | a754b4f | 2015-10-27 01:29:34 +0000 | [diff] [blame] | 2024 | // release mLock before releasing strong reference on the service as |
| 2025 | // AudioPolicyService destructor calls AudioCommandThread::exit() which |
| 2026 | // acquires mLock. |
| 2027 | mLock.unlock(); |
| 2028 | svc.clear(); |
| 2029 | mLock.lock(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2030 | } else { |
| 2031 | waitTime = mAudioCommands[0]->mTime - curTime; |
| 2032 | break; |
| 2033 | } |
| 2034 | } |
Zach Jang | a754b4f | 2015-10-27 01:29:34 +0000 | [diff] [blame] | 2035 | |
| 2036 | // release delayed commands wake lock if the queue is empty |
| 2037 | if (mAudioCommands.isEmpty()) { |
Ricardo Garcia | 05f2fdc | 2014-07-24 15:48:24 -0700 | [diff] [blame] | 2038 | release_wake_lock(mName.string()); |
Zach Jang | a754b4f | 2015-10-27 01:29:34 +0000 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | // At this stage we have either an empty command queue or the first command in the queue |
| 2042 | // has a finite delay. So unless we are exiting it is safe to wait. |
| 2043 | if (!exitPending()) { |
Eric Laurent | 59a8923 | 2014-06-08 14:14:17 -0700 | [diff] [blame] | 2044 | ALOGV("AudioCommandThread() going to sleep"); |
Eric Laurent | d7eda8d | 2016-02-02 17:18:39 -0800 | [diff] [blame] | 2045 | if (waitTime == -1) { |
| 2046 | mWaitWorkCV.wait(mLock); |
| 2047 | } else { |
| 2048 | mWaitWorkCV.waitRelative(mLock, waitTime); |
| 2049 | } |
Eric Laurent | 59a8923 | 2014-06-08 14:14:17 -0700 | [diff] [blame] | 2050 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2051 | } |
Ricardo Garcia | 05f2fdc | 2014-07-24 15:48:24 -0700 | [diff] [blame] | 2052 | // release delayed commands wake lock before quitting |
| 2053 | if (!mAudioCommands.isEmpty()) { |
| 2054 | release_wake_lock(mName.string()); |
| 2055 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2056 | mLock.unlock(); |
| 2057 | return false; |
| 2058 | } |
| 2059 | |
| 2060 | status_t AudioPolicyService::AudioCommandThread::dump(int fd) |
| 2061 | { |
| 2062 | const size_t SIZE = 256; |
| 2063 | char buffer[SIZE]; |
| 2064 | String8 result; |
| 2065 | |
Mikhail Naganov | 12b716c | 2020-04-30 22:37:43 +0000 | [diff] [blame] | 2066 | const bool locked = dumpTryLock(mLock); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2067 | if (!locked) { |
| 2068 | String8 result2(kCmdDeadlockedString); |
| 2069 | write(fd, result2.string(), result2.size()); |
| 2070 | } |
| 2071 | |
| 2072 | snprintf(buffer, SIZE, "- Commands:\n"); |
| 2073 | result = String8(buffer); |
| 2074 | result.append(" Command Time Wait pParam\n"); |
Glenn Kasten | 8d6a244 | 2012-02-08 14:04:28 -0800 | [diff] [blame] | 2075 | for (size_t i = 0; i < mAudioCommands.size(); i++) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2076 | mAudioCommands[i]->dump(buffer, SIZE); |
| 2077 | result.append(buffer); |
| 2078 | } |
| 2079 | result.append(" Last Command\n"); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2080 | if (mLastCommand != 0) { |
| 2081 | mLastCommand->dump(buffer, SIZE); |
| 2082 | result.append(buffer); |
| 2083 | } else { |
| 2084 | result.append(" none\n"); |
| 2085 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2086 | |
| 2087 | write(fd, result.string(), result.size()); |
| 2088 | |
Mikhail Naganov | 12b716c | 2020-04-30 22:37:43 +0000 | [diff] [blame] | 2089 | dumpReleaseLock(mLock, locked); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2090 | |
| 2091 | return NO_ERROR; |
| 2092 | } |
| 2093 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 2094 | status_t AudioPolicyService::AudioCommandThread::volumeCommand(audio_stream_type_t stream, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 2095 | float volume, |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 2096 | audio_io_handle_t output, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 2097 | int delayMs) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2098 | { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2099 | sp<AudioCommand> command = new AudioCommand(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2100 | command->mCommand = SET_VOLUME; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2101 | sp<VolumeData> data = new VolumeData(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2102 | data->mStream = stream; |
| 2103 | data->mVolume = volume; |
| 2104 | data->mIO = output; |
| 2105 | command->mParam = data; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2106 | command->mWaitStatus = true; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2107 | ALOGV("AudioCommandThread() adding set volume stream %d, volume %f, output %d", |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 2108 | stream, volume, output); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2109 | return sendCommand(command, delayMs); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2110 | } |
| 2111 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 2112 | status_t AudioPolicyService::AudioCommandThread::parametersCommand(audio_io_handle_t ioHandle, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 2113 | const char *keyValuePairs, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 2114 | int delayMs) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2115 | { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2116 | sp<AudioCommand> command = new AudioCommand(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2117 | command->mCommand = SET_PARAMETERS; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2118 | sp<ParametersData> data = new ParametersData(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2119 | data->mIO = ioHandle; |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 2120 | data->mKeyValuePairs = String8(keyValuePairs); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2121 | command->mParam = data; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2122 | command->mWaitStatus = true; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2123 | ALOGV("AudioCommandThread() adding set parameter string %s, io %d ,delay %d", |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 2124 | keyValuePairs, ioHandle, delayMs); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2125 | return sendCommand(command, delayMs); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2126 | } |
| 2127 | |
| 2128 | status_t AudioPolicyService::AudioCommandThread::voiceVolumeCommand(float volume, int delayMs) |
| 2129 | { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2130 | sp<AudioCommand> command = new AudioCommand(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2131 | command->mCommand = SET_VOICE_VOLUME; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2132 | sp<VoiceVolumeData> data = new VoiceVolumeData(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2133 | data->mVolume = volume; |
| 2134 | command->mParam = data; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2135 | command->mWaitStatus = true; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2136 | ALOGV("AudioCommandThread() adding set voice volume volume %f", volume); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2137 | return sendCommand(command, delayMs); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2138 | } |
| 2139 | |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 2140 | void AudioPolicyService::AudioCommandThread::setEffectSuspendedCommand(int effectId, |
| 2141 | audio_session_t sessionId, |
| 2142 | bool suspended) |
| 2143 | { |
| 2144 | sp<AudioCommand> command = new AudioCommand(); |
| 2145 | command->mCommand = SET_EFFECT_SUSPENDED; |
| 2146 | sp<SetEffectSuspendedData> data = new SetEffectSuspendedData(); |
| 2147 | data->mEffectId = effectId; |
| 2148 | data->mSessionId = sessionId; |
| 2149 | data->mSuspended = suspended; |
| 2150 | command->mParam = data; |
| 2151 | ALOGV("AudioCommandThread() adding set suspended effectId %d sessionId %d suspended %d", |
| 2152 | effectId, sessionId, suspended); |
| 2153 | sendCommand(command); |
| 2154 | } |
| 2155 | |
| 2156 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 2157 | void AudioPolicyService::AudioCommandThread::stopOutputCommand(audio_port_handle_t portId) |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 2158 | { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2159 | sp<AudioCommand> command = new AudioCommand(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 2160 | command->mCommand = STOP_OUTPUT; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2161 | sp<StopOutputData> data = new StopOutputData(); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 2162 | data->mPortId = portId; |
Jesper Tragardh | 48412dc | 2014-03-24 14:12:43 +0100 | [diff] [blame] | 2163 | command->mParam = data; |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 2164 | ALOGV("AudioCommandThread() adding stop output portId %d", portId); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2165 | sendCommand(command); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 2166 | } |
| 2167 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 2168 | void AudioPolicyService::AudioCommandThread::releaseOutputCommand(audio_port_handle_t portId) |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 2169 | { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2170 | sp<AudioCommand> command = new AudioCommand(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 2171 | command->mCommand = RELEASE_OUTPUT; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2172 | sp<ReleaseOutputData> data = new ReleaseOutputData(); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 2173 | data->mPortId = portId; |
Jesper Tragardh | 48412dc | 2014-03-24 14:12:43 +0100 | [diff] [blame] | 2174 | command->mParam = data; |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 2175 | ALOGV("AudioCommandThread() adding release output portId %d", portId); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2176 | sendCommand(command); |
| 2177 | } |
| 2178 | |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 2179 | status_t AudioPolicyService::AudioCommandThread::createAudioPatchCommand( |
| 2180 | const struct audio_patch *patch, |
| 2181 | audio_patch_handle_t *handle, |
| 2182 | int delayMs) |
| 2183 | { |
| 2184 | status_t status = NO_ERROR; |
| 2185 | |
| 2186 | sp<AudioCommand> command = new AudioCommand(); |
| 2187 | command->mCommand = CREATE_AUDIO_PATCH; |
| 2188 | CreateAudioPatchData *data = new CreateAudioPatchData(); |
| 2189 | data->mPatch = *patch; |
| 2190 | data->mHandle = *handle; |
| 2191 | command->mParam = data; |
| 2192 | command->mWaitStatus = true; |
| 2193 | ALOGV("AudioCommandThread() adding create patch delay %d", delayMs); |
| 2194 | status = sendCommand(command, delayMs); |
| 2195 | if (status == NO_ERROR) { |
| 2196 | *handle = data->mHandle; |
| 2197 | } |
| 2198 | return status; |
| 2199 | } |
| 2200 | |
| 2201 | status_t AudioPolicyService::AudioCommandThread::releaseAudioPatchCommand(audio_patch_handle_t handle, |
| 2202 | int delayMs) |
| 2203 | { |
| 2204 | sp<AudioCommand> command = new AudioCommand(); |
| 2205 | command->mCommand = RELEASE_AUDIO_PATCH; |
| 2206 | ReleaseAudioPatchData *data = new ReleaseAudioPatchData(); |
| 2207 | data->mHandle = handle; |
| 2208 | command->mParam = data; |
| 2209 | command->mWaitStatus = true; |
| 2210 | ALOGV("AudioCommandThread() adding release patch delay %d", delayMs); |
| 2211 | return sendCommand(command, delayMs); |
| 2212 | } |
| 2213 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 2214 | void AudioPolicyService::AudioCommandThread::updateAudioPortListCommand() |
| 2215 | { |
| 2216 | sp<AudioCommand> command = new AudioCommand(); |
| 2217 | command->mCommand = UPDATE_AUDIOPORT_LIST; |
| 2218 | ALOGV("AudioCommandThread() adding update audio port list"); |
| 2219 | sendCommand(command); |
| 2220 | } |
| 2221 | |
Eric Laurent | ed726cc | 2021-07-01 14:26:41 +0200 | [diff] [blame] | 2222 | void AudioPolicyService::AudioCommandThread::updateUidStatesCommand() |
| 2223 | { |
| 2224 | sp<AudioCommand> command = new AudioCommand(); |
| 2225 | command->mCommand = UPDATE_UID_STATES; |
| 2226 | ALOGV("AudioCommandThread() adding update UID states"); |
| 2227 | sendCommand(command); |
| 2228 | } |
| 2229 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 2230 | void AudioPolicyService::AudioCommandThread::updateAudioPatchListCommand() |
| 2231 | { |
| 2232 | sp<AudioCommand>command = new AudioCommand(); |
| 2233 | command->mCommand = UPDATE_AUDIOPATCH_LIST; |
| 2234 | ALOGV("AudioCommandThread() adding update audio patch list"); |
| 2235 | sendCommand(command); |
| 2236 | } |
| 2237 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 2238 | void AudioPolicyService::AudioCommandThread::changeAudioVolumeGroupCommand(volume_group_t group, |
| 2239 | int flags) |
| 2240 | { |
| 2241 | sp<AudioCommand>command = new AudioCommand(); |
| 2242 | command->mCommand = CHANGED_AUDIOVOLUMEGROUP; |
| 2243 | AudioVolumeGroupData *data= new AudioVolumeGroupData(); |
| 2244 | data->mGroup = group; |
| 2245 | data->mFlags = flags; |
| 2246 | command->mParam = data; |
| 2247 | ALOGV("AudioCommandThread() adding audio volume group changed"); |
| 2248 | sendCommand(command); |
| 2249 | } |
| 2250 | |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 2251 | status_t AudioPolicyService::AudioCommandThread::setAudioPortConfigCommand( |
| 2252 | const struct audio_port_config *config, int delayMs) |
| 2253 | { |
| 2254 | sp<AudioCommand> command = new AudioCommand(); |
| 2255 | command->mCommand = SET_AUDIOPORT_CONFIG; |
| 2256 | SetAudioPortConfigData *data = new SetAudioPortConfigData(); |
| 2257 | data->mConfig = *config; |
| 2258 | command->mParam = data; |
| 2259 | command->mWaitStatus = true; |
| 2260 | ALOGV("AudioCommandThread() adding set port config delay %d", delayMs); |
| 2261 | return sendCommand(command, delayMs); |
| 2262 | } |
| 2263 | |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 2264 | void AudioPolicyService::AudioCommandThread::dynamicPolicyMixStateUpdateCommand( |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 2265 | const String8& regId, int32_t state) |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 2266 | { |
| 2267 | sp<AudioCommand> command = new AudioCommand(); |
| 2268 | command->mCommand = DYN_POLICY_MIX_STATE_UPDATE; |
| 2269 | DynPolicyMixStateUpdateData *data = new DynPolicyMixStateUpdateData(); |
| 2270 | data->mRegId = regId; |
| 2271 | data->mState = state; |
| 2272 | command->mParam = data; |
| 2273 | ALOGV("AudioCommandThread() sending dynamic policy mix (id=%s) state update to %d", |
| 2274 | regId.string(), state); |
| 2275 | sendCommand(command); |
| 2276 | } |
| 2277 | |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 2278 | void AudioPolicyService::AudioCommandThread::recordingConfigurationUpdateCommand( |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 2279 | int event, |
| 2280 | const record_client_info_t *clientInfo, |
| 2281 | const audio_config_base_t *clientConfig, |
| 2282 | std::vector<effect_descriptor_t> clientEffects, |
| 2283 | const audio_config_base_t *deviceConfig, |
| 2284 | std::vector<effect_descriptor_t> effects, |
| 2285 | audio_patch_handle_t patchHandle, |
| 2286 | audio_source_t source) |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 2287 | { |
| 2288 | sp<AudioCommand>command = new AudioCommand(); |
| 2289 | command->mCommand = RECORDING_CONFIGURATION_UPDATE; |
| 2290 | RecordingConfigurationUpdateData *data = new RecordingConfigurationUpdateData(); |
| 2291 | data->mEvent = event; |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 2292 | data->mClientInfo = *clientInfo; |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 2293 | data->mClientConfig = *clientConfig; |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 2294 | data->mClientEffects = clientEffects; |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 2295 | data->mDeviceConfig = *deviceConfig; |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 2296 | data->mEffects = effects; |
Jean-Michel Trivi | 8c7cf3b | 2016-02-25 17:08:24 -0800 | [diff] [blame] | 2297 | data->mPatchHandle = patchHandle; |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 2298 | data->mSource = source; |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 2299 | command->mParam = data; |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 2300 | ALOGV("AudioCommandThread() adding recording configuration update event %d, source %d uid %u", |
| 2301 | event, clientInfo->source, clientInfo->uid); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 2302 | sendCommand(command); |
| 2303 | } |
| 2304 | |
Mikhail Naganov | 88b30d2 | 2020-03-09 19:43:13 +0000 | [diff] [blame] | 2305 | void AudioPolicyService::AudioCommandThread::audioModulesUpdateCommand() |
| 2306 | { |
| 2307 | sp<AudioCommand> command = new AudioCommand(); |
| 2308 | command->mCommand = AUDIO_MODULES_UPDATE; |
| 2309 | sendCommand(command); |
| 2310 | } |
| 2311 | |
Jean-Michel Trivi | 9a6b9ad | 2020-10-22 16:46:43 -0700 | [diff] [blame] | 2312 | void AudioPolicyService::AudioCommandThread::routingChangedCommand() |
| 2313 | { |
| 2314 | sp<AudioCommand>command = new AudioCommand(); |
| 2315 | command->mCommand = ROUTING_UPDATED; |
| 2316 | ALOGV("AudioCommandThread() adding routing update"); |
| 2317 | sendCommand(command); |
| 2318 | } |
| 2319 | |
Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 2320 | void AudioPolicyService::AudioCommandThread::checkSpatializerCommand() |
| 2321 | { |
| 2322 | sp<AudioCommand>command = new AudioCommand(); |
Eric Laurent | 1590359 | 2022-02-24 20:44:36 +0100 | [diff] [blame] | 2323 | command->mCommand = CHECK_SPATIALIZER_OUTPUT; |
Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 2324 | ALOGV("AudioCommandThread() adding check spatializer"); |
| 2325 | sendCommand(command); |
| 2326 | } |
| 2327 | |
Eric Laurent | 1590359 | 2022-02-24 20:44:36 +0100 | [diff] [blame] | 2328 | void AudioPolicyService::AudioCommandThread::updateActiveSpatializerTracksCommand() |
| 2329 | { |
| 2330 | sp<AudioCommand>command = new AudioCommand(); |
| 2331 | command->mCommand = UPDATE_ACTIVE_SPATIALIZER_TRACKS; |
| 2332 | ALOGV("AudioCommandThread() adding update active spatializer tracks"); |
| 2333 | sendCommand(command); |
| 2334 | } |
| 2335 | |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2336 | status_t AudioPolicyService::AudioCommandThread::sendCommand(sp<AudioCommand>& command, int delayMs) |
| 2337 | { |
| 2338 | { |
| 2339 | Mutex::Autolock _l(mLock); |
| 2340 | insertCommand_l(command, delayMs); |
| 2341 | mWaitWorkCV.signal(); |
| 2342 | } |
| 2343 | Mutex::Autolock _l(command->mLock); |
| 2344 | while (command->mWaitStatus) { |
| 2345 | nsecs_t timeOutNs = kAudioCommandTimeoutNs + milliseconds(delayMs); |
| 2346 | if (command->mCond.waitRelative(command->mLock, timeOutNs) != NO_ERROR) { |
| 2347 | command->mStatus = TIMED_OUT; |
| 2348 | command->mWaitStatus = false; |
| 2349 | } |
| 2350 | } |
| 2351 | return command->mStatus; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 2352 | } |
| 2353 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2354 | // insertCommand_l() must be called with mLock held |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2355 | void AudioPolicyService::AudioCommandThread::insertCommand_l(sp<AudioCommand>& command, int delayMs) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2356 | { |
Glenn Kasten | 8d6a244 | 2012-02-08 14:04:28 -0800 | [diff] [blame] | 2357 | 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] | 2358 | Vector < sp<AudioCommand> > removedCommands; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2359 | command->mTime = systemTime() + milliseconds(delayMs); |
| 2360 | |
| 2361 | // acquire wake lock to make sure delayed commands are processed |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 2362 | if (mAudioCommands.isEmpty()) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2363 | acquire_wake_lock(PARTIAL_WAKE_LOCK, mName.string()); |
| 2364 | } |
| 2365 | |
| 2366 | // check same pending commands with later time stamps and eliminate them |
Ivan Lozano | 5ff158f | 2017-10-30 09:06:24 -0700 | [diff] [blame] | 2367 | for (i = (ssize_t)mAudioCommands.size()-1; i >= 0; i--) { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2368 | sp<AudioCommand> command2 = mAudioCommands[i]; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2369 | // commands are sorted by increasing time stamp: no need to scan the rest of mAudioCommands |
| 2370 | if (command2->mTime <= command->mTime) break; |
Eric Laurent | e45b48a | 2014-09-04 16:40:57 -0700 | [diff] [blame] | 2371 | |
| 2372 | // create audio patch or release audio patch commands are equivalent |
| 2373 | // with regard to filtering |
| 2374 | if ((command->mCommand == CREATE_AUDIO_PATCH) || |
| 2375 | (command->mCommand == RELEASE_AUDIO_PATCH)) { |
| 2376 | if ((command2->mCommand != CREATE_AUDIO_PATCH) && |
| 2377 | (command2->mCommand != RELEASE_AUDIO_PATCH)) { |
| 2378 | continue; |
| 2379 | } |
| 2380 | } else if (command2->mCommand != command->mCommand) continue; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2381 | |
| 2382 | switch (command->mCommand) { |
| 2383 | case SET_PARAMETERS: { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2384 | ParametersData *data = (ParametersData *)command->mParam.get(); |
| 2385 | ParametersData *data2 = (ParametersData *)command2->mParam.get(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2386 | if (data->mIO != data2->mIO) break; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2387 | ALOGV("Comparing parameter command %s to new command %s", |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 2388 | data2->mKeyValuePairs.string(), data->mKeyValuePairs.string()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2389 | AudioParameter param = AudioParameter(data->mKeyValuePairs); |
| 2390 | AudioParameter param2 = AudioParameter(data2->mKeyValuePairs); |
| 2391 | for (size_t j = 0; j < param.size(); j++) { |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 2392 | String8 key; |
| 2393 | String8 value; |
| 2394 | param.getAt(j, key, value); |
| 2395 | for (size_t k = 0; k < param2.size(); k++) { |
| 2396 | String8 key2; |
| 2397 | String8 value2; |
| 2398 | param2.getAt(k, key2, value2); |
| 2399 | if (key2 == key) { |
| 2400 | param2.remove(key2); |
| 2401 | ALOGV("Filtering out parameter %s", key2.string()); |
| 2402 | break; |
| 2403 | } |
| 2404 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2405 | } |
| 2406 | // if all keys have been filtered out, remove the command. |
| 2407 | // otherwise, update the key value pairs |
| 2408 | if (param2.size() == 0) { |
| 2409 | removedCommands.add(command2); |
| 2410 | } else { |
| 2411 | data2->mKeyValuePairs = param2.toString(); |
| 2412 | } |
Eric Laurent | 21e5456 | 2013-09-23 12:08:05 -0700 | [diff] [blame] | 2413 | command->mTime = command2->mTime; |
| 2414 | // force delayMs to non 0 so that code below does not request to wait for |
| 2415 | // command status as the command is now delayed |
| 2416 | delayMs = 1; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2417 | } break; |
| 2418 | |
| 2419 | case SET_VOLUME: { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2420 | VolumeData *data = (VolumeData *)command->mParam.get(); |
| 2421 | VolumeData *data2 = (VolumeData *)command2->mParam.get(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2422 | if (data->mIO != data2->mIO) break; |
| 2423 | if (data->mStream != data2->mStream) break; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2424 | ALOGV("Filtering out volume command on output %d for stream %d", |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 2425 | data->mIO, data->mStream); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2426 | removedCommands.add(command2); |
Eric Laurent | 21e5456 | 2013-09-23 12:08:05 -0700 | [diff] [blame] | 2427 | command->mTime = command2->mTime; |
| 2428 | // force delayMs to non 0 so that code below does not request to wait for |
| 2429 | // command status as the command is now delayed |
| 2430 | delayMs = 1; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2431 | } break; |
Eric Laurent | e45b48a | 2014-09-04 16:40:57 -0700 | [diff] [blame] | 2432 | |
Eric Laurent | baf35fe | 2016-07-27 15:36:53 -0700 | [diff] [blame] | 2433 | case SET_VOICE_VOLUME: { |
| 2434 | VoiceVolumeData *data = (VoiceVolumeData *)command->mParam.get(); |
| 2435 | VoiceVolumeData *data2 = (VoiceVolumeData *)command2->mParam.get(); |
| 2436 | ALOGV("Filtering out voice volume command value %f replaced by %f", |
| 2437 | data2->mVolume, data->mVolume); |
| 2438 | removedCommands.add(command2); |
| 2439 | command->mTime = command2->mTime; |
| 2440 | // force delayMs to non 0 so that code below does not request to wait for |
| 2441 | // command status as the command is now delayed |
| 2442 | delayMs = 1; |
| 2443 | } break; |
| 2444 | |
Eric Laurent | e45b48a | 2014-09-04 16:40:57 -0700 | [diff] [blame] | 2445 | case CREATE_AUDIO_PATCH: |
| 2446 | case RELEASE_AUDIO_PATCH: { |
| 2447 | audio_patch_handle_t handle; |
Haynes Mathew George | a2d4a6d | 2014-10-13 13:05:22 -0700 | [diff] [blame] | 2448 | struct audio_patch patch; |
Eric Laurent | e45b48a | 2014-09-04 16:40:57 -0700 | [diff] [blame] | 2449 | if (command->mCommand == CREATE_AUDIO_PATCH) { |
| 2450 | handle = ((CreateAudioPatchData *)command->mParam.get())->mHandle; |
Haynes Mathew George | a2d4a6d | 2014-10-13 13:05:22 -0700 | [diff] [blame] | 2451 | patch = ((CreateAudioPatchData *)command->mParam.get())->mPatch; |
Eric Laurent | e45b48a | 2014-09-04 16:40:57 -0700 | [diff] [blame] | 2452 | } else { |
| 2453 | handle = ((ReleaseAudioPatchData *)command->mParam.get())->mHandle; |
Mikhail Naganov | 7be71d2 | 2018-05-23 16:51:46 -0700 | [diff] [blame] | 2454 | memset(&patch, 0, sizeof(patch)); |
Eric Laurent | e45b48a | 2014-09-04 16:40:57 -0700 | [diff] [blame] | 2455 | } |
| 2456 | audio_patch_handle_t handle2; |
Haynes Mathew George | a2d4a6d | 2014-10-13 13:05:22 -0700 | [diff] [blame] | 2457 | struct audio_patch patch2; |
Eric Laurent | e45b48a | 2014-09-04 16:40:57 -0700 | [diff] [blame] | 2458 | if (command2->mCommand == CREATE_AUDIO_PATCH) { |
| 2459 | handle2 = ((CreateAudioPatchData *)command2->mParam.get())->mHandle; |
Haynes Mathew George | a2d4a6d | 2014-10-13 13:05:22 -0700 | [diff] [blame] | 2460 | patch2 = ((CreateAudioPatchData *)command2->mParam.get())->mPatch; |
Eric Laurent | e45b48a | 2014-09-04 16:40:57 -0700 | [diff] [blame] | 2461 | } else { |
| 2462 | handle2 = ((ReleaseAudioPatchData *)command2->mParam.get())->mHandle; |
Glenn Kasten | f60b6b6 | 2015-07-06 10:53:26 -0700 | [diff] [blame] | 2463 | memset(&patch2, 0, sizeof(patch2)); |
Eric Laurent | e45b48a | 2014-09-04 16:40:57 -0700 | [diff] [blame] | 2464 | } |
| 2465 | if (handle != handle2) break; |
Haynes Mathew George | a2d4a6d | 2014-10-13 13:05:22 -0700 | [diff] [blame] | 2466 | /* Filter CREATE_AUDIO_PATCH commands only when they are issued for |
| 2467 | same output. */ |
| 2468 | if( (command->mCommand == CREATE_AUDIO_PATCH) && |
| 2469 | (command2->mCommand == CREATE_AUDIO_PATCH) ) { |
| 2470 | bool isOutputDiff = false; |
| 2471 | if (patch.num_sources == patch2.num_sources) { |
| 2472 | for (unsigned count = 0; count < patch.num_sources; count++) { |
| 2473 | if (patch.sources[count].id != patch2.sources[count].id) { |
| 2474 | isOutputDiff = true; |
| 2475 | break; |
| 2476 | } |
| 2477 | } |
| 2478 | if (isOutputDiff) |
| 2479 | break; |
| 2480 | } |
| 2481 | } |
Eric Laurent | e45b48a | 2014-09-04 16:40:57 -0700 | [diff] [blame] | 2482 | ALOGV("Filtering out %s audio patch command for handle %d", |
| 2483 | (command->mCommand == CREATE_AUDIO_PATCH) ? "create" : "release", handle); |
| 2484 | removedCommands.add(command2); |
| 2485 | command->mTime = command2->mTime; |
| 2486 | // force delayMs to non 0 so that code below does not request to wait for |
| 2487 | // command status as the command is now delayed |
| 2488 | delayMs = 1; |
| 2489 | } break; |
| 2490 | |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 2491 | case DYN_POLICY_MIX_STATE_UPDATE: { |
| 2492 | |
| 2493 | } break; |
| 2494 | |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 2495 | case RECORDING_CONFIGURATION_UPDATE: { |
| 2496 | |
| 2497 | } break; |
| 2498 | |
Jean-Michel Trivi | 9a6b9ad | 2020-10-22 16:46:43 -0700 | [diff] [blame] | 2499 | case ROUTING_UPDATED: { |
| 2500 | |
| 2501 | } break; |
| 2502 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2503 | default: |
| 2504 | break; |
| 2505 | } |
| 2506 | } |
| 2507 | |
| 2508 | // remove filtered commands |
| 2509 | for (size_t j = 0; j < removedCommands.size(); j++) { |
| 2510 | // removed commands always have time stamps greater than current command |
| 2511 | for (size_t k = i + 1; k < mAudioCommands.size(); k++) { |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2512 | if (mAudioCommands[k].get() == removedCommands[j].get()) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2513 | ALOGV("suppressing command: %d", mAudioCommands[k]->mCommand); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2514 | mAudioCommands.removeAt(k); |
| 2515 | break; |
| 2516 | } |
| 2517 | } |
| 2518 | } |
| 2519 | removedCommands.clear(); |
| 2520 | |
Eric Laurent | aa79bef | 2015-01-15 14:33:51 -0800 | [diff] [blame] | 2521 | // Disable wait for status if delay is not 0. |
| 2522 | // Except for create audio patch command because the returned patch handle |
| 2523 | // is needed by audio policy manager |
| 2524 | if (delayMs != 0 && command->mCommand != CREATE_AUDIO_PATCH) { |
Eric Laurent | cec4abb | 2012-07-03 12:23:02 -0700 | [diff] [blame] | 2525 | command->mWaitStatus = false; |
| 2526 | } |
Eric Laurent | cec4abb | 2012-07-03 12:23:02 -0700 | [diff] [blame] | 2527 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2528 | // insert command at the right place according to its time stamp |
Eric Laurent | 1e693b5 | 2014-07-09 15:03:28 -0700 | [diff] [blame] | 2529 | ALOGV("inserting command: %d at index %zd, num commands %zu", |
| 2530 | command->mCommand, i+1, mAudioCommands.size()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2531 | mAudioCommands.insertAt(command, i + 1); |
| 2532 | } |
| 2533 | |
| 2534 | void AudioPolicyService::AudioCommandThread::exit() |
| 2535 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2536 | ALOGV("AudioCommandThread::exit"); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2537 | { |
| 2538 | AutoMutex _l(mLock); |
| 2539 | requestExit(); |
| 2540 | mWaitWorkCV.signal(); |
| 2541 | } |
Zach Jang | a754b4f | 2015-10-27 01:29:34 +0000 | [diff] [blame] | 2542 | // Note that we can call it from the thread loop if all other references have been released |
| 2543 | // but it will safely return WOULD_BLOCK in this case |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2544 | requestExitAndWait(); |
| 2545 | } |
| 2546 | |
| 2547 | void AudioPolicyService::AudioCommandThread::AudioCommand::dump(char* buffer, size_t size) |
| 2548 | { |
| 2549 | snprintf(buffer, size, " %02d %06d.%03d %01u %p\n", |
| 2550 | mCommand, |
| 2551 | (int)ns2s(mTime), |
| 2552 | (int)ns2ms(mTime)%1000, |
| 2553 | mWaitStatus, |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 2554 | mParam.get()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2555 | } |
| 2556 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 2557 | /******* helpers for the service_ops callbacks defined below *********/ |
| 2558 | void AudioPolicyService::setParameters(audio_io_handle_t ioHandle, |
| 2559 | const char *keyValuePairs, |
| 2560 | int delayMs) |
| 2561 | { |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 2562 | mAudioCommandThread->parametersCommand(ioHandle, keyValuePairs, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 2563 | delayMs); |
| 2564 | } |
| 2565 | |
| 2566 | int AudioPolicyService::setStreamVolume(audio_stream_type_t stream, |
| 2567 | float volume, |
| 2568 | audio_io_handle_t output, |
| 2569 | int delayMs) |
| 2570 | { |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 2571 | return (int)mAudioCommandThread->volumeCommand(stream, volume, |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 2572 | output, delayMs); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 2573 | } |
| 2574 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 2575 | int AudioPolicyService::setVoiceVolume(float volume, int delayMs) |
| 2576 | { |
| 2577 | return (int)mAudioCommandThread->voiceVolumeCommand(volume, delayMs); |
| 2578 | } |
| 2579 | |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 2580 | void AudioPolicyService::setEffectSuspended(int effectId, |
| 2581 | audio_session_t sessionId, |
| 2582 | bool suspended) |
| 2583 | { |
| 2584 | mAudioCommandThread->setEffectSuspendedCommand(effectId, sessionId, suspended); |
| 2585 | } |
| 2586 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2587 | Status AudioPolicyService::onNewAudioModulesAvailable() |
Mikhail Naganov | 88b30d2 | 2020-03-09 19:43:13 +0000 | [diff] [blame] | 2588 | { |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 2589 | mOutputCommandThread->audioModulesUpdateCommand(); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2590 | return Status::ok(); |
Mikhail Naganov | 88b30d2 | 2020-03-09 19:43:13 +0000 | [diff] [blame] | 2591 | } |
| 2592 | |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 2593 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 2594 | extern "C" { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 2595 | audio_module_handle_t aps_load_hw_module(void *service __unused, |
| 2596 | const char *name); |
| 2597 | audio_io_handle_t aps_open_output(void *service __unused, |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 2598 | audio_devices_t *pDevices, |
| 2599 | uint32_t *pSamplingRate, |
| 2600 | audio_format_t *pFormat, |
| 2601 | audio_channel_mask_t *pChannelMask, |
| 2602 | uint32_t *pLatencyMs, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 2603 | audio_output_flags_t flags); |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 2604 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 2605 | audio_io_handle_t aps_open_output_on_module(void *service __unused, |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 2606 | audio_module_handle_t module, |
| 2607 | audio_devices_t *pDevices, |
| 2608 | uint32_t *pSamplingRate, |
| 2609 | audio_format_t *pFormat, |
| 2610 | audio_channel_mask_t *pChannelMask, |
| 2611 | uint32_t *pLatencyMs, |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 2612 | audio_output_flags_t flags, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 2613 | const audio_offload_info_t *offloadInfo); |
| 2614 | audio_io_handle_t aps_open_dup_output(void *service __unused, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 2615 | audio_io_handle_t output1, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 2616 | audio_io_handle_t output2); |
| 2617 | int aps_close_output(void *service __unused, audio_io_handle_t output); |
| 2618 | int aps_suspend_output(void *service __unused, audio_io_handle_t output); |
| 2619 | int aps_restore_output(void *service __unused, audio_io_handle_t output); |
| 2620 | audio_io_handle_t aps_open_input(void *service __unused, |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 2621 | audio_devices_t *pDevices, |
| 2622 | uint32_t *pSamplingRate, |
| 2623 | audio_format_t *pFormat, |
| 2624 | audio_channel_mask_t *pChannelMask, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 2625 | audio_in_acoustics_t acoustics __unused); |
| 2626 | audio_io_handle_t aps_open_input_on_module(void *service __unused, |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 2627 | audio_module_handle_t module, |
| 2628 | audio_devices_t *pDevices, |
| 2629 | uint32_t *pSamplingRate, |
| 2630 | audio_format_t *pFormat, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 2631 | audio_channel_mask_t *pChannelMask); |
| 2632 | int aps_close_input(void *service __unused, audio_io_handle_t input); |
| 2633 | int aps_invalidate_stream(void *service __unused, audio_stream_type_t stream); |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 2634 | int aps_move_effects(void *service __unused, audio_session_t session, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 2635 | audio_io_handle_t src_output, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 2636 | audio_io_handle_t dst_output); |
| 2637 | char * aps_get_parameters(void *service __unused, audio_io_handle_t io_handle, |
| 2638 | const char *keys); |
| 2639 | void aps_set_parameters(void *service, audio_io_handle_t io_handle, |
| 2640 | const char *kv_pairs, int delay_ms); |
| 2641 | int aps_set_stream_volume(void *service, audio_stream_type_t stream, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 2642 | float volume, audio_io_handle_t output, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 2643 | int delay_ms); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 2644 | int aps_set_voice_volume(void *service, float volume, int delay_ms); |
| 2645 | }; |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 2646 | |
Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 2647 | } // namespace android |