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