summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QFileSystemEngine: make factory functions return unique_ptr<QABFE>Ahmad Samir2024-03-211-4/+5
| | | | | | | | | | | | | | | | This makes the ownership of the returned pointer clearer. It also matches reality, some call sites were already storing the pointer in a unique_ptr. Also shorten the function name to "createLegacyEngine", you have to read its docs anyway to figure out what it does. Drive-by changes: less magic numbers; use sliced(); return nullptr instead of `0`. Change-Id: I637759b4160b28b15adf5f6548de336887338dab Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* QAbstractFileEngineIterator: add `bool advance()` virtual methodAhmad Samir2024-03-201-24/+8
| | | | | | | | | | | | | | | | | | | | | | | And remove hasNext/next() methods. This remodels QAFEI to be like QFileSystemIterator. This better fits the logic in the newly added QDirListing class (which uses STL-style iterators). QFSFileEngineIterator: Initialize the internal nativeIterator in the constructor; also replace the advance() private method with an override for the advance() method inherited from the base class. QResourceFileEngineIterator: Override currentFileInfo(), with a QResouces the QFileInfo is created on demand if/when this method is called. This is the backend/private API, and QDirListing is the public API that can be used in a ranged-for to iterate over directory entries. Change-Id: I93eb7bdd64823ac01eea2dcaaa6bcc8ad868b2c4 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QAbstractFileEngine: add a path parameter to beginEntryList()Ahmad Samir2024-03-171-2/+3
| | | | | | | | | | | | | Change beginEntryList() to take a path parameter, which it passes on to the QAFEIterator constructor; setting the path at construction makes more sense, because typically the path isn't supposed to change during iteration, and this simplifies the code at the call site. Remove setPath(), the last usage in Qt repos was in QtCreator, and that has been ported away from it. Change-Id: I01baa688e0f9b582aacb63d7d98a794276e58034 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QAbstractFileEngine: make {begin,end}EntryList() return a unique_ptrAhmad Samir2024-03-171-2/+3
| | | | | | | | Makes ownership clearer. Change-Id: Ibb57ca900ef30b16d48964a977e997ba6705248b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Don't add prefix for BaseNameBogDan Vatra2023-06-161-2/+2
| | | | | | | | | | | | | | Adding the "assets:" prefix to BaseName leads to wrong names returned by QFileInfo{"assets:/path/to/file"}.fileName(). Instead to return "file" it returns "assets:/file" which is not the expected result. Fixes: QTBUG-114576 Fixes: QTBUG-114219 Fixes: QTBUG-112261 Pick-to: 6.6 6.5 6.5.2 Change-Id: I574bf325300c0aedef68b1b183fa837144ad63c6 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: fix Android assets handler not listing dirs with only sub dirsBartlomiej Moskal2022-12-131-1/+8
| | | | | | | | | | | | | | | | | | | | | 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 Pick-to: 6.4 6.2 5.15 Change-Id: Id375fe8f99f4ca3f8cad4756f783ffafe5c074df Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Fix infinite loop when iterating content uri sub-files/dirsAssam Boudjelthia2022-12-101-1/+1
| | | | | | | | | | | | make QAbstractFileEngineIterator::currentFilePath() virtual and implement it under AndroidContentFileEngine to return current fileName because content uris shouldn't be constructed manaully like normal file paths. Pick-to: 6.4 6.2 Fixes: QTBUG-104776 Change-Id: I4643a73a3bd4019bedaa056c35468117bcec18dc Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
* Revert "Android: fix Android assets handler not listing dirs with only sub dirs"Jani Heikkinen2022-10-251-6/+5
| | | | | | | | | | | This reverts commit 89f89cedc0e62f4b66de340da57d6c56dc61baf0. Reason for revert: QTBUG-107879 Task-number: QTBUG-107627 Fixes: QTBUG-107879 Change-Id: I31ceec5156837281b25fd17024c01e3477550ce0 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: fix Android assets handler not listing dirs with only sub dirsAssam Boudjelthia2022-10-211-5/+6
| | | | | | | | | | | | | | | | | | Amends edd983071e0a90ee8665d2f45916fb575fc25857. Remove redundant calls to AAssetDir_getNextFileName() in AndroidAbstractFileEngine::setFileName(). It's enough to check if AAssetManager_open() returns null and AAssetManager_openDir() is valid for the provided asset file name. As part of this fix, add some unit tests to cover/ensure assets listing/iterating works as expected. Fixes: QTBUG-107627 Pick-to: 6.4 6.2 5.15 Change-Id: I37ae9cb64fbbc60699bb748895f77fd6a34fae1f Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Apply Q_CONSTINIT where beneficialSona Kurazyan2022-09-011-2/+2
| | | | | | | | | | Applied Q_CONSTINIT to variables with static storage duration, but skipped the POD types with core constant initializers. Task-number: QTBUG-100486 Change-Id: Iaabf824e9cb0f29a405a149912200d4e4b3573c1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Fix tst_AndroidAssets, broken by recent changes on assets load speedLouis du Verdier2022-06-201-4/+5
| | | | | | | | | | | | | | | | | | | | | | 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>
* Android: Improve loading speed of individual assetsLouis du Verdier2022-06-151-18/+46
| | | | | | | | | | | | | | | | | | | | | | This change improves the loading speed of files stored in Android assets folder by caching the information about files already opened. Prior to the change, when creating a QFile or QFileInfo to an asset file, the engine would first scan all the file's directory and parent directories in order to cache all this in FolderIterator::m_assetsCache. Due to the nature of Android assets, it might be very slow, depending on the number of images in this tree. In this patch, individual file accesses will stop using FolderIterator and will simply open what is asked, caching the information about the resource in order to avoid to have to call the expensive AAssetManager_open if the file is accessed again (e.g. by QFileInfo). Fixes: QTBUG-101161 Change-Id: Iaedf4cdf83d5116053b51895a6795d43bc60f942 Pick-to: 6.4 6.3 6.2 5.15 Reviewed-by: Rami Potinkara <rami.potinkara@qt.io> Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-38/+2
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* Android: use _L1 for for creating Latin-1 string literalsSona Kurazyan2022-04-141-6/+8
| | | | | | Task-number: QTBUG-98434 Change-Id: I5ee5fe079c9a4530f636e59f6171abfa523591f4 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: stop using QLatin1Char constructor for creating char literalsSona Kurazyan2022-04-141-12/+12
| | | | | | | | | | | Required for porting away from QLatin1Char/QLatin1String in scope of QTBUG-98434. As a drive-by, fix qsizetype -> int narrowing conversion warnings for the touched lines. Change-Id: Iebcbdbd7cecac09d0a7039e3ef6a4509d33039ba Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* QAbstractFileEngine: Add permission argument to open()Ievgenii Meshcheriakov2021-12-041-2/+4
| | | | | | | | | The new argument allows atomic creation of files with non-default permissions. Task-number: QTBUG-79750 Change-Id: I4c49455b41f924ba87148302c8d0f77f5de0832b Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QAbstractFileEngine: Remove useless method overridesIevgenii Meshcheriakov2021-11-031-10/+0
| | | | | | | | | | | | Remove useless overrides of QAbstractFileEngine methods from the derived classes. Also remove "This virtual function must be reimplemented by all subclasses" passages from the QAbstractFileEngine's documentation. There are pure virtual methods for such use cases. QAbstractFileEngine already contains useful defaults for classes not supporting all the functionality. Change-Id: Ia25965854f3809b15d7502da3749cc2f3414bbc3 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Use templated QJniObject::object() instead of static_castAssam Boudjelthia2021-05-061-1/+1
| | | | | | | Change-Id: I3bf366967d7995621aba1a7c1bec6732f3ef957d Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Make QJniObject and QJniEnvironment public APIAssam Boudjelthia2021-01-271-6/+8
| | | | | | | | | | | | | | | | | | | | As part of Qt 6 restructring for the extras modules, this change exposes the Jni APIs which are very important for Android platform. This patch adds the APIs QJniObject, QJniEnvironment, QJniExceptionCleaner based from private QtCore and QtAndroidExtras. The Jni interface is cross-platform which justifies the name, but currently, this API is used mainly for Android, and the naming comes generic without Android keyword to avoid any future limitation on supporting other platforms. [ChangeLog][QtCore] Add new QJniObject, QJniEnvironment and QJniExceptionCleaner APIs. Task-number: QTBUG-89482 Fixes: QTBUG-89633 Change-Id: I4382dd53a225375759b9d042f6035a4a9810572b Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
* Use QList instead of QVector in pluginsJarek Kobus2020-07-061-2/+2
| | | | | | Task-number: QTBUG-84469 Change-Id: Ic86f4a3000592a1c9ae62e4a83f4fe39832a6b24 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Android: Don't recurse into directories inside the assets when iteratingAndy Shaw2020-02-271-20/+5
| | | | | | | | | When iterating, it should only return what is in the specified path and not the contents of the sub-directories inside the given path in addition. Change-Id: Iad56f075c22fdf1c633582e37444e26520c24a73 Reviewed-by: BogDan Vatra <bogdan@kdab.com>
* Fix AndroidAbstractFileEngineBogDan Vatra2020-02-051-1/+4
| | | | | | | | | | "" it's the root folder of the assets, setting m_fileName = "" will make AndroidAbstractFileEngine::setFileName to fail and it will not set the proper flags. Fixes: QTBUG-81535 Change-Id: I0653f83b55ee790c8edf188889ccb30ef54584c0 Reviewed-by: Andy Shaw <andy.shaw@qt.io>
* Release the local ref immediatelyBogDan Vatra2020-01-221-1/+1
| | | | | | | | | The local refs are released by the JVM when we exit the function, but if we need tons of local refs, JVM will not be happy. Fixes: QTBUG-81077 Change-Id: Ic38a5be1a563cb9c2465f9f902ff6ae6c61e698b Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
* Initialize all variablesBogDan Vatra2019-12-031-2/+3
| | | | | | | | Set m_isFolder = false also in "close" method Fixes: QTBUG-80468 Change-Id: I5449692d61d4d340e83bdca337b86e054e8bf561 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
* Fix assets iteratorBogDan Vatra2019-11-291-14/+56
| | | | | | | | | | | | | | | | - start from index -1 each time when we iterate. Each time when we add a FolderIterator to the stack we MUST reset the index (-1) otherwise it will continue from it's last position. To fix it we are cloning the FolderIterator to set the index to -1. The index must be -1 in order to set it to 0 when we first call next() method. - introduce "fileType" static method for a more reliable also much faster file type lookup. The old version of checking if a file exists, is a folder or a file was buggy that's why it skipped some file randomly. Fixes: QTBUG-80178 Change-Id: I4b28e4616399b1bff35d792b55ded1bf19b62dd9 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
* Android: rework assets supportBogDan Vatra2019-10-021-183/+173
| | | | | | | The new version fix QDirIterators and it lists all the files and dirs. Change-Id: I5a30eedb61ab2397a84365d00f308cda0c194de2 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
* QAbstractFileEngine: make setFileTime not a pure virtualThiago Macieira2017-07-071-7/+0
| | | | | | | | Most engines just had to override the virtual to return false. So do it in the base class. Change-Id: I8d96dea9955d4c749b99fffd14cd738a48aa818c Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@qt.io>
* QFileDevice/QFileInfo: Add fileTime() and setFileTime()Nikita Krupenko2017-04-271-0/+7
| | | | | | | | | | | [ChangeLog][QtCore][QFileDevice] Added fileTime() and setFileTime(). [ChangeLog][QtCore][QFileInfo] Added fileTime(). Task-number: QTBUG-984 Change-Id: I84dfb05b9454a54e26b57b78edee5773dc4c5c3c Initial-patch-by: Raphael Gozzo <raphael.rg91@gmail.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Android: Add missing overrideAlexander Volkov2016-11-291-17/+17
| | | | | Change-Id: I70b802517d8f7d129ffb71dc3e92cb2458a55acc Reviewed-by: BogDan Vatra <bogdan@kdab.com>
* Updated license headersJani Heikkinen2016-01-151-13/+19
| | | | | | | | | | | From Qt 5.7 -> LGPL v2.1 isn't an option anymore, see http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/ Updated license headers to use new LGPL header instead of LGPL21 one (in those files which will be under LGPL v3) Change-Id: I046ec3e47b1876cd7b4b0353a576b352e3a946d9 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* Libraries: Fix single-character string literals.Friedemann Kleint2015-10-131-4/+4
| | | | | | | Use character literals where applicable. Change-Id: I8e198774c2247c1cc1d852a41b59b301199b7878 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* Update copyright headersJani Heikkinen2015-02-111-6/+6
| | | | | | | | | | | | | | | | | | Qt copyrights are now in The Qt Company, so we could update the source code headers accordingly. In the same go we should also fix the links to point to qt.io. Outdated header.LGPL removed (use header.LGPL21 instead) Old header.LGPL3 renamed to header.LGPL3-COMM to match actual licensing combination. New header.LGPL-COMM taken in the use file which were using old header.LGPL3 (src/plugins/platforms/android/extract.cpp) Added new header.LGPL3 containing Commercial + LGPLv3 + GPLv2 license combination Change-Id: I6f49b819a8a20cc4f88b794a8f6726d975e8ffbe Reviewed-by: Matti Paaso <matti.paaso@theqtcompany.com>
* Android: Don't open assets files in read/write modeEskil Abrahamsen Blomfeldt2015-01-281-3/+1
| | | | | | | | | | | | | | | | | We would return true when opening assets in read/write mode despite the fact that the files are not writable. The logic now matches that of the qrc file engine. This also adds a unit test for Android-specific issues. [ChangeLog][Android][Important Behavior Changes] Opening assets with QIODevice::ReadWrite now returns false to correctly indicate that the files are not writable. Change-Id: I019cc27861fc9b000dc13c5e0a38c0fc09a08671 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@theqtcompany.com> Reviewed-by: Christian Stromme <christian.stromme@theqtcompany.com> Reviewed-by: BogDan Vatra <bogdan@kde.org>
* Merge remote-tracking branch 'origin/5.4' into devOswald Buddenhagen2014-09-291-18/+10
|\ | | | | | | | | | | | | | | | | | | | | Conflicts: src/corelib/tools/qbytearray.cpp src/gui/image/qimage.cpp src/gui/image/qppmhandler.cpp src/gui/kernel/qguiapplication.cpp src/gui/painting/qpaintengine_raster.cpp Change-Id: I7c1a8e7ebdfd7f7ae767fdb932823498a7660765
| * Update license headers and add new license filesMatti Paaso2014-09-241-18/+10
| | | | | | | | | | | | | | | | | | - Renamed LICENSE.LGPL to LICENSE.LGPLv21 - Added LICENSE.LGPLv3 - Removed LICENSE.GPL Change-Id: Iec3406e3eb3f133be549092015cefe33d259a3f2 Reviewed-by: Iikka Eklund <iikka.eklund@digia.com>
* | Android: use qEnvironmentVariableIntValue()Marc Mutz2014-09-121-1/+1
|/ | | | | | | | It doesn't allocate memory, so cannot throw and is a lot faster than qgetenv(). Change-Id: I6d79852613228658f9093a272edf9b434e60286c Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
* Android: Fix namespace usageChristian Strømme2014-06-301-0/+4
| | | | | | | This change makes it possible to set a Qt namespace for Android builds. Change-Id: I79f4ae8200223f36f97e2849aae49e45b8850d23 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
* REG: Android: Fix freeze when accessing assetsEskil Abrahamsen Blomfeldt2014-03-211-1/+0
| | | | | | | | | | | Change 287fa94fe2f93e2857a4c15f69435c4ea14de82e created a freeze in the assets file engine because it will try locking the mutex twice. Since prepopulateCache() is only called from create(), we don't need to lock it recursively. Task-number: QTBUG-37661 Change-Id: I00d0fed132a86c1be5603484eb6ee05454da9ef0 Reviewed-by: BogDan Vatra <bogdan@kde.org>
* Android: Fix another "QApplication not on main() thread" crashEskil Abrahamsen Blomfeldt2014-03-151-2/+9
| | | | | | | | | | | | | | The assets file engine is created before main() is called, thus prepopulate was called before main(). In this function, we created a QDataStream which internally created a QBuffer which inherits from QObject. This caused the main thread pointer to be initialized early, and the old "QApplication is not on the main() thread" warning and crash returned. The fix is to prepopulate the first time the file engine is used instead. Task-number: QTBUG-37444 Change-Id: I2c6e5f1a8ca88b5dc7d8e145fffeb7587dc0e623 Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
* Android: Support pregenerated cache in assets file engineEskil Abrahamsen Blomfeldt2014-02-261-24/+104
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This provides a way for androiddeployqt to pregenerate the entry list cache for the assets file engine, greatly improving performance the first time a directory is read. If the file is not present, the cache will operate as before. Some numbers from testing on Samsung Galaxy 2, doing QDir::entryList() on a directory inside the assets folder: 10 files -------- Before: 280 ms for first read, 5 ms for subsequent reads After: 2 ms for reading pregenerated cache 5 ms for first read 5 ms for subsequent reads 2000 files ---------- Before: 1000 ms for first read, 150 ms for subsequent reads After: 5 ms for reading pregenerated cache 150 ms for first read 150 ms for subsequent reads 4000 files ---------- Before: 3000 ms for first read 300 ms for subsequent reads After: 8 ms for reading pregenerated cache 300 ms for first read 300 ms for subsequent reads [ChangeLog][Android] Speed up first time directory listing in assets by using pregenerated entry list. Task-number: QTBUG-33704 Change-Id: I3973a1d823b8b38e88a2cc7843326cbe885f8bc2 Reviewed-by: Christian Stromme <christian.stromme@digia.com>
* Android: Don't skip first file in assets entry listEskil Abrahamsen Blomfeldt2014-01-301-0/+1
| | | | | | | | | | | | | | | We're using AAssetDir_getNextFileName() to verify that the directory exists and has content, and this moves the current file pointer to the second file in the dir, so we need to reset the pointer before iterating to populate the entry list. [ChangeLog][Android] Fixed QDir::entryList() for assets scheme to no longer skip the first file in the directory. Task-number: QTBUG-36528 Change-Id: I9938c669658330b0e11d6fbe3df8c6566fd79f5f Reviewed-by: BogDan Vatra <bogdan@kde.org>
* Support multiple native surfaces on Android.BogDan Vatra2014-01-171-0/+309
Support for multiple native surfaces is needed by applications that need to mix raster windows with GL windows. Rework the raster and opengl implementation, get rid of eglfs and fbconvenience dependencies. Create a single android platform plugin. [ChangeLog][Android] Rework the raster and opengl implementation. [ChangeLog][Android] Create a single android platform plugin. Task-number: QTBUG-34650 Change-Id: I9b1ab51554823329dda8cfbf8fef27c38f917c7b Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>