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> |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 28 | #include <android/content/AttributionSourceState.h> |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 29 | #include <media/AudioPolicy.h> |
Mikhail Naganov | dc76968 | 2018-05-04 15:34:08 -0700 | [diff] [blame] | 30 | #include <media/PatchBuilder.h> |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 31 | #include <media/RecordingActivityTracker.h> |
| 32 | #include <utils/Log.h> |
| 33 | #include <utils/Vector.h> |
Mikhail Naganov | dc76968 | 2018-05-04 15:34:08 -0700 | [diff] [blame] | 34 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 35 | #include "AudioPolicyInterface.h" |
jiabin | b3f9804 | 2019-09-26 17:56:44 -0700 | [diff] [blame] | 36 | #include "AudioPolicyManagerTestClient.h" |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 37 | #include "AudioPolicyManagerTestClientForHdmi.h" |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 38 | #include "AudioPolicyTestClient.h" |
| 39 | #include "AudioPolicyTestManager.h" |
| 40 | |
| 41 | using namespace android; |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 42 | using testing::UnorderedElementsAre; |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 43 | using android::content::AttributionSourceState; |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 44 | |
Mikhail Naganov | 4783555 | 2019-05-14 10:32:51 -0700 | [diff] [blame] | 45 | TEST(AudioPolicyManagerTestInit, EngineFailure) { |
| 46 | AudioPolicyTestClient client; |
| 47 | AudioPolicyTestManager manager(&client); |
| 48 | manager.getConfig().setDefault(); |
| 49 | manager.getConfig().setEngineLibraryNameSuffix("non-existent"); |
| 50 | ASSERT_EQ(NO_INIT, manager.initialize()); |
| 51 | ASSERT_EQ(NO_INIT, manager.initCheck()); |
| 52 | } |
| 53 | |
| 54 | TEST(AudioPolicyManagerTestInit, ClientFailure) { |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 55 | AudioPolicyTestClient client; |
| 56 | AudioPolicyTestManager manager(&client); |
| 57 | manager.getConfig().setDefault(); |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 58 | // Since the default client fails to open anything, |
| 59 | // APM should indicate that the initialization didn't succeed. |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 60 | ASSERT_EQ(NO_INIT, manager.initialize()); |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 61 | ASSERT_EQ(NO_INIT, manager.initCheck()); |
| 62 | } |
| 63 | |
Mikhail Naganov | 946c003 | 2020-10-21 13:04:58 -0700 | [diff] [blame] | 64 | // Verifies that a failure while loading a config doesn't leave |
| 65 | // APM config in a "dirty" state. Since AudioPolicyConfig object |
| 66 | // is a proxy for the data hosted by APM, it isn't possible |
| 67 | // to "deep copy" it, and thus we have to test its elements |
| 68 | // individually. |
| 69 | TEST(AudioPolicyManagerTestInit, ConfigLoadingIsTransactional) { |
| 70 | AudioPolicyTestClient client; |
| 71 | AudioPolicyTestManager manager(&client); |
| 72 | ASSERT_TRUE(manager.getConfig().getHwModules().isEmpty()); |
| 73 | ASSERT_TRUE(manager.getConfig().getInputDevices().isEmpty()); |
| 74 | ASSERT_TRUE(manager.getConfig().getOutputDevices().isEmpty()); |
| 75 | status_t status = deserializeAudioPolicyFile( |
| 76 | (base::GetExecutableDirectory() + |
| 77 | "/test_invalid_audio_policy_configuration.xml").c_str(), |
| 78 | &manager.getConfig()); |
| 79 | ASSERT_NE(NO_ERROR, status); |
| 80 | EXPECT_TRUE(manager.getConfig().getHwModules().isEmpty()); |
| 81 | EXPECT_TRUE(manager.getConfig().getInputDevices().isEmpty()); |
| 82 | EXPECT_TRUE(manager.getConfig().getOutputDevices().isEmpty()); |
| 83 | status = deserializeAudioPolicyFile( |
| 84 | (base::GetExecutableDirectory() + "/test_audio_policy_configuration.xml").c_str(), |
| 85 | &manager.getConfig()); |
| 86 | ASSERT_EQ(NO_ERROR, status); |
| 87 | EXPECT_FALSE(manager.getConfig().getHwModules().isEmpty()); |
| 88 | EXPECT_FALSE(manager.getConfig().getInputDevices().isEmpty()); |
| 89 | EXPECT_FALSE(manager.getConfig().getOutputDevices().isEmpty()); |
| 90 | } |
| 91 | |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 92 | |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 93 | class PatchCountCheck { |
| 94 | public: |
| 95 | explicit PatchCountCheck(AudioPolicyManagerTestClient *client) |
| 96 | : mClient{client}, |
| 97 | mInitialCount{mClient->getActivePatchesCount()} {} |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 98 | int deltaFromSnapshot() const { |
| 99 | size_t currentCount = mClient->getActivePatchesCount(); |
| 100 | if (mInitialCount <= currentCount) { |
| 101 | return currentCount - mInitialCount; |
| 102 | } else { |
| 103 | return -(static_cast<int>(mInitialCount - currentCount)); |
| 104 | } |
| 105 | } |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 106 | private: |
| 107 | const AudioPolicyManagerTestClient *mClient; |
| 108 | const size_t mInitialCount; |
| 109 | }; |
| 110 | |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 111 | class AudioPolicyManagerTest : public testing::Test { |
| 112 | protected: |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 113 | void SetUp() override; |
| 114 | void TearDown() override; |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 115 | virtual void SetUpManagerConfig(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 116 | |
| 117 | void dumpToLog(); |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 118 | // When explicit routing is needed, selectedDeviceId needs to be set as the wanted port |
| 119 | // id. Otherwise, selectedDeviceId needs to be initialized as AUDIO_PORT_HANDLE_NONE. |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 120 | void getOutputForAttr( |
| 121 | audio_port_handle_t *selectedDeviceId, |
| 122 | audio_format_t format, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 123 | audio_channel_mask_t channelMask, |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 124 | int sampleRate, |
| 125 | audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE, |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 126 | audio_io_handle_t *output = nullptr, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 127 | audio_port_handle_t *portId = nullptr, |
| 128 | audio_attributes_t attr = {}); |
| 129 | void getInputForAttr( |
| 130 | const audio_attributes_t &attr, |
| 131 | audio_unique_id_t riid, |
| 132 | audio_port_handle_t *selectedDeviceId, |
| 133 | audio_format_t format, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 134 | audio_channel_mask_t channelMask, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 135 | int sampleRate, |
| 136 | audio_input_flags_t flags = AUDIO_INPUT_FLAG_NONE, |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 137 | audio_port_handle_t *portId = nullptr); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 138 | PatchCountCheck snapshotPatchCount() { return PatchCountCheck(mClient.get()); } |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 139 | |
Mikhail Naganov | 0805de1 | 2022-02-15 23:00:07 +0000 | [diff] [blame] | 140 | void getAudioPorts(audio_port_type_t type, audio_port_role_t role, |
| 141 | std::vector<audio_port_v7>* ports); |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 142 | // Tries to find a device port. If 'foundPort' isn't nullptr, |
| 143 | // will generate a failure if the port hasn't been found. |
| 144 | bool findDevicePort(audio_port_role_t role, audio_devices_t deviceType, |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 145 | const std::string &address, audio_port_v7 *foundPort); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 146 | static audio_port_handle_t getDeviceIdFromPatch(const struct audio_patch* patch); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 147 | virtual AudioPolicyManagerTestClient* getClient() { return new AudioPolicyManagerTestClient; } |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 148 | |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 149 | std::unique_ptr<AudioPolicyManagerTestClient> mClient; |
| 150 | std::unique_ptr<AudioPolicyTestManager> mManager; |
| 151 | }; |
| 152 | |
| 153 | void AudioPolicyManagerTest::SetUp() { |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 154 | mClient.reset(getClient()); |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 155 | mManager.reset(new AudioPolicyTestManager(mClient.get())); |
Mikhail Naganov | d4c21aa | 2021-10-05 15:10:16 -0700 | [diff] [blame] | 156 | ASSERT_NO_FATAL_FAILURE(SetUpManagerConfig()); // Subclasses may want to customize the config. |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 157 | ASSERT_EQ(NO_ERROR, mManager->initialize()); |
| 158 | ASSERT_EQ(NO_ERROR, mManager->initCheck()); |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 159 | } |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 160 | |
| 161 | void AudioPolicyManagerTest::TearDown() { |
| 162 | mManager.reset(); |
| 163 | mClient.reset(); |
| 164 | } |
| 165 | |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 166 | void AudioPolicyManagerTest::SetUpManagerConfig() { |
| 167 | mManager->getConfig().setDefault(); |
| 168 | } |
| 169 | |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 170 | void AudioPolicyManagerTest::dumpToLog() { |
Mikhail Naganov | 21b4336 | 2018-06-04 10:37:09 -0700 | [diff] [blame] | 171 | int pipefd[2]; |
| 172 | ASSERT_NE(-1, pipe(pipefd)); |
| 173 | pid_t cpid = fork(); |
| 174 | ASSERT_NE(-1, cpid); |
| 175 | if (cpid == 0) { |
| 176 | // Child process reads from the pipe and logs. |
| 177 | close(pipefd[1]); |
| 178 | std::string line; |
| 179 | char buf; |
| 180 | while (read(pipefd[0], &buf, sizeof(buf)) > 0) { |
| 181 | if (buf != '\n') { |
| 182 | line += buf; |
| 183 | } else { |
| 184 | ALOGI("%s", line.c_str()); |
| 185 | line = ""; |
| 186 | } |
| 187 | } |
| 188 | if (!line.empty()) ALOGI("%s", line.c_str()); |
| 189 | close(pipefd[0]); |
| 190 | _exit(EXIT_SUCCESS); |
| 191 | } else { |
| 192 | // Parent does the dump and checks the status code. |
| 193 | close(pipefd[0]); |
| 194 | ASSERT_EQ(NO_ERROR, mManager->dump(pipefd[1])); |
| 195 | close(pipefd[1]); |
| 196 | wait(NULL); // Wait for the child to exit. |
| 197 | } |
| 198 | } |
| 199 | |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 200 | void AudioPolicyManagerTest::getOutputForAttr( |
| 201 | audio_port_handle_t *selectedDeviceId, |
| 202 | audio_format_t format, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 203 | audio_channel_mask_t channelMask, |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 204 | int sampleRate, |
| 205 | audio_output_flags_t flags, |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 206 | audio_io_handle_t *output, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 207 | audio_port_handle_t *portId, |
| 208 | audio_attributes_t attr) { |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 209 | audio_io_handle_t localOutput; |
| 210 | if (!output) output = &localOutput; |
| 211 | *output = AUDIO_IO_HANDLE_NONE; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 212 | audio_stream_type_t stream = AUDIO_STREAM_DEFAULT; |
| 213 | audio_config_t config = AUDIO_CONFIG_INITIALIZER; |
| 214 | config.sample_rate = sampleRate; |
| 215 | config.channel_mask = channelMask; |
| 216 | config.format = format; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 217 | audio_port_handle_t localPortId; |
| 218 | if (!portId) portId = &localPortId; |
| 219 | *portId = AUDIO_PORT_HANDLE_NONE; |
Eric Laurent | 8a1095a | 2019-11-08 14:44:16 -0800 | [diff] [blame] | 220 | AudioPolicyInterface::output_type_t outputType; |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 221 | // TODO b/182392769: use attribution source util |
| 222 | AttributionSourceState attributionSource = AttributionSourceState(); |
| 223 | attributionSource.uid = 0; |
| 224 | attributionSource.token = sp<BBinder>::make(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 225 | ASSERT_EQ(OK, mManager->getOutputForAttr( |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 226 | &attr, output, AUDIO_SESSION_NONE, &stream, attributionSource, &config, &flags, |
Eric Laurent | 8a1095a | 2019-11-08 14:44:16 -0800 | [diff] [blame] | 227 | selectedDeviceId, portId, {}, &outputType)); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 228 | ASSERT_NE(AUDIO_PORT_HANDLE_NONE, *portId); |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 229 | ASSERT_NE(AUDIO_IO_HANDLE_NONE, *output); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 230 | } |
| 231 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 232 | void AudioPolicyManagerTest::getInputForAttr( |
| 233 | const audio_attributes_t &attr, |
| 234 | audio_unique_id_t riid, |
| 235 | audio_port_handle_t *selectedDeviceId, |
| 236 | audio_format_t format, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 237 | audio_channel_mask_t channelMask, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 238 | int sampleRate, |
| 239 | audio_input_flags_t flags, |
| 240 | audio_port_handle_t *portId) { |
| 241 | audio_io_handle_t input = AUDIO_PORT_HANDLE_NONE; |
| 242 | audio_config_base_t config = AUDIO_CONFIG_BASE_INITIALIZER; |
| 243 | config.sample_rate = sampleRate; |
| 244 | config.channel_mask = channelMask; |
| 245 | config.format = format; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 246 | audio_port_handle_t localPortId; |
| 247 | if (!portId) portId = &localPortId; |
| 248 | *portId = AUDIO_PORT_HANDLE_NONE; |
| 249 | AudioPolicyInterface::input_type_t inputType; |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 250 | // TODO b/182392769: use attribution source util |
| 251 | AttributionSourceState attributionSource = AttributionSourceState(); |
| 252 | attributionSource.uid = 0; |
| 253 | attributionSource.token = sp<BBinder>::make(); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 254 | ASSERT_EQ(OK, mManager->getInputForAttr( |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 255 | &attr, &input, riid, AUDIO_SESSION_NONE, attributionSource, &config, flags, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 256 | selectedDeviceId, &inputType, portId)); |
| 257 | ASSERT_NE(AUDIO_PORT_HANDLE_NONE, *portId); |
| 258 | } |
| 259 | |
Mikhail Naganov | 0805de1 | 2022-02-15 23:00:07 +0000 | [diff] [blame] | 260 | void AudioPolicyManagerTest::getAudioPorts(audio_port_type_t type, audio_port_role_t role, |
| 261 | std::vector<audio_port_v7>* ports) { |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 262 | uint32_t numPorts = 0; |
| 263 | uint32_t generation1; |
| 264 | status_t ret; |
| 265 | |
Mikhail Naganov | 0805de1 | 2022-02-15 23:00:07 +0000 | [diff] [blame] | 266 | ret = mManager->listAudioPorts(role, type, &numPorts, nullptr, &generation1); |
| 267 | ASSERT_EQ(NO_ERROR, ret) << "mManager->listAudioPorts returned error"; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 268 | |
| 269 | uint32_t generation2; |
Mikhail Naganov | 0805de1 | 2022-02-15 23:00:07 +0000 | [diff] [blame] | 270 | ports->resize(numPorts); |
| 271 | ret = mManager->listAudioPorts(role, type, &numPorts, ports->data(), &generation2); |
| 272 | ASSERT_EQ(NO_ERROR, ret) << "mManager->listAudioPorts returned error"; |
| 273 | ASSERT_EQ(generation1, generation2) << "Generations changed during ports retrieval"; |
| 274 | } |
| 275 | |
| 276 | bool AudioPolicyManagerTest::findDevicePort(audio_port_role_t role, |
| 277 | audio_devices_t deviceType, const std::string &address, audio_port_v7 *foundPort) { |
| 278 | std::vector<audio_port_v7> ports; |
| 279 | getAudioPorts(AUDIO_PORT_TYPE_DEVICE, role, &ports); |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 280 | if (HasFailure()) return false; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 281 | |
| 282 | for (const auto &port : ports) { |
| 283 | if (port.role == role && port.ext.device.type == deviceType && |
| 284 | (strncmp(port.ext.device.address, address.c_str(), |
| 285 | AUDIO_DEVICE_MAX_ADDRESS_LEN) == 0)) { |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 286 | if (foundPort) *foundPort = port; |
| 287 | return true; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 288 | } |
| 289 | } |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 290 | if (foundPort) { |
| 291 | ADD_FAILURE() << "Device port with role " << role << " and address " |
| 292 | << address << " not found"; |
| 293 | } |
| 294 | return false; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 295 | } |
| 296 | |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 297 | audio_port_handle_t AudioPolicyManagerTest::getDeviceIdFromPatch( |
| 298 | const struct audio_patch* patch) { |
| 299 | // The logic here is the same as the one in AudioIoDescriptor. |
| 300 | // Note this function is aim to get routed device id for test. |
| 301 | // In that case, device to device patch is not expected here. |
| 302 | if (patch->num_sources != 0 && patch->num_sinks != 0) { |
| 303 | if (patch->sources[0].type == AUDIO_PORT_TYPE_MIX) { |
| 304 | return patch->sinks[0].id; |
| 305 | } else { |
| 306 | return patch->sources[0].id; |
| 307 | } |
| 308 | } |
| 309 | return AUDIO_PORT_HANDLE_NONE; |
| 310 | } |
| 311 | |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 312 | |
| 313 | TEST_F(AudioPolicyManagerTest, InitSuccess) { |
| 314 | // SetUp must finish with no assertions. |
| 315 | } |
| 316 | |
| 317 | TEST_F(AudioPolicyManagerTest, Dump) { |
| 318 | dumpToLog(); |
| 319 | } |
| 320 | |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 321 | TEST_F(AudioPolicyManagerTest, CreateAudioPatchFailure) { |
| 322 | audio_patch patch{}; |
| 323 | audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE; |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 324 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 325 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(nullptr, &handle, 0)); |
| 326 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(&patch, nullptr, 0)); |
| 327 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(&patch, &handle, 0)); |
| 328 | patch.num_sources = AUDIO_PATCH_PORTS_MAX + 1; |
| 329 | patch.num_sinks = 1; |
| 330 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(&patch, &handle, 0)); |
| 331 | patch.num_sources = 1; |
| 332 | patch.num_sinks = AUDIO_PATCH_PORTS_MAX + 1; |
| 333 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(&patch, &handle, 0)); |
| 334 | patch.num_sources = 2; |
| 335 | patch.num_sinks = 1; |
| 336 | ASSERT_EQ(INVALID_OPERATION, mManager->createAudioPatch(&patch, &handle, 0)); |
| 337 | patch = {}; |
| 338 | patch.num_sources = 1; |
| 339 | patch.sources[0].role = AUDIO_PORT_ROLE_SINK; |
| 340 | patch.num_sinks = 1; |
| 341 | patch.sinks[0].role = AUDIO_PORT_ROLE_SINK; |
| 342 | ASSERT_EQ(INVALID_OPERATION, mManager->createAudioPatch(&patch, &handle, 0)); |
| 343 | patch = {}; |
| 344 | patch.num_sources = 1; |
| 345 | patch.sources[0].role = AUDIO_PORT_ROLE_SOURCE; |
| 346 | patch.num_sinks = 1; |
| 347 | patch.sinks[0].role = AUDIO_PORT_ROLE_SOURCE; |
| 348 | ASSERT_EQ(INVALID_OPERATION, mManager->createAudioPatch(&patch, &handle, 0)); |
| 349 | // Verify that the handle is left unchanged. |
| 350 | ASSERT_EQ(AUDIO_PATCH_HANDLE_NONE, handle); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 351 | ASSERT_EQ(0, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | TEST_F(AudioPolicyManagerTest, CreateAudioPatchFromMix) { |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 355 | audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE; |
| 356 | uid_t uid = 42; |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 357 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | c0d0498 | 2020-03-02 21:02:28 +0000 | [diff] [blame] | 358 | ASSERT_FALSE(mManager->getAvailableInputDevices().isEmpty()); |
Mikhail Naganov | dc76968 | 2018-05-04 15:34:08 -0700 | [diff] [blame] | 359 | PatchBuilder patchBuilder; |
Mikhail Naganov | c0d0498 | 2020-03-02 21:02:28 +0000 | [diff] [blame] | 360 | patchBuilder.addSource(mManager->getAvailableInputDevices()[0]). |
Mikhail Naganov | dc76968 | 2018-05-04 15:34:08 -0700 | [diff] [blame] | 361 | addSink(mManager->getConfig().getDefaultOutputDevice()); |
| 362 | ASSERT_EQ(NO_ERROR, mManager->createAudioPatch(patchBuilder.patch(), &handle, uid)); |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 363 | ASSERT_NE(AUDIO_PATCH_HANDLE_NONE, handle); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 364 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | // TODO: Add patch creation tests that involve already existing patch |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 368 | |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 369 | enum |
| 370 | { |
| 371 | MSD_AUDIO_PATCH_COUNT_NUM_AUDIO_PATCHES_INDEX = 0, |
| 372 | MSD_AUDIO_PATCH_COUNT_NAME_INDEX = 1 |
| 373 | }; |
| 374 | using MsdAudioPatchCountSpecification = std::tuple<size_t, std::string>; |
| 375 | |
| 376 | class AudioPolicyManagerTestMsd : public AudioPolicyManagerTest, |
| 377 | public ::testing::WithParamInterface<MsdAudioPatchCountSpecification> { |
| 378 | public: |
| 379 | AudioPolicyManagerTestMsd(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 380 | protected: |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 381 | void SetUpManagerConfig() override; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 382 | void TearDown() override; |
Dorin Drimus | 94d9441 | 2022-02-02 09:05:02 +0100 | [diff] [blame] | 383 | AudioProfileVector getDirectProfilesForAttributes(const audio_attributes_t& attr); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 384 | |
| 385 | sp<DeviceDescriptor> mMsdOutputDevice; |
| 386 | sp<DeviceDescriptor> mMsdInputDevice; |
Eric Laurent | 74c38dc | 2020-12-23 18:19:44 +0100 | [diff] [blame] | 387 | sp<DeviceDescriptor> mDefaultOutputDevice; |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 388 | |
| 389 | const size_t mExpectedAudioPatchCount; |
| 390 | sp<DeviceDescriptor> mSpdifDevice; |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 391 | |
| 392 | sp<DeviceDescriptor> mHdmiInputDevice; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 393 | }; |
| 394 | |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 395 | AudioPolicyManagerTestMsd::AudioPolicyManagerTestMsd() |
| 396 | : mExpectedAudioPatchCount(std::get<MSD_AUDIO_PATCH_COUNT_NUM_AUDIO_PATCHES_INDEX>( |
| 397 | GetParam())) {} |
| 398 | |
| 399 | INSTANTIATE_TEST_CASE_P( |
| 400 | MsdAudioPatchCount, |
| 401 | AudioPolicyManagerTestMsd, |
| 402 | ::testing::Values( |
| 403 | MsdAudioPatchCountSpecification(1u, "single"), |
| 404 | MsdAudioPatchCountSpecification(2u, "dual") |
| 405 | ), |
| 406 | [](const ::testing::TestParamInfo<MsdAudioPatchCountSpecification> &info) { |
| 407 | return std::get<MSD_AUDIO_PATCH_COUNT_NAME_INDEX>(info.param); } |
| 408 | ); |
| 409 | |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 410 | void AudioPolicyManagerTestMsd::SetUpManagerConfig() { |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 411 | // TODO: Consider using Serializer to load part of the config from a string. |
Mikhail Naganov | d4c21aa | 2021-10-05 15:10:16 -0700 | [diff] [blame] | 412 | ASSERT_NO_FATAL_FAILURE(AudioPolicyManagerTest::SetUpManagerConfig()); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 413 | AudioPolicyConfig& config = mManager->getConfig(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 414 | mMsdOutputDevice = new DeviceDescriptor(AUDIO_DEVICE_OUT_BUS); |
| 415 | sp<AudioProfile> pcmOutputProfile = new AudioProfile( |
| 416 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, 48000); |
| 417 | sp<AudioProfile> ac3OutputProfile = new AudioProfile( |
| 418 | AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, 48000); |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 419 | sp<AudioProfile> iec958OutputProfile = new AudioProfile( |
| 420 | AUDIO_FORMAT_IEC60958, AUDIO_CHANNEL_OUT_STEREO, 48000); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 421 | mMsdOutputDevice->addAudioProfile(pcmOutputProfile); |
| 422 | mMsdOutputDevice->addAudioProfile(ac3OutputProfile); |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 423 | mMsdOutputDevice->addAudioProfile(iec958OutputProfile); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 424 | mMsdInputDevice = new DeviceDescriptor(AUDIO_DEVICE_IN_BUS); |
| 425 | // Match output profile from AudioPolicyConfig::setDefault. |
| 426 | sp<AudioProfile> pcmInputProfile = new AudioProfile( |
| 427 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_STEREO, 44100); |
| 428 | mMsdInputDevice->addAudioProfile(pcmInputProfile); |
Mikhail Naganov | c0d0498 | 2020-03-02 21:02:28 +0000 | [diff] [blame] | 429 | config.addDevice(mMsdOutputDevice); |
| 430 | config.addDevice(mMsdInputDevice); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 431 | |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 432 | if (mExpectedAudioPatchCount == 2) { |
| 433 | // Add SPDIF device with PCM output profile as a second device for dual MSD audio patching. |
| 434 | mSpdifDevice = new DeviceDescriptor(AUDIO_DEVICE_OUT_SPDIF); |
| 435 | mSpdifDevice->addAudioProfile(pcmOutputProfile); |
| 436 | config.addDevice(mSpdifDevice); |
| 437 | |
| 438 | sp<OutputProfile> spdifOutputProfile = new OutputProfile("spdif output"); |
| 439 | spdifOutputProfile->addAudioProfile(pcmOutputProfile); |
| 440 | spdifOutputProfile->addSupportedDevice(mSpdifDevice); |
| 441 | config.getHwModules().getModuleFromName(AUDIO_HARDWARE_MODULE_ID_PRIMARY)-> |
| 442 | addOutputProfile(spdifOutputProfile); |
| 443 | } |
| 444 | |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 445 | sp<HwModule> msdModule = new HwModule(AUDIO_HARDWARE_MODULE_ID_MSD, 2 /*halVersionMajor*/); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 446 | HwModuleCollection modules = config.getHwModules(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 447 | modules.add(msdModule); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 448 | config.setHwModules(modules); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 449 | |
jiabin | 5740f08 | 2019-08-19 15:08:30 -0700 | [diff] [blame] | 450 | sp<OutputProfile> msdOutputProfile = new OutputProfile("msd input"); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 451 | msdOutputProfile->addAudioProfile(pcmOutputProfile); |
| 452 | msdOutputProfile->addSupportedDevice(mMsdOutputDevice); |
| 453 | msdModule->addOutputProfile(msdOutputProfile); |
jiabin | 5740f08 | 2019-08-19 15:08:30 -0700 | [diff] [blame] | 454 | sp<OutputProfile> msdCompressedOutputProfile = new OutputProfile("msd compressed input"); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 455 | msdCompressedOutputProfile->addAudioProfile(ac3OutputProfile); |
| 456 | msdCompressedOutputProfile->setFlags( |
| 457 | AUDIO_OUTPUT_FLAG_DIRECT | AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD | |
| 458 | AUDIO_OUTPUT_FLAG_NON_BLOCKING); |
| 459 | msdCompressedOutputProfile->addSupportedDevice(mMsdOutputDevice); |
| 460 | msdModule->addOutputProfile(msdCompressedOutputProfile); |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 461 | sp<OutputProfile> msdIec958OutputProfile = new OutputProfile("msd iec958 input"); |
| 462 | msdIec958OutputProfile->addAudioProfile(iec958OutputProfile); |
| 463 | msdIec958OutputProfile->setFlags(AUDIO_OUTPUT_FLAG_DIRECT); |
| 464 | msdIec958OutputProfile->addSupportedDevice(mMsdOutputDevice); |
| 465 | msdModule->addOutputProfile(msdIec958OutputProfile); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 466 | |
jiabin | 5740f08 | 2019-08-19 15:08:30 -0700 | [diff] [blame] | 467 | sp<InputProfile> msdInputProfile = new InputProfile("msd output"); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 468 | msdInputProfile->addAudioProfile(pcmInputProfile); |
| 469 | msdInputProfile->addSupportedDevice(mMsdInputDevice); |
| 470 | msdModule->addInputProfile(msdInputProfile); |
| 471 | |
| 472 | // Add a profile with another encoding to the default device to test routing |
| 473 | // of streams that are not supported by MSD. |
| 474 | sp<AudioProfile> dtsOutputProfile = new AudioProfile( |
| 475 | AUDIO_FORMAT_DTS, AUDIO_CHANNEL_OUT_5POINT1, 48000); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 476 | config.getDefaultOutputDevice()->addAudioProfile(dtsOutputProfile); |
jiabin | 5740f08 | 2019-08-19 15:08:30 -0700 | [diff] [blame] | 477 | sp<OutputProfile> primaryEncodedOutputProfile = new OutputProfile("encoded"); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 478 | primaryEncodedOutputProfile->addAudioProfile(dtsOutputProfile); |
| 479 | primaryEncodedOutputProfile->setFlags(AUDIO_OUTPUT_FLAG_DIRECT); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 480 | primaryEncodedOutputProfile->addSupportedDevice(config.getDefaultOutputDevice()); |
| 481 | config.getHwModules().getModuleFromName(AUDIO_HARDWARE_MODULE_ID_PRIMARY)-> |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 482 | addOutputProfile(primaryEncodedOutputProfile); |
Eric Laurent | 74c38dc | 2020-12-23 18:19:44 +0100 | [diff] [blame] | 483 | |
| 484 | mDefaultOutputDevice = config.getDefaultOutputDevice(); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 485 | if (mExpectedAudioPatchCount == 2) { |
| 486 | mSpdifDevice->addAudioProfile(dtsOutputProfile); |
| 487 | primaryEncodedOutputProfile->addSupportedDevice(mSpdifDevice); |
| 488 | } |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 489 | |
| 490 | // Add HDMI input device with IEC60958 profile for HDMI in -> MSD patching. |
| 491 | mHdmiInputDevice = new DeviceDescriptor(AUDIO_DEVICE_IN_HDMI); |
| 492 | sp<AudioProfile> iec958InputProfile = new AudioProfile( |
| 493 | AUDIO_FORMAT_IEC60958, AUDIO_CHANNEL_IN_STEREO, 48000); |
| 494 | mHdmiInputDevice->addAudioProfile(iec958InputProfile); |
| 495 | config.addDevice(mHdmiInputDevice); |
| 496 | sp<InputProfile> hdmiInputProfile = new InputProfile("hdmi input"); |
| 497 | hdmiInputProfile->addAudioProfile(iec958InputProfile); |
| 498 | hdmiInputProfile->setFlags(AUDIO_INPUT_FLAG_DIRECT); |
| 499 | hdmiInputProfile->addSupportedDevice(mHdmiInputDevice); |
| 500 | config.getHwModules().getModuleFromName(AUDIO_HARDWARE_MODULE_ID_PRIMARY)-> |
| 501 | addInputProfile(hdmiInputProfile); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | void AudioPolicyManagerTestMsd::TearDown() { |
| 505 | mMsdOutputDevice.clear(); |
| 506 | mMsdInputDevice.clear(); |
Eric Laurent | 74c38dc | 2020-12-23 18:19:44 +0100 | [diff] [blame] | 507 | mDefaultOutputDevice.clear(); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 508 | mSpdifDevice.clear(); |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 509 | mHdmiInputDevice.clear(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 510 | AudioPolicyManagerTest::TearDown(); |
| 511 | } |
| 512 | |
Dorin Drimus | 94d9441 | 2022-02-02 09:05:02 +0100 | [diff] [blame] | 513 | AudioProfileVector AudioPolicyManagerTestMsd::getDirectProfilesForAttributes( |
| 514 | const audio_attributes_t& attr) { |
| 515 | AudioProfileVector audioProfilesVector; |
| 516 | mManager->getDirectProfilesForAttributes(&attr, audioProfilesVector); |
| 517 | return audioProfilesVector; |
| 518 | } |
| 519 | |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 520 | TEST_P(AudioPolicyManagerTestMsd, InitSuccess) { |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 521 | ASSERT_TRUE(mMsdOutputDevice); |
| 522 | ASSERT_TRUE(mMsdInputDevice); |
Eric Laurent | 74c38dc | 2020-12-23 18:19:44 +0100 | [diff] [blame] | 523 | ASSERT_TRUE(mDefaultOutputDevice); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 524 | } |
| 525 | |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 526 | TEST_P(AudioPolicyManagerTestMsd, Dump) { |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 527 | dumpToLog(); |
| 528 | } |
| 529 | |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 530 | TEST_P(AudioPolicyManagerTestMsd, PatchCreationOnSetForceUse) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 531 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 532 | mManager->setForceUse(AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND, |
| 533 | AUDIO_POLICY_FORCE_ENCODED_SURROUND_ALWAYS); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 534 | ASSERT_EQ(mExpectedAudioPatchCount, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 535 | } |
| 536 | |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 537 | TEST_P(AudioPolicyManagerTestMsd, PatchCreationSetReleaseMsdOutputPatches) { |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 538 | const PatchCountCheck patchCount = snapshotPatchCount(); |
| 539 | DeviceVector devices = mManager->getAvailableOutputDevices(); |
| 540 | // Remove MSD output device to avoid patching to itself |
| 541 | devices.remove(mMsdOutputDevice); |
| 542 | ASSERT_EQ(mExpectedAudioPatchCount, devices.size()); |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 543 | mManager->setMsdOutputPatches(&devices); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 544 | ASSERT_EQ(mExpectedAudioPatchCount, patchCount.deltaFromSnapshot()); |
| 545 | // Dual patch: exercise creating one new audio patch and reusing another existing audio patch. |
| 546 | DeviceVector singleDevice(devices[0]); |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 547 | mManager->releaseMsdOutputPatches(singleDevice); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 548 | ASSERT_EQ(mExpectedAudioPatchCount - 1, patchCount.deltaFromSnapshot()); |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 549 | mManager->setMsdOutputPatches(&devices); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 550 | ASSERT_EQ(mExpectedAudioPatchCount, patchCount.deltaFromSnapshot()); |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 551 | mManager->releaseMsdOutputPatches(devices); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 552 | ASSERT_EQ(0, patchCount.deltaFromSnapshot()); |
| 553 | } |
| 554 | |
| 555 | TEST_P(AudioPolicyManagerTestMsd, GetOutputForAttrEncodedRoutesToMsd) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 556 | const PatchCountCheck patchCount = snapshotPatchCount(); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 557 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 558 | getOutputForAttr(&selectedDeviceId, |
| 559 | AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, 48000, AUDIO_OUTPUT_FLAG_DIRECT); |
Eric Laurent | 74c38dc | 2020-12-23 18:19:44 +0100 | [diff] [blame] | 560 | ASSERT_EQ(selectedDeviceId, mDefaultOutputDevice->getId()); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 561 | ASSERT_EQ(mExpectedAudioPatchCount, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 562 | } |
| 563 | |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 564 | TEST_P(AudioPolicyManagerTestMsd, GetOutputForAttrPcmRoutesToMsd) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 565 | const PatchCountCheck patchCount = snapshotPatchCount(); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 566 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 567 | getOutputForAttr(&selectedDeviceId, |
| 568 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, 48000); |
Eric Laurent | 74c38dc | 2020-12-23 18:19:44 +0100 | [diff] [blame] | 569 | ASSERT_EQ(selectedDeviceId, mDefaultOutputDevice->getId()); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 570 | ASSERT_EQ(mExpectedAudioPatchCount, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 571 | } |
| 572 | |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 573 | TEST_P(AudioPolicyManagerTestMsd, GetOutputForAttrEncodedPlusPcmRoutesToMsd) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 574 | const PatchCountCheck patchCount = snapshotPatchCount(); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 575 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 576 | getOutputForAttr(&selectedDeviceId, |
| 577 | AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, 48000, AUDIO_OUTPUT_FLAG_DIRECT); |
Eric Laurent | 74c38dc | 2020-12-23 18:19:44 +0100 | [diff] [blame] | 578 | ASSERT_EQ(selectedDeviceId, mDefaultOutputDevice->getId()); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 579 | ASSERT_EQ(mExpectedAudioPatchCount, patchCount.deltaFromSnapshot()); |
| 580 | selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 581 | getOutputForAttr(&selectedDeviceId, |
| 582 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, 48000); |
Eric Laurent | 74c38dc | 2020-12-23 18:19:44 +0100 | [diff] [blame] | 583 | ASSERT_EQ(selectedDeviceId, mDefaultOutputDevice->getId()); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 584 | ASSERT_EQ(mExpectedAudioPatchCount, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 585 | } |
| 586 | |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 587 | TEST_P(AudioPolicyManagerTestMsd, GetOutputForAttrUnsupportedFormatBypassesMsd) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 588 | const PatchCountCheck patchCount = snapshotPatchCount(); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 589 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 590 | getOutputForAttr(&selectedDeviceId, |
| 591 | AUDIO_FORMAT_DTS, AUDIO_CHANNEL_OUT_5POINT1, 48000, AUDIO_OUTPUT_FLAG_DIRECT); |
| 592 | ASSERT_NE(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 593 | ASSERT_EQ(0, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 594 | } |
| 595 | |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 596 | TEST_P(AudioPolicyManagerTestMsd, GetOutputForAttrFormatSwitching) { |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 597 | // Switch between formats that are supported and not supported by MSD. |
| 598 | { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 599 | const PatchCountCheck patchCount = snapshotPatchCount(); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 600 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 601 | audio_port_handle_t portId; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 602 | getOutputForAttr(&selectedDeviceId, |
| 603 | AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, 48000, AUDIO_OUTPUT_FLAG_DIRECT, |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 604 | nullptr /*output*/, &portId); |
Eric Laurent | 74c38dc | 2020-12-23 18:19:44 +0100 | [diff] [blame] | 605 | ASSERT_EQ(selectedDeviceId, mDefaultOutputDevice->getId()); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 606 | ASSERT_EQ(mExpectedAudioPatchCount, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 607 | mManager->releaseOutput(portId); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 608 | ASSERT_EQ(mExpectedAudioPatchCount, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 609 | } |
| 610 | { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 611 | const PatchCountCheck patchCount = snapshotPatchCount(); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 612 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 613 | audio_port_handle_t portId; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 614 | getOutputForAttr(&selectedDeviceId, |
| 615 | AUDIO_FORMAT_DTS, AUDIO_CHANNEL_OUT_5POINT1, 48000, AUDIO_OUTPUT_FLAG_DIRECT, |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 616 | nullptr /*output*/, &portId); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 617 | ASSERT_NE(selectedDeviceId, mMsdOutputDevice->getId()); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 618 | ASSERT_EQ(-static_cast<int>(mExpectedAudioPatchCount), patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 619 | mManager->releaseOutput(portId); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 620 | ASSERT_EQ(0, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 621 | } |
| 622 | { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 623 | const PatchCountCheck patchCount = snapshotPatchCount(); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 624 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 625 | getOutputForAttr(&selectedDeviceId, |
| 626 | AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, 48000, AUDIO_OUTPUT_FLAG_DIRECT); |
Eric Laurent | 74c38dc | 2020-12-23 18:19:44 +0100 | [diff] [blame] | 627 | ASSERT_EQ(selectedDeviceId, mDefaultOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 628 | ASSERT_EQ(0, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 629 | } |
| 630 | } |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 631 | |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 632 | TEST_P(AudioPolicyManagerTestMsd, PatchCreationFromHdmiInToMsd) { |
| 633 | audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE; |
| 634 | uid_t uid = 42; |
| 635 | const PatchCountCheck patchCount = snapshotPatchCount(); |
| 636 | ASSERT_FALSE(mManager->getAvailableInputDevices().isEmpty()); |
| 637 | PatchBuilder patchBuilder; |
| 638 | patchBuilder. |
| 639 | addSource(mManager->getAvailableInputDevices(). |
| 640 | getDevice(AUDIO_DEVICE_IN_HDMI, String8(""), AUDIO_FORMAT_DEFAULT)). |
| 641 | addSink(mManager->getAvailableOutputDevices(). |
| 642 | getDevice(AUDIO_DEVICE_OUT_BUS, String8(""), AUDIO_FORMAT_DEFAULT)); |
| 643 | ASSERT_EQ(NO_ERROR, mManager->createAudioPatch(patchBuilder.patch(), &handle, uid)); |
| 644 | ASSERT_NE(AUDIO_PATCH_HANDLE_NONE, handle); |
| 645 | AudioPatchCollection patches = mManager->getAudioPatches(); |
| 646 | sp<AudioPatch> patch = patches.valueFor(handle); |
| 647 | ASSERT_EQ(1, patch->mPatch.num_sources); |
| 648 | ASSERT_EQ(1, patch->mPatch.num_sinks); |
| 649 | ASSERT_EQ(AUDIO_PORT_ROLE_SOURCE, patch->mPatch.sources[0].role); |
| 650 | ASSERT_EQ(AUDIO_PORT_ROLE_SINK, patch->mPatch.sinks[0].role); |
| 651 | ASSERT_EQ(AUDIO_FORMAT_IEC60958, patch->mPatch.sources[0].format); |
| 652 | ASSERT_EQ(AUDIO_FORMAT_IEC60958, patch->mPatch.sinks[0].format); |
| 653 | ASSERT_EQ(AUDIO_CHANNEL_IN_STEREO, patch->mPatch.sources[0].channel_mask); |
| 654 | ASSERT_EQ(AUDIO_CHANNEL_OUT_STEREO, patch->mPatch.sinks[0].channel_mask); |
| 655 | ASSERT_EQ(48000, patch->mPatch.sources[0].sample_rate); |
| 656 | ASSERT_EQ(48000, patch->mPatch.sinks[0].sample_rate); |
| 657 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
| 658 | } |
| 659 | |
Dorin Drimus | 94d9441 | 2022-02-02 09:05:02 +0100 | [diff] [blame] | 660 | TEST_P(AudioPolicyManagerTestMsd, GetDirectProfilesForAttributesWithMsd) { |
| 661 | const audio_attributes_t attr = { |
| 662 | AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 663 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}; |
| 664 | |
| 665 | // count expected direct profiles for the default device |
| 666 | int countDirectProfilesPrimary = 0; |
| 667 | const auto& primary = mManager->getConfig().getHwModules() |
| 668 | .getModuleFromName(AUDIO_HARDWARE_MODULE_ID_PRIMARY); |
| 669 | for (const auto outputProfile : primary->getOutputProfiles()) { |
| 670 | if (outputProfile->asAudioPort()->isDirectOutput()) { |
| 671 | countDirectProfilesPrimary += outputProfile->asAudioPort()->getAudioProfiles().size(); |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | // count expected direct profiles for the msd device |
| 676 | int countDirectProfilesMsd = 0; |
| 677 | const auto& msd = mManager->getConfig().getHwModules() |
| 678 | .getModuleFromName(AUDIO_HARDWARE_MODULE_ID_MSD); |
| 679 | for (const auto outputProfile : msd->getOutputProfiles()) { |
| 680 | if (outputProfile->asAudioPort()->isDirectOutput()) { |
| 681 | countDirectProfilesMsd += outputProfile->asAudioPort()->getAudioProfiles().size(); |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | // before setting up MSD audio patches we only have the primary hal direct profiles |
| 686 | ASSERT_EQ(countDirectProfilesPrimary, getDirectProfilesForAttributes(attr).size()); |
| 687 | |
| 688 | DeviceVector outputDevices = mManager->getAvailableOutputDevices(); |
| 689 | // Remove MSD output device to avoid patching to itself |
| 690 | outputDevices.remove(mMsdOutputDevice); |
| 691 | mManager->setMsdOutputPatches(&outputDevices); |
| 692 | |
| 693 | // after setting up MSD audio patches the MSD direct profiles are added |
| 694 | ASSERT_EQ(countDirectProfilesPrimary + countDirectProfilesMsd, |
| 695 | getDirectProfilesForAttributes(attr).size()); |
| 696 | |
| 697 | mManager->releaseMsdOutputPatches(outputDevices); |
| 698 | // releasing the MSD audio patches gets us back to the primary hal direct profiles only |
| 699 | ASSERT_EQ(countDirectProfilesPrimary, getDirectProfilesForAttributes(attr).size()); |
| 700 | } |
| 701 | |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 702 | class AudioPolicyManagerTestWithConfigurationFile : public AudioPolicyManagerTest { |
| 703 | protected: |
| 704 | void SetUpManagerConfig() override; |
| 705 | virtual std::string getConfigFile() { return sDefaultConfig; } |
| 706 | |
| 707 | static const std::string sExecutableDir; |
| 708 | static const std::string sDefaultConfig; |
| 709 | }; |
| 710 | |
| 711 | const std::string AudioPolicyManagerTestWithConfigurationFile::sExecutableDir = |
| 712 | base::GetExecutableDirectory() + "/"; |
| 713 | |
| 714 | const std::string AudioPolicyManagerTestWithConfigurationFile::sDefaultConfig = |
| 715 | sExecutableDir + "test_audio_policy_configuration.xml"; |
| 716 | |
| 717 | void AudioPolicyManagerTestWithConfigurationFile::SetUpManagerConfig() { |
| 718 | status_t status = deserializeAudioPolicyFile(getConfigFile().c_str(), &mManager->getConfig()); |
| 719 | ASSERT_EQ(NO_ERROR, status); |
Mikhail Naganov | d4c21aa | 2021-10-05 15:10:16 -0700 | [diff] [blame] | 720 | mManager->getConfig().setSource(getConfigFile()); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | TEST_F(AudioPolicyManagerTestWithConfigurationFile, InitSuccess) { |
| 724 | // SetUp must finish with no assertions. |
| 725 | } |
| 726 | |
| 727 | TEST_F(AudioPolicyManagerTestWithConfigurationFile, Dump) { |
| 728 | dumpToLog(); |
| 729 | } |
| 730 | |
Mikhail Naganov | 0805de1 | 2022-02-15 23:00:07 +0000 | [diff] [blame] | 731 | TEST_F(AudioPolicyManagerTestWithConfigurationFile, ListAudioPortsHasFlags) { |
| 732 | // Create an input for VOIP TX because it's not opened automatically like outputs are. |
| 733 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 734 | audio_port_handle_t mixPortId = AUDIO_PORT_HANDLE_NONE; |
| 735 | audio_source_t source = AUDIO_SOURCE_VOICE_COMMUNICATION; |
| 736 | audio_attributes_t attr = { |
| 737 | AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, source, AUDIO_FLAG_NONE, ""}; |
| 738 | ASSERT_NO_FATAL_FAILURE(getInputForAttr(attr, 1, &selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, |
| 739 | AUDIO_CHANNEL_IN_MONO, 8000, AUDIO_INPUT_FLAG_VOIP_TX, &mixPortId)); |
| 740 | |
| 741 | std::vector<audio_port_v7> ports; |
| 742 | ASSERT_NO_FATAL_FAILURE( |
| 743 | getAudioPorts(AUDIO_PORT_TYPE_MIX, AUDIO_PORT_ROLE_NONE, &ports)); |
| 744 | EXPECT_NE(0, ports.size()); |
| 745 | bool hasFlags = false, foundPrimary = false, foundVoipRx = false, foundVoipTx = false; |
| 746 | for (const auto& port : ports) { |
| 747 | if ((port.active_config.config_mask & AUDIO_PORT_CONFIG_FLAGS) != 0) { |
| 748 | hasFlags = true; |
| 749 | if (port.role == AUDIO_PORT_ROLE_SOURCE) { |
| 750 | if ((port.active_config.flags.output & AUDIO_OUTPUT_FLAG_PRIMARY) != 0) { |
| 751 | foundPrimary = true; |
| 752 | } |
| 753 | if ((port.active_config.flags.output & AUDIO_OUTPUT_FLAG_VOIP_RX) != 0) { |
| 754 | foundVoipRx = true; |
| 755 | } |
| 756 | } else if (port.role == AUDIO_PORT_ROLE_SINK) { |
| 757 | if ((port.active_config.flags.input & AUDIO_INPUT_FLAG_VOIP_TX) != 0) { |
| 758 | foundVoipTx = true; |
| 759 | } |
| 760 | } |
| 761 | } |
| 762 | } |
| 763 | EXPECT_TRUE(hasFlags); |
| 764 | EXPECT_TRUE(foundPrimary); |
| 765 | EXPECT_TRUE(foundVoipRx); |
| 766 | EXPECT_TRUE(foundVoipTx); |
| 767 | } |
| 768 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 769 | using PolicyMixTuple = std::tuple<audio_usage_t, audio_source_t, uint32_t>; |
| 770 | |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 771 | class AudioPolicyManagerTestDynamicPolicy : public AudioPolicyManagerTestWithConfigurationFile { |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 772 | protected: |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 773 | void TearDown() override; |
| 774 | |
| 775 | status_t addPolicyMix(int mixType, int mixFlag, audio_devices_t deviceType, |
| 776 | std::string mixAddress, const audio_config_t& audioConfig, |
| 777 | const std::vector<PolicyMixTuple>& rules); |
| 778 | void clearPolicyMix(); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 779 | |
| 780 | Vector<AudioMix> mAudioMixes; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 781 | const std::string mMixAddress = "remote_submix_media"; |
| 782 | }; |
| 783 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 784 | void AudioPolicyManagerTestDynamicPolicy::TearDown() { |
| 785 | mManager->unregisterPolicyMixes(mAudioMixes); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 786 | AudioPolicyManagerTestWithConfigurationFile::TearDown(); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | status_t AudioPolicyManagerTestDynamicPolicy::addPolicyMix(int mixType, int mixFlag, |
| 790 | audio_devices_t deviceType, std::string mixAddress, const audio_config_t& audioConfig, |
| 791 | const std::vector<PolicyMixTuple>& rules) { |
| 792 | Vector<AudioMixMatchCriterion> myMixMatchCriteria; |
| 793 | |
| 794 | for(const auto &rule: rules) { |
| 795 | myMixMatchCriteria.add(AudioMixMatchCriterion( |
| 796 | std::get<0>(rule), std::get<1>(rule), std::get<2>(rule))); |
| 797 | } |
| 798 | |
| 799 | AudioMix myAudioMix(myMixMatchCriteria, mixType, audioConfig, mixFlag, |
| 800 | String8(mixAddress.c_str()), 0); |
| 801 | myAudioMix.mDeviceType = deviceType; |
| 802 | // Clear mAudioMix before add new one to make sure we don't add already exist mixes. |
| 803 | mAudioMixes.clear(); |
| 804 | mAudioMixes.add(myAudioMix); |
| 805 | |
| 806 | // As the policy mixes registration may fail at some case, |
| 807 | // caller need to check the returned status. |
| 808 | status_t ret = mManager->registerPolicyMixes(mAudioMixes); |
| 809 | return ret; |
| 810 | } |
| 811 | |
| 812 | void AudioPolicyManagerTestDynamicPolicy::clearPolicyMix() { |
| 813 | if (mManager != nullptr) { |
| 814 | mManager->unregisterPolicyMixes(mAudioMixes); |
| 815 | } |
| 816 | mAudioMixes.clear(); |
| 817 | } |
| 818 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 819 | TEST_F(AudioPolicyManagerTestDynamicPolicy, InitSuccess) { |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 820 | // SetUp must finish with no assertions |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | TEST_F(AudioPolicyManagerTestDynamicPolicy, Dump) { |
| 824 | dumpToLog(); |
| 825 | } |
| 826 | |
| 827 | TEST_F(AudioPolicyManagerTestDynamicPolicy, RegisterPolicyMixes) { |
| 828 | status_t ret; |
| 829 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 830 | |
| 831 | // Only capture of playback is allowed in LOOP_BACK &RENDER mode |
| 832 | ret = addPolicyMix(MIX_TYPE_RECORDERS, MIX_ROUTE_FLAG_LOOP_BACK_AND_RENDER, |
| 833 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, "", audioConfig, std::vector<PolicyMixTuple>()); |
| 834 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 835 | |
| 836 | // Fail due to the device is already connected. |
| 837 | clearPolicyMix(); |
| 838 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 839 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, "", audioConfig, std::vector<PolicyMixTuple>()); |
| 840 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 841 | |
| 842 | // The first time to register policy mixes with valid parameter should succeed. |
| 843 | clearPolicyMix(); |
| 844 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 845 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 846 | audioConfig.sample_rate = 48000; |
| 847 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 848 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, mMixAddress, audioConfig, |
| 849 | std::vector<PolicyMixTuple>()); |
| 850 | ASSERT_EQ(NO_ERROR, ret); |
| 851 | // Registering the same policy mixes should fail. |
| 852 | ret = mManager->registerPolicyMixes(mAudioMixes); |
| 853 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 854 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 855 | // Registration should fail due to device not found. |
| 856 | // Note that earpiece is not present in the test configuration file. |
| 857 | // 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] | 858 | clearPolicyMix(); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 859 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 860 | AUDIO_DEVICE_OUT_EARPIECE, "", audioConfig, std::vector<PolicyMixTuple>()); |
| 861 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 862 | |
| 863 | // Registration should fail due to output not found. |
| 864 | clearPolicyMix(); |
| 865 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 866 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, "", audioConfig, std::vector<PolicyMixTuple>()); |
| 867 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 868 | |
| 869 | // The first time to register valid policy mixes should succeed. |
| 870 | clearPolicyMix(); |
| 871 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 872 | AUDIO_DEVICE_OUT_SPEAKER, "", audioConfig, std::vector<PolicyMixTuple>()); |
| 873 | ASSERT_EQ(NO_ERROR, ret); |
| 874 | // Registering the same policy mixes should fail. |
| 875 | ret = mManager->registerPolicyMixes(mAudioMixes); |
| 876 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 877 | } |
| 878 | |
| 879 | TEST_F(AudioPolicyManagerTestDynamicPolicy, UnregisterPolicyMixes) { |
| 880 | status_t ret; |
| 881 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 882 | |
| 883 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 884 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 885 | audioConfig.sample_rate = 48000; |
| 886 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 887 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, mMixAddress, audioConfig, |
| 888 | std::vector<PolicyMixTuple>()); |
| 889 | ASSERT_EQ(NO_ERROR, ret); |
| 890 | |
| 891 | // After successfully registering policy mixes, it should be able to unregister. |
| 892 | ret = mManager->unregisterPolicyMixes(mAudioMixes); |
| 893 | ASSERT_EQ(NO_ERROR, ret); |
| 894 | |
| 895 | // After unregistering policy mixes successfully, it should fail unregistering |
| 896 | // the same policy mixes as they are not registered. |
| 897 | ret = mManager->unregisterPolicyMixes(mAudioMixes); |
| 898 | ASSERT_EQ(INVALID_OPERATION, ret); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 899 | } |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 900 | |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 901 | class AudioPolicyManagerTestForHdmi |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 902 | : public AudioPolicyManagerTestWithConfigurationFile, |
| 903 | public testing::WithParamInterface<audio_format_t> { |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 904 | protected: |
| 905 | void SetUp() override; |
| 906 | std::string getConfigFile() override { return sTvConfig; } |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 907 | std::map<audio_format_t, bool> getSurroundFormatsHelper(); |
| 908 | std::vector<audio_format_t> getReportedSurroundFormatsHelper(); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 909 | std::unordered_set<audio_format_t> getFormatsFromPorts(); |
| 910 | AudioPolicyManagerTestClient* getClient() override { |
| 911 | return new AudioPolicyManagerTestClientForHdmi; |
| 912 | } |
| 913 | void TearDown() override; |
| 914 | |
| 915 | static const std::string sTvConfig; |
| 916 | |
| 917 | }; |
| 918 | |
| 919 | const std::string AudioPolicyManagerTestForHdmi::sTvConfig = |
| 920 | AudioPolicyManagerTestForHdmi::sExecutableDir + |
| 921 | "test_settop_box_surround_configuration.xml"; |
| 922 | |
| 923 | void AudioPolicyManagerTestForHdmi::SetUp() { |
Mikhail Naganov | d4c21aa | 2021-10-05 15:10:16 -0700 | [diff] [blame] | 924 | ASSERT_NO_FATAL_FAILURE(AudioPolicyManagerTest::SetUp()); |
Mikhail Naganov | 83caee0 | 2021-10-05 15:52:01 -0700 | [diff] [blame] | 925 | mClient->addSupportedFormat(AUDIO_FORMAT_AC3); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 926 | mClient->addSupportedFormat(AUDIO_FORMAT_E_AC3); |
| 927 | mManager->setDeviceConnectionState( |
| 928 | AUDIO_DEVICE_OUT_HDMI, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 929 | "" /*address*/, "" /*name*/, AUDIO_FORMAT_DEFAULT); |
| 930 | } |
| 931 | |
| 932 | void AudioPolicyManagerTestForHdmi::TearDown() { |
| 933 | mManager->setDeviceConnectionState( |
| 934 | AUDIO_DEVICE_OUT_HDMI, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 935 | "" /*address*/, "" /*name*/, AUDIO_FORMAT_DEFAULT); |
| 936 | AudioPolicyManagerTest::TearDown(); |
| 937 | } |
| 938 | |
| 939 | std::map<audio_format_t, bool> |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 940 | AudioPolicyManagerTestForHdmi::getSurroundFormatsHelper() { |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 941 | unsigned int numSurroundFormats = 0; |
| 942 | std::map<audio_format_t, bool> surroundFormatsMap; |
| 943 | status_t ret = mManager->getSurroundFormats( |
| 944 | &numSurroundFormats, nullptr /* surroundFormats */, |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 945 | nullptr /* surroundFormatsEnabled */); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 946 | EXPECT_EQ(NO_ERROR, ret); |
| 947 | if (ret != NO_ERROR) { |
| 948 | return surroundFormatsMap; |
| 949 | } |
| 950 | audio_format_t surroundFormats[numSurroundFormats]; |
| 951 | memset(surroundFormats, 0, sizeof(audio_format_t) * numSurroundFormats); |
| 952 | bool surroundFormatsEnabled[numSurroundFormats]; |
| 953 | memset(surroundFormatsEnabled, 0, sizeof(bool) * numSurroundFormats); |
| 954 | ret = mManager->getSurroundFormats( |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 955 | &numSurroundFormats, surroundFormats, surroundFormatsEnabled); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 956 | EXPECT_EQ(NO_ERROR, ret); |
| 957 | if (ret != NO_ERROR) { |
| 958 | return surroundFormatsMap; |
| 959 | } |
| 960 | for (int i = 0; i< numSurroundFormats; i++) { |
| 961 | surroundFormatsMap[surroundFormats[i]] = surroundFormatsEnabled[i]; |
| 962 | } |
| 963 | return surroundFormatsMap; |
| 964 | } |
| 965 | |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 966 | std::vector<audio_format_t> AudioPolicyManagerTestForHdmi::getReportedSurroundFormatsHelper() { |
| 967 | unsigned int numSurroundFormats = 0; |
| 968 | std::vector<audio_format_t> surroundFormatsVector; |
| 969 | status_t ret = mManager->getReportedSurroundFormats( |
| 970 | &numSurroundFormats, nullptr /* surroundFormats */); |
| 971 | EXPECT_EQ(NO_ERROR, ret); |
| 972 | if (ret != NO_ERROR) { |
| 973 | return surroundFormatsVector; |
| 974 | } |
| 975 | audio_format_t surroundFormats[numSurroundFormats]; |
| 976 | memset(surroundFormats, 0, sizeof(audio_format_t) * numSurroundFormats); |
| 977 | ret = mManager->getReportedSurroundFormats(&numSurroundFormats, surroundFormats); |
| 978 | EXPECT_EQ(NO_ERROR, ret); |
| 979 | if (ret != NO_ERROR) { |
| 980 | return surroundFormatsVector; |
| 981 | } |
| 982 | for (const auto &surroundFormat : surroundFormats) { |
| 983 | surroundFormatsVector.push_back(surroundFormat); |
| 984 | } |
| 985 | return surroundFormatsVector; |
| 986 | } |
| 987 | |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 988 | std::unordered_set<audio_format_t> |
| 989 | AudioPolicyManagerTestForHdmi::getFormatsFromPorts() { |
| 990 | uint32_t numPorts = 0; |
| 991 | uint32_t generation1; |
| 992 | status_t ret; |
| 993 | std::unordered_set<audio_format_t> formats; |
| 994 | ret = mManager->listAudioPorts( |
| 995 | AUDIO_PORT_ROLE_SINK, AUDIO_PORT_TYPE_DEVICE, &numPorts, nullptr, &generation1); |
| 996 | EXPECT_EQ(NO_ERROR, ret) << "mManager->listAudioPorts returned error"; |
| 997 | if (ret != NO_ERROR) { |
| 998 | return formats; |
| 999 | } |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 1000 | struct audio_port_v7 ports[numPorts]; |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1001 | ret = mManager->listAudioPorts( |
| 1002 | AUDIO_PORT_ROLE_SINK, AUDIO_PORT_TYPE_DEVICE, &numPorts, ports, &generation1); |
| 1003 | EXPECT_EQ(NO_ERROR, ret) << "mManager->listAudioPorts returned error"; |
| 1004 | if (ret != NO_ERROR) { |
| 1005 | return formats; |
| 1006 | } |
| 1007 | for (const auto &port : ports) { |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 1008 | for (size_t i = 0; i < port.num_audio_profiles; ++i) { |
| 1009 | formats.insert(port.audio_profiles[i].format); |
| 1010 | } |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1011 | } |
| 1012 | return formats; |
| 1013 | } |
| 1014 | |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1015 | TEST_P(AudioPolicyManagerTestForHdmi, GetSurroundFormatsReturnsSupportedFormats) { |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1016 | mManager->setForceUse( |
| 1017 | AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND, AUDIO_POLICY_FORCE_ENCODED_SURROUND_ALWAYS); |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1018 | auto surroundFormats = getSurroundFormatsHelper(); |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1019 | ASSERT_EQ(1, surroundFormats.count(GetParam())); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1020 | } |
| 1021 | |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1022 | TEST_P(AudioPolicyManagerTestForHdmi, |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1023 | GetSurroundFormatsReturnsManipulatedFormats) { |
| 1024 | mManager->setForceUse( |
| 1025 | AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND, AUDIO_POLICY_FORCE_ENCODED_SURROUND_MANUAL); |
| 1026 | |
| 1027 | status_t ret = |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1028 | mManager->setSurroundFormatEnabled(GetParam(), false /*enabled*/); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1029 | ASSERT_EQ(NO_ERROR, ret); |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1030 | auto surroundFormats = getSurroundFormatsHelper(); |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1031 | ASSERT_EQ(1, surroundFormats.count(GetParam())); |
| 1032 | ASSERT_FALSE(surroundFormats[GetParam()]); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1033 | |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1034 | ret = mManager->setSurroundFormatEnabled(GetParam(), true /*enabled*/); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1035 | ASSERT_EQ(NO_ERROR, ret); |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1036 | surroundFormats = getSurroundFormatsHelper(); |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1037 | ASSERT_EQ(1, surroundFormats.count(GetParam())); |
| 1038 | ASSERT_TRUE(surroundFormats[GetParam()]); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1039 | |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1040 | ret = mManager->setSurroundFormatEnabled(GetParam(), false /*enabled*/); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1041 | ASSERT_EQ(NO_ERROR, ret); |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1042 | surroundFormats = getSurroundFormatsHelper(); |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1043 | ASSERT_EQ(1, surroundFormats.count(GetParam())); |
| 1044 | ASSERT_FALSE(surroundFormats[GetParam()]); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1045 | } |
| 1046 | |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1047 | TEST_P(AudioPolicyManagerTestForHdmi, |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1048 | ListAudioPortsReturnManipulatedHdmiFormats) { |
| 1049 | mManager->setForceUse( |
| 1050 | AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND, AUDIO_POLICY_FORCE_ENCODED_SURROUND_MANUAL); |
| 1051 | |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1052 | ASSERT_EQ(NO_ERROR, mManager->setSurroundFormatEnabled(GetParam(), false /*enabled*/)); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1053 | auto formats = getFormatsFromPorts(); |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1054 | ASSERT_EQ(0, formats.count(GetParam())); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1055 | |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1056 | ASSERT_EQ(NO_ERROR, mManager->setSurroundFormatEnabled(GetParam(), true /*enabled*/)); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1057 | formats = getFormatsFromPorts(); |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1058 | ASSERT_EQ(1, formats.count(GetParam())); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1059 | } |
| 1060 | |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1061 | TEST_P(AudioPolicyManagerTestForHdmi, |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1062 | GetReportedSurroundFormatsReturnsHdmiReportedFormats) { |
| 1063 | mManager->setForceUse( |
| 1064 | AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND, AUDIO_POLICY_FORCE_ENCODED_SURROUND_ALWAYS); |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1065 | auto surroundFormats = getReportedSurroundFormatsHelper(); |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1066 | ASSERT_EQ(1, std::count(surroundFormats.begin(), surroundFormats.end(), GetParam())); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1067 | } |
| 1068 | |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1069 | TEST_P(AudioPolicyManagerTestForHdmi, |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1070 | GetReportedSurroundFormatsReturnsNonManipulatedHdmiReportedFormats) { |
| 1071 | mManager->setForceUse( |
| 1072 | AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND, AUDIO_POLICY_FORCE_ENCODED_SURROUND_MANUAL); |
| 1073 | |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1074 | status_t ret = mManager->setSurroundFormatEnabled(GetParam(), false /*enabled*/); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1075 | ASSERT_EQ(NO_ERROR, ret); |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1076 | auto surroundFormats = getReportedSurroundFormatsHelper(); |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1077 | ASSERT_EQ(1, std::count(surroundFormats.begin(), surroundFormats.end(), GetParam())); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1078 | |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1079 | ret = mManager->setSurroundFormatEnabled(GetParam(), true /*enabled*/); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1080 | ASSERT_EQ(NO_ERROR, ret); |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1081 | surroundFormats = getReportedSurroundFormatsHelper(); |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1082 | ASSERT_EQ(1, std::count(surroundFormats.begin(), surroundFormats.end(), GetParam())); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1083 | } |
| 1084 | |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1085 | TEST_P(AudioPolicyManagerTestForHdmi, GetSurroundFormatsIgnoresSupportedFormats) { |
| 1086 | mManager->setForceUse( |
| 1087 | AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND, AUDIO_POLICY_FORCE_ENCODED_SURROUND_NEVER); |
| 1088 | auto surroundFormats = getSurroundFormatsHelper(); |
| 1089 | ASSERT_EQ(1, surroundFormats.count(GetParam())); |
| 1090 | ASSERT_FALSE(surroundFormats[GetParam()]); |
| 1091 | } |
| 1092 | |
| 1093 | INSTANTIATE_TEST_SUITE_P(SurroundFormatSupport, AudioPolicyManagerTestForHdmi, |
| 1094 | testing::Values(AUDIO_FORMAT_AC3, AUDIO_FORMAT_E_AC3), |
| 1095 | [](const ::testing::TestParamInfo<AudioPolicyManagerTestForHdmi::ParamType>& info) { |
| 1096 | return audio_format_to_string(info.param); |
| 1097 | }); |
| 1098 | |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 1099 | class AudioPolicyManagerTestDPNoRemoteSubmixModule : public AudioPolicyManagerTestDynamicPolicy { |
| 1100 | protected: |
| 1101 | std::string getConfigFile() override { return sPrimaryOnlyConfig; } |
| 1102 | |
| 1103 | static const std::string sPrimaryOnlyConfig; |
| 1104 | }; |
| 1105 | |
| 1106 | const std::string AudioPolicyManagerTestDPNoRemoteSubmixModule::sPrimaryOnlyConfig = |
| 1107 | sExecutableDir + "test_audio_policy_primary_only_configuration.xml"; |
| 1108 | |
| 1109 | TEST_F(AudioPolicyManagerTestDPNoRemoteSubmixModule, InitSuccess) { |
| 1110 | // SetUp must finish with no assertions. |
| 1111 | } |
| 1112 | |
| 1113 | TEST_F(AudioPolicyManagerTestDPNoRemoteSubmixModule, Dump) { |
| 1114 | dumpToLog(); |
| 1115 | } |
| 1116 | |
| 1117 | TEST_F(AudioPolicyManagerTestDPNoRemoteSubmixModule, RegistrationFailure) { |
| 1118 | // Registration/Unregistration should fail due to module for remote submix not found. |
| 1119 | status_t ret; |
| 1120 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 1121 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 1122 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 1123 | audioConfig.sample_rate = 48000; |
| 1124 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 1125 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, "", audioConfig, std::vector<PolicyMixTuple>()); |
| 1126 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 1127 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1128 | ret = mManager->unregisterPolicyMixes(mAudioMixes); |
| 1129 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 1130 | } |
| 1131 | |
| 1132 | class AudioPolicyManagerTestDPPlaybackReRouting : public AudioPolicyManagerTestDynamicPolicy, |
| 1133 | public testing::WithParamInterface<audio_attributes_t> { |
| 1134 | protected: |
| 1135 | void SetUp() override; |
| 1136 | void TearDown() override; |
| 1137 | |
| 1138 | std::unique_ptr<RecordingActivityTracker> mTracker; |
| 1139 | |
| 1140 | std::vector<PolicyMixTuple> mUsageRules = { |
| 1141 | {AUDIO_USAGE_MEDIA, AUDIO_SOURCE_DEFAULT, RULE_MATCH_ATTRIBUTE_USAGE}, |
| 1142 | {AUDIO_USAGE_ALARM, AUDIO_SOURCE_DEFAULT, RULE_MATCH_ATTRIBUTE_USAGE} |
| 1143 | }; |
| 1144 | |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 1145 | struct audio_port_v7 mInjectionPort; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1146 | audio_port_handle_t mPortId = AUDIO_PORT_HANDLE_NONE; |
| 1147 | }; |
| 1148 | |
| 1149 | void AudioPolicyManagerTestDPPlaybackReRouting::SetUp() { |
Mikhail Naganov | d4c21aa | 2021-10-05 15:10:16 -0700 | [diff] [blame] | 1150 | ASSERT_NO_FATAL_FAILURE(AudioPolicyManagerTestDynamicPolicy::SetUp()); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1151 | |
| 1152 | mTracker.reset(new RecordingActivityTracker()); |
| 1153 | |
| 1154 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 1155 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 1156 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 1157 | audioConfig.sample_rate = 48000; |
| 1158 | status_t ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 1159 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, mMixAddress, audioConfig, mUsageRules); |
| 1160 | ASSERT_EQ(NO_ERROR, ret); |
| 1161 | |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 1162 | struct audio_port_v7 extractionPort; |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 1163 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SOURCE, AUDIO_DEVICE_IN_REMOTE_SUBMIX, |
| 1164 | mMixAddress, &extractionPort)); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1165 | |
| 1166 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 1167 | audio_source_t source = AUDIO_SOURCE_REMOTE_SUBMIX; |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1168 | audio_attributes_t attr = { |
| 1169 | AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, source, AUDIO_FLAG_NONE, ""}; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1170 | std::string tags = "addr=" + mMixAddress; |
| 1171 | strncpy(attr.tags, tags.c_str(), AUDIO_ATTRIBUTES_TAGS_MAX_SIZE - 1); |
| 1172 | getInputForAttr(attr, mTracker->getRiid(), &selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, |
| 1173 | AUDIO_CHANNEL_IN_STEREO, 48000 /*sampleRate*/, AUDIO_INPUT_FLAG_NONE, &mPortId); |
| 1174 | ASSERT_EQ(NO_ERROR, mManager->startInput(mPortId)); |
| 1175 | ASSERT_EQ(extractionPort.id, selectedDeviceId); |
| 1176 | |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 1177 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SINK, AUDIO_DEVICE_OUT_REMOTE_SUBMIX, |
| 1178 | mMixAddress, &mInjectionPort)); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | void AudioPolicyManagerTestDPPlaybackReRouting::TearDown() { |
| 1182 | mManager->stopInput(mPortId); |
| 1183 | AudioPolicyManagerTestDynamicPolicy::TearDown(); |
| 1184 | } |
| 1185 | |
| 1186 | TEST_F(AudioPolicyManagerTestDPPlaybackReRouting, InitSuccess) { |
| 1187 | // SetUp must finish with no assertions |
| 1188 | } |
| 1189 | |
| 1190 | TEST_F(AudioPolicyManagerTestDPPlaybackReRouting, Dump) { |
| 1191 | dumpToLog(); |
| 1192 | } |
| 1193 | |
| 1194 | TEST_P(AudioPolicyManagerTestDPPlaybackReRouting, PlaybackReRouting) { |
| 1195 | const audio_attributes_t attr = GetParam(); |
| 1196 | const audio_usage_t usage = attr.usage; |
| 1197 | |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 1198 | audio_port_handle_t playbackRoutedPortId = AUDIO_PORT_HANDLE_NONE; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1199 | getOutputForAttr(&playbackRoutedPortId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 1200 | 48000 /*sampleRate*/, AUDIO_OUTPUT_FLAG_NONE, |
| 1201 | nullptr /*output*/, nullptr /*portId*/, attr); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1202 | if (std::find_if(begin(mUsageRules), end(mUsageRules), [&usage](const auto &usageRule) { |
| 1203 | return (std::get<0>(usageRule) == usage) && |
| 1204 | (std::get<2>(usageRule) == RULE_MATCH_ATTRIBUTE_USAGE);}) != end(mUsageRules) || |
| 1205 | (strncmp(attr.tags, "addr=", strlen("addr=")) == 0 && |
| 1206 | strncmp(attr.tags + strlen("addr="), mMixAddress.c_str(), |
| 1207 | AUDIO_ATTRIBUTES_TAGS_MAX_SIZE - strlen("addr=") - 1) == 0)) { |
| 1208 | EXPECT_EQ(mInjectionPort.id, playbackRoutedPortId); |
| 1209 | } else { |
| 1210 | EXPECT_NE(mInjectionPort.id, playbackRoutedPortId); |
| 1211 | } |
| 1212 | } |
| 1213 | |
| 1214 | INSTANTIATE_TEST_CASE_P( |
| 1215 | PlaybackReroutingUsageMatch, |
| 1216 | AudioPolicyManagerTestDPPlaybackReRouting, |
| 1217 | testing::Values( |
| 1218 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_MEDIA, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1219 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1220 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_ALARM, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1221 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""} |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1222 | ) |
| 1223 | ); |
| 1224 | |
| 1225 | INSTANTIATE_TEST_CASE_P( |
| 1226 | PlaybackReroutingAddressPriorityMatch, |
| 1227 | AudioPolicyManagerTestDPPlaybackReRouting, |
| 1228 | testing::Values( |
| 1229 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_MEDIA, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1230 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1231 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_VOICE_COMMUNICATION, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1232 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1233 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1234 | AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING, |
| 1235 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1236 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_ALARM, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1237 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1238 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_NOTIFICATION, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1239 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1240 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1241 | AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE, |
| 1242 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1243 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1244 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST, |
| 1245 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1246 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1247 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT, |
| 1248 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1249 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1250 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED, |
| 1251 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1252 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_NOTIFICATION_EVENT, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1253 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1254 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1255 | AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY, |
| 1256 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1257 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1258 | AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE, |
| 1259 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1260 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1261 | AUDIO_USAGE_ASSISTANCE_SONIFICATION, |
| 1262 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1263 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_GAME, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1264 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1265 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_VIRTUAL_SOURCE, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1266 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1267 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_ASSISTANT, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1268 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}, |
Baekgyeong Kim | 47ea671 | 2019-10-30 20:29:41 +0900 | [diff] [blame] | 1269 | (audio_attributes_t){AUDIO_CONTENT_TYPE_SPEECH, AUDIO_USAGE_ASSISTANT, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1270 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"} |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1271 | ) |
| 1272 | ); |
| 1273 | |
| 1274 | INSTANTIATE_TEST_CASE_P( |
| 1275 | PlaybackReroutingUnHandledUsages, |
| 1276 | AudioPolicyManagerTestDPPlaybackReRouting, |
| 1277 | testing::Values( |
| 1278 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_VOICE_COMMUNICATION, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1279 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1280 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 1281 | AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1282 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1283 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_NOTIFICATION, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1284 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1285 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 1286 | AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1287 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1288 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 1289 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1290 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1291 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 1292 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1293 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1294 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 1295 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1296 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1297 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_NOTIFICATION_EVENT, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1298 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1299 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 1300 | AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1301 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1302 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 1303 | AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1304 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1305 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 1306 | AUDIO_USAGE_ASSISTANCE_SONIFICATION, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1307 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1308 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_GAME, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1309 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1310 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_ASSISTANT, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1311 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}, |
Baekgyeong Kim | 47ea671 | 2019-10-30 20:29:41 +0900 | [diff] [blame] | 1312 | (audio_attributes_t){AUDIO_CONTENT_TYPE_SPEECH, AUDIO_USAGE_ASSISTANT, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1313 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""} |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1314 | ) |
| 1315 | ); |
| 1316 | |
| 1317 | class AudioPolicyManagerTestDPMixRecordInjection : public AudioPolicyManagerTestDynamicPolicy, |
| 1318 | public testing::WithParamInterface<audio_attributes_t> { |
| 1319 | protected: |
| 1320 | void SetUp() override; |
| 1321 | void TearDown() override; |
| 1322 | |
| 1323 | std::unique_ptr<RecordingActivityTracker> mTracker; |
| 1324 | |
| 1325 | std::vector<PolicyMixTuple> mSourceRules = { |
| 1326 | {AUDIO_USAGE_UNKNOWN, AUDIO_SOURCE_CAMCORDER, RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET}, |
| 1327 | {AUDIO_USAGE_UNKNOWN, AUDIO_SOURCE_MIC, RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET}, |
| 1328 | {AUDIO_USAGE_UNKNOWN, AUDIO_SOURCE_VOICE_COMMUNICATION, RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET} |
| 1329 | }; |
| 1330 | |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 1331 | struct audio_port_v7 mExtractionPort; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1332 | audio_port_handle_t mPortId = AUDIO_PORT_HANDLE_NONE; |
| 1333 | }; |
| 1334 | |
| 1335 | void AudioPolicyManagerTestDPMixRecordInjection::SetUp() { |
Mikhail Naganov | d4c21aa | 2021-10-05 15:10:16 -0700 | [diff] [blame] | 1336 | ASSERT_NO_FATAL_FAILURE(AudioPolicyManagerTestDynamicPolicy::SetUp()); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1337 | |
| 1338 | mTracker.reset(new RecordingActivityTracker()); |
| 1339 | |
| 1340 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 1341 | audioConfig.channel_mask = AUDIO_CHANNEL_IN_STEREO; |
| 1342 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 1343 | audioConfig.sample_rate = 48000; |
| 1344 | status_t ret = addPolicyMix(MIX_TYPE_RECORDERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 1345 | AUDIO_DEVICE_IN_REMOTE_SUBMIX, mMixAddress, audioConfig, mSourceRules); |
| 1346 | ASSERT_EQ(NO_ERROR, ret); |
| 1347 | |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 1348 | struct audio_port_v7 injectionPort; |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 1349 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SINK, AUDIO_DEVICE_OUT_REMOTE_SUBMIX, |
| 1350 | mMixAddress, &injectionPort)); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1351 | |
| 1352 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 1353 | audio_usage_t usage = AUDIO_USAGE_VIRTUAL_SOURCE; |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1354 | audio_attributes_t attr = |
| 1355 | {AUDIO_CONTENT_TYPE_UNKNOWN, usage, AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1356 | std::string tags = std::string("addr=") + mMixAddress; |
| 1357 | strncpy(attr.tags, tags.c_str(), AUDIO_ATTRIBUTES_TAGS_MAX_SIZE - 1); |
| 1358 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 1359 | 48000 /*sampleRate*/, AUDIO_OUTPUT_FLAG_NONE, nullptr /*output*/, &mPortId, attr); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1360 | ASSERT_EQ(NO_ERROR, mManager->startOutput(mPortId)); |
| 1361 | ASSERT_EQ(injectionPort.id, getDeviceIdFromPatch(mClient->getLastAddedPatch())); |
| 1362 | |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 1363 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SOURCE, AUDIO_DEVICE_IN_REMOTE_SUBMIX, |
| 1364 | mMixAddress, &mExtractionPort)); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | void AudioPolicyManagerTestDPMixRecordInjection::TearDown() { |
| 1368 | mManager->stopOutput(mPortId); |
| 1369 | AudioPolicyManagerTestDynamicPolicy::TearDown(); |
| 1370 | } |
| 1371 | |
| 1372 | TEST_F(AudioPolicyManagerTestDPMixRecordInjection, InitSuccess) { |
| 1373 | // SetUp mush finish with no assertions. |
| 1374 | } |
| 1375 | |
| 1376 | TEST_F(AudioPolicyManagerTestDPMixRecordInjection, Dump) { |
| 1377 | dumpToLog(); |
| 1378 | } |
| 1379 | |
| 1380 | TEST_P(AudioPolicyManagerTestDPMixRecordInjection, RecordingInjection) { |
| 1381 | const audio_attributes_t attr = GetParam(); |
| 1382 | const audio_source_t source = attr.source; |
| 1383 | |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 1384 | audio_port_handle_t captureRoutedPortId = AUDIO_PORT_HANDLE_NONE; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1385 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE; |
| 1386 | getInputForAttr(attr, mTracker->getRiid(), &captureRoutedPortId, AUDIO_FORMAT_PCM_16_BIT, |
| 1387 | AUDIO_CHANNEL_IN_STEREO, 48000 /*sampleRate*/, AUDIO_INPUT_FLAG_NONE, &portId); |
| 1388 | if (std::find_if(begin(mSourceRules), end(mSourceRules), [&source](const auto &sourceRule) { |
| 1389 | return (std::get<1>(sourceRule) == source) && |
| 1390 | (std::get<2>(sourceRule) == RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET);}) |
| 1391 | != end(mSourceRules)) { |
| 1392 | EXPECT_EQ(mExtractionPort.id, captureRoutedPortId); |
| 1393 | } else { |
| 1394 | EXPECT_NE(mExtractionPort.id, captureRoutedPortId); |
| 1395 | } |
| 1396 | } |
| 1397 | |
| 1398 | // No address priority rule for remote recording, address is a "don't care" |
| 1399 | INSTANTIATE_TEST_CASE_P( |
| 1400 | RecordInjectionSourceMatch, |
| 1401 | AudioPolicyManagerTestDPMixRecordInjection, |
| 1402 | testing::Values( |
| 1403 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1404 | AUDIO_SOURCE_CAMCORDER, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1405 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1406 | AUDIO_SOURCE_CAMCORDER, AUDIO_FLAG_NONE, |
| 1407 | "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1408 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1409 | AUDIO_SOURCE_MIC, AUDIO_FLAG_NONE, |
| 1410 | "addr=remote_submix_media"}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1411 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1412 | AUDIO_SOURCE_MIC, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1413 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1414 | AUDIO_SOURCE_VOICE_COMMUNICATION, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1415 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1416 | AUDIO_SOURCE_VOICE_COMMUNICATION, AUDIO_FLAG_NONE, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1417 | "addr=remote_submix_media"} |
| 1418 | ) |
| 1419 | ); |
| 1420 | |
| 1421 | // No address priority rule for remote recording |
| 1422 | INSTANTIATE_TEST_CASE_P( |
| 1423 | RecordInjectionSourceNotMatch, |
| 1424 | AudioPolicyManagerTestDPMixRecordInjection, |
| 1425 | testing::Values( |
| 1426 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1427 | AUDIO_SOURCE_VOICE_RECOGNITION, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1428 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1429 | AUDIO_SOURCE_HOTWORD, AUDIO_FLAG_NONE, ""}, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1430 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1431 | AUDIO_SOURCE_VOICE_RECOGNITION, AUDIO_FLAG_NONE, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1432 | "addr=remote_submix_media"}, |
| 1433 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1434 | AUDIO_SOURCE_HOTWORD, AUDIO_FLAG_NONE, |
| 1435 | "addr=remote_submix_media"} |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1436 | ) |
| 1437 | ); |
jiabin | 43848a5 | 2019-09-05 14:07:25 -0700 | [diff] [blame] | 1438 | |
| 1439 | using DeviceConnectionTestParams = |
| 1440 | std::tuple<audio_devices_t /*type*/, std::string /*name*/, std::string /*address*/>; |
| 1441 | |
| 1442 | class AudioPolicyManagerTestDeviceConnection : public AudioPolicyManagerTestWithConfigurationFile, |
| 1443 | public testing::WithParamInterface<DeviceConnectionTestParams> { |
| 1444 | }; |
| 1445 | |
| 1446 | TEST_F(AudioPolicyManagerTestDeviceConnection, InitSuccess) { |
| 1447 | // SetUp must finish with no assertions. |
| 1448 | } |
| 1449 | |
| 1450 | TEST_F(AudioPolicyManagerTestDeviceConnection, Dump) { |
| 1451 | dumpToLog(); |
| 1452 | } |
| 1453 | |
Jean-Michel Trivi | 9a6b9ad | 2020-10-22 16:46:43 -0700 | [diff] [blame] | 1454 | TEST_F(AudioPolicyManagerTestDeviceConnection, RoutingUpdate) { |
| 1455 | mClient->resetRoutingUpdatedCounter(); |
| 1456 | // Connecting a valid output device with valid parameters should trigger a routing update |
| 1457 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 1458 | AUDIO_DEVICE_OUT_BLUETOOTH_SCO, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 1459 | "a", "b", AUDIO_FORMAT_DEFAULT)); |
| 1460 | ASSERT_EQ(1, mClient->getRoutingUpdatedCounter()); |
| 1461 | |
| 1462 | // Disconnecting a connected device should succeed and trigger a routing update |
| 1463 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 1464 | AUDIO_DEVICE_OUT_BLUETOOTH_SCO, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 1465 | "a", "b", AUDIO_FORMAT_DEFAULT)); |
| 1466 | ASSERT_EQ(2, mClient->getRoutingUpdatedCounter()); |
| 1467 | |
| 1468 | // Disconnecting a disconnected device should fail and not trigger a routing update |
| 1469 | ASSERT_EQ(INVALID_OPERATION, mManager->setDeviceConnectionState( |
| 1470 | AUDIO_DEVICE_OUT_BLUETOOTH_SCO, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 1471 | "a", "b", AUDIO_FORMAT_DEFAULT)); |
| 1472 | ASSERT_EQ(2, mClient->getRoutingUpdatedCounter()); |
| 1473 | |
| 1474 | // Changing force use should trigger an update |
| 1475 | auto config = mManager->getForceUse(AUDIO_POLICY_FORCE_FOR_MEDIA); |
| 1476 | auto newConfig = config == AUDIO_POLICY_FORCE_BT_A2DP ? |
| 1477 | AUDIO_POLICY_FORCE_NONE : AUDIO_POLICY_FORCE_BT_A2DP; |
| 1478 | mManager->setForceUse(AUDIO_POLICY_FORCE_FOR_MEDIA, newConfig); |
| 1479 | ASSERT_EQ(3, mClient->getRoutingUpdatedCounter()); |
| 1480 | } |
| 1481 | |
jiabin | 43848a5 | 2019-09-05 14:07:25 -0700 | [diff] [blame] | 1482 | TEST_P(AudioPolicyManagerTestDeviceConnection, SetDeviceConnectionState) { |
| 1483 | const audio_devices_t type = std::get<0>(GetParam()); |
| 1484 | const std::string name = std::get<1>(GetParam()); |
| 1485 | const std::string address = std::get<2>(GetParam()); |
| 1486 | |
| 1487 | if (type == AUDIO_DEVICE_OUT_HDMI) { |
| 1488 | // Set device connection state failed due to no device descriptor found |
| 1489 | // For HDMI case, it is easier to simulate device descriptor not found error |
Mikhail Naganov | 83caee0 | 2021-10-05 15:52:01 -0700 | [diff] [blame] | 1490 | // by using an encoded format which isn't listed in the 'encodedFormats' |
| 1491 | // attribute for this devicePort. |
jiabin | 43848a5 | 2019-09-05 14:07:25 -0700 | [diff] [blame] | 1492 | ASSERT_EQ(INVALID_OPERATION, mManager->setDeviceConnectionState( |
| 1493 | type, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 1494 | address.c_str(), name.c_str(), AUDIO_FORMAT_MAT_2_1)); |
| 1495 | } |
| 1496 | // Connect with valid parameters should succeed |
| 1497 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 1498 | type, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 1499 | address.c_str(), name.c_str(), AUDIO_FORMAT_DEFAULT)); |
| 1500 | // Try to connect with the same device again should fail |
| 1501 | ASSERT_EQ(INVALID_OPERATION, mManager->setDeviceConnectionState( |
| 1502 | type, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 1503 | address.c_str(), name.c_str(), AUDIO_FORMAT_DEFAULT)); |
| 1504 | // Disconnect the connected device should succeed |
| 1505 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 1506 | type, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 1507 | address.c_str(), name.c_str(), AUDIO_FORMAT_DEFAULT)); |
| 1508 | // Disconnect device that is not connected should fail |
| 1509 | ASSERT_EQ(INVALID_OPERATION, mManager->setDeviceConnectionState( |
| 1510 | type, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 1511 | address.c_str(), name.c_str(), AUDIO_FORMAT_DEFAULT)); |
| 1512 | // Try to set device connection state with a invalid connection state should fail |
| 1513 | ASSERT_EQ(BAD_VALUE, mManager->setDeviceConnectionState( |
| 1514 | type, AUDIO_POLICY_DEVICE_STATE_CNT, |
| 1515 | "", "", AUDIO_FORMAT_DEFAULT)); |
| 1516 | } |
| 1517 | |
| 1518 | TEST_P(AudioPolicyManagerTestDeviceConnection, ExplicitlyRoutingAfterConnection) { |
| 1519 | const audio_devices_t type = std::get<0>(GetParam()); |
| 1520 | const std::string name = std::get<1>(GetParam()); |
| 1521 | const std::string address = std::get<2>(GetParam()); |
| 1522 | |
| 1523 | // Connect device to do explicitly routing test |
| 1524 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 1525 | type, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 1526 | address.c_str(), name.c_str(), AUDIO_FORMAT_DEFAULT)); |
| 1527 | |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 1528 | audio_port_v7 devicePort; |
jiabin | 43848a5 | 2019-09-05 14:07:25 -0700 | [diff] [blame] | 1529 | const audio_port_role_t role = audio_is_output_device(type) |
| 1530 | ? AUDIO_PORT_ROLE_SINK : AUDIO_PORT_ROLE_SOURCE; |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 1531 | ASSERT_TRUE(findDevicePort(role, type, address, &devicePort)); |
jiabin | 43848a5 | 2019-09-05 14:07:25 -0700 | [diff] [blame] | 1532 | |
| 1533 | audio_port_handle_t routedPortId = devicePort.id; |
jiabin | 43848a5 | 2019-09-05 14:07:25 -0700 | [diff] [blame] | 1534 | // Try start input or output according to the device type |
| 1535 | if (audio_is_output_devices(type)) { |
| 1536 | getOutputForAttr(&routedPortId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 1537 | 48000 /*sampleRate*/, AUDIO_OUTPUT_FLAG_NONE); |
jiabin | 43848a5 | 2019-09-05 14:07:25 -0700 | [diff] [blame] | 1538 | } else if (audio_is_input_device(type)) { |
| 1539 | RecordingActivityTracker tracker; |
| 1540 | getInputForAttr({}, tracker.getRiid(), &routedPortId, AUDIO_FORMAT_PCM_16_BIT, |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 1541 | AUDIO_CHANNEL_IN_STEREO, 48000 /*sampleRate*/, AUDIO_INPUT_FLAG_NONE); |
jiabin | 43848a5 | 2019-09-05 14:07:25 -0700 | [diff] [blame] | 1542 | } |
| 1543 | ASSERT_EQ(devicePort.id, routedPortId); |
| 1544 | |
| 1545 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 1546 | type, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 1547 | address.c_str(), name.c_str(), AUDIO_FORMAT_DEFAULT)); |
| 1548 | } |
| 1549 | |
| 1550 | INSTANTIATE_TEST_CASE_P( |
| 1551 | DeviceConnectionState, |
| 1552 | AudioPolicyManagerTestDeviceConnection, |
| 1553 | testing::Values( |
| 1554 | DeviceConnectionTestParams({AUDIO_DEVICE_IN_HDMI, "test_in_hdmi", |
| 1555 | "audio_policy_test_in_hdmi"}), |
| 1556 | DeviceConnectionTestParams({AUDIO_DEVICE_OUT_HDMI, "test_out_hdmi", |
| 1557 | "audio_policy_test_out_hdmi"}), |
| 1558 | DeviceConnectionTestParams({AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET, "bt_hfp_in", |
| 1559 | "hfp_client_in"}), |
| 1560 | DeviceConnectionTestParams({AUDIO_DEVICE_OUT_BLUETOOTH_SCO, "bt_hfp_out", |
| 1561 | "hfp_client_out"}) |
| 1562 | ) |
| 1563 | ); |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 1564 | |
| 1565 | class AudioPolicyManagerTVTest : public AudioPolicyManagerTestWithConfigurationFile { |
| 1566 | protected: |
| 1567 | std::string getConfigFile() override { return sTvConfig; } |
| 1568 | void testHDMIPortSelection(audio_output_flags_t flags, const char* expectedMixPortName); |
| 1569 | |
| 1570 | static const std::string sTvConfig; |
| 1571 | }; |
| 1572 | |
| 1573 | const std::string AudioPolicyManagerTVTest::sTvConfig = |
| 1574 | AudioPolicyManagerTVTest::sExecutableDir + "test_tv_apm_configuration.xml"; |
| 1575 | |
| 1576 | // SwAudioOutputDescriptor doesn't populate flags so check against the port name. |
| 1577 | void AudioPolicyManagerTVTest::testHDMIPortSelection( |
| 1578 | audio_output_flags_t flags, const char* expectedMixPortName) { |
| 1579 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 1580 | AUDIO_DEVICE_OUT_AUX_DIGITAL, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 1581 | "" /*address*/, "" /*name*/, AUDIO_FORMAT_DEFAULT)); |
| 1582 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 1583 | audio_io_handle_t output; |
| 1584 | audio_port_handle_t portId; |
Mikhail Naganov | 57ac2ce | 2019-09-11 09:29:41 -0700 | [diff] [blame] | 1585 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, 48000, |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 1586 | flags, &output, &portId); |
| 1587 | sp<SwAudioOutputDescriptor> outDesc = mManager->getOutputs().valueFor(output); |
| 1588 | ASSERT_NE(nullptr, outDesc.get()); |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 1589 | audio_port_v7 port = {}; |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 1590 | outDesc->toAudioPort(&port); |
| 1591 | mManager->releaseOutput(portId); |
| 1592 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 1593 | AUDIO_DEVICE_OUT_AUX_DIGITAL, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 1594 | "" /*address*/, "" /*name*/, AUDIO_FORMAT_DEFAULT)); |
| 1595 | ASSERT_EQ(AUDIO_PORT_TYPE_MIX, port.type); |
| 1596 | ASSERT_EQ(AUDIO_PORT_ROLE_SOURCE, port.role); |
| 1597 | ASSERT_STREQ(expectedMixPortName, port.name); |
| 1598 | } |
| 1599 | |
| 1600 | TEST_F(AudioPolicyManagerTVTest, InitSuccess) { |
| 1601 | // SetUp must finish with no assertions. |
| 1602 | } |
| 1603 | |
| 1604 | TEST_F(AudioPolicyManagerTVTest, Dump) { |
| 1605 | dumpToLog(); |
| 1606 | } |
| 1607 | |
Mikhail Naganov | 57ac2ce | 2019-09-11 09:29:41 -0700 | [diff] [blame] | 1608 | TEST_F(AudioPolicyManagerTVTest, MatchNoFlags) { |
| 1609 | testHDMIPortSelection(AUDIO_OUTPUT_FLAG_NONE, "primary output"); |
| 1610 | } |
| 1611 | |
| 1612 | TEST_F(AudioPolicyManagerTVTest, MatchOutputDirectNoHwAvSync) { |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 1613 | // b/140447125: The selected port must not have HW AV Sync flag (see the config file). |
| 1614 | testHDMIPortSelection(AUDIO_OUTPUT_FLAG_DIRECT, "direct"); |
| 1615 | } |
| 1616 | |
Mikhail Naganov | 57ac2ce | 2019-09-11 09:29:41 -0700 | [diff] [blame] | 1617 | TEST_F(AudioPolicyManagerTVTest, MatchOutputDirectHwAvSync) { |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 1618 | testHDMIPortSelection(static_cast<audio_output_flags_t>( |
| 1619 | AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_HW_AV_SYNC), |
| 1620 | "tunnel"); |
| 1621 | } |
Mikhail Naganov | 57ac2ce | 2019-09-11 09:29:41 -0700 | [diff] [blame] | 1622 | |
| 1623 | TEST_F(AudioPolicyManagerTVTest, MatchOutputDirectMMapNoIrq) { |
| 1624 | testHDMIPortSelection(static_cast<audio_output_flags_t>( |
| 1625 | AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_MMAP_NOIRQ), |
| 1626 | "low latency"); |
| 1627 | } |
Mikhail Naganov | c0d0498 | 2020-03-02 21:02:28 +0000 | [diff] [blame] | 1628 | |
| 1629 | class AudioPolicyManagerDynamicHwModulesTest : public AudioPolicyManagerTestWithConfigurationFile { |
| 1630 | protected: |
| 1631 | void SetUpManagerConfig() override; |
| 1632 | }; |
| 1633 | |
| 1634 | void AudioPolicyManagerDynamicHwModulesTest::SetUpManagerConfig() { |
Mikhail Naganov | d4c21aa | 2021-10-05 15:10:16 -0700 | [diff] [blame] | 1635 | ASSERT_NO_FATAL_FAILURE(AudioPolicyManagerTestWithConfigurationFile::SetUpManagerConfig()); |
Mikhail Naganov | c0d0498 | 2020-03-02 21:02:28 +0000 | [diff] [blame] | 1636 | // Only allow successful opening of "primary" hw module during APM initialization. |
| 1637 | mClient->swapAllowedModuleNames({"primary"}); |
| 1638 | } |
| 1639 | |
| 1640 | TEST_F(AudioPolicyManagerDynamicHwModulesTest, InitSuccess) { |
| 1641 | // SetUp must finish with no assertions. |
| 1642 | } |
| 1643 | |
| 1644 | TEST_F(AudioPolicyManagerDynamicHwModulesTest, DynamicAddition) { |
| 1645 | const auto handleBefore = mClient->peekNextModuleHandle(); |
| 1646 | mManager->onNewAudioModulesAvailable(); |
| 1647 | ASSERT_EQ(handleBefore, mClient->peekNextModuleHandle()); |
| 1648 | // Reset module loading restrictions. |
| 1649 | mClient->swapAllowedModuleNames(); |
| 1650 | mManager->onNewAudioModulesAvailable(); |
| 1651 | const auto handleAfter = mClient->peekNextModuleHandle(); |
| 1652 | ASSERT_GT(handleAfter, handleBefore); |
| 1653 | mManager->onNewAudioModulesAvailable(); |
| 1654 | ASSERT_EQ(handleAfter, mClient->peekNextModuleHandle()); |
| 1655 | } |
| 1656 | |
| 1657 | TEST_F(AudioPolicyManagerDynamicHwModulesTest, AddedDeviceAvailable) { |
| 1658 | ASSERT_EQ(AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, mManager->getDeviceConnectionState( |
| 1659 | AUDIO_DEVICE_IN_REMOTE_SUBMIX, "0")); |
| 1660 | mClient->swapAllowedModuleNames({"primary", "r_submix"}); |
| 1661 | mManager->onNewAudioModulesAvailable(); |
| 1662 | ASSERT_EQ(AUDIO_POLICY_DEVICE_STATE_AVAILABLE, mManager->getDeviceConnectionState( |
| 1663 | AUDIO_DEVICE_IN_REMOTE_SUBMIX, "0")); |
| 1664 | } |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 1665 | |
| 1666 | TEST_F(AudioPolicyManagerDynamicHwModulesTest, ListAddedAudioPorts) { |
| 1667 | ASSERT_FALSE( |
| 1668 | findDevicePort(AUDIO_PORT_ROLE_SOURCE, AUDIO_DEVICE_IN_REMOTE_SUBMIX, "0", nullptr)); |
| 1669 | mClient->swapAllowedModuleNames({"primary", "r_submix"}); |
| 1670 | mManager->onNewAudioModulesAvailable(); |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 1671 | struct audio_port_v7 port; |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 1672 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SOURCE, AUDIO_DEVICE_IN_REMOTE_SUBMIX, "0", &port)); |
| 1673 | } |
| 1674 | |
| 1675 | TEST_F(AudioPolicyManagerDynamicHwModulesTest, ClientIsUpdated) { |
| 1676 | const size_t prevAudioPortListUpdateCount = mClient->getAudioPortListUpdateCount(); |
| 1677 | const uint32_t prevAudioPortGeneration = mManager->getAudioPortGeneration(); |
| 1678 | mClient->swapAllowedModuleNames({"primary", "r_submix"}); |
| 1679 | mManager->onNewAudioModulesAvailable(); |
| 1680 | EXPECT_GT(mClient->getAudioPortListUpdateCount(), prevAudioPortListUpdateCount); |
| 1681 | EXPECT_GT(mManager->getAudioPortGeneration(), prevAudioPortGeneration); |
| 1682 | } |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 1683 | |
| 1684 | using DevicesRoleForCapturePresetParam = std::tuple<audio_source_t, device_role_t>; |
| 1685 | |
| 1686 | class AudioPolicyManagerDevicesRoleForCapturePresetTest |
| 1687 | : public AudioPolicyManagerTestWithConfigurationFile, |
| 1688 | public testing::WithParamInterface<DevicesRoleForCapturePresetParam> { |
| 1689 | protected: |
| 1690 | // The `inputDevice` and `inputDevice2` indicate the audio devices type to be used for setting |
| 1691 | // device role. They must be declared in the test_audio_policy_configuration.xml |
| 1692 | AudioDeviceTypeAddr inputDevice = AudioDeviceTypeAddr(AUDIO_DEVICE_IN_BUILTIN_MIC, ""); |
| 1693 | AudioDeviceTypeAddr inputDevice2 = AudioDeviceTypeAddr(AUDIO_DEVICE_IN_HDMI, ""); |
| 1694 | }; |
| 1695 | |
| 1696 | TEST_P(AudioPolicyManagerDevicesRoleForCapturePresetTest, DevicesRoleForCapturePreset) { |
| 1697 | const audio_source_t audioSource = std::get<0>(GetParam()); |
| 1698 | const device_role_t role = std::get<1>(GetParam()); |
| 1699 | |
| 1700 | // Test invalid device when setting |
| 1701 | const AudioDeviceTypeAddr outputDevice(AUDIO_DEVICE_OUT_SPEAKER, ""); |
| 1702 | const AudioDeviceTypeAddrVector outputDevices = {outputDevice}; |
| 1703 | ASSERT_EQ(BAD_VALUE, |
| 1704 | mManager->setDevicesRoleForCapturePreset(audioSource, role, outputDevices)); |
| 1705 | ASSERT_EQ(BAD_VALUE, |
| 1706 | mManager->addDevicesRoleForCapturePreset(audioSource, role, outputDevices)); |
| 1707 | AudioDeviceTypeAddrVector devices; |
| 1708 | ASSERT_EQ(NAME_NOT_FOUND, |
| 1709 | mManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices)); |
| 1710 | ASSERT_TRUE(devices.empty()); |
| 1711 | ASSERT_EQ(BAD_VALUE, |
| 1712 | mManager->removeDevicesRoleForCapturePreset(audioSource, role, outputDevices)); |
| 1713 | |
| 1714 | // Without setting, call get/remove/clear must fail |
| 1715 | ASSERT_EQ(NAME_NOT_FOUND, |
| 1716 | mManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices)); |
| 1717 | ASSERT_EQ(NAME_NOT_FOUND, |
| 1718 | mManager->removeDevicesRoleForCapturePreset(audioSource, role, devices)); |
| 1719 | ASSERT_EQ(NAME_NOT_FOUND, |
| 1720 | mManager->clearDevicesRoleForCapturePreset(audioSource, role)); |
| 1721 | |
| 1722 | // Test set/get devices role |
| 1723 | const AudioDeviceTypeAddrVector inputDevices = {inputDevice}; |
| 1724 | ASSERT_EQ(NO_ERROR, |
| 1725 | mManager->setDevicesRoleForCapturePreset(audioSource, role, inputDevices)); |
| 1726 | ASSERT_EQ(NO_ERROR, mManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices)); |
| 1727 | EXPECT_THAT(devices, UnorderedElementsAre(inputDevice)); |
| 1728 | |
| 1729 | // Test setting will change the previously set devices |
| 1730 | const AudioDeviceTypeAddrVector inputDevices2 = {inputDevice2}; |
| 1731 | ASSERT_EQ(NO_ERROR, |
| 1732 | mManager->setDevicesRoleForCapturePreset(audioSource, role, inputDevices2)); |
| 1733 | devices.clear(); |
| 1734 | ASSERT_EQ(NO_ERROR, mManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices)); |
| 1735 | EXPECT_THAT(devices, UnorderedElementsAre(inputDevice2)); |
| 1736 | |
| 1737 | // Test add devices |
| 1738 | ASSERT_EQ(NO_ERROR, |
| 1739 | mManager->addDevicesRoleForCapturePreset(audioSource, role, inputDevices)); |
| 1740 | devices.clear(); |
| 1741 | ASSERT_EQ(NO_ERROR, mManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices)); |
| 1742 | EXPECT_THAT(devices, UnorderedElementsAre(inputDevice, inputDevice2)); |
| 1743 | |
| 1744 | // Test remove devices |
| 1745 | ASSERT_EQ(NO_ERROR, |
| 1746 | mManager->removeDevicesRoleForCapturePreset(audioSource, role, inputDevices)); |
| 1747 | devices.clear(); |
| 1748 | ASSERT_EQ(NO_ERROR, mManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices)); |
| 1749 | EXPECT_THAT(devices, UnorderedElementsAre(inputDevice2)); |
| 1750 | |
| 1751 | // Test remove devices that are not set as the device role |
| 1752 | ASSERT_EQ(BAD_VALUE, |
| 1753 | mManager->removeDevicesRoleForCapturePreset(audioSource, role, inputDevices)); |
| 1754 | |
| 1755 | // Test clear devices |
| 1756 | ASSERT_EQ(NO_ERROR, |
| 1757 | mManager->clearDevicesRoleForCapturePreset(audioSource, role)); |
| 1758 | devices.clear(); |
| 1759 | ASSERT_EQ(NAME_NOT_FOUND, |
| 1760 | mManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices)); |
| 1761 | } |
| 1762 | |
| 1763 | INSTANTIATE_TEST_CASE_P( |
| 1764 | DevicesRoleForCapturePresetOperation, |
| 1765 | AudioPolicyManagerDevicesRoleForCapturePresetTest, |
| 1766 | testing::Values( |
| 1767 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_MIC, DEVICE_ROLE_PREFERRED}), |
| 1768 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_VOICE_UPLINK, |
| 1769 | DEVICE_ROLE_PREFERRED}), |
| 1770 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_VOICE_DOWNLINK, |
| 1771 | DEVICE_ROLE_PREFERRED}), |
| 1772 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_VOICE_CALL, DEVICE_ROLE_PREFERRED}), |
| 1773 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_CAMCORDER, DEVICE_ROLE_PREFERRED}), |
| 1774 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_VOICE_RECOGNITION, |
| 1775 | DEVICE_ROLE_PREFERRED}), |
| 1776 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_VOICE_COMMUNICATION, |
| 1777 | DEVICE_ROLE_PREFERRED}), |
| 1778 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_REMOTE_SUBMIX, |
| 1779 | DEVICE_ROLE_PREFERRED}), |
| 1780 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_UNPROCESSED, DEVICE_ROLE_PREFERRED}), |
| 1781 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_VOICE_PERFORMANCE, |
| 1782 | DEVICE_ROLE_PREFERRED}), |
| 1783 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_ECHO_REFERENCE, |
| 1784 | DEVICE_ROLE_PREFERRED}), |
| 1785 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_FM_TUNER, DEVICE_ROLE_PREFERRED}), |
| 1786 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_HOTWORD, DEVICE_ROLE_PREFERRED}) |
| 1787 | ) |
| 1788 | ); |