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