diff options
author | Pekka Gehör <pekka.gehor@qt.io> | 2022-05-31 13:24:46 +0300 |
---|---|---|
committer | Pekka Gehör <pekka.gehor@qt.io> | 2022-06-02 09:40:33 +0300 |
commit | 1579efff73a16fd33ccbc859f80ad4ee2c21c70e (patch) | |
tree | 1efebc2a4fbff44c5e0b6ca6535ba516367fe0de | |
parent | cf3cbfb0e057c8889a55092fef85ea3bf1b554d8 (diff) |
Android: Fix for the permissions issue on the tst_QAudioSource test
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 <assam.boudjelthia@qt.io>
(cherry picked from commit 7a5876caae7696b887a99c053629c638ec55f418)
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r-- | src/multimedia/platform/android/audio/qopenslesengine.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
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<int> 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<QOpenSLESEngine *>(this)->checkSupportedInputFormats(); return m_supportedInputChannelCounts; |