165 Commits

Author SHA1 Message Date
Assam Boudjelthia
5c37d3f06b Android: rename and move updateWindow native method to QtWindow
That method is related to window management so move it to
QtWindow where it belongs, and any related C++ code from
androidjnimain.cpp to QAndroidPlatformWindow.

Rename the method to updateWindows since it's operating on all
windows and not one window.

Change-Id: I91e729b0749b6a8168b7126f9140d79c542b23d3
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2024-12-03 17:27:27 +02:00
Volker Krause
83483b8b20 Android: Send locale/language change events on system locale changes
This enables applications to retranslate or otherwise update their UI
when the Android system locale/language settings are changed during
their runtime.

Pick-to: 6.8
Change-Id: Id482ca146080d9f3e74990f64e686f6b3504887c
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2024-10-11 19:33:41 +02:00
Assam Boudjelthia
cd5d30fa33 Android: delete androidContentFileEngineHandler in terminateQt()
Similar to other Android file engine handlers.

Pick-to: 6.8
Change-Id: I63591e09312e439eee1e7bdd71a65d3df4cefbae
Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io>
2024-10-05 11:47:13 +03:00
Assam Boudjelthia
0db5b424cd Android: support uncompressed native libs within APKs
Android 6 and above produces uncompressed native libraries that
are only part of the APK by default. However, Qt had this behavior
explicitly disabled via packagingOptions.jniLibs.useLegacyPackaging
Gradle flag (previously extractNativeLibs manifest flag) because
we didn't support loading libraries directly from the APK.

This patch adds support for reading and loading shared libraries
directly from the APK without having them extracted to disk. Enabling
this might increase slightly the total size of produced APKs, but
saves on disk space after installation and also on update sizes from
the Play Store and slightly faster startups [1][2].

Loading libraries on the Java side is handled by System.loadLibrary().
On C++, dlopen(3) can directly handle library paths relative to the
APK file [3] which would save us the need to add custom code that calls
android_dlopen_ext() [4] which works with compressed libraries then
using AssetFileDescriptor and having to manage its file descriptor
manually.

To ensure proper integration with various Qt APIs and modules, this
adds a QAbstractFileEngine/Iterator implementations to allow reading
and listing APK files. Since, the files are expected to not change,
they are cached once at startup and re-used thereafter. The engine
implementation allows reading the libraries content using Android's
AssetManager. Also, it allows mapping the libraries directly to
memory to allow proper integration with QPluginLoader.

For plugins, the native libs dir inside the APK is added to Qt and
QML plugins search paths.

With this patch, both compressed and uncompressed libs should work,
to ensure this, an auto test is added with 'useLegacyPackaging true'
to make sure both scenarios still works.

[ChangeLog][Android] Add support for uncompressed native libraries
within APKs.

[1] https://android-developers.googleblog.com/2016/07/improvements-for-
smaller-app-downloads.html
[2] https://developer.android.com/guide/topics/manifest/application-
element#extractNativeLibs
[3] https://android.googlesource.com/platform/bionic/+/master/android-
changes-for-ndk-developers.md#Opening-shared-libraries-directly-from-an-
APK
[4] https://developer.android.com/ndk/reference/group/
libdl#android_dlopen_ext

Fixes: QTBUG-61072
Fixes: QTBUG-97650
Change-Id: Ica6c4cc9e5bd8f3610829b76b64bf599339435d9
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2024-10-05 00:56:01 +03:00
Soheil Armin
55fc15ce82 Android: Add Java QtAbstractItemModel and QtAbstractListModel
These classes used to be a part of QtDeclarative and are being moved
to QtCore based on API reviews.

Pick-to: 6.8
Task-number: QTBUG-126976
Task-number: QTBUG-126977
Change-Id: Ic269f23ca2292031cda62faf41428667889537d0
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2024-08-20 03:05:06 +03:00
Petri Virkkunen
cf816a57f6 Android: Remove unused qtActivityDelegate() API
Since the new functionality interface feature has removed all calls to
qtActivityDelegate, this is no longer needed.

Task-number: QTBUG-118874
Change-Id: Ibf65f953be8c4694b543610b405b65b91f3ec9ee
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2024-05-21 16:15:14 +03:00
Petri Virkkunen
6bee03629f Android: Implement input backend interface
Interface for input-related actions, based off of QtInputDelegate.

Implements all the QtInputDelegate functions called from native code
plus an extra function that allows the native side to get a
QtInputConnectionListener object for QtWindow creation.

Removed some unused functions and unmarked @UsedFromNativeCode in some
that are no longer called from native, but still used from java.

Added QtInputConnectionListener null checks in QtInputConnection, due
to the possibility of a non-existent InputInterface returning a null
QtInputConnectionListener for the QtInputConnection constructor.

Task-number: QTBUG-118874
Change-Id: I8d4cde3e0c735471d0fa30d16db20eb13542cdaa
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
2024-05-21 16:15:14 +03:00
Petri Virkkunen
2322c71cc7 Android: Implement accessibility backend interface
This will provide the JNI API used by QtAndroidAccessibility namespace
via QtAndroid namespace.

Removed unnecessary functions like createAccessibilityDelegate from
QtEmbeddedDelegate, moved the interface extension to where it is
actually supported: QtActivityDelegate.

Until now, QtActivityDelegateBase has called the QtEmbeddedDelegate
implementation on createAccessibilityDelegate() in order to create a
QtAccessibilityDelegate - which has not actually created the delegate -
and then done a null check before trying to call the - always null -
QtAccessibilityDelegate member.

The embedding and service-embedding usecases are now dealt with via the
interface validity checks on the C++ side, until an actual
implementation for those is completed.

Task-number: QTBUG-118874
Change-Id: Iea3db0e17ae80c0443e9027bdfe36bba311eed2b
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2024-05-21 16:15:13 +03:00
Petri Virkkunen
46a23b1fae Android: Implement interface for window-related backend
Add QtWindowInterface interface, to access native functionality related
to windows.

QtActivityBase now follows QtNative.onAppStateDetailsChanged in order
to register and unregister functionalities of QtActivityDelegate.

Task-number: QTBUG-118874
Change-Id: Ifad33bd7aac7683081f026f0591ef496909be095
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2024-05-21 16:15:13 +03:00
Petri Virkkunen
124eaa6b22 Android: Implement backend register class
This class will be used by java delegates to register their supported
functionalities to the Qt/C++ side.

It registers two native functions: register- and
unregisterBackend, which will be used by the aforementioned
delegates.

It will be used by C++ classes which currently use
QtAndroid::qtActivityDelegate() to access a JNI object which implements
all these features in one big class.

Task-number: QTBUG-118874
Change-Id: I23a7e433104c20b96c08b682a96cfaec98ecb4a9
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2024-05-21 16:15:13 +03:00
Petri Virkkunen
b43341f678 Android: Do not wait for service onBind() in service embedding path
When embedding QML into an Android service, Qt is not actually running
as a service. Avoid checking for QtAndroid::Service() and assuming that
means we are running as a service.

Task-number: QTBUG-118874
Change-Id: I5eea32b9fc200c4f34f1507d591aa1a483849118
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2024-04-30 22:17:04 +03:00
Jens Trillmann
efd00066b4 Android: Propagate a11y ObjectShow events to screen reader
Sending an ObjectShow event, e.g. by setting QQuickItem::visible to
true, has to trigger a refresh of the screen reader hierarchy. If the
signal is ignored the source of the signal will be ignored by the
screen reader.

Fixes: QTBUG-122436
Pick-to: 6.5 6.7
Change-Id: I32ee2e8b2602cd0dd9b9a83ff1fe426d88d137a8
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2024-04-25 17:19:20 +02:00
Volker Hilsheimer
eee575595b ColorScheme: clean up code to prepare adding a setter
The current QStyleHintsPrivate::setColorScheme is called when the system
theme changes, handling the change and informing the application. It is
not a setter. When we add a public setter, that setter will have to go
through the QPlatformTheme to request an override for the application.
That will then result in a call back to the QStyleHints to update the
theme with the effective color scheme (or ignore the request for the
override, on some platforms).

Rename it (and similar misleading APIs in platform plugins) to
updateColorScheme, and adjust outdated comments in some of the platform
plugins.

Task-number: QTBUG-124490
Change-Id: I6a852211254993df86acf2e2d42cf345e7401f4f
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Doris Verria <doris.verria@qt.io>
2024-04-23 16:44:26 +02:00
Tinja Paavoseppä
702c420f51 Android: Add classes to embed QML into native Android
Add classes that make it possible to add QML as a View into
a native Android app:

QtView: Base class for QtQuickView, handles non-Quick dependent
operations. In essence a Java ViewGroup class which loads a
QWindow and embeds it into itself.

QtEmbeddedLoader: Extends QtLoader for embedded case, creates the
embedded version of QtActivityDelegate and provides an embedded-specific
path to loading Qt libraries (Mostly just allows users to set the name
of the main lib)

QtAndroidWindowEmbedding namespace: Deals with calls from
QtEmbeddedDelegate to create/destroy QWindow and from QtView to
show the window.

Take the QtEmbeddedDelegate introduced in an earlier commit
into use, and add functionality for loading QWindows for
QtViews and managing QtViews into it.

Add a factory for creating instances of QtEmbeddedDelegate.
The factory holds a map of QtEmbeddedDelegate objects and
creates them, with the Activity as the key. This is to make
it so that the same delegate can be used by multiple views
which share the same Context.

Known issues left:
* keyboard focus not working, as with other child windows

Pick-to: 6.7
Task-number: QTBUG-118872
Change-Id: I94a5f9b4f904c05cc6368cf20f273fcf10d31f17
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2024-01-30 20:01:29 +02:00
Tinja Paavoseppä
06d2aa91eb Android: Add a context delegate for embedding QML to native Android
When we are embedding a QML view to a non-Qt Android app, there are a lot
of functionalities that are shared with the refular Qt Android app, but
some are not. We should not, for example, try to control the hosting
Activity.
Create a base class that both the QtActivityDelegate, used for the
standard Qt for Android app, and the delegate for the embedding case
can extend.

In this commit, the QtEmbeddedDelegate is very simple, the
biggest difference to QtActivityDelegate being it does not create
a QtLayout or instantiate a QtAccessibilityDelegate.
It does start the Qt app, without waiting for a layout, and register
to listen for changes in the state of the Qt app.

Taking the embedded delegate into use, loading the embedded QML
views and their handling is added in a follow up commit.

Task-number: QTBUG-118872
Pick-to: 6.7
Change-Id: Id390a2b35c70b35880523886bf6fcf59d420cb42
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2024-01-21 15:46:30 +02:00
Tinja Paavoseppä
c1a79b442c Android: Differentiate between standalone Qt app and embedded view
Add a helper method to tell whether the app is a standalone Qt for
Android app, where also the Context is created by Qt, or whether Qt
content is embedded as a View into a Context created by the user, i.e.
a "native" Android app.

Pick-to: 6.7
Change-Id: I618ba1c8cb40c9b132fc12a7ee6d54c071efa983
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2023-12-14 00:26:55 +02:00
Tinja Paavoseppä
b2e44a2d1d Android: Fix touch events for child windows
In the touch dispatcher methods, all events were routed for the
top level window at the position, which lead to all the events
being delivered for the parent window.

Since the JNI methods already have a parameter for window ID, take
that into use and determine the window to deliver the events to
by ID.

Pick-to: 6.7
Change-Id: I07ad7851c32a3e633ee748036d6818b6d0fa5588
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2023-12-14 00:26:55 +02:00
Tinja Paavoseppä
0a92d881bb Android: Make QtLayout per window instead of per screen
Each QAndroidPlatformWindow has its own QtLayout,
instead of one for the whole app/screen. This paves the
way for addition of child windows.

Task-number: QTBUG-116187
Change-Id: I36c68cea1a5f27ded3696bcfc2fbc04d9a8ce79e
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2023-12-08 15:53:36 +02:00
Tinja Paavoseppä
2020ce5fd2 Android: Give raster windows their own surface, and flush via RHI
Refactored platform windows on Android so that all window
types, including raster windows, have their own surface to
draw on.

Raster windows now flush the backing-store via RHI/OpenGL.

As a drive by, update to newer JNI syntax where appropriate.

Task-number: QTBUG-116187
Change-Id: I3b764b7126abf53556750b0ccbb7d27efe007bc1
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2023-12-07 10:56:43 +02:00
Assam Boudjelthia
82a40f084b AndroidTestRunner: fix args with quotes and spaces
First, replace double quote characters with 3 escaped double quotes
to allow QProcess::splitCommand() to treat it as an actual quote
character that's part of the tag.

Then, escape single quote characters so they don't interfere with
the shell command and also to be treated as part of the argument.

Lastly, surround the args with escaped double quote so that args
with spaces are also treated as one.

Amends b044323c1656aeeec508afab8457755cc1e8c587.

Example of this:
 tst_qkeyevent::modifiers("M","e","t","a") for double quotes
 tst_qunicodetools::wordBreakClass(two words) for spaces
 tst_QSpinBox::stepSelectAll("don't select all") for single quotes

Task-number: QTQAINFRA-5703
Change-Id: Ie4317e4350bbac619bac41e41f42613f50cf1ad4
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-12-05 22:03:55 +02:00
Assam Boudjelthia
b044323c16 AndroidTestRunner: Fix treatement of quotes in test args
This has two parts, under testrunner, make sure to pass test args
that has quotes as \\\" so that the Android app gets a \" after parsing
the intent extras. The app args are then is passed to C++ where
QProcess::splitCommand() is used to parse the args string into a list,
and to preserve the quotes in this case, the former call expects triple
quotes to to get the quote character preserved in the split list.

Fixes: QTQAINFRA-5703
Change-Id: Iad81cadf24a6def21ef1536c882ecd510c4426cf
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-11-30 17:26:26 +02:00
Assam Boudjelthia
57330a18ca Android: rename isPluginRunning to isNativePluginIntegrationReady
This has been used to notify that the platform integration is
setup and ready, now the name is more descriptive of what it does.

Task-number: QTBUG-118077
Change-Id: I9fab525f07433f9ec8057e2475a3b1e4658f84d9
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
2023-11-28 14:37:56 +02:00
Assam Boudjelthia
9a58062a73 Android: print correct return code of main()
... and print it always after main() returns.

Task-number: QTBUG-118077
Change-Id: I1f57b3f7a646d01eebf67d4a4ff6a8d9f6e82cc7
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
2023-11-23 03:34:26 +02:00
Tinja Paavoseppä
2198fc6a4a Android: Fix broken insertNativeView() signature
Method is trying to infer the signature from the types of the
arguments, but since the argument for the view is a plain jobject
this signature is wrong, method is not found and the view is never
inserted.

Change-Id: I3cbf9bccbcb1e5526f843213ba0f66e5bd1e7107
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2023-11-17 23:27:01 +02:00
Assam Boudjelthia
f5e2302851 Android: don't call delegates outside of the Activity
The delegate classes shouldn't be used outside of the Activity/Service
classes, since they're practically private implementation, so don't use
them anywhere outside Activity/Service.

Since Qt Android apps still mainly support having one QtActivity/
QtService, QtNative heavily uses those objects to do various operations.
For that reason, we still need to use the delegate there. The aim is
to change that in future patches and do the operations where they make
more sense for example directly under QtActivityBase/QtActivityDelegate
or Service counterpart.

The QtServiceDelegate is used no where and have no special
implementation, so it's removed here.

Task-number: QTBUG-118077
Change-Id: I5e106318169be19fec8163e8e500ee573af0e1bc
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-11-10 21:57:11 +02:00
Assam Boudjelthia
0f3dbd6dc7 Android: remove a11y methods from QtNative, call a11y delegate direct
Remove yet another two layers of delegation, QtNative calling
QtActivityDelegate and that in turn calls QtAccessibilityDelegate.
Now from c++ native code, acquire the a11y delegate and use it to
call a11y operations that live in QtAccessibilityDelegate.

Task-number: QTBUG-118077
Change-Id: I9e84520c2caa281a6f786a687b0106d702f92a67
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
2023-11-06 19:59:51 +02:00
Assam Boudjelthia
742f45f7cf JNI: pass same QJniEnvironment object to QAndroidPlatformClipboard
... registerNatives() call.

Change-Id: I42539846249880ed4a215522bdcafb3a2ffa4d14
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-11-02 21:46:32 +02:00
Assam Boudjelthia
58c7249ee8 Android: move display and screen management to new QtDisplayManager
Have all or most of Android code dealing with displays in
QtDisplayManager. Also, simplify setApplicationDisplayMetrics()
call and avoid caching any uneccessary members.

Task-number: QTBUG-118077
Change-Id: I943069c24bb40ae3016db5896e553b501e700a6b
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
2023-11-02 16:13:22 +02:00
Volker Hilsheimer
daf15a4aaf Android: clean up error handling and native methods registration
Emit log output and return false immediately if we fail to get both the
Activity and the Service objects. Standardize the registerNative methods
to return bool and take a QJniEnvironment, and adjust the macros
accordingly.

Simplify the startup routine to use QJniEnvironment.

Change-Id: I11be35426520dc803f5a07bbb495e908592f254e
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
2023-11-01 15:58:45 +08:00
Assam Boudjelthia
457566c96f Android: Move clipboard management to own class
Move all clipboard management logic outside of QtNative and
to own QtClipboardManager class. Also, don't keep any keep
Activity objects under it to avoid memory leaks, the native
c++ clipboard manager should be responsible of passing a
context when needed instead.

As a pass-by, use newer JNI APIs for C++ QtAndroidClipboard
code.

Task-number: QTBUG-118077
Change-Id: I61726e84a75918d80329f753e9e1c6ebde179bf4
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
2023-10-30 16:59:14 +02:00
Volker Hilsheimer
8c9f5fba03 Android: don't rely on implicit cast of declared QtJniTypes to jobject
The operator jobject() should be removed from declared QtJniTypes in
qtbase, as it's dangerous. Prepare for that by calling object(), which
returns the wrapped jobject as well, or isValid() where previously the
implicit conversion to jobject also enabled implicit conversion to bool.

Change-Id: I00cf6f1463dd5ab5cbaf03d9e77bfff3bced9b15
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-10-27 17:44:35 +02:00
Volker Hilsheimer
703614f03b Android: replace QtAndroid::activity/service with QtAndroidPrivate
There's no need for both, and QtAndroidPrivate is a documented namespace.
Replace all calls to QtAndroid::activity/service with QtAndroidPrivate
equivalents, and drop the QtAndroid version. Since we no longer store a
global copy of the activity and service, we can drop the reference right
away.

This comes with a bit of overhead - QtAndroid::activity returned a copy
of a global static QJniObject (62cb5589b3723fe8162e190cd54d9c78929b98d2,
after which declared QtJniTypes became QJniObjects), while
QtAndroidPrivate::activity returns a newly created QtJniTypes::Activity
on each call.

This however makes it also safer, as the QJniObject is then associated
with the calling thread's JNI environment, and we can optimize critical
code paths where it's safe to do so later. Also, QtAndroid's activity
object was never updated, while QtAndroidPrivate's activity is updated
in the updateNativeActivity native method.

Change-Id: I36c5b504eac52d9e28b4c6b265daab8fedc877e2
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-10-27 17:44:35 +02:00
Assam Boudjelthia
ac7f22ed0a Android: move input handling from QtActivityDelegate to separate class
To further simplify the code and logic of the delegate, move keyboard
input code to separate class. Make an input delegate available under the
QtActivityDelegate to allow classes like QtNative and the Activity to
access that. For now, it's okay to leave access from QtNative to that,
but for future even that should be simplified and the Activity should be
accessing that directly.

For the case where the QtInputDelegate needs access to
QtActivityDelegate, for now namely updateFullScreen(), a new Listener
is implemented to be implemented under QtActivityDelegate.

Along the way use newer JNI APIs under C++ QtAndroidInput.

Don't make them static methods, so that it can be possible later to
do various keyboard operations to specific activity and not a global
one.

Task-number: QTBUG-114593
Task-number: QTBUG-118077
Change-Id: I110b897f6f16d0ae5f5a645551b4a82e8ad3f2fb
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
2023-10-18 16:54:31 +03:00
Juha Vuolle
c0bc0d0643 Android: fix double-freeing of a global references on app exit
The m_activityObject and m_serviceObjects are no longer plain
jobjects. Instead they are constructed with a jobject.
The constructor makes it a global ref, which the destructor
then frees. The destruction happens when the stdlib exit()
is called.

However, since the terminateQt() function already had released the
global ref, the destruction of the objects crashes the
application with a JNI APPLICATION ERROR in Android logs.

In addition since the the code only ever freed the reference to
a reference, the actual reference was leaked.

Change-Id: I6bb637dba2de59e89436685a9d63950d36438fa5
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2023-10-12 17:12:04 +03:00
Anton Kudryavtsev
60d6051490 androidjnimain: use rvalue overloads more
Change-Id: Ib4f5bccbf4f384248e2651492337ff5e227adce1
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
2023-09-19 01:29:25 +03:00
Tor Arne Vestbø
32749c913b Rename Qt::Appearance to Qt::ColorScheme
Based on discussions in the 6.5 API review, where we concluded that
'appearance' is too general. Instead, we follow the CSS standard
and use the term 'color scheme'.

Pick-to: 6.5
Change-Id: I8ceaf4138ecadff5ccd962480e8e5beb39b556ec
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Reviewed-by: Jonas Kvinge <jonas@jkvinge.net>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2023-02-13 17:19:23 +01:00
Piotr Mikolajczyk
9ce8d4890f Add handling of screen hotplug
When a display is connected to an Android device
a notification is sent to the platform layer of the
application. The QAndroidPlatformIntegration will create
a platform screen and add it to QWindowSystem.

Task-number: QAA-1257
Change-Id: Id2cf6b47363630c3b5c93c0bc778e2058d8372b3
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2022-12-13 07:49:22 +00:00
Axel Spoerl
4973155512 Replace QPlatformTheme::Appearance by Qt:Appearance
With the introduction of Qt:Appearance, its predecessor in
QPlatformTheme has become redundant.

This patch replaces all occurrences of QPlatformTheme::Appearance with
the new enum class.

Task-number: QTBUG-106381
Change-Id: I5406f1b7c19f68571f074617c681318c96a6517e
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2022-09-20 22:25:59 +02:00
Samuel Mira
072387edec Android: Fix flickering on window resize and show keyboard
Changed to use display getMetrics which will return the size of the
application window, and use getRealMetrics to obtain the size of the
largest region accessible to the app.
I updated the fullscreen mode to use the new sizes.

Task-number: QTBUG-41170
Task-number: QTBUG-66727
Pick-to: 6.4 6.3 6.2 5.15
Change-Id: Ic25555ed2e1b910b3fdbc0f3a31e3a19763a04eb
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Rami Potinkara <rami.potinkara@qt.io>
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
2022-09-17 08:42:48 +00:00
Bartlomiej Moskal
76abdaafb5 Android: Light/dark modes detection
After commit: 2248487c6ca9d5459c70a16868d5aeee07d96157 light/dark mode
detection is supported by Windows and macOS. This commit add similar
implementation on the Android side.

Task-number: QTBUG-83185
Pick-to: 6.4 6.3 6.2
Change-Id: Id1ece98e91a31759b58d651ef62b3715ea25d85f
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2022-09-05 18:29:09 +02:00
Sona Kurazyan
711105058a Apply Q_CONSTINIT where beneficial
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>
2022-09-01 19:44:19 +02:00
Jens Trillmann
3c70919883 Android A11Y: Notify android about scroll events
QtQuick Flickable has an issue that after a scroll the previously
hidden items are not added to the A11Y hierarchy. That happens because
Android has no ways to detect that something has changed.

This patch uses the ScrollingEnd event to notify Android A11Y backend
that the Flickable was scrolled, so that it could update the A11Y
hierarchy and add the previously hidden nodes.

The ScrollingEnd event generation is added to QQuickFlickable in a
separate commit.

Task-number: QTBUG-103513
Pick-to: 6.4 6.3 6.2 5.15
Change-Id: Ie6cd688d56343bcfe7ce9580c0b9244dd6d6c068
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Samuel Mira <samuel.mira@qt.io>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2022-08-29 12:26:43 +02:00
Assam Boudjelthia
edc024e826 Android: handle quoted args passed to an app
Currently, arguments passed to the app through applicationArguments
extra bundle treat every space as an argument separator. This then
doesn't handle the case where an argument is a space separated quoted
multi-word. This is more apparent when androidtestrunner is passing
test arguments to the app where an argument can be a test case with
a data tag that contains a space, which then is treated as two separate
tag names.

This change makes sure that androidtestrunner quotes each argument,
and the app doesn't split the arguments list by spaces, but rather
passed the argument string directly to c++ where
QProcess::splitCommand() is used to get the correct set of arguments
that will be passed to main().

Pick-to: 6.4 6.3 6.2
Task-number: QTBUG-104730
Change-Id: I45d8ca979d90f2a383c84623f0eb2eec29bba727
Reviewed-by: Dimitrios Apostolou <jimis@qt.io>
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
2022-08-11 13:21:44 +00:00
Volker Hilsheimer
367092d7e0 Return specific types for frequently used Java objects
This allows us to specialize JNI type signature templates for e.g. the
context object, which in Java signatures is "android/content/Context".

Introduce a Q_DECLARE_JNI_TYPE macro that takes care of the plumbing.
The types declared this way live in the QtJniTypes namespace, and
transparently convert from and to jobject. Since jobject is a typedef
to _jobject* we cannot create a subclass. Use a "Object" superclass
that we can provide a QJniObject constructor for so that we don't
require the QJniObject declaration to be able to use the macro.

The APIs in the QNativeInterface namespace doesn't provide source or
binary compatibility guarantees, so we can change the return types.

Change-Id: I4cf9fa734ec9a5550b6fddeb14ef0ffd72663f29
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2022-05-17 00:34:06 +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
Ivan Solovev
0613146d21 Android A11Y: handle LocationChanged event only for focused element
LocationChanged event unconditionally triggered invalidateVirtualViewId
call. That call results in TYPE_WINDOW_CONTENT_CHANGED Android event,
which causes a lot of background processing.
That is not correct, because LocationChanged event is generated by
every accessible element, not only the one that has A11Y focus.

This patch checks event->uniqueId(), and processes only events that
come from the focused accessible element.

Done-with: Mike Achtelik <mike.achtelik@gmail.com>
Task-number: QTBUG-102594
Pick-to: 6.3 6.2 5.15
Change-Id: I6b941733c9d215fed5ee5a7aeeb5be234add9ebe
Reviewed-by: Mike Achtelik <mike.achtelik@gmail.com>
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
2022-05-16 15:16:35 +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
Assam Boudjelthia
daf7f07c1b Android: terminate argv passed to main() with nullptr
the char array of argv passed to the app's main() function
need to be null terminated [*] and argv to be **char.

[*] http://eel.is/c++draft/basic.start.main#2

Fixes: QTBUG-101028
Pick-to: 6.2 6.3 5.15
Change-Id: I6e3a685f092a92a94f60d166357b75d2538af74c
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
2022-03-05 00:36:40 +02:00
Ivan Solovev
79fb80152f Android: make sure that orientationChange is reported after resize
On Android orientation changes are reported from the
DisplayListener.onDisplayChanged() method, while the screen size
changes are reported from QtLayout.onSizeChanged().
In practice these callbacks come in random order, so rotating the
screen multiple times might result in inconsistent order of signals
and events.

This patch makes sure that size change events always happen before
orientation changes. This is done by caching the new orientation
values and reporting them only when needed. At this point we also
need to use QMetaObject::invokeMethod() for orientation change,
like it is done for geometry change. Otherwise the orientation
update can still be processed earlier than the geometry change.

Also note that at some point we might get an orientation change
without a size change (for example Qt::LandscapeOrientation ->
Qt::InvertedLandscapeOrientation). That is the reason for
isSimilarRotation() helper function.

As a drive-by: ignore size changes with inconsistent values when window
size is reported to have old orientation, while the screen has already
been rotated. In such cases a new size change will be triggered shortly
with normal value.

Task-number: QTBUG-94459
Pick-to: 6.3 6.2 5.15
Change-Id: I5c98e526d0370d380344b2297169d5e0c0ee8ea7
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2022-03-04 02:37:11 +01:00
Ivan Solovev
285ea13286 Android: set all QScreen's geometry-related parameters together
Screen has 3 parameters:
- physical size
- screen size (or screen geometry)
- available geometry

Before this patch, they were reported in 3 different methods. Screen
size update and available geometry update both were generating the
"screen geometry changed" event, that updated the user-visible
parameters. As a result, at some point we could end up in an
intermediate state, when screen size was already updated, but
available geometry was not yet updated.
This was specially visible while changing the screen orientation:
at some point screen geometry could be reported for the new
orientation, while the available geometry - still for old orientation.

This patch introduces a new method to set all geometry-related
parameters together and generate only one "screen geometry changed"
event. This allows to maintain consistency between 'geometry' and
'availableGeometry' properties of QScreen.

Task-number: QTBUG-94459
Pick-to: 6.3 6.2 5.15
Change-Id: I844f6d0db87df8d5e6e9bcce5d27126384a5a0de
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2022-03-04 02:37:10 +01:00