Revert "Android: fix Android assets handler not listing dirs with only sub dirs"

This reverts commit 89f89cedc0.

Reason for revert: QTBUG-107879

Task-number: QTBUG-107627
Fixes: QTBUG-107879
Change-Id: I31ceec5156837281b25fd17024c01e3477550ce0
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
Jani Heikkinen 2022-10-25 04:31:17 +00:00 committed by Assam Boudjelthia
parent 2c639aea76
commit 283e29e539
5 changed files with 5 additions and 32 deletions

View File

@ -108,12 +108,10 @@ 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.
QJniObject files = QJniObject::callStaticObjectMethod(QtAndroid::applicationClass(),
"listAssetContent",
"(Landroid/content/res/AssetManager;Ljava/lang/String;)[Ljava/lang/String;",
QtAndroid::assets(), QJniObject::fromString(path).object());
"listAssetContent",
"(Landroid/content/res/AssetManager;Ljava/lang/String;)[Ljava/lang/String;",
QtAndroid::assets(), QJniObject::fromString(path).object());
if (files.isValid()) {
QJniEnvironment env;
jobjectArray jFiles = files.object<jobjectArray>();
@ -352,7 +350,8 @@ public:
} else {
auto *assetDir = AAssetManager_openDir(m_assetManager, m_fileName.toUtf8());
if (assetDir) {
m_assetInfo->type = AssetItem::Type::Folder;
if (AAssetDir_getNextFileName(assetDir))
m_assetInfo->type = AssetItem::Type::Folder;
AAssetDir_close(assetDir);
}
}

View File

@ -6,7 +6,6 @@
#include <QTest>
#include <QtCore/qnativeinterface.h>
#include <QtCore/qjniobject.h>
#include <QtCore/qdiriterator.h>
class tst_Android : public QObject
{
@ -14,7 +13,6 @@ Q_OBJECT
private slots:
void assetsRead();
void assetsNotWritable();
void assetsIterating();
void testAndroidSdkVersion();
void testAndroidActivity();
void testRunOnAndroidMainThread();
@ -43,27 +41,6 @@ void tst_Android::assetsNotWritable()
QVERIFY(!file.open(QIODevice::Append));
}
void tst_Android::assetsIterating()
{
QStringList assets = {"assets:/top_level_dir/file_in_top_dir.txt",
"assets:/top_level_dir/sub_dir",
"assets:/top_level_dir/sub_dir/file_in_sub_dir.txt",
"assets:/top_level_dir/sub_dir/sub_dir_2",
"assets:/top_level_dir/sub_dir/sub_dir_2/sub_dir_3",
"assets:/top_level_dir/sub_dir/sub_dir_2/sub_dir_3/file_in_sub_dir_3.txt"};
// Note that we have an "assets:/top_level_dir/sub_dir/empty_sub_dir" in the test's
// assets physical directory, but empty folders are not packaged in the built apk,
// so it's expected to not have such folder be listed in the assets on runtime
QDirIterator it("assets:/top_level_dir", QDirIterator::Subdirectories);
QStringList iteratorAssets;
while (it.hasNext())
iteratorAssets.append(it.next());
QVERIFY(assets == iteratorAssets);
}
void tst_Android::testAndroidSdkVersion()
{
QVERIFY(QNativeInterface::QAndroidApplication::sdkVersion() > 0);