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

Commit 799fc5db authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 7566880 from 997554db to sc-release

Change-Id: Ieaa57be5fa25d3130ee682b4be297cfe742bc67f
parents cc6e4b7e 997554db
Loading
Loading
Loading
Loading
+16 −24
Original line number Diff line number Diff line
@@ -53,6 +53,11 @@ TEST_P(AudioHidlDeviceTest, GetMicrophonesTest) {
        GTEST_SKIP() << "getMicrophones is not supported";  // returns
    }
    ASSERT_OK(res);

#if MAJOR_VERSION <= 6
    // In V7, 'getActiveMicrophones' is tested by the 'MicrophoneInfoInputStream'
    // test which uses the actual configuration of the device.

    if (microphones.size() > 0) {
        // When there is microphone on the phone, try to open an input stream
        // and query for the active microphones.
@@ -60,30 +65,13 @@ TEST_P(AudioHidlDeviceTest, GetMicrophonesTest) {
            "Make sure getMicrophones always succeeds"
            "and getActiveMicrophones always succeeds when recording from these microphones.");
        AudioConfig config{};
#if MAJOR_VERSION <= 6
        config.channelMask = mkEnumBitfield(AudioChannelMask::IN_MONO);
        config.sampleRateHz = 8000;
        config.format = AudioFormat::PCM_16_BIT;
        auto flags = hidl_bitfield<AudioInputFlag>(AudioInputFlag::NONE);
        const SinkMetadata initMetadata = {{{.source = AudioSource::MIC, .gain = 1}}};
#elif MAJOR_VERSION >= 7
        config.base.channelMask = toString(xsd::AudioChannelMask::AUDIO_CHANNEL_IN_MONO);
        config.base.sampleRateHz = 8000;
        config.base.format = toString(xsd::AudioFormat::AUDIO_FORMAT_PCM_16_BIT);
        hidl_vec<hidl_string> flags;
        const SinkMetadata initMetadata = {
                {{.source = toString(xsd::AudioSource::AUDIO_SOURCE_MIC),
                  .gain = 1,
                  .tags = {},
                  .channelMask = toString(xsd::AudioChannelMask::AUDIO_CHANNEL_IN_MONO)}}};
#endif
        for (auto microphone : microphones) {
#if MAJOR_VERSION <= 6
            if (microphone.deviceAddress.device != AudioDevice::IN_BUILTIN_MIC) {
#elif MAJOR_VERSION >= 7
            if (xsd::stringToAudioDevice(microphone.deviceAddress.deviceType) !=
                xsd::AudioDevice::AUDIO_DEVICE_IN_BUILTIN_MIC) {
#endif
                continue;
            }
            sp<IStreamIn> stream;
@@ -106,6 +94,7 @@ TEST_P(AudioHidlDeviceTest, GetMicrophonesTest) {
            EXPECT_NE(0U, activeMicrophones.size());
        }
    }
#endif  // MAJOR_VERSION <= 6
}

TEST_P(AudioHidlDeviceTest, SetConnectedState) {
@@ -343,18 +332,21 @@ TEST_P(AudioPrimaryHidlTest, setMode) {
#endif

    for (int mode : {-2, -1, maxMode + 1}) {
        ASSERT_RESULT(Result::INVALID_ARGUMENTS, getDevice()->setMode(AudioMode(mode)))
        EXPECT_RESULT(Result::INVALID_ARGUMENTS, getDevice()->setMode(AudioMode(mode)))
                << "mode=" << mode;
    }
    // Test valid values
    for (AudioMode mode : {AudioMode::IN_CALL, AudioMode::IN_COMMUNICATION, AudioMode::RINGTONE,
                           AudioMode::NORMAL /* Make sure to leave the test in normal mode */}) {
        ASSERT_OK(getDevice()->setMode(mode)) << "mode=" << toString(mode);
    }

    // AudioMode::CALL_SCREEN as support is optional
#if MAJOR_VERSION >= 6
    ASSERT_RESULT(okOrNotSupportedOrInvalidArgs, getDevice()->setMode(AudioMode::CALL_SCREEN));
    EXPECT_RESULT(okOrNotSupportedOrInvalidArgs, getDevice()->setMode(AudioMode::CALL_SCREEN));
#endif
    // Test valid values
    for (AudioMode mode : {AudioMode::IN_CALL, AudioMode::IN_COMMUNICATION, AudioMode::RINGTONE,
                           AudioMode::NORMAL}) {
        EXPECT_OK(getDevice()->setMode(mode)) << "mode=" << toString(mode);
    }
    // Make sure to leave the test in normal mode
    getDevice()->setMode(AudioMode::NORMAL);
}

TEST_P(AudioPrimaryHidlTest, setBtHfpSampleRate) {
+61 −0
Original line number Diff line number Diff line
@@ -839,3 +839,64 @@ INSTANTIATE_TEST_CASE_P(PcmOnlyConfigInputStream, PcmOnlyConfigInputStreamTest,
                        ::testing::ValuesIn(getInputDevicePcmOnlyConfigParameters()),
                        &DeviceConfigParameterToString);
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(PcmOnlyConfigInputStreamTest);

static const std::vector<DeviceConfigParameter>& getBuiltinMicConfigParameters() {
    static const std::vector<DeviceConfigParameter> parameters = [] {
        auto allParams = getInputDeviceConfigParameters();
        std::vector<DeviceConfigParameter> builtinMicParams;
        std::copy_if(allParams.begin(), allParams.end(), std::back_inserter(builtinMicParams),
                     [](auto cfg) {
                         // The built in mic may participate in various scenarios:
                         // FAST, HW_HOTWORD, MMAP NOIRQ, which are indicated by flags.
                         // We are only interested in testing the simplest scenario w/o any flags.
                         if (!std::get<PARAM_FLAGS>(cfg).empty()) return false;
                         auto maybeSourceDevice = getCachedPolicyConfig().getSourceDeviceForMixPort(
                                 std::get<PARAM_DEVICE_NAME>(std::get<PARAM_DEVICE>(cfg)),
                                 std::get<PARAM_PORT_NAME>(cfg));
                         return maybeSourceDevice.has_value() &&
                                xsd::stringToAudioDevice(maybeSourceDevice.value().deviceType) ==
                                        xsd::AudioDevice::AUDIO_DEVICE_IN_BUILTIN_MIC;
                     });
        return builtinMicParams;
    }();
    return parameters;
}

class MicrophoneInfoInputStreamTest : public InputStreamTest {};

TEST_P(MicrophoneInfoInputStreamTest, GetActiveMicrophones) {
    doc::test(
            "Make sure getActiveMicrophones always succeeds when recording "
            "from the built-in microphone.");
    hidl_vec<MicrophoneInfo> microphones;
    ASSERT_OK(getDevice()->getMicrophones(returnIn(res, microphones)));
    if (res == Result::NOT_SUPPORTED) {
        GTEST_SKIP() << "getMicrophones is not supported";  // returns
    }
    ASSERT_OK(res);

    auto maybeSourceAddress =
            getCachedPolicyConfig().getSourceDeviceForMixPort(getDeviceName(), getMixPortName());
    ASSERT_TRUE(maybeSourceAddress.has_value())
            << "No source device found for mix port " << getMixPortName() << " (module "
            << getDeviceName() << ")";

    for (auto microphone : microphones) {
        if (microphone.deviceAddress == maybeSourceAddress.value()) {
            StreamReader reader(stream.get(), stream->getBufferSize());
            ASSERT_TRUE(reader.start());
            reader.pause();  // This ensures that at least one read has happened.
            EXPECT_FALSE(reader.hasError());

            hidl_vec<MicrophoneInfo> activeMicrophones;
            ASSERT_OK(stream->getActiveMicrophones(returnIn(res, activeMicrophones)));
            ASSERT_OK(res);
            EXPECT_NE(0U, activeMicrophones.size());
        }
    }
}

INSTANTIATE_TEST_CASE_P(MicrophoneInfoInputStream, MicrophoneInfoInputStreamTest,
                        ::testing::ValuesIn(getBuiltinMicConfigParameters()),
                        &DeviceConfigParameterToString);
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(MicrophoneInfoInputStreamTest);