diff options
| author | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2025-07-13 04:47:15 +0300 |
|---|---|---|
| committer | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2025-07-26 04:38:56 +0300 |
| commit | 082e632c614d7f2ea0214e5cb5a77ccf91a264a8 (patch) | |
| tree | 2ea80c004dded28bb349d83877de19bb6ec9ee15 /src/plugins/platforms/android/androidcontentfileengine.cpp | |
| parent | 72c8952c24ed16104ed9849a48f93ad609a9d806 (diff) | |
Android: silence spurious warnings from AndroidContentFileEngine
Move Java calls that might throw exceptions and handle them
with a try/catch by printing the appropriate error messages
where relevant and ignore the ones we don't necessarily need.
For certain operations like query we should check if we have
read permission for the URI first, and only then do the query,
because otherwise it's guaranteed to fail if there's no read
permission.
Pick-to: 6.10 6.9 6.8
Fixes: QTBUG-138013
Fixes: QTBUG-126531
Fixes: QTBUG-123319
Fixes: QTBUG-134912
Fixes: QTBUG-110240
Fixes: QTBUG-132403
Fixes: QTBUG-129324
Change-Id: I8457b6bfd9381bf1a62077520cf9a222311ded7a
Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io>
Diffstat (limited to 'src/plugins/platforms/android/androidcontentfileengine.cpp')
| -rw-r--r-- | src/plugins/platforms/android/androidcontentfileengine.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/plugins/platforms/android/androidcontentfileengine.cpp b/src/plugins/platforms/android/androidcontentfileengine.cpp index 7efe4d52d4c..46d78c688c5 100644 --- a/src/plugins/platforms/android/androidcontentfileengine.cpp +++ b/src/plugins/platforms/android/androidcontentfileengine.cpp @@ -19,6 +19,7 @@ using namespace Qt::StringLiterals; Q_DECLARE_JNI_CLASS(ParcelFileDescriptorType, "android/os/ParcelFileDescriptor"); Q_DECLARE_JNI_CLASS(CursorType, "android/database/Cursor"); +Q_DECLARE_JNI_CLASS(QtContentFileEngine, "org/qtproject/qt/android/QtContentFileEngine"); static QJniObject &contentResolverInstance() { @@ -76,11 +77,12 @@ bool AndroidContentFileEngine::open(QIODevice::OpenMode openMode, openModeStr += u'a'; } - m_pfd = contentResolverInstance().callMethod< - QtJniTypes::ParcelFileDescriptorType, QtJniTypes::Uri, jstring>( + using namespace QtJniTypes; + m_pfd = QtContentFileEngine::callStaticMethod<ParcelFileDescriptorType>( "openFileDescriptor", - m_documentFile->uri().object(), - QJniObject::fromString(openModeStr).object<jstring>()); + contentResolverInstance().object<ContentResolver>(), + m_documentFile->uri().object<Uri>(), + openModeStr); if (!m_pfd.isValid()) return false; @@ -369,13 +371,14 @@ public: const QStringList &selectionArgs = {}, const QString &sortOrder = {}) { - auto cursor = contentResolverInstance().callMethod<QtJniTypes::CursorType>( - "query", - uri.object<QtJniTypes::Uri>(), - QJniArray(projection), - selection.isEmpty() ? nullptr : QJniObject::fromString(selection).object<jstring>(), - QJniArray(selectionArgs), - sortOrder.isEmpty() ? nullptr : QJniObject::fromString(sortOrder).object<jstring>()); + using namespace QtJniTypes; + auto cursor = QtContentFileEngine::callStaticMethod<CursorType>("query", + contentResolverInstance().object<ContentResolver>(), + uri.object<Uri>(), + QJniArray(projection), + selection.isEmpty() ? nullptr : selection, + QJniArray(selectionArgs), + sortOrder.isEmpty() ? nullptr : sortOrder); if (!cursor.isValid()) return {}; return std::make_unique<Cursor>(cursor); |
