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