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