summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/android
diff options
context:
space:
mode:
authorLouis du Verdier <louis.du.verdier@free.fr>2022-06-17 18:45:05 +0200
committerLouis du Verdier <louis.du.verdier@free.fr>2022-06-20 16:18:34 +0200
commitd7068eaad7c180c814a766c91cebee25f04513a6 (patch)
treeb60fa981b22dc7a6210a8852044cf7f0daa44374 /src/plugins/platforms/android
parent4679d16db8d2052a63e3ed8fd113b22f3eba0689 (diff)
Fix tst_AndroidAssets, broken by recent changes on assets load speed
Recent changes on load speed of individual assets made AndroidAbstractFileEngine use a cache for basic information in order to avoid to have to open assets every time a QFileInfo is created, which was very expensive for older phones. However, size() method was forgotten and continued to expect that the asset would be opened first, and therefore QFileInfo().size() would always return -1. This change fixes this by caching as well the information about the size of the asset, and also reverts a part in open() to close() first in case asset would already be opened, in order to keep previous behavior (even if this did not cause any known issue). Fixes: QTBUG-104412 Pick-to: 6.4 6.3 6.2 5.15 Change-Id: I992f31b8f9e14dfec44cec78d0c1a2a3e18bdb7f Reviewed-by: Jani Heikkinen <jani.heikkinen@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/plugins/platforms/android')
-rw-r--r--src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp b/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp
index 165f953357..36fa2dd945 100644
--- a/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp
+++ b/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp
@@ -54,6 +54,7 @@ struct AssetItem {
}
Type type = Type::File;
QString name;
+ qint64 size = -1;
};
using AssetItemList = QList<AssetItem>;
@@ -233,8 +234,7 @@ public:
if (!m_assetInfo || m_assetInfo->type != AssetItem::Type::File || (openMode & QIODevice::WriteOnly))
return false;
- if (m_assetFile)
- return true;
+ close();
m_assetFile = AAssetManager_open(m_assetManager, m_fileName.toUtf8(), AASSET_MODE_BUFFER);
return m_assetFile;
}
@@ -251,8 +251,8 @@ public:
qint64 size() const override
{
- if (m_assetFile)
- return AAsset_getLength(m_assetFile);
+ if (m_assetInfo)
+ return m_assetInfo->size;
return -1;
}
@@ -346,6 +346,7 @@ public:
if (m_assetFile) {
m_assetInfo->type = AssetItem::Type::File;
+ m_assetInfo->size = AAsset_getLength(m_assetFile);
} else {
auto *assetDir = AAssetManager_openDir(m_assetManager, m_fileName.toUtf8());
if (assetDir) {