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>
This commit is contained in:
Louis du Verdier 2022-06-17 18:45:05 +02:00
parent 4679d16db8
commit d7068eaad7

View File

@ -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) {