Warning, /graphics/krita/3rdparty/ext_qt/0041-Android-Use-External-Storage-for-some-Standard-Paths.patch is written in an unsupported language. File is not indexed.
0001 From 71762fe814e6cb960dee40fe3d2fc5303bf552ca Mon Sep 17 00:00:00 2001 0002 From: Sharaf Zaman <sharafzaz121@gmail.com> 0003 Date: Wed, 16 Jun 2021 18:03:58 +0000 0004 Subject: [PATCH] Android: Use External Storage for some Standard Paths 0005 0006 Types: 0007 - AppConfigLocation 0008 - AppDataLocation 0009 - AppLocalDataLocation 0010 - HomeLocation 0011 --- 0012 src/corelib/io/qstandardpaths_android.cpp | 77 +++++++++++++++++++++-- 0013 1 file changed, 73 insertions(+), 4 deletions(-) 0014 0015 diff --git a/src/corelib/io/qstandardpaths_android.cpp b/src/corelib/io/qstandardpaths_android.cpp 0016 index 9fe98d34cd..17de41a82b 100644 0017 --- a/src/corelib/io/qstandardpaths_android.cpp 0018 +++ b/src/corelib/io/qstandardpaths_android.cpp 0019 @@ -45,12 +45,15 @@ 0020 #include <QtCore/private/qjnihelpers_p.h> 0021 #include <QtCore/qmap.h> 0022 #include <QDir> 0023 +#include <QDebug> 0024 0025 QT_BEGIN_NAMESPACE 0026 0027 typedef QMap<QString, QString> AndroidDirCache; 0028 Q_GLOBAL_STATIC(AndroidDirCache, androidDirCache) 0029 0030 +static QString getFilesDir(); 0031 + 0032 static QString testDir() 0033 { 0034 return QStandardPaths::isTestModeEnabled() ? QLatin1String("/qttest") 0035 @@ -115,9 +118,63 @@ static QString getExternalFilesDir(const char *directoryField = 0) 0036 if (!file.isValid()) 0037 return QString(); 0038 0039 + QJNIObjectPrivate mediaMountedObj = QJNIObjectPrivate::getStaticObjectField( 0040 + "android/os/Environment", "MEDIA_MOUNTED", "Ljava/lang/String;"); 0041 + 0042 + QJNIObjectPrivate storageStateObj = QJNIObjectPrivate::callStaticObjectMethod( 0043 + "android/os/Environment", "getExternalStorageState", "()Ljava/lang/String;"); 0044 + 0045 + if (!storageStateObj.isValid() || !mediaMountedObj.isValid()) { 0046 + return QString(); 0047 + } 0048 + 0049 + QString storageState = storageStateObj.toString(); 0050 + QString mediaMounted = mediaMountedObj.toString(); 0051 + if (storageState != mediaMounted) { 0052 + qWarning() << "External Storage not mounted"; 0053 + return getFilesDir(); 0054 + } 0055 + 0056 return (path = getAbsolutePath(file)); 0057 } 0058 0059 +static QStringList getExternalFilesDirs(const char *directoryField = 0) 0060 +{ 0061 + QStringList paths; 0062 + 0063 + QJNIObjectPrivate appCtx = applicationContext(); 0064 + if (!appCtx.isValid()) 0065 + return QStringList(); 0066 + 0067 + QJNIObjectPrivate dirField = QJNIObjectPrivate::fromString(QLatin1String("")); 0068 + if (directoryField) { 0069 + dirField = QJNIObjectPrivate::getStaticObjectField("android/os/Environment", 0070 + directoryField, 0071 + "Ljava/lang/String;"); 0072 + if (!dirField.isValid()) 0073 + return QStringList(); 0074 + } 0075 + 0076 + QJNIObjectPrivate files = appCtx.callObjectMethod("getExternalFilesDirs", 0077 + "(Ljava/lang/String;)[Ljava/io/File;", 0078 + dirField.object()); 0079 + 0080 + if (!files.isValid()) 0081 + return QStringList(); 0082 + 0083 + auto filesObjectArray = static_cast<jobjectArray>(files.object()); 0084 + QJNIEnvironmentPrivate env; 0085 + jsize numPaths = env->GetArrayLength(filesObjectArray); 0086 + for (jsize i = 0; i < numPaths; ++i) { 0087 + QJNIObjectPrivate file(env->GetObjectArrayElement(filesObjectArray, i)); 0088 + if (file.isValid()) { 0089 + paths << getAbsolutePath(file); 0090 + } 0091 + } 0092 + 0093 + return paths; 0094 +} 0095 + 0096 /* 0097 * Directory where applications can store cache files it owns (public). 0098 * E.g., /storage/org.app/ 0099 @@ -203,12 +260,12 @@ QString QStandardPaths::writableLocation(StandardLocation type) 0100 case QStandardPaths::GenericConfigLocation: 0101 case QStandardPaths::ConfigLocation: 0102 case QStandardPaths::AppConfigLocation: 0103 - return getFilesDir() + testDir() + QLatin1String("/settings"); 0104 + return getExternalFilesDir() + testDir() + QLatin1String("/settings"); 0105 case QStandardPaths::GenericDataLocation: 0106 return getExternalFilesDir() + testDir(); 0107 case QStandardPaths::AppDataLocation: 0108 case QStandardPaths::AppLocalDataLocation: 0109 - return getFilesDir() + testDir(); 0110 + return getExternalFilesDir() + testDir(); 0111 case QStandardPaths::GenericCacheLocation: 0112 case QStandardPaths::RuntimeLocation: 0113 case QStandardPaths::TempLocation: 0114 @@ -216,7 +273,7 @@ QString QStandardPaths::writableLocation(StandardLocation type) 0115 return getCacheDir() + testDir(); 0116 case QStandardPaths::DesktopLocation: 0117 case QStandardPaths::HomeLocation: 0118 - return getFilesDir(); 0119 + return getExternalFilesDir(); 0120 case QStandardPaths::ApplicationsLocation: 0121 case QStandardPaths::FontsLocation: 0122 default: 0123 @@ -261,9 +318,21 @@ QStringList QStandardPaths::standardLocations(StandardLocation type) 0124 << getExternalFilesDir("DIRECTORY_DOWNLOADS"); 0125 } 0126 0127 + if (type == AppConfigLocation) { 0128 + return QStringList() << writableLocation(type) 0129 + << getFilesDir() + testDir() + QLatin1String("/settings"); 0130 + } 0131 + 0132 if (type == AppDataLocation || type == AppLocalDataLocation) { 0133 return QStringList() << writableLocation(type) 0134 - << getExternalFilesDir(); 0135 + << getFilesDir() 0136 + << getExternalFilesDirs(); 0137 + } 0138 + 0139 + if (type == HomeLocation) { 0140 + return QStringList() << writableLocation(type) 0141 + << getFilesDir() 0142 + << getExternalFilesDirs(); 0143 } 0144 0145 if (type == CacheLocation) { 0146 -- 0147 2.37.2 0148