Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 30eee0e0 authored by jiabin's avatar jiabin
Browse files

Add test for device connection.

All supported devices declared in audio policy configuration file must
be able to be connected/disconnected.

Bug: 172345306
Test: atest audio_health_tests
Change-Id: Iec13ff8a41eebf7d5ddaa57a48939cab4f31195f
parent b1c141b9
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -45,6 +45,7 @@ cc_test {


cc_test {
cc_test {
    name: "audio_health_tests",
    name: "audio_health_tests",
    require_root: true,


    shared_libs: [
    shared_libs: [
        "libaudiofoundation",
        "libaudiofoundation",
+41 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


#define LOG_TAG "AudioPolicy_Boot_Test"
#define LOG_TAG "AudioPolicy_Boot_Test"


#include <string>
#include <unordered_set>
#include <unordered_set>


#include <gtest/gtest.h>
#include <gtest/gtest.h>
@@ -74,3 +75,43 @@ TEST(AudioHealthTest, AttachedDeviceFound) {
        ASSERT_NE(attachedDevices.end(), attachedDevices.find(desc->type()));
        ASSERT_NE(attachedDevices.end(), attachedDevices.find(desc->type()));
    }
    }
}
}

TEST(AudioHealthTest, ConnectSupportedDevice) {
    AudioPolicyManagerTestClient client;
    AudioPolicyTestManager manager(&client);
    manager.loadConfig();
    ASSERT_NE("AudioPolicyConfig::setDefault", manager.getConfig().getSource());

    DeviceVector devices;
    for (const auto& hwModule : manager.getConfig().getHwModules()) {
        for (const auto& profile : hwModule->getOutputProfiles()) {
            devices.merge(profile->getSupportedDevices());
        }
        for (const auto& profile : hwModule->getInputProfiles()) {
            devices.merge(profile->getSupportedDevices());
        }
    }
    for (const auto& device : devices) {
        if (!audio_is_bluetooth_out_sco_device(device->type()) &&
            !audio_is_bluetooth_in_sco_device(device->type())) {
            // There are two reasons to only test connecting BT devices.
            // 1) It is easier to construct a fake address.
            // 2) This test will be run in presubmit. In that case, it makes sense to make the test
            //    processing time short.
            continue;
        }
        std::string address = "11:22:33:44:55:66";
        ASSERT_EQ(AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE,
                AudioSystem::getDeviceConnectionState(device->type(), address.c_str()));
        ASSERT_EQ(NO_ERROR, AudioSystem::setDeviceConnectionState(
                device->type(), AUDIO_POLICY_DEVICE_STATE_AVAILABLE, address.c_str(),
                "" /*device_name*/, AUDIO_FORMAT_DEFAULT));
        ASSERT_EQ(AUDIO_POLICY_DEVICE_STATE_AVAILABLE,
                AudioSystem::getDeviceConnectionState(device->type(), address.c_str()));
        ASSERT_EQ(NO_ERROR, AudioSystem::setDeviceConnectionState(
                device->type(), AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, address.c_str(),
                "" /*device_name*/, AUDIO_FORMAT_DEFAULT));
        ASSERT_EQ(AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE,
                AudioSystem::getDeviceConnectionState(device->type(), address.c_str()));
    }
}