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