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> |
François Gaffie | 6ebbce0 | 2023-07-19 13:27:53 +0200 | [diff] [blame] | 29 | #include <android-base/properties.h> |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 30 | #include <android/content/AttributionSourceState.h> |
François Gaffie | 6ebbce0 | 2023-07-19 13:27:53 +0200 | [diff] [blame] | 31 | #include <hardware/audio_effect.h> |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 32 | #include <media/AudioPolicy.h> |
Mikhail Naganov | dc76968 | 2018-05-04 15:34:08 -0700 | [diff] [blame] | 33 | #include <media/PatchBuilder.h> |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 34 | #include <media/RecordingActivityTracker.h> |
| 35 | #include <utils/Log.h> |
| 36 | #include <utils/Vector.h> |
Oscar Azucena | 4f49ef6 | 2023-01-25 23:32:13 -0800 | [diff] [blame] | 37 | #include <cutils/multiuser.h> |
Mikhail Naganov | dc76968 | 2018-05-04 15:34:08 -0700 | [diff] [blame] | 38 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 39 | #include "AudioPolicyInterface.h" |
jiabin | b3f9804 | 2019-09-26 17:56:44 -0700 | [diff] [blame] | 40 | #include "AudioPolicyManagerTestClient.h" |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 41 | #include "AudioPolicyTestClient.h" |
| 42 | #include "AudioPolicyTestManager.h" |
| 43 | |
| 44 | using namespace android; |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 45 | using testing::UnorderedElementsAre; |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 46 | using android::content::AttributionSourceState; |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 47 | |
Jan Sebechlebsky | 0e7b2f1 | 2022-08-18 14:40:37 +0200 | [diff] [blame] | 48 | namespace { |
| 49 | |
| 50 | AudioMixMatchCriterion createUidCriterion(uint32_t uid, bool exclude = false) { |
| 51 | AudioMixMatchCriterion criterion; |
| 52 | criterion.mValue.mUid = uid; |
| 53 | criterion.mRule = exclude ? RULE_EXCLUDE_UID : RULE_MATCH_UID; |
| 54 | return criterion; |
| 55 | } |
| 56 | |
Oscar Azucena | 873d10f | 2023-01-12 18:34:42 -0800 | [diff] [blame] | 57 | AudioMixMatchCriterion createUserIdCriterion(int userId, bool exclude = false) { |
| 58 | AudioMixMatchCriterion criterion; |
| 59 | criterion.mValue.mUserId = userId; |
| 60 | criterion.mRule = exclude ? RULE_EXCLUDE_USERID : RULE_MATCH_USERID; |
| 61 | return criterion; |
| 62 | } |
| 63 | |
Jan Sebechlebsky | 0e7b2f1 | 2022-08-18 14:40:37 +0200 | [diff] [blame] | 64 | AudioMixMatchCriterion createUsageCriterion(audio_usage_t usage, bool exclude = false) { |
| 65 | AudioMixMatchCriterion criterion; |
| 66 | criterion.mValue.mUsage = usage; |
| 67 | criterion.mRule = exclude ? RULE_EXCLUDE_ATTRIBUTE_USAGE : RULE_MATCH_ATTRIBUTE_USAGE; |
| 68 | return criterion; |
| 69 | } |
| 70 | |
| 71 | AudioMixMatchCriterion createCapturePresetCriterion(audio_source_t source, bool exclude = false) { |
| 72 | AudioMixMatchCriterion criterion; |
| 73 | criterion.mValue.mSource = source; |
| 74 | criterion.mRule = exclude ? |
| 75 | RULE_EXCLUDE_ATTRIBUTE_CAPTURE_PRESET : RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET; |
| 76 | return criterion; |
| 77 | } |
| 78 | |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 79 | AudioMixMatchCriterion createSessionIdCriterion(audio_session_t session, bool exclude = false) { |
| 80 | AudioMixMatchCriterion criterion; |
| 81 | criterion.mValue.mAudioSessionId = session; |
| 82 | criterion.mRule = exclude ? |
| 83 | RULE_EXCLUDE_AUDIO_SESSION_ID : RULE_MATCH_AUDIO_SESSION_ID; |
| 84 | return criterion; |
| 85 | } |
| 86 | |
Jan Sebechlebsky | 8e10cea | 2023-03-29 11:43:31 +0200 | [diff] [blame] | 87 | // TODO b/182392769: use attribution source util |
| 88 | AttributionSourceState createAttributionSourceState(uid_t uid) { |
| 89 | AttributionSourceState attributionSourceState; |
| 90 | attributionSourceState.uid = uid; |
| 91 | attributionSourceState.token = sp<BBinder>::make(); |
| 92 | return attributionSourceState; |
| 93 | } |
| 94 | |
jiabin | de7ae44 | 2024-02-06 00:57:36 +0000 | [diff] [blame^] | 95 | bool equals(const audio_config_base_t& config1, const audio_config_base_t& config2) { |
| 96 | return config1.format == config2.format |
| 97 | && config1.sample_rate == config2.sample_rate |
| 98 | && config1.channel_mask == config2.channel_mask; |
| 99 | } |
| 100 | |
Jan Sebechlebsky | 0e7b2f1 | 2022-08-18 14:40:37 +0200 | [diff] [blame] | 101 | } // namespace |
| 102 | |
Mikhail Naganov | 68e3f64 | 2023-04-28 13:06:32 -0700 | [diff] [blame] | 103 | TEST(AudioPolicyConfigTest, DefaultConfigForTestsIsEmpty) { |
| 104 | auto config = AudioPolicyConfig::createWritableForTests(); |
| 105 | EXPECT_TRUE(config->getSource().empty()); |
| 106 | EXPECT_TRUE(config->getHwModules().isEmpty()); |
| 107 | EXPECT_TRUE(config->getInputDevices().isEmpty()); |
| 108 | EXPECT_TRUE(config->getOutputDevices().isEmpty()); |
| 109 | } |
| 110 | |
| 111 | TEST(AudioPolicyConfigTest, FallbackToDefault) { |
| 112 | auto config = AudioPolicyConfig::loadFromApmXmlConfigWithFallback( |
| 113 | base::GetExecutableDirectory() + "/test_invalid_audio_policy_configuration.xml"); |
| 114 | EXPECT_EQ(AudioPolicyConfig::kDefaultConfigSource, config->getSource()); |
| 115 | } |
| 116 | |
| 117 | TEST(AudioPolicyConfigTest, LoadForTests) { |
| 118 | { |
| 119 | auto result = AudioPolicyConfig::loadFromCustomXmlConfigForTests( |
| 120 | base::GetExecutableDirectory() + "/test_invalid_audio_policy_configuration.xml"); |
| 121 | EXPECT_FALSE(result.ok()); |
| 122 | } |
| 123 | { |
| 124 | const std::string source = |
| 125 | base::GetExecutableDirectory() + "/test_audio_policy_configuration.xml"; |
| 126 | auto result = AudioPolicyConfig::loadFromCustomXmlConfigForTests(source); |
| 127 | ASSERT_TRUE(result.ok()); |
| 128 | EXPECT_EQ(source, result.value()->getSource()); |
| 129 | EXPECT_FALSE(result.value()->getHwModules().isEmpty()); |
| 130 | EXPECT_FALSE(result.value()->getInputDevices().isEmpty()); |
| 131 | EXPECT_FALSE(result.value()->getOutputDevices().isEmpty()); |
| 132 | } |
| 133 | } |
| 134 | |
Mikhail Naganov | 4783555 | 2019-05-14 10:32:51 -0700 | [diff] [blame] | 135 | TEST(AudioPolicyManagerTestInit, EngineFailure) { |
| 136 | AudioPolicyTestClient client; |
Mikhail Naganov | 68e3f64 | 2023-04-28 13:06:32 -0700 | [diff] [blame] | 137 | auto config = AudioPolicyConfig::createWritableForTests(); |
| 138 | config->setDefault(); |
| 139 | config->setEngineLibraryNameSuffix("non-existent"); |
| 140 | AudioPolicyTestManager manager(config, &client); |
Mikhail Naganov | 4783555 | 2019-05-14 10:32:51 -0700 | [diff] [blame] | 141 | ASSERT_EQ(NO_INIT, manager.initialize()); |
| 142 | ASSERT_EQ(NO_INIT, manager.initCheck()); |
| 143 | } |
| 144 | |
| 145 | TEST(AudioPolicyManagerTestInit, ClientFailure) { |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 146 | AudioPolicyTestClient client; |
| 147 | AudioPolicyTestManager manager(&client); |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 148 | // Since the default client fails to open anything, |
| 149 | // APM should indicate that the initialization didn't succeed. |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 150 | ASSERT_EQ(NO_INIT, manager.initialize()); |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 151 | ASSERT_EQ(NO_INIT, manager.initCheck()); |
| 152 | } |
| 153 | |
| 154 | |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 155 | class PatchCountCheck { |
| 156 | public: |
| 157 | explicit PatchCountCheck(AudioPolicyManagerTestClient *client) |
| 158 | : mClient{client}, |
| 159 | mInitialCount{mClient->getActivePatchesCount()} {} |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 160 | int deltaFromSnapshot() const { |
| 161 | size_t currentCount = mClient->getActivePatchesCount(); |
| 162 | if (mInitialCount <= currentCount) { |
| 163 | return currentCount - mInitialCount; |
| 164 | } else { |
| 165 | return -(static_cast<int>(mInitialCount - currentCount)); |
| 166 | } |
| 167 | } |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 168 | private: |
| 169 | const AudioPolicyManagerTestClient *mClient; |
| 170 | const size_t mInitialCount; |
| 171 | }; |
| 172 | |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 173 | class AudioPolicyManagerTest : public testing::Test { |
| 174 | protected: |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 175 | void SetUp() override; |
| 176 | void TearDown() override; |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 177 | virtual void SetUpManagerConfig(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 178 | |
| 179 | void dumpToLog(); |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 180 | // When explicit routing is needed, selectedDeviceId needs to be set as the wanted port |
| 181 | // id. Otherwise, selectedDeviceId needs to be initialized as AUDIO_PORT_HANDLE_NONE. |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 182 | void getOutputForAttr( |
| 183 | audio_port_handle_t *selectedDeviceId, |
| 184 | audio_format_t format, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 185 | audio_channel_mask_t channelMask, |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 186 | int sampleRate, |
| 187 | audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE, |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 188 | audio_io_handle_t *output = nullptr, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 189 | audio_port_handle_t *portId = nullptr, |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 190 | audio_attributes_t attr = {}, |
jiabin | 3ff8d7d | 2022-12-13 06:27:44 +0000 | [diff] [blame] | 191 | audio_session_t session = AUDIO_SESSION_NONE, |
jiabin | 5eaf096 | 2022-12-20 20:11:38 +0000 | [diff] [blame] | 192 | int uid = 0, |
| 193 | bool* isBitPerfect = nullptr); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 194 | void getInputForAttr( |
| 195 | const audio_attributes_t &attr, |
François Gaffie | 6ebbce0 | 2023-07-19 13:27:53 +0200 | [diff] [blame] | 196 | audio_io_handle_t *input, |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 197 | audio_session_t session, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 198 | audio_unique_id_t riid, |
| 199 | audio_port_handle_t *selectedDeviceId, |
| 200 | audio_format_t format, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 201 | audio_channel_mask_t channelMask, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 202 | int sampleRate, |
| 203 | audio_input_flags_t flags = AUDIO_INPUT_FLAG_NONE, |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 204 | audio_port_handle_t *portId = nullptr); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 205 | PatchCountCheck snapshotPatchCount() { return PatchCountCheck(mClient.get()); } |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 206 | |
Mikhail Naganov | 0805de1 | 2022-02-15 23:00:07 +0000 | [diff] [blame] | 207 | void getAudioPorts(audio_port_type_t type, audio_port_role_t role, |
| 208 | std::vector<audio_port_v7>* ports); |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 209 | // Tries to find a device port. If 'foundPort' isn't nullptr, |
| 210 | // will generate a failure if the port hasn't been found. |
| 211 | bool findDevicePort(audio_port_role_t role, audio_devices_t deviceType, |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 212 | const std::string &address, audio_port_v7 *foundPort); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 213 | static audio_port_handle_t getDeviceIdFromPatch(const struct audio_patch* patch); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 214 | virtual AudioPolicyManagerTestClient* getClient() { return new AudioPolicyManagerTestClient; } |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 215 | |
Mikhail Naganov | 68e3f64 | 2023-04-28 13:06:32 -0700 | [diff] [blame] | 216 | sp<AudioPolicyConfig> mConfig; |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 217 | std::unique_ptr<AudioPolicyManagerTestClient> mClient; |
| 218 | std::unique_ptr<AudioPolicyTestManager> mManager; |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 219 | |
jiabin | 24ff57a | 2023-11-27 21:06:51 +0000 | [diff] [blame] | 220 | constexpr static const uint32_t k48000SamplingRate = 48000; |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 221 | }; |
| 222 | |
| 223 | void AudioPolicyManagerTest::SetUp() { |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 224 | mClient.reset(getClient()); |
Mikhail Naganov | d4c21aa | 2021-10-05 15:10:16 -0700 | [diff] [blame] | 225 | ASSERT_NO_FATAL_FAILURE(SetUpManagerConfig()); // Subclasses may want to customize the config. |
Mikhail Naganov | 68e3f64 | 2023-04-28 13:06:32 -0700 | [diff] [blame] | 226 | mManager.reset(new AudioPolicyTestManager(mConfig, mClient.get())); |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 227 | ASSERT_EQ(NO_ERROR, mManager->initialize()); |
| 228 | ASSERT_EQ(NO_ERROR, mManager->initCheck()); |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 229 | } |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 230 | |
| 231 | void AudioPolicyManagerTest::TearDown() { |
| 232 | mManager.reset(); |
| 233 | mClient.reset(); |
| 234 | } |
| 235 | |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 236 | void AudioPolicyManagerTest::SetUpManagerConfig() { |
Mikhail Naganov | 68e3f64 | 2023-04-28 13:06:32 -0700 | [diff] [blame] | 237 | mConfig = AudioPolicyConfig::createWritableForTests(); |
| 238 | mConfig->setDefault(); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 241 | void AudioPolicyManagerTest::dumpToLog() { |
Mikhail Naganov | 21b4336 | 2018-06-04 10:37:09 -0700 | [diff] [blame] | 242 | int pipefd[2]; |
| 243 | ASSERT_NE(-1, pipe(pipefd)); |
| 244 | pid_t cpid = fork(); |
| 245 | ASSERT_NE(-1, cpid); |
| 246 | if (cpid == 0) { |
| 247 | // Child process reads from the pipe and logs. |
| 248 | close(pipefd[1]); |
| 249 | std::string line; |
| 250 | char buf; |
| 251 | while (read(pipefd[0], &buf, sizeof(buf)) > 0) { |
| 252 | if (buf != '\n') { |
| 253 | line += buf; |
| 254 | } else { |
| 255 | ALOGI("%s", line.c_str()); |
| 256 | line = ""; |
| 257 | } |
| 258 | } |
| 259 | if (!line.empty()) ALOGI("%s", line.c_str()); |
| 260 | close(pipefd[0]); |
| 261 | _exit(EXIT_SUCCESS); |
| 262 | } else { |
| 263 | // Parent does the dump and checks the status code. |
| 264 | close(pipefd[0]); |
| 265 | ASSERT_EQ(NO_ERROR, mManager->dump(pipefd[1])); |
| 266 | close(pipefd[1]); |
| 267 | wait(NULL); // Wait for the child to exit. |
| 268 | } |
| 269 | } |
| 270 | |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 271 | void AudioPolicyManagerTest::getOutputForAttr( |
| 272 | audio_port_handle_t *selectedDeviceId, |
| 273 | audio_format_t format, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 274 | audio_channel_mask_t channelMask, |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 275 | int sampleRate, |
| 276 | audio_output_flags_t flags, |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 277 | audio_io_handle_t *output, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 278 | audio_port_handle_t *portId, |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 279 | audio_attributes_t attr, |
jiabin | 3ff8d7d | 2022-12-13 06:27:44 +0000 | [diff] [blame] | 280 | audio_session_t session, |
jiabin | 5eaf096 | 2022-12-20 20:11:38 +0000 | [diff] [blame] | 281 | int uid, |
| 282 | bool* isBitPerfect) { |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 283 | audio_io_handle_t localOutput; |
| 284 | if (!output) output = &localOutput; |
| 285 | *output = AUDIO_IO_HANDLE_NONE; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 286 | audio_stream_type_t stream = AUDIO_STREAM_DEFAULT; |
| 287 | audio_config_t config = AUDIO_CONFIG_INITIALIZER; |
| 288 | config.sample_rate = sampleRate; |
| 289 | config.channel_mask = channelMask; |
| 290 | config.format = format; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 291 | audio_port_handle_t localPortId; |
| 292 | if (!portId) portId = &localPortId; |
| 293 | *portId = AUDIO_PORT_HANDLE_NONE; |
Eric Laurent | 8a1095a | 2019-11-08 14:44:16 -0800 | [diff] [blame] | 294 | AudioPolicyInterface::output_type_t outputType; |
Eric Laurent | b0a7bc9 | 2022-04-05 15:06:08 +0200 | [diff] [blame] | 295 | bool isSpatialized; |
jiabin | 5eaf096 | 2022-12-20 20:11:38 +0000 | [diff] [blame] | 296 | bool isBitPerfectInternal; |
Jan Sebechlebsky | 8e10cea | 2023-03-29 11:43:31 +0200 | [diff] [blame] | 297 | AttributionSourceState attributionSource = createAttributionSourceState(uid); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 298 | ASSERT_EQ(OK, mManager->getOutputForAttr( |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 299 | &attr, output, session, &stream, attributionSource, &config, &flags, |
jiabin | 5eaf096 | 2022-12-20 20:11:38 +0000 | [diff] [blame] | 300 | selectedDeviceId, portId, {}, &outputType, &isSpatialized, |
| 301 | isBitPerfect == nullptr ? &isBitPerfectInternal : isBitPerfect)); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 302 | ASSERT_NE(AUDIO_PORT_HANDLE_NONE, *portId); |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 303 | ASSERT_NE(AUDIO_IO_HANDLE_NONE, *output); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 304 | } |
| 305 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 306 | void AudioPolicyManagerTest::getInputForAttr( |
| 307 | const audio_attributes_t &attr, |
François Gaffie | 6ebbce0 | 2023-07-19 13:27:53 +0200 | [diff] [blame] | 308 | audio_io_handle_t *input, |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 309 | const audio_session_t session, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 310 | audio_unique_id_t riid, |
| 311 | audio_port_handle_t *selectedDeviceId, |
| 312 | audio_format_t format, |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 313 | audio_channel_mask_t channelMask, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 314 | int sampleRate, |
| 315 | audio_input_flags_t flags, |
| 316 | audio_port_handle_t *portId) { |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 317 | audio_config_base_t config = AUDIO_CONFIG_BASE_INITIALIZER; |
| 318 | config.sample_rate = sampleRate; |
| 319 | config.channel_mask = channelMask; |
| 320 | config.format = format; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 321 | audio_port_handle_t localPortId; |
| 322 | if (!portId) portId = &localPortId; |
| 323 | *portId = AUDIO_PORT_HANDLE_NONE; |
| 324 | AudioPolicyInterface::input_type_t inputType; |
Jan Sebechlebsky | 8e10cea | 2023-03-29 11:43:31 +0200 | [diff] [blame] | 325 | AttributionSourceState attributionSource = createAttributionSourceState(/*uid=*/ 0); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 326 | ASSERT_EQ(OK, mManager->getInputForAttr( |
François Gaffie | 6ebbce0 | 2023-07-19 13:27:53 +0200 | [diff] [blame] | 327 | &attr, input, riid, session, attributionSource, &config, flags, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 328 | selectedDeviceId, &inputType, portId)); |
| 329 | ASSERT_NE(AUDIO_PORT_HANDLE_NONE, *portId); |
| 330 | } |
| 331 | |
Mikhail Naganov | 0805de1 | 2022-02-15 23:00:07 +0000 | [diff] [blame] | 332 | void AudioPolicyManagerTest::getAudioPorts(audio_port_type_t type, audio_port_role_t role, |
| 333 | std::vector<audio_port_v7>* ports) { |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 334 | uint32_t numPorts = 0; |
| 335 | uint32_t generation1; |
| 336 | status_t ret; |
| 337 | |
Mikhail Naganov | 0805de1 | 2022-02-15 23:00:07 +0000 | [diff] [blame] | 338 | ret = mManager->listAudioPorts(role, type, &numPorts, nullptr, &generation1); |
| 339 | ASSERT_EQ(NO_ERROR, ret) << "mManager->listAudioPorts returned error"; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 340 | |
| 341 | uint32_t generation2; |
Mikhail Naganov | 0805de1 | 2022-02-15 23:00:07 +0000 | [diff] [blame] | 342 | ports->resize(numPorts); |
| 343 | ret = mManager->listAudioPorts(role, type, &numPorts, ports->data(), &generation2); |
| 344 | ASSERT_EQ(NO_ERROR, ret) << "mManager->listAudioPorts returned error"; |
| 345 | ASSERT_EQ(generation1, generation2) << "Generations changed during ports retrieval"; |
| 346 | } |
| 347 | |
| 348 | bool AudioPolicyManagerTest::findDevicePort(audio_port_role_t role, |
| 349 | audio_devices_t deviceType, const std::string &address, audio_port_v7 *foundPort) { |
| 350 | std::vector<audio_port_v7> ports; |
| 351 | getAudioPorts(AUDIO_PORT_TYPE_DEVICE, role, &ports); |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 352 | if (HasFailure()) return false; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 353 | |
| 354 | for (const auto &port : ports) { |
| 355 | if (port.role == role && port.ext.device.type == deviceType && |
| 356 | (strncmp(port.ext.device.address, address.c_str(), |
| 357 | AUDIO_DEVICE_MAX_ADDRESS_LEN) == 0)) { |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 358 | if (foundPort) *foundPort = port; |
| 359 | return true; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 360 | } |
| 361 | } |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 362 | if (foundPort) { |
| 363 | ADD_FAILURE() << "Device port with role " << role << " and address " |
| 364 | << address << " not found"; |
| 365 | } |
| 366 | return false; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 367 | } |
| 368 | |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 369 | audio_port_handle_t AudioPolicyManagerTest::getDeviceIdFromPatch( |
| 370 | const struct audio_patch* patch) { |
| 371 | // The logic here is the same as the one in AudioIoDescriptor. |
| 372 | // Note this function is aim to get routed device id for test. |
| 373 | // In that case, device to device patch is not expected here. |
| 374 | if (patch->num_sources != 0 && patch->num_sinks != 0) { |
| 375 | if (patch->sources[0].type == AUDIO_PORT_TYPE_MIX) { |
| 376 | return patch->sinks[0].id; |
| 377 | } else { |
| 378 | return patch->sources[0].id; |
| 379 | } |
| 380 | } |
| 381 | return AUDIO_PORT_HANDLE_NONE; |
| 382 | } |
| 383 | |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 384 | |
| 385 | TEST_F(AudioPolicyManagerTest, InitSuccess) { |
| 386 | // SetUp must finish with no assertions. |
| 387 | } |
| 388 | |
| 389 | TEST_F(AudioPolicyManagerTest, Dump) { |
| 390 | dumpToLog(); |
| 391 | } |
| 392 | |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 393 | TEST_F(AudioPolicyManagerTest, CreateAudioPatchFailure) { |
| 394 | audio_patch patch{}; |
| 395 | audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE; |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 396 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 397 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(nullptr, &handle, 0)); |
| 398 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(&patch, nullptr, 0)); |
| 399 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(&patch, &handle, 0)); |
| 400 | patch.num_sources = AUDIO_PATCH_PORTS_MAX + 1; |
| 401 | patch.num_sinks = 1; |
| 402 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(&patch, &handle, 0)); |
| 403 | patch.num_sources = 1; |
| 404 | patch.num_sinks = AUDIO_PATCH_PORTS_MAX + 1; |
| 405 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(&patch, &handle, 0)); |
| 406 | patch.num_sources = 2; |
| 407 | patch.num_sinks = 1; |
| 408 | ASSERT_EQ(INVALID_OPERATION, mManager->createAudioPatch(&patch, &handle, 0)); |
| 409 | patch = {}; |
| 410 | patch.num_sources = 1; |
| 411 | patch.sources[0].role = AUDIO_PORT_ROLE_SINK; |
| 412 | patch.num_sinks = 1; |
| 413 | patch.sinks[0].role = AUDIO_PORT_ROLE_SINK; |
| 414 | ASSERT_EQ(INVALID_OPERATION, mManager->createAudioPatch(&patch, &handle, 0)); |
| 415 | patch = {}; |
| 416 | patch.num_sources = 1; |
| 417 | patch.sources[0].role = AUDIO_PORT_ROLE_SOURCE; |
| 418 | patch.num_sinks = 1; |
| 419 | patch.sinks[0].role = AUDIO_PORT_ROLE_SOURCE; |
| 420 | ASSERT_EQ(INVALID_OPERATION, mManager->createAudioPatch(&patch, &handle, 0)); |
| 421 | // Verify that the handle is left unchanged. |
| 422 | ASSERT_EQ(AUDIO_PATCH_HANDLE_NONE, handle); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 423 | ASSERT_EQ(0, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | TEST_F(AudioPolicyManagerTest, CreateAudioPatchFromMix) { |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 427 | audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE; |
| 428 | uid_t uid = 42; |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 429 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | c0d0498 | 2020-03-02 21:02:28 +0000 | [diff] [blame] | 430 | ASSERT_FALSE(mManager->getAvailableInputDevices().isEmpty()); |
Mikhail Naganov | dc76968 | 2018-05-04 15:34:08 -0700 | [diff] [blame] | 431 | PatchBuilder patchBuilder; |
Mikhail Naganov | c0d0498 | 2020-03-02 21:02:28 +0000 | [diff] [blame] | 432 | patchBuilder.addSource(mManager->getAvailableInputDevices()[0]). |
Mikhail Naganov | dc76968 | 2018-05-04 15:34:08 -0700 | [diff] [blame] | 433 | addSink(mManager->getConfig().getDefaultOutputDevice()); |
| 434 | ASSERT_EQ(NO_ERROR, mManager->createAudioPatch(patchBuilder.patch(), &handle, uid)); |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 435 | ASSERT_NE(AUDIO_PATCH_HANDLE_NONE, handle); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 436 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | // TODO: Add patch creation tests that involve already existing patch |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 440 | |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 441 | enum |
| 442 | { |
| 443 | MSD_AUDIO_PATCH_COUNT_NUM_AUDIO_PATCHES_INDEX = 0, |
| 444 | MSD_AUDIO_PATCH_COUNT_NAME_INDEX = 1 |
| 445 | }; |
| 446 | using MsdAudioPatchCountSpecification = std::tuple<size_t, std::string>; |
| 447 | |
| 448 | class AudioPolicyManagerTestMsd : public AudioPolicyManagerTest, |
| 449 | public ::testing::WithParamInterface<MsdAudioPatchCountSpecification> { |
| 450 | public: |
| 451 | AudioPolicyManagerTestMsd(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 452 | protected: |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 453 | void SetUpManagerConfig() override; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 454 | void TearDown() override; |
Dorin Drimus | 94d9441 | 2022-02-02 09:05:02 +0100 | [diff] [blame] | 455 | AudioProfileVector getDirectProfilesForAttributes(const audio_attributes_t& attr); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 456 | |
| 457 | sp<DeviceDescriptor> mMsdOutputDevice; |
| 458 | sp<DeviceDescriptor> mMsdInputDevice; |
Eric Laurent | 74c38dc | 2020-12-23 18:19:44 +0100 | [diff] [blame] | 459 | sp<DeviceDescriptor> mDefaultOutputDevice; |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 460 | |
| 461 | const size_t mExpectedAudioPatchCount; |
| 462 | sp<DeviceDescriptor> mSpdifDevice; |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 463 | |
| 464 | sp<DeviceDescriptor> mHdmiInputDevice; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 465 | }; |
| 466 | |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 467 | AudioPolicyManagerTestMsd::AudioPolicyManagerTestMsd() |
| 468 | : mExpectedAudioPatchCount(std::get<MSD_AUDIO_PATCH_COUNT_NUM_AUDIO_PATCHES_INDEX>( |
| 469 | GetParam())) {} |
| 470 | |
| 471 | INSTANTIATE_TEST_CASE_P( |
| 472 | MsdAudioPatchCount, |
| 473 | AudioPolicyManagerTestMsd, |
| 474 | ::testing::Values( |
| 475 | MsdAudioPatchCountSpecification(1u, "single"), |
| 476 | MsdAudioPatchCountSpecification(2u, "dual") |
| 477 | ), |
| 478 | [](const ::testing::TestParamInfo<MsdAudioPatchCountSpecification> &info) { |
| 479 | return std::get<MSD_AUDIO_PATCH_COUNT_NAME_INDEX>(info.param); } |
| 480 | ); |
| 481 | |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 482 | void AudioPolicyManagerTestMsd::SetUpManagerConfig() { |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 483 | // 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] | 484 | ASSERT_NO_FATAL_FAILURE(AudioPolicyManagerTest::SetUpManagerConfig()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 485 | mMsdOutputDevice = new DeviceDescriptor(AUDIO_DEVICE_OUT_BUS); |
| 486 | sp<AudioProfile> pcmOutputProfile = new AudioProfile( |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 487 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, k48000SamplingRate); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 488 | sp<AudioProfile> ac3OutputProfile = new AudioProfile( |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 489 | AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, k48000SamplingRate); |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 490 | sp<AudioProfile> iec958OutputProfile = new AudioProfile( |
Dean Wheatley | 16809da | 2022-12-09 14:55:46 +1100 | [diff] [blame] | 491 | AUDIO_FORMAT_IEC60958, AUDIO_CHANNEL_INDEX_MASK_24, k48000SamplingRate); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 492 | mMsdOutputDevice->addAudioProfile(pcmOutputProfile); |
| 493 | mMsdOutputDevice->addAudioProfile(ac3OutputProfile); |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 494 | mMsdOutputDevice->addAudioProfile(iec958OutputProfile); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 495 | mMsdInputDevice = new DeviceDescriptor(AUDIO_DEVICE_IN_BUS); |
| 496 | // Match output profile from AudioPolicyConfig::setDefault. |
| 497 | sp<AudioProfile> pcmInputProfile = new AudioProfile( |
| 498 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_STEREO, 44100); |
| 499 | mMsdInputDevice->addAudioProfile(pcmInputProfile); |
Mikhail Naganov | 68e3f64 | 2023-04-28 13:06:32 -0700 | [diff] [blame] | 500 | mConfig->addDevice(mMsdOutputDevice); |
| 501 | mConfig->addDevice(mMsdInputDevice); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 502 | |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 503 | if (mExpectedAudioPatchCount == 2) { |
| 504 | // Add SPDIF device with PCM output profile as a second device for dual MSD audio patching. |
| 505 | mSpdifDevice = new DeviceDescriptor(AUDIO_DEVICE_OUT_SPDIF); |
| 506 | mSpdifDevice->addAudioProfile(pcmOutputProfile); |
Mikhail Naganov | 68e3f64 | 2023-04-28 13:06:32 -0700 | [diff] [blame] | 507 | mConfig->addDevice(mSpdifDevice); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 508 | |
| 509 | sp<OutputProfile> spdifOutputProfile = new OutputProfile("spdif output"); |
| 510 | spdifOutputProfile->addAudioProfile(pcmOutputProfile); |
| 511 | spdifOutputProfile->addSupportedDevice(mSpdifDevice); |
Mikhail Naganov | 68e3f64 | 2023-04-28 13:06:32 -0700 | [diff] [blame] | 512 | mConfig->getHwModules().getModuleFromName(AUDIO_HARDWARE_MODULE_ID_PRIMARY)-> |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 513 | addOutputProfile(spdifOutputProfile); |
| 514 | } |
| 515 | |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 516 | sp<HwModule> msdModule = new HwModule(AUDIO_HARDWARE_MODULE_ID_MSD, 2 /*halVersionMajor*/); |
Mikhail Naganov | 68e3f64 | 2023-04-28 13:06:32 -0700 | [diff] [blame] | 517 | HwModuleCollection modules = mConfig->getHwModules(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 518 | modules.add(msdModule); |
Mikhail Naganov | 68e3f64 | 2023-04-28 13:06:32 -0700 | [diff] [blame] | 519 | mConfig->setHwModules(modules); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 520 | |
jiabin | 5740f08 | 2019-08-19 15:08:30 -0700 | [diff] [blame] | 521 | sp<OutputProfile> msdOutputProfile = new OutputProfile("msd input"); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 522 | msdOutputProfile->addAudioProfile(pcmOutputProfile); |
| 523 | msdOutputProfile->addSupportedDevice(mMsdOutputDevice); |
| 524 | msdModule->addOutputProfile(msdOutputProfile); |
jiabin | 5740f08 | 2019-08-19 15:08:30 -0700 | [diff] [blame] | 525 | sp<OutputProfile> msdCompressedOutputProfile = new OutputProfile("msd compressed input"); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 526 | msdCompressedOutputProfile->addAudioProfile(ac3OutputProfile); |
| 527 | msdCompressedOutputProfile->setFlags( |
| 528 | AUDIO_OUTPUT_FLAG_DIRECT | AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD | |
| 529 | AUDIO_OUTPUT_FLAG_NON_BLOCKING); |
| 530 | msdCompressedOutputProfile->addSupportedDevice(mMsdOutputDevice); |
| 531 | msdModule->addOutputProfile(msdCompressedOutputProfile); |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 532 | sp<OutputProfile> msdIec958OutputProfile = new OutputProfile("msd iec958 input"); |
| 533 | msdIec958OutputProfile->addAudioProfile(iec958OutputProfile); |
| 534 | msdIec958OutputProfile->setFlags(AUDIO_OUTPUT_FLAG_DIRECT); |
| 535 | msdIec958OutputProfile->addSupportedDevice(mMsdOutputDevice); |
| 536 | msdModule->addOutputProfile(msdIec958OutputProfile); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 537 | |
jiabin | 5740f08 | 2019-08-19 15:08:30 -0700 | [diff] [blame] | 538 | sp<InputProfile> msdInputProfile = new InputProfile("msd output"); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 539 | msdInputProfile->addAudioProfile(pcmInputProfile); |
| 540 | msdInputProfile->addSupportedDevice(mMsdInputDevice); |
| 541 | msdModule->addInputProfile(msdInputProfile); |
| 542 | |
| 543 | // Add a profile with another encoding to the default device to test routing |
| 544 | // of streams that are not supported by MSD. |
| 545 | sp<AudioProfile> dtsOutputProfile = new AudioProfile( |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 546 | AUDIO_FORMAT_DTS, AUDIO_CHANNEL_OUT_5POINT1, k48000SamplingRate); |
Mikhail Naganov | 68e3f64 | 2023-04-28 13:06:32 -0700 | [diff] [blame] | 547 | mConfig->getDefaultOutputDevice()->addAudioProfile(dtsOutputProfile); |
jiabin | 5740f08 | 2019-08-19 15:08:30 -0700 | [diff] [blame] | 548 | sp<OutputProfile> primaryEncodedOutputProfile = new OutputProfile("encoded"); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 549 | primaryEncodedOutputProfile->addAudioProfile(dtsOutputProfile); |
| 550 | primaryEncodedOutputProfile->setFlags(AUDIO_OUTPUT_FLAG_DIRECT); |
Mikhail Naganov | 68e3f64 | 2023-04-28 13:06:32 -0700 | [diff] [blame] | 551 | primaryEncodedOutputProfile->addSupportedDevice(mConfig->getDefaultOutputDevice()); |
| 552 | mConfig->getHwModules().getModuleFromName(AUDIO_HARDWARE_MODULE_ID_PRIMARY)-> |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 553 | addOutputProfile(primaryEncodedOutputProfile); |
Eric Laurent | 74c38dc | 2020-12-23 18:19:44 +0100 | [diff] [blame] | 554 | |
Mikhail Naganov | 68e3f64 | 2023-04-28 13:06:32 -0700 | [diff] [blame] | 555 | mDefaultOutputDevice = mConfig->getDefaultOutputDevice(); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 556 | if (mExpectedAudioPatchCount == 2) { |
| 557 | mSpdifDevice->addAudioProfile(dtsOutputProfile); |
| 558 | primaryEncodedOutputProfile->addSupportedDevice(mSpdifDevice); |
| 559 | } |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 560 | |
| 561 | // Add HDMI input device with IEC60958 profile for HDMI in -> MSD patching. |
| 562 | mHdmiInputDevice = new DeviceDescriptor(AUDIO_DEVICE_IN_HDMI); |
| 563 | sp<AudioProfile> iec958InputProfile = new AudioProfile( |
Dean Wheatley | 16809da | 2022-12-09 14:55:46 +1100 | [diff] [blame] | 564 | AUDIO_FORMAT_IEC60958, AUDIO_CHANNEL_INDEX_MASK_24, k48000SamplingRate); |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 565 | mHdmiInputDevice->addAudioProfile(iec958InputProfile); |
Mikhail Naganov | 68e3f64 | 2023-04-28 13:06:32 -0700 | [diff] [blame] | 566 | mConfig->addDevice(mHdmiInputDevice); |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 567 | sp<InputProfile> hdmiInputProfile = new InputProfile("hdmi input"); |
| 568 | hdmiInputProfile->addAudioProfile(iec958InputProfile); |
| 569 | hdmiInputProfile->setFlags(AUDIO_INPUT_FLAG_DIRECT); |
| 570 | hdmiInputProfile->addSupportedDevice(mHdmiInputDevice); |
Mikhail Naganov | 68e3f64 | 2023-04-28 13:06:32 -0700 | [diff] [blame] | 571 | mConfig->getHwModules().getModuleFromName(AUDIO_HARDWARE_MODULE_ID_PRIMARY)-> |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 572 | addInputProfile(hdmiInputProfile); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | void AudioPolicyManagerTestMsd::TearDown() { |
| 576 | mMsdOutputDevice.clear(); |
| 577 | mMsdInputDevice.clear(); |
Eric Laurent | 74c38dc | 2020-12-23 18:19:44 +0100 | [diff] [blame] | 578 | mDefaultOutputDevice.clear(); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 579 | mSpdifDevice.clear(); |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 580 | mHdmiInputDevice.clear(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 581 | AudioPolicyManagerTest::TearDown(); |
| 582 | } |
| 583 | |
Dorin Drimus | 94d9441 | 2022-02-02 09:05:02 +0100 | [diff] [blame] | 584 | AudioProfileVector AudioPolicyManagerTestMsd::getDirectProfilesForAttributes( |
| 585 | const audio_attributes_t& attr) { |
| 586 | AudioProfileVector audioProfilesVector; |
| 587 | mManager->getDirectProfilesForAttributes(&attr, audioProfilesVector); |
| 588 | return audioProfilesVector; |
| 589 | } |
| 590 | |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 591 | TEST_P(AudioPolicyManagerTestMsd, InitSuccess) { |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 592 | ASSERT_TRUE(mMsdOutputDevice); |
| 593 | ASSERT_TRUE(mMsdInputDevice); |
Eric Laurent | 74c38dc | 2020-12-23 18:19:44 +0100 | [diff] [blame] | 594 | ASSERT_TRUE(mDefaultOutputDevice); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 595 | } |
| 596 | |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 597 | TEST_P(AudioPolicyManagerTestMsd, Dump) { |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 598 | dumpToLog(); |
| 599 | } |
| 600 | |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 601 | TEST_P(AudioPolicyManagerTestMsd, PatchCreationOnSetForceUse) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 602 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 603 | mManager->setForceUse(AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND, |
| 604 | AUDIO_POLICY_FORCE_ENCODED_SURROUND_ALWAYS); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 605 | ASSERT_EQ(mExpectedAudioPatchCount, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 606 | } |
| 607 | |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 608 | TEST_P(AudioPolicyManagerTestMsd, PatchCreationSetReleaseMsdOutputPatches) { |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 609 | const PatchCountCheck patchCount = snapshotPatchCount(); |
| 610 | DeviceVector devices = mManager->getAvailableOutputDevices(); |
| 611 | // Remove MSD output device to avoid patching to itself |
| 612 | devices.remove(mMsdOutputDevice); |
| 613 | ASSERT_EQ(mExpectedAudioPatchCount, devices.size()); |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 614 | mManager->setMsdOutputPatches(&devices); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 615 | ASSERT_EQ(mExpectedAudioPatchCount, patchCount.deltaFromSnapshot()); |
| 616 | // Dual patch: exercise creating one new audio patch and reusing another existing audio patch. |
| 617 | DeviceVector singleDevice(devices[0]); |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 618 | mManager->releaseMsdOutputPatches(singleDevice); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 619 | ASSERT_EQ(mExpectedAudioPatchCount - 1, patchCount.deltaFromSnapshot()); |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 620 | mManager->setMsdOutputPatches(&devices); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 621 | ASSERT_EQ(mExpectedAudioPatchCount, patchCount.deltaFromSnapshot()); |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 622 | mManager->releaseMsdOutputPatches(devices); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 623 | ASSERT_EQ(0, patchCount.deltaFromSnapshot()); |
| 624 | } |
| 625 | |
| 626 | TEST_P(AudioPolicyManagerTestMsd, GetOutputForAttrEncodedRoutesToMsd) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 627 | const PatchCountCheck patchCount = snapshotPatchCount(); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 628 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 629 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, |
| 630 | k48000SamplingRate, AUDIO_OUTPUT_FLAG_DIRECT); |
Eric Laurent | 74c38dc | 2020-12-23 18:19:44 +0100 | [diff] [blame] | 631 | ASSERT_EQ(selectedDeviceId, mDefaultOutputDevice->getId()); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 632 | ASSERT_EQ(mExpectedAudioPatchCount, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 633 | } |
| 634 | |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 635 | TEST_P(AudioPolicyManagerTestMsd, GetOutputForAttrPcmRoutesToMsd) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 636 | const PatchCountCheck patchCount = snapshotPatchCount(); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 637 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 638 | getOutputForAttr(&selectedDeviceId, |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 639 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, k48000SamplingRate); |
Eric Laurent | 74c38dc | 2020-12-23 18:19:44 +0100 | [diff] [blame] | 640 | ASSERT_EQ(selectedDeviceId, mDefaultOutputDevice->getId()); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 641 | ASSERT_EQ(mExpectedAudioPatchCount, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 642 | } |
| 643 | |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 644 | TEST_P(AudioPolicyManagerTestMsd, GetOutputForAttrEncodedPlusPcmRoutesToMsd) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 645 | const PatchCountCheck patchCount = snapshotPatchCount(); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 646 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 647 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, |
| 648 | k48000SamplingRate, AUDIO_OUTPUT_FLAG_DIRECT); |
Eric Laurent | 74c38dc | 2020-12-23 18:19:44 +0100 | [diff] [blame] | 649 | ASSERT_EQ(selectedDeviceId, mDefaultOutputDevice->getId()); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 650 | ASSERT_EQ(mExpectedAudioPatchCount, patchCount.deltaFromSnapshot()); |
| 651 | selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 652 | getOutputForAttr(&selectedDeviceId, |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 653 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, k48000SamplingRate); |
Eric Laurent | 74c38dc | 2020-12-23 18:19:44 +0100 | [diff] [blame] | 654 | ASSERT_EQ(selectedDeviceId, mDefaultOutputDevice->getId()); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 655 | ASSERT_EQ(mExpectedAudioPatchCount, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 656 | } |
| 657 | |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 658 | TEST_P(AudioPolicyManagerTestMsd, GetOutputForAttrUnsupportedFormatBypassesMsd) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 659 | const PatchCountCheck patchCount = snapshotPatchCount(); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 660 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 661 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_DTS, AUDIO_CHANNEL_OUT_5POINT1, |
| 662 | k48000SamplingRate, AUDIO_OUTPUT_FLAG_DIRECT); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 663 | ASSERT_NE(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 664 | ASSERT_EQ(0, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 665 | } |
| 666 | |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 667 | TEST_P(AudioPolicyManagerTestMsd, GetOutputForAttrFormatSwitching) { |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 668 | // Switch between formats that are supported and not supported by MSD. |
| 669 | { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 670 | const PatchCountCheck patchCount = snapshotPatchCount(); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 671 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 672 | audio_port_handle_t portId; |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 673 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, |
| 674 | k48000SamplingRate, AUDIO_OUTPUT_FLAG_DIRECT, nullptr /*output*/, &portId); |
Eric Laurent | 74c38dc | 2020-12-23 18:19:44 +0100 | [diff] [blame] | 675 | ASSERT_EQ(selectedDeviceId, mDefaultOutputDevice->getId()); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 676 | ASSERT_EQ(mExpectedAudioPatchCount, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 677 | mManager->releaseOutput(portId); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 678 | ASSERT_EQ(mExpectedAudioPatchCount, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 679 | } |
| 680 | { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 681 | const PatchCountCheck patchCount = snapshotPatchCount(); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 682 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 683 | audio_port_handle_t portId; |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 684 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_DTS, AUDIO_CHANNEL_OUT_5POINT1, |
| 685 | k48000SamplingRate, AUDIO_OUTPUT_FLAG_DIRECT, nullptr /*output*/, &portId); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 686 | ASSERT_NE(selectedDeviceId, mMsdOutputDevice->getId()); |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 687 | ASSERT_EQ(-static_cast<int>(mExpectedAudioPatchCount), patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 688 | mManager->releaseOutput(portId); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 689 | ASSERT_EQ(0, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 690 | } |
| 691 | { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 692 | const PatchCountCheck patchCount = snapshotPatchCount(); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 693 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 694 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, |
| 695 | k48000SamplingRate, AUDIO_OUTPUT_FLAG_DIRECT); |
Eric Laurent | 74c38dc | 2020-12-23 18:19:44 +0100 | [diff] [blame] | 696 | ASSERT_EQ(selectedDeviceId, mDefaultOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 697 | ASSERT_EQ(0, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 698 | } |
| 699 | } |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 700 | |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 701 | TEST_P(AudioPolicyManagerTestMsd, PatchCreationFromHdmiInToMsd) { |
| 702 | audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE; |
| 703 | uid_t uid = 42; |
| 704 | const PatchCountCheck patchCount = snapshotPatchCount(); |
| 705 | ASSERT_FALSE(mManager->getAvailableInputDevices().isEmpty()); |
| 706 | PatchBuilder patchBuilder; |
| 707 | patchBuilder. |
| 708 | addSource(mManager->getAvailableInputDevices(). |
| 709 | getDevice(AUDIO_DEVICE_IN_HDMI, String8(""), AUDIO_FORMAT_DEFAULT)). |
| 710 | addSink(mManager->getAvailableOutputDevices(). |
| 711 | getDevice(AUDIO_DEVICE_OUT_BUS, String8(""), AUDIO_FORMAT_DEFAULT)); |
| 712 | ASSERT_EQ(NO_ERROR, mManager->createAudioPatch(patchBuilder.patch(), &handle, uid)); |
| 713 | ASSERT_NE(AUDIO_PATCH_HANDLE_NONE, handle); |
| 714 | AudioPatchCollection patches = mManager->getAudioPatches(); |
| 715 | sp<AudioPatch> patch = patches.valueFor(handle); |
| 716 | ASSERT_EQ(1, patch->mPatch.num_sources); |
| 717 | ASSERT_EQ(1, patch->mPatch.num_sinks); |
| 718 | ASSERT_EQ(AUDIO_PORT_ROLE_SOURCE, patch->mPatch.sources[0].role); |
| 719 | ASSERT_EQ(AUDIO_PORT_ROLE_SINK, patch->mPatch.sinks[0].role); |
| 720 | ASSERT_EQ(AUDIO_FORMAT_IEC60958, patch->mPatch.sources[0].format); |
| 721 | ASSERT_EQ(AUDIO_FORMAT_IEC60958, patch->mPatch.sinks[0].format); |
Dean Wheatley | 16809da | 2022-12-09 14:55:46 +1100 | [diff] [blame] | 722 | ASSERT_EQ(AUDIO_CHANNEL_INDEX_MASK_24, patch->mPatch.sources[0].channel_mask); |
| 723 | ASSERT_EQ(AUDIO_CHANNEL_INDEX_MASK_24, patch->mPatch.sinks[0].channel_mask); |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 724 | ASSERT_EQ(k48000SamplingRate, patch->mPatch.sources[0].sample_rate); |
| 725 | ASSERT_EQ(k48000SamplingRate, patch->mPatch.sinks[0].sample_rate); |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 726 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
| 727 | } |
| 728 | |
Dorin Drimus | 94d9441 | 2022-02-02 09:05:02 +0100 | [diff] [blame] | 729 | TEST_P(AudioPolicyManagerTestMsd, GetDirectProfilesForAttributesWithMsd) { |
| 730 | const audio_attributes_t attr = { |
| 731 | AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 732 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}; |
| 733 | |
| 734 | // count expected direct profiles for the default device |
| 735 | int countDirectProfilesPrimary = 0; |
| 736 | const auto& primary = mManager->getConfig().getHwModules() |
| 737 | .getModuleFromName(AUDIO_HARDWARE_MODULE_ID_PRIMARY); |
Mikhail Naganov | 68e3f64 | 2023-04-28 13:06:32 -0700 | [diff] [blame] | 738 | for (const auto& outputProfile : primary->getOutputProfiles()) { |
Dorin Drimus | 94d9441 | 2022-02-02 09:05:02 +0100 | [diff] [blame] | 739 | if (outputProfile->asAudioPort()->isDirectOutput()) { |
| 740 | countDirectProfilesPrimary += outputProfile->asAudioPort()->getAudioProfiles().size(); |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | // count expected direct profiles for the msd device |
| 745 | int countDirectProfilesMsd = 0; |
| 746 | const auto& msd = mManager->getConfig().getHwModules() |
| 747 | .getModuleFromName(AUDIO_HARDWARE_MODULE_ID_MSD); |
Mikhail Naganov | 68e3f64 | 2023-04-28 13:06:32 -0700 | [diff] [blame] | 748 | for (const auto& outputProfile : msd->getOutputProfiles()) { |
Dorin Drimus | 94d9441 | 2022-02-02 09:05:02 +0100 | [diff] [blame] | 749 | if (outputProfile->asAudioPort()->isDirectOutput()) { |
| 750 | countDirectProfilesMsd += outputProfile->asAudioPort()->getAudioProfiles().size(); |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | // before setting up MSD audio patches we only have the primary hal direct profiles |
| 755 | ASSERT_EQ(countDirectProfilesPrimary, getDirectProfilesForAttributes(attr).size()); |
| 756 | |
| 757 | DeviceVector outputDevices = mManager->getAvailableOutputDevices(); |
| 758 | // Remove MSD output device to avoid patching to itself |
| 759 | outputDevices.remove(mMsdOutputDevice); |
| 760 | mManager->setMsdOutputPatches(&outputDevices); |
| 761 | |
| 762 | // after setting up MSD audio patches the MSD direct profiles are added |
| 763 | ASSERT_EQ(countDirectProfilesPrimary + countDirectProfilesMsd, |
| 764 | getDirectProfilesForAttributes(attr).size()); |
| 765 | |
| 766 | mManager->releaseMsdOutputPatches(outputDevices); |
| 767 | // releasing the MSD audio patches gets us back to the primary hal direct profiles only |
| 768 | ASSERT_EQ(countDirectProfilesPrimary, getDirectProfilesForAttributes(attr).size()); |
| 769 | } |
| 770 | |
Dorin Drimus | ecc9f42 | 2022-03-09 17:57:40 +0100 | [diff] [blame] | 771 | TEST_P(AudioPolicyManagerTestMsd, IsDirectPlaybackSupportedWithMsd) { |
| 772 | const audio_attributes_t attr = { |
| 773 | AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 774 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}; |
| 775 | |
| 776 | audio_config_base_t directConfig = AUDIO_CONFIG_BASE_INITIALIZER; |
| 777 | directConfig.format = AUDIO_FORMAT_DTS; |
| 778 | directConfig.sample_rate = 48000; |
| 779 | directConfig.channel_mask = AUDIO_CHANNEL_OUT_5POINT1; |
| 780 | |
| 781 | audio_config_base_t nonDirectConfig = AUDIO_CONFIG_BASE_INITIALIZER; |
| 782 | nonDirectConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 783 | nonDirectConfig.sample_rate = 48000; |
| 784 | nonDirectConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 785 | |
| 786 | audio_config_base_t nonExistentConfig = AUDIO_CONFIG_BASE_INITIALIZER; |
| 787 | nonExistentConfig.format = AUDIO_FORMAT_E_AC3; |
| 788 | nonExistentConfig.sample_rate = 48000; |
| 789 | nonExistentConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 790 | |
| 791 | audio_config_base_t msdDirectConfig1 = AUDIO_CONFIG_BASE_INITIALIZER; |
| 792 | msdDirectConfig1.format = AUDIO_FORMAT_AC3; |
| 793 | msdDirectConfig1.sample_rate = 48000; |
| 794 | msdDirectConfig1.channel_mask = AUDIO_CHANNEL_OUT_5POINT1; |
| 795 | |
| 796 | audio_config_base_t msdDirectConfig2 = AUDIO_CONFIG_BASE_INITIALIZER; |
| 797 | msdDirectConfig2.format = AUDIO_FORMAT_IEC60958; |
| 798 | msdDirectConfig2.sample_rate = 48000; |
Dean Wheatley | 16809da | 2022-12-09 14:55:46 +1100 | [diff] [blame] | 799 | msdDirectConfig2.channel_mask = AUDIO_CHANNEL_INDEX_MASK_24; |
Dorin Drimus | ecc9f42 | 2022-03-09 17:57:40 +0100 | [diff] [blame] | 800 | |
| 801 | audio_config_base_t msdNonDirectConfig = AUDIO_CONFIG_BASE_INITIALIZER; |
| 802 | msdNonDirectConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 803 | msdNonDirectConfig.sample_rate = 96000; |
| 804 | msdNonDirectConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 805 | |
| 806 | ASSERT_TRUE(mManager->isDirectOutputSupported(directConfig, attr)); |
| 807 | ASSERT_FALSE(mManager->isDirectOutputSupported(nonDirectConfig, attr)); |
| 808 | ASSERT_FALSE(mManager->isDirectOutputSupported(nonExistentConfig, attr)); |
| 809 | // before setting MSD patches the direct MSD configs return false |
| 810 | ASSERT_FALSE(mManager->isDirectOutputSupported(msdDirectConfig1, attr)); |
| 811 | ASSERT_FALSE(mManager->isDirectOutputSupported(msdDirectConfig2, attr)); |
| 812 | ASSERT_FALSE(mManager->isDirectOutputSupported(msdNonDirectConfig, attr)); |
| 813 | |
| 814 | DeviceVector outputDevices = mManager->getAvailableOutputDevices(); |
| 815 | // Remove MSD output device to avoid patching to itself |
| 816 | outputDevices.remove(mMsdOutputDevice); |
| 817 | mManager->setMsdOutputPatches(&outputDevices); |
| 818 | |
| 819 | ASSERT_TRUE(mManager->isDirectOutputSupported(directConfig, attr)); |
| 820 | ASSERT_FALSE(mManager->isDirectOutputSupported(nonDirectConfig, attr)); |
| 821 | ASSERT_FALSE(mManager->isDirectOutputSupported(nonExistentConfig, attr)); |
| 822 | // after setting MSD patches the direct MSD configs return true |
| 823 | ASSERT_TRUE(mManager->isDirectOutputSupported(msdDirectConfig1, attr)); |
| 824 | ASSERT_TRUE(mManager->isDirectOutputSupported(msdDirectConfig2, attr)); |
| 825 | ASSERT_FALSE(mManager->isDirectOutputSupported(msdNonDirectConfig, attr)); |
| 826 | |
| 827 | mManager->releaseMsdOutputPatches(outputDevices); |
| 828 | |
| 829 | ASSERT_TRUE(mManager->isDirectOutputSupported(directConfig, attr)); |
| 830 | ASSERT_FALSE(mManager->isDirectOutputSupported(nonDirectConfig, attr)); |
| 831 | ASSERT_FALSE(mManager->isDirectOutputSupported(nonExistentConfig, attr)); |
| 832 | // AFTER releasing MSD patches the direct MSD configs return false |
| 833 | ASSERT_FALSE(mManager->isDirectOutputSupported(msdDirectConfig1, attr)); |
| 834 | ASSERT_FALSE(mManager->isDirectOutputSupported(msdDirectConfig2, attr)); |
| 835 | ASSERT_FALSE(mManager->isDirectOutputSupported(msdNonDirectConfig, attr)); |
| 836 | } |
| 837 | |
Dorin Drimus | fae3c64 | 2022-03-17 18:36:30 +0100 | [diff] [blame] | 838 | TEST_P(AudioPolicyManagerTestMsd, GetDirectPlaybackSupportWithMsd) { |
| 839 | const audio_attributes_t attr = { |
| 840 | AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 841 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}; |
| 842 | |
| 843 | audio_config_t directConfig = AUDIO_CONFIG_INITIALIZER; |
| 844 | directConfig.format = AUDIO_FORMAT_DTS; |
| 845 | directConfig.sample_rate = 48000; |
| 846 | directConfig.channel_mask = AUDIO_CHANNEL_OUT_5POINT1; |
| 847 | |
| 848 | audio_config_t nonDirectConfig = AUDIO_CONFIG_INITIALIZER; |
| 849 | nonDirectConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 850 | nonDirectConfig.sample_rate = 48000; |
| 851 | nonDirectConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 852 | |
| 853 | audio_config_t nonExistentConfig = AUDIO_CONFIG_INITIALIZER; |
| 854 | nonExistentConfig.format = AUDIO_FORMAT_E_AC3; |
| 855 | nonExistentConfig.sample_rate = 48000; |
| 856 | nonExistentConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 857 | |
| 858 | audio_config_t msdDirectConfig1 = AUDIO_CONFIG_INITIALIZER; |
| 859 | msdDirectConfig1.format = AUDIO_FORMAT_AC3; |
| 860 | msdDirectConfig1.sample_rate = 48000; |
| 861 | msdDirectConfig1.channel_mask = AUDIO_CHANNEL_OUT_5POINT1; |
| 862 | |
| 863 | audio_config_t msdDirectConfig2 = AUDIO_CONFIG_INITIALIZER; |
| 864 | msdDirectConfig2.format = AUDIO_FORMAT_IEC60958; |
| 865 | msdDirectConfig2.sample_rate = 48000; |
Dean Wheatley | 16809da | 2022-12-09 14:55:46 +1100 | [diff] [blame] | 866 | msdDirectConfig2.channel_mask = AUDIO_CHANNEL_INDEX_MASK_24; |
Dorin Drimus | fae3c64 | 2022-03-17 18:36:30 +0100 | [diff] [blame] | 867 | |
| 868 | audio_config_t msdNonDirectConfig = AUDIO_CONFIG_INITIALIZER; |
| 869 | msdNonDirectConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 870 | msdNonDirectConfig.sample_rate = 96000; |
| 871 | msdNonDirectConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 872 | |
| 873 | ASSERT_EQ(AUDIO_DIRECT_BITSTREAM_SUPPORTED, |
| 874 | mManager->getDirectPlaybackSupport(&attr, &directConfig)); |
| 875 | ASSERT_EQ(AUDIO_DIRECT_NOT_SUPPORTED, |
| 876 | mManager->getDirectPlaybackSupport(&attr, &nonDirectConfig)); |
| 877 | ASSERT_EQ(AUDIO_DIRECT_NOT_SUPPORTED, |
| 878 | mManager->getDirectPlaybackSupport(&attr, &nonExistentConfig)); |
| 879 | // before setting MSD patches the direct MSD configs return AUDIO_DIRECT_NOT_SUPPORTED |
| 880 | ASSERT_EQ(AUDIO_DIRECT_NOT_SUPPORTED, |
| 881 | mManager->getDirectPlaybackSupport(&attr, &msdDirectConfig1)); |
| 882 | ASSERT_EQ(AUDIO_DIRECT_NOT_SUPPORTED, |
| 883 | mManager->getDirectPlaybackSupport(&attr, &msdDirectConfig2)); |
| 884 | ASSERT_EQ(AUDIO_DIRECT_NOT_SUPPORTED, |
| 885 | mManager->getDirectPlaybackSupport(&attr, &msdNonDirectConfig)); |
| 886 | |
| 887 | DeviceVector outputDevices = mManager->getAvailableOutputDevices(); |
| 888 | // Remove MSD output device to avoid patching to itself |
| 889 | outputDevices.remove(mMsdOutputDevice); |
| 890 | mManager->setMsdOutputPatches(&outputDevices); |
| 891 | |
| 892 | ASSERT_EQ(AUDIO_DIRECT_BITSTREAM_SUPPORTED, |
| 893 | mManager->getDirectPlaybackSupport(&attr, &directConfig)); |
| 894 | ASSERT_EQ(AUDIO_DIRECT_NOT_SUPPORTED, |
| 895 | mManager->getDirectPlaybackSupport(&attr, &nonDirectConfig)); |
| 896 | ASSERT_EQ(AUDIO_DIRECT_NOT_SUPPORTED, |
| 897 | mManager->getDirectPlaybackSupport(&attr, &nonExistentConfig)); |
| 898 | // after setting MSD patches the direct MSD configs return values according to their flags |
| 899 | ASSERT_EQ(AUDIO_DIRECT_OFFLOAD_SUPPORTED, |
| 900 | mManager->getDirectPlaybackSupport(&attr, &msdDirectConfig1)); |
| 901 | ASSERT_EQ(AUDIO_DIRECT_BITSTREAM_SUPPORTED, |
| 902 | mManager->getDirectPlaybackSupport(&attr, &msdDirectConfig2)); |
| 903 | ASSERT_EQ(AUDIO_DIRECT_NOT_SUPPORTED, |
| 904 | mManager->getDirectPlaybackSupport(&attr, &msdNonDirectConfig)); |
| 905 | |
| 906 | mManager->releaseMsdOutputPatches(outputDevices); |
| 907 | |
| 908 | ASSERT_EQ(AUDIO_DIRECT_BITSTREAM_SUPPORTED, |
| 909 | mManager->getDirectPlaybackSupport(&attr, &directConfig)); |
| 910 | ASSERT_EQ(AUDIO_DIRECT_NOT_SUPPORTED, |
| 911 | mManager->getDirectPlaybackSupport(&attr, &nonDirectConfig)); |
| 912 | ASSERT_EQ(AUDIO_DIRECT_NOT_SUPPORTED, |
| 913 | mManager->getDirectPlaybackSupport(&attr, &nonExistentConfig)); |
| 914 | // after releasing MSD patches the direct MSD configs return AUDIO_DIRECT_NOT_SUPPORTED |
| 915 | ASSERT_EQ(AUDIO_DIRECT_NOT_SUPPORTED, |
| 916 | mManager->getDirectPlaybackSupport(&attr, &msdDirectConfig1)); |
| 917 | ASSERT_EQ(AUDIO_DIRECT_NOT_SUPPORTED, |
| 918 | mManager->getDirectPlaybackSupport(&attr, &msdDirectConfig2)); |
| 919 | ASSERT_EQ(AUDIO_DIRECT_NOT_SUPPORTED, |
| 920 | mManager->getDirectPlaybackSupport(&attr, &msdNonDirectConfig)); |
| 921 | } |
| 922 | |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 923 | class AudioPolicyManagerTestWithConfigurationFile : public AudioPolicyManagerTest { |
| 924 | protected: |
| 925 | void SetUpManagerConfig() override; |
| 926 | virtual std::string getConfigFile() { return sDefaultConfig; } |
| 927 | |
| 928 | static const std::string sExecutableDir; |
| 929 | static const std::string sDefaultConfig; |
| 930 | }; |
| 931 | |
| 932 | const std::string AudioPolicyManagerTestWithConfigurationFile::sExecutableDir = |
| 933 | base::GetExecutableDirectory() + "/"; |
| 934 | |
| 935 | const std::string AudioPolicyManagerTestWithConfigurationFile::sDefaultConfig = |
| 936 | sExecutableDir + "test_audio_policy_configuration.xml"; |
| 937 | |
| 938 | void AudioPolicyManagerTestWithConfigurationFile::SetUpManagerConfig() { |
Mikhail Naganov | 68e3f64 | 2023-04-28 13:06:32 -0700 | [diff] [blame] | 939 | auto result = AudioPolicyConfig::loadFromCustomXmlConfigForTests(getConfigFile()); |
| 940 | ASSERT_TRUE(result.ok()); |
| 941 | mConfig = result.value(); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | TEST_F(AudioPolicyManagerTestWithConfigurationFile, InitSuccess) { |
| 945 | // SetUp must finish with no assertions. |
| 946 | } |
| 947 | |
| 948 | TEST_F(AudioPolicyManagerTestWithConfigurationFile, Dump) { |
| 949 | dumpToLog(); |
| 950 | } |
| 951 | |
Mikhail Naganov | 0805de1 | 2022-02-15 23:00:07 +0000 | [diff] [blame] | 952 | TEST_F(AudioPolicyManagerTestWithConfigurationFile, ListAudioPortsHasFlags) { |
| 953 | // Create an input for VOIP TX because it's not opened automatically like outputs are. |
| 954 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 955 | audio_port_handle_t mixPortId = AUDIO_PORT_HANDLE_NONE; |
| 956 | audio_source_t source = AUDIO_SOURCE_VOICE_COMMUNICATION; |
François Gaffie | 6ebbce0 | 2023-07-19 13:27:53 +0200 | [diff] [blame] | 957 | audio_attributes_t attr = {AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, source, |
| 958 | AUDIO_FLAG_NONE, ""}; |
| 959 | audio_io_handle_t input = AUDIO_PORT_HANDLE_NONE; |
| 960 | ASSERT_NO_FATAL_FAILURE(getInputForAttr(attr, &input, AUDIO_SESSION_NONE, 1, |
| 961 | &selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, |
| 962 | AUDIO_CHANNEL_IN_MONO, 8000, AUDIO_INPUT_FLAG_VOIP_TX, |
| 963 | &mixPortId)); |
Mikhail Naganov | 0805de1 | 2022-02-15 23:00:07 +0000 | [diff] [blame] | 964 | |
| 965 | std::vector<audio_port_v7> ports; |
| 966 | ASSERT_NO_FATAL_FAILURE( |
| 967 | getAudioPorts(AUDIO_PORT_TYPE_MIX, AUDIO_PORT_ROLE_NONE, &ports)); |
| 968 | EXPECT_NE(0, ports.size()); |
| 969 | bool hasFlags = false, foundPrimary = false, foundVoipRx = false, foundVoipTx = false; |
| 970 | for (const auto& port : ports) { |
| 971 | if ((port.active_config.config_mask & AUDIO_PORT_CONFIG_FLAGS) != 0) { |
| 972 | hasFlags = true; |
| 973 | if (port.role == AUDIO_PORT_ROLE_SOURCE) { |
| 974 | if ((port.active_config.flags.output & AUDIO_OUTPUT_FLAG_PRIMARY) != 0) { |
| 975 | foundPrimary = true; |
| 976 | } |
| 977 | if ((port.active_config.flags.output & AUDIO_OUTPUT_FLAG_VOIP_RX) != 0) { |
| 978 | foundVoipRx = true; |
| 979 | } |
| 980 | } else if (port.role == AUDIO_PORT_ROLE_SINK) { |
| 981 | if ((port.active_config.flags.input & AUDIO_INPUT_FLAG_VOIP_TX) != 0) { |
| 982 | foundVoipTx = true; |
| 983 | } |
| 984 | } |
| 985 | } |
| 986 | } |
| 987 | EXPECT_TRUE(hasFlags); |
| 988 | EXPECT_TRUE(foundPrimary); |
| 989 | EXPECT_TRUE(foundVoipRx); |
| 990 | EXPECT_TRUE(foundVoipTx); |
| 991 | } |
| 992 | |
Ram Mohan M | 594558d | 2022-06-14 14:42:44 +0530 | [diff] [blame] | 993 | TEST_F(AudioPolicyManagerTestWithConfigurationFile, HandleDeviceConfigChange) { |
| 994 | { |
| 995 | const auto prevCounter = mClient->getRoutingUpdatedCounter(); |
| 996 | |
| 997 | EXPECT_EQ(NO_ERROR, mManager->setDeviceConnectionState(AUDIO_DEVICE_OUT_BLUETOOTH_A2DP, |
| 998 | AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 999 | "", "", AUDIO_FORMAT_LDAC)); |
| 1000 | const auto currCounter = mClient->getRoutingUpdatedCounter(); |
| 1001 | EXPECT_GT(currCounter, prevCounter); |
| 1002 | } |
| 1003 | { |
| 1004 | const auto prevCounter = mClient->getRoutingUpdatedCounter(); |
| 1005 | // Update device configuration |
| 1006 | EXPECT_EQ(NO_ERROR, mManager->handleDeviceConfigChange(AUDIO_DEVICE_OUT_BLUETOOTH_A2DP, |
| 1007 | "" /*address*/, "" /*name*/, |
| 1008 | AUDIO_FORMAT_AAC)); |
| 1009 | |
| 1010 | // As mClient marks isReconfigA2dpSupported to false, device state needs to be toggled for |
| 1011 | // config changes to take effect |
| 1012 | const auto currCounter = mClient->getRoutingUpdatedCounter(); |
| 1013 | EXPECT_GT(currCounter, prevCounter); |
| 1014 | } |
| 1015 | } |
| 1016 | |
jiabin | a84c3d3 | 2022-12-02 18:59:55 +0000 | [diff] [blame] | 1017 | TEST_F(AudioPolicyManagerTestWithConfigurationFile, PreferredMixerAttributes) { |
| 1018 | mClient->addSupportedFormat(AUDIO_FORMAT_PCM_16_BIT); |
| 1019 | mClient->addSupportedChannelMask(AUDIO_CHANNEL_OUT_STEREO); |
| 1020 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState(AUDIO_DEVICE_OUT_USB_DEVICE, |
| 1021 | AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 1022 | "", "", AUDIO_FORMAT_DEFAULT)); |
| 1023 | auto devices = mManager->getAvailableOutputDevices(); |
| 1024 | audio_port_handle_t maxPortId = 0; |
| 1025 | audio_port_handle_t speakerPortId; |
| 1026 | audio_port_handle_t usbPortId; |
| 1027 | for (auto device : devices) { |
| 1028 | maxPortId = std::max(maxPortId, device->getId()); |
| 1029 | if (device->type() == AUDIO_DEVICE_OUT_SPEAKER) { |
| 1030 | speakerPortId = device->getId(); |
| 1031 | } else if (device->type() == AUDIO_DEVICE_OUT_USB_DEVICE) { |
| 1032 | usbPortId = device->getId(); |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | const uid_t uid = 1234; |
| 1037 | const uid_t otherUid = 4321; |
| 1038 | const audio_attributes_t mediaAttr = { |
| 1039 | .content_type = AUDIO_CONTENT_TYPE_MUSIC, |
| 1040 | .usage = AUDIO_USAGE_MEDIA, |
| 1041 | }; |
| 1042 | const audio_attributes_t alarmAttr = { |
| 1043 | .content_type = AUDIO_CONTENT_TYPE_SONIFICATION, |
| 1044 | .usage = AUDIO_USAGE_ALARM, |
| 1045 | }; |
| 1046 | |
| 1047 | std::vector<audio_mixer_attributes_t> mixerAttributes; |
| 1048 | EXPECT_EQ(NO_ERROR, mManager->getSupportedMixerAttributes(usbPortId, mixerAttributes)); |
| 1049 | for (const auto attrToSet : mixerAttributes) { |
| 1050 | audio_mixer_attributes_t attrFromQuery = AUDIO_MIXER_ATTRIBUTES_INITIALIZER; |
| 1051 | |
| 1052 | // The given device is not available |
| 1053 | EXPECT_EQ(BAD_VALUE, |
| 1054 | mManager->setPreferredMixerAttributes( |
| 1055 | &mediaAttr, maxPortId + 1, uid, &attrToSet)); |
| 1056 | // The only allowed device is USB |
| 1057 | EXPECT_EQ(BAD_VALUE, |
| 1058 | mManager->setPreferredMixerAttributes( |
| 1059 | &mediaAttr, speakerPortId, uid, &attrToSet)); |
| 1060 | // The only allowed usage is media |
| 1061 | EXPECT_EQ(BAD_VALUE, |
| 1062 | mManager->setPreferredMixerAttributes(&alarmAttr, usbPortId, uid, &attrToSet)); |
| 1063 | // Nothing set yet, must get null when query |
| 1064 | EXPECT_EQ(NAME_NOT_FOUND, |
| 1065 | mManager->getPreferredMixerAttributes(&mediaAttr, usbPortId, &attrFromQuery)); |
| 1066 | EXPECT_EQ(NO_ERROR, |
| 1067 | mManager->setPreferredMixerAttributes( |
| 1068 | &mediaAttr, usbPortId, uid, &attrToSet)); |
| 1069 | EXPECT_EQ(NO_ERROR, |
| 1070 | mManager->getPreferredMixerAttributes(&mediaAttr, usbPortId, &attrFromQuery)); |
| 1071 | EXPECT_EQ(attrToSet.config.format, attrFromQuery.config.format); |
| 1072 | EXPECT_EQ(attrToSet.config.sample_rate, attrFromQuery.config.sample_rate); |
| 1073 | EXPECT_EQ(attrToSet.config.channel_mask, attrFromQuery.config.channel_mask); |
| 1074 | EXPECT_EQ(attrToSet.mixer_behavior, attrFromQuery.mixer_behavior); |
| 1075 | EXPECT_EQ(NAME_NOT_FOUND, |
| 1076 | mManager->clearPreferredMixerAttributes(&mediaAttr, speakerPortId, uid)); |
| 1077 | EXPECT_EQ(PERMISSION_DENIED, |
| 1078 | mManager->clearPreferredMixerAttributes(&mediaAttr, usbPortId, otherUid)); |
| 1079 | EXPECT_EQ(NO_ERROR, |
| 1080 | mManager->clearPreferredMixerAttributes(&mediaAttr, usbPortId, uid)); |
| 1081 | } |
| 1082 | |
| 1083 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState(AUDIO_DEVICE_OUT_USB_DEVICE, |
| 1084 | AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 1085 | "", "", AUDIO_FORMAT_LDAC)); |
| 1086 | } |
| 1087 | |
jiabin | 3ff8d7d | 2022-12-13 06:27:44 +0000 | [diff] [blame] | 1088 | TEST_F(AudioPolicyManagerTestWithConfigurationFile, RoutingChangedWithPreferredMixerAttributes) { |
| 1089 | mClient->addSupportedFormat(AUDIO_FORMAT_PCM_16_BIT); |
| 1090 | mClient->addSupportedChannelMask(AUDIO_CHANNEL_OUT_STEREO); |
| 1091 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState(AUDIO_DEVICE_OUT_USB_DEVICE, |
| 1092 | AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 1093 | "", "", AUDIO_FORMAT_DEFAULT)); |
| 1094 | auto devices = mManager->getAvailableOutputDevices(); |
| 1095 | audio_port_handle_t usbPortId = AUDIO_PORT_HANDLE_NONE; |
| 1096 | for (auto device : devices) { |
| 1097 | if (device->type() == AUDIO_DEVICE_OUT_USB_DEVICE) { |
| 1098 | usbPortId = device->getId(); |
| 1099 | break; |
| 1100 | } |
| 1101 | } |
| 1102 | EXPECT_NE(AUDIO_PORT_HANDLE_NONE, usbPortId); |
| 1103 | |
| 1104 | const uid_t uid = 1234; |
| 1105 | const audio_attributes_t mediaAttr = { |
| 1106 | .content_type = AUDIO_CONTENT_TYPE_MUSIC, |
| 1107 | .usage = AUDIO_USAGE_MEDIA, |
| 1108 | }; |
| 1109 | |
| 1110 | std::vector<audio_mixer_attributes_t> mixerAttributes; |
| 1111 | EXPECT_EQ(NO_ERROR, mManager->getSupportedMixerAttributes(usbPortId, mixerAttributes)); |
| 1112 | EXPECT_GT(mixerAttributes.size(), 0); |
| 1113 | EXPECT_EQ(NO_ERROR, |
| 1114 | mManager->setPreferredMixerAttributes( |
| 1115 | &mediaAttr, usbPortId, uid, &mixerAttributes[0])); |
| 1116 | |
| 1117 | audio_io_handle_t output = AUDIO_IO_HANDLE_NONE; |
| 1118 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 1119 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE; |
| 1120 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
| 1121 | 48000, AUDIO_OUTPUT_FLAG_NONE, &output, &portId, mediaAttr, |
| 1122 | AUDIO_SESSION_NONE, uid); |
| 1123 | status_t status = mManager->startOutput(portId); |
| 1124 | if (status == DEAD_OBJECT) { |
| 1125 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
| 1126 | 48000, AUDIO_OUTPUT_FLAG_NONE, &output, &portId, mediaAttr, |
| 1127 | AUDIO_SESSION_NONE, uid); |
| 1128 | status = mManager->startOutput(portId); |
| 1129 | } |
| 1130 | EXPECT_EQ(NO_ERROR, status); |
| 1131 | EXPECT_NE(AUDIO_IO_HANDLE_NONE, output); |
| 1132 | EXPECT_NE(nullptr, mManager->getOutputs().valueFor(output)); |
| 1133 | EXPECT_EQ(NO_ERROR, mManager->setDeviceConnectionState(AUDIO_DEVICE_OUT_BLUETOOTH_A2DP, |
| 1134 | AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 1135 | "", "", AUDIO_FORMAT_LDAC)); |
| 1136 | // When BT device is connected, it will be selected as media device and trigger routing changed. |
| 1137 | // When this happens, existing output that is opened with preferred mixer attributes will be |
| 1138 | // closed and reopened with default config. |
| 1139 | EXPECT_EQ(nullptr, mManager->getOutputs().valueFor(output)); |
| 1140 | |
| 1141 | EXPECT_EQ(NO_ERROR, |
| 1142 | mManager->clearPreferredMixerAttributes(&mediaAttr, usbPortId, uid)); |
| 1143 | |
| 1144 | EXPECT_EQ(NO_ERROR, mManager->setDeviceConnectionState(AUDIO_DEVICE_OUT_BLUETOOTH_A2DP, |
| 1145 | AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 1146 | "", "", AUDIO_FORMAT_LDAC)); |
| 1147 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState(AUDIO_DEVICE_OUT_USB_DEVICE, |
| 1148 | AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 1149 | "", "", AUDIO_FORMAT_LDAC)); |
| 1150 | } |
| 1151 | |
jiabin | 5eaf096 | 2022-12-20 20:11:38 +0000 | [diff] [blame] | 1152 | TEST_F(AudioPolicyManagerTestWithConfigurationFile, BitPerfectPlayback) { |
| 1153 | const audio_format_t bitPerfectFormat = AUDIO_FORMAT_PCM_16_BIT; |
| 1154 | const audio_channel_mask_t bitPerfectChannelMask = AUDIO_CHANNEL_OUT_QUAD; |
| 1155 | const uint32_t bitPerfectSampleRate = 48000; |
| 1156 | mClient->addSupportedFormat(bitPerfectFormat); |
| 1157 | mClient->addSupportedChannelMask(bitPerfectChannelMask); |
| 1158 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState(AUDIO_DEVICE_OUT_USB_DEVICE, |
| 1159 | AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 1160 | "", "", AUDIO_FORMAT_DEFAULT)); |
| 1161 | auto devices = mManager->getAvailableOutputDevices(); |
| 1162 | audio_port_handle_t usbPortId = AUDIO_PORT_HANDLE_NONE; |
| 1163 | for (auto device : devices) { |
| 1164 | if (device->type() == AUDIO_DEVICE_OUT_USB_DEVICE) { |
| 1165 | usbPortId = device->getId(); |
| 1166 | break; |
| 1167 | } |
| 1168 | } |
| 1169 | EXPECT_NE(AUDIO_PORT_HANDLE_NONE, usbPortId); |
| 1170 | |
| 1171 | const uid_t uid = 1234; |
| 1172 | const uid_t anotherUid = 5678; |
| 1173 | const audio_attributes_t mediaAttr = { |
| 1174 | .content_type = AUDIO_CONTENT_TYPE_MUSIC, |
| 1175 | .usage = AUDIO_USAGE_MEDIA, |
| 1176 | }; |
| 1177 | |
| 1178 | std::vector<audio_mixer_attributes_t> mixerAttributes; |
| 1179 | EXPECT_EQ(NO_ERROR, mManager->getSupportedMixerAttributes(usbPortId, mixerAttributes)); |
| 1180 | EXPECT_GT(mixerAttributes.size(), 0); |
| 1181 | size_t bitPerfectIndex = 0; |
| 1182 | for (; bitPerfectIndex < mixerAttributes.size(); ++bitPerfectIndex) { |
| 1183 | if (mixerAttributes[bitPerfectIndex].mixer_behavior == AUDIO_MIXER_BEHAVIOR_BIT_PERFECT) { |
| 1184 | break; |
| 1185 | } |
| 1186 | } |
| 1187 | EXPECT_LT(bitPerfectIndex, mixerAttributes.size()); |
| 1188 | EXPECT_EQ(bitPerfectFormat, mixerAttributes[bitPerfectIndex].config.format); |
| 1189 | EXPECT_EQ(bitPerfectChannelMask, mixerAttributes[bitPerfectIndex].config.channel_mask); |
| 1190 | EXPECT_EQ(bitPerfectSampleRate, mixerAttributes[bitPerfectIndex].config.sample_rate); |
| 1191 | EXPECT_EQ(NO_ERROR, |
| 1192 | mManager->setPreferredMixerAttributes( |
| 1193 | &mediaAttr, usbPortId, uid, &mixerAttributes[bitPerfectIndex])); |
| 1194 | |
| 1195 | audio_io_handle_t bitPerfectOutput = AUDIO_IO_HANDLE_NONE; |
| 1196 | audio_io_handle_t output = AUDIO_IO_HANDLE_NONE; |
| 1197 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 1198 | audio_port_handle_t bitPerfectPortId = AUDIO_PORT_HANDLE_NONE; |
| 1199 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE; |
| 1200 | bool isBitPerfect; |
| 1201 | |
| 1202 | // When there is no active bit-perfect playback, the output selection will follow default |
| 1203 | // routing strategy. |
| 1204 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
| 1205 | 48000, AUDIO_OUTPUT_FLAG_NONE, &output, &portId, mediaAttr, AUDIO_SESSION_NONE, |
| 1206 | uid, &isBitPerfect); |
| 1207 | EXPECT_FALSE(isBitPerfect); |
| 1208 | EXPECT_NE(AUDIO_IO_HANDLE_NONE, output); |
| 1209 | const auto outputDesc = mManager->getOutputs().valueFor(output); |
| 1210 | EXPECT_NE(nullptr, outputDesc); |
| 1211 | EXPECT_NE(AUDIO_OUTPUT_FLAG_BIT_PERFECT, outputDesc->mFlags & AUDIO_OUTPUT_FLAG_BIT_PERFECT); |
| 1212 | |
| 1213 | // Start bit-perfect playback |
| 1214 | getOutputForAttr(&selectedDeviceId, bitPerfectFormat, bitPerfectChannelMask, |
| 1215 | bitPerfectSampleRate, AUDIO_OUTPUT_FLAG_NONE, &bitPerfectOutput, &bitPerfectPortId, |
| 1216 | mediaAttr, AUDIO_SESSION_NONE, uid, &isBitPerfect); |
| 1217 | status_t status = mManager->startOutput(bitPerfectPortId); |
| 1218 | if (status == DEAD_OBJECT) { |
| 1219 | getOutputForAttr(&selectedDeviceId, bitPerfectFormat, bitPerfectChannelMask, |
| 1220 | bitPerfectSampleRate, AUDIO_OUTPUT_FLAG_NONE, &bitPerfectOutput, &bitPerfectPortId, |
| 1221 | mediaAttr, AUDIO_SESSION_NONE, uid, &isBitPerfect); |
| 1222 | status = mManager->startOutput(bitPerfectPortId); |
| 1223 | } |
| 1224 | EXPECT_EQ(NO_ERROR, status); |
| 1225 | EXPECT_TRUE(isBitPerfect); |
| 1226 | EXPECT_NE(AUDIO_IO_HANDLE_NONE, bitPerfectOutput); |
| 1227 | const auto bitPerfectOutputDesc = mManager->getOutputs().valueFor(bitPerfectOutput); |
| 1228 | EXPECT_NE(nullptr, bitPerfectOutputDesc); |
| 1229 | EXPECT_EQ(AUDIO_OUTPUT_FLAG_BIT_PERFECT, |
| 1230 | bitPerfectOutputDesc->mFlags & AUDIO_OUTPUT_FLAG_BIT_PERFECT); |
| 1231 | |
| 1232 | // If the playback is from preferred mixer attributes owner but the request doesn't match |
| 1233 | // preferred mixer attributes, it will not be bit-perfect. |
| 1234 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
| 1235 | 48000, AUDIO_OUTPUT_FLAG_NONE, &output, &portId, mediaAttr, AUDIO_SESSION_NONE, |
| 1236 | uid, &isBitPerfect); |
| 1237 | EXPECT_FALSE(isBitPerfect); |
| 1238 | EXPECT_EQ(bitPerfectOutput, output); |
| 1239 | |
| 1240 | // When bit-perfect playback is active, all other playback will be routed to bit-perfect output. |
| 1241 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
| 1242 | 48000, AUDIO_OUTPUT_FLAG_NONE, &output, &portId, mediaAttr, AUDIO_SESSION_NONE, |
| 1243 | anotherUid, &isBitPerfect); |
| 1244 | EXPECT_FALSE(isBitPerfect); |
| 1245 | EXPECT_EQ(bitPerfectOutput, output); |
| 1246 | |
jiabin | d9a58d3 | 2023-06-01 17:57:30 +0000 | [diff] [blame] | 1247 | const audio_attributes_t dtmfAttr = { |
| 1248 | .content_type = AUDIO_CONTENT_TYPE_UNKNOWN, |
| 1249 | .usage = AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING, |
| 1250 | }; |
| 1251 | audio_io_handle_t dtmfOutput = AUDIO_IO_HANDLE_NONE; |
| 1252 | selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 1253 | portId = AUDIO_PORT_HANDLE_NONE; |
| 1254 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
| 1255 | 48000, AUDIO_OUTPUT_FLAG_NONE, &dtmfOutput, &portId, dtmfAttr, |
| 1256 | AUDIO_SESSION_NONE, anotherUid, &isBitPerfect); |
| 1257 | EXPECT_FALSE(isBitPerfect); |
| 1258 | EXPECT_EQ(bitPerfectOutput, dtmfOutput); |
| 1259 | |
jiabin | 5eaf096 | 2022-12-20 20:11:38 +0000 | [diff] [blame] | 1260 | // When configuration matches preferred mixer attributes, which is bit-perfect, but the client |
| 1261 | // is not the owner of preferred mixer attributes, the playback will not be bit-perfect. |
| 1262 | getOutputForAttr(&selectedDeviceId, bitPerfectFormat, bitPerfectChannelMask, |
| 1263 | bitPerfectSampleRate, AUDIO_OUTPUT_FLAG_NONE, &output, &portId, mediaAttr, |
| 1264 | AUDIO_SESSION_NONE, anotherUid, &isBitPerfect); |
| 1265 | EXPECT_FALSE(isBitPerfect); |
| 1266 | EXPECT_EQ(bitPerfectOutput, output); |
| 1267 | |
| 1268 | EXPECT_EQ(NO_ERROR, |
| 1269 | mManager->clearPreferredMixerAttributes(&mediaAttr, usbPortId, uid)); |
| 1270 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState(AUDIO_DEVICE_OUT_USB_DEVICE, |
| 1271 | AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 1272 | "", "", AUDIO_FORMAT_LDAC)); |
| 1273 | } |
| 1274 | |
jiabin | de7ae44 | 2024-02-06 00:57:36 +0000 | [diff] [blame^] | 1275 | TEST_F(AudioPolicyManagerTestWithConfigurationFile, PreferExactConfigForInput) { |
| 1276 | const audio_channel_mask_t deviceChannelMask = AUDIO_CHANNEL_IN_3POINT1; |
| 1277 | mClient->addSupportedFormat(AUDIO_FORMAT_PCM_16_BIT); |
| 1278 | mClient->addSupportedChannelMask(deviceChannelMask); |
| 1279 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState(AUDIO_DEVICE_IN_USB_DEVICE, |
| 1280 | AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 1281 | "", "", AUDIO_FORMAT_DEFAULT)); |
| 1282 | |
| 1283 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 1284 | audio_attributes_t attr = {AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 1285 | AUDIO_SOURCE_VOICE_COMMUNICATION,AUDIO_FLAG_NONE, ""}; |
| 1286 | AudioPolicyInterface::input_type_t inputType; |
| 1287 | audio_io_handle_t input = AUDIO_PORT_HANDLE_NONE; |
| 1288 | AttributionSourceState attributionSource = createAttributionSourceState(/*uid=*/ 0); |
| 1289 | audio_config_base_t requestedConfig = { |
| 1290 | .channel_mask = AUDIO_CHANNEL_IN_STEREO, |
| 1291 | .format = AUDIO_FORMAT_PCM_16_BIT, |
| 1292 | .sample_rate = 48000 |
| 1293 | }; |
| 1294 | audio_config_base_t config = requestedConfig; |
| 1295 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE; |
| 1296 | ASSERT_EQ(OK, mManager->getInputForAttr( |
| 1297 | &attr, &input, 1 /*riid*/, AUDIO_SESSION_NONE, attributionSource, &config, |
| 1298 | AUDIO_INPUT_FLAG_NONE, |
| 1299 | &selectedDeviceId, &inputType, &portId)); |
| 1300 | ASSERT_NE(AUDIO_PORT_HANDLE_NONE, portId); |
| 1301 | ASSERT_TRUE(equals(requestedConfig, config)); |
| 1302 | |
| 1303 | attr = {AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 1304 | AUDIO_SOURCE_VOICE_COMMUNICATION, AUDIO_FLAG_NONE, ""}; |
| 1305 | requestedConfig.channel_mask = deviceChannelMask; |
| 1306 | config = requestedConfig; |
| 1307 | selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 1308 | input = AUDIO_PORT_HANDLE_NONE; |
| 1309 | portId = AUDIO_PORT_HANDLE_NONE; |
| 1310 | ASSERT_EQ(OK, mManager->getInputForAttr( |
| 1311 | &attr, &input, 1 /*riid*/, AUDIO_SESSION_NONE, attributionSource, &config, |
| 1312 | AUDIO_INPUT_FLAG_NONE, |
| 1313 | &selectedDeviceId, &inputType, &portId)); |
| 1314 | ASSERT_NE(AUDIO_PORT_HANDLE_NONE, portId); |
| 1315 | ASSERT_TRUE(equals(requestedConfig, config)); |
| 1316 | |
| 1317 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState(AUDIO_DEVICE_IN_USB_DEVICE, |
| 1318 | AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 1319 | "", "", AUDIO_FORMAT_DEFAULT)); |
| 1320 | } |
| 1321 | |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 1322 | class AudioPolicyManagerTestDynamicPolicy : public AudioPolicyManagerTestWithConfigurationFile { |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1323 | protected: |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1324 | void TearDown() override; |
| 1325 | |
| 1326 | status_t addPolicyMix(int mixType, int mixFlag, audio_devices_t deviceType, |
| 1327 | std::string mixAddress, const audio_config_t& audioConfig, |
Jan Sebechlebsky | 0e7b2f1 | 2022-08-18 14:40:37 +0200 | [diff] [blame] | 1328 | const std::vector<AudioMixMatchCriterion>& matchCriteria); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1329 | void clearPolicyMix(); |
jiabin | 24ff57a | 2023-11-27 21:06:51 +0000 | [diff] [blame] | 1330 | void addPolicyMixAndStartInputForLoopback( |
| 1331 | int mixType, int mixFlag, audio_devices_t deviceType, std::string mixAddress, |
| 1332 | const audio_config_t& audioConfig, |
| 1333 | const std::vector<AudioMixMatchCriterion>& matchCriteria, |
| 1334 | audio_session_t session=AUDIO_SESSION_NONE, |
| 1335 | audio_config_base_t config=DEFAULT_INPUT_CONFIG, |
| 1336 | audio_input_flags_t inputFlags=AUDIO_INPUT_FLAG_NONE); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1337 | |
| 1338 | Vector<AudioMix> mAudioMixes; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1339 | const std::string mMixAddress = "remote_submix_media"; |
jiabin | 24ff57a | 2023-11-27 21:06:51 +0000 | [diff] [blame] | 1340 | |
| 1341 | audio_port_handle_t mLoopbackInputPortId = AUDIO_PORT_HANDLE_NONE; |
| 1342 | std::unique_ptr<RecordingActivityTracker> mTracker; |
| 1343 | struct audio_port_v7 mInjectionPort; |
| 1344 | |
| 1345 | constexpr static const audio_config_base_t DEFAULT_INPUT_CONFIG = { |
| 1346 | .sample_rate = k48000SamplingRate, |
| 1347 | .channel_mask = AUDIO_CHANNEL_IN_STEREO, |
| 1348 | .format = AUDIO_FORMAT_PCM_16_BIT |
| 1349 | }; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1350 | }; |
| 1351 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1352 | void AudioPolicyManagerTestDynamicPolicy::TearDown() { |
jiabin | 24ff57a | 2023-11-27 21:06:51 +0000 | [diff] [blame] | 1353 | clearPolicyMix(); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 1354 | AudioPolicyManagerTestWithConfigurationFile::TearDown(); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | status_t AudioPolicyManagerTestDynamicPolicy::addPolicyMix(int mixType, int mixFlag, |
| 1358 | audio_devices_t deviceType, std::string mixAddress, const audio_config_t& audioConfig, |
Jan Sebechlebsky | 0e7b2f1 | 2022-08-18 14:40:37 +0200 | [diff] [blame] | 1359 | const std::vector<AudioMixMatchCriterion>& matchCriteria = {}) { |
| 1360 | AudioMix myAudioMix(matchCriteria, mixType, audioConfig, mixFlag, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1361 | String8(mixAddress.c_str()), 0); |
| 1362 | myAudioMix.mDeviceType = deviceType; |
| 1363 | // Clear mAudioMix before add new one to make sure we don't add already exist mixes. |
| 1364 | mAudioMixes.clear(); |
| 1365 | mAudioMixes.add(myAudioMix); |
| 1366 | |
| 1367 | // As the policy mixes registration may fail at some case, |
| 1368 | // caller need to check the returned status. |
| 1369 | status_t ret = mManager->registerPolicyMixes(mAudioMixes); |
| 1370 | return ret; |
| 1371 | } |
| 1372 | |
| 1373 | void AudioPolicyManagerTestDynamicPolicy::clearPolicyMix() { |
| 1374 | if (mManager != nullptr) { |
jiabin | 24ff57a | 2023-11-27 21:06:51 +0000 | [diff] [blame] | 1375 | mManager->stopInput(mLoopbackInputPortId); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1376 | mManager->unregisterPolicyMixes(mAudioMixes); |
| 1377 | } |
| 1378 | mAudioMixes.clear(); |
| 1379 | } |
| 1380 | |
jiabin | 24ff57a | 2023-11-27 21:06:51 +0000 | [diff] [blame] | 1381 | void AudioPolicyManagerTestDynamicPolicy::addPolicyMixAndStartInputForLoopback( |
| 1382 | int mixType, int mixFlag, audio_devices_t deviceType, std::string mixAddress, |
| 1383 | const audio_config_t& audioConfig, |
| 1384 | const std::vector<AudioMixMatchCriterion>& matchCriteria, audio_session_t session, |
| 1385 | audio_config_base_t config, audio_input_flags_t inputFlags) { |
| 1386 | ASSERT_EQ(NO_ERROR, |
| 1387 | addPolicyMix(mixType, mixFlag, deviceType, mixAddress, audioConfig, matchCriteria)); |
| 1388 | if ((mixFlag & MIX_ROUTE_FLAG_LOOP_BACK) != MIX_ROUTE_FLAG_LOOP_BACK) { |
| 1389 | return; |
| 1390 | } |
| 1391 | |
| 1392 | mTracker.reset(new RecordingActivityTracker()); |
| 1393 | struct audio_port_v7 extractionPort; |
| 1394 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SOURCE, AUDIO_DEVICE_IN_REMOTE_SUBMIX, |
| 1395 | mixAddress, &extractionPort)); |
| 1396 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 1397 | audio_source_t source = AUDIO_SOURCE_REMOTE_SUBMIX; |
| 1398 | audio_attributes_t attr = { |
| 1399 | AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, source, AUDIO_FLAG_NONE, ""}; |
| 1400 | std::string tags = "addr=" + mMixAddress; |
| 1401 | audio_io_handle_t input = AUDIO_PORT_HANDLE_NONE; |
| 1402 | strncpy(attr.tags, tags.c_str(), AUDIO_ATTRIBUTES_TAGS_MAX_SIZE - 1); |
| 1403 | ASSERT_NO_FATAL_FAILURE( |
| 1404 | getInputForAttr(attr, &input, session, mTracker->getRiid(), |
| 1405 | &selectedDeviceId, config.format, config.channel_mask, |
| 1406 | config.sample_rate, inputFlags, &mLoopbackInputPortId)); |
| 1407 | ASSERT_EQ(NO_ERROR, mManager->startInput(mLoopbackInputPortId)); |
| 1408 | ASSERT_EQ(extractionPort.id, selectedDeviceId); |
| 1409 | |
| 1410 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SINK, AUDIO_DEVICE_OUT_REMOTE_SUBMIX, |
| 1411 | mMixAddress, &mInjectionPort)); |
| 1412 | } |
| 1413 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1414 | TEST_F(AudioPolicyManagerTestDynamicPolicy, InitSuccess) { |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 1415 | // SetUp must finish with no assertions |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | TEST_F(AudioPolicyManagerTestDynamicPolicy, Dump) { |
| 1419 | dumpToLog(); |
| 1420 | } |
| 1421 | |
| 1422 | TEST_F(AudioPolicyManagerTestDynamicPolicy, RegisterPolicyMixes) { |
| 1423 | status_t ret; |
| 1424 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 1425 | |
| 1426 | // Only capture of playback is allowed in LOOP_BACK &RENDER mode |
| 1427 | ret = addPolicyMix(MIX_TYPE_RECORDERS, MIX_ROUTE_FLAG_LOOP_BACK_AND_RENDER, |
Jan Sebechlebsky | 0e7b2f1 | 2022-08-18 14:40:37 +0200 | [diff] [blame] | 1428 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, "", audioConfig); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1429 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 1430 | |
| 1431 | // Fail due to the device is already connected. |
| 1432 | clearPolicyMix(); |
| 1433 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
Jan Sebechlebsky | 0e7b2f1 | 2022-08-18 14:40:37 +0200 | [diff] [blame] | 1434 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, "", audioConfig); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1435 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 1436 | |
| 1437 | // The first time to register policy mixes with valid parameter should succeed. |
| 1438 | clearPolicyMix(); |
| 1439 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 1440 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 1441 | audioConfig.sample_rate = k48000SamplingRate; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1442 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
Jan Sebechlebsky | 0e7b2f1 | 2022-08-18 14:40:37 +0200 | [diff] [blame] | 1443 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, mMixAddress, audioConfig); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1444 | ASSERT_EQ(NO_ERROR, ret); |
| 1445 | // Registering the same policy mixes should fail. |
| 1446 | ret = mManager->registerPolicyMixes(mAudioMixes); |
| 1447 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 1448 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1449 | // Registration should fail due to device not found. |
| 1450 | // Note that earpiece is not present in the test configuration file. |
| 1451 | // 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] | 1452 | clearPolicyMix(); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1453 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
Jan Sebechlebsky | 0e7b2f1 | 2022-08-18 14:40:37 +0200 | [diff] [blame] | 1454 | AUDIO_DEVICE_OUT_EARPIECE, "", audioConfig); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1455 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 1456 | |
| 1457 | // Registration should fail due to output not found. |
| 1458 | clearPolicyMix(); |
| 1459 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
Jan Sebechlebsky | 0e7b2f1 | 2022-08-18 14:40:37 +0200 | [diff] [blame] | 1460 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, "", audioConfig); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1461 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 1462 | |
Jan Sebechlebsky | cd33d8d | 2023-06-07 10:45:50 +0200 | [diff] [blame] | 1463 | // The first time to register valid loopback policy mix should succeed. |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1464 | clearPolicyMix(); |
Jan Sebechlebsky | cd33d8d | 2023-06-07 10:45:50 +0200 | [diff] [blame] | 1465 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 1466 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, "addr", audioConfig); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1467 | ASSERT_EQ(NO_ERROR, ret); |
Jan Sebechlebsky | cd33d8d | 2023-06-07 10:45:50 +0200 | [diff] [blame] | 1468 | // Registering the render policy for the loopback address should succeed. |
| 1469 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 1470 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, "addr", audioConfig); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1471 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 1472 | } |
| 1473 | |
| 1474 | TEST_F(AudioPolicyManagerTestDynamicPolicy, UnregisterPolicyMixes) { |
| 1475 | status_t ret; |
| 1476 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 1477 | |
| 1478 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 1479 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 1480 | audioConfig.sample_rate = k48000SamplingRate; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1481 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
Jan Sebechlebsky | 0e7b2f1 | 2022-08-18 14:40:37 +0200 | [diff] [blame] | 1482 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, mMixAddress, audioConfig); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1483 | ASSERT_EQ(NO_ERROR, ret); |
| 1484 | |
| 1485 | // After successfully registering policy mixes, it should be able to unregister. |
| 1486 | ret = mManager->unregisterPolicyMixes(mAudioMixes); |
| 1487 | ASSERT_EQ(NO_ERROR, ret); |
| 1488 | |
| 1489 | // After unregistering policy mixes successfully, it should fail unregistering |
| 1490 | // the same policy mixes as they are not registered. |
| 1491 | ret = mManager->unregisterPolicyMixes(mAudioMixes); |
| 1492 | ASSERT_EQ(INVALID_OPERATION, ret); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 1493 | } |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1494 | |
Jan Sebechlebsky | 0e7b2f1 | 2022-08-18 14:40:37 +0200 | [diff] [blame] | 1495 | TEST_F(AudioPolicyManagerTestDynamicPolicy, RegisterPolicyWithConsistentMixSucceeds) { |
| 1496 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 1497 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 1498 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 1499 | audioConfig.sample_rate = k48000SamplingRate; |
| 1500 | |
| 1501 | std::vector<AudioMixMatchCriterion> mixMatchCriteria = { |
| 1502 | createUidCriterion(/*uid=*/42), |
| 1503 | createUsageCriterion(AUDIO_USAGE_MEDIA, /*exclude=*/true)}; |
| 1504 | status_t ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 1505 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, mMixAddress, audioConfig, |
| 1506 | mixMatchCriteria); |
| 1507 | ASSERT_EQ(NO_ERROR, ret); |
| 1508 | } |
| 1509 | |
| 1510 | TEST_F(AudioPolicyManagerTestDynamicPolicy, RegisterPolicyWithInconsistentMixFails) { |
| 1511 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 1512 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 1513 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 1514 | audioConfig.sample_rate = k48000SamplingRate; |
| 1515 | |
| 1516 | std::vector<AudioMixMatchCriterion> mixMatchCriteria = { |
| 1517 | createUidCriterion(/*uid=*/42), |
| 1518 | createUidCriterion(/*uid=*/1235, /*exclude=*/true), |
| 1519 | createUsageCriterion(AUDIO_USAGE_MEDIA, /*exclude=*/true)}; |
| 1520 | status_t ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 1521 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, mMixAddress, audioConfig, |
| 1522 | mixMatchCriteria); |
| 1523 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 1524 | } |
| 1525 | |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1526 | class AudioPolicyManagerTestForHdmi |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1527 | : public AudioPolicyManagerTestWithConfigurationFile, |
| 1528 | public testing::WithParamInterface<audio_format_t> { |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1529 | protected: |
| 1530 | void SetUp() override; |
| 1531 | std::string getConfigFile() override { return sTvConfig; } |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1532 | std::map<audio_format_t, bool> getSurroundFormatsHelper(); |
| 1533 | std::vector<audio_format_t> getReportedSurroundFormatsHelper(); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1534 | std::unordered_set<audio_format_t> getFormatsFromPorts(); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1535 | void TearDown() override; |
| 1536 | |
| 1537 | static const std::string sTvConfig; |
| 1538 | |
| 1539 | }; |
| 1540 | |
| 1541 | const std::string AudioPolicyManagerTestForHdmi::sTvConfig = |
| 1542 | AudioPolicyManagerTestForHdmi::sExecutableDir + |
| 1543 | "test_settop_box_surround_configuration.xml"; |
| 1544 | |
| 1545 | void AudioPolicyManagerTestForHdmi::SetUp() { |
Mikhail Naganov | d4c21aa | 2021-10-05 15:10:16 -0700 | [diff] [blame] | 1546 | ASSERT_NO_FATAL_FAILURE(AudioPolicyManagerTest::SetUp()); |
Mikhail Naganov | 83caee0 | 2021-10-05 15:52:01 -0700 | [diff] [blame] | 1547 | mClient->addSupportedFormat(AUDIO_FORMAT_AC3); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1548 | mClient->addSupportedFormat(AUDIO_FORMAT_E_AC3); |
jiabin | 12537fc | 2023-10-12 17:56:08 +0000 | [diff] [blame] | 1549 | mClient->addSupportedChannelMask(AUDIO_CHANNEL_OUT_STEREO); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1550 | mManager->setDeviceConnectionState( |
| 1551 | AUDIO_DEVICE_OUT_HDMI, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 1552 | "" /*address*/, "" /*name*/, AUDIO_FORMAT_DEFAULT); |
| 1553 | } |
| 1554 | |
| 1555 | void AudioPolicyManagerTestForHdmi::TearDown() { |
| 1556 | mManager->setDeviceConnectionState( |
| 1557 | AUDIO_DEVICE_OUT_HDMI, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 1558 | "" /*address*/, "" /*name*/, AUDIO_FORMAT_DEFAULT); |
| 1559 | AudioPolicyManagerTest::TearDown(); |
| 1560 | } |
| 1561 | |
| 1562 | std::map<audio_format_t, bool> |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1563 | AudioPolicyManagerTestForHdmi::getSurroundFormatsHelper() { |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1564 | unsigned int numSurroundFormats = 0; |
| 1565 | std::map<audio_format_t, bool> surroundFormatsMap; |
| 1566 | status_t ret = mManager->getSurroundFormats( |
| 1567 | &numSurroundFormats, nullptr /* surroundFormats */, |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1568 | nullptr /* surroundFormatsEnabled */); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1569 | EXPECT_EQ(NO_ERROR, ret); |
| 1570 | if (ret != NO_ERROR) { |
| 1571 | return surroundFormatsMap; |
| 1572 | } |
| 1573 | audio_format_t surroundFormats[numSurroundFormats]; |
| 1574 | memset(surroundFormats, 0, sizeof(audio_format_t) * numSurroundFormats); |
| 1575 | bool surroundFormatsEnabled[numSurroundFormats]; |
| 1576 | memset(surroundFormatsEnabled, 0, sizeof(bool) * numSurroundFormats); |
| 1577 | ret = mManager->getSurroundFormats( |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1578 | &numSurroundFormats, surroundFormats, surroundFormatsEnabled); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1579 | EXPECT_EQ(NO_ERROR, ret); |
| 1580 | if (ret != NO_ERROR) { |
| 1581 | return surroundFormatsMap; |
| 1582 | } |
| 1583 | for (int i = 0; i< numSurroundFormats; i++) { |
| 1584 | surroundFormatsMap[surroundFormats[i]] = surroundFormatsEnabled[i]; |
| 1585 | } |
| 1586 | return surroundFormatsMap; |
| 1587 | } |
| 1588 | |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1589 | std::vector<audio_format_t> AudioPolicyManagerTestForHdmi::getReportedSurroundFormatsHelper() { |
| 1590 | unsigned int numSurroundFormats = 0; |
| 1591 | std::vector<audio_format_t> surroundFormatsVector; |
| 1592 | status_t ret = mManager->getReportedSurroundFormats( |
| 1593 | &numSurroundFormats, nullptr /* surroundFormats */); |
| 1594 | EXPECT_EQ(NO_ERROR, ret); |
| 1595 | if (ret != NO_ERROR) { |
| 1596 | return surroundFormatsVector; |
| 1597 | } |
| 1598 | audio_format_t surroundFormats[numSurroundFormats]; |
| 1599 | memset(surroundFormats, 0, sizeof(audio_format_t) * numSurroundFormats); |
| 1600 | ret = mManager->getReportedSurroundFormats(&numSurroundFormats, surroundFormats); |
| 1601 | EXPECT_EQ(NO_ERROR, ret); |
| 1602 | if (ret != NO_ERROR) { |
| 1603 | return surroundFormatsVector; |
| 1604 | } |
| 1605 | for (const auto &surroundFormat : surroundFormats) { |
| 1606 | surroundFormatsVector.push_back(surroundFormat); |
| 1607 | } |
| 1608 | return surroundFormatsVector; |
| 1609 | } |
| 1610 | |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1611 | std::unordered_set<audio_format_t> |
| 1612 | AudioPolicyManagerTestForHdmi::getFormatsFromPorts() { |
| 1613 | uint32_t numPorts = 0; |
| 1614 | uint32_t generation1; |
| 1615 | status_t ret; |
| 1616 | std::unordered_set<audio_format_t> formats; |
| 1617 | ret = mManager->listAudioPorts( |
| 1618 | AUDIO_PORT_ROLE_SINK, AUDIO_PORT_TYPE_DEVICE, &numPorts, nullptr, &generation1); |
| 1619 | EXPECT_EQ(NO_ERROR, ret) << "mManager->listAudioPorts returned error"; |
| 1620 | if (ret != NO_ERROR) { |
| 1621 | return formats; |
| 1622 | } |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 1623 | struct audio_port_v7 ports[numPorts]; |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1624 | ret = mManager->listAudioPorts( |
| 1625 | AUDIO_PORT_ROLE_SINK, AUDIO_PORT_TYPE_DEVICE, &numPorts, ports, &generation1); |
| 1626 | EXPECT_EQ(NO_ERROR, ret) << "mManager->listAudioPorts returned error"; |
| 1627 | if (ret != NO_ERROR) { |
| 1628 | return formats; |
| 1629 | } |
| 1630 | for (const auto &port : ports) { |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 1631 | for (size_t i = 0; i < port.num_audio_profiles; ++i) { |
| 1632 | formats.insert(port.audio_profiles[i].format); |
| 1633 | } |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1634 | } |
| 1635 | return formats; |
| 1636 | } |
| 1637 | |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1638 | TEST_P(AudioPolicyManagerTestForHdmi, GetSurroundFormatsReturnsSupportedFormats) { |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1639 | mManager->setForceUse( |
| 1640 | AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND, AUDIO_POLICY_FORCE_ENCODED_SURROUND_ALWAYS); |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1641 | auto surroundFormats = getSurroundFormatsHelper(); |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1642 | ASSERT_EQ(1, surroundFormats.count(GetParam())); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1643 | } |
| 1644 | |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1645 | TEST_P(AudioPolicyManagerTestForHdmi, |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1646 | GetSurroundFormatsReturnsManipulatedFormats) { |
| 1647 | mManager->setForceUse( |
| 1648 | AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND, AUDIO_POLICY_FORCE_ENCODED_SURROUND_MANUAL); |
| 1649 | |
| 1650 | status_t ret = |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1651 | mManager->setSurroundFormatEnabled(GetParam(), false /*enabled*/); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1652 | ASSERT_EQ(NO_ERROR, ret); |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1653 | auto surroundFormats = getSurroundFormatsHelper(); |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1654 | ASSERT_EQ(1, surroundFormats.count(GetParam())); |
| 1655 | ASSERT_FALSE(surroundFormats[GetParam()]); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1656 | |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1657 | ret = mManager->setSurroundFormatEnabled(GetParam(), true /*enabled*/); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1658 | ASSERT_EQ(NO_ERROR, ret); |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1659 | surroundFormats = getSurroundFormatsHelper(); |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1660 | ASSERT_EQ(1, surroundFormats.count(GetParam())); |
| 1661 | ASSERT_TRUE(surroundFormats[GetParam()]); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1662 | |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1663 | ret = mManager->setSurroundFormatEnabled(GetParam(), false /*enabled*/); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1664 | ASSERT_EQ(NO_ERROR, ret); |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1665 | surroundFormats = getSurroundFormatsHelper(); |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1666 | ASSERT_EQ(1, surroundFormats.count(GetParam())); |
| 1667 | ASSERT_FALSE(surroundFormats[GetParam()]); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1668 | } |
| 1669 | |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1670 | TEST_P(AudioPolicyManagerTestForHdmi, |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1671 | ListAudioPortsReturnManipulatedHdmiFormats) { |
| 1672 | mManager->setForceUse( |
| 1673 | AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND, AUDIO_POLICY_FORCE_ENCODED_SURROUND_MANUAL); |
| 1674 | |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1675 | ASSERT_EQ(NO_ERROR, mManager->setSurroundFormatEnabled(GetParam(), true /*enabled*/)); |
jiabin | 12537fc | 2023-10-12 17:56:08 +0000 | [diff] [blame] | 1676 | auto formats = getFormatsFromPorts(); |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1677 | ASSERT_EQ(1, formats.count(GetParam())); |
jiabin | 12537fc | 2023-10-12 17:56:08 +0000 | [diff] [blame] | 1678 | |
| 1679 | ASSERT_EQ(NO_ERROR, mManager->setSurroundFormatEnabled(GetParam(), false /*enabled*/)); |
| 1680 | formats = getFormatsFromPorts(); |
| 1681 | ASSERT_EQ(0, formats.count(GetParam())); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1682 | } |
| 1683 | |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1684 | TEST_P(AudioPolicyManagerTestForHdmi, |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1685 | GetReportedSurroundFormatsReturnsHdmiReportedFormats) { |
| 1686 | mManager->setForceUse( |
| 1687 | AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND, AUDIO_POLICY_FORCE_ENCODED_SURROUND_ALWAYS); |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1688 | auto surroundFormats = getReportedSurroundFormatsHelper(); |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1689 | ASSERT_EQ(1, std::count(surroundFormats.begin(), surroundFormats.end(), GetParam())); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1690 | } |
| 1691 | |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1692 | TEST_P(AudioPolicyManagerTestForHdmi, |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1693 | GetReportedSurroundFormatsReturnsNonManipulatedHdmiReportedFormats) { |
| 1694 | mManager->setForceUse( |
| 1695 | AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND, AUDIO_POLICY_FORCE_ENCODED_SURROUND_MANUAL); |
| 1696 | |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1697 | status_t ret = mManager->setSurroundFormatEnabled(GetParam(), false /*enabled*/); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1698 | ASSERT_EQ(NO_ERROR, ret); |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1699 | auto surroundFormats = getReportedSurroundFormatsHelper(); |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1700 | ASSERT_EQ(1, std::count(surroundFormats.begin(), surroundFormats.end(), GetParam())); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1701 | |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1702 | ret = mManager->setSurroundFormatEnabled(GetParam(), true /*enabled*/); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1703 | ASSERT_EQ(NO_ERROR, ret); |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1704 | surroundFormats = getReportedSurroundFormatsHelper(); |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1705 | ASSERT_EQ(1, std::count(surroundFormats.begin(), surroundFormats.end(), GetParam())); |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1706 | } |
| 1707 | |
Mikhail Naganov | 18885d3 | 2021-10-01 13:03:09 -0700 | [diff] [blame] | 1708 | TEST_P(AudioPolicyManagerTestForHdmi, GetSurroundFormatsIgnoresSupportedFormats) { |
| 1709 | mManager->setForceUse( |
| 1710 | AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND, AUDIO_POLICY_FORCE_ENCODED_SURROUND_NEVER); |
| 1711 | auto surroundFormats = getSurroundFormatsHelper(); |
| 1712 | ASSERT_EQ(1, surroundFormats.count(GetParam())); |
| 1713 | ASSERT_FALSE(surroundFormats[GetParam()]); |
| 1714 | } |
| 1715 | |
| 1716 | INSTANTIATE_TEST_SUITE_P(SurroundFormatSupport, AudioPolicyManagerTestForHdmi, |
| 1717 | testing::Values(AUDIO_FORMAT_AC3, AUDIO_FORMAT_E_AC3), |
| 1718 | [](const ::testing::TestParamInfo<AudioPolicyManagerTestForHdmi::ParamType>& info) { |
| 1719 | return audio_format_to_string(info.param); |
| 1720 | }); |
| 1721 | |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 1722 | class AudioPolicyManagerTestDPNoRemoteSubmixModule : public AudioPolicyManagerTestDynamicPolicy { |
| 1723 | protected: |
| 1724 | std::string getConfigFile() override { return sPrimaryOnlyConfig; } |
| 1725 | |
| 1726 | static const std::string sPrimaryOnlyConfig; |
| 1727 | }; |
| 1728 | |
| 1729 | const std::string AudioPolicyManagerTestDPNoRemoteSubmixModule::sPrimaryOnlyConfig = |
| 1730 | sExecutableDir + "test_audio_policy_primary_only_configuration.xml"; |
| 1731 | |
| 1732 | TEST_F(AudioPolicyManagerTestDPNoRemoteSubmixModule, InitSuccess) { |
| 1733 | // SetUp must finish with no assertions. |
| 1734 | } |
| 1735 | |
| 1736 | TEST_F(AudioPolicyManagerTestDPNoRemoteSubmixModule, Dump) { |
| 1737 | dumpToLog(); |
| 1738 | } |
| 1739 | |
| 1740 | TEST_F(AudioPolicyManagerTestDPNoRemoteSubmixModule, RegistrationFailure) { |
| 1741 | // Registration/Unregistration should fail due to module for remote submix not found. |
| 1742 | status_t ret; |
| 1743 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 1744 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 1745 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 1746 | audioConfig.sample_rate = k48000SamplingRate; |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 1747 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
Jan Sebechlebsky | 0e7b2f1 | 2022-08-18 14:40:37 +0200 | [diff] [blame] | 1748 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, "", audioConfig); |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 1749 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 1750 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1751 | ret = mManager->unregisterPolicyMixes(mAudioMixes); |
| 1752 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 1753 | } |
| 1754 | |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 1755 | struct DPTestParam { |
| 1756 | DPTestParam(const std::vector<AudioMixMatchCriterion>& mixCriteria, |
| 1757 | bool expected_match = false) |
| 1758 | : mixCriteria(mixCriteria), attributes(defaultAttr), session(AUDIO_SESSION_NONE), |
| 1759 | expected_match(expected_match) {} |
| 1760 | |
| 1761 | DPTestParam& withUsage(audio_usage_t usage) { |
| 1762 | attributes.usage = usage; |
| 1763 | return *this; |
| 1764 | } |
| 1765 | |
| 1766 | DPTestParam& withTags(const char *tags) { |
| 1767 | std::strncpy(attributes.tags, tags, sizeof(attributes.tags)); |
| 1768 | return *this; |
| 1769 | } |
| 1770 | |
| 1771 | DPTestParam& withSource(audio_source_t source) { |
| 1772 | attributes.source = source; |
| 1773 | return *this; |
| 1774 | } |
| 1775 | |
| 1776 | DPTestParam& withSessionId(audio_session_t sessionId) { |
| 1777 | session = sessionId; |
| 1778 | return *this; |
| 1779 | } |
| 1780 | |
| 1781 | std::vector<AudioMixMatchCriterion> mixCriteria; |
| 1782 | audio_attributes_t attributes; |
| 1783 | audio_session_t session; |
| 1784 | bool expected_match; |
| 1785 | }; |
| 1786 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1787 | class AudioPolicyManagerTestDPPlaybackReRouting : public AudioPolicyManagerTestDynamicPolicy, |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 1788 | public testing::WithParamInterface<DPTestParam> { |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1789 | protected: |
| 1790 | void SetUp() override; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1791 | }; |
| 1792 | |
| 1793 | void AudioPolicyManagerTestDPPlaybackReRouting::SetUp() { |
Mikhail Naganov | d4c21aa | 2021-10-05 15:10:16 -0700 | [diff] [blame] | 1794 | ASSERT_NO_FATAL_FAILURE(AudioPolicyManagerTestDynamicPolicy::SetUp()); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1795 | |
| 1796 | mTracker.reset(new RecordingActivityTracker()); |
| 1797 | |
| 1798 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 1799 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 1800 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 1801 | audioConfig.sample_rate = k48000SamplingRate; |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 1802 | |
| 1803 | DPTestParam param = GetParam(); |
jiabin | 24ff57a | 2023-11-27 21:06:51 +0000 | [diff] [blame] | 1804 | ASSERT_NO_FATAL_FAILURE( |
| 1805 | addPolicyMixAndStartInputForLoopback(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 1806 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, mMixAddress, audioConfig, param.mixCriteria, |
| 1807 | param.session)); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1808 | } |
| 1809 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1810 | TEST_P(AudioPolicyManagerTestDPPlaybackReRouting, PlaybackReRouting) { |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 1811 | const DPTestParam param = GetParam(); |
| 1812 | const audio_attributes_t& attr = param.attributes; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1813 | |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 1814 | audio_port_handle_t playbackRoutedPortId = AUDIO_PORT_HANDLE_NONE; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1815 | getOutputForAttr(&playbackRoutedPortId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 1816 | k48000SamplingRate, AUDIO_OUTPUT_FLAG_NONE, nullptr /*output*/, nullptr /*portId*/, |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 1817 | attr, param.session); |
| 1818 | if (param.expected_match) { |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1819 | EXPECT_EQ(mInjectionPort.id, playbackRoutedPortId); |
| 1820 | } else { |
| 1821 | EXPECT_NE(mInjectionPort.id, playbackRoutedPortId); |
| 1822 | } |
| 1823 | } |
| 1824 | |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 1825 | const std::vector<AudioMixMatchCriterion> USAGE_MEDIA_ALARM_CRITERIA = { |
| 1826 | createUsageCriterion(AUDIO_USAGE_MEDIA), |
| 1827 | createUsageCriterion(AUDIO_USAGE_ALARM) |
| 1828 | }; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1829 | |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 1830 | INSTANTIATE_TEST_SUITE_P( |
| 1831 | PlaybackReroutingUsageMatch, |
| 1832 | AudioPolicyManagerTestDPPlaybackReRouting, |
| 1833 | testing::Values( |
| 1834 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ true) |
| 1835 | .withUsage(AUDIO_USAGE_MEDIA), |
| 1836 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ true) |
| 1837 | .withUsage(AUDIO_USAGE_MEDIA).withTags("addr=other"), |
| 1838 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ true) |
| 1839 | .withUsage(AUDIO_USAGE_ALARM), |
| 1840 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ false) |
| 1841 | .withUsage(AUDIO_USAGE_VOICE_COMMUNICATION), |
| 1842 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ false) |
| 1843 | .withUsage(AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING), |
| 1844 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ false) |
| 1845 | .withUsage(AUDIO_USAGE_NOTIFICATION), |
| 1846 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ false) |
| 1847 | .withUsage(AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE), |
| 1848 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ false) |
| 1849 | .withUsage(AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST), |
| 1850 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ false) |
| 1851 | .withUsage(AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT), |
| 1852 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ false) |
| 1853 | .withUsage(AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED), |
| 1854 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ false) |
| 1855 | .withUsage(AUDIO_USAGE_NOTIFICATION_EVENT), |
| 1856 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ false) |
| 1857 | .withUsage(AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY), |
| 1858 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ false) |
| 1859 | .withUsage(AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE), |
| 1860 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ false) |
| 1861 | .withUsage(AUDIO_USAGE_ASSISTANCE_SONIFICATION), |
| 1862 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ false) |
| 1863 | .withUsage(AUDIO_USAGE_GAME), |
| 1864 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ false) |
| 1865 | .withUsage(AUDIO_USAGE_ASSISTANT))); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1866 | |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 1867 | INSTANTIATE_TEST_SUITE_P( |
| 1868 | PlaybackReroutingAddressPriorityMatch, |
| 1869 | AudioPolicyManagerTestDPPlaybackReRouting, |
| 1870 | testing::Values( |
| 1871 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ true) |
| 1872 | .withUsage(AUDIO_USAGE_MEDIA).withTags("addr=remote_submix_media"), |
| 1873 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ true) |
| 1874 | .withUsage(AUDIO_USAGE_VOICE_COMMUNICATION).withTags("addr=remote_submix_media"), |
| 1875 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ true) |
| 1876 | .withUsage(AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING) |
| 1877 | .withTags("addr=remote_submix_media"), |
| 1878 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ true) |
| 1879 | .withUsage(AUDIO_USAGE_ALARM) |
| 1880 | .withTags("addr=remote_submix_media"), |
| 1881 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ true) |
| 1882 | .withUsage(AUDIO_USAGE_NOTIFICATION) |
| 1883 | .withTags("addr=remote_submix_media"), |
| 1884 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ true) |
| 1885 | .withUsage(AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE) |
| 1886 | .withTags("addr=remote_submix_media"), |
| 1887 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ true) |
| 1888 | .withUsage(AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST) |
| 1889 | .withTags("addr=remote_submix_media"), |
| 1890 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ true) |
| 1891 | .withUsage(AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT) |
| 1892 | .withTags("addr=remote_submix_media"), |
| 1893 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ true) |
| 1894 | .withUsage(AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED) |
| 1895 | .withTags("addr=remote_submix_media"), |
| 1896 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ true) |
| 1897 | .withUsage(AUDIO_USAGE_NOTIFICATION_EVENT) |
| 1898 | .withTags("addr=remote_submix_media"), |
| 1899 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ true) |
| 1900 | .withUsage(AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY) |
| 1901 | .withTags("addr=remote_submix_media"), |
| 1902 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ true) |
| 1903 | .withUsage(AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE) |
| 1904 | .withTags("addr=remote_submix_media"), |
| 1905 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ true) |
| 1906 | .withUsage(AUDIO_USAGE_ASSISTANCE_SONIFICATION) |
| 1907 | .withTags("addr=remote_submix_media"), |
| 1908 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ true) |
| 1909 | .withUsage(AUDIO_USAGE_GAME) |
| 1910 | .withTags("addr=remote_submix_media"), |
| 1911 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ true) |
| 1912 | .withUsage(AUDIO_USAGE_VIRTUAL_SOURCE) |
| 1913 | .withTags("addr=remote_submix_media"), |
| 1914 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ true) |
| 1915 | .withUsage(AUDIO_USAGE_ASSISTANT) |
Jan Sebechlebsky | bc56bcd | 2022-09-26 13:15:19 +0200 | [diff] [blame] | 1916 | .withTags("addr=remote_submix_media"), |
| 1917 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ true) |
| 1918 | .withUsage(AUDIO_USAGE_ASSISTANT) |
| 1919 | .withTags("sometag;addr=remote_submix_media;othertag=somevalue"), |
| 1920 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ true) |
| 1921 | .withUsage(AUDIO_USAGE_ASSISTANT) |
| 1922 | .withTags("addr=remote_submix_media;othertag"), |
| 1923 | DPTestParam(USAGE_MEDIA_ALARM_CRITERIA, /*expected_match=*/ true) |
| 1924 | .withUsage(AUDIO_USAGE_ASSISTANT) |
| 1925 | .withTags("sometag;othertag;addr=remote_submix_media"))); |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 1926 | |
| 1927 | static constexpr audio_session_t TEST_SESSION_ID = static_cast<audio_session_t>(42); |
| 1928 | static constexpr audio_session_t OTHER_SESSION_ID = static_cast<audio_session_t>(77); |
| 1929 | |
| 1930 | INSTANTIATE_TEST_SUITE_P( |
| 1931 | PlaybackReRoutingWithSessionId, |
| 1932 | AudioPolicyManagerTestDPPlaybackReRouting, |
| 1933 | testing::Values( |
| 1934 | // Mix is matched because the session id matches the one specified by the mix rule. |
| 1935 | DPTestParam(/*mixCriteria=*/ {createSessionIdCriterion(TEST_SESSION_ID)}, |
| 1936 | /*expected_match=*/ true) |
| 1937 | .withSessionId(TEST_SESSION_ID), |
| 1938 | // Mix is not matched because the session id doesn't match the one specified |
| 1939 | // by the mix rule. |
| 1940 | DPTestParam(/*mixCriteria=*/ {createSessionIdCriterion(TEST_SESSION_ID)}, |
| 1941 | /*expected_match=*/ false) |
| 1942 | .withSessionId(OTHER_SESSION_ID), |
| 1943 | // Mix is matched, the session id doesn't match the one specified by rule, |
| 1944 | // but there's address specified in the tags which takes precedence. |
| 1945 | DPTestParam(/*mixCriteria=*/ {createSessionIdCriterion(TEST_SESSION_ID)}, |
| 1946 | /*expected_match=*/ true) |
| 1947 | .withSessionId(OTHER_SESSION_ID).withTags("addr=remote_submix_media"), |
| 1948 | // Mix is matched, both the session id and the usage match ones specified by mix rule. |
| 1949 | DPTestParam(/*mixCriteria=*/ {createSessionIdCriterion(TEST_SESSION_ID), |
| 1950 | createUsageCriterion(AUDIO_USAGE_MEDIA)}, |
| 1951 | /*expected_match=*/ true) |
| 1952 | .withSessionId(TEST_SESSION_ID).withUsage(AUDIO_USAGE_MEDIA), |
| 1953 | // Mix is not matched, the session id matches the one specified by mix rule, |
| 1954 | // but usage does not. |
| 1955 | DPTestParam(/*mixCriteria=*/ {createSessionIdCriterion(TEST_SESSION_ID), |
| 1956 | createUsageCriterion(AUDIO_USAGE_MEDIA)}, |
| 1957 | /*expected_match=*/ false) |
| 1958 | .withSessionId(TEST_SESSION_ID).withUsage(AUDIO_USAGE_GAME), |
| 1959 | // Mix is not matched, the usage matches the one specified by mix rule, |
| 1960 | // but the session id is excluded. |
| 1961 | DPTestParam(/*mixCriteria=*/ {createSessionIdCriterion(TEST_SESSION_ID, /*exclude=*/ true), |
| 1962 | createUsageCriterion(AUDIO_USAGE_MEDIA)}, |
| 1963 | /*expected_match=*/ false) |
| 1964 | .withSessionId(TEST_SESSION_ID).withUsage(AUDIO_USAGE_MEDIA))); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 1965 | |
Jan Sebechlebsky | 8e10cea | 2023-03-29 11:43:31 +0200 | [diff] [blame] | 1966 | struct DPMmapTestParam { |
| 1967 | DPMmapTestParam(int mixRouteFlags, audio_devices_t deviceType, const std::string& deviceAddress) |
| 1968 | : mixRouteFlags(mixRouteFlags), deviceType(deviceType), deviceAddress(deviceAddress) {} |
| 1969 | |
| 1970 | int mixRouteFlags; |
| 1971 | audio_devices_t deviceType; |
| 1972 | std::string deviceAddress; |
| 1973 | }; |
| 1974 | |
| 1975 | class AudioPolicyManagerTestMMapPlaybackRerouting |
| 1976 | : public AudioPolicyManagerTestDynamicPolicy, |
| 1977 | public ::testing::WithParamInterface<DPMmapTestParam> { |
| 1978 | protected: |
| 1979 | void SetUp() override { |
| 1980 | AudioPolicyManagerTestDynamicPolicy::SetUp(); |
| 1981 | audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 1982 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 1983 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 1984 | audioConfig.sample_rate = k48000SamplingRate; |
| 1985 | } |
| 1986 | |
| 1987 | audio_config_t audioConfig; |
| 1988 | audio_io_handle_t mOutput; |
| 1989 | audio_stream_type_t mStream = AUDIO_STREAM_DEFAULT; |
| 1990 | audio_port_handle_t mSelectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
Jan Sebechlebsky | b3d3f62 | 2023-07-13 11:09:15 +0200 | [diff] [blame] | 1991 | audio_port_handle_t mPortId = AUDIO_PORT_HANDLE_NONE; |
Jan Sebechlebsky | 8e10cea | 2023-03-29 11:43:31 +0200 | [diff] [blame] | 1992 | AudioPolicyInterface::output_type_t mOutputType; |
| 1993 | audio_attributes_t attr = AUDIO_ATTRIBUTES_INITIALIZER; |
| 1994 | bool mIsSpatialized; |
| 1995 | bool mIsBitPerfect; |
| 1996 | }; |
| 1997 | |
Jan Sebechlebsky | 370abec | 2023-06-15 10:18:30 +0200 | [diff] [blame] | 1998 | TEST_P(AudioPolicyManagerTestMMapPlaybackRerouting, MmapPlaybackStreamMatchingLoopbackDapMixFails) { |
Jan Sebechlebsky | 8e10cea | 2023-03-29 11:43:31 +0200 | [diff] [blame] | 1999 | // Add mix matching the test uid. |
| 2000 | const int testUid = 12345; |
| 2001 | const auto param = GetParam(); |
jiabin | 24ff57a | 2023-11-27 21:06:51 +0000 | [diff] [blame] | 2002 | ASSERT_NO_FATAL_FAILURE( |
| 2003 | addPolicyMixAndStartInputForLoopback(MIX_TYPE_PLAYERS, param.mixRouteFlags, |
| 2004 | param.deviceType, param.deviceAddress, audioConfig, |
| 2005 | {createUidCriterion(testUid)})); |
Jan Sebechlebsky | 8e10cea | 2023-03-29 11:43:31 +0200 | [diff] [blame] | 2006 | |
jiabin | 24ff57a | 2023-11-27 21:06:51 +0000 | [diff] [blame] | 2007 | // Getting output for matching uid and mmap-ed stream should fail. |
| 2008 | audio_output_flags_t outputFlags = |
| 2009 | (audio_output_flags_t) (AUDIO_OUTPUT_FLAG_MMAP_NOIRQ | AUDIO_OUTPUT_FLAG_DIRECT); |
Jan Sebechlebsky | 8e10cea | 2023-03-29 11:43:31 +0200 | [diff] [blame] | 2010 | ASSERT_EQ(INVALID_OPERATION, |
| 2011 | mManager->getOutputForAttr(&attr, &mOutput, AUDIO_SESSION_NONE, &mStream, |
| 2012 | createAttributionSourceState(testUid), &audioConfig, |
| 2013 | &outputFlags, &mSelectedDeviceId, &mPortId, {}, |
| 2014 | &mOutputType, &mIsSpatialized, &mIsBitPerfect)); |
| 2015 | } |
| 2016 | |
Jan Sebechlebsky | 370abec | 2023-06-15 10:18:30 +0200 | [diff] [blame] | 2017 | TEST_P(AudioPolicyManagerTestMMapPlaybackRerouting, |
| 2018 | NonMmapPlaybackStreamMatchingLoopbackDapMixSucceeds) { |
Jan Sebechlebsky | 8e10cea | 2023-03-29 11:43:31 +0200 | [diff] [blame] | 2019 | // Add mix matching the test uid. |
| 2020 | const int testUid = 12345; |
| 2021 | const auto param = GetParam(); |
jiabin | 24ff57a | 2023-11-27 21:06:51 +0000 | [diff] [blame] | 2022 | ASSERT_NO_FATAL_FAILURE( |
| 2023 | addPolicyMixAndStartInputForLoopback(MIX_TYPE_PLAYERS, param.mixRouteFlags, |
| 2024 | param.deviceType,param.deviceAddress, audioConfig, |
| 2025 | {createUidCriterion(testUid)})); |
Jan Sebechlebsky | 8e10cea | 2023-03-29 11:43:31 +0200 | [diff] [blame] | 2026 | |
jiabin | 24ff57a | 2023-11-27 21:06:51 +0000 | [diff] [blame] | 2027 | // Getting output for matching uid should succeed for non-mmaped stream. |
Jan Sebechlebsky | 8e10cea | 2023-03-29 11:43:31 +0200 | [diff] [blame] | 2028 | audio_output_flags_t outputFlags = AUDIO_OUTPUT_FLAG_NONE; |
| 2029 | ASSERT_EQ(NO_ERROR, |
| 2030 | mManager->getOutputForAttr(&attr, &mOutput, AUDIO_SESSION_NONE, &mStream, |
| 2031 | createAttributionSourceState(testUid), &audioConfig, |
| 2032 | &outputFlags, &mSelectedDeviceId, &mPortId, {}, |
| 2033 | &mOutputType, &mIsSpatialized, &mIsBitPerfect)); |
| 2034 | } |
| 2035 | |
Jan Sebechlebsky | 370abec | 2023-06-15 10:18:30 +0200 | [diff] [blame] | 2036 | TEST_F(AudioPolicyManagerTestMMapPlaybackRerouting, |
Jan Sebechlebsky | 697f5d9 | 2023-08-04 11:15:00 +0200 | [diff] [blame] | 2037 | MmapPlaybackStreamMatchingRenderDapMixSupportingMmapSucceeds) { |
jiabin | 24ff57a | 2023-11-27 21:06:51 +0000 | [diff] [blame] | 2038 | const std::string usbAddress = "card=1;device=0"; |
| 2039 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 2040 | AUDIO_DEVICE_OUT_USB_DEVICE, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 2041 | usbAddress.c_str(), "", AUDIO_FORMAT_DEFAULT)); |
| 2042 | audio_port_v7 usbDevicePort; |
| 2043 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SINK, AUDIO_DEVICE_OUT_USB_DEVICE, |
| 2044 | usbAddress, &usbDevicePort)); |
| 2045 | |
Jan Sebechlebsky | 697f5d9 | 2023-08-04 11:15:00 +0200 | [diff] [blame] | 2046 | // Add render-only mix matching the test uid. |
Jan Sebechlebsky | 370abec | 2023-06-15 10:18:30 +0200 | [diff] [blame] | 2047 | const int testUid = 12345; |
Jan Sebechlebsky | 697f5d9 | 2023-08-04 11:15:00 +0200 | [diff] [blame] | 2048 | // test_audio_policy_configuration.xml declares mmap-capable mix port |
| 2049 | // for AUDIO_DEVICE_OUT_USB_DEVICE. |
jiabin | 24ff57a | 2023-11-27 21:06:51 +0000 | [diff] [blame] | 2050 | ASSERT_EQ(NO_ERROR, |
| 2051 | addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2052 | AUDIO_DEVICE_OUT_USB_DEVICE, /*mixAddress=*/"", |
| 2053 | audioConfig, {createUidCriterion(testUid)})); |
Jan Sebechlebsky | 370abec | 2023-06-15 10:18:30 +0200 | [diff] [blame] | 2054 | |
jiabin | 24ff57a | 2023-11-27 21:06:51 +0000 | [diff] [blame] | 2055 | static const audio_output_flags_t mmapDirectFlags = |
| 2056 | (audio_output_flags_t) (AUDIO_OUTPUT_FLAG_MMAP_NOIRQ | AUDIO_OUTPUT_FLAG_DIRECT); |
| 2057 | // Getting output for matching uid should succeed for mmaped stream, because matched mix |
Jan Sebechlebsky | 697f5d9 | 2023-08-04 11:15:00 +0200 | [diff] [blame] | 2058 | // redirects to mmap capable device. |
jiabin | 24ff57a | 2023-11-27 21:06:51 +0000 | [diff] [blame] | 2059 | audio_output_flags_t outputFlags = mmapDirectFlags; |
Jan Sebechlebsky | 370abec | 2023-06-15 10:18:30 +0200 | [diff] [blame] | 2060 | ASSERT_EQ(NO_ERROR, |
| 2061 | mManager->getOutputForAttr(&attr, &mOutput, AUDIO_SESSION_NONE, &mStream, |
| 2062 | createAttributionSourceState(testUid), &audioConfig, |
| 2063 | &outputFlags, &mSelectedDeviceId, &mPortId, {}, |
| 2064 | &mOutputType, &mIsSpatialized, &mIsBitPerfect)); |
jiabin | 24ff57a | 2023-11-27 21:06:51 +0000 | [diff] [blame] | 2065 | ASSERT_EQ(usbDevicePort.id, mSelectedDeviceId); |
| 2066 | auto outputDesc = mManager->getOutputs().valueFor(mOutput); |
| 2067 | ASSERT_NE(nullptr, outputDesc); |
| 2068 | ASSERT_EQ(mmapDirectFlags, outputDesc->getFlags().output); |
| 2069 | |
| 2070 | // After releasing the client, the output is closed. APM should reselect output for the policy |
| 2071 | // mix. |
| 2072 | mManager->releaseOutput(mPortId); |
| 2073 | ASSERT_EQ(nullptr, mManager->getOutputs().valueFor(mOutput)); |
| 2074 | outputFlags = AUDIO_OUTPUT_FLAG_NONE; |
| 2075 | mPortId = AUDIO_PORT_HANDLE_NONE; |
| 2076 | ASSERT_EQ(NO_ERROR, |
| 2077 | mManager->getOutputForAttr(&attr, &mOutput, AUDIO_SESSION_NONE, &mStream, |
| 2078 | createAttributionSourceState(testUid), &audioConfig, |
| 2079 | &outputFlags, &mSelectedDeviceId, &mPortId, {}, |
| 2080 | &mOutputType, &mIsSpatialized, &mIsBitPerfect)); |
| 2081 | ASSERT_EQ(usbDevicePort.id, mSelectedDeviceId); |
| 2082 | outputDesc = mManager->getOutputs().valueFor(mOutput); |
| 2083 | ASSERT_NE(nullptr, outputDesc); |
| 2084 | ASSERT_NE(mmapDirectFlags, outputDesc->getFlags().output); |
| 2085 | |
| 2086 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 2087 | AUDIO_DEVICE_OUT_USB_DEVICE, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 2088 | usbAddress.c_str(), "", AUDIO_FORMAT_DEFAULT)); |
Jan Sebechlebsky | 370abec | 2023-06-15 10:18:30 +0200 | [diff] [blame] | 2089 | } |
| 2090 | |
Jan Sebechlebsky | 697f5d9 | 2023-08-04 11:15:00 +0200 | [diff] [blame] | 2091 | TEST_F(AudioPolicyManagerTestMMapPlaybackRerouting, |
| 2092 | MmapPlaybackStreamMatchingRenderDapMixNotSupportingMmapFails) { |
| 2093 | // Add render-only mix matching the test uid. |
| 2094 | const int testUid = 12345; |
| 2095 | // Per test_audio_policy_configuration.xml AUDIO_DEVICE_OUT_SPEAKER doesn't support mmap. |
jiabin | 24ff57a | 2023-11-27 21:06:51 +0000 | [diff] [blame] | 2096 | ASSERT_EQ(NO_ERROR, |
| 2097 | addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2098 | AUDIO_DEVICE_OUT_SPEAKER, /*mixAddress=*/"", audioConfig, |
| 2099 | {createUidCriterion(testUid)})); |
Jan Sebechlebsky | 697f5d9 | 2023-08-04 11:15:00 +0200 | [diff] [blame] | 2100 | |
jiabin | 24ff57a | 2023-11-27 21:06:51 +0000 | [diff] [blame] | 2101 | // Getting output for matching uid should fail for mmaped stream, because |
Jan Sebechlebsky | 697f5d9 | 2023-08-04 11:15:00 +0200 | [diff] [blame] | 2102 | // matched mix redirects to device which doesn't support mmap. |
jiabin | 24ff57a | 2023-11-27 21:06:51 +0000 | [diff] [blame] | 2103 | audio_output_flags_t outputFlags = |
| 2104 | (audio_output_flags_t) (AUDIO_OUTPUT_FLAG_MMAP_NOIRQ | AUDIO_OUTPUT_FLAG_DIRECT); |
Jan Sebechlebsky | 697f5d9 | 2023-08-04 11:15:00 +0200 | [diff] [blame] | 2105 | ASSERT_EQ(INVALID_OPERATION, |
| 2106 | mManager->getOutputForAttr(&attr, &mOutput, AUDIO_SESSION_NONE, &mStream, |
| 2107 | createAttributionSourceState(testUid), &audioConfig, |
| 2108 | &outputFlags, &mSelectedDeviceId, &mPortId, {}, |
| 2109 | &mOutputType, &mIsSpatialized, &mIsBitPerfect)); |
| 2110 | } |
| 2111 | |
Jan Sebechlebsky | 8e10cea | 2023-03-29 11:43:31 +0200 | [diff] [blame] | 2112 | INSTANTIATE_TEST_SUITE_P( |
| 2113 | MmapPlaybackRerouting, AudioPolicyManagerTestMMapPlaybackRerouting, |
| 2114 | testing::Values(DPMmapTestParam(MIX_ROUTE_FLAG_LOOP_BACK, AUDIO_DEVICE_OUT_REMOTE_SUBMIX, |
| 2115 | /*deviceAddress=*/"remote_submix_media"), |
| 2116 | DPMmapTestParam(MIX_ROUTE_FLAG_LOOP_BACK_AND_RENDER, |
| 2117 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, |
jiabin | 1ca6c6f | 2023-09-22 17:25:59 +0000 | [diff] [blame] | 2118 | /*deviceAddress=*/"remote_submix_media"), |
| 2119 | DPMmapTestParam(MIX_ROUTE_FLAG_RENDER, AUDIO_DEVICE_OUT_SPEAKER, |
| 2120 | /*deviceAddress=*/""))); |
Jan Sebechlebsky | 8e10cea | 2023-03-29 11:43:31 +0200 | [diff] [blame] | 2121 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 2122 | class AudioPolicyManagerTestDPMixRecordInjection : public AudioPolicyManagerTestDynamicPolicy, |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 2123 | public testing::WithParamInterface<DPTestParam> { |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 2124 | protected: |
| 2125 | void SetUp() override; |
| 2126 | void TearDown() override; |
| 2127 | |
| 2128 | std::unique_ptr<RecordingActivityTracker> mTracker; |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 2129 | struct audio_port_v7 mExtractionPort; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 2130 | audio_port_handle_t mPortId = AUDIO_PORT_HANDLE_NONE; |
| 2131 | }; |
| 2132 | |
| 2133 | void AudioPolicyManagerTestDPMixRecordInjection::SetUp() { |
Mikhail Naganov | d4c21aa | 2021-10-05 15:10:16 -0700 | [diff] [blame] | 2134 | ASSERT_NO_FATAL_FAILURE(AudioPolicyManagerTestDynamicPolicy::SetUp()); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 2135 | |
| 2136 | mTracker.reset(new RecordingActivityTracker()); |
| 2137 | |
| 2138 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 2139 | audioConfig.channel_mask = AUDIO_CHANNEL_IN_STEREO; |
| 2140 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 2141 | audioConfig.sample_rate = k48000SamplingRate; |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 2142 | |
| 2143 | DPTestParam param = GetParam(); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 2144 | status_t ret = addPolicyMix(MIX_TYPE_RECORDERS, MIX_ROUTE_FLAG_LOOP_BACK, |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 2145 | AUDIO_DEVICE_IN_REMOTE_SUBMIX, mMixAddress, audioConfig, param.mixCriteria); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 2146 | ASSERT_EQ(NO_ERROR, ret); |
| 2147 | |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 2148 | struct audio_port_v7 injectionPort; |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 2149 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SINK, AUDIO_DEVICE_OUT_REMOTE_SUBMIX, |
| 2150 | mMixAddress, &injectionPort)); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 2151 | |
| 2152 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 2153 | audio_usage_t usage = AUDIO_USAGE_VIRTUAL_SOURCE; |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 2154 | audio_attributes_t attr = |
| 2155 | {AUDIO_CONTENT_TYPE_UNKNOWN, usage, AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 2156 | std::string tags = std::string("addr=") + mMixAddress; |
| 2157 | strncpy(attr.tags, tags.c_str(), AUDIO_ATTRIBUTES_TAGS_MAX_SIZE - 1); |
| 2158 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 2159 | k48000SamplingRate, AUDIO_OUTPUT_FLAG_NONE, nullptr /*output*/, &mPortId, attr); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 2160 | ASSERT_EQ(NO_ERROR, mManager->startOutput(mPortId)); |
| 2161 | ASSERT_EQ(injectionPort.id, getDeviceIdFromPatch(mClient->getLastAddedPatch())); |
| 2162 | |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 2163 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SOURCE, AUDIO_DEVICE_IN_REMOTE_SUBMIX, |
| 2164 | mMixAddress, &mExtractionPort)); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 2165 | } |
| 2166 | |
| 2167 | void AudioPolicyManagerTestDPMixRecordInjection::TearDown() { |
| 2168 | mManager->stopOutput(mPortId); |
| 2169 | AudioPolicyManagerTestDynamicPolicy::TearDown(); |
| 2170 | } |
| 2171 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 2172 | TEST_P(AudioPolicyManagerTestDPMixRecordInjection, RecordingInjection) { |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 2173 | const DPTestParam param = GetParam(); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 2174 | |
jiabin | 7c0205e | 2019-09-05 10:26:04 -0700 | [diff] [blame] | 2175 | audio_port_handle_t captureRoutedPortId = AUDIO_PORT_HANDLE_NONE; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 2176 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE; |
François Gaffie | 6ebbce0 | 2023-07-19 13:27:53 +0200 | [diff] [blame] | 2177 | audio_io_handle_t input = AUDIO_PORT_HANDLE_NONE; |
| 2178 | getInputForAttr(param.attributes, &input, param.session, mTracker->getRiid(), |
| 2179 | &captureRoutedPortId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_STEREO, |
| 2180 | k48000SamplingRate, AUDIO_INPUT_FLAG_NONE, &portId); |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 2181 | if (param.expected_match) { |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 2182 | EXPECT_EQ(mExtractionPort.id, captureRoutedPortId); |
| 2183 | } else { |
| 2184 | EXPECT_NE(mExtractionPort.id, captureRoutedPortId); |
| 2185 | } |
| 2186 | } |
| 2187 | |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 2188 | const std::vector<AudioMixMatchCriterion> SOURCE_CAM_MIC_VOICE_CRITERIA = { |
| 2189 | createCapturePresetCriterion(AUDIO_SOURCE_CAMCORDER), |
| 2190 | createCapturePresetCriterion(AUDIO_SOURCE_MIC), |
| 2191 | createCapturePresetCriterion(AUDIO_SOURCE_VOICE_COMMUNICATION) |
| 2192 | }; |
| 2193 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 2194 | // No address priority rule for remote recording, address is a "don't care" |
| 2195 | INSTANTIATE_TEST_CASE_P( |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 2196 | RecordInjectionSource, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 2197 | AudioPolicyManagerTestDPMixRecordInjection, |
| 2198 | testing::Values( |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 2199 | DPTestParam(SOURCE_CAM_MIC_VOICE_CRITERIA, /*expected_match=*/ true) |
| 2200 | .withSource(AUDIO_SOURCE_CAMCORDER), |
| 2201 | DPTestParam(SOURCE_CAM_MIC_VOICE_CRITERIA, /*expected_match=*/ true) |
| 2202 | .withSource(AUDIO_SOURCE_CAMCORDER) |
| 2203 | .withTags("addr=remote_submix_media"), |
| 2204 | DPTestParam(SOURCE_CAM_MIC_VOICE_CRITERIA, /*expected_match=*/ true) |
| 2205 | .withSource(AUDIO_SOURCE_MIC), |
| 2206 | DPTestParam(SOURCE_CAM_MIC_VOICE_CRITERIA, /*expected_match=*/ true) |
| 2207 | .withSource(AUDIO_SOURCE_MIC) |
| 2208 | .withTags("addr=remote_submix_media"), |
| 2209 | DPTestParam(SOURCE_CAM_MIC_VOICE_CRITERIA, /*expected_match=*/ true) |
| 2210 | .withSource(AUDIO_SOURCE_VOICE_COMMUNICATION), |
| 2211 | DPTestParam(SOURCE_CAM_MIC_VOICE_CRITERIA, /*expected_match=*/ true) |
| 2212 | .withSource(AUDIO_SOURCE_VOICE_COMMUNICATION) |
| 2213 | .withTags("addr=remote_submix_media"), |
| 2214 | DPTestParam(SOURCE_CAM_MIC_VOICE_CRITERIA, /*expected_match=*/ false) |
| 2215 | .withSource(AUDIO_SOURCE_VOICE_RECOGNITION), |
| 2216 | DPTestParam(SOURCE_CAM_MIC_VOICE_CRITERIA, /*expected_match=*/ false) |
| 2217 | .withSource(AUDIO_SOURCE_VOICE_RECOGNITION) |
| 2218 | .withTags("addr=remote_submix_media"), |
| 2219 | DPTestParam(SOURCE_CAM_MIC_VOICE_CRITERIA, /*expected_match=*/ false) |
| 2220 | .withSource(AUDIO_SOURCE_HOTWORD), |
| 2221 | DPTestParam(SOURCE_CAM_MIC_VOICE_CRITERIA, /*expected_match=*/ false) |
| 2222 | .withSource(AUDIO_SOURCE_HOTWORD) |
| 2223 | .withTags("addr=remote_submix_media"))); |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 2224 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 2225 | INSTANTIATE_TEST_CASE_P( |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 2226 | RecordInjectionWithSessionId, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 2227 | AudioPolicyManagerTestDPMixRecordInjection, |
| 2228 | testing::Values( |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 2229 | // Mix is matched because the session id matches the one specified by the mix rule. |
| 2230 | DPTestParam(/*mixCriteria=*/ {createSessionIdCriterion(TEST_SESSION_ID)}, |
| 2231 | /*expected_match=*/ true) |
| 2232 | .withSessionId(TEST_SESSION_ID), |
| 2233 | // Mix is not matched because the session id doesn't match the one specified |
| 2234 | // by the mix rule. |
| 2235 | DPTestParam(/*mixCriteria=*/ {createSessionIdCriterion(TEST_SESSION_ID)}, |
| 2236 | /*expected_match=*/ false) |
| 2237 | .withSessionId(OTHER_SESSION_ID), |
| 2238 | // Mix is not matched, the session id doesn't match the one specified by rule, |
| 2239 | // but tand address specified in the tags is ignored for recorder mix. |
| 2240 | DPTestParam(/*mixCriteria=*/ {createSessionIdCriterion(TEST_SESSION_ID)}, |
| 2241 | /*expected_match=*/ false) |
| 2242 | .withSessionId(OTHER_SESSION_ID).withTags("addr=remote_submix_media"), |
| 2243 | // Mix is matched, both the session id and the source match ones specified by mix rule |
| 2244 | DPTestParam(/*mixCriteria=*/ {createSessionIdCriterion(TEST_SESSION_ID), |
| 2245 | createCapturePresetCriterion(AUDIO_SOURCE_CAMCORDER)}, |
| 2246 | /*expected_match=*/ true) |
| 2247 | .withSessionId(TEST_SESSION_ID).withSource(AUDIO_SOURCE_CAMCORDER), |
| 2248 | // Mix is not matched, the session id matches the one specified by mix rule, |
| 2249 | // but source does not. |
| 2250 | DPTestParam(/*mixCriteria=*/ {createSessionIdCriterion(TEST_SESSION_ID), |
| 2251 | createCapturePresetCriterion(AUDIO_SOURCE_CAMCORDER)}, |
| 2252 | /*expected_match=*/ false) |
| 2253 | .withSessionId(TEST_SESSION_ID).withSource(AUDIO_SOURCE_MIC), |
| 2254 | // Mix is not matched, the source matches the one specified by mix rule, |
| 2255 | // but the session id is excluded. |
| 2256 | DPTestParam(/*mixCriteria=*/ {createSessionIdCriterion(TEST_SESSION_ID, |
| 2257 | /*exclude=*/ true), |
| 2258 | createCapturePresetCriterion(AUDIO_SOURCE_MIC)}, |
| 2259 | /*expected_match=*/ false) |
| 2260 | .withSessionId(TEST_SESSION_ID).withSource(AUDIO_SOURCE_MIC))); |
jiabin | 43848a5 | 2019-09-05 14:07:25 -0700 | [diff] [blame] | 2261 | |
| 2262 | using DeviceConnectionTestParams = |
| 2263 | std::tuple<audio_devices_t /*type*/, std::string /*name*/, std::string /*address*/>; |
| 2264 | |
| 2265 | class AudioPolicyManagerTestDeviceConnection : public AudioPolicyManagerTestWithConfigurationFile, |
| 2266 | public testing::WithParamInterface<DeviceConnectionTestParams> { |
| 2267 | }; |
| 2268 | |
| 2269 | TEST_F(AudioPolicyManagerTestDeviceConnection, InitSuccess) { |
| 2270 | // SetUp must finish with no assertions. |
| 2271 | } |
| 2272 | |
| 2273 | TEST_F(AudioPolicyManagerTestDeviceConnection, Dump) { |
| 2274 | dumpToLog(); |
| 2275 | } |
| 2276 | |
Jean-Michel Trivi | 9a6b9ad | 2020-10-22 16:46:43 -0700 | [diff] [blame] | 2277 | TEST_F(AudioPolicyManagerTestDeviceConnection, RoutingUpdate) { |
| 2278 | mClient->resetRoutingUpdatedCounter(); |
| 2279 | // Connecting a valid output device with valid parameters should trigger a routing update |
| 2280 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 2281 | AUDIO_DEVICE_OUT_BLUETOOTH_SCO, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
Mikhail Naganov | b1ddbb0 | 2023-03-15 17:06:59 -0700 | [diff] [blame] | 2282 | "00:11:22:33:44:55", "b", AUDIO_FORMAT_DEFAULT)); |
Jean-Michel Trivi | 9a6b9ad | 2020-10-22 16:46:43 -0700 | [diff] [blame] | 2283 | ASSERT_EQ(1, mClient->getRoutingUpdatedCounter()); |
| 2284 | |
| 2285 | // Disconnecting a connected device should succeed and trigger a routing update |
| 2286 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 2287 | AUDIO_DEVICE_OUT_BLUETOOTH_SCO, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
Mikhail Naganov | b1ddbb0 | 2023-03-15 17:06:59 -0700 | [diff] [blame] | 2288 | "00:11:22:33:44:55", "b", AUDIO_FORMAT_DEFAULT)); |
Jean-Michel Trivi | 9a6b9ad | 2020-10-22 16:46:43 -0700 | [diff] [blame] | 2289 | ASSERT_EQ(2, mClient->getRoutingUpdatedCounter()); |
| 2290 | |
| 2291 | // Disconnecting a disconnected device should fail and not trigger a routing update |
| 2292 | ASSERT_EQ(INVALID_OPERATION, mManager->setDeviceConnectionState( |
| 2293 | AUDIO_DEVICE_OUT_BLUETOOTH_SCO, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
Mikhail Naganov | b1ddbb0 | 2023-03-15 17:06:59 -0700 | [diff] [blame] | 2294 | "00:11:22:33:44:55", "b", AUDIO_FORMAT_DEFAULT)); |
Jean-Michel Trivi | 9a6b9ad | 2020-10-22 16:46:43 -0700 | [diff] [blame] | 2295 | ASSERT_EQ(2, mClient->getRoutingUpdatedCounter()); |
| 2296 | |
| 2297 | // Changing force use should trigger an update |
| 2298 | auto config = mManager->getForceUse(AUDIO_POLICY_FORCE_FOR_MEDIA); |
| 2299 | auto newConfig = config == AUDIO_POLICY_FORCE_BT_A2DP ? |
| 2300 | AUDIO_POLICY_FORCE_NONE : AUDIO_POLICY_FORCE_BT_A2DP; |
| 2301 | mManager->setForceUse(AUDIO_POLICY_FORCE_FOR_MEDIA, newConfig); |
| 2302 | ASSERT_EQ(3, mClient->getRoutingUpdatedCounter()); |
| 2303 | } |
| 2304 | |
jiabin | 43848a5 | 2019-09-05 14:07:25 -0700 | [diff] [blame] | 2305 | TEST_P(AudioPolicyManagerTestDeviceConnection, SetDeviceConnectionState) { |
| 2306 | const audio_devices_t type = std::get<0>(GetParam()); |
| 2307 | const std::string name = std::get<1>(GetParam()); |
| 2308 | const std::string address = std::get<2>(GetParam()); |
| 2309 | |
| 2310 | if (type == AUDIO_DEVICE_OUT_HDMI) { |
| 2311 | // Set device connection state failed due to no device descriptor found |
| 2312 | // 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] | 2313 | // by using an encoded format which isn't listed in the 'encodedFormats' |
| 2314 | // attribute for this devicePort. |
jiabin | 43848a5 | 2019-09-05 14:07:25 -0700 | [diff] [blame] | 2315 | ASSERT_EQ(INVALID_OPERATION, mManager->setDeviceConnectionState( |
| 2316 | type, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 2317 | address.c_str(), name.c_str(), AUDIO_FORMAT_MAT_2_1)); |
| 2318 | } |
| 2319 | // Connect with valid parameters should succeed |
| 2320 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 2321 | type, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 2322 | address.c_str(), name.c_str(), AUDIO_FORMAT_DEFAULT)); |
| 2323 | // Try to connect with the same device again should fail |
| 2324 | ASSERT_EQ(INVALID_OPERATION, mManager->setDeviceConnectionState( |
| 2325 | type, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 2326 | address.c_str(), name.c_str(), AUDIO_FORMAT_DEFAULT)); |
| 2327 | // Disconnect the connected device should succeed |
| 2328 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 2329 | type, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 2330 | address.c_str(), name.c_str(), AUDIO_FORMAT_DEFAULT)); |
| 2331 | // Disconnect device that is not connected should fail |
| 2332 | ASSERT_EQ(INVALID_OPERATION, mManager->setDeviceConnectionState( |
| 2333 | type, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 2334 | address.c_str(), name.c_str(), AUDIO_FORMAT_DEFAULT)); |
| 2335 | // Try to set device connection state with a invalid connection state should fail |
| 2336 | ASSERT_EQ(BAD_VALUE, mManager->setDeviceConnectionState( |
| 2337 | type, AUDIO_POLICY_DEVICE_STATE_CNT, |
| 2338 | "", "", AUDIO_FORMAT_DEFAULT)); |
| 2339 | } |
| 2340 | |
| 2341 | TEST_P(AudioPolicyManagerTestDeviceConnection, ExplicitlyRoutingAfterConnection) { |
| 2342 | const audio_devices_t type = std::get<0>(GetParam()); |
| 2343 | const std::string name = std::get<1>(GetParam()); |
| 2344 | const std::string address = std::get<2>(GetParam()); |
| 2345 | |
| 2346 | // Connect device to do explicitly routing test |
| 2347 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 2348 | type, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 2349 | address.c_str(), name.c_str(), AUDIO_FORMAT_DEFAULT)); |
| 2350 | |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 2351 | audio_port_v7 devicePort; |
jiabin | 43848a5 | 2019-09-05 14:07:25 -0700 | [diff] [blame] | 2352 | const audio_port_role_t role = audio_is_output_device(type) |
| 2353 | ? AUDIO_PORT_ROLE_SINK : AUDIO_PORT_ROLE_SOURCE; |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 2354 | ASSERT_TRUE(findDevicePort(role, type, address, &devicePort)); |
jiabin | 43848a5 | 2019-09-05 14:07:25 -0700 | [diff] [blame] | 2355 | |
| 2356 | audio_port_handle_t routedPortId = devicePort.id; |
jiabin | 43848a5 | 2019-09-05 14:07:25 -0700 | [diff] [blame] | 2357 | // Try start input or output according to the device type |
| 2358 | if (audio_is_output_devices(type)) { |
| 2359 | getOutputForAttr(&routedPortId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 2360 | k48000SamplingRate, AUDIO_OUTPUT_FLAG_NONE); |
jiabin | 43848a5 | 2019-09-05 14:07:25 -0700 | [diff] [blame] | 2361 | } else if (audio_is_input_device(type)) { |
| 2362 | RecordingActivityTracker tracker; |
François Gaffie | 6ebbce0 | 2023-07-19 13:27:53 +0200 | [diff] [blame] | 2363 | audio_io_handle_t input = AUDIO_PORT_HANDLE_NONE; |
| 2364 | getInputForAttr({}, &input, AUDIO_SESSION_NONE, tracker.getRiid(), &routedPortId, |
| 2365 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_STEREO, k48000SamplingRate, |
| 2366 | AUDIO_INPUT_FLAG_NONE); |
jiabin | 43848a5 | 2019-09-05 14:07:25 -0700 | [diff] [blame] | 2367 | } |
| 2368 | ASSERT_EQ(devicePort.id, routedPortId); |
| 2369 | |
| 2370 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 2371 | type, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 2372 | address.c_str(), name.c_str(), AUDIO_FORMAT_DEFAULT)); |
| 2373 | } |
| 2374 | |
Mikhail Naganov | ddc5f31 | 2022-06-11 00:47:52 +0000 | [diff] [blame] | 2375 | android::media::audio::common::ExtraAudioDescriptor make_ExtraAudioDescriptor( |
| 2376 | android::media::audio::common::AudioStandard audioStandard, |
| 2377 | android::media::audio::common::AudioEncapsulationType audioEncapsulationType) { |
| 2378 | android::media::audio::common::ExtraAudioDescriptor result; |
| 2379 | result.standard = audioStandard; |
| 2380 | result.audioDescriptor = {0xb4, 0xaf, 0x98, 0x1a}; |
| 2381 | result.encapsulationType = audioEncapsulationType; |
| 2382 | return result; |
| 2383 | } |
| 2384 | |
| 2385 | TEST_P(AudioPolicyManagerTestDeviceConnection, PassingExtraAudioDescriptors) { |
| 2386 | const audio_devices_t type = std::get<0>(GetParam()); |
| 2387 | if (!audio_device_is_digital(type)) { |
| 2388 | // EADs are used only for HDMI devices. |
| 2389 | GTEST_SKIP() << "Not a digital device type: " << audio_device_to_string(type); |
| 2390 | } |
| 2391 | const std::string name = std::get<1>(GetParam()); |
| 2392 | const std::string address = std::get<2>(GetParam()); |
Atneya Nair | 638a6e4 | 2022-12-18 16:45:15 -0800 | [diff] [blame] | 2393 | android::media::AudioPortFw audioPort; |
Mikhail Naganov | ddc5f31 | 2022-06-11 00:47:52 +0000 | [diff] [blame] | 2394 | ASSERT_EQ(NO_ERROR, |
| 2395 | mManager->deviceToAudioPort(type, address.c_str(), name.c_str(), &audioPort)); |
| 2396 | android::media::audio::common::AudioPort& port = audioPort.hal; |
| 2397 | port.extraAudioDescriptors.push_back(make_ExtraAudioDescriptor( |
| 2398 | android::media::audio::common::AudioStandard::EDID, |
| 2399 | android::media::audio::common::AudioEncapsulationType::IEC61937)); |
| 2400 | const size_t lastConnectedDevicePortCount = mClient->getConnectedDevicePortCount(); |
| 2401 | const size_t lastDisconnectedDevicePortCount = mClient->getDisconnectedDevicePortCount(); |
| 2402 | EXPECT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 2403 | AUDIO_POLICY_DEVICE_STATE_AVAILABLE, port, AUDIO_FORMAT_DEFAULT)); |
| 2404 | EXPECT_EQ(lastConnectedDevicePortCount + 1, mClient->getConnectedDevicePortCount()); |
| 2405 | EXPECT_EQ(lastDisconnectedDevicePortCount, mClient->getDisconnectedDevicePortCount()); |
| 2406 | const audio_port_v7* devicePort = mClient->getLastConnectedDevicePort(); |
| 2407 | EXPECT_EQ(port.extraAudioDescriptors.size(), devicePort->num_extra_audio_descriptors); |
| 2408 | EXPECT_EQ(AUDIO_STANDARD_EDID, devicePort->extra_audio_descriptors[0].standard); |
| 2409 | EXPECT_EQ(AUDIO_ENCAPSULATION_TYPE_IEC61937, |
| 2410 | devicePort->extra_audio_descriptors[0].encapsulation_type); |
| 2411 | EXPECT_NE(0, devicePort->extra_audio_descriptors[0].descriptor[0]); |
| 2412 | } |
| 2413 | |
jiabin | 43848a5 | 2019-09-05 14:07:25 -0700 | [diff] [blame] | 2414 | INSTANTIATE_TEST_CASE_P( |
| 2415 | DeviceConnectionState, |
| 2416 | AudioPolicyManagerTestDeviceConnection, |
| 2417 | testing::Values( |
| 2418 | DeviceConnectionTestParams({AUDIO_DEVICE_IN_HDMI, "test_in_hdmi", |
| 2419 | "audio_policy_test_in_hdmi"}), |
| 2420 | DeviceConnectionTestParams({AUDIO_DEVICE_OUT_HDMI, "test_out_hdmi", |
| 2421 | "audio_policy_test_out_hdmi"}), |
| 2422 | DeviceConnectionTestParams({AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET, "bt_hfp_in", |
Mikhail Naganov | b1ddbb0 | 2023-03-15 17:06:59 -0700 | [diff] [blame] | 2423 | "00:11:22:33:44:55"}), |
jiabin | 43848a5 | 2019-09-05 14:07:25 -0700 | [diff] [blame] | 2424 | DeviceConnectionTestParams({AUDIO_DEVICE_OUT_BLUETOOTH_SCO, "bt_hfp_out", |
Mikhail Naganov | b1ddbb0 | 2023-03-15 17:06:59 -0700 | [diff] [blame] | 2425 | "00:11:22:33:44:55"}) |
jiabin | 43848a5 | 2019-09-05 14:07:25 -0700 | [diff] [blame] | 2426 | ) |
| 2427 | ); |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 2428 | |
Mikhail Naganov | 3754b64 | 2024-04-17 18:31:04 +0000 | [diff] [blame] | 2429 | namespace { |
| 2430 | |
| 2431 | class AudioPolicyManagerTestClientOpenFails : public AudioPolicyManagerTestClient { |
| 2432 | public: |
| 2433 | status_t openOutput(audio_module_handle_t module, |
| 2434 | audio_io_handle_t *output, |
| 2435 | audio_config_t * halConfig, |
| 2436 | audio_config_base_t * mixerConfig, |
| 2437 | const sp<DeviceDescriptorBase>& device, |
| 2438 | uint32_t * latencyMs, |
| 2439 | audio_output_flags_t flags) override { |
| 2440 | return mSimulateFailure ? BAD_VALUE : |
| 2441 | AudioPolicyManagerTestClient::openOutput( |
| 2442 | module, output, halConfig, mixerConfig, device, latencyMs, flags); |
| 2443 | } |
| 2444 | |
| 2445 | status_t openInput(audio_module_handle_t module, |
| 2446 | audio_io_handle_t *input, |
| 2447 | audio_config_t * config, |
| 2448 | audio_devices_t * device, |
| 2449 | const String8 & address, |
| 2450 | audio_source_t source, |
| 2451 | audio_input_flags_t flags) override { |
| 2452 | return mSimulateFailure ? BAD_VALUE : |
| 2453 | AudioPolicyManagerTestClient::openInput( |
| 2454 | module, input, config, device, address, source, flags); |
| 2455 | } |
| 2456 | |
| 2457 | void setSimulateFailure(bool simulateFailure) { mSimulateFailure = simulateFailure; } |
| 2458 | |
| 2459 | private: |
| 2460 | bool mSimulateFailure = false; |
| 2461 | }; |
| 2462 | |
| 2463 | } // namespace |
| 2464 | |
| 2465 | using DeviceConnectionWithFormatTestParams = |
| 2466 | std::tuple<audio_devices_t /*type*/, std::string /*name*/, std::string /*address*/, |
| 2467 | audio_format_t /*format*/>; |
| 2468 | |
| 2469 | class AudioPolicyManagerTestDeviceConnectionFailed : |
| 2470 | public AudioPolicyManagerTestWithConfigurationFile, |
| 2471 | public testing::WithParamInterface<DeviceConnectionWithFormatTestParams> { |
| 2472 | protected: |
| 2473 | std::string getConfigFile() override { return sBluetoothConfig; } |
| 2474 | AudioPolicyManagerTestClient* getClient() override { |
| 2475 | mFullClient = new AudioPolicyManagerTestClientOpenFails; |
| 2476 | return mFullClient; |
| 2477 | } |
| 2478 | void setSimulateOpenFailure(bool simulateFailure) { |
| 2479 | mFullClient->setSimulateFailure(simulateFailure); } |
| 2480 | |
| 2481 | static const std::string sBluetoothConfig; |
| 2482 | |
| 2483 | private: |
| 2484 | AudioPolicyManagerTestClientOpenFails* mFullClient; |
| 2485 | }; |
| 2486 | |
| 2487 | const std::string AudioPolicyManagerTestDeviceConnectionFailed::sBluetoothConfig = |
| 2488 | AudioPolicyManagerTestDeviceConnectionFailed::sExecutableDir + |
| 2489 | "test_audio_policy_configuration_bluetooth.xml"; |
| 2490 | |
| 2491 | TEST_P(AudioPolicyManagerTestDeviceConnectionFailed, SetDeviceConnectedStateHasAddress) { |
| 2492 | const audio_devices_t type = std::get<0>(GetParam()); |
| 2493 | const std::string name = std::get<1>(GetParam()); |
| 2494 | const std::string address = std::get<2>(GetParam()); |
| 2495 | const audio_format_t format = std::get<3>(GetParam()); |
| 2496 | |
| 2497 | EXPECT_EQ(0, mClient->getConnectedDevicePortCount()); |
| 2498 | EXPECT_EQ(0, mClient->getDisconnectedDevicePortCount()); |
| 2499 | |
| 2500 | setSimulateOpenFailure(true); |
| 2501 | ASSERT_EQ(INVALID_OPERATION, mManager->setDeviceConnectionState( |
| 2502 | type, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 2503 | address.c_str(), name.c_str(), format)); |
| 2504 | |
| 2505 | // Since the failure happens when opening input/output, the device must be connected |
| 2506 | // first and then disconnected. |
| 2507 | EXPECT_EQ(1, mClient->getConnectedDevicePortCount()); |
| 2508 | EXPECT_EQ(1, mClient->getDisconnectedDevicePortCount()); |
| 2509 | |
| 2510 | if (mClient->getConnectedDevicePortCount() > 0) { |
| 2511 | auto port = mClient->getLastConnectedDevicePort(); |
| 2512 | EXPECT_EQ(type, port->ext.device.type); |
| 2513 | EXPECT_EQ(0, strncmp(port->ext.device.address, address.c_str(), |
| 2514 | AUDIO_DEVICE_MAX_ADDRESS_LEN)) << "\"" << port->ext.device.address << "\""; |
| 2515 | } |
| 2516 | if (mClient->getDisconnectedDevicePortCount() > 0) { |
| 2517 | auto port = mClient->getLastDisconnectedDevicePort(); |
| 2518 | EXPECT_EQ(type, port->ext.device.type); |
| 2519 | EXPECT_EQ(0, strncmp(port->ext.device.address, address.c_str(), |
| 2520 | AUDIO_DEVICE_MAX_ADDRESS_LEN)) << "\"" << port->ext.device.address << "\""; |
| 2521 | } |
| 2522 | } |
| 2523 | |
| 2524 | INSTANTIATE_TEST_CASE_P( |
| 2525 | DeviceConnectionFailure, |
| 2526 | AudioPolicyManagerTestDeviceConnectionFailed, |
| 2527 | testing::Values( |
| 2528 | DeviceConnectionWithFormatTestParams({AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET, |
| 2529 | "bt_hfp_in", "00:11:22:33:44:55", AUDIO_FORMAT_DEFAULT}), |
| 2530 | DeviceConnectionWithFormatTestParams({AUDIO_DEVICE_OUT_BLUETOOTH_SCO, |
| 2531 | "bt_hfp_out", "00:11:22:33:44:55", AUDIO_FORMAT_DEFAULT}), |
| 2532 | DeviceConnectionWithFormatTestParams({AUDIO_DEVICE_OUT_BLUETOOTH_A2DP, |
| 2533 | "bt_a2dp_out", "00:11:22:33:44:55", AUDIO_FORMAT_DEFAULT}), |
| 2534 | DeviceConnectionWithFormatTestParams({AUDIO_DEVICE_OUT_BLUETOOTH_A2DP, |
| 2535 | "bt_a2dp_out", "00:11:22:33:44:66", AUDIO_FORMAT_LDAC}) |
| 2536 | ) |
| 2537 | ); |
| 2538 | |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 2539 | class AudioPolicyManagerCarTest : public AudioPolicyManagerTestDynamicPolicy { |
| 2540 | protected: |
| 2541 | std::string getConfigFile() override { return sCarConfig; } |
| 2542 | |
| 2543 | static const std::string sCarConfig; |
Oscar Azucena | 873d10f | 2023-01-12 18:34:42 -0800 | [diff] [blame] | 2544 | static const std::string sCarBusMediaOutput; |
| 2545 | static const std::string sCarBusNavigationOutput; |
Oscar Azucena | 4f49ef6 | 2023-01-25 23:32:13 -0800 | [diff] [blame] | 2546 | static const std::string sCarRearZoneOneOutput; |
| 2547 | static const std::string sCarRearZoneTwoOutput; |
jiabin | 24ff57a | 2023-11-27 21:06:51 +0000 | [diff] [blame] | 2548 | static const std::string sCarBusMmapOutput; |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 2549 | }; |
| 2550 | |
| 2551 | const std::string AudioPolicyManagerCarTest::sCarConfig = |
| 2552 | AudioPolicyManagerCarTest::sExecutableDir + "test_car_ap_atmos_offload_configuration.xml"; |
| 2553 | |
Oscar Azucena | 873d10f | 2023-01-12 18:34:42 -0800 | [diff] [blame] | 2554 | const std::string AudioPolicyManagerCarTest::sCarBusMediaOutput = "bus0_media_out"; |
| 2555 | |
| 2556 | const std::string AudioPolicyManagerCarTest::sCarBusNavigationOutput = "bus1_navigation_out"; |
| 2557 | |
Oscar Azucena | 4f49ef6 | 2023-01-25 23:32:13 -0800 | [diff] [blame] | 2558 | const std::string AudioPolicyManagerCarTest::sCarRearZoneOneOutput = "bus100_audio_zone_1"; |
| 2559 | |
| 2560 | const std::string AudioPolicyManagerCarTest::sCarRearZoneTwoOutput = "bus200_audio_zone_2"; |
| 2561 | |
jiabin | 24ff57a | 2023-11-27 21:06:51 +0000 | [diff] [blame] | 2562 | const std::string AudioPolicyManagerCarTest::sCarBusMmapOutput = "bus8_mmap_out"; |
| 2563 | |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 2564 | TEST_F(AudioPolicyManagerCarTest, InitSuccess) { |
| 2565 | // SetUp must finish with no assertions. |
| 2566 | } |
| 2567 | |
| 2568 | TEST_F(AudioPolicyManagerCarTest, Dump) { |
| 2569 | dumpToLog(); |
| 2570 | } |
| 2571 | |
Dean Wheatley | ecbf2ee | 2022-03-04 10:51:36 +1100 | [diff] [blame] | 2572 | TEST_F(AudioPolicyManagerCarTest, GetOutputForAttrAtmosOutputAfterRegisteringPolicyMix) { |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 2573 | status_t ret; |
| 2574 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 2575 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
Oscar Azucena | 873d10f | 2023-01-12 18:34:42 -0800 | [diff] [blame] | 2576 | AUDIO_DEVICE_OUT_BUS, sCarBusMediaOutput, audioConfig); |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 2577 | ASSERT_EQ(NO_ERROR, ret); |
| 2578 | |
| 2579 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 2580 | audio_io_handle_t output; |
| 2581 | audio_port_handle_t portId; |
| 2582 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_E_AC3_JOC, AUDIO_CHANNEL_OUT_5POINT1, |
| 2583 | k48000SamplingRate, AUDIO_OUTPUT_FLAG_DIRECT, &output, &portId); |
| 2584 | ASSERT_NE(AUDIO_PORT_HANDLE_NONE, selectedDeviceId); |
| 2585 | sp<SwAudioOutputDescriptor> outDesc = mManager->getOutputs().valueFor(output); |
| 2586 | ASSERT_NE(nullptr, outDesc.get()); |
| 2587 | ASSERT_EQ(AUDIO_FORMAT_E_AC3_JOC, outDesc->getFormat()); |
| 2588 | ASSERT_EQ(AUDIO_CHANNEL_OUT_5POINT1, outDesc->getChannelMask()); |
| 2589 | ASSERT_EQ(k48000SamplingRate, outDesc->getSamplingRate()); |
Dean Wheatley | ecbf2ee | 2022-03-04 10:51:36 +1100 | [diff] [blame] | 2590 | |
| 2591 | selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 2592 | output = AUDIO_IO_HANDLE_NONE; |
| 2593 | portId = AUDIO_PORT_HANDLE_NONE; |
| 2594 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_7POINT1POINT4, |
| 2595 | k48000SamplingRate, AUDIO_OUTPUT_FLAG_DIRECT, &output, &portId); |
| 2596 | ASSERT_NE(AUDIO_PORT_HANDLE_NONE, selectedDeviceId); |
| 2597 | outDesc = mManager->getOutputs().valueFor(output); |
| 2598 | ASSERT_NE(nullptr, outDesc.get()); |
| 2599 | ASSERT_EQ(AUDIO_FORMAT_PCM_16_BIT, outDesc->getFormat()); |
| 2600 | ASSERT_EQ(AUDIO_CHANNEL_OUT_7POINT1POINT4, outDesc->getChannelMask()); |
| 2601 | ASSERT_EQ(k48000SamplingRate, outDesc->getSamplingRate()); |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 2602 | } |
| 2603 | |
Oscar Azucena | 873d10f | 2023-01-12 18:34:42 -0800 | [diff] [blame] | 2604 | TEST_F(AudioPolicyManagerCarTest, GetOutputForAttrAfterRegisteringPolicyMix) { |
| 2605 | status_t ret; |
| 2606 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 2607 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 2608 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 2609 | audioConfig.sample_rate = k48000SamplingRate; |
| 2610 | std::vector<AudioMixMatchCriterion> mediaMatchCriteria = { |
| 2611 | createUsageCriterion(AUDIO_USAGE_MEDIA, /*exclude=*/ false)}; |
| 2612 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2613 | AUDIO_DEVICE_OUT_BUS, sCarBusMediaOutput, audioConfig, mediaMatchCriteria); |
| 2614 | ASSERT_EQ(NO_ERROR, ret); |
| 2615 | std::vector<AudioMixMatchCriterion> navMatchCriteria = { |
| 2616 | createUsageCriterion(AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE, |
| 2617 | /*exclude=*/ false)}; |
| 2618 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2619 | AUDIO_DEVICE_OUT_BUS, sCarBusNavigationOutput, audioConfig, navMatchCriteria); |
| 2620 | ASSERT_EQ(NO_ERROR, ret); |
| 2621 | audio_port_v7 mediaDevicePort; |
| 2622 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SINK, AUDIO_DEVICE_OUT_BUS, |
| 2623 | sCarBusMediaOutput, &mediaDevicePort)); |
| 2624 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 2625 | audio_io_handle_t output; |
| 2626 | audio_port_handle_t portId; |
| 2627 | const audio_attributes_t mediaAttribute = { |
| 2628 | AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_MEDIA, |
| 2629 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}; |
| 2630 | |
| 2631 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
| 2632 | k48000SamplingRate, AUDIO_OUTPUT_FLAG_DIRECT, &output, &portId, mediaAttribute); |
| 2633 | |
| 2634 | ASSERT_EQ(mediaDevicePort.id, selectedDeviceId); |
| 2635 | } |
| 2636 | |
| 2637 | TEST_F(AudioPolicyManagerCarTest, GetOutputForAttrWithSelectedOutputAfterRegisteringPolicyMix) { |
| 2638 | status_t ret; |
| 2639 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 2640 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 2641 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 2642 | audioConfig.sample_rate = k48000SamplingRate; |
| 2643 | std::vector<AudioMixMatchCriterion> mediaMatchCriteria = { |
| 2644 | createUsageCriterion(AUDIO_USAGE_MEDIA, /*exclude=*/ false)}; |
| 2645 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2646 | AUDIO_DEVICE_OUT_BUS, sCarBusMediaOutput, audioConfig, mediaMatchCriteria); |
| 2647 | ASSERT_EQ(NO_ERROR, ret); |
| 2648 | std::vector<AudioMixMatchCriterion> navMatchCriteria = { |
| 2649 | createUsageCriterion(AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE, |
| 2650 | /*exclude=*/ false)}; |
| 2651 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2652 | AUDIO_DEVICE_OUT_BUS, sCarBusNavigationOutput, audioConfig, navMatchCriteria); |
| 2653 | ASSERT_EQ(NO_ERROR, ret); |
| 2654 | audio_port_v7 navDevicePort; |
| 2655 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SINK, AUDIO_DEVICE_OUT_BUS, |
| 2656 | sCarBusNavigationOutput, &navDevicePort)); |
| 2657 | audio_port_handle_t selectedDeviceId = navDevicePort.id; |
| 2658 | audio_io_handle_t output; |
| 2659 | audio_port_handle_t portId; |
| 2660 | const audio_attributes_t mediaAttribute = { |
| 2661 | AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_MEDIA, |
| 2662 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}; |
| 2663 | |
| 2664 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
| 2665 | k48000SamplingRate, AUDIO_OUTPUT_FLAG_DIRECT, &output, &portId, mediaAttribute); |
| 2666 | |
| 2667 | ASSERT_EQ(navDevicePort.id, selectedDeviceId); |
| 2668 | } |
| 2669 | |
| 2670 | TEST_F(AudioPolicyManagerCarTest, GetOutputForAttrWithSelectedOutputAfterUserAffinities) { |
| 2671 | status_t ret; |
| 2672 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 2673 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 2674 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 2675 | audioConfig.sample_rate = k48000SamplingRate; |
| 2676 | std::vector<AudioMixMatchCriterion> mediaMatchCriteria = { |
| 2677 | createUsageCriterion(AUDIO_USAGE_MEDIA, /*exclude=*/ false)}; |
| 2678 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2679 | AUDIO_DEVICE_OUT_BUS, sCarBusMediaOutput, audioConfig, mediaMatchCriteria); |
| 2680 | ASSERT_EQ(NO_ERROR, ret); |
| 2681 | std::vector<AudioMixMatchCriterion> navMatchCriteria = { |
| 2682 | createUsageCriterion(AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE, |
| 2683 | /*exclude=*/ false)}; |
| 2684 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2685 | AUDIO_DEVICE_OUT_BUS, sCarBusNavigationOutput, audioConfig, navMatchCriteria); |
| 2686 | ASSERT_EQ(NO_ERROR, ret); |
| 2687 | const AudioDeviceTypeAddr mediaOutputDevice(AUDIO_DEVICE_OUT_BUS, sCarBusMediaOutput); |
| 2688 | const AudioDeviceTypeAddrVector outputDevices = {mediaOutputDevice}; |
Oscar Azucena | 4f49ef6 | 2023-01-25 23:32:13 -0800 | [diff] [blame] | 2689 | mManager->setUserIdDeviceAffinities(/* userId */ 0, outputDevices); |
Oscar Azucena | 873d10f | 2023-01-12 18:34:42 -0800 | [diff] [blame] | 2690 | audio_port_v7 navDevicePort; |
| 2691 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SINK, AUDIO_DEVICE_OUT_BUS, |
| 2692 | sCarBusNavigationOutput, &navDevicePort)); |
| 2693 | audio_port_handle_t selectedDeviceId = navDevicePort.id; |
| 2694 | audio_io_handle_t output; |
| 2695 | audio_port_handle_t portId; |
| 2696 | const audio_attributes_t mediaAttribute = { |
| 2697 | AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_MEDIA, |
| 2698 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}; |
| 2699 | |
| 2700 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
| 2701 | k48000SamplingRate, AUDIO_OUTPUT_FLAG_DIRECT, &output, &portId, mediaAttribute); |
| 2702 | |
| 2703 | ASSERT_NE(navDevicePort.id, selectedDeviceId); |
| 2704 | } |
| 2705 | |
| 2706 | TEST_F(AudioPolicyManagerCarTest, GetOutputForAttrWithExcludeUserIdCriteria) { |
| 2707 | status_t ret; |
| 2708 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 2709 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 2710 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 2711 | audioConfig.sample_rate = k48000SamplingRate; |
| 2712 | std::vector<AudioMixMatchCriterion> mediaMatchCriteria = { |
| 2713 | createUsageCriterion(AUDIO_USAGE_MEDIA, /*exclude=*/ false)}; |
| 2714 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2715 | AUDIO_DEVICE_OUT_BUS, sCarBusMediaOutput, audioConfig, mediaMatchCriteria); |
| 2716 | ASSERT_EQ(NO_ERROR, ret); |
| 2717 | std::vector<AudioMixMatchCriterion> navMatchCriteria = { |
| 2718 | createUsageCriterion(AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE, |
| 2719 | /*exclude=*/ false), |
| 2720 | createUserIdCriterion(/* userId */ 0, /* exclude */ true)}; |
| 2721 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2722 | AUDIO_DEVICE_OUT_BUS, sCarBusNavigationOutput, audioConfig, navMatchCriteria); |
| 2723 | ASSERT_EQ(NO_ERROR, ret); |
| 2724 | audio_port_v7 navDevicePort; |
| 2725 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SINK, AUDIO_DEVICE_OUT_BUS, |
| 2726 | sCarBusNavigationOutput, &navDevicePort)); |
| 2727 | audio_io_handle_t output; |
| 2728 | audio_port_handle_t portId; |
| 2729 | const audio_attributes_t navigationAttribute = { |
| 2730 | AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE, |
| 2731 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}; |
| 2732 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 2733 | |
| 2734 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
| 2735 | k48000SamplingRate, AUDIO_OUTPUT_FLAG_DIRECT, &output, &portId, navigationAttribute); |
| 2736 | |
| 2737 | ASSERT_NE(navDevicePort.id, selectedDeviceId); |
| 2738 | } |
| 2739 | |
| 2740 | TEST_F(AudioPolicyManagerCarTest, GetOutputForAttrWithSelectedOutputExcludeUserIdCriteria) { |
| 2741 | status_t ret; |
| 2742 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 2743 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 2744 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 2745 | audioConfig.sample_rate = k48000SamplingRate; |
| 2746 | std::vector<AudioMixMatchCriterion> mediaMatchCriteria = { |
| 2747 | createUsageCriterion(AUDIO_USAGE_MEDIA, /*exclude=*/ false)}; |
| 2748 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2749 | AUDIO_DEVICE_OUT_BUS, sCarBusMediaOutput, audioConfig, mediaMatchCriteria); |
| 2750 | ASSERT_EQ(NO_ERROR, ret); |
| 2751 | std::vector<AudioMixMatchCriterion> navMatchCriteria = { |
| 2752 | createUsageCriterion(AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE, |
| 2753 | /*exclude=*/ false), |
| 2754 | createUserIdCriterion(0 /* userId */, /* exclude */ true)}; |
| 2755 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2756 | AUDIO_DEVICE_OUT_BUS, sCarBusNavigationOutput, audioConfig, navMatchCriteria); |
| 2757 | ASSERT_EQ(NO_ERROR, ret); |
| 2758 | audio_port_v7 navDevicePort; |
| 2759 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SINK, AUDIO_DEVICE_OUT_BUS, |
| 2760 | sCarBusNavigationOutput, &navDevicePort)); |
| 2761 | audio_port_handle_t selectedDeviceId = navDevicePort.id; |
| 2762 | audio_io_handle_t output; |
| 2763 | audio_port_handle_t portId; |
| 2764 | const audio_attributes_t mediaAttribute = { |
| 2765 | AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_MEDIA, |
| 2766 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}; |
| 2767 | |
| 2768 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
| 2769 | k48000SamplingRate, AUDIO_OUTPUT_FLAG_DIRECT, &output, &portId, mediaAttribute); |
| 2770 | |
| 2771 | ASSERT_EQ(navDevicePort.id, selectedDeviceId); |
| 2772 | } |
| 2773 | |
| 2774 | TEST_F(AudioPolicyManagerCarTest, |
| 2775 | GetOutputForAttrWithMatchingMixAndSelectedOutputAfterUserAffinities) { |
| 2776 | status_t ret; |
| 2777 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 2778 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 2779 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 2780 | audioConfig.sample_rate = k48000SamplingRate; |
| 2781 | std::vector<AudioMixMatchCriterion> mediaMatchCriteria = { |
| 2782 | createUsageCriterion(AUDIO_USAGE_MEDIA, /*exclude=*/ false)}; |
| 2783 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2784 | AUDIO_DEVICE_OUT_BUS, sCarBusMediaOutput, audioConfig, mediaMatchCriteria); |
| 2785 | ASSERT_EQ(NO_ERROR, ret); |
| 2786 | std::vector<AudioMixMatchCriterion> navMatchCriteria = { |
| 2787 | createUsageCriterion(AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE, |
| 2788 | /*exclude=*/ false)}; |
| 2789 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2790 | AUDIO_DEVICE_OUT_BUS, sCarBusNavigationOutput, audioConfig, navMatchCriteria); |
| 2791 | ASSERT_EQ(NO_ERROR, ret); |
| 2792 | const AudioDeviceTypeAddr mediaOutputDevice(AUDIO_DEVICE_OUT_BUS, sCarBusMediaOutput); |
| 2793 | const AudioDeviceTypeAddr navOutputDevice(AUDIO_DEVICE_OUT_BUS, sCarBusNavigationOutput); |
| 2794 | const AudioDeviceTypeAddrVector outputDevices = {mediaOutputDevice, navOutputDevice}; |
Oscar Azucena | 4f49ef6 | 2023-01-25 23:32:13 -0800 | [diff] [blame] | 2795 | mManager->setUserIdDeviceAffinities(/* userId */ 0, outputDevices); |
Oscar Azucena | 873d10f | 2023-01-12 18:34:42 -0800 | [diff] [blame] | 2796 | audio_port_v7 navDevicePort; |
| 2797 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SINK, AUDIO_DEVICE_OUT_BUS, |
| 2798 | sCarBusNavigationOutput, &navDevicePort)); |
| 2799 | audio_port_handle_t selectedDeviceId = navDevicePort.id; |
| 2800 | audio_io_handle_t output; |
| 2801 | audio_port_handle_t portId; |
| 2802 | const audio_attributes_t mediaAttribute = { |
| 2803 | AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_MEDIA, |
| 2804 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}; |
| 2805 | |
| 2806 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
| 2807 | k48000SamplingRate, AUDIO_OUTPUT_FLAG_DIRECT, &output, &portId, mediaAttribute); |
| 2808 | |
| 2809 | ASSERT_EQ(navDevicePort.id, selectedDeviceId); |
| 2810 | } |
| 2811 | |
| 2812 | TEST_F(AudioPolicyManagerCarTest, |
| 2813 | GetOutputForAttrWithNoMatchingMaxAndSelectedOutputAfterUserAffinities) { |
| 2814 | status_t ret; |
| 2815 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 2816 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 2817 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 2818 | audioConfig.sample_rate = k48000SamplingRate; |
| 2819 | std::vector<AudioMixMatchCriterion> mediaMatchCriteria = { |
| 2820 | createUsageCriterion(AUDIO_USAGE_MEDIA, /*exclude=*/ false)}; |
| 2821 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2822 | AUDIO_DEVICE_OUT_BUS, sCarBusMediaOutput, audioConfig, mediaMatchCriteria); |
| 2823 | ASSERT_EQ(NO_ERROR, ret); |
| 2824 | std::vector<AudioMixMatchCriterion> navMatchCriteria = { |
| 2825 | createUsageCriterion(AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE, |
| 2826 | /*exclude=*/ false)}; |
| 2827 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2828 | AUDIO_DEVICE_OUT_BUS, sCarBusNavigationOutput, audioConfig, navMatchCriteria); |
| 2829 | ASSERT_EQ(NO_ERROR, ret); |
| 2830 | const AudioDeviceTypeAddr mediaOutputDevice(AUDIO_DEVICE_OUT_BUS, sCarBusMediaOutput); |
| 2831 | const AudioDeviceTypeAddr navOutputDevice(AUDIO_DEVICE_OUT_BUS, sCarBusNavigationOutput); |
| 2832 | const AudioDeviceTypeAddrVector outputDevices = {mediaOutputDevice, navOutputDevice}; |
Oscar Azucena | 4f49ef6 | 2023-01-25 23:32:13 -0800 | [diff] [blame] | 2833 | mManager->setUserIdDeviceAffinities(/* userId */ 0, outputDevices); |
Oscar Azucena | 873d10f | 2023-01-12 18:34:42 -0800 | [diff] [blame] | 2834 | audio_port_v7 navDevicePort; |
| 2835 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SINK, AUDIO_DEVICE_OUT_BUS, |
| 2836 | sCarBusNavigationOutput, &navDevicePort)); |
| 2837 | audio_port_handle_t selectedDeviceId = navDevicePort.id; |
| 2838 | audio_io_handle_t output; |
| 2839 | audio_port_handle_t portId; |
| 2840 | const audio_attributes_t alarmAttribute = { |
| 2841 | AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_ALARM, |
| 2842 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}; |
| 2843 | |
| 2844 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
| 2845 | k48000SamplingRate, AUDIO_OUTPUT_FLAG_DIRECT, &output, &portId, alarmAttribute); |
| 2846 | |
| 2847 | ASSERT_EQ(navDevicePort.id, selectedDeviceId); |
| 2848 | } |
| 2849 | |
Oscar Azucena | 4f49ef6 | 2023-01-25 23:32:13 -0800 | [diff] [blame] | 2850 | TEST_F(AudioPolicyManagerCarTest, |
| 2851 | GetOutputForAttrWithMatMixAfterUserAffinitiesForOneUser) { |
| 2852 | status_t ret; |
| 2853 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 2854 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 2855 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 2856 | audioConfig.sample_rate = k48000SamplingRate; |
| 2857 | std::vector<AudioMixMatchCriterion> mediaMatchCriteria = { |
| 2858 | createUsageCriterion(AUDIO_USAGE_MEDIA, /*exclude=*/ false)}; |
| 2859 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2860 | AUDIO_DEVICE_OUT_BUS, sCarBusMediaOutput, audioConfig, mediaMatchCriteria); |
| 2861 | ASSERT_EQ(NO_ERROR, ret); |
| 2862 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2863 | AUDIO_DEVICE_OUT_BUS, sCarRearZoneOneOutput, audioConfig, mediaMatchCriteria); |
| 2864 | ASSERT_EQ(NO_ERROR, ret); |
| 2865 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2866 | AUDIO_DEVICE_OUT_BUS, sCarRearZoneTwoOutput, audioConfig, mediaMatchCriteria); |
| 2867 | ASSERT_EQ(NO_ERROR, ret); |
| 2868 | const AudioDeviceTypeAddr mediaOutputDevice(AUDIO_DEVICE_OUT_BUS, sCarBusMediaOutput); |
| 2869 | const AudioDeviceTypeAddrVector primaryZoneDevices = {mediaOutputDevice}; |
| 2870 | mManager->setUserIdDeviceAffinities(/* userId */ 0, primaryZoneDevices); |
| 2871 | audio_port_v7 primaryZoneDevicePort; |
| 2872 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SINK, AUDIO_DEVICE_OUT_BUS, |
| 2873 | sCarBusMediaOutput, &primaryZoneDevicePort)); |
| 2874 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 2875 | audio_io_handle_t output; |
| 2876 | audio_port_handle_t portId; |
| 2877 | const audio_attributes_t mediaAttribute = { |
| 2878 | AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_MEDIA, |
| 2879 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}; |
| 2880 | uid_t user11AppUid = multiuser_get_uid(/* user_id */ 11, /* app_id */ 12345); |
| 2881 | |
| 2882 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
| 2883 | k48000SamplingRate, AUDIO_OUTPUT_FLAG_DIRECT, &output, &portId, mediaAttribute, |
| 2884 | AUDIO_SESSION_NONE, user11AppUid); |
| 2885 | |
| 2886 | ASSERT_EQ(primaryZoneDevicePort.id, selectedDeviceId); |
| 2887 | } |
| 2888 | |
| 2889 | TEST_F(AudioPolicyManagerCarTest, |
| 2890 | GetOutputForAttrWithMatMixAfterUserAffinitiesForTwoUsers) { |
| 2891 | status_t ret; |
| 2892 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 2893 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 2894 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 2895 | audioConfig.sample_rate = k48000SamplingRate; |
| 2896 | std::vector<AudioMixMatchCriterion> mediaMatchCriteria = { |
| 2897 | createUsageCriterion(AUDIO_USAGE_MEDIA, /*exclude=*/ false)}; |
| 2898 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2899 | AUDIO_DEVICE_OUT_BUS, sCarBusMediaOutput, audioConfig, mediaMatchCriteria); |
| 2900 | ASSERT_EQ(NO_ERROR, ret); |
| 2901 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2902 | AUDIO_DEVICE_OUT_BUS, sCarRearZoneOneOutput, audioConfig, mediaMatchCriteria); |
| 2903 | ASSERT_EQ(NO_ERROR, ret); |
| 2904 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2905 | AUDIO_DEVICE_OUT_BUS, sCarRearZoneTwoOutput, audioConfig, mediaMatchCriteria); |
| 2906 | ASSERT_EQ(NO_ERROR, ret); |
| 2907 | const AudioDeviceTypeAddr mediaOutputDevice(AUDIO_DEVICE_OUT_BUS, sCarBusMediaOutput); |
| 2908 | const AudioDeviceTypeAddrVector primaryZoneDevices = {mediaOutputDevice}; |
| 2909 | mManager->setUserIdDeviceAffinities(/* userId */ 0, primaryZoneDevices); |
| 2910 | const AudioDeviceTypeAddr secondaryOutputDevice(AUDIO_DEVICE_OUT_BUS, sCarRearZoneOneOutput); |
| 2911 | const AudioDeviceTypeAddrVector secondaryZoneDevices = {secondaryOutputDevice}; |
| 2912 | mManager->setUserIdDeviceAffinities(/* userId */ 11, secondaryZoneDevices); |
| 2913 | audio_port_v7 secondaryZoneDevicePort; |
| 2914 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SINK, AUDIO_DEVICE_OUT_BUS, |
| 2915 | sCarRearZoneOneOutput, &secondaryZoneDevicePort)); |
| 2916 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 2917 | audio_io_handle_t output; |
| 2918 | audio_port_handle_t portId; |
| 2919 | const audio_attributes_t mediaAttribute = { |
| 2920 | AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_MEDIA, |
| 2921 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}; |
| 2922 | uid_t user11AppUid = multiuser_get_uid(/* user_id */ 11, /* app_id */ 12345); |
| 2923 | |
| 2924 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
| 2925 | k48000SamplingRate, AUDIO_OUTPUT_FLAG_DIRECT, &output, &portId, mediaAttribute, |
| 2926 | AUDIO_SESSION_NONE, user11AppUid); |
| 2927 | |
| 2928 | ASSERT_EQ(secondaryZoneDevicePort.id, selectedDeviceId); |
| 2929 | } |
| 2930 | |
| 2931 | TEST_F(AudioPolicyManagerCarTest, |
| 2932 | GetOutputForAttrWithMatMixAfterUserAffinitiesForThreeUsers) { |
| 2933 | status_t ret; |
| 2934 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 2935 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 2936 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 2937 | audioConfig.sample_rate = k48000SamplingRate; |
| 2938 | std::vector<AudioMixMatchCriterion> mediaMatchCriteria = { |
| 2939 | createUsageCriterion(AUDIO_USAGE_MEDIA, /*exclude=*/ false)}; |
| 2940 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2941 | AUDIO_DEVICE_OUT_BUS, sCarBusMediaOutput, audioConfig, mediaMatchCriteria); |
| 2942 | ASSERT_EQ(NO_ERROR, ret); |
| 2943 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2944 | AUDIO_DEVICE_OUT_BUS, sCarRearZoneOneOutput, audioConfig, mediaMatchCriteria); |
| 2945 | ASSERT_EQ(NO_ERROR, ret); |
| 2946 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2947 | AUDIO_DEVICE_OUT_BUS, sCarRearZoneTwoOutput, audioConfig, mediaMatchCriteria); |
| 2948 | ASSERT_EQ(NO_ERROR, ret); |
| 2949 | const AudioDeviceTypeAddr mediaOutputDevice(AUDIO_DEVICE_OUT_BUS, sCarBusMediaOutput); |
| 2950 | const AudioDeviceTypeAddrVector primaryZoneDevices = {mediaOutputDevice}; |
| 2951 | mManager->setUserIdDeviceAffinities(/* userId */ 0, primaryZoneDevices); |
| 2952 | const AudioDeviceTypeAddr secondaryOutputDevice(AUDIO_DEVICE_OUT_BUS, sCarRearZoneOneOutput); |
| 2953 | const AudioDeviceTypeAddrVector secondaryZoneDevices = {secondaryOutputDevice}; |
| 2954 | mManager->setUserIdDeviceAffinities(/* userId */ 11, secondaryZoneDevices); |
| 2955 | const AudioDeviceTypeAddr tertiaryOutputDevice(AUDIO_DEVICE_OUT_BUS, sCarRearZoneTwoOutput); |
| 2956 | const AudioDeviceTypeAddrVector tertiaryZoneDevices = {tertiaryOutputDevice}; |
| 2957 | mManager->setUserIdDeviceAffinities(/* userId */ 15, tertiaryZoneDevices); |
| 2958 | audio_port_v7 tertiaryZoneDevicePort; |
| 2959 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SINK, AUDIO_DEVICE_OUT_BUS, |
| 2960 | sCarRearZoneTwoOutput, &tertiaryZoneDevicePort)); |
| 2961 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 2962 | audio_io_handle_t output; |
| 2963 | audio_port_handle_t portId; |
| 2964 | const audio_attributes_t mediaAttribute = { |
| 2965 | AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_MEDIA, |
| 2966 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}; |
| 2967 | uid_t user15AppUid = multiuser_get_uid(/* user_id */ 15, /* app_id */ 12345); |
| 2968 | |
| 2969 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
| 2970 | k48000SamplingRate, AUDIO_OUTPUT_FLAG_DIRECT, &output, &portId, mediaAttribute, |
| 2971 | AUDIO_SESSION_NONE, user15AppUid); |
| 2972 | |
| 2973 | ASSERT_EQ(tertiaryZoneDevicePort.id, selectedDeviceId); |
| 2974 | } |
| 2975 | |
Oscar Azucena | 873d10f | 2023-01-12 18:34:42 -0800 | [diff] [blame] | 2976 | TEST_F(AudioPolicyManagerCarTest, GetOutputForAttrWithNoMatchingMix) { |
| 2977 | status_t ret; |
| 2978 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 2979 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 2980 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 2981 | audioConfig.sample_rate = k48000SamplingRate; |
| 2982 | std::vector<AudioMixMatchCriterion> mediaMatchCriteria = { |
| 2983 | createUsageCriterion(AUDIO_USAGE_MEDIA, /*exclude=*/ false)}; |
| 2984 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2985 | AUDIO_DEVICE_OUT_BUS, sCarBusMediaOutput, audioConfig, mediaMatchCriteria); |
| 2986 | ASSERT_EQ(NO_ERROR, ret); |
| 2987 | std::vector<AudioMixMatchCriterion> navMatchCriteria = { |
| 2988 | createUsageCriterion(AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE, |
| 2989 | /*exclude=*/ false)}; |
| 2990 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 2991 | AUDIO_DEVICE_OUT_BUS, sCarBusNavigationOutput, audioConfig, navMatchCriteria); |
| 2992 | ASSERT_EQ(NO_ERROR, ret); |
| 2993 | const AudioDeviceTypeAddr mediaOutputDevice(AUDIO_DEVICE_OUT_BUS, sCarBusMediaOutput); |
| 2994 | const AudioDeviceTypeAddr navOutputDevice(AUDIO_DEVICE_OUT_BUS, sCarBusNavigationOutput); |
| 2995 | const AudioDeviceTypeAddrVector outputDevices = {mediaOutputDevice, navOutputDevice}; |
Oscar Azucena | 4f49ef6 | 2023-01-25 23:32:13 -0800 | [diff] [blame] | 2996 | mManager->setUserIdDeviceAffinities(/* userId */ 0, outputDevices); |
Oscar Azucena | 873d10f | 2023-01-12 18:34:42 -0800 | [diff] [blame] | 2997 | audio_port_v7 navDevicePort; |
| 2998 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SINK, AUDIO_DEVICE_OUT_BUS, |
| 2999 | sCarBusNavigationOutput, &navDevicePort)); |
| 3000 | audio_port_handle_t selectedDeviceId = navDevicePort.id; |
| 3001 | audio_io_handle_t output; |
| 3002 | audio_port_handle_t portId; |
| 3003 | const audio_attributes_t alarmAttribute = { |
| 3004 | AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_ALARM, |
| 3005 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}; |
| 3006 | |
| 3007 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
| 3008 | k48000SamplingRate, AUDIO_OUTPUT_FLAG_DIRECT, &output, &portId, alarmAttribute); |
| 3009 | |
| 3010 | ASSERT_EQ(navDevicePort.id, selectedDeviceId); |
| 3011 | } |
| 3012 | |
jiabin | 24ff57a | 2023-11-27 21:06:51 +0000 | [diff] [blame] | 3013 | TEST_F(AudioPolicyManagerCarTest, GetOutputForAttrForMMapWithPolicyMatched) { |
| 3014 | status_t ret; |
| 3015 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 3016 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 3017 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 3018 | audioConfig.sample_rate = k48000SamplingRate; |
| 3019 | std::vector<AudioMixMatchCriterion> mediaMatchCriteria = { |
| 3020 | createUsageCriterion(AUDIO_USAGE_MEDIA, /*exclude=*/ false)}; |
| 3021 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 3022 | AUDIO_DEVICE_OUT_BUS, sCarBusMmapOutput, audioConfig, mediaMatchCriteria); |
| 3023 | ASSERT_EQ(NO_ERROR, ret); |
| 3024 | ASSERT_EQ(NO_ERROR, ret); |
| 3025 | audio_port_v7 mmapDevicePort; |
| 3026 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SINK, AUDIO_DEVICE_OUT_BUS, |
| 3027 | sCarBusMmapOutput, &mmapDevicePort)); |
| 3028 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 3029 | audio_io_handle_t output; |
| 3030 | audio_port_handle_t portId; |
| 3031 | const audio_attributes_t mediaAttribute = { |
| 3032 | AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_MEDIA, |
| 3033 | AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}; |
| 3034 | |
| 3035 | getOutputForAttr( |
| 3036 | &selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
| 3037 | k48000SamplingRate, |
| 3038 | (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_MMAP_NOIRQ | AUDIO_OUTPUT_FLAG_DIRECT), |
| 3039 | &output, &portId, mediaAttribute); |
| 3040 | |
| 3041 | ASSERT_EQ(mmapDevicePort.id, selectedDeviceId); |
| 3042 | } |
| 3043 | |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 3044 | class AudioPolicyManagerTVTest : public AudioPolicyManagerTestWithConfigurationFile { |
| 3045 | protected: |
| 3046 | std::string getConfigFile() override { return sTvConfig; } |
| 3047 | void testHDMIPortSelection(audio_output_flags_t flags, const char* expectedMixPortName); |
| 3048 | |
| 3049 | static const std::string sTvConfig; |
| 3050 | }; |
| 3051 | |
| 3052 | const std::string AudioPolicyManagerTVTest::sTvConfig = |
| 3053 | AudioPolicyManagerTVTest::sExecutableDir + "test_tv_apm_configuration.xml"; |
| 3054 | |
| 3055 | // SwAudioOutputDescriptor doesn't populate flags so check against the port name. |
| 3056 | void AudioPolicyManagerTVTest::testHDMIPortSelection( |
| 3057 | audio_output_flags_t flags, const char* expectedMixPortName) { |
| 3058 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 3059 | AUDIO_DEVICE_OUT_AUX_DIGITAL, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 3060 | "" /*address*/, "" /*name*/, AUDIO_FORMAT_DEFAULT)); |
| 3061 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 3062 | audio_io_handle_t output; |
| 3063 | audio_port_handle_t portId; |
Dean Wheatley | d082f47 | 2022-02-04 11:10:48 +1100 | [diff] [blame] | 3064 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
| 3065 | k48000SamplingRate, flags, &output, &portId); |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 3066 | sp<SwAudioOutputDescriptor> outDesc = mManager->getOutputs().valueFor(output); |
| 3067 | ASSERT_NE(nullptr, outDesc.get()); |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 3068 | audio_port_v7 port = {}; |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 3069 | outDesc->toAudioPort(&port); |
| 3070 | mManager->releaseOutput(portId); |
| 3071 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 3072 | AUDIO_DEVICE_OUT_AUX_DIGITAL, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 3073 | "" /*address*/, "" /*name*/, AUDIO_FORMAT_DEFAULT)); |
| 3074 | ASSERT_EQ(AUDIO_PORT_TYPE_MIX, port.type); |
| 3075 | ASSERT_EQ(AUDIO_PORT_ROLE_SOURCE, port.role); |
| 3076 | ASSERT_STREQ(expectedMixPortName, port.name); |
| 3077 | } |
| 3078 | |
| 3079 | TEST_F(AudioPolicyManagerTVTest, InitSuccess) { |
| 3080 | // SetUp must finish with no assertions. |
| 3081 | } |
| 3082 | |
| 3083 | TEST_F(AudioPolicyManagerTVTest, Dump) { |
| 3084 | dumpToLog(); |
| 3085 | } |
| 3086 | |
Mikhail Naganov | 57ac2ce | 2019-09-11 09:29:41 -0700 | [diff] [blame] | 3087 | TEST_F(AudioPolicyManagerTVTest, MatchNoFlags) { |
| 3088 | testHDMIPortSelection(AUDIO_OUTPUT_FLAG_NONE, "primary output"); |
| 3089 | } |
| 3090 | |
| 3091 | TEST_F(AudioPolicyManagerTVTest, MatchOutputDirectNoHwAvSync) { |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 3092 | // b/140447125: The selected port must not have HW AV Sync flag (see the config file). |
| 3093 | testHDMIPortSelection(AUDIO_OUTPUT_FLAG_DIRECT, "direct"); |
| 3094 | } |
| 3095 | |
Mikhail Naganov | 57ac2ce | 2019-09-11 09:29:41 -0700 | [diff] [blame] | 3096 | TEST_F(AudioPolicyManagerTVTest, MatchOutputDirectHwAvSync) { |
Mikhail Naganov | 0756bbf | 2019-09-06 13:53:26 -0700 | [diff] [blame] | 3097 | testHDMIPortSelection(static_cast<audio_output_flags_t>( |
| 3098 | AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_HW_AV_SYNC), |
| 3099 | "tunnel"); |
| 3100 | } |
Mikhail Naganov | 57ac2ce | 2019-09-11 09:29:41 -0700 | [diff] [blame] | 3101 | |
| 3102 | TEST_F(AudioPolicyManagerTVTest, MatchOutputDirectMMapNoIrq) { |
| 3103 | testHDMIPortSelection(static_cast<audio_output_flags_t>( |
| 3104 | AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_MMAP_NOIRQ), |
| 3105 | "low latency"); |
| 3106 | } |
Mikhail Naganov | c0d0498 | 2020-03-02 21:02:28 +0000 | [diff] [blame] | 3107 | |
| 3108 | class AudioPolicyManagerDynamicHwModulesTest : public AudioPolicyManagerTestWithConfigurationFile { |
| 3109 | protected: |
| 3110 | void SetUpManagerConfig() override; |
| 3111 | }; |
| 3112 | |
| 3113 | void AudioPolicyManagerDynamicHwModulesTest::SetUpManagerConfig() { |
Mikhail Naganov | d4c21aa | 2021-10-05 15:10:16 -0700 | [diff] [blame] | 3114 | ASSERT_NO_FATAL_FAILURE(AudioPolicyManagerTestWithConfigurationFile::SetUpManagerConfig()); |
Mikhail Naganov | c0d0498 | 2020-03-02 21:02:28 +0000 | [diff] [blame] | 3115 | // Only allow successful opening of "primary" hw module during APM initialization. |
| 3116 | mClient->swapAllowedModuleNames({"primary"}); |
| 3117 | } |
| 3118 | |
| 3119 | TEST_F(AudioPolicyManagerDynamicHwModulesTest, InitSuccess) { |
| 3120 | // SetUp must finish with no assertions. |
| 3121 | } |
| 3122 | |
| 3123 | TEST_F(AudioPolicyManagerDynamicHwModulesTest, DynamicAddition) { |
| 3124 | const auto handleBefore = mClient->peekNextModuleHandle(); |
| 3125 | mManager->onNewAudioModulesAvailable(); |
| 3126 | ASSERT_EQ(handleBefore, mClient->peekNextModuleHandle()); |
| 3127 | // Reset module loading restrictions. |
| 3128 | mClient->swapAllowedModuleNames(); |
| 3129 | mManager->onNewAudioModulesAvailable(); |
| 3130 | const auto handleAfter = mClient->peekNextModuleHandle(); |
| 3131 | ASSERT_GT(handleAfter, handleBefore); |
| 3132 | mManager->onNewAudioModulesAvailable(); |
| 3133 | ASSERT_EQ(handleAfter, mClient->peekNextModuleHandle()); |
| 3134 | } |
| 3135 | |
| 3136 | TEST_F(AudioPolicyManagerDynamicHwModulesTest, AddedDeviceAvailable) { |
| 3137 | ASSERT_EQ(AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, mManager->getDeviceConnectionState( |
| 3138 | AUDIO_DEVICE_IN_REMOTE_SUBMIX, "0")); |
| 3139 | mClient->swapAllowedModuleNames({"primary", "r_submix"}); |
| 3140 | mManager->onNewAudioModulesAvailable(); |
| 3141 | ASSERT_EQ(AUDIO_POLICY_DEVICE_STATE_AVAILABLE, mManager->getDeviceConnectionState( |
| 3142 | AUDIO_DEVICE_IN_REMOTE_SUBMIX, "0")); |
| 3143 | } |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 3144 | |
| 3145 | TEST_F(AudioPolicyManagerDynamicHwModulesTest, ListAddedAudioPorts) { |
| 3146 | ASSERT_FALSE( |
| 3147 | findDevicePort(AUDIO_PORT_ROLE_SOURCE, AUDIO_DEVICE_IN_REMOTE_SUBMIX, "0", nullptr)); |
| 3148 | mClient->swapAllowedModuleNames({"primary", "r_submix"}); |
| 3149 | mManager->onNewAudioModulesAvailable(); |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 3150 | struct audio_port_v7 port; |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 3151 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SOURCE, AUDIO_DEVICE_IN_REMOTE_SUBMIX, "0", &port)); |
| 3152 | } |
| 3153 | |
| 3154 | TEST_F(AudioPolicyManagerDynamicHwModulesTest, ClientIsUpdated) { |
| 3155 | const size_t prevAudioPortListUpdateCount = mClient->getAudioPortListUpdateCount(); |
| 3156 | const uint32_t prevAudioPortGeneration = mManager->getAudioPortGeneration(); |
| 3157 | mClient->swapAllowedModuleNames({"primary", "r_submix"}); |
| 3158 | mManager->onNewAudioModulesAvailable(); |
| 3159 | EXPECT_GT(mClient->getAudioPortListUpdateCount(), prevAudioPortListUpdateCount); |
| 3160 | EXPECT_GT(mManager->getAudioPortGeneration(), prevAudioPortGeneration); |
| 3161 | } |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 3162 | |
| 3163 | using DevicesRoleForCapturePresetParam = std::tuple<audio_source_t, device_role_t>; |
| 3164 | |
| 3165 | class AudioPolicyManagerDevicesRoleForCapturePresetTest |
| 3166 | : public AudioPolicyManagerTestWithConfigurationFile, |
| 3167 | public testing::WithParamInterface<DevicesRoleForCapturePresetParam> { |
| 3168 | protected: |
| 3169 | // The `inputDevice` and `inputDevice2` indicate the audio devices type to be used for setting |
| 3170 | // device role. They must be declared in the test_audio_policy_configuration.xml |
| 3171 | AudioDeviceTypeAddr inputDevice = AudioDeviceTypeAddr(AUDIO_DEVICE_IN_BUILTIN_MIC, ""); |
| 3172 | AudioDeviceTypeAddr inputDevice2 = AudioDeviceTypeAddr(AUDIO_DEVICE_IN_HDMI, ""); |
| 3173 | }; |
| 3174 | |
| 3175 | TEST_P(AudioPolicyManagerDevicesRoleForCapturePresetTest, DevicesRoleForCapturePreset) { |
| 3176 | const audio_source_t audioSource = std::get<0>(GetParam()); |
| 3177 | const device_role_t role = std::get<1>(GetParam()); |
| 3178 | |
| 3179 | // Test invalid device when setting |
| 3180 | const AudioDeviceTypeAddr outputDevice(AUDIO_DEVICE_OUT_SPEAKER, ""); |
| 3181 | const AudioDeviceTypeAddrVector outputDevices = {outputDevice}; |
| 3182 | ASSERT_EQ(BAD_VALUE, |
| 3183 | mManager->setDevicesRoleForCapturePreset(audioSource, role, outputDevices)); |
| 3184 | ASSERT_EQ(BAD_VALUE, |
| 3185 | mManager->addDevicesRoleForCapturePreset(audioSource, role, outputDevices)); |
| 3186 | AudioDeviceTypeAddrVector devices; |
| 3187 | ASSERT_EQ(NAME_NOT_FOUND, |
| 3188 | mManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices)); |
| 3189 | ASSERT_TRUE(devices.empty()); |
| 3190 | ASSERT_EQ(BAD_VALUE, |
| 3191 | mManager->removeDevicesRoleForCapturePreset(audioSource, role, outputDevices)); |
| 3192 | |
| 3193 | // Without setting, call get/remove/clear must fail |
| 3194 | ASSERT_EQ(NAME_NOT_FOUND, |
| 3195 | mManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices)); |
| 3196 | ASSERT_EQ(NAME_NOT_FOUND, |
| 3197 | mManager->removeDevicesRoleForCapturePreset(audioSource, role, devices)); |
| 3198 | ASSERT_EQ(NAME_NOT_FOUND, |
| 3199 | mManager->clearDevicesRoleForCapturePreset(audioSource, role)); |
| 3200 | |
| 3201 | // Test set/get devices role |
| 3202 | const AudioDeviceTypeAddrVector inputDevices = {inputDevice}; |
| 3203 | ASSERT_EQ(NO_ERROR, |
| 3204 | mManager->setDevicesRoleForCapturePreset(audioSource, role, inputDevices)); |
| 3205 | ASSERT_EQ(NO_ERROR, mManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices)); |
| 3206 | EXPECT_THAT(devices, UnorderedElementsAre(inputDevice)); |
| 3207 | |
| 3208 | // Test setting will change the previously set devices |
| 3209 | const AudioDeviceTypeAddrVector inputDevices2 = {inputDevice2}; |
| 3210 | ASSERT_EQ(NO_ERROR, |
| 3211 | mManager->setDevicesRoleForCapturePreset(audioSource, role, inputDevices2)); |
| 3212 | devices.clear(); |
| 3213 | ASSERT_EQ(NO_ERROR, mManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices)); |
| 3214 | EXPECT_THAT(devices, UnorderedElementsAre(inputDevice2)); |
| 3215 | |
| 3216 | // Test add devices |
| 3217 | ASSERT_EQ(NO_ERROR, |
| 3218 | mManager->addDevicesRoleForCapturePreset(audioSource, role, inputDevices)); |
| 3219 | devices.clear(); |
| 3220 | ASSERT_EQ(NO_ERROR, mManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices)); |
| 3221 | EXPECT_THAT(devices, UnorderedElementsAre(inputDevice, inputDevice2)); |
| 3222 | |
| 3223 | // Test remove devices |
| 3224 | ASSERT_EQ(NO_ERROR, |
| 3225 | mManager->removeDevicesRoleForCapturePreset(audioSource, role, inputDevices)); |
| 3226 | devices.clear(); |
| 3227 | ASSERT_EQ(NO_ERROR, mManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices)); |
| 3228 | EXPECT_THAT(devices, UnorderedElementsAre(inputDevice2)); |
| 3229 | |
| 3230 | // Test remove devices that are not set as the device role |
| 3231 | ASSERT_EQ(BAD_VALUE, |
| 3232 | mManager->removeDevicesRoleForCapturePreset(audioSource, role, inputDevices)); |
| 3233 | |
| 3234 | // Test clear devices |
| 3235 | ASSERT_EQ(NO_ERROR, |
| 3236 | mManager->clearDevicesRoleForCapturePreset(audioSource, role)); |
| 3237 | devices.clear(); |
| 3238 | ASSERT_EQ(NAME_NOT_FOUND, |
| 3239 | mManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices)); |
| 3240 | } |
| 3241 | |
jiabin | 14662b5 | 2023-03-06 21:35:29 +0000 | [diff] [blame] | 3242 | TEST_F(AudioPolicyManagerDevicesRoleForCapturePresetTest, PreferredDeviceUsedForInput) { |
| 3243 | const audio_source_t source = AUDIO_SOURCE_MIC; |
| 3244 | const device_role_t role = DEVICE_ROLE_PREFERRED; |
| 3245 | const std::string address = "card=1;device=0"; |
| 3246 | const std::string deviceName = "randomName"; |
| 3247 | |
| 3248 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 3249 | AUDIO_DEVICE_IN_USB_DEVICE, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 3250 | address.c_str(), deviceName.c_str(), AUDIO_FORMAT_DEFAULT)); |
| 3251 | auto availableDevices = mManager->getAvailableInputDevices(); |
| 3252 | ASSERT_GT(availableDevices.size(), 1); |
| 3253 | |
| 3254 | audio_attributes_t attr = AUDIO_ATTRIBUTES_INITIALIZER; |
| 3255 | attr.source = source; |
| 3256 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
François Gaffie | 6ebbce0 | 2023-07-19 13:27:53 +0200 | [diff] [blame] | 3257 | audio_io_handle_t input = AUDIO_PORT_HANDLE_NONE; |
| 3258 | ASSERT_NO_FATAL_FAILURE(getInputForAttr(attr, &input, AUDIO_SESSION_NONE, 1, &selectedDeviceId, |
jiabin | 14662b5 | 2023-03-06 21:35:29 +0000 | [diff] [blame] | 3259 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_STEREO, |
| 3260 | 48000)); |
| 3261 | auto selectedDevice = availableDevices.getDeviceFromId(selectedDeviceId); |
| 3262 | ASSERT_NE(nullptr, selectedDevice); |
| 3263 | |
| 3264 | sp<DeviceDescriptor> preferredDevice = nullptr; |
| 3265 | for (const auto& device : availableDevices) { |
| 3266 | if (device != selectedDevice) { |
| 3267 | preferredDevice = device; |
| 3268 | break; |
| 3269 | } |
| 3270 | } |
| 3271 | ASSERT_NE(nullptr, preferredDevice); |
| 3272 | // After setting preferred device for capture preset, the selected device for input should be |
| 3273 | // the preferred device. |
| 3274 | ASSERT_EQ(NO_ERROR, |
| 3275 | mManager->setDevicesRoleForCapturePreset(source, role, |
| 3276 | {preferredDevice->getDeviceTypeAddr()})); |
| 3277 | selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
François Gaffie | 6ebbce0 | 2023-07-19 13:27:53 +0200 | [diff] [blame] | 3278 | input = AUDIO_PORT_HANDLE_NONE; |
| 3279 | ASSERT_NO_FATAL_FAILURE(getInputForAttr(attr, &input, AUDIO_SESSION_NONE, 1, &selectedDeviceId, |
jiabin | 14662b5 | 2023-03-06 21:35:29 +0000 | [diff] [blame] | 3280 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_STEREO, |
| 3281 | 48000)); |
| 3282 | ASSERT_EQ(preferredDevice, availableDevices.getDeviceFromId(selectedDeviceId)); |
| 3283 | |
| 3284 | // After clearing preferred device for capture preset, the selected device for input should be |
| 3285 | // the same as original one. |
| 3286 | ASSERT_EQ(NO_ERROR, |
| 3287 | mManager->clearDevicesRoleForCapturePreset(source, role)); |
| 3288 | selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
François Gaffie | 6ebbce0 | 2023-07-19 13:27:53 +0200 | [diff] [blame] | 3289 | input = AUDIO_PORT_HANDLE_NONE; |
| 3290 | ASSERT_NO_FATAL_FAILURE(getInputForAttr(attr, &input, AUDIO_SESSION_NONE, 1, &selectedDeviceId, |
jiabin | 14662b5 | 2023-03-06 21:35:29 +0000 | [diff] [blame] | 3291 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_STEREO, |
| 3292 | 48000)); |
| 3293 | ASSERT_EQ(selectedDevice, availableDevices.getDeviceFromId(selectedDeviceId)); |
| 3294 | |
| 3295 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 3296 | AUDIO_DEVICE_IN_USB_DEVICE, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 3297 | address.c_str(), deviceName.c_str(), AUDIO_FORMAT_DEFAULT)); |
| 3298 | } |
| 3299 | |
| 3300 | TEST_F(AudioPolicyManagerDevicesRoleForCapturePresetTest, DisabledDeviceNotUsedForInput) { |
| 3301 | const audio_source_t source = AUDIO_SOURCE_MIC; |
| 3302 | const device_role_t role = DEVICE_ROLE_DISABLED; |
| 3303 | const std::string address = "card=1;device=0"; |
| 3304 | const std::string deviceName = "randomName"; |
| 3305 | |
| 3306 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 3307 | AUDIO_DEVICE_IN_USB_DEVICE, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 3308 | address.c_str(), deviceName.c_str(), AUDIO_FORMAT_DEFAULT)); |
| 3309 | auto availableDevices = mManager->getAvailableInputDevices(); |
| 3310 | ASSERT_GT(availableDevices.size(), 1); |
| 3311 | |
| 3312 | audio_attributes_t attr = AUDIO_ATTRIBUTES_INITIALIZER; |
| 3313 | attr.source = source; |
| 3314 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
François Gaffie | 6ebbce0 | 2023-07-19 13:27:53 +0200 | [diff] [blame] | 3315 | audio_io_handle_t input = AUDIO_PORT_HANDLE_NONE; |
| 3316 | ASSERT_NO_FATAL_FAILURE(getInputForAttr(attr, &input, AUDIO_SESSION_NONE, 1, &selectedDeviceId, |
jiabin | 14662b5 | 2023-03-06 21:35:29 +0000 | [diff] [blame] | 3317 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_STEREO, |
| 3318 | 48000)); |
| 3319 | auto selectedDevice = availableDevices.getDeviceFromId(selectedDeviceId); |
| 3320 | ASSERT_NE(nullptr, selectedDevice); |
| 3321 | |
| 3322 | // After setting disabled device for capture preset, the disabled device must not be |
| 3323 | // selected for input. |
| 3324 | ASSERT_EQ(NO_ERROR, |
| 3325 | mManager->setDevicesRoleForCapturePreset(source, role, |
| 3326 | {selectedDevice->getDeviceTypeAddr()})); |
| 3327 | selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
François Gaffie | 6ebbce0 | 2023-07-19 13:27:53 +0200 | [diff] [blame] | 3328 | input = AUDIO_PORT_HANDLE_NONE; |
| 3329 | ASSERT_NO_FATAL_FAILURE(getInputForAttr(attr, &input, AUDIO_SESSION_NONE, 1, |
| 3330 | &selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, |
| 3331 | AUDIO_CHANNEL_IN_STEREO, 48000)); |
jiabin | 14662b5 | 2023-03-06 21:35:29 +0000 | [diff] [blame] | 3332 | ASSERT_NE(selectedDevice, availableDevices.getDeviceFromId(selectedDeviceId)); |
| 3333 | |
| 3334 | // After clearing disabled device for capture preset, the selected device for input should be |
| 3335 | // the original one. |
| 3336 | ASSERT_EQ(NO_ERROR, |
| 3337 | mManager->clearDevicesRoleForCapturePreset(source, role)); |
| 3338 | selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
François Gaffie | 6ebbce0 | 2023-07-19 13:27:53 +0200 | [diff] [blame] | 3339 | input = AUDIO_PORT_HANDLE_NONE; |
| 3340 | ASSERT_NO_FATAL_FAILURE(getInputForAttr(attr, &input, AUDIO_SESSION_NONE, 1, &selectedDeviceId, |
jiabin | 14662b5 | 2023-03-06 21:35:29 +0000 | [diff] [blame] | 3341 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_STEREO, |
| 3342 | 48000)); |
| 3343 | ASSERT_EQ(selectedDevice, availableDevices.getDeviceFromId(selectedDeviceId)); |
| 3344 | |
| 3345 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 3346 | AUDIO_DEVICE_IN_USB_DEVICE, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 3347 | address.c_str(), deviceName.c_str(), AUDIO_FORMAT_DEFAULT)); |
| 3348 | } |
| 3349 | |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 3350 | INSTANTIATE_TEST_CASE_P( |
| 3351 | DevicesRoleForCapturePresetOperation, |
| 3352 | AudioPolicyManagerDevicesRoleForCapturePresetTest, |
| 3353 | testing::Values( |
| 3354 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_MIC, DEVICE_ROLE_PREFERRED}), |
| 3355 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_VOICE_UPLINK, |
| 3356 | DEVICE_ROLE_PREFERRED}), |
| 3357 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_VOICE_DOWNLINK, |
| 3358 | DEVICE_ROLE_PREFERRED}), |
| 3359 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_VOICE_CALL, DEVICE_ROLE_PREFERRED}), |
| 3360 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_CAMCORDER, DEVICE_ROLE_PREFERRED}), |
| 3361 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_VOICE_RECOGNITION, |
| 3362 | DEVICE_ROLE_PREFERRED}), |
| 3363 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_VOICE_COMMUNICATION, |
| 3364 | DEVICE_ROLE_PREFERRED}), |
| 3365 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_REMOTE_SUBMIX, |
| 3366 | DEVICE_ROLE_PREFERRED}), |
| 3367 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_UNPROCESSED, DEVICE_ROLE_PREFERRED}), |
| 3368 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_VOICE_PERFORMANCE, |
| 3369 | DEVICE_ROLE_PREFERRED}), |
| 3370 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_ECHO_REFERENCE, |
| 3371 | DEVICE_ROLE_PREFERRED}), |
| 3372 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_FM_TUNER, DEVICE_ROLE_PREFERRED}), |
| 3373 | DevicesRoleForCapturePresetParam({AUDIO_SOURCE_HOTWORD, DEVICE_ROLE_PREFERRED}) |
| 3374 | ) |
| 3375 | ); |
François Gaffie | 6ebbce0 | 2023-07-19 13:27:53 +0200 | [diff] [blame] | 3376 | |
| 3377 | |
| 3378 | const effect_descriptor_t TEST_EFFECT_DESC = { |
| 3379 | {0xf2a4bb20, 0x0c3c, 0x11e3, 0x8b07, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // type |
| 3380 | {0xff93e360, 0x0c3c, 0x11e3, 0x8a97, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid |
| 3381 | EFFECT_CONTROL_API_VERSION, |
| 3382 | EFFECT_FLAG_TYPE_PRE_PROC, |
| 3383 | 0, |
| 3384 | 1, |
| 3385 | "APM test Effect", |
| 3386 | "The Android Open Source Project", |
| 3387 | }; |
| 3388 | |
| 3389 | class AudioPolicyManagerPreProcEffectTest : public AudioPolicyManagerTestWithConfigurationFile { |
| 3390 | }; |
| 3391 | |
| 3392 | TEST_F(AudioPolicyManagerPreProcEffectTest, DeviceDisconnectWhileClientActive) { |
| 3393 | const audio_source_t source = AUDIO_SOURCE_MIC; |
| 3394 | const std::string address = "BUS00_MIC"; |
| 3395 | const std::string deviceName = "randomName"; |
| 3396 | audio_port_handle_t portId; |
| 3397 | audio_devices_t type = AUDIO_DEVICE_IN_BUS; |
| 3398 | |
| 3399 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState(type, |
| 3400 | AUDIO_POLICY_DEVICE_STATE_AVAILABLE, address.c_str(), deviceName.c_str(), |
| 3401 | AUDIO_FORMAT_DEFAULT)); |
| 3402 | auto availableDevices = mManager->getAvailableInputDevices(); |
| 3403 | ASSERT_GT(availableDevices.size(), 1); |
| 3404 | |
| 3405 | audio_attributes_t attr = AUDIO_ATTRIBUTES_INITIALIZER; |
| 3406 | attr.source = source; |
| 3407 | audio_session_t session = TEST_SESSION_ID; |
| 3408 | audio_io_handle_t inputClientHandle = 777; |
| 3409 | int effectId = 666; |
| 3410 | audio_port_v7 devicePort; |
| 3411 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SOURCE, type, address, &devicePort)); |
| 3412 | |
| 3413 | audio_port_handle_t routedPortId = devicePort.id; |
| 3414 | ASSERT_NO_FATAL_FAILURE(getInputForAttr(attr, &inputClientHandle, session, 1, &routedPortId, |
| 3415 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_STEREO, |
| 3416 | 48000, AUDIO_INPUT_FLAG_NONE, &portId)); |
| 3417 | ASSERT_EQ(devicePort.id, routedPortId); |
| 3418 | auto selectedDevice = availableDevices.getDeviceFromId(routedPortId); |
| 3419 | ASSERT_NE(nullptr, selectedDevice); |
| 3420 | |
| 3421 | // Add a pre processing effect on the input client session |
| 3422 | ASSERT_EQ(NO_ERROR, mManager->registerEffect(&TEST_EFFECT_DESC, inputClientHandle, |
| 3423 | PRODUCT_STRATEGY_NONE, session, effectId)); |
| 3424 | |
| 3425 | ASSERT_EQ(NO_ERROR, mManager->startInput(portId)); |
| 3426 | |
| 3427 | // Force a device disconnection to close the input, no crash expected of APM |
| 3428 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 3429 | type, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
| 3430 | address.c_str(), deviceName.c_str(), AUDIO_FORMAT_DEFAULT)); |
| 3431 | |
| 3432 | // Reconnect the device |
| 3433 | ASSERT_EQ(NO_ERROR, mManager->setDeviceConnectionState( |
| 3434 | type, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
| 3435 | address.c_str(), deviceName.c_str(), AUDIO_FORMAT_DEFAULT)); |
| 3436 | |
| 3437 | inputClientHandle += 1; |
| 3438 | ASSERT_TRUE(findDevicePort(AUDIO_PORT_ROLE_SOURCE, type, address, &devicePort)); |
| 3439 | routedPortId = devicePort.id; |
| 3440 | |
| 3441 | // Reconnect the client changing voluntarily the io, but keeping the session to get the |
| 3442 | // effect attached again |
| 3443 | ASSERT_NO_FATAL_FAILURE(getInputForAttr(attr, &inputClientHandle, session, 1, &routedPortId, |
| 3444 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_STEREO, |
| 3445 | 48000)); |
| 3446 | |
| 3447 | // unregister effect should succeed since effect shall have been restore on the client session |
| 3448 | ASSERT_EQ(NO_ERROR, mManager->unregisterEffect(effectId)); |
Mikhail Naganov | 3754b64 | 2024-04-17 18:31:04 +0000 | [diff] [blame] | 3449 | } |