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