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