From df022972b0860400449e3a6dabab63ea4e4656ac Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Mon, 17 May 2021 15:12:30 +0300 Subject: [PATCH] Don't throw an exception on platforms with no permission API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Tor Arne Vestbø --- src/corelib/kernel/qcoreapplication.cpp | 29 ++++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index bb874569ab..0cb7f30644 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -3085,14 +3085,11 @@ void QCoreApplication::setEventDispatcher(QAbstractEventDispatcher *eventDispatc QPromise promise; QFuture 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() */