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