Warning, /graphics/krita/3rdparty/ext_qt/0006-Add-file-engine-for-Android-content-URLs.patch is written in an unsupported language. File is not indexed.
0001 From 193afd76bac2b574086f20efb1c529236d77ee1b Mon Sep 17 00:00:00 2001 0002 From: Volker Krause <vkrause@kde.org> 0003 Date: Fri, 26 Nov 2021 15:55:12 +0000 0004 Subject: [PATCH 06/46] Add file engine for Android content URLs 0005 0006 The "file dialog" on Android returns such URLs, which so far required 0007 special-casing this in application code. With this change QFile can 0008 consume those URLs directly. 0009 0010 Change-Id: I489c0db112cf1dc7497e7a90f0e9a79ea8fa5237 0011 Reviewed-by: Nicolas Fella <nicolas.fella@kdab.com> 0012 Reviewed-by: BogDan Vatra <bogdan@kdab.com> 0013 Reviewed-by: Aleix Pol Gonzalez <aleixpol@kde.org> 0014 0015 # Conflicts: 0016 # src/android/jar/src/org/qtproject/qt5/android/QtNative.java 0017 --- 0018 .../org/qtproject/qt5/android/QtNative.java | 13 +++ 0019 src/plugins/platforms/android/android.pro | 2 + 0020 .../android/androidcontentfileengine.cpp | 92 +++++++++++++++++++ 0021 .../android/androidcontentfileengine.h | 60 ++++++++++++ 0022 .../platforms/android/androidjnimain.cpp | 5 + 0023 5 files changed, 172 insertions(+) 0024 create mode 100644 src/plugins/platforms/android/androidcontentfileengine.cpp 0025 create mode 100644 src/plugins/platforms/android/androidcontentfileengine.h 0026 0027 diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java 0028 index 11e6a129be..c9521e09b1 100644 0029 --- a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java 0030 +++ b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java 0031 @@ -41,6 +41,7 @@ 0032 package org.qtproject.qt5.android; 0033 0034 import java.io.File; 0035 +import java.io.FileNotFoundException; 0036 import java.util.ArrayList; 0037 import java.util.concurrent.Semaphore; 0038 0039 @@ -60,6 +61,7 @@ import android.content.ClipboardManager; 0040 import android.content.ClipboardManager.OnPrimaryClipChangedListener; 0041 import android.content.ClipData; 0042 import android.content.ClipDescription; 0043 +import android.os.ParcelFileDescriptor; 0044 import android.util.Log; 0045 import android.view.ContextMenu; 0046 import android.view.KeyEvent; 0047 @@ -169,6 +171,17 @@ public class QtNative 0048 return ok; 0049 } 0050 0051 + public static int openFdForContentUrl(Context context, String contentUrl, String openMode) 0052 + { 0053 + try { 0054 + ContentResolver resolver = context.getContentResolver(); 0055 + ParcelFileDescriptor fdDesc = resolver.openFileDescriptor(Uri.parse(contentUrl), openMode); 0056 + return fdDesc.detachFd(); 0057 + } catch (FileNotFoundException e) { 0058 + return -1; 0059 + } 0060 + } 0061 + 0062 // this method loads full path libs 0063 public static void loadQtLibraries(final ArrayList<String> libraries) 0064 { 0065 diff --git a/src/plugins/platforms/android/android.pro b/src/plugins/platforms/android/android.pro 0066 index 73db9e93a3..940bd5fc55 100644 0067 --- a/src/plugins/platforms/android/android.pro 0068 +++ b/src/plugins/platforms/android/android.pro 0069 @@ -20,6 +20,7 @@ INCLUDEPATH += \ 0070 $$QT_SOURCE_TREE/src/3rdparty/android 0071 0072 SOURCES += $$PWD/androidplatformplugin.cpp \ 0073 + $$PWD/androidcontentfileengine.cpp \ 0074 $$PWD/androiddeadlockprotector.cpp \ 0075 $$PWD/androidjnimain.cpp \ 0076 $$PWD/androidjniaccessibility.cpp \ 0077 @@ -49,6 +50,7 @@ SOURCES += $$PWD/androidplatformplugin.cpp \ 0078 $$PWD/qandroidplatformoffscreensurface.cpp 0079 0080 HEADERS += $$PWD/qandroidplatformintegration.h \ 0081 + $$PWD/androidcontentfileengine.h \ 0082 $$PWD/androiddeadlockprotector.h \ 0083 $$PWD/androidjnimain.h \ 0084 $$PWD/androidjniaccessibility.h \ 0085 diff --git a/src/plugins/platforms/android/androidcontentfileengine.cpp b/src/plugins/platforms/android/androidcontentfileengine.cpp 0086 new file mode 100644 0087 index 0000000000..1444407195 0088 --- /dev/null 0089 +++ b/src/plugins/platforms/android/androidcontentfileengine.cpp 0090 @@ -0,0 +1,92 @@ 0091 +/**************************************************************************** 0092 +** 0093 +** Copyright (C) 2019 Volker Krause <vkrause@kde.org> 0094 +** Contact: https://www.qt.io/licensing/ 0095 +** 0096 +** This file is part of the plugins of the Qt Toolkit. 0097 +** 0098 +** $QT_BEGIN_LICENSE:LGPL$ 0099 +** Commercial License Usage 0100 +** Licensees holding valid commercial Qt licenses may use this file in 0101 +** accordance with the commercial license agreement provided with the 0102 +** Software or, alternatively, in accordance with the terms contained in 0103 +** a written agreement between you and The Qt Company. For licensing terms 0104 +** and conditions see https://www.qt.io/terms-conditions. For further 0105 +** information use the contact form at https://www.qt.io/contact-us. 0106 +** 0107 +** GNU Lesser General Public License Usage 0108 +** Alternatively, this file may be used under the terms of the GNU Lesser 0109 +** General Public License version 3 as published by the Free Software 0110 +** Foundation and appearing in the file LICENSE.LGPL3 included in the 0111 +** packaging of this file. Please review the following information to 0112 +** ensure the GNU Lesser General Public License version 3 requirements 0113 +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 0114 +** 0115 +** GNU General Public License Usage 0116 +** Alternatively, this file may be used under the terms of the GNU 0117 +** General Public License version 2.0 or (at your option) the GNU General 0118 +** Public license version 3 or any later version approved by the KDE Free 0119 +** Qt Foundation. The licenses are as published by the Free Software 0120 +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 0121 +** included in the packaging of this file. Please review the following 0122 +** information to ensure the GNU General Public License requirements will 0123 +** be met: https://www.gnu.org/licenses/gpl-2.0.html and 0124 +** https://www.gnu.org/licenses/gpl-3.0.html. 0125 +** 0126 +** $QT_END_LICENSE$ 0127 +** 0128 +****************************************************************************/ 0129 + 0130 +#include "androidcontentfileengine.h" 0131 + 0132 +#include <private/qjni_p.h> 0133 +#include <private/qjnihelpers_p.h> 0134 + 0135 +#include <QDebug> 0136 + 0137 +AndroidContentFileEngine::AndroidContentFileEngine(const QString &fileName) 0138 + : QFSFileEngine(fileName) 0139 +{ 0140 +} 0141 + 0142 +bool AndroidContentFileEngine::open(QIODevice::OpenMode openMode) 0143 +{ 0144 + QString openModeStr; 0145 + if (openMode & QFileDevice::ReadOnly) { 0146 + openModeStr += QLatin1Char('r'); 0147 + } 0148 + if (openMode & QFileDevice::WriteOnly) { 0149 + openModeStr += QLatin1Char('w'); 0150 + } 0151 + if (openMode & QFileDevice::Truncate) { 0152 + openModeStr += QLatin1Char('t'); 0153 + } else if (openMode & QFileDevice::Append) { 0154 + openModeStr += QLatin1Char('a'); 0155 + } 0156 + 0157 + const auto fd = QJNIObjectPrivate::callStaticMethod<jint>("org/qtproject/qt5/android/QtNative", 0158 + "openFdForContentUrl", 0159 + "(Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;)I", 0160 + QtAndroidPrivate::context(), 0161 + QJNIObjectPrivate::fromString(fileName(DefaultName)).object(), 0162 + QJNIObjectPrivate::fromString(openModeStr).object()); 0163 + 0164 + if (fd < 0) { 0165 + return false; 0166 + } 0167 + 0168 + return QFSFileEngine::open(openMode, fd, QFile::AutoCloseHandle); 0169 +} 0170 + 0171 + 0172 +AndroidContentFileEngineHandler::AndroidContentFileEngineHandler() = default; 0173 +AndroidContentFileEngineHandler::~AndroidContentFileEngineHandler() = default; 0174 + 0175 +QAbstractFileEngine* AndroidContentFileEngineHandler::create(const QString &fileName) const 0176 +{ 0177 + if (!fileName.startsWith(QLatin1String("content"))) { 0178 + return nullptr; 0179 + } 0180 + 0181 + return new AndroidContentFileEngine(fileName); 0182 +} 0183 diff --git a/src/plugins/platforms/android/androidcontentfileengine.h b/src/plugins/platforms/android/androidcontentfileengine.h 0184 new file mode 100644 0185 index 0000000000..db3def03d6 0186 --- /dev/null 0187 +++ b/src/plugins/platforms/android/androidcontentfileengine.h 0188 @@ -0,0 +1,60 @@ 0189 +/**************************************************************************** 0190 +** 0191 +** Copyright (C) 2019 Volker Krause <vkrause@kde.org> 0192 +** Contact: https://www.qt.io/licensing/ 0193 +** 0194 +** This file is part of the plugins of the Qt Toolkit. 0195 +** 0196 +** $QT_BEGIN_LICENSE:LGPL$ 0197 +** Commercial License Usage 0198 +** Licensees holding valid commercial Qt licenses may use this file in 0199 +** accordance with the commercial license agreement provided with the 0200 +** Software or, alternatively, in accordance with the terms contained in 0201 +** a written agreement between you and The Qt Company. For licensing terms 0202 +** and conditions see https://www.qt.io/terms-conditions. For further 0203 +** information use the contact form at https://www.qt.io/contact-us. 0204 +** 0205 +** GNU Lesser General Public License Usage 0206 +** Alternatively, this file may be used under the terms of the GNU Lesser 0207 +** General Public License version 3 as published by the Free Software 0208 +** Foundation and appearing in the file LICENSE.LGPL3 included in the 0209 +** packaging of this file. Please review the following information to 0210 +** ensure the GNU Lesser General Public License version 3 requirements 0211 +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 0212 +** 0213 +** GNU General Public License Usage 0214 +** Alternatively, this file may be used under the terms of the GNU 0215 +** General Public License version 2.0 or (at your option) the GNU General 0216 +** Public license version 3 or any later version approved by the KDE Free 0217 +** Qt Foundation. The licenses are as published by the Free Software 0218 +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 0219 +** included in the packaging of this file. Please review the following 0220 +** information to ensure the GNU General Public License requirements will 0221 +** be met: https://www.gnu.org/licenses/gpl-2.0.html and 0222 +** https://www.gnu.org/licenses/gpl-3.0.html. 0223 +** 0224 +** $QT_END_LICENSE$ 0225 +** 0226 +****************************************************************************/ 0227 + 0228 +#ifndef ANDROIDCONTENTFILEENGINE_H 0229 +#define ANDROIDCONTENTFILEENGINE_H 0230 + 0231 +#include <private/qfsfileengine_p.h> 0232 + 0233 +class AndroidContentFileEngine : public QFSFileEngine 0234 +{ 0235 +public: 0236 + AndroidContentFileEngine(const QString &fileName); 0237 + bool open(QIODevice::OpenMode openMode) override; 0238 +}; 0239 + 0240 +class AndroidContentFileEngineHandler : public QAbstractFileEngineHandler 0241 +{ 0242 +public: 0243 + AndroidContentFileEngineHandler(); 0244 + ~AndroidContentFileEngineHandler(); 0245 + QAbstractFileEngine *create(const QString &fileName) const override; 0246 +}; 0247 + 0248 +#endif // ANDROIDCONTENTFILEENGINE_H 0249 diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp 0250 index 9ce3353040..a60b121979 100644 0251 --- a/src/plugins/platforms/android/androidjnimain.cpp 0252 +++ b/src/plugins/platforms/android/androidjnimain.cpp 0253 @@ -49,6 +49,7 @@ 0254 #include "androidjniinput.h" 0255 #include "androidjniclipboard.h" 0256 #include "androidjnimenu.h" 0257 +#include "androidcontentfileengine.h" 0258 #include "androiddeadlockprotector.h" 0259 #include "qandroidplatformdialoghelpers.h" 0260 #include "qandroidplatformintegration.h" 0261 @@ -116,6 +117,7 @@ static double m_scaledDensity = 0; 0262 static double m_density = 1.0; 0263 0264 static AndroidAssetsFileEngineHandler *m_androidAssetsFileEngineHandler = nullptr; 0265 +static AndroidContentFileEngineHandler *m_androidContentFileEngineHandler = nullptr; 0266 0267 0268 0269 @@ -445,6 +447,7 @@ static jboolean startQtAndroidPlugin(JNIEnv *env, jobject /*object*/, jstring pa 0270 { 0271 m_androidPlatformIntegration = nullptr; 0272 m_androidAssetsFileEngineHandler = new AndroidAssetsFileEngineHandler(); 0273 + m_androidContentFileEngineHandler = new AndroidContentFileEngineHandler(); 0274 m_mainLibraryHnd = nullptr; 0275 { // Set env. vars 0276 const char *nativeString = env->GetStringUTFChars(environmentString, 0); 0277 @@ -556,6 +559,8 @@ static void quitQtAndroidPlugin(JNIEnv *env, jclass /*clazz*/) 0278 m_androidPlatformIntegration = nullptr; 0279 delete m_androidAssetsFileEngineHandler; 0280 m_androidAssetsFileEngineHandler = nullptr; 0281 + delete m_androidContentFileEngineHandler; 0282 + m_androidContentFileEngineHandler = nullptr; 0283 } 0284 0285 static void terminateQt(JNIEnv *env, jclass /*clazz*/) 0286 -- 0287 2.33.0 0288