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