From 1579efff73a16fd33ccbc859f80ad4ee2c21c70e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pekka=20Geh=C3=B6r?= Date: Tue, 31 May 2022 13:24:46 +0300 Subject: Android: Fix for the permissions issue on the tst_QAudioSource test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When testing for the first time with an emulator with Android version <= 9 after test installation, the test passes because we do not have record permissions from user, so we use the default SampleRates list for QAudioDevice input. We don’t even check to see if these sample rates are supported in opensles. After the fix, the QOpenSLESEngine::supportedSampleRates() function works the same way on the first and second runs of the test and so on. Fixes: QTBUG-99095 Change-Id: I0b61232b5cb38c314913fa60c8bf2fd374b0468f Reviewed-by: Assam Boudjelthia (cherry picked from commit 7a5876caae7696b887a99c053629c638ec55f418) Reviewed-by: Lars Knoll --- src/multimedia/platform/android/audio/qopenslesengine.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/multimedia/platform/android/audio/qopenslesengine.cpp b/src/multimedia/platform/android/audio/qopenslesengine.cpp index 8f6caa5e4..de3912e91 100644 --- a/src/multimedia/platform/android/audio/qopenslesengine.cpp +++ b/src/multimedia/platform/android/audio/qopenslesengine.cpp @@ -153,9 +153,19 @@ static bool hasRecordPermission() return recordPerm.result() == QtAndroidPrivate::Authorized; } +static bool requestPermissions() +{ + const auto recordPerm = QtAndroidPrivate::requestPermission(QtAndroidPrivate::Microphone); + return recordPerm.result() == QtAndroidPrivate::Authorized; +} + QList QOpenSLESEngine::supportedChannelCounts(QAudioDevice::Mode mode) const { - if (mode == QAudioDevice::Input && hasRecordPermission()) { + bool hasRecordPermissions = hasRecordPermission(); + if (!hasRecordPermissions) + hasRecordPermissions = requestPermissions(); + + if (mode == QAudioDevice::Input && hasRecordPermissions) { if (!m_checkedInputFormats) const_cast(this)->checkSupportedInputFormats(); return m_supportedInputChannelCounts; -- cgit v1.2.3