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