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 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 17 | #include <map> |
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> |
| 24 | |
Mikhail Naganov | 21b4336 | 2018-06-04 10:37:09 -0700 | [diff] [blame] | 25 | #define LOG_TAG "APM_Test" |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 26 | #include <Serializer.h> |
| 27 | #include <android-base/file.h> |
| 28 | #include <media/AudioPolicy.h> |
Mikhail Naganov | dc76968 | 2018-05-04 15:34:08 -0700 | [diff] [blame] | 29 | #include <media/PatchBuilder.h> |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 30 | #include <media/RecordingActivityTracker.h> |
| 31 | #include <utils/Log.h> |
| 32 | #include <utils/Vector.h> |
Mikhail Naganov | dc76968 | 2018-05-04 15:34:08 -0700 | [diff] [blame] | 33 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 34 | #include "AudioPolicyInterface.h" |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 35 | #include "AudioPolicyTestClient.h" |
| 36 | #include "AudioPolicyTestManager.h" |
| 37 | |
| 38 | using namespace android; |
| 39 | |
Mikhail Naganov | 4783555 | 2019-05-14 10:32:51 -0700 | [diff] [blame] | 40 | TEST(AudioPolicyManagerTestInit, EngineFailure) { |
| 41 | AudioPolicyTestClient client; |
| 42 | AudioPolicyTestManager manager(&client); |
| 43 | manager.getConfig().setDefault(); |
| 44 | manager.getConfig().setEngineLibraryNameSuffix("non-existent"); |
| 45 | ASSERT_EQ(NO_INIT, manager.initialize()); |
| 46 | ASSERT_EQ(NO_INIT, manager.initCheck()); |
| 47 | } |
| 48 | |
| 49 | TEST(AudioPolicyManagerTestInit, ClientFailure) { |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 50 | AudioPolicyTestClient client; |
| 51 | AudioPolicyTestManager manager(&client); |
| 52 | manager.getConfig().setDefault(); |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 53 | // Since the default client fails to open anything, |
| 54 | // APM should indicate that the initialization didn't succeed. |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 55 | ASSERT_EQ(NO_INIT, manager.initialize()); |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 56 | ASSERT_EQ(NO_INIT, manager.initCheck()); |
| 57 | } |
| 58 | |
| 59 | |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 60 | class AudioPolicyManagerTestClient : public AudioPolicyTestClient { |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 61 | public: |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 62 | // AudioPolicyClientInterface implementation |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 63 | audio_module_handle_t loadHwModule(const char* /*name*/) override { |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 64 | return mNextModuleHandle++; |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 65 | } |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 66 | |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 67 | status_t openOutput(audio_module_handle_t module, |
| 68 | audio_io_handle_t* output, |
| 69 | audio_config_t* /*config*/, |
| 70 | audio_devices_t* /*devices*/, |
| 71 | const String8& /*address*/, |
| 72 | uint32_t* /*latencyMs*/, |
| 73 | audio_output_flags_t /*flags*/) override { |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 74 | if (module >= mNextModuleHandle) { |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 75 | ALOGE("%s: Module handle %d has not been allocated yet (next is %d)", |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 76 | __func__, module, mNextModuleHandle); |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 77 | return BAD_VALUE; |
| 78 | } |
| 79 | *output = mNextIoHandle++; |
| 80 | return NO_ERROR; |
| 81 | } |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 82 | |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 83 | status_t openInput(audio_module_handle_t module, |
| 84 | audio_io_handle_t* input, |
| 85 | audio_config_t* /*config*/, |
| 86 | audio_devices_t* /*device*/, |
| 87 | const String8& /*address*/, |
| 88 | audio_source_t /*source*/, |
| 89 | audio_input_flags_t /*flags*/) override { |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 90 | if (module >= mNextModuleHandle) { |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 91 | ALOGE("%s: Module handle %d has not been allocated yet (next is %d)", |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 92 | __func__, module, mNextModuleHandle); |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 93 | return BAD_VALUE; |
| 94 | } |
| 95 | *input = mNextIoHandle++; |
| 96 | return NO_ERROR; |
| 97 | } |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 98 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 99 | status_t createAudioPatch(const struct audio_patch* patch, |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 100 | audio_patch_handle_t* handle, |
| 101 | int /*delayMs*/) override { |
| 102 | *handle = mNextPatchHandle++; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 103 | mActivePatches.insert(std::make_pair(*handle, *patch)); |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 104 | return NO_ERROR; |
| 105 | } |
| 106 | |
| 107 | status_t releaseAudioPatch(audio_patch_handle_t handle, |
| 108 | int /*delayMs*/) override { |
| 109 | if (mActivePatches.erase(handle) != 1) { |
| 110 | if (handle >= mNextPatchHandle) { |
| 111 | ALOGE("%s: Patch handle %d has not been allocated yet (next is %d)", |
| 112 | __func__, handle, mNextPatchHandle); |
| 113 | } else { |
| 114 | ALOGE("%s: Attempt to release patch %d twice", __func__, handle); |
| 115 | } |
| 116 | return BAD_VALUE; |
| 117 | } |
| 118 | return NO_ERROR; |
| 119 | } |
| 120 | |
| 121 | // Helper methods for tests |
| 122 | size_t getActivePatchesCount() const { return mActivePatches.size(); } |
| 123 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 124 | const struct audio_patch* getLastAddedPatch() const { |
| 125 | if (mActivePatches.empty()) { |
| 126 | return nullptr; |
| 127 | } |
| 128 | auto it = --mActivePatches.end(); |
| 129 | return &it->second; |
| 130 | }; |
| 131 | |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 132 | private: |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 133 | audio_module_handle_t mNextModuleHandle = AUDIO_MODULE_HANDLE_NONE + 1; |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 134 | audio_io_handle_t mNextIoHandle = AUDIO_IO_HANDLE_NONE + 1; |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 135 | audio_patch_handle_t mNextPatchHandle = AUDIO_PATCH_HANDLE_NONE + 1; |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 136 | std::map<audio_patch_handle_t, struct audio_patch> mActivePatches; |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 137 | }; |
| 138 | |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 139 | class PatchCountCheck { |
| 140 | public: |
| 141 | explicit PatchCountCheck(AudioPolicyManagerTestClient *client) |
| 142 | : mClient{client}, |
| 143 | mInitialCount{mClient->getActivePatchesCount()} {} |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 144 | int deltaFromSnapshot() const { |
| 145 | size_t currentCount = mClient->getActivePatchesCount(); |
| 146 | if (mInitialCount <= currentCount) { |
| 147 | return currentCount - mInitialCount; |
| 148 | } else { |
| 149 | return -(static_cast<int>(mInitialCount - currentCount)); |
| 150 | } |
| 151 | } |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 152 | private: |
| 153 | const AudioPolicyManagerTestClient *mClient; |
| 154 | const size_t mInitialCount; |
| 155 | }; |
| 156 | |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 157 | class AudioPolicyManagerTest : public testing::Test { |
| 158 | protected: |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 159 | void SetUp() override; |
| 160 | void TearDown() override; |
| 161 | virtual void SetUpConfig(AudioPolicyConfig *config) { (void)config; } |
| 162 | |
| 163 | void dumpToLog(); |
| 164 | void getOutputForAttr( |
| 165 | audio_port_handle_t *selectedDeviceId, |
| 166 | audio_format_t format, |
| 167 | int channelMask, |
| 168 | int sampleRate, |
| 169 | audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 170 | audio_port_handle_t *portId = nullptr, |
| 171 | audio_attributes_t attr = {}); |
| 172 | void getInputForAttr( |
| 173 | const audio_attributes_t &attr, |
| 174 | audio_unique_id_t riid, |
| 175 | audio_port_handle_t *selectedDeviceId, |
| 176 | audio_format_t format, |
| 177 | int channelMask, |
| 178 | int sampleRate, |
| 179 | audio_input_flags_t flags = AUDIO_INPUT_FLAG_NONE, |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 180 | audio_port_handle_t *portId = nullptr); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 181 | PatchCountCheck snapshotPatchCount() { return PatchCountCheck(mClient.get()); } |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 182 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 183 | void findDevicePort(audio_port_role_t role, audio_devices_t deviceType, |
| 184 | const std::string &address, audio_port &foundPort); |
| 185 | |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 186 | std::unique_ptr<AudioPolicyManagerTestClient> mClient; |
| 187 | std::unique_ptr<AudioPolicyTestManager> mManager; |
| 188 | }; |
| 189 | |
| 190 | void AudioPolicyManagerTest::SetUp() { |
| 191 | mClient.reset(new AudioPolicyManagerTestClient); |
| 192 | mManager.reset(new AudioPolicyTestManager(mClient.get())); |
| 193 | mManager->getConfig().setDefault(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 194 | SetUpConfig(&mManager->getConfig()); // Subclasses may want to customize the config. |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 195 | ASSERT_EQ(NO_ERROR, mManager->initialize()); |
| 196 | ASSERT_EQ(NO_ERROR, mManager->initCheck()); |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 197 | } |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 198 | |
| 199 | void AudioPolicyManagerTest::TearDown() { |
| 200 | mManager.reset(); |
| 201 | mClient.reset(); |
| 202 | } |
| 203 | |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 204 | void AudioPolicyManagerTest::dumpToLog() { |
Mikhail Naganov | 21b4336 | 2018-06-04 10:37:09 -0700 | [diff] [blame] | 205 | int pipefd[2]; |
| 206 | ASSERT_NE(-1, pipe(pipefd)); |
| 207 | pid_t cpid = fork(); |
| 208 | ASSERT_NE(-1, cpid); |
| 209 | if (cpid == 0) { |
| 210 | // Child process reads from the pipe and logs. |
| 211 | close(pipefd[1]); |
| 212 | std::string line; |
| 213 | char buf; |
| 214 | while (read(pipefd[0], &buf, sizeof(buf)) > 0) { |
| 215 | if (buf != '\n') { |
| 216 | line += buf; |
| 217 | } else { |
| 218 | ALOGI("%s", line.c_str()); |
| 219 | line = ""; |
| 220 | } |
| 221 | } |
| 222 | if (!line.empty()) ALOGI("%s", line.c_str()); |
| 223 | close(pipefd[0]); |
| 224 | _exit(EXIT_SUCCESS); |
| 225 | } else { |
| 226 | // Parent does the dump and checks the status code. |
| 227 | close(pipefd[0]); |
| 228 | ASSERT_EQ(NO_ERROR, mManager->dump(pipefd[1])); |
| 229 | close(pipefd[1]); |
| 230 | wait(NULL); // Wait for the child to exit. |
| 231 | } |
| 232 | } |
| 233 | |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 234 | void AudioPolicyManagerTest::getOutputForAttr( |
| 235 | audio_port_handle_t *selectedDeviceId, |
| 236 | audio_format_t format, |
| 237 | int channelMask, |
| 238 | int sampleRate, |
| 239 | audio_output_flags_t flags, |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 240 | audio_port_handle_t *portId, |
| 241 | audio_attributes_t attr) { |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 242 | audio_io_handle_t output = AUDIO_PORT_HANDLE_NONE; |
| 243 | audio_stream_type_t stream = AUDIO_STREAM_DEFAULT; |
| 244 | audio_config_t config = AUDIO_CONFIG_INITIALIZER; |
| 245 | config.sample_rate = sampleRate; |
| 246 | config.channel_mask = channelMask; |
| 247 | config.format = format; |
| 248 | *selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 249 | audio_port_handle_t localPortId; |
| 250 | if (!portId) portId = &localPortId; |
| 251 | *portId = AUDIO_PORT_HANDLE_NONE; |
| 252 | ASSERT_EQ(OK, mManager->getOutputForAttr( |
| 253 | &attr, &output, AUDIO_SESSION_NONE, &stream, 0 /*uid*/, &config, &flags, |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 254 | selectedDeviceId, portId, {})); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 255 | ASSERT_NE(AUDIO_PORT_HANDLE_NONE, *portId); |
| 256 | } |
| 257 | |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 258 | void AudioPolicyManagerTest::getInputForAttr( |
| 259 | const audio_attributes_t &attr, |
| 260 | audio_unique_id_t riid, |
| 261 | audio_port_handle_t *selectedDeviceId, |
| 262 | audio_format_t format, |
| 263 | int channelMask, |
| 264 | int sampleRate, |
| 265 | audio_input_flags_t flags, |
| 266 | audio_port_handle_t *portId) { |
| 267 | audio_io_handle_t input = AUDIO_PORT_HANDLE_NONE; |
| 268 | audio_config_base_t config = AUDIO_CONFIG_BASE_INITIALIZER; |
| 269 | config.sample_rate = sampleRate; |
| 270 | config.channel_mask = channelMask; |
| 271 | config.format = format; |
| 272 | *selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 273 | audio_port_handle_t localPortId; |
| 274 | if (!portId) portId = &localPortId; |
| 275 | *portId = AUDIO_PORT_HANDLE_NONE; |
| 276 | AudioPolicyInterface::input_type_t inputType; |
| 277 | ASSERT_EQ(OK, mManager->getInputForAttr( |
| 278 | &attr, &input, riid, AUDIO_SESSION_NONE, 0 /*uid*/, &config, flags, |
| 279 | selectedDeviceId, &inputType, portId)); |
| 280 | ASSERT_NE(AUDIO_PORT_HANDLE_NONE, *portId); |
| 281 | } |
| 282 | |
| 283 | void AudioPolicyManagerTest::findDevicePort(audio_port_role_t role, |
| 284 | audio_devices_t deviceType, const std::string &address, audio_port &foundPort) { |
| 285 | uint32_t numPorts = 0; |
| 286 | uint32_t generation1; |
| 287 | status_t ret; |
| 288 | |
| 289 | ret = mManager->listAudioPorts(role, AUDIO_PORT_TYPE_DEVICE, &numPorts, nullptr, &generation1); |
| 290 | ASSERT_EQ(NO_ERROR, ret); |
| 291 | |
| 292 | uint32_t generation2; |
| 293 | struct audio_port ports[numPorts]; |
| 294 | ret = mManager->listAudioPorts(role, AUDIO_PORT_TYPE_DEVICE, &numPorts, ports, &generation2); |
| 295 | ASSERT_EQ(NO_ERROR, ret); |
| 296 | ASSERT_EQ(generation1, generation2); |
| 297 | |
| 298 | for (const auto &port : ports) { |
| 299 | if (port.role == role && port.ext.device.type == deviceType && |
| 300 | (strncmp(port.ext.device.address, address.c_str(), |
| 301 | AUDIO_DEVICE_MAX_ADDRESS_LEN) == 0)) { |
| 302 | foundPort = port; |
| 303 | return; |
| 304 | } |
| 305 | } |
| 306 | GTEST_FAIL(); |
| 307 | } |
| 308 | |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 309 | |
| 310 | TEST_F(AudioPolicyManagerTest, InitSuccess) { |
| 311 | // SetUp must finish with no assertions. |
| 312 | } |
| 313 | |
| 314 | TEST_F(AudioPolicyManagerTest, Dump) { |
| 315 | dumpToLog(); |
| 316 | } |
| 317 | |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 318 | TEST_F(AudioPolicyManagerTest, CreateAudioPatchFailure) { |
| 319 | audio_patch patch{}; |
| 320 | audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE; |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 321 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 322 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(nullptr, &handle, 0)); |
| 323 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(&patch, nullptr, 0)); |
| 324 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(&patch, &handle, 0)); |
| 325 | patch.num_sources = AUDIO_PATCH_PORTS_MAX + 1; |
| 326 | patch.num_sinks = 1; |
| 327 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(&patch, &handle, 0)); |
| 328 | patch.num_sources = 1; |
| 329 | patch.num_sinks = AUDIO_PATCH_PORTS_MAX + 1; |
| 330 | ASSERT_EQ(BAD_VALUE, mManager->createAudioPatch(&patch, &handle, 0)); |
| 331 | patch.num_sources = 2; |
| 332 | patch.num_sinks = 1; |
| 333 | ASSERT_EQ(INVALID_OPERATION, mManager->createAudioPatch(&patch, &handle, 0)); |
| 334 | patch = {}; |
| 335 | patch.num_sources = 1; |
| 336 | patch.sources[0].role = AUDIO_PORT_ROLE_SINK; |
| 337 | patch.num_sinks = 1; |
| 338 | patch.sinks[0].role = AUDIO_PORT_ROLE_SINK; |
| 339 | ASSERT_EQ(INVALID_OPERATION, mManager->createAudioPatch(&patch, &handle, 0)); |
| 340 | patch = {}; |
| 341 | patch.num_sources = 1; |
| 342 | patch.sources[0].role = AUDIO_PORT_ROLE_SOURCE; |
| 343 | patch.num_sinks = 1; |
| 344 | patch.sinks[0].role = AUDIO_PORT_ROLE_SOURCE; |
| 345 | ASSERT_EQ(INVALID_OPERATION, mManager->createAudioPatch(&patch, &handle, 0)); |
| 346 | // Verify that the handle is left unchanged. |
| 347 | ASSERT_EQ(AUDIO_PATCH_HANDLE_NONE, handle); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 348 | ASSERT_EQ(0, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | TEST_F(AudioPolicyManagerTest, CreateAudioPatchFromMix) { |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 352 | audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE; |
| 353 | uid_t uid = 42; |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 354 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | dc76968 | 2018-05-04 15:34:08 -0700 | [diff] [blame] | 355 | ASSERT_FALSE(mManager->getConfig().getAvailableInputDevices().isEmpty()); |
| 356 | PatchBuilder patchBuilder; |
| 357 | patchBuilder.addSource(mManager->getConfig().getAvailableInputDevices()[0]). |
| 358 | addSink(mManager->getConfig().getDefaultOutputDevice()); |
| 359 | ASSERT_EQ(NO_ERROR, mManager->createAudioPatch(patchBuilder.patch(), &handle, uid)); |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 360 | ASSERT_NE(AUDIO_PATCH_HANDLE_NONE, handle); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 361 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | 04a8663 | 2017-12-15 18:01:42 -0800 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | // TODO: Add patch creation tests that involve already existing patch |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 365 | |
| 366 | class AudioPolicyManagerTestMsd : public AudioPolicyManagerTest { |
| 367 | protected: |
| 368 | void SetUpConfig(AudioPolicyConfig *config) override; |
| 369 | void TearDown() override; |
| 370 | |
| 371 | sp<DeviceDescriptor> mMsdOutputDevice; |
| 372 | sp<DeviceDescriptor> mMsdInputDevice; |
| 373 | }; |
| 374 | |
| 375 | void AudioPolicyManagerTestMsd::SetUpConfig(AudioPolicyConfig *config) { |
| 376 | // TODO: Consider using Serializer to load part of the config from a string. |
| 377 | mMsdOutputDevice = new DeviceDescriptor(AUDIO_DEVICE_OUT_BUS); |
| 378 | sp<AudioProfile> pcmOutputProfile = new AudioProfile( |
| 379 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, 48000); |
| 380 | sp<AudioProfile> ac3OutputProfile = new AudioProfile( |
| 381 | AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, 48000); |
| 382 | mMsdOutputDevice->addAudioProfile(pcmOutputProfile); |
| 383 | mMsdOutputDevice->addAudioProfile(ac3OutputProfile); |
| 384 | mMsdInputDevice = new DeviceDescriptor(AUDIO_DEVICE_IN_BUS); |
| 385 | // Match output profile from AudioPolicyConfig::setDefault. |
| 386 | sp<AudioProfile> pcmInputProfile = new AudioProfile( |
| 387 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_STEREO, 44100); |
| 388 | mMsdInputDevice->addAudioProfile(pcmInputProfile); |
| 389 | config->addAvailableDevice(mMsdOutputDevice); |
| 390 | config->addAvailableDevice(mMsdInputDevice); |
| 391 | |
| 392 | sp<HwModule> msdModule = new HwModule(AUDIO_HARDWARE_MODULE_ID_MSD, 2 /*halVersionMajor*/); |
| 393 | HwModuleCollection modules = config->getHwModules(); |
| 394 | modules.add(msdModule); |
| 395 | config->setHwModules(modules); |
| 396 | mMsdOutputDevice->attach(msdModule); |
| 397 | mMsdInputDevice->attach(msdModule); |
| 398 | |
jiabin | 5740f08 | 2019-08-19 15:08:30 -0700 | [diff] [blame] | 399 | sp<OutputProfile> msdOutputProfile = new OutputProfile("msd input"); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 400 | msdOutputProfile->addAudioProfile(pcmOutputProfile); |
| 401 | msdOutputProfile->addSupportedDevice(mMsdOutputDevice); |
| 402 | msdModule->addOutputProfile(msdOutputProfile); |
jiabin | 5740f08 | 2019-08-19 15:08:30 -0700 | [diff] [blame] | 403 | sp<OutputProfile> msdCompressedOutputProfile = new OutputProfile("msd compressed input"); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 404 | msdCompressedOutputProfile->addAudioProfile(ac3OutputProfile); |
| 405 | msdCompressedOutputProfile->setFlags( |
| 406 | AUDIO_OUTPUT_FLAG_DIRECT | AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD | |
| 407 | AUDIO_OUTPUT_FLAG_NON_BLOCKING); |
| 408 | msdCompressedOutputProfile->addSupportedDevice(mMsdOutputDevice); |
| 409 | msdModule->addOutputProfile(msdCompressedOutputProfile); |
| 410 | |
jiabin | 5740f08 | 2019-08-19 15:08:30 -0700 | [diff] [blame] | 411 | sp<InputProfile> msdInputProfile = new InputProfile("msd output"); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 412 | msdInputProfile->addAudioProfile(pcmInputProfile); |
| 413 | msdInputProfile->addSupportedDevice(mMsdInputDevice); |
| 414 | msdModule->addInputProfile(msdInputProfile); |
| 415 | |
| 416 | // Add a profile with another encoding to the default device to test routing |
| 417 | // of streams that are not supported by MSD. |
| 418 | sp<AudioProfile> dtsOutputProfile = new AudioProfile( |
| 419 | AUDIO_FORMAT_DTS, AUDIO_CHANNEL_OUT_5POINT1, 48000); |
| 420 | config->getDefaultOutputDevice()->addAudioProfile(dtsOutputProfile); |
jiabin | 5740f08 | 2019-08-19 15:08:30 -0700 | [diff] [blame] | 421 | sp<OutputProfile> primaryEncodedOutputProfile = new OutputProfile("encoded"); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 422 | primaryEncodedOutputProfile->addAudioProfile(dtsOutputProfile); |
| 423 | primaryEncodedOutputProfile->setFlags(AUDIO_OUTPUT_FLAG_DIRECT); |
| 424 | primaryEncodedOutputProfile->addSupportedDevice(config->getDefaultOutputDevice()); |
| 425 | config->getHwModules().getModuleFromName(AUDIO_HARDWARE_MODULE_ID_PRIMARY)-> |
| 426 | addOutputProfile(primaryEncodedOutputProfile); |
| 427 | } |
| 428 | |
| 429 | void AudioPolicyManagerTestMsd::TearDown() { |
| 430 | mMsdOutputDevice.clear(); |
| 431 | mMsdInputDevice.clear(); |
| 432 | AudioPolicyManagerTest::TearDown(); |
| 433 | } |
| 434 | |
| 435 | TEST_F(AudioPolicyManagerTestMsd, InitSuccess) { |
| 436 | ASSERT_TRUE(mMsdOutputDevice); |
| 437 | ASSERT_TRUE(mMsdInputDevice); |
| 438 | } |
| 439 | |
| 440 | TEST_F(AudioPolicyManagerTestMsd, Dump) { |
| 441 | dumpToLog(); |
| 442 | } |
| 443 | |
| 444 | TEST_F(AudioPolicyManagerTestMsd, PatchCreationOnSetForceUse) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 445 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 446 | mManager->setForceUse(AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND, |
| 447 | AUDIO_POLICY_FORCE_ENCODED_SURROUND_ALWAYS); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 448 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | TEST_F(AudioPolicyManagerTestMsd, GetOutputForAttrEncodedRoutesToMsd) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 452 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 453 | audio_port_handle_t selectedDeviceId; |
| 454 | getOutputForAttr(&selectedDeviceId, |
| 455 | AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, 48000, AUDIO_OUTPUT_FLAG_DIRECT); |
| 456 | ASSERT_EQ(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 457 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | TEST_F(AudioPolicyManagerTestMsd, GetOutputForAttrPcmRoutesToMsd) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 461 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 462 | audio_port_handle_t selectedDeviceId; |
| 463 | getOutputForAttr(&selectedDeviceId, |
| 464 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, 48000); |
| 465 | ASSERT_EQ(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 466 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | TEST_F(AudioPolicyManagerTestMsd, GetOutputForAttrEncodedPlusPcmRoutesToMsd) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 470 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 471 | audio_port_handle_t selectedDeviceId; |
| 472 | getOutputForAttr(&selectedDeviceId, |
| 473 | AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, 48000, AUDIO_OUTPUT_FLAG_DIRECT); |
| 474 | ASSERT_EQ(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 475 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 476 | getOutputForAttr(&selectedDeviceId, |
| 477 | AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, 48000); |
| 478 | ASSERT_EQ(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 479 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | TEST_F(AudioPolicyManagerTestMsd, GetOutputForAttrUnsupportedFormatBypassesMsd) { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 483 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 484 | audio_port_handle_t selectedDeviceId; |
| 485 | getOutputForAttr(&selectedDeviceId, |
| 486 | AUDIO_FORMAT_DTS, AUDIO_CHANNEL_OUT_5POINT1, 48000, AUDIO_OUTPUT_FLAG_DIRECT); |
| 487 | ASSERT_NE(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 488 | ASSERT_EQ(0, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | TEST_F(AudioPolicyManagerTestMsd, GetOutputForAttrFormatSwitching) { |
| 492 | // Switch between formats that are supported and not supported by MSD. |
| 493 | { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 494 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 495 | audio_port_handle_t selectedDeviceId, portId; |
| 496 | getOutputForAttr(&selectedDeviceId, |
| 497 | AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, 48000, AUDIO_OUTPUT_FLAG_DIRECT, |
| 498 | &portId); |
| 499 | ASSERT_EQ(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 500 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 501 | mManager->releaseOutput(portId); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 502 | ASSERT_EQ(1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 503 | } |
| 504 | { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 505 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 506 | audio_port_handle_t selectedDeviceId, portId; |
| 507 | getOutputForAttr(&selectedDeviceId, |
| 508 | AUDIO_FORMAT_DTS, AUDIO_CHANNEL_OUT_5POINT1, 48000, AUDIO_OUTPUT_FLAG_DIRECT, |
| 509 | &portId); |
| 510 | ASSERT_NE(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 511 | ASSERT_EQ(-1, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 512 | mManager->releaseOutput(portId); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 513 | ASSERT_EQ(0, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 514 | } |
| 515 | { |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 516 | const PatchCountCheck patchCount = snapshotPatchCount(); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 517 | audio_port_handle_t selectedDeviceId; |
| 518 | getOutputForAttr(&selectedDeviceId, |
| 519 | AUDIO_FORMAT_AC3, AUDIO_CHANNEL_OUT_5POINT1, 48000, AUDIO_OUTPUT_FLAG_DIRECT); |
| 520 | ASSERT_EQ(selectedDeviceId, mMsdOutputDevice->getId()); |
Mikhail Naganov | d53525f | 2019-01-24 13:15:46 -0800 | [diff] [blame] | 521 | ASSERT_EQ(0, patchCount.deltaFromSnapshot()); |
Mikhail Naganov | df2e359 | 2018-12-19 14:27:42 -0800 | [diff] [blame] | 522 | } |
| 523 | } |
jiabin | f4eb15a | 2019-08-28 15:31:47 -0700 | [diff] [blame] | 524 | |
| 525 | using PolicyMixTuple = std::tuple<audio_usage_t, audio_source_t, uint32_t>; |
| 526 | |
| 527 | class AudioPolicyManagerTestDynamicPolicy : public AudioPolicyManagerTest { |
| 528 | protected: |
| 529 | void SetUp() override; |
| 530 | void TearDown() override; |
| 531 | |
| 532 | status_t addPolicyMix(int mixType, int mixFlag, audio_devices_t deviceType, |
| 533 | std::string mixAddress, const audio_config_t& audioConfig, |
| 534 | const std::vector<PolicyMixTuple>& rules); |
| 535 | void clearPolicyMix(); |
| 536 | void resetManager(const std::string& configFileName); |
| 537 | audio_port_handle_t getDeviceIdFromPatch(const struct audio_patch* patch); |
| 538 | |
| 539 | Vector<AudioMix> mAudioMixes; |
| 540 | const std::string mExecutableDir = base::GetExecutableDirectory(); |
| 541 | const std::string mConfig = mExecutableDir + "/test_audio_policy_configuration.xml"; |
| 542 | const std::string mPrimaryOnlyConfig = mExecutableDir + |
| 543 | "/test_audio_policy_primary_only_configuration.xml"; |
| 544 | const std::string mMixAddress = "remote_submix_media"; |
| 545 | }; |
| 546 | |
| 547 | void AudioPolicyManagerTestDynamicPolicy::SetUp() { |
| 548 | // Override Setup function to use configuration file to do initialization. |
| 549 | mClient.reset(new AudioPolicyManagerTestClient); |
| 550 | resetManager(mConfig); |
| 551 | } |
| 552 | |
| 553 | void AudioPolicyManagerTestDynamicPolicy::TearDown() { |
| 554 | mManager->unregisterPolicyMixes(mAudioMixes); |
| 555 | AudioPolicyManagerTest::TearDown(); |
| 556 | } |
| 557 | |
| 558 | status_t AudioPolicyManagerTestDynamicPolicy::addPolicyMix(int mixType, int mixFlag, |
| 559 | audio_devices_t deviceType, std::string mixAddress, const audio_config_t& audioConfig, |
| 560 | const std::vector<PolicyMixTuple>& rules) { |
| 561 | Vector<AudioMixMatchCriterion> myMixMatchCriteria; |
| 562 | |
| 563 | for(const auto &rule: rules) { |
| 564 | myMixMatchCriteria.add(AudioMixMatchCriterion( |
| 565 | std::get<0>(rule), std::get<1>(rule), std::get<2>(rule))); |
| 566 | } |
| 567 | |
| 568 | AudioMix myAudioMix(myMixMatchCriteria, mixType, audioConfig, mixFlag, |
| 569 | String8(mixAddress.c_str()), 0); |
| 570 | myAudioMix.mDeviceType = deviceType; |
| 571 | // Clear mAudioMix before add new one to make sure we don't add already exist mixes. |
| 572 | mAudioMixes.clear(); |
| 573 | mAudioMixes.add(myAudioMix); |
| 574 | |
| 575 | // As the policy mixes registration may fail at some case, |
| 576 | // caller need to check the returned status. |
| 577 | status_t ret = mManager->registerPolicyMixes(mAudioMixes); |
| 578 | return ret; |
| 579 | } |
| 580 | |
| 581 | void AudioPolicyManagerTestDynamicPolicy::clearPolicyMix() { |
| 582 | if (mManager != nullptr) { |
| 583 | mManager->unregisterPolicyMixes(mAudioMixes); |
| 584 | } |
| 585 | mAudioMixes.clear(); |
| 586 | } |
| 587 | |
| 588 | void AudioPolicyManagerTestDynamicPolicy::resetManager(const std::string& configFileName) { |
| 589 | clearPolicyMix(); |
| 590 | mManager.reset(new AudioPolicyTestManager(mClient.get())); |
| 591 | status_t status = deserializeAudioPolicyFile(configFileName.c_str(), &mManager->getConfig()); |
| 592 | ASSERT_EQ(NO_ERROR, status); |
| 593 | ASSERT_EQ(NO_ERROR, mManager->initialize()); |
| 594 | ASSERT_EQ(NO_ERROR, mManager->initCheck()); |
| 595 | } |
| 596 | |
| 597 | audio_port_handle_t AudioPolicyManagerTestDynamicPolicy::getDeviceIdFromPatch( |
| 598 | const struct audio_patch* patch) { |
| 599 | // The logic here is the same as the one in AudioIoDescriptor. |
| 600 | // Note this function is aim to get routed device id for test. |
| 601 | // In that case, device to device patch is not expected here. |
| 602 | if (patch->num_sources != 0 && patch->num_sinks != 0) { |
| 603 | if (patch->sources[0].type == AUDIO_PORT_TYPE_MIX) { |
| 604 | return patch->sinks[0].id; |
| 605 | } else { |
| 606 | return patch->sources[0].id; |
| 607 | } |
| 608 | } |
| 609 | return AUDIO_PORT_HANDLE_NONE; |
| 610 | } |
| 611 | |
| 612 | TEST_F(AudioPolicyManagerTestDynamicPolicy, InitSuccess) { |
| 613 | // SetUp must finish with no assertions. |
| 614 | } |
| 615 | |
| 616 | TEST_F(AudioPolicyManagerTestDynamicPolicy, Dump) { |
| 617 | dumpToLog(); |
| 618 | } |
| 619 | |
| 620 | TEST_F(AudioPolicyManagerTestDynamicPolicy, RegisterPolicyMixes) { |
| 621 | status_t ret; |
| 622 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 623 | |
| 624 | // Only capture of playback is allowed in LOOP_BACK &RENDER mode |
| 625 | ret = addPolicyMix(MIX_TYPE_RECORDERS, MIX_ROUTE_FLAG_LOOP_BACK_AND_RENDER, |
| 626 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, "", audioConfig, std::vector<PolicyMixTuple>()); |
| 627 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 628 | |
| 629 | // Fail due to the device is already connected. |
| 630 | clearPolicyMix(); |
| 631 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 632 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, "", audioConfig, std::vector<PolicyMixTuple>()); |
| 633 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 634 | |
| 635 | // The first time to register policy mixes with valid parameter should succeed. |
| 636 | clearPolicyMix(); |
| 637 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 638 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 639 | audioConfig.sample_rate = 48000; |
| 640 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 641 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, mMixAddress, audioConfig, |
| 642 | std::vector<PolicyMixTuple>()); |
| 643 | ASSERT_EQ(NO_ERROR, ret); |
| 644 | // Registering the same policy mixes should fail. |
| 645 | ret = mManager->registerPolicyMixes(mAudioMixes); |
| 646 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 647 | |
| 648 | // Registration should fail due to not module for remote submix found. |
| 649 | resetManager(mPrimaryOnlyConfig); |
| 650 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 651 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, "", audioConfig, std::vector<PolicyMixTuple>()); |
| 652 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 653 | |
| 654 | // Registration should fail due to device not found. |
| 655 | // Note that earpiece is not present in the test configuration file. |
| 656 | // This will need to be updated if earpiece is added in the test configuration file. |
| 657 | resetManager(mConfig); |
| 658 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 659 | AUDIO_DEVICE_OUT_EARPIECE, "", audioConfig, std::vector<PolicyMixTuple>()); |
| 660 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 661 | |
| 662 | // Registration should fail due to output not found. |
| 663 | clearPolicyMix(); |
| 664 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 665 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, "", audioConfig, std::vector<PolicyMixTuple>()); |
| 666 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 667 | |
| 668 | // The first time to register valid policy mixes should succeed. |
| 669 | clearPolicyMix(); |
| 670 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_RENDER, |
| 671 | AUDIO_DEVICE_OUT_SPEAKER, "", audioConfig, std::vector<PolicyMixTuple>()); |
| 672 | ASSERT_EQ(NO_ERROR, ret); |
| 673 | // Registering the same policy mixes should fail. |
| 674 | ret = mManager->registerPolicyMixes(mAudioMixes); |
| 675 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 676 | } |
| 677 | |
| 678 | TEST_F(AudioPolicyManagerTestDynamicPolicy, UnregisterPolicyMixes) { |
| 679 | status_t ret; |
| 680 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 681 | |
| 682 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 683 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 684 | audioConfig.sample_rate = 48000; |
| 685 | ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 686 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, mMixAddress, audioConfig, |
| 687 | std::vector<PolicyMixTuple>()); |
| 688 | ASSERT_EQ(NO_ERROR, ret); |
| 689 | |
| 690 | // After successfully registering policy mixes, it should be able to unregister. |
| 691 | ret = mManager->unregisterPolicyMixes(mAudioMixes); |
| 692 | ASSERT_EQ(NO_ERROR, ret); |
| 693 | |
| 694 | // After unregistering policy mixes successfully, it should fail unregistering |
| 695 | // the same policy mixes as they are not registered. |
| 696 | ret = mManager->unregisterPolicyMixes(mAudioMixes); |
| 697 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 698 | |
| 699 | resetManager(mPrimaryOnlyConfig); |
| 700 | // Create a fake policy mixes, the unregistration should fail due to no remote |
| 701 | // submix module found. |
| 702 | mAudioMixes.add(AudioMix(Vector<AudioMixMatchCriterion>(), MIX_TYPE_PLAYERS, |
| 703 | audioConfig, MIX_ROUTE_FLAG_LOOP_BACK, String8(mMixAddress.c_str()), 0)); |
| 704 | ret = mManager->unregisterPolicyMixes(mAudioMixes); |
| 705 | ASSERT_EQ(INVALID_OPERATION, ret); |
| 706 | } |
| 707 | |
| 708 | class AudioPolicyManagerTestDPPlaybackReRouting : public AudioPolicyManagerTestDynamicPolicy, |
| 709 | public testing::WithParamInterface<audio_attributes_t> { |
| 710 | protected: |
| 711 | void SetUp() override; |
| 712 | void TearDown() override; |
| 713 | |
| 714 | std::unique_ptr<RecordingActivityTracker> mTracker; |
| 715 | |
| 716 | std::vector<PolicyMixTuple> mUsageRules = { |
| 717 | {AUDIO_USAGE_MEDIA, AUDIO_SOURCE_DEFAULT, RULE_MATCH_ATTRIBUTE_USAGE}, |
| 718 | {AUDIO_USAGE_ALARM, AUDIO_SOURCE_DEFAULT, RULE_MATCH_ATTRIBUTE_USAGE} |
| 719 | }; |
| 720 | |
| 721 | struct audio_port mInjectionPort; |
| 722 | audio_port_handle_t mPortId = AUDIO_PORT_HANDLE_NONE; |
| 723 | }; |
| 724 | |
| 725 | void AudioPolicyManagerTestDPPlaybackReRouting::SetUp() { |
| 726 | AudioPolicyManagerTestDynamicPolicy::SetUp(); |
| 727 | |
| 728 | mTracker.reset(new RecordingActivityTracker()); |
| 729 | |
| 730 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 731 | audioConfig.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 732 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 733 | audioConfig.sample_rate = 48000; |
| 734 | status_t ret = addPolicyMix(MIX_TYPE_PLAYERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 735 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, mMixAddress, audioConfig, mUsageRules); |
| 736 | ASSERT_EQ(NO_ERROR, ret); |
| 737 | |
| 738 | struct audio_port extractionPort; |
| 739 | findDevicePort(AUDIO_PORT_ROLE_SOURCE, AUDIO_DEVICE_IN_REMOTE_SUBMIX, |
| 740 | mMixAddress, extractionPort); |
| 741 | |
| 742 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 743 | audio_source_t source = AUDIO_SOURCE_REMOTE_SUBMIX; |
| 744 | audio_attributes_t attr = {AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, source, 0, ""}; |
| 745 | std::string tags = "addr=" + mMixAddress; |
| 746 | strncpy(attr.tags, tags.c_str(), AUDIO_ATTRIBUTES_TAGS_MAX_SIZE - 1); |
| 747 | getInputForAttr(attr, mTracker->getRiid(), &selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, |
| 748 | AUDIO_CHANNEL_IN_STEREO, 48000 /*sampleRate*/, AUDIO_INPUT_FLAG_NONE, &mPortId); |
| 749 | ASSERT_EQ(NO_ERROR, mManager->startInput(mPortId)); |
| 750 | ASSERT_EQ(extractionPort.id, selectedDeviceId); |
| 751 | |
| 752 | findDevicePort(AUDIO_PORT_ROLE_SINK, AUDIO_DEVICE_OUT_REMOTE_SUBMIX, |
| 753 | mMixAddress, mInjectionPort); |
| 754 | } |
| 755 | |
| 756 | void AudioPolicyManagerTestDPPlaybackReRouting::TearDown() { |
| 757 | mManager->stopInput(mPortId); |
| 758 | AudioPolicyManagerTestDynamicPolicy::TearDown(); |
| 759 | } |
| 760 | |
| 761 | TEST_F(AudioPolicyManagerTestDPPlaybackReRouting, InitSuccess) { |
| 762 | // SetUp must finish with no assertions |
| 763 | } |
| 764 | |
| 765 | TEST_F(AudioPolicyManagerTestDPPlaybackReRouting, Dump) { |
| 766 | dumpToLog(); |
| 767 | } |
| 768 | |
| 769 | TEST_P(AudioPolicyManagerTestDPPlaybackReRouting, PlaybackReRouting) { |
| 770 | const audio_attributes_t attr = GetParam(); |
| 771 | const audio_usage_t usage = attr.usage; |
| 772 | |
| 773 | audio_port_handle_t playbackRoutedPortId; |
| 774 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE; |
| 775 | getOutputForAttr(&playbackRoutedPortId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
| 776 | 48000 /*sampleRate*/, AUDIO_OUTPUT_FLAG_NONE, &portId, attr); |
| 777 | if (std::find_if(begin(mUsageRules), end(mUsageRules), [&usage](const auto &usageRule) { |
| 778 | return (std::get<0>(usageRule) == usage) && |
| 779 | (std::get<2>(usageRule) == RULE_MATCH_ATTRIBUTE_USAGE);}) != end(mUsageRules) || |
| 780 | (strncmp(attr.tags, "addr=", strlen("addr=")) == 0 && |
| 781 | strncmp(attr.tags + strlen("addr="), mMixAddress.c_str(), |
| 782 | AUDIO_ATTRIBUTES_TAGS_MAX_SIZE - strlen("addr=") - 1) == 0)) { |
| 783 | EXPECT_EQ(mInjectionPort.id, playbackRoutedPortId); |
| 784 | } else { |
| 785 | EXPECT_NE(mInjectionPort.id, playbackRoutedPortId); |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | INSTANTIATE_TEST_CASE_P( |
| 790 | PlaybackReroutingUsageMatch, |
| 791 | AudioPolicyManagerTestDPPlaybackReRouting, |
| 792 | testing::Values( |
| 793 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_MEDIA, |
| 794 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 795 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_ALARM, |
| 796 | AUDIO_SOURCE_DEFAULT, 0, ""} |
| 797 | ) |
| 798 | ); |
| 799 | |
| 800 | INSTANTIATE_TEST_CASE_P( |
| 801 | PlaybackReroutingAddressPriorityMatch, |
| 802 | AudioPolicyManagerTestDPPlaybackReRouting, |
| 803 | testing::Values( |
| 804 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_MEDIA, |
| 805 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 806 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_VOICE_COMMUNICATION, |
| 807 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 808 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 809 | AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING, |
| 810 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 811 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_ALARM, |
| 812 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 813 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_NOTIFICATION, |
| 814 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 815 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 816 | AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE, |
| 817 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 818 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 819 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST, |
| 820 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 821 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 822 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT, |
| 823 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 824 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 825 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED, |
| 826 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 827 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_NOTIFICATION_EVENT, |
| 828 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 829 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 830 | AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY, |
| 831 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 832 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 833 | AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE, |
| 834 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 835 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 836 | AUDIO_USAGE_ASSISTANCE_SONIFICATION, |
| 837 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 838 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_GAME, |
| 839 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 840 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_VIRTUAL_SOURCE, |
| 841 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}, |
| 842 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_ASSISTANT, |
| 843 | AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"} |
| 844 | ) |
| 845 | ); |
| 846 | |
| 847 | INSTANTIATE_TEST_CASE_P( |
| 848 | PlaybackReroutingUnHandledUsages, |
| 849 | AudioPolicyManagerTestDPPlaybackReRouting, |
| 850 | testing::Values( |
| 851 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_VOICE_COMMUNICATION, |
| 852 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 853 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 854 | AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING, |
| 855 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 856 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_NOTIFICATION, |
| 857 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 858 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 859 | AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE, |
| 860 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 861 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 862 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST, |
| 863 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 864 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 865 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT, |
| 866 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 867 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 868 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED, |
| 869 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 870 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_NOTIFICATION_EVENT, |
| 871 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 872 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 873 | AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY, |
| 874 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 875 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 876 | AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE, |
| 877 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 878 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, |
| 879 | AUDIO_USAGE_ASSISTANCE_SONIFICATION, |
| 880 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 881 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_GAME, |
| 882 | AUDIO_SOURCE_DEFAULT, 0, ""}, |
| 883 | (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_ASSISTANT, |
| 884 | AUDIO_SOURCE_DEFAULT, 0, ""} |
| 885 | ) |
| 886 | ); |
| 887 | |
| 888 | class AudioPolicyManagerTestDPMixRecordInjection : public AudioPolicyManagerTestDynamicPolicy, |
| 889 | public testing::WithParamInterface<audio_attributes_t> { |
| 890 | protected: |
| 891 | void SetUp() override; |
| 892 | void TearDown() override; |
| 893 | |
| 894 | std::unique_ptr<RecordingActivityTracker> mTracker; |
| 895 | |
| 896 | std::vector<PolicyMixTuple> mSourceRules = { |
| 897 | {AUDIO_USAGE_UNKNOWN, AUDIO_SOURCE_CAMCORDER, RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET}, |
| 898 | {AUDIO_USAGE_UNKNOWN, AUDIO_SOURCE_MIC, RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET}, |
| 899 | {AUDIO_USAGE_UNKNOWN, AUDIO_SOURCE_VOICE_COMMUNICATION, RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET} |
| 900 | }; |
| 901 | |
| 902 | struct audio_port mExtractionPort; |
| 903 | audio_port_handle_t mPortId = AUDIO_PORT_HANDLE_NONE; |
| 904 | }; |
| 905 | |
| 906 | void AudioPolicyManagerTestDPMixRecordInjection::SetUp() { |
| 907 | AudioPolicyManagerTestDynamicPolicy::SetUp(); |
| 908 | |
| 909 | mTracker.reset(new RecordingActivityTracker()); |
| 910 | |
| 911 | audio_config_t audioConfig = AUDIO_CONFIG_INITIALIZER; |
| 912 | audioConfig.channel_mask = AUDIO_CHANNEL_IN_STEREO; |
| 913 | audioConfig.format = AUDIO_FORMAT_PCM_16_BIT; |
| 914 | audioConfig.sample_rate = 48000; |
| 915 | status_t ret = addPolicyMix(MIX_TYPE_RECORDERS, MIX_ROUTE_FLAG_LOOP_BACK, |
| 916 | AUDIO_DEVICE_IN_REMOTE_SUBMIX, mMixAddress, audioConfig, mSourceRules); |
| 917 | ASSERT_EQ(NO_ERROR, ret); |
| 918 | |
| 919 | struct audio_port injectionPort; |
| 920 | findDevicePort(AUDIO_PORT_ROLE_SINK, AUDIO_DEVICE_OUT_REMOTE_SUBMIX, |
| 921 | mMixAddress, injectionPort); |
| 922 | |
| 923 | audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 924 | audio_usage_t usage = AUDIO_USAGE_VIRTUAL_SOURCE; |
| 925 | audio_attributes_t attr = {AUDIO_CONTENT_TYPE_UNKNOWN, usage, AUDIO_SOURCE_DEFAULT, 0, ""}; |
| 926 | std::string tags = std::string("addr=") + mMixAddress; |
| 927 | strncpy(attr.tags, tags.c_str(), AUDIO_ATTRIBUTES_TAGS_MAX_SIZE - 1); |
| 928 | getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, |
| 929 | 48000 /*sampleRate*/, AUDIO_OUTPUT_FLAG_NONE, &mPortId, attr); |
| 930 | ASSERT_EQ(NO_ERROR, mManager->startOutput(mPortId)); |
| 931 | ASSERT_EQ(injectionPort.id, getDeviceIdFromPatch(mClient->getLastAddedPatch())); |
| 932 | |
| 933 | findDevicePort(AUDIO_PORT_ROLE_SOURCE, AUDIO_DEVICE_IN_REMOTE_SUBMIX, |
| 934 | mMixAddress, mExtractionPort); |
| 935 | } |
| 936 | |
| 937 | void AudioPolicyManagerTestDPMixRecordInjection::TearDown() { |
| 938 | mManager->stopOutput(mPortId); |
| 939 | AudioPolicyManagerTestDynamicPolicy::TearDown(); |
| 940 | } |
| 941 | |
| 942 | TEST_F(AudioPolicyManagerTestDPMixRecordInjection, InitSuccess) { |
| 943 | // SetUp mush finish with no assertions. |
| 944 | } |
| 945 | |
| 946 | TEST_F(AudioPolicyManagerTestDPMixRecordInjection, Dump) { |
| 947 | dumpToLog(); |
| 948 | } |
| 949 | |
| 950 | TEST_P(AudioPolicyManagerTestDPMixRecordInjection, RecordingInjection) { |
| 951 | const audio_attributes_t attr = GetParam(); |
| 952 | const audio_source_t source = attr.source; |
| 953 | |
| 954 | audio_port_handle_t captureRoutedPortId; |
| 955 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE; |
| 956 | getInputForAttr(attr, mTracker->getRiid(), &captureRoutedPortId, AUDIO_FORMAT_PCM_16_BIT, |
| 957 | AUDIO_CHANNEL_IN_STEREO, 48000 /*sampleRate*/, AUDIO_INPUT_FLAG_NONE, &portId); |
| 958 | if (std::find_if(begin(mSourceRules), end(mSourceRules), [&source](const auto &sourceRule) { |
| 959 | return (std::get<1>(sourceRule) == source) && |
| 960 | (std::get<2>(sourceRule) == RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET);}) |
| 961 | != end(mSourceRules)) { |
| 962 | EXPECT_EQ(mExtractionPort.id, captureRoutedPortId); |
| 963 | } else { |
| 964 | EXPECT_NE(mExtractionPort.id, captureRoutedPortId); |
| 965 | } |
| 966 | } |
| 967 | |
| 968 | // No address priority rule for remote recording, address is a "don't care" |
| 969 | INSTANTIATE_TEST_CASE_P( |
| 970 | RecordInjectionSourceMatch, |
| 971 | AudioPolicyManagerTestDPMixRecordInjection, |
| 972 | testing::Values( |
| 973 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 974 | AUDIO_SOURCE_CAMCORDER, 0, ""}, |
| 975 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 976 | AUDIO_SOURCE_CAMCORDER, 0, "addr=remote_submix_media"}, |
| 977 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 978 | AUDIO_SOURCE_MIC, 0, "addr=remote_submix_media"}, |
| 979 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 980 | AUDIO_SOURCE_MIC, 0, ""}, |
| 981 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 982 | AUDIO_SOURCE_VOICE_COMMUNICATION, 0, ""}, |
| 983 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 984 | AUDIO_SOURCE_VOICE_COMMUNICATION, 0, |
| 985 | "addr=remote_submix_media"} |
| 986 | ) |
| 987 | ); |
| 988 | |
| 989 | // No address priority rule for remote recording |
| 990 | INSTANTIATE_TEST_CASE_P( |
| 991 | RecordInjectionSourceNotMatch, |
| 992 | AudioPolicyManagerTestDPMixRecordInjection, |
| 993 | testing::Values( |
| 994 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 995 | AUDIO_SOURCE_VOICE_RECOGNITION, 0, ""}, |
| 996 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 997 | AUDIO_SOURCE_HOTWORD, 0, ""}, |
| 998 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 999 | AUDIO_SOURCE_VOICE_RECOGNITION, 0, |
| 1000 | "addr=remote_submix_media"}, |
| 1001 | (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, |
| 1002 | AUDIO_SOURCE_HOTWORD, 0, "addr=remote_submix_media"} |
| 1003 | ) |
| 1004 | ); |