Fix QSaveFile always failing on content: URLs

QSaveFile needs QFileInfo::isWritable() to work, which 7e5f38aec6 caused
to always return false for content: URLs.

Change-Id: If839331e4bd176765ed242791cb253c2064f5f6d
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
Volker Krause 2020-10-16 16:40:49 +02:00
parent f6d09d426b
commit d53bbecf4c
2 changed files with 14 additions and 2 deletions

View File

@ -329,6 +329,11 @@ public class QtNative
}
}
public static boolean checkIfWritable(Context context, String contentUrl)
{
return getUriWithValidPermission(context, contentUrl, "w") != null;
}
public static boolean checkIfDir(Context context, String contentUrl)
{
boolean isDir = false;

View File

@ -103,10 +103,17 @@ AndroidContentFileEngine::FileFlags AndroidContentFileEngine::fileFlags(FileFlag
QJNIObjectPrivate::fromString(fileName(DefaultName)).object());
if (!exists && !isDir)
return flags;
if (isDir)
if (isDir) {
flags = DirectoryType | commonFlags;
else
} else {
flags = FileType | commonFlags;
const bool writable = QJNIObjectPrivate::callStaticMethod<jboolean>(
"org/qtproject/qt/android/QtNative", "checkIfWritable",
"(Landroid/content/Context;Ljava/lang/String;)Z", QtAndroidPrivate::context(),
QJNIObjectPrivate::fromString(fileName(DefaultName)).object());
if (writable)
flags |= WriteOwnerPerm|WriteUserPerm|WriteGroupPerm|WriteOtherPerm;
}
return type & flags;
}