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