Don't throw an exception on platforms with no permission API

Using the permission API without guards for Android cause exception
on all other platforms, instead we can print a warning with the same
message if QT_DEBUG is defined to also make it less confusing for other
platforms.

Also, return QPermission::Authorized by default for platforms with no
implementation to this API.

Change-Id: Ie01a6a7f8b6a066685d32c861a56e9ded2c06410
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
bb10
Assam Boudjelthia 2021-05-17 15:12:30 +03:00
parent 6fcc272ac9
commit df022972b0
1 changed files with 21 additions and 8 deletions

View File

@ -3085,14 +3085,11 @@ void QCoreApplication::setEventDispatcher(QAbstractEventDispatcher *eventDispatc
QPromise<QPermission::PermissionResult> promise;
QFuture<QPermission::PermissionResult> future = promise.future();
promise.start();
#ifndef QT_NO_EXCEPTIONS
const auto exception = std::make_exception_ptr(
std::runtime_error("This platform doesn't have an implementation "
"for the application permissions API."));
promise.setException(exception);
#else
promise.addResult(QPermission::Denied);
#endif
#if defined(QT_DEBUG)
qWarning() << "This platform doesn't have an implementation"
<< "for the application permissions API.";
#endif
promise.addResult(QPermission::Authorized);
promise.finish();
return future;
}
@ -3144,6 +3141,10 @@ void QCoreApplication::setEventDispatcher(QAbstractEventDispatcher *eventDispatc
\snippet permissions/permissions.cpp Request camera permission sync
\note Any platform that doesn't have an implementation for this API,
returns QPermission::Authorized by default. Currently, only Android
has an implemtation for this API.
\since 6.2
\sa checkPermission()
*/
@ -3172,6 +3173,10 @@ QCoreApplication::requestPermission(QPermission::PermisionType permission)
\snippet permissions/permissions.cpp Request camera permission sync on Android
\note Any platform that doesn't have an implementation for this API,
returns QPermission::Authorized by default. Currently, only Android
has an implemtation for this API.
\since 6.2
\sa checkPermission()
*/
@ -3194,6 +3199,10 @@ QCoreApplication::requestPermission(const QString &permission)
\snippet permissions/permissions.cpp Check camera permission sync
\note Any platform that doesn't have an implementation for this API,
returns QPermission::Authorized by default. Currently, only Android
has an implemtation for this API.
\since 6.2
\sa requestPermission()
*/
@ -3217,6 +3226,10 @@ QCoreApplication::checkPermission(QPermission::PermisionType permission)
\snippet permissions/permissions.cpp Check camera permission sync on Android
\note Any platform that doesn't have an implementation for this API,
returns QPermission::Authorized by default. Currently, only Android
has an implemtation for this API.
\since 6.2
\sa requestPermission()
*/