diff options
| author | Jarkko Koivikko <jarkko.koivikko@code-q.fi> | 2022-03-24 06:12:38 +0200 |
|---|---|---|
| committer | Jarkko Koivikko <jarkko.koivikko@code-q.fi> | 2022-03-25 19:06:53 +0200 |
| commit | 1fefff6d1f99dbcf1a453424753ad5562fb675ef (patch) | |
| tree | 5cbc1eca4fdcdac8a35417a680161784d6f0956c /src/plugins/platforms/android/androidcontentfileengine.cpp | |
| parent | eda8b7b4dad6fada6c7afa43b7df0f531d2504d1 (diff) | |
Android: Keep the ParcelFileDescriptor open for content uris
Detaching fd and closing the ParcelFileDescriptor prevents IO with the
services like Google Drive on Android.
Instead, the file system should keep the ParcelFileDescriptor open while
the IO operations take place and close it manually. Also, prevent Qt
from closing the handle for us.
Pick-to: 6.2 6.3
Fixes: QTBUG-101996
Change-Id: Ie54c04ad5aa1e7ee5444a04c30ac1323f73047bb
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Diffstat (limited to 'src/plugins/platforms/android/androidcontentfileengine.cpp')
| -rw-r--r-- | src/plugins/platforms/android/androidcontentfileengine.cpp | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/plugins/platforms/android/androidcontentfileengine.cpp b/src/plugins/platforms/android/androidcontentfileengine.cpp index b18c81e8964..c5ead186c90 100644 --- a/src/plugins/platforms/android/androidcontentfileengine.cpp +++ b/src/plugins/platforms/android/androidcontentfileengine.cpp @@ -71,17 +71,35 @@ bool AndroidContentFileEngine::open(QIODevice::OpenMode openMode, openModeStr += QLatin1Char('a'); } - const auto fd = QJniObject::callStaticMethod<jint>("org/qtproject/qt/android/QtNative", - "openFdForContentUrl", - "(Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;)I", + m_pfd = QJniObject::callStaticObjectMethod("org/qtproject/qt/android/QtNative", + "openParcelFdForContentUrl", + "(Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;)Landroid/os/ParcelFileDescriptor;", QAndroidApplication::context(), QJniObject::fromString(fileName(DefaultName)).object(), QJniObject::fromString(openModeStr).object()); - if (fd < 0) + if (!m_pfd.isValid()) return false; - return QFSFileEngine::open(openMode, fd, QFile::AutoCloseHandle); + const auto fd = m_pfd.callMethod<jint>("getFd", "()I"); + + if (fd < 0) { + m_pfd.callMethod<void>("close", "()V"); + m_pfd = QJniObject(); + return false; + } + + return QFSFileEngine::open(openMode, fd, QFile::DontCloseHandle); +} + +bool AndroidContentFileEngine::close() +{ + if (m_pfd.isValid()) { + m_pfd.callMethod<void>("close", "()V"); + m_pfd = QJniObject(); + } + + return QFSFileEngine::close(); } qint64 AndroidContentFileEngine::size() const |
