37 Commits

Author SHA1 Message Date
Lauri Pohjanheimo
61d14ea267 Mark files as security sensitive
androidcontentfileengine.cpp
qandroidapkfileengine.cpp,
qandroidassetsfileenginehandler.cpp and
extract.cpp marked
Reasons: Data serialization, filename parsing

Task-number: QTBUG-136818
Task-number: QTBUG-135178
Task-number: QTBUG-136816
Pick-to: 6.8
Change-Id: Ib277a04cc00dc0762feed17a7f185aa5d19942dc
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
(cherry picked from commit a6caa394ba49cb58cc07613f9a5fc6bfb5975e3b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-05-24 00:46:12 +00:00
Ahmad Samir
e583c3d516 QDirListing: add flags to handle entries filtering
By extending IteratorFlag so that it replaces both QDir::Filter and
QDirIterator::IteratorFlag enums, but with better defaults (based on how
QDir/Iterator is used in 15-20 years worth of code in Qt and KDE).

Make the QDirListing(QDir ~~) ctor private, also change it to use
QDirIterator::IteratatorFlags; it will be used to port existing code.

If QDir is ported to use QDirListing::IteratorFlags, instead of
QDir::Filters, a public QDirListing(QDir) constructor can then be added.

Pick-to: 6.8
Fixes: QTBUG-125504
Task-number: QTBUG-125859
Change-Id: Ide4ff8279f554029ac30d0579b0e8373ed4337f7
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-06-27 03:35:02 +03:00
Volker Hilsheimer
457a1c973d JNI: pre-declare JNI classes for standard Java types
This avoids that we or users have to declare e.g. String or Uri in
several places in Qt. This also prevents problems where multiple
declarations (possibly from different headers) cause build errors.

As a drive-by, remove some unnecessary type declarations (e.g.
UriType, which had the same class string as Uri).

To ease the submodule update process, define a preprocessor symbol
that submodules can use to conditionally declare the type locally.
Once the dependency update is through, the symbol can be removed
and submodules can use the declaration from qjnitypes.h.

Pick-to: 6.8
Change-Id: I7d96edf644a54246302b5c5cb478e66fa615e73e
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2024-06-20 06:47:07 +02:00
Volker Hilsheimer
254d5ca38d JNI: use QJniArray in ContentFileEngine
Replace manual array creation and conversion code.

Pick-to: 6.8
Change-Id: Icd728b69790c0ed7a6ab38ff4f07622bea2be000
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2024-06-11 20:28:07 +02:00
Ahmad Samir
fd295f4bf6 QAbstractFileEngine: remove member FileTime and use QFile::FileTime
This is probably a remnant from when QAbstractFileEngine was public API
since it's been changed to private API, just use QFile::FileTime.

Pick-to: 6.7
Change-Id: I60d3d4ff811f95434b81d5ca115f5d43cfff8b15
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-03-21 19:05:02 +02:00
Ahmad Samir
3c50ad8288 QFileSystemEngine: make factory functions return unique_ptr<QABFE>
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>
2024-03-21 19:05:02 +02:00
Ahmad Samir
ceeaf1b657 QAbstractFileEngineIterator: add bool advance() virtual method
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>
2024-03-20 21:49:59 +02:00
Ahmad Samir
886eb76aea QAbstractFileEngine: add a path parameter to beginEntryList()
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>
2024-03-17 17:49:33 +02:00
Ahmad Samir
e146d835a6 QAbstractFileEngine: make {begin,end}EntryList() return a unique_ptr
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>
2024-03-17 14:30:33 +02:00
Ahmad Samir
269919fa1e QAbstractFileEngine: remove redundant endEntryList() overrides
QAFE sub-classes endEntryList() overrides returned nullptr, which is
exactly what the base class implementation does.

Change-Id: I2e901647cd087c3b8ba674db6e7b371e620af340
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-03-03 20:28:54 +02:00
Volker Krause
9d4a34bbbe Fix opening temporary content: URIs from application content providers
e5d591a0d09 focused on document or tree URIs you'd get from the file
dialog, but we can also get ones via Intents from application-specific
content providers (e.g. opening an attachment from an email client).
Those need to be handled like a single document here, parsing them
like a tree URI results in a bunch of Java exceptions down the line.

Change-Id: I19cb1075fd6a3ccad927543f8bc5a63566f4877e
Pick-to: 6.7 6.6 6.5
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2024-01-09 02:26:48 +00:00
Volker Hilsheimer
e1a349983c JNI: move signature/className template functions into a template class
Template functions don't permit partial specialization, e.g. we cannot
specialize typeSignature() to return an array signature for any
std::vector or QList type. We need to do that for better array support,
so move those functions as static members into a template class, which
then can be specialized.

Since submodules are both calling and specializing typeSignature and
className as template functions, keep and use those until the porting is
complete.

Change-Id: I74ec957fc41f78046cd9d0f803d8cc9d1e56672b
Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io>
Reviewed-by: Zoltan Gera <zoltan.gera@qt.io>
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
2023-09-22 07:18:16 +02:00
Volker Hilsheimer
7f4cdb9941 JNI: replace TYPE declarations with CLASS declarations
That we have two macros to declare a C++ type to represent a Java class
is confusing. The TYPE macro as of now allows us to declare array types,
but with QJniArray we won't need that anymore, and can just use Class[]
as the type instead. Changing that will be a follow-up commit; for now,
get rid of TYPE-usages to declare regular classes.

Change-Id: Iea0a9548772ca701148442412cf6ad567583213f
Reviewed-by: Zoltan Gera <zoltan.gera@qt.io>
Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2023-09-20 00:05:39 +02:00
Assam Boudjelthia
4721721f60 Android: fix handling of tree content uri with sub-document
Check for the index of last '/' from the non-encoded path.

Amends ea75e34d6968bb59624874411e793c95b26d0dbe.

Pick-to: 6.6 6.5 6.2 5.15
Change-Id: I3ef5d454a46c711a85fe7ef01ea9d3d93a2d574f
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
2023-08-29 16:21:56 +03:00
Assam Boudjelthia
ea75e34d69 Android: fix content URI handling for non-ascii file names
Pass an encoded URI string before parsing them through the Android APIs.

Fixes: QTBUG-114435
Pick-to: 6.6 6.5 6.2 5.15
Change-Id: I65131799fad81bfe7490d663d3b7996c94d37f0b
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
2023-08-15 15:23:30 +03:00
Assam Boudjelthia
f1778f34e0 Android: fix QDir::entryInfoList() with content URIs
Correctly return only the fileName portion from
AndroidContentFileEngineIterator::currentFileName(); which
QDirIteratorPrivate::matchesFilters() expects when looking for matches
of the file pattern provided to the QDirIterator.

Fixes: QTBUG-112738
Pick-to: 6.5 6.2 5.15
Change-Id: I98dba2df014b27f33cd7e54fab3ad2de8c7c1750
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
2023-05-11 13:38:32 +03:00
Assam Boudjelthia
ac8a39c416 Android: fix content url handling of filenames with spaces
The Android APIs expect the content url filenames to have
percent encoded spaces, so handle that internally, if missing,
under the content file engine.

Fixes: QTBUG-112663
Pick-to: 6.5 6.2 5.15
Change-Id: Ieb2ee41a2587f985b589ca54b88f1cff89992154
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
2023-05-05 17:40:46 +03:00
Michal Klocek
fb24576fa4 Fix compilation issues for android
Deals with:
  * unknown class name 'Object'; did you mean 'QObject'?
  * use of undeclared identifier 'QTimer'; did you mean 'QTime'?

Pick-to: 6.5
Change-Id: Id63064e70090ed1f816fa19db047b382220d634c
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2023-03-16 14:48:43 +01:00
Assam Boudjelthia
ba3db0cacd Android: use signature-less jni syntax for AndroidContentFileEngine
Task-number: QTBUG-98974
Pick-to: 6.5 6.4
Change-Id: I1e8e102282af2877bbbe6e8018b7649fac66804e
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
2023-01-18 15:47:12 +02:00
Assam Boudjelthia
c203ec2720 Android: handle move operation with content uris
Allow moving content uris if the destination is provided
a full content uri with a parent that's different from the
source content uri (i.e. different folders).

Note: since the underlaying Android APIs don't always know about
the parent of a uri, we do some step to deduce that, but that's
not always guaranteed to work.

Pick-to: 6.5 6.4 6.2
Task-number: QTBUG-98974
Change-Id: If21954e5963f4eb0b96c7ccd983943ea2cab5b24
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
2022-12-21 11:09:13 +02:00
Assam Boudjelthia
c1fa5d602c Android: handle rename() operation with content uris
Allow renaming content uris if the destination is provided
as a direct fileName (i.e. not full content scheme path),
and if the destination has the same trailing path (or parent)
which means a rename in the same folder structure.

Pick-to: 6.5 6.4 6.2
Task-number: QTBUG-98974
Change-Id: Ibc4973366807dd5284c19912ab04ff90f2a573cb
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
2022-12-20 12:42:31 +00:00
Assam Boudjelthia
e5d591a0d0 Android: Add facilities to handle more content URIs operations
Use DocumentFile and DocumentsContract to support more operations
on content URIs, such as:
* listing files and subdirectories with usable content uris
* mkdir, rmdir
* creating non-existing files under a tree uri
* remove

And since dealing with content URIs require some level of user
interation, manual tests were added to cover what's been implemented.

Note: parts of the code were from from BogDan Vatra <bogdan@kdab.com>.

Pick-to: 6.4 6.2
Task-number: QTBUG-98974
Task-number: QTBUG-104776
Change-Id: I3d64958ef26d0155210905b65daae2efa3db31c1
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
2022-12-14 12:15:38 +02:00
Assam Boudjelthia
f3c998510d Fix infinite loop when iterating content uri sub-files/dirs
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>
2022-12-10 07:40:11 +02:00
Lucie Gérard
05fc3aef53 Use SPDX license identifiers
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>
2022-05-16 16:37:38 +02:00
Sona Kurazyan
b28ed7fdc2 Android: use _L1 for for creating Latin-1 string literals
Task-number: QTBUG-98434
Change-Id: I5ee5fe079c9a4530f636e59f6171abfa523591f4
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2022-04-14 15:29:06 +02:00
Sona Kurazyan
d0a08d1f11 Android: stop using QLatin1Char constructor for creating char literals
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>
2022-04-14 15:29:06 +02:00
Jarkko Koivikko
1fefff6d1f Android: Keep the ParcelFileDescriptor open for content uris
Detaching fd and closing the ParcelFileDescriptor prevents IO with the
services like Google Drive on Android.

Instead, the file system should keep the ParcelFileDescriptor open while
the IO operations take place and close it manually. Also, prevent Qt
from closing the handle for us.

Pick-to: 6.2 6.3
Fixes: QTBUG-101996
Change-Id: Ie54c04ad5aa1e7ee5444a04c30ac1323f73047bb
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2022-03-25 19:06:53 +02:00
Ievgenii Meshcheriakov
56e13acf4e QAbstractFileEngine: Add permission argument to open()
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>
2021-12-04 01:27:08 +01:00
Assam Boudjelthia
c4961c0fbe Use templated QJniObject::object() instead of static_cast
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>
2021-05-06 18:06:44 +00:00
Xing LinKun
6a7d2da7dd Fix coding style in android platform and style plugins
Change-Id: Ic0a1150178c571ea0c20a045ad7520d23d6d878c
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2021-03-31 01:09:24 +00:00
Assam Boudjelthia
255459250d Add QAndroidApplication as a nativeInterface
QAndroidApplication provides the Android specific app context() and
isActivityContext() to determine whether the context is an Activity or
otherwise a Service.

Task-number: QTBUG-90499
Change-Id: Iae2eef7ec44859a89825b09f52f09506b20b5420
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-02-20 22:53:05 +02:00
Assam Boudjelthia
4e60681c87 Make QJniObject and QJniEnvironment public API
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>
2021-01-27 17:23:04 +02:00
Volker Krause
d53bbecf4c Fix QSaveFile always failing on content: URLs
QSaveFile needs QFileInfo::isWritable() to work, which 7e5f38aec667 caused
to always return false for content: URLs.

Change-Id: If839331e4bd176765ed242791cb253c2064f5f6d
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2020-10-23 16:37:14 +02:00
Assam Boudjelthia
1907599bfd Android: rename Android's package name for Qt 6
Rename Android package name org.qtproject.qt5.android to
org.qtproject.qt.android to avoid inconsistency with Qt 6 name.
Also, we include the major version number in the jar target.

Task-number: QTBUG-86969
Change-Id: Ibb68947289be1079911b34ea157bf089cc52c47f
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2020-10-03 11:22:35 +03:00
Andy Shaw
ac17e62f65 Android: Add support for travesing directories and accessing files
This enables QDir and QFileInfo/QFile to work with entries found from
a entryList() as it will obtain the permission for these files correctly
when it is encountered.

Due to what seems to be a quirk in the Android API, we cache whenever we
come across a known directory to save time later on for checking if it
is a directory. All uris accessed where we get permissions for are
cached so we get the right URI for that given content url as some are
granted via the Intent.

Fixes: QTBUG-85538
Fixes: QTBUG-83041
Fixes: QTBUG-76886
Pick-to: 5.15
Change-Id: I685b3c60804812a0e4b85fbdbb4ec5efaa09420c
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2020-08-07 12:04:57 +02:00
Andy Shaw
7e5f38aec6 Android: Add support for getting information about content uris
This enables things like size(), exists() to work with Android content
uris with the provided uri given from a filedialog. It is expected that
it is always a full path due to the nature of content uris, so relative
paths will not work.

Change-Id: I9c9ea42833677eb9d937b33e9dd42ee2a7d9c7c5
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
2020-02-28 16:37:34 +02:00
Volker Krause
7d2d1eb9e0 Add file engine for Android content URLs
The "file dialog" on Android returns such URLs, which so far required
special-casing this in application code. With this change QFile can
consume those URLs directly.

Change-Id: I489c0db112cf1dc7497e7a90f0e9a79ea8fa5237
Reviewed-by: Nicolas Fella <nicolas.fella@kdab.com>
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
Reviewed-by: Aleix Pol Gonzalez <aleixpol@kde.org>
2019-02-13 10:31:59 +00:00