summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBartlomiej Moskal <bartlomiej.moskal@qt.io>2022-11-21 17:28:52 +0100
committerBartlomiej Moskal <bartlomiej.moskal@qt.io>2023-01-02 08:42:14 +0100
commitaa7b2436b5a357ea7d76eebaecab0c05719b5c91 (patch)
tree593f975147454ae82b63af631e17a10ac8a21182 /src
parent9e2eb42d63b56c3062ff1ab6d4d4381f471ccabf (diff)
Android: fix Android assets handler not listing dirs with only sub dirs
It looks like AAssetDir_getNextFileName is not enough. Directories that contain only other directories (no files) were not listed. On the other hand, AAssetManager_openDir() will always return a pointer to initialized object (even if the specified directory does not exists), so we can't just leave only it here. Using FolderIterator as a last resort. This approach should not be too time consuming. As part of this fix, add some unit tests to cover/ensure assets listing/iterating works as expected. Fixes: QTBUG-107627 Change-Id: Id375fe8f99f4ca3f8cad4756f783ffafe5c074df Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> (cherry picked from commit 4ceee3911a2ef567f614fc296475bc2b2a0e3add)
Diffstat (limited to 'src')
-rw-r--r--src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp b/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp
index 14fab3dce7..301eab8b10 100644
--- a/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp
+++ b/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp
@@ -140,6 +140,8 @@ public:
FolderIterator(const QString &path)
: m_path(path)
{
+ // Note that empty dirs in the assets dir before the build are not going to be
+ // included in the final apk, so no empty folders should expected to be listed.
QJNIObjectPrivate files = QJNIObjectPrivate::callStaticObjectMethod(QtAndroid::applicationClass(),
"listAssetContent",
"(Landroid/content/res/AssetManager;Ljava/lang/String;)[Ljava/lang/String;",
@@ -390,8 +392,13 @@ public:
} else {
auto *assetDir = AAssetManager_openDir(m_assetManager, m_fileName.toUtf8());
if (assetDir) {
- if (AAssetDir_getNextFileName(assetDir))
+ if (AAssetDir_getNextFileName(assetDir)
+ || (!FolderIterator::fromCache(m_fileName, false)->empty())) {
+ // If AAssetDir_getNextFileName is not valid, it still can be a directory that
+ // contains only other directories (no files). FolderIterator will not be called
+ // on the directory containing files so it should not be too time consuming now.
m_assetInfo->type = AssetItem::Type::Folder;
+ }
AAssetDir_close(assetDir);
}
}