Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 17 | #include <memory> |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 18 | #include <string> |
Mikhail Naganov | 21b4336 | 2018-06-04 10:37:09 -0700 | [diff] [blame] | 19 | #include <sys/wait.h> |
| 20 | #include <unistd.h> |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 21 | |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 22 | #include <gtest/gtest.h> |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 23 | #include <gmock/gmock.h> |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 24 | |
Mikhail Naganov | 21b4336 | 2018-06-04 10:37:09 -0700 | [diff] [blame] | 25 | #define LOG_TAG "APM_Test" |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 26 | #include <Serializer.h> |
| 27 | #include <android-base/file.h> |
| 28 | #include <media/AudioPolicy.h> |
Mikhail Naganov | dc76968 | 2018-05-04 15:34:08 -0700 | [diff] [blame] | 29 | #include <media/PatchBuilder.h> |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 30 | #include <media/RecordingActivityTracker.h> |
| 31 | #include <utils/Log.h> |
| 32 | #include <utils/Vector.h> |
Mikhail Naganov | dc76968 | 2018-05-04 15:34:08 -0700 | [diff] [blame] | 33 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 34 | #include "AudioPolicyInterface.h" |
jiabin | b3f9804 | 2019-09-26 17:56:44 -0700 | [diff] [blame] | 35 | #include "AudioPolicyManagerTestClient.h" |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 36 | #include "AudioPolicyTestClient.h" |
| 37 | #include "AudioPolicyTestManager.h" |
| 38 | |
| 39 | using namespace android; |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 40 | using testing::UnorderedElementsAre; |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 41 | |
Mikhail Naganov | 4783555 | 2019-05-14 10:32:51 -0700 | [diff] [blame] | 42 | TEST(AudioPolicyManagerTestInit, EngineFailure) { |
| 43 | AudioPolicyTestClient client; |
| 44 | AudioPolicyTestManager manager(&client); |
| 45 | manager.getConfig().setDefault(); |
| 46 | manager.getConfig().setEngineLibraryNameSuffix("non-existent"); |
| 47 | ASSERT_EQ(NO_INIT, manager.initialize()); |
| 48 | ASSERT_EQ(NO_INIT, manager.initCheck()); |
| 49 | } |
| 50 | |
| 51 | TEST(AudioPolicyManagerTestInit, ClientFailure) { |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 52 | AudioPolicyTestClient client; |
| 53 | AudioPolicyTestManager manager(&client); |
| 54 | manager.getConfig().setDefault(); |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 55 | // Since the default client fails to open anything, |
| 56 | // APM should indicate that the initialization didn't succeed. |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 57 | ASSERT_EQ(NO_INIT, manager.initialize()); |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 58 | ASSERT_EQ(NO_INIT, manager.initCheck()); |
| 59 | } |
| 60 | |
Mikhail Naganov | 946c003 | 2020-10-21 13:04:58 -0700 | [diff] [blame] | 61 | // Verifies that a failure while loading a config doesn't leave |
| 62 | // APM config in a "dirty" state. Since AudioPolicyConfig object |
| 63 | // is a proxy for the data hosted by APM, it isn't possible |
| 64 | // to "deep copy" it, and thus we have to test its elements |
| 65 | // individually. |
| 66 | TEST(AudioPolicyManagerTestInit, ConfigLoadingIsTransactional) { |
| 67 | AudioPolicyTestClient client; |
| 68 | AudioPolicyTestManager manager(&client); |
| 69 | ASSERT_TRUE(manager.getConfig().getHwModules().isEmpty()); |
| 70 | ASSERT_TRUE(manager.getConfig().getInputDevices().isEmpty()); |
| 71 | ASSERT_TRUE(manager.getConfig().getOutputDevices().isEmpty()); |
| 72 | status_t status = deserializeAudioPolicyFile( |
| 73 | (base::GetExecutableDirectory() + |
| 74 | "/test_invalid_audio_policy_configuration.xml").c_str(), |
| 75 | &manager.getConfig()); |
| 76 | ASSERT_NE(NO_ERROR, status); |
| 77 | EXPECT_TRUE(manager.getConfig().getHwModules().isEmpty()); |
| 78 | EXPECT_TRUE(manager.getConfig().getInputDevices().isEmpty()); |
| 79 | EXPECT_TRUE(manager.getConfig().getOutputDevices().isEmpty()); |
| 80 | status = deserializeAudioPolicyFile( |
| 81 | (base::GetExecutableDirectory() + "/test_audio_policy_configuration.xml").c_str(), |
| 82 | &manager.getConfig()); |
| 83 | ASSERT_EQ(NO_ERROR, status); |
| 84 | EXPECT_FALSE(manager.getConfig().getHwModules().isEmpty()); |
| 85 | EXPECT_FALSE(manager.getConfig().getInputDevices().isEmpty()); |
| 86 | EXPECT_FALSE(manager.getConfig().getOutputDevices().isEmpty()); |
| 87 | } |
| 88 | |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 89 | |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 90 | class PatchCountCheck { |
| 91 | public: |
| 92 | explicit PatchCountCheck(AudioPolicyManagerTestClient *client) |
| 93 | : mClient{client}, |
| 94 | mInitialCount{mClient->getActivePatchesCount()} {} |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 95 | int deltaFromSnapshot() const { |
| 96 | size_t currentCount = mClient->getActivePatchesCount(); |
| 97 | if (mInitialCount <= currentCount) { |
| 98 | return currentCount - mInitialCount; |
| 99 | } else { |
| 100 | return -(static_cast<int>(mInitialCount - currentCount)); |
| 101 | } |
| 102 | } |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 103 | private: |
| 104 | const AudioPolicyManagerTestClient *mClient; |
| 105 | const size_t mInitialCount; |
| 106 | }; |
| 107 | |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 108 | class AudioPolicyManagerTest : public testing::Test { |
| 109 | protected: |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 110 | void SetUp() override; |
| 111 | void TearDown() override; |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 112 | virtual void SetUpManagerConfig(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 113 | |
| 114 | void dumpToLog(); |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 115 | // When explicit routing is needed, selectedDeviceId needs to be set as the wanted port |
| 116 | // id. Otherwise, selectedDeviceId needs to be initialized as AUDIO_PORT_HANDLE_NONE. |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 117 | void getOutputForAttr( |
| 118 | audio_port_handle_t *selectedDeviceId, |
| 119 | audio_format_t format, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 120 | audio_channel_mask_t channelMask, |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 121 | int sampleRate, |
| 122 | audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE, |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 123 | audio_io_handle_t *output = nullptr, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 124 | audio_port_handle_t *portId = nullptr, |
| 125 | audio_attributes_t attr = {}); |
| 126 | void getInputForAttr( |
| 127 | const audio_attributes_t &attr, |
| 128 | audio_unique_id_t riid, |
| 129 | audio_port_handle_t *selectedDeviceId, |
| 130 | audio_format_t format, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 131 | audio_channel_mask_t channelMask, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 132 | int sampleRate, |
| 133 | audio_input_flags_t flags = AUDIO_INPUT_FLAG_NONE, |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 134 | audio_port_handle_t *portId = nullptr); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 135 | PatchCountCheck snapshotPatchCount() { return PatchCountCheck(mClient.get()); } |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 136 | |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 137 | // Tries to find a device port. If 'foundPort' isn't nullptr, |
| 138 | // will generate a failure if the port hasn't been found. |
| 139 | bool findDevicePort(audio_port_role_t role, audio_devices_t deviceType, |
| 140 | const std::string &address, audio_port *foundPort); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 141 | static audio_port_handle_t getDeviceIdFromPatch(const struct audio_patch* patch); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 142 | |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 143 | std::unique_ptr<AudioPolicyManagerTestClient> mClient; |
| 144 | std::unique_ptr<AudioPolicyTestManager> mManager; |
| 145 | }; |
| 146 | |
| 147 | void AudioPolicyManagerTest::SetUp() { |
| 148 | mClient.reset(new AudioPolicyManagerTestClient); |
| 149 | mManager.reset(new AudioPolicyTestManager(mClient.get())); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 150 | SetUpManagerConfig(); // Subclasses may want to customize the config. |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 151 | ASSERT_EQ(NO_ERROR, mManager->initialize()); |
| 152 | ASSERT_EQ(NO_ERROR, mManager->initCheck()); |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 153 | } |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 154 | |
| 155 | void AudioPolicyManagerTest::TearDown() { |
| 156 | mManager.reset(); |
| 157 | mClient.reset(); |
| 158 | } |
| 159 | |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 160 | void AudioPolicyManagerTest::SetUpManagerConfig() { |
| 161 | mManager->getConfig().setDefault(); |
| 162 | } |
| 163 | |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 164 | void AudioPolicyManagerTest::dumpToLog() { |
Mikhail Naganov | 21b4336 | 2018-06-04 10:37:09 -0700 | [diff] [blame] | 165 | int pipefd[2]; |
| 166 | ASSERT_NE(-1, pipe(pipefd)); |
| 167 | pid_t cpid = fork(); |
| 168 | ASSERT_NE(-1, cpid); |
| 169 | if (cpid == 0) { |
| 170 | // Child process reads from the pipe and logs. |
| 171 | close(pipefd[1]); |
| 172 | std::string line; |
| 173 | char buf; |
| 174 | while (read(pipefd[0], &buf, sizeof(buf)) > 0) { |
| 175 | if (buf != '\n') { |
| 176 | line += buf; |
| 177 | } else { |
| 178 | ALOGI("%s", line.c_str()); |
| 179 | line = ""; |
| 180 | } |
| 181 | } |
| 182 | if (!line.empty()) ALOGI("%s", line.c_str()); |
| 183 | close(pipefd[0]); |
| 184 | _exit(EXIT_SUCCESS); |
| 185 | } else { |
| 186 | // Parent does the dump and checks the status code. |
| 187 | close(pipefd[0]); |
| 188 | ASSERT_EQ(NO_ERROR, mManager->dump(pipefd[1])); |
| 189 | close(pipefd[1]); |
| 190 | wait(NULL); // Wait for the child to exit. |
| 191 | } |
| 192 | } |
| 193 | |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 194 | void AudioPolicyManagerTest::getOutputForAttr( |
| 195 | audio_port_handle_t *selectedDeviceId, |
| 196 | audio_format_t format, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 197 | audio_channel_mask_t channelMask, |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 198 | int sampleRate, |
| 199 | audio_output_flags_t flags, |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 200 | audio_io_handle_t *output, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 201 | audio_port_handle_t *portId, |
| 202 | audio_attributes_t attr) { |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 203 | audio_io_handle_t localOutput; |
| 204 | if (!output) output = &localOutput; |
| 205 | *output = AUDIO_IO_HANDLE_NONE; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 206 | audio_stream_type_t stream = AUDIO_STREAM_DEFAULT; |
| 207 | audio_config_t config = AUDIO_CONFIG_INITIALIZER; |
| 208 | config.sample_rate = sampleRate; |
| 209 | config.channel_mask = channelMask; |
| 210 | config.format = format; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 211 | audio_port_handle_t localPortId; |
| 212 | if (!portId) portId = &localPortId; |
| 213 | *portId = AUDIO_PORT_HANDLE_NONE; |
Eric Laurent | 8a1095a | 2019-11-08 14:44:16 -0800 | [diff] [blame] | 214 | AudioPolicyInterface::output_type_t outputType; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 215 | ASSERT_EQ(OK, mManager->getOutputForAttr( |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 216 | &attr, output, AUDIO_SESSION_NONE, &stream, 0 /*uid*/, &config, &flags, |
Eric Laurent | 8a1095a | 2019-11-08 14:44:16 -0800 | [diff] [blame] | 217 | selectedDeviceId, portId, {}, &outputType)); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 218 | ASSERT_NE(AUDIO_PORT_HANDLE_NONE, *portId); |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 219 | ASSERT_NE(AUDIO_IO_HANDLE_NONE, *output); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 220 | } |
| 221 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 222 | void AudioPolicyManagerTest::getInputForAttr( |
| 223 | const audio_attributes_t &attr, |
| 224 | audio_unique_id_t riid, |
| 225 | audio_port_handle_t *selectedDeviceId, |
| 226 | audio_format_t format, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 227 | audio_channel_mask_t channelMask, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 228 | int sampleRate, |
| 229 | audio_input_flags_t flags, |
| 230 | audio_port_handle_t *portId) { |
| 231 | audio_io_handle_t input = AUDIO_PORT_HANDLE_NONE; |
| 232 | audio_config_base_t config = AUDIO_CONFIG_BASE_INITIALIZER; |
| 233 | config.sample_rate = sampleRate; |
| 234 | config.channel_mask = channelMask; |
| 235 | config.format = format; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 236 | audio_port_handle_t localPortId; |
| 237 | if (!portId) portId = &localPortId; |
| 238 | *portId = AUDIO_PORT_HANDLE_NONE; |
| 239 | AudioPolicyInterface::input_type_t inputType; |
| 240 | ASSERT_EQ(OK, mManager->getInputForAttr( |
| 241 | &attr, &input, riid, AUDIO_SESSION_NONE, 0 /*uid*/, &config, flags, |
| 242 | selectedDeviceId, &inputType, portId)); |
| 243 | ASSERT_NE(AUDIO_PORT_HANDLE_NONE, *portId); |
| 244 | } |
| 245 | |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 246 | bool AudioPolicyManagerTest::findDevicePort(audio_port_role_t role, |
| 247 | audio_devices_t deviceType, const std::string &address, audio_port *foundPort) { |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 248 | uint32_t numPorts = 0; |
| 249 | uint32_t generation1; |
| 250 | status_t ret; |
| 251 | |
| 252 | ret = mManager->listAudioPorts(role, AUDIO_PORT_TYPE_DEVICE, &numPorts, nullptr, &generation1); |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 253 | EXPECT_EQ(NO_ERROR, ret) << "mManager->listAudioPorts returned error"; |
| 254 | if (HasFailure()) return false; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 255 | |
| 256 | uint32_t generation2; |
| 257 | struct audio_port ports[numPorts]; |
| 258 | ret = mManager->listAudioPorts(role, AUDIO_PORT_TYPE_DEVICE, &numPorts, ports, &generation2); |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 259 | EXPECT_EQ(NO_ERROR, ret) << "mManager->listAudioPorts returned error"; |
| 260 | EXPECT_EQ(generation1, generation2) << "Generations changed during ports retrieval"; |
| 261 | if (HasFailure()) return false; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 262 | |
| 263 | for (const auto &port : ports) { |
| 264 | if (port.role == role && port.ext.device.type == deviceType && |
| 265 | (strncmp(port.ext.device.address, address.c_str(), |
| 266 | AUDIO_DEVICE_MAX_ADDRESS_LEN) == 0)) { |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 267 | if (foundPort) *foundPort = port; |
| 268 | return true; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 269 | } |
| 270 | } |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 271 | if (foundPort) { |
| 272 | ADD_FAILURE() << "Device port with role " << role << " and address " |
| 273 | << address << " not found"; |
| 274 | } |
| 275 | return false; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 276 | } |
| 277 | |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 278 | audio_port_handle_t AudioPolicyManagerTest::getDeviceIdFromPatch( |
| 279 | const struct audio_patch* patch) { |
| 280 | // The logic here is the same as the one in AudioIoDescriptor. |
| 281 | // Note this function is aim to get routed device id for test. |
| 282 | // In that case, device to device patch is not expected here. |
| 283 | if (patch->num_sources != 0 && patch->num_sinks != 0) { |
| 284 | if (patch->sources[0].type == AUDIO_PORT_TYPE_MIX) { |
| 285 | return patch->sinks[0].id; |
| 286 | } else { |
| 287 | return patch->sources[0].id; |
| 288 | } |
| 289 | } |
| 290 | return AUDIO_PORT_HANDLE_NONE; |
| 291 | } |
| 292 | |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 293 | |
| 294 | TEST_F(AudioPolicyManagerTest, InitSuccess) { |
| 295 | // SetUp must finish with no assertions. |
| 296 | } |
| 297 | |
| 298 | TEST_F(AudioPolicyManagerTest, Dump) { |
| 299 | dumpToLog(); |
| 300 | } |
| 301 | |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 302 | TEST_F(AudioPolicyManagerTest, CreateAudioPatchFailure) { |
| 303 | audio_patch patch{}; |
| 304 | audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE; |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 305 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 306 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(nullptr, &handle, 0)); |
| 307 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(&patch, nullptr, 0)); |
| 308 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(&patch, &handle, 0)); |
| 309 | patch.num_sources = AUDIO_PATCH_PORTS_MAX + 1; |
| 310 | patch.num_sinks = 1; |
| 311 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(&patch, &handle, 0)); |
| 312 | patch.num_sources = 1; |
| 313 | patch.num_sinks = AUDIO_PATCH_PORTS_MAX + 1; |
| 314 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(&patch, &handle, 0)); |
| 315 | patch.num_sources = 2; |
| 316 | patch.num_sinks = 1; |
| 317 | ASSERT_EQ(INVALID_OPERATION, mManager->createAudioPatch(&patch, &handle, 0)); |
| 318 | patch = {}; |
| 319 | patch.num_sources = 1; |
| 320 | patch.sources[0].role = AUDIO_PORT_ROLE_SINK; |
| 321 | patch.num_sinks = 1; |
| 322 | patch.sinks[0].role = AUDIO_PORT_ROLE_SINK; |
| 323 | ASSERT_EQ(INVALID_OPERATION, mManager->createAudioPatch(&patch, &handle, 0)); |
| 324 | patch = {}; |
| 325 | patch.num_sources = 1; |
| 326 | patch.sources[0].role = AUDIO_PORT_ROLE_SOURCE; |
| 327 | patch.num_sinks = 1; |
| 328 | patch.sinks[0].role = AUDIO_PORT_ROLE_SOURCE; |
| 329 | ASSERT_EQ(INVALID_OPERATION, mManager->createAudioPatch(&patch, &handle, 0)); |
| 330 | // Verify that the handle is left unchanged. |
| 331 | ASSERT_EQ(AUDIO_PATCH_HANDLE_NONE, handle); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 332 | ASSERT_EQ(0, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | TEST_F(AudioPolicyManagerTest, CreateAudioPatchFromMix) { |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 336 | audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE; |
| 337 | uid_t uid = 42; |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 338 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | c0d0498 | 2020-03-02 21:02:28 +0000 | [diff] [blame] | 339 | ASSERT_FALSE(mManager->getAvailableInputDevices().isEmpty()); |
Mikhail Naganov | dc76968 | 2018-05-04 15:34:08 -0700 | [diff] [blame] | 340 | PatchBuilder patchBuilder; |
Mikhail Naganov | c0d0498 | 2020-03-02 21:02:28 +0000 | [diff] [blame] | 341 | patchBuilder.addSource(mManager->getAvailableInputDevices()[0]). |
Mikhail Naganov | dc76968 | 2018-05-04 15:34:08 -0700 | [diff] [blame] | 342 | addSink(mManager->getConfig().getDefaultOutputDevice()); |
| 343 | ASSERT_EQ(NO_ERROR, mManager->createAudioPatch(patchBuilder.patch(), &handle, uid)); |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 344 | ASSERT_NE(AUDIO_PATCH_HANDLE_NONE, handle); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 345 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | // TODO: Add patch creation tests that involve already existing patch |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 349 | |
| 350 | class AudioPolicyManagerTestMsd : public AudioPolicyManagerTest { |
| 351 | protected: |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 352 | void SetUpManagerConfig() override; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 353 | void TearDown() override; |
| 354 | |
| 355 | sp<DeviceDescriptor> mMsdOutputDevice; |
| 356 | sp<DeviceDescriptor> mMsdInputDevice; |
| 357 | }; |
| 358 | |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 359 | void AudioPolicyManagerTestMsd::SetUpManagerConfig() { |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 360 | // TODO: Consider using Serializer to load part of the config from a string. |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 361 | AudioPolicyManagerTest::SetUpManagerConfig(); |
| 362 | AudioPolicyConfig& config = mManager->getConfig(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 363 | mMsdOutputDevice = new DeviceDescriptor(AUDIO_DEVICE_OUT_BUS); |
| 364 | sp<AudioProfile> pcmOutputProfile = new AudioProfile( |
| 365 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, 48000); |
| 366 | sp<AudioProfile> ac3OutputProfile = new AudioProfile( |
| 367 | AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, 48000); |
| 368 | mMsdOutputDevice->addAudioProfile(pcmOutputProfile); |
| 369 | mMsdOutputDevice->addAudioProfile(ac3OutputProfile); |
| 370 | mMsdInputDevice = new DeviceDescriptor(AUDIO_DEVICE_IN_BUS); |
| 371 | // Match output profile from AudioPolicyConfig::setDefault. |
| 372 | sp<AudioProfile> pcmInputProfile = new AudioProfile( |
| 373 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_STEREO, 44100); |
| 374 | mMsdInputDevice->addAudioProfile(pcmInputProfile); |
Mikhail Naganov | c0d0498 | 2020-03-02 21:02:28 +0000 | [diff] [blame] | 375 | config.addDevice(mMsdOutputDevice); |
| 376 | config.addDevice(mMsdInputDevice); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 377 | |
| 378 | sp<HwModule> msdModule = new HwModule(AUDIO_HARDWARE_MODULE_ID_MSD, 2 /*halVersionMajor*/); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 379 | HwModuleCollection modules = config.getHwModules(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 380 | modules.add(msdModule); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 381 | config.setHwModules(modules); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 382 | |
jiabin | 5740f08 | 2019-08-19 15:08:30 -0700 | [diff] [blame] | 383 | sp<OutputProfile> msdOutputProfile = new OutputProfile("msd input"); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 384 | msdOutputProfile->addAudioProfile(pcmOutputProfile); |
| 385 | msdOutputProfile->addSupportedDevice(mMsdOutputDevice); |
| 386 | msdModule->addOutputProfile(msdOutputProfile); |
jiabin | 5740f08 | 2019-08-19 15:08:30 -0700 | [diff] [blame] | 387 | sp<OutputProfile> msdCompressedOutputProfile = new OutputProfile("msd compressed input"); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 388 | msdCompressedOutputProfile->addAudioProfile(ac3OutputProfile); |
| 389 | msdCompressedOutputProfile->setFlags( |
| 390 | AUDIO_OUTPUT_FLAG_DIRECT | AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD | |
| 391 | AUDIO_OUTPUT_FLAG_NON_BLOCKING); |
| 392 | msdCompressedOutputProfile->addSupportedDevice(mMsdOutputDevice); |
| 393 | msdModule->addOutputProfile(msdCompressedOutputProfile); |
| 394 | |
jiabin | 5740f08 | 2019-08-19 15:08:30 -0700 | [diff] [blame] | 395 | sp<InputProfile> msdInputProfile = new InputProfile("msd output"); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 396 | msdInputProfile->addAudioProfile(pcmInputProfile); |
| 397 | msdInputProfile->addSupportedDevice(mMsdInputDevice); |
| 398 | msdModule->addInputProfile(msdInputProfile); |
| 399 | |
| 400 | // Add a profile with another encoding to the default device to test routing |
| 401 | // of streams that are not supported by MSD. |
| 402 | sp<AudioProfile> dtsOutputProfile = new AudioProfile( |
| 403 | AUDIO_FORMAT_DTS, AUDIO_CHANNEL_OUT_5POINT1, 48000); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 404 | config.getDefaultOutputDevice()->addAudioProfile(dtsOutputProfile); |
jiabin | 5740f08 | 2019-08-19 15:08:30 -0700 | [diff] [blame] | 405 | sp<OutputProfile> primaryEncodedOutputProfile = new OutputProfile("encoded"); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 406 | primaryEncodedOutputProfile->addAudioProfile(dtsOutputProfile); |
| 407 | primaryEncodedOutputProfile->setFlags(AUDIO_OUTPUT_FLAG_DIRECT); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 408 | primaryEncodedOutputProfile->addSupportedDevice(config.getDefaultOutputDevice()); |
| 409 | config.getHwModules().getModuleFromName(AUDIO_HARDWARE_MODULE_ID_PRIMARY)-> |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 410 | addOutputProfile(primaryEncodedOutputProfile); |
| 411 | } |
| 412 | |
| 413 | void AudioPolicyManagerTestMsd::TearDown() { |
| 414 | mMsdOutputDevice.clear(); |
| 415 | mMsdInputDevice.clear(); |
| 416 | AudioPolicyManagerTest::TearDown(); |
| 417 | } |
| 418 | |
| 419 | TEST_F(AudioPolicyManagerTestMsd, InitSuccess) { |
| 420 | ASSERT_TRUE(mMsdOutputDevice); |
| 421 | ASSERT_TRUE(mMsdInputDevice); |
| 422 | } |
| 423 | |
| 424 | TEST_F(AudioPolicyManagerTestMsd, Dump) { |
| 425 | dumpToLog(); |
| 426 | } |
| 427 | |
| 428 | TEST_F(AudioPolicyManagerTestMsd, PatchCreationOnSetForceUse) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 429 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 430 | mManager->setForceUse(AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND, |
| 431 | AUDIO_POLICY_FORCE_ENCODED_SURROUND_ALWAYS); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 432 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | TEST_F(AudioPolicyManagerTestMsd, GetOutputForAttrEncodedRoutesToMsd) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 436 | const PatchCountCheck patchCount = snapshotPatchCount(); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 437 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 438 | getOutputForAttr(&selectedDeviceId, |
| 439 | AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, 48000, AUDIO_OUTPUT_FLAG_DIRECT); |
| 440 | ASSERT_EQ(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 441 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | TEST_F(AudioPolicyManagerTestMsd, GetOutputForAttrPcmRoutesToMsd) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 445 | const PatchCountCheck patchCount = snapshotPatchCount(); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 446 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 447 | getOutputForAttr(&selectedDeviceId, |
| 448 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, 48000); |
| 449 | ASSERT_EQ(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 450 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | TEST_F(AudioPolicyManagerTestMsd, GetOutputForAttrEncodedPlusPcmRoutesToMsd) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 454 | const PatchCountCheck patchCount = snapshotPatchCount(); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 455 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 456 | getOutputForAttr(&selectedDeviceId, |
| 457 | AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, 48000, AUDIO_OUTPUT_FLAG_DIRECT); |
| 458 | ASSERT_EQ(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 459 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 460 | getOutputForAttr(&selectedDeviceId, |
| 461 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, 48000); |
| 462 | ASSERT_EQ(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 463 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | TEST_F(AudioPolicyManagerTestMsd, GetOutputForAttrUnsupportedFormatBypassesMsd) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 467 | const PatchCountCheck patchCount = snapshotPatchCount(); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 468 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 469 | getOutputForAttr(&selectedDeviceId, |
| 470 | AUDIO_FORMAT_DTS, AUDIO_CHANNEL_OUT_5POINT1, 48000, AUDIO_OUTPUT_FLAG_DIRECT); |
| 471 | ASSERT_NE(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 472 | ASSERT_EQ(0, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | TEST_F(AudioPolicyManagerTestMsd, GetOutputForAttrFormatSwitching) { |
| 476 | // Switch between formats that are supported and not supported by MSD. |
| 477 | { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 478 | const PatchCountCheck patchCount = snapshotPatchCount(); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 479 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 480 | audio_port_handle_t portId; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 481 | getOutputForAttr(&selectedDeviceId, |
| 482 | AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, 48000, AUDIO_OUTPUT_FLAG_DIRECT, |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 483 | nullptr /*output*/, &portId); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 484 | ASSERT_EQ(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 485 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 486 | mManager->releaseOutput(portId); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 487 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 488 | } |
| 489 | { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 490 | const PatchCountCheck patchCount = snapshotPatchCount(); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 491 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 492 | audio_port_handle_t portId; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 493 | getOutputForAttr(&selectedDeviceId, |
| 494 | AUDIO_FORMAT_DTS, AUDIO_CHANNEL_OUT_5POINT1, 48000, AUDIO_OUTPUT_FLAG_DIRECT, |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 495 | nullptr /*output*/, &portId); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 496 | ASSERT_NE(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 497 | ASSERT_EQ(-1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 498 | mManager->releaseOutput(portId); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 499 | ASSERT_EQ(0, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 500 | } |
| 501 | { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 502 | const PatchCountCheck patchCount = snapshotPatchCount(); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 503 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 504 | getOutputForAttr(&selectedDeviceId, |
| 505 | AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, 48000, AUDIO_OUTPUT_FLAG_DIRECT); |
| 506 | ASSERT_EQ(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 507 | ASSERT_EQ(0, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 508 | } |
| 509 | } |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 510 | |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 511 | class AudioPolicyManagerTestWithConfigurationFile : public AudioPolicyManagerTest { |
| 512 | protected: |
| 513 | void SetUpManagerConfig() override; |
| 514 | virtual std::string getConfigFile() { return sDefaultConfig; } |
| 515 | |
| 516 | static const std::string sExecutableDir; |
| 517 | static const std::string sDefaultConfig; |
| 518 | }; |
| 519 | |
| 520 | const std::string AudioPolicyManagerTestWithConfigurationFile::sExecutableDir = |
| 521 | base::GetExecutableDirectory() + "/"; |
| 522 | |
| 523 | const std::string AudioPolicyManagerTestWithConfigurationFile::sDefaultConfig = |
| 524 | sExecutableDir + "test_audio_policy_configuration.xml"; |
| 525 | |
| 526 | void AudioPolicyManagerTestWithConfigurationFile::SetUpManagerConfig() { |
| 527 | status_t status = deserializeAudioPolicyFile(getConfigFile().c_str(), &mManager->getConfig()); |
| 528 | ASSERT_EQ(NO_ERROR, status); |
| 529 | } |
| 530 | |
| 531 | TEST_F(AudioPolicyManagerTestWithConfigurationFile, InitSuccess) { |
| 532 | // SetUp must finish with no assertions. |
| 533 | } |
| 534 | |
| 535 | TEST_F(AudioPolicyManagerTestWithConfigurationFile, Dump) { |
| 536 | dumpToLog(); |
| 537 | } |
| 538 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 539 | using PolicyMixTuple = std::tuple<audio_usage_t, audio_source_t, uint32_t>; |
| 540 | |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 541 | class AudioPolicyManagerTestDynamicPolicy : public AudioPolicyManagerTestWithConfigurationFile { |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 542 | protected: |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 543 | void TearDown() override; |
| 544 | |
| 545 | status_t addPolicyMix(int mixType, int mixFlag, audio_devices_t deviceType, |
| 546 | std::string mixAddress, const audio_config_t& audioConfig, |
| 547 | const std::vector<PolicyMixTuple>& rules); |
| 548 | void clearPolicyMix(); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 549 | |
| 550 | Vector<AudioMix> mAudioMixes; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 551 | const std::string mMixAddress = "remote_submix_media"; |
| 552 | }; |
| 553 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 554 | void AudioPolicyManagerTestDynamicPolicy::TearDown() { |
| 555 | mManager->unregisterPolicyMixes(mAudioMixes); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 556 | AudioPolicyManagerTestWithConfigurationFile::TearDown(); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | status_t AudioPolicyManagerTestDynamicPolicy::addPolicyMix(int mixType, int mixFlag, |
| 560 | audio_devices_t deviceType, std::string mixAddress, const audio_config_t& audioConfig, |
| 561 | const std::vector<PolicyMixTuple>& rules) { |
| 562 | Vector<AudioMixMatchCriterion> myMixMatchCriteria; |
| 563 | |
| 564 | for(const auto &rule: rules) { |
| 565 | myMixMatchCriteria.add(AudioMixMatchCriterion( |
| 566 | std::get<0>(rule), std::get<1>(rule), std::get<2>(rule))); |
| 567 | } |
| 568 | |
| 569 | AudioMix myAudioMix(myMixMatchCriteria, mixType, audioConfig, mixFlag, |
| 570 | String8(mixAddress.c_str()), 0); |
| 571 | myAudioMix.mDeviceType = deviceType; |
| 572 | // Clear mAudioMix before add new one to make sure we don't add already exist mixes. |
| 573 | mAudioMixes.clear(); |
| 574 | mAudioMixes.add(myAudioMix); |
| 575 | |
| 576 | // As the policy mixes registration may fail at some case, |
| 577 | // caller need to check the returned status. |
| 578 | status_t ret = mManager->registerPolicyMixes(mAudioMixes); |
| 579 | return ret; |
| 580 | } |
| 581 | |
| 582 | void AudioPolicyManagerTestDynamicPolicy::clearPolicyMix() { |
| 583 | if (mManager != nullptr) { |
| 584 | mManager->unregisterPolicyMixes(mAudioMixes); |
| 585 | } |
| 586 | mAudioMixes.clear(); |
| 587 | } |
| 588 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 589 | TEST_F(AudioPolicyManagerTestDynamicPolicy, InitSuccess) { |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 590 | // SetUp must finish with no assertions |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | TEST_F(AudioPolicyManagerTestDynamicPolicy, Dump) { |
| 594 | dumpToLog(); |
| 595 | } |
| 596 | |
| 597 | TEST_F(AudioPolicyManagerTestDynamicPolicy, RegisterPolicyMixes) { |
| 598 | status_t ret; |
| 599 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 600 | |
| 601 | // Only capture of playback is allowed in LOOP_BACK &RENDER mode |
| 602 | ret = addPolicyMix(MIX_TYPE_RECORDERS, MIX_ROUTE_FLAG_LOOP_BACK_AND_RENDER, |
| 603 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, "", audioConfig, std::vector<PolicyMixTuple>()); |
| 604 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 605 | |
| 606 | // Fail due to the device is already connected. |
| 607 | clearPolicyMix(); |
| 608 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 609 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, "", audioConfig, std::vector<PolicyMixTuple>()); |
| 610 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 611 | |
| 612 | // The first time to register policy mixes with valid parameter should succeed. |
| 613 | clearPolicyMix(); |
| 614 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 615 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 616 | audioConfig.sample_rate = 48000; |
| 617 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 618 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, mMixAddress, audioConfig, |
| 619 | std::vector<PolicyMixTuple>()); |
| 620 | ASSERT_EQ(NO_ERROR, ret); |
| 621 | // Registering the same policy mixes should fail. |
| 622 | ret = mManager->registerPolicyMixes(mAudioMixes); |
| 623 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 624 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 625 | // Registration should fail due to device not found. |
| 626 | // Note that earpiece is not present in the test configuration file. |
| 627 | // This will need to be updated if earpiece is added in the test configuration file. |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 628 | clearPolicyMix(); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 629 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 630 | AUDIO_DEVICE_OUT_EARPIECE, "", audioConfig, std::vector<PolicyMixTuple>()); |
| 631 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 632 | |
| 633 | // Registration should fail due to output not found. |
| 634 | clearPolicyMix(); |
| 635 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 636 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, "", audioConfig, std::vector<PolicyMixTuple>()); |
| 637 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 638 | |
| 639 | // The first time to register valid policy mixes should succeed. |
| 640 | clearPolicyMix(); |
| 641 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 642 | AUDIO_DEVICE_OUT_SPEAKER, "", audioConfig, std::vector<PolicyMixTuple>()); |
| 643 | ASSERT_EQ(NO_ERROR, ret); |
| 644 | // Registering the same policy mixes should fail. |
| 645 | ret = mManager->registerPolicyMixes(mAudioMixes); |
| 646 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 647 | } |
| 648 | |
| 649 | TEST_F(AudioPolicyManagerTestDynamicPolicy, UnregisterPolicyMixes) { |
| 650 | status_t ret; |
| 651 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 652 | |
| 653 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 654 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 655 | audioConfig.sample_rate = 48000; |
| 656 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 657 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, mMixAddress, audioConfig, |
| 658 | std::vector<PolicyMixTuple>()); |
| 659 | ASSERT_EQ(NO_ERROR, ret); |
| 660 | |
| 661 | // After successfully registering policy mixes, it should be able to unregister. |
| 662 | ret = mManager->unregisterPolicyMixes(mAudioMixes); |
| 663 | ASSERT_EQ(NO_ERROR, ret); |
| 664 | |
| 665 | // After unregistering policy mixes successfully, it should fail unregistering |
| 666 | // the same policy mixes as they are not registered. |
| 667 | ret = mManager->unregisterPolicyMixes(mAudioMixes); |
| 668 | ASSERT_EQ(INVALID_OPERATION, ret); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 669 | } |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 670 | |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 671 | class AudioPolicyManagerTestDPNoRemoteSubmixModule : public AudioPolicyManagerTestDynamicPolicy { |
| 672 | protected: |
| 673 | std::string getConfigFile() override { return sPrimaryOnlyConfig; } |
| 674 | |
| 675 | static const std::string sPrimaryOnlyConfig; |
| 676 | }; |
| 677 | |
| 678 | const std::string AudioPolicyManagerTestDPNoRemoteSubmixModule::sPrimaryOnlyConfig = |
| 679 | sExecutableDir + "test_audio_policy_primary_only_configuration.xml"; |
| 680 | |
| 681 | TEST_F(AudioPolicyManagerTestDPNoRemoteSubmixModule, InitSuccess) { |
| 682 | // SetUp must finish with no assertions. |
| 683 | } |
| 684 | |
| 685 | TEST_F(AudioPolicyManagerTestDPNoRemoteSubmixModule, Dump) { |
| 686 | dumpToLog(); |
| 687 | } |
| 688 | |
| 689 | TEST_F(AudioPolicyManagerTestDPNoRemoteSubmixModule, RegistrationFailure) { |
| 690 | // Registration/Unregistration should fail due to module for remote submix not found. |
| 691 | status_t ret; |
| 692 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 693 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 694 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 695 | audioConfig.sample_rate = 48000; |
| 696 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 697 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, "", audioConfig, std::vector<PolicyMixTuple>()); |
| 698 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 699 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 700 | ret = mManager->unregisterPolicyMixes(mAudioMixes); |
| 701 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 702 | } |
| 703 | |
| 704 | class AudioPolicyManagerTestDPPlaybackReRouting : public AudioPolicyManagerTestDynamicPolicy, |
| 705 | public testing::WithParamInterface<audio_attributes_t> { |
| 706 | protected: |
| 707 | void SetUp() override; |
| 708 | void TearDown() override; |
| 709 | |
| 710 | std::unique_ptr<RecordingActivityTracker> mTracker; |
| 711 | |
| 712 | std::vector<PolicyMixTuple> mUsageRules = { |
| 713 | {AUDIO_USAGE_MEDIA, AUDIO_SOURCE_DEFAULT, RULE_MATCH_ATTRIBUTE_USAGE}, |
| 714 | {AUDIO_USAGE_ALARM, AUDIO_SOURCE_DEFAULT, RULE_MATCH_ATTRIBUTE_USAGE} |
| 715 | }; |
| 716 | |
| 717 | struct audio_port mInjectionPort; |
| 718 | audio_port_handle_t mPortId = AUDIO_PORT_HANDLE_NONE; |
| 719 | }; |
| 720 | |
| 721 | void AudioPolicyManagerTestDPPlaybackReRouting::SetUp() { |
| 722 | AudioPolicyManagerTestDynamicPolicy::SetUp(); |
| 723 | |
| 724 | mTracker.reset(new RecordingActivityTracker()); |
| 725 | |
| 726 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 727 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 728 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 729 | audioConfig.sample_rate = 48000; |
| 730 | status_t ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 731 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, mMixAddress, audioConfig, mUsageRules); |
| 732 | ASSERT_EQ(NO_ERROR, ret); |
| 733 | |
| 734 | struct audio_port extractionPort; |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 735 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SOURCE, AUDIO_DEVICE_IN_REMOTE_SUBMIX, |
| 736 | mMixAddress, &extractionPort)); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 737 | |
| 738 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 739 | audio_source_t source = AUDIO_SOURCE_REMOTE_SUBMIX; |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 740 | audio_attributes_t attr = { |
| 741 | AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, source, AUDIO_FLAG_NONE, ""}; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 742 | std::string tags = "addr=" + mMixAddress; |
| 743 | strncpy(attr.tags, tags.c_str(), AUDIO_ATTRIBUTES_TAGS_MAX_SIZE - 1); |
| 744 | getInputForAttr(attr, mTracker->getRiid(), &selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, |
| 745 | AUDIO_CHANNEL_IN_STEREO, 48000 /*sampleRate*/, AUDIO_INPUT_FLAG_NONE, &mPortId); |
| 746 | ASSERT_EQ(NO_ERROR, mManager->startInput(mPortId)); |
| 747 | ASSERT_EQ(extractionPort.id, selectedDeviceId); |
| 748 | |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 749 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SINK, AUDIO_DEVICE_OUT_REMOTE_SUBMIX, |
| 750 | mMixAddress, &mInjectionPort)); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | void AudioPolicyManagerTestDPPlaybackReRouting::TearDown() { |
| 754 | mManager->stopInput(mPortId); |
| 755 | AudioPolicyManagerTestDynamicPolicy::TearDown(); |
| 756 | } |
| 757 | |
| 758 | TEST_F(AudioPolicyManagerTestDPPlaybackReRouting, InitSuccess) { |
| 759 | // SetUp must finish with no assertions |
| 760 | } |
| 761 | |
| 762 | TEST_F(AudioPolicyManagerTestDPPlaybackReRouting, Dump) { |
| 763 | dumpToLog(); |
| 764 | } |
| 765 | |
| 766 | TEST_P(AudioPolicyManagerTestDPPlaybackReRouting, PlaybackReRouting) { |
| 767 | const audio_attributes_t attr = GetParam(); |
| 768 | const audio_usage_t usage = attr.usage; |
| 769 | |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 770 | audio_port_handle_t playbackRoutedPortId = AUDIO_PORT_HANDLE_NONE; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 771 | getOutputForAttr(&playbackRoutedPortId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 772 | 48000 /*sampleRate*/, AUDIO_OUTPUT_FLAG_NONE, |
| 773 | nullptr /*output*/, nullptr /*portId*/, attr); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 774 | if (std::find_if(begin(mUsageRules), end(mUsageRules), [&usage](const auto &usageRule) { |
| 775 | return (std::get<0>(usageRule) == usage) && |
| 776 | (std::get<2>(usageRule) == RULE_MATCH_ATTRIBUTE_USAGE);}) != end(mUsageRules) || |
| 777 | (strncmp(attr.tags, "addr=", strlen("addr=")) == 0 && |
| 778 | strncmp(attr.tags + strlen("addr="), mMixAddress.c_str(), |
| 779 | AUDIO_ATTRIBUTES_TAGS_MAX_SIZE - strlen("addr=") - 1) == 0)) { |
| 780 | EXPECT_EQ(mInjectionPort.id, playbackRoutedPortId); |
| 781 | } else { |
| 782 | EXPECT_NE(mInjectionPort.id, playbackRoutedPortId); |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | INSTANTIATE_TEST_CASE_P( |
| 787 | PlaybackReroutingUsageMatch, |
| 788 | AudioPolicyManagerTestDPPlaybackReRouting, |
| 789 | testing::Values( |
| 790 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_MEDIA, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 791 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 792 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_ALARM, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 793 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""} |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 794 | ) |
| 795 | ); |
| 796 | |
| 797 | INSTANTIATE_TEST_CASE_P( |
| 798 | PlaybackReroutingAddressPriorityMatch, |
| 799 | AudioPolicyManagerTestDPPlaybackReRouting, |
| 800 | testing::Values( |
| 801 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_MEDIA, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 802 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 803 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_VOICE_COMMUNICATION, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 804 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 805 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 806 | AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING, |
| 807 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 808 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_ALARM, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 809 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 810 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_NOTIFICATION, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 811 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 812 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 813 | AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE, |
| 814 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 815 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 816 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST, |
| 817 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 818 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 819 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT, |
| 820 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 821 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 822 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED, |
| 823 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 824 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_NOTIFICATION_EVENT, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 825 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 826 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 827 | AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY, |
| 828 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 829 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 830 | AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE, |
| 831 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 832 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 833 | AUDIO_USAGE_ASSISTANCE_SONIFICATION, |
| 834 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 835 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_GAME, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 836 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 837 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_VIRTUAL_SOURCE, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 838 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 839 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_ASSISTANT, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 840 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
Baekgyeong Kim | 47ea671 | 2019-10-30 20:29:41 +0900 | [diff] [blame] | 841 | (audio_attributes_t){AUDIO_CONTENT_TYPE_SPEECH, AUDIO_USAGE_ASSISTANT, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 842 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"} |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 843 | ) |
| 844 | ); |
| 845 | |
| 846 | INSTANTIATE_TEST_CASE_P( |
| 847 | PlaybackReroutingUnHandledUsages, |
| 848 | AudioPolicyManagerTestDPPlaybackReRouting, |
| 849 | testing::Values( |
| 850 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_VOICE_COMMUNICATION, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 851 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 852 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 853 | AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 854 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 855 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_NOTIFICATION, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 856 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 857 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 858 | AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 859 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 860 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 861 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 862 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 863 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 864 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 865 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 866 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 867 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 868 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 869 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_NOTIFICATION_EVENT, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 870 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 871 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 872 | AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 873 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 874 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 875 | AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 876 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 877 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 878 | AUDIO_USAGE_ASSISTANCE_SONIFICATION, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 879 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 880 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_GAME, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 881 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 882 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_ASSISTANT, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 883 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
Baekgyeong Kim | 47ea671 | 2019-10-30 20:29:41 +0900 | [diff] [blame] | 884 | (audio_attributes_t){AUDIO_CONTENT_TYPE_SPEECH, AUDIO_USAGE_ASSISTANT, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 885 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""} |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 886 | ) |
| 887 | ); |
| 888 | |
| 889 | class AudioPolicyManagerTestDPMixRecordInjection : public AudioPolicyManagerTestDynamicPolicy, |
| 890 | public testing::WithParamInterface<audio_attributes_t> { |
| 891 | protected: |
| 892 | void SetUp() override; |
| 893 | void TearDown() override; |
| 894 | |
| 895 | std::unique_ptr<RecordingActivityTracker> mTracker; |
| 896 | |
| 897 | std::vector<PolicyMixTuple> mSourceRules = { |
| 898 | {AUDIO_USAGE_UNKNOWN, AUDIO_SOURCE_CAMCORDER, RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET}, |
| 899 | {AUDIO_USAGE_UNKNOWN, AUDIO_SOURCE_MIC, RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET}, |
| 900 | {AUDIO_USAGE_UNKNOWN, AUDIO_SOURCE_VOICE_COMMUNICATION, RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET} |
| 901 | }; |
| 902 | |
| 903 | struct audio_port mExtractionPort; |
| 904 | audio_port_handle_t mPortId = AUDIO_PORT_HANDLE_NONE; |
| 905 | }; |
| 906 | |
| 907 | void AudioPolicyManagerTestDPMixRecordInjection::SetUp() { |
| 908 | AudioPolicyManagerTestDynamicPolicy::SetUp(); |
| 909 | |
| 910 | mTracker.reset(new RecordingActivityTracker()); |
| 911 | |
| 912 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 913 | audioConfig.channel_mask = AUDIO_CHANNEL_IN_STEREO; |
| 914 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 915 | audioConfig.sample_rate = 48000; |
| 916 | status_t ret = addPolicyMix(MIX_TYPE_RECORDERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 917 | AUDIO_DEVICE_IN_REMOTE_SUBMIX, mMixAddress, audioConfig, mSourceRules); |
| 918 | ASSERT_EQ(NO_ERROR, ret); |
| 919 | |
| 920 | struct audio_port injectionPort; |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 921 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SINK, AUDIO_DEVICE_OUT_REMOTE_SUBMIX, |
| 922 | mMixAddress, &injectionPort)); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 923 | |
| 924 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 925 | audio_usage_t usage = AUDIO_USAGE_VIRTUAL_SOURCE; |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 926 | audio_attributes_t attr = |
| 927 | {AUDIO_CONTENT_TYPE_UNKNOWN, usage, AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 928 | std::string tags = std::string("addr=") + mMixAddress; |
| 929 | strncpy(attr.tags, tags.c_str(), AUDIO_ATTRIBUTES_TAGS_MAX_SIZE - 1); |
| 930 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 931 | 48000 /*sampleRate*/, AUDIO_OUTPUT_FLAG_NONE, nullptr /*output*/, &mPortId, attr); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 932 | ASSERT_EQ(NO_ERROR, mManager->startOutput(mPortId)); |
| 933 | ASSERT_EQ(injectionPort.id, getDeviceIdFromPatch(mClient->getLastAddedPatch())); |
| 934 | |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 935 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SOURCE, AUDIO_DEVICE_IN_REMOTE_SUBMIX, |
| 936 | mMixAddress, &mExtractionPort)); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | void AudioPolicyManagerTestDPMixRecordInjection::TearDown() { |
| 940 | mManager->stopOutput(mPortId); |
| 941 | AudioPolicyManagerTestDynamicPolicy::TearDown(); |
| 942 | } |
| 943 | |
| 944 | TEST_F(AudioPolicyManagerTestDPMixRecordInjection, InitSuccess) { |
| 945 | // SetUp mush finish with no assertions. |
| 946 | } |
| 947 | |
| 948 | TEST_F(AudioPolicyManagerTestDPMixRecordInjection, Dump) { |
| 949 | dumpToLog(); |
| 950 | } |
| 951 | |
| 952 | TEST_P(AudioPolicyManagerTestDPMixRecordInjection, RecordingInjection) { |
| 953 | const audio_attributes_t attr = GetParam(); |
| 954 | const audio_source_t source = attr.source; |
| 955 | |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 956 | audio_port_handle_t captureRoutedPortId = AUDIO_PORT_HANDLE_NONE; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 957 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE; |
| 958 | getInputForAttr(attr, mTracker->getRiid(), &captureRoutedPortId, AUDIO_FORMAT_PCM_16_BIT, |
| 959 | AUDIO_CHANNEL_IN_STEREO, 48000 /*sampleRate*/, AUDIO_INPUT_FLAG_NONE, &portId); |
| 960 | if (std::find_if(begin(mSourceRules), end(mSourceRules), [&source](const auto &sourceRule) { |
| 961 | return (std::get<1>(sourceRule) == source) && |
| 962 | (std::get<2>(sourceRule) == RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET);}) |
| 963 | != end(mSourceRules)) { |
| 964 | EXPECT_EQ(mExtractionPort.id, captureRoutedPortId); |
| 965 | } else { |
| 966 | EXPECT_NE(mExtractionPort.id, captureRoutedPortId); |
| 967 | } |
| 968 | } |
| 969 | |
| 970 | // No address priority rule for remote recording, address is a "don't care" |
| 971 | INSTANTIATE_TEST_CASE_P( |
| 972 | RecordInjectionSourceMatch, |
| 973 | AudioPolicyManagerTestDPMixRecordInjection, |
| 974 | testing::Values( |
| 975 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 976 | AUDIO_SOURCE_CAMCORDER, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 977 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 978 | AUDIO_SOURCE_CAMCORDER, AUDIO_FLAG_NONE, |
| 979 | "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 980 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 981 | AUDIO_SOURCE_MIC, AUDIO_FLAG_NONE, |
| 982 | "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 983 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 984 | AUDIO_SOURCE_MIC, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 985 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 986 | AUDIO_SOURCE_VOICE_COMMUNICATION, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 987 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 988 | AUDIO_SOURCE_VOICE_COMMUNICATION, AUDIO_FLAG_NONE, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 989 | "addr=remote_submix_media"} |
| 990 | ) |
| 991 | ); |
| 992 | |
| 993 | // No address priority rule for remote recording |
| 994 | INSTANTIATE_TEST_CASE_P( |
| 995 | RecordInjectionSourceNotMatch, |
| 996 | AudioPolicyManagerTestDPMixRecordInjection, |
| 997 | testing::Values( |
| 998 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 999 | AUDIO_SOURCE_VOICE_RECOGNITION, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1000 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1001 | AUDIO_SOURCE_HOTWORD, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1002 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1003 | AUDIO_SOURCE_VOICE_RECOGNITION, AUDIO_FLAG_NONE, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1004 | "addr=remote_submix_media"}, |
| 1005 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1006 | AUDIO_SOURCE_HOTWORD, AUDIO_FLAG_NONE, |
| 1007 | "addr=remote_submix_media"} |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1008 | ) |
| 1009 | ); |
jiabin | 43848a5 | 2019-09-05 14:07:25 -0700 | [diff] [blame] | 1010 | |
| 1011 | using DeviceConnectionTestParams = |
| 1012 | std::tuple<audio_devices_t /*type*/, std::string /*name*/, std::string /*address*/>; |
| 1013 | |
| 1014 | class AudioPolicyManagerTestDeviceConnection : public AudioPolicyManagerTestWithConfigurationFile, |
| 1015 | public testing::WithParamInterface<DeviceConnectionTestParams> { |
| 1016 | }; |
| 1017 | |
| 1018 | TEST_F(AudioPolicyManagerTestDeviceConnection, InitSuccess) { |
| 1019 | // SetUp must finish with no assertions. |
| 1020 | } |
| 1021 | |
| 1022 | TEST_F(AudioPolicyManagerTestDeviceConnection, Dump) { |
| 1023 | dumpToLog(); |
| 1024 | } |
| 1025 | |
| 1026 | TEST_P(AudioPolicyManagerTestDeviceConnection, SetDeviceConnectionState) { |
| 1027 | const audio_devices_t type = std::get<0>(GetParam()); |
| 1028 | const std::string name = std::get<1>(GetParam()); |
| 1029 | const std::string address = std::get<2>(GetParam()); |
| 1030 | |
| 1031 | if (type == AUDIO_DEVICE_OUT_HDMI) { |
| 1032 | // Set device connection state failed due to no device descriptor found |
| 1033 | // For HDMI case, it is easier to simulate device descriptor not found error |
| 1034 | // by using a undeclared encoded format. |
| 1035 | ASSERT_EQ(INVALID_OPERATION, mManager->setDeviceConnectionState( |
| 1036 | type, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 1037 | address.c_str(), name.c_str(), AUDIO_FORMAT_MAT_2_1)); |
| 1038 | } |
| 1039 | // Connect with valid parameters should succeed |
| 1040 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 1041 | type, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 1042 | address.c_str(), name.c_str(), AUDIO_FORMAT_DEFAULT)); |
| 1043 | // Try to connect with the same device again should fail |
| 1044 | ASSERT_EQ(INVALID_OPERATION, mManager->setDeviceConnectionState( |
| 1045 | type, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 1046 | address.c_str(), name.c_str(), AUDIO_FORMAT_DEFAULT)); |
| 1047 | // Disconnect the connected device should succeed |
| 1048 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 1049 | type, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 1050 | address.c_str(), name.c_str(), AUDIO_FORMAT_DEFAULT)); |
| 1051 | // Disconnect device that is not connected should fail |
| 1052 | ASSERT_EQ(INVALID_OPERATION, mManager->setDeviceConnectionState( |
| 1053 | type, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 1054 | address.c_str(), name.c_str(), AUDIO_FORMAT_DEFAULT)); |
| 1055 | // Try to set device connection state with a invalid connection state should fail |
| 1056 | ASSERT_EQ(BAD_VALUE, mManager->setDeviceConnectionState( |
| 1057 | type, AUDIO_POLICY_DEVICE_STATE_CNT, |
| 1058 | "", "", AUDIO_FORMAT_DEFAULT)); |
| 1059 | } |
| 1060 | |
| 1061 | TEST_P(AudioPolicyManagerTestDeviceConnection, ExplicitlyRoutingAfterConnection) { |
| 1062 | const audio_devices_t type = std::get<0>(GetParam()); |
| 1063 | const std::string name = std::get<1>(GetParam()); |
| 1064 | const std::string address = std::get<2>(GetParam()); |
| 1065 | |
| 1066 | // Connect device to do explicitly routing test |
| 1067 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 1068 | type, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 1069 | address.c_str(), name.c_str(), AUDIO_FORMAT_DEFAULT)); |
| 1070 | |
| 1071 | audio_port devicePort; |
| 1072 | const audio_port_role_t role = audio_is_output_device(type) |
| 1073 | ? AUDIO_PORT_ROLE_SINK : AUDIO_PORT_ROLE_SOURCE; |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 1074 | ASSERT_TRUE(findDevicePort(role, type, address, &devicePort)); |
jiabin | 43848a5 | 2019-09-05 14:07:25 -0700 | [diff] [blame] | 1075 | |
| 1076 | audio_port_handle_t routedPortId = devicePort.id; |
jiabin | 43848a5 | 2019-09-05 14:07:25 -0700 | [diff] [blame] | 1077 | // Try start input or output according to the device type |
| 1078 | if (audio_is_output_devices(type)) { |
| 1079 | getOutputForAttr(&routedPortId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 1080 | 48000 /*sampleRate*/, AUDIO_OUTPUT_FLAG_NONE); |
jiabin | 43848a5 | 2019-09-05 14:07:25 -0700 | [diff] [blame] | 1081 | } else if (audio_is_input_device(type)) { |
| 1082 | RecordingActivityTracker tracker; |
| 1083 | getInputForAttr({}, tracker.getRiid(), &routedPortId, AUDIO_FORMAT_PCM_16_BIT, |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 1084 | AUDIO_CHANNEL_IN_STEREO, 48000 /*sampleRate*/, AUDIO_INPUT_FLAG_NONE); |
jiabin | 43848a5 | 2019-09-05 14:07:25 -0700 | [diff] [blame] | 1085 | } |
| 1086 | ASSERT_EQ(devicePort.id, routedPortId); |
| 1087 | |
| 1088 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 1089 | type, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 1090 | address.c_str(), name.c_str(), AUDIO_FORMAT_DEFAULT)); |
| 1091 | } |
| 1092 | |
| 1093 | INSTANTIATE_TEST_CASE_P( |
| 1094 | DeviceConnectionState, |
| 1095 | AudioPolicyManagerTestDeviceConnection, |
| 1096 | testing::Values( |
| 1097 | DeviceConnectionTestParams({AUDIO_DEVICE_IN_HDMI, "test_in_hdmi", |
| 1098 | "audio_policy_test_in_hdmi"}), |
| 1099 | DeviceConnectionTestParams({AUDIO_DEVICE_OUT_HDMI, "test_out_hdmi", |
| 1100 | "audio_policy_test_out_hdmi"}), |
| 1101 | DeviceConnectionTestParams({AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET, "bt_hfp_in", |
| 1102 | "hfp_client_in"}), |
| 1103 | DeviceConnectionTestParams({AUDIO_DEVICE_OUT_BLUETOOTH_SCO, "bt_hfp_out", |
| 1104 | "hfp_client_out"}) |
| 1105 | ) |
| 1106 | ); |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 1107 | |
| 1108 | class AudioPolicyManagerTVTest : public AudioPolicyManagerTestWithConfigurationFile { |
| 1109 | protected: |
| 1110 | std::string getConfigFile() override { return sTvConfig; } |
| 1111 | void testHDMIPortSelection(audio_output_flags_t flags, const char* expectedMixPortName); |
| 1112 | |
| 1113 | static const std::string sTvConfig; |
| 1114 | }; |
| 1115 | |
| 1116 | const std::string AudioPolicyManagerTVTest::sTvConfig = |
| 1117 | AudioPolicyManagerTVTest::sExecutableDir + "test_tv_apm_configuration.xml"; |
| 1118 | |
| 1119 | // SwAudioOutputDescriptor doesn't populate flags so check against the port name. |
| 1120 | void AudioPolicyManagerTVTest::testHDMIPortSelection( |
| 1121 | audio_output_flags_t flags, const char* expectedMixPortName) { |
| 1122 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 1123 | AUDIO_DEVICE_OUT_AUX_DIGITAL, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 1124 | "" /*address*/, "" /*name*/, AUDIO_FORMAT_DEFAULT)); |
| 1125 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 1126 | audio_io_handle_t output; |
| 1127 | audio_port_handle_t portId; |
Mikhail Naganov | 57ac2ce | 2019-09-11 09:29:41 -0700 | [diff] [blame] | 1128 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, 48000, |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 1129 | flags, &output, &portId); |
| 1130 | sp<SwAudioOutputDescriptor> outDesc = mManager->getOutputs().valueFor(output); |
| 1131 | ASSERT_NE(nullptr, outDesc.get()); |
| 1132 | audio_port port = {}; |
| 1133 | outDesc->toAudioPort(&port); |
| 1134 | mManager->releaseOutput(portId); |
| 1135 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 1136 | AUDIO_DEVICE_OUT_AUX_DIGITAL, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 1137 | "" /*address*/, "" /*name*/, AUDIO_FORMAT_DEFAULT)); |
| 1138 | ASSERT_EQ(AUDIO_PORT_TYPE_MIX, port.type); |
| 1139 | ASSERT_EQ(AUDIO_PORT_ROLE_SOURCE, port.role); |
| 1140 | ASSERT_STREQ(expectedMixPortName, port.name); |
| 1141 | } |
| 1142 | |
| 1143 | TEST_F(AudioPolicyManagerTVTest, InitSuccess) { |
| 1144 | // SetUp must finish with no assertions. |
| 1145 | } |
| 1146 | |
| 1147 | TEST_F(AudioPolicyManagerTVTest, Dump) { |
| 1148 | dumpToLog(); |
| 1149 | } |
| 1150 | |
Mikhail Naganov | 57ac2ce | 2019-09-11 09:29:41 -0700 | [diff] [blame] | 1151 | TEST_F(AudioPolicyManagerTVTest, MatchNoFlags) { |
| 1152 | testHDMIPortSelection(AUDIO_OUTPUT_FLAG_NONE, "primary output"); |
| 1153 | } |
| 1154 | |
| 1155 | TEST_F(AudioPolicyManagerTVTest, MatchOutputDirectNoHwAvSync) { |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 1156 | // b/140447125: The selected port must not have HW AV Sync flag (see the config file). |
| 1157 | testHDMIPortSelection(AUDIO_OUTPUT_FLAG_DIRECT, "direct"); |
| 1158 | } |
| 1159 | |
Mikhail Naganov | 57ac2ce | 2019-09-11 09:29:41 -0700 | [diff] [blame] | 1160 | TEST_F(AudioPolicyManagerTVTest, MatchOutputDirectHwAvSync) { |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 1161 | testHDMIPortSelection(static_cast<audio_output_flags_t>( |
| 1162 | AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_HW_AV_SYNC), |
| 1163 | "tunnel"); |
| 1164 | } |
Mikhail Naganov | 57ac2ce | 2019-09-11 09:29:41 -0700 | [diff] [blame] | 1165 | |
| 1166 | TEST_F(AudioPolicyManagerTVTest, MatchOutputDirectMMapNoIrq) { |
| 1167 | testHDMIPortSelection(static_cast<audio_output_flags_t>( |
| 1168 | AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_MMAP_NOIRQ), |
| 1169 | "low latency"); |
| 1170 | } |
Mikhail Naganov | c0d0498 | 2020-03-02 21:02:28 +0000 | [diff] [blame] | 1171 | |
| 1172 | class AudioPolicyManagerDynamicHwModulesTest : public AudioPolicyManagerTestWithConfigurationFile { |
| 1173 | protected: |
| 1174 | void SetUpManagerConfig() override; |
| 1175 | }; |
| 1176 | |
| 1177 | void AudioPolicyManagerDynamicHwModulesTest::SetUpManagerConfig() { |
| 1178 | AudioPolicyManagerTestWithConfigurationFile::SetUpManagerConfig(); |
| 1179 | // Only allow successful opening of "primary" hw module during APM initialization. |
| 1180 | mClient->swapAllowedModuleNames({"primary"}); |
| 1181 | } |
| 1182 | |
| 1183 | TEST_F(AudioPolicyManagerDynamicHwModulesTest, InitSuccess) { |
| 1184 | // SetUp must finish with no assertions. |
| 1185 | } |
| 1186 | |
| 1187 | TEST_F(AudioPolicyManagerDynamicHwModulesTest, DynamicAddition) { |
| 1188 | const auto handleBefore = mClient->peekNextModuleHandle(); |
| 1189 | mManager->onNewAudioModulesAvailable(); |
| 1190 | ASSERT_EQ(handleBefore, mClient->peekNextModuleHandle()); |
| 1191 | // Reset module loading restrictions. |
| 1192 | mClient->swapAllowedModuleNames(); |
| 1193 | mManager->onNewAudioModulesAvailable(); |
| 1194 | const auto handleAfter = mClient->peekNextModuleHandle(); |
| 1195 | ASSERT_GT(handleAfter, handleBefore); |
| 1196 | mManager->onNewAudioModulesAvailable(); |
| 1197 | ASSERT_EQ(handleAfter, mClient->peekNextModuleHandle()); |
| 1198 | } |
| 1199 | |
| 1200 | TEST_F(AudioPolicyManagerDynamicHwModulesTest, AddedDeviceAvailable) { |
| 1201 | ASSERT_EQ(AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, mManager->getDeviceConnectionState( |
| 1202 | AUDIO_DEVICE_IN_REMOTE_SUBMIX, "0")); |
| 1203 | mClient->swapAllowedModuleNames({"primary", "r_submix"}); |
| 1204 | mManager->onNewAudioModulesAvailable(); |
| 1205 | ASSERT_EQ(AUDIO_POLICY_DEVICE_STATE_AVAILABLE, mManager->getDeviceConnectionState( |
| 1206 | AUDIO_DEVICE_IN_REMOTE_SUBMIX, "0")); |
| 1207 | } |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 1208 | |
| 1209 | TEST_F(AudioPolicyManagerDynamicHwModulesTest, ListAddedAudioPorts) { |
| 1210 | ASSERT_FALSE( |
| 1211 | findDevicePort(AUDIO_PORT_ROLE_SOURCE, AUDIO_DEVICE_IN_REMOTE_SUBMIX, "0", nullptr)); |
| 1212 | mClient->swapAllowedModuleNames({"primary", "r_submix"}); |
| 1213 | mManager->onNewAudioModulesAvailable(); |
| 1214 | struct audio_port port; |
| 1215 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SOURCE, AUDIO_DEVICE_IN_REMOTE_SUBMIX, "0", &port)); |
| 1216 | } |
| 1217 | |
| 1218 | TEST_F(AudioPolicyManagerDynamicHwModulesTest, ClientIsUpdated) { |
| 1219 | const size_t prevAudioPortListUpdateCount = mClient->getAudioPortListUpdateCount(); |
| 1220 | const uint32_t prevAudioPortGeneration = mManager->getAudioPortGeneration(); |
| 1221 | mClient->swapAllowedModuleNames({"primary", "r_submix"}); |
| 1222 | mManager->onNewAudioModulesAvailable(); |
| 1223 | EXPECT_GT(mClient->getAudioPortListUpdateCount(), prevAudioPortListUpdateCount); |
| 1224 | EXPECT_GT(mManager->getAudioPortGeneration(), prevAudioPortGeneration); |
| 1225 | } |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 1226 | |
| 1227 | using DevicesRoleForCapturePresetParam = std::tuple<audio_source_t, device_role_t>; |
| 1228 | |
| 1229 | class AudioPolicyManagerDevicesRoleForCapturePresetTest |
| 1230 | : public AudioPolicyManagerTestWithConfigurationFile, |
| 1231 | public testing::WithParamInterface<DevicesRoleForCapturePresetParam> { |
| 1232 | protected: |
| 1233 | // The `inputDevice` and `inputDevice2` indicate the audio devices type to be used for setting |
| 1234 | // device role. They must be declared in the test_audio_policy_configuration.xml |
| 1235 | AudioDeviceTypeAddr inputDevice = AudioDeviceTypeAddr(AUDIO_DEVICE_IN_BUILTIN_MIC, ""); |
| 1236 | AudioDeviceTypeAddr inputDevice2 = AudioDeviceTypeAddr(AUDIO_DEVICE_IN_HDMI, ""); |
| 1237 | }; |
| 1238 | |
| 1239 | TEST_P(AudioPolicyManagerDevicesRoleForCapturePresetTest, DevicesRoleForCapturePreset) { |
| 1240 | const audio_source_t audioSource = std::get<0>(GetParam()); |
| 1241 | const device_role_t role = std::get<1>(GetParam()); |
| 1242 | |
| 1243 | // Test invalid device when setting |
| 1244 | const AudioDeviceTypeAddr outputDevice(AUDIO_DEVICE_OUT_SPEAKER, ""); |
| 1245 | const AudioDeviceTypeAddrVector outputDevices = {outputDevice}; |
| 1246 | ASSERT_EQ(BAD_VALUE, |
| 1247 | mManager->setDevicesRoleForCapturePreset(audioSource, role, outputDevices)); |
| 1248 | ASSERT_EQ(BAD_VALUE, |
| 1249 | mManager->addDevicesRoleForCapturePreset(audioSource, role, outputDevices)); |
| 1250 | AudioDeviceTypeAddrVector devices; |
| 1251 | ASSERT_EQ(NAME_NOT_FOUND, |
| 1252 | mManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices)); |
| 1253 | ASSERT_TRUE(devices.empty()); |
| 1254 | ASSERT_EQ(BAD_VALUE, |
| 1255 | mManager->removeDevicesRoleForCapturePreset(audioSource, role, outputDevices)); |
| 1256 | |
| 1257 | // Without setting, call get/remove/clear must fail |
| 1258 | ASSERT_EQ(NAME_NOT_FOUND, |
| 1259 | mManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices)); |
| 1260 | ASSERT_EQ(NAME_NOT_FOUND, |
| 1261 | mManager->removeDevicesRoleForCapturePreset(audioSource, role, devices)); |
| 1262 | ASSERT_EQ(NAME_NOT_FOUND, |
| 1263 | mManager->clearDevicesRoleForCapturePreset(audioSource, role)); |
| 1264 | |
| 1265 | // Test set/get devices role |
| 1266 | const AudioDeviceTypeAddrVector inputDevices = {inputDevice}; |
| 1267 | ASSERT_EQ(NO_ERROR, |
| 1268 | mManager->setDevicesRoleForCapturePreset(audioSource, role, inputDevices)); |
| 1269 | ASSERT_EQ(NO_ERROR, mManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices)); |
| 1270 | EXPECT_THAT(devices, UnorderedElementsAre(inputDevice)); |
| 1271 | |
| 1272 | // Test setting will change the previously set devices |
| 1273 | const AudioDeviceTypeAddrVector inputDevices2 = {inputDevice2}; |
| 1274 | ASSERT_EQ(NO_ERROR, |
| 1275 | mManager->setDevicesRoleForCapturePreset(audioSource, role, inputDevices2)); |
| 1276 | devices.clear(); |
| 1277 | ASSERT_EQ(NO_ERROR, mManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices)); |
| 1278 | EXPECT_THAT(devices, UnorderedElementsAre(inputDevice2)); |
| 1279 | |
| 1280 | // Test add devices |
| 1281 | ASSERT_EQ(NO_ERROR, |
| 1282 | mManager->addDevicesRoleForCapturePreset(audioSource, role, inputDevices)); |
| 1283 | devices.clear(); |
| 1284 | ASSERT_EQ(NO_ERROR, mManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices)); |
| 1285 | EXPECT_THAT(devices, UnorderedElementsAre(inputDevice, inputDevice2)); |
| 1286 | |
| 1287 | // Test remove devices |
| 1288 | ASSERT_EQ(NO_ERROR, |
| 1289 | mManager->removeDevicesRoleForCapturePreset(audioSource, role, inputDevices)); |
| 1290 | devices.clear(); |
| 1291 | ASSERT_EQ(NO_ERROR, mManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices)); |
| 1292 | EXPECT_THAT(devices, UnorderedElementsAre(inputDevice2)); |
| 1293 | |
| 1294 | // Test remove devices that are not set as the device role |
| 1295 | ASSERT_EQ(BAD_VALUE, |
| 1296 | mManager->removeDevicesRoleForCapturePreset(audioSource, role, inputDevices)); |
| 1297 | |
| 1298 | // Test clear devices |
| 1299 | ASSERT_EQ(NO_ERROR, |
| 1300 | mManager->clearDevicesRoleForCapturePreset(audioSource, role)); |
| 1301 | devices.clear(); |
| 1302 | ASSERT_EQ(NAME_NOT_FOUND, |
| 1303 | mManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices)); |
| 1304 | } |
| 1305 | |
| 1306 | INSTANTIATE_TEST_CASE_P( |
| 1307 | DevicesRoleForCapturePresetOperation, |
| 1308 | AudioPolicyManagerDevicesRoleForCapturePresetTest, |
| 1309 | testing::Values( |
| 1310 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_MIC, DEVICE_ROLE_PREFERRED}), |
| 1311 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_VOICE_UPLINK, |
| 1312 | DEVICE_ROLE_PREFERRED}), |
| 1313 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_VOICE_DOWNLINK, |
| 1314 | DEVICE_ROLE_PREFERRED}), |
| 1315 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_VOICE_CALL, DEVICE_ROLE_PREFERRED}), |
| 1316 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_CAMCORDER, DEVICE_ROLE_PREFERRED}), |
| 1317 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_VOICE_RECOGNITION, |
| 1318 | DEVICE_ROLE_PREFERRED}), |
| 1319 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_VOICE_COMMUNICATION, |
| 1320 | DEVICE_ROLE_PREFERRED}), |
| 1321 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_REMOTE_SUBMIX, |
| 1322 | DEVICE_ROLE_PREFERRED}), |
| 1323 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_UNPROCESSED, DEVICE_ROLE_PREFERRED}), |
| 1324 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_VOICE_PERFORMANCE, |
| 1325 | DEVICE_ROLE_PREFERRED}), |
| 1326 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_ECHO_REFERENCE, |
| 1327 | DEVICE_ROLE_PREFERRED}), |
| 1328 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_FM_TUNER, DEVICE_ROLE_PREFERRED}), |
| 1329 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_HOTWORD, DEVICE_ROLE_PREFERRED}) |
| 1330 | ) |
| 1331 | ); |