22#include <android/api-level.h>
23#include <android/asset_manager_jni.h>
24#include <android/bitmap.h>
26#include <QtCore/private/qjnihelpers_p.h>
27#include <QtCore/qbasicatomic.h>
28#include <QtCore/qjnienvironment.h>
29#include <QtCore/qjniobject.h>
30#include <QtCore/qprocess.h>
31#include <QtCore/qresource.h>
32#include <QtCore/qthread.h>
33#include <QtGui/private/qguiapplication_p.h>
34#include <QtGui/private/qhighdpiscaling_p.h>
36#include <qpa/qwindowsysteminterface.h>
64extern "C" typedef int (*
Main)(int,
char **);
175 QJniObject::callStaticMethod<void>(
m_applicationClass,
"setSystemUiVisibility",
"(I)V", jint(uiVisibility));
180 QJniObject::callStaticMethod<void>(
m_applicationClass,
"notifyAccessibilityLocationChange",
181 "(I)V", accessibilityObjectId);
187 accessibilityObjectId, parentObjectId);
192 QJniObject::callStaticMethod<void>(
m_applicationClass,
"notifyObjectFocus",
"(I)V", accessibilityObjectId);
198 "(ILjava/lang/String;)V", accessibilityObjectId,
value);
204 accessibilityObjectId);
230 AndroidBitmapInfo
info;
231 if (AndroidBitmap_getInfo(env,
bitmap, &
info) < 0) {
232 env->DeleteLocalRef(
bitmap);
237 if (AndroidBitmap_lockPixels(env,
bitmap, &
pixels) < 0) {
238 env->DeleteLocalRef(
bitmap);
251 memcpy(bmpPtr,
img.constScanLine(
y),
width);
253 AndroidBitmap_unlockPixels(env,
bitmap);
300 QString manufacturer = QJniObject::getStaticObjectField(
"android/os/Build",
"MANUFACTURER",
"Ljava/lang/String;").toString();
301 QString model = QJniObject::getStaticObjectField(
"android/os/Build",
"MODEL",
"Ljava/lang/String;").toString();
303 return manufacturer + u
' ' +
model;
308 return QJniObject::callStaticMethod<jint>(
"android/view/View",
"generateViewId",
"()I");
322 jint
x = 0,
y = 0,
w = -1,
h = -1;
326 w = std::max(geometry.
width(), 1);
327 h = std::max(geometry.
height(), 1);
345 jint
x = 0,
y = 0,
w = -1,
h = -1;
351 "(ILandroid/view/View;IIII)V",
366 "(Landroid/view/View;Z)V",
379 jint
x = 0,
y = 0,
w = -1,
h = -1;
454 const char *nativeString = env->GetStringUTFChars(paramsString, 0);
456 env->ReleaseStringUTFChars(paramsString, nativeString);
470 qCritical() <<
"dlopen failed:" << dlerror();
475 qWarning(
"No main library was specified; searching entire process (this is slow!)");
481 <<
"Could not find main method";
506 JNIEnv* env =
nullptr;
507 JavaVMAttachArgs
args;
508 args.version = JNI_VERSION_1_6;
509 args.name =
"QtMainThread";
511 JavaVM *vm = QJniEnvironment::javaVM();
513 vm->AttachCurrentThread(&env, &
args);
517 qRegisterMetaType<Qt::ScreenOrientation>(
"Qt::ScreenOrientation");
525 for (
int i = 0;
i < argc;
i++)
527 argv[argc] =
nullptr;
535 qWarning() <<
"dlclose failed:" << dlerror();
606static void setSurface(JNIEnv *env, jobject , jint
id, jobject jSurface, jint
w, jint
h)
613 auto surfaceClient =
it.value();
615 surfaceClient->surfaceChanged(env, jSurface,
w,
h);
619 jint screenHeightPixels, jint availableLeftPixels,
620 jint availableTopPixels, jint availableWidthPixels,
621 jint availableHeightPixels, jdouble xdpi, jdouble ydpi,
622 jdouble scaledDensity, jdouble density, jfloat refreshRate)
632 const QSize screenSize(screenWidthPixels, screenHeightPixels);
634 const QRect availableGeometry(0, 0, availableWidthPixels, availableHeightPixels);
635 const QSize physicalSize(
qRound(
double(screenWidthPixels) / xdpi * 25.4),
636 qRound(
double(screenHeightPixels) / ydpi * 25.4));
641 availableGeometry.
left(), availableGeometry.
top(), availableGeometry.
width(),
664 QRect availableGeometry =
w->screen()->availableGeometry();
665 if (
w->geometry().width() > 0 &&
w->geometry().height() > 0 && availableGeometry.
width() > 0 && availableGeometry.
height() > 0)
671 if (
screen->rasterSurfaces())
795static jobject
onBind(JNIEnv *, jclass , jobject intent)
808 {
"setSurface",
"(ILjava/lang/Object;II)V", (
void *)
setSurface },
813 {
"onActivityResult",
"(IILandroid/content/Intent;)V", (
void *)
onActivityResult },
814 {
"onNewIntent",
"(Landroid/content/Intent;)V", (
void *)
onNewIntent },
815 {
"onBind",
"(Landroid/content/Intent;)Landroid/os/IBinder;", (
void *)
onBind },
822#define FIND_AND_CHECK_CLASS(CLASS_NAME) \
823clazz = env->FindClass(CLASS_NAME); \
825 __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_classErrorMsg, CLASS_NAME); \
829#define GET_AND_CHECK_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE) \
830VAR = env->GetMethodID(CLASS, METHOD_NAME, METHOD_SIGNATURE); \
832 __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_methodErrorMsg, METHOD_NAME, METHOD_SIGNATURE); \
836#define GET_AND_CHECK_STATIC_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE) \
837VAR = env->GetStaticMethodID(CLASS, METHOD_NAME, METHOD_SIGNATURE); \
839 __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_methodErrorMsg, METHOD_NAME, METHOD_SIGNATURE); \
843#define GET_AND_CHECK_FIELD(VAR, CLASS, FIELD_NAME, FIELD_SIGNATURE) \
844VAR = env->GetFieldID(CLASS, FIELD_NAME, FIELD_SIGNATURE); \
846 __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_methodErrorMsg, FIELD_NAME, FIELD_SIGNATURE); \
850#define GET_AND_CHECK_STATIC_FIELD(VAR, CLASS, FIELD_NAME, FIELD_SIGNATURE) \
851VAR = env->GetStaticFieldID(CLASS, FIELD_NAME, FIELD_SIGNATURE); \
853 __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_methodErrorMsg, FIELD_NAME, FIELD_SIGNATURE); \
864 __android_log_print(ANDROID_LOG_FATAL,
"Qt",
"RegisterNatives failed");
887 jobject
object = activityObject ? activityObject : serviceObject;
891 m_assets = env->NewGlobalRef(env->CallObjectMethod(
object, methodID));
895 m_resourcesObj = env->NewGlobalRef(env->CallObjectMethod(
object, methodID));
898 m_bitmapClass =
static_cast<jclass
>(env->NewGlobalRef(clazz));
900 ,
"createBitmap",
"(IILandroid/graphics/Bitmap$Config;)Landroid/graphics/Bitmap;");
913 "(Landroid/content/res/Resources;Landroid/graphics/Bitmap;)V");
923 static bool initialized =
false;
925 return JNI_VERSION_1_6;
930 JNIEnv *nativeEnvironment;
934 UnionJNIEnvToVoid uenv;
938 if (vm->GetEnv(&uenv.venv, JNI_VERSION_1_6) != JNI_OK) {
939 __android_log_print(ANDROID_LOG_FATAL,
"Qt",
"GetEnv failed");
943 JNIEnv *env = uenv.nativeEnvironment;
949 __android_log_print(ANDROID_LOG_FATAL,
"Qt",
"registerNatives failed");
957 if (threadSetter.
thread())
959 __android_log_print(ANDROID_LOG_INFO,
"Qt",
"qt started");
960 return JNI_VERSION_1_6;
static const char m_classErrorMsg[]
static const char m_qtTag[]
static int m_pendingApplicationState
static jobject m_ARGB_8888_BitmapConfigValue
#define GET_AND_CHECK_STATIC_FIELD(VAR, CLASS, FIELD_NAME, FIELD_SIGNATURE)
static jmethodID m_bitmapDrawableConstructorMethodID
static void setDisplayMetrics(JNIEnv *, jclass, jint screenWidthPixels, jint screenHeightPixels, jint availableLeftPixels, jint availableTopPixels, jint availableWidthPixels, jint availableHeightPixels, jdouble xdpi, jdouble ydpi, jdouble scaledDensity, jdouble density, jfloat refreshRate)
#define GET_AND_CHECK_STATIC_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE)
static AndroidAssetsFileEngineHandler * m_androidAssetsFileEngineHandler
static Q_CONSTINIT QBasicAtomicInt startQtAndroidPluginCalled
static QBasicMutex m_platformMutex
static jmethodID m_loadClassMethodID
static void * m_mainLibraryHnd
static void waitForServiceSetup(JNIEnv *env, jclass)
static sem_t m_exitSemaphore
static JNINativeMethod methods[]
static void handleScreenChanged(JNIEnv *, jclass, jint displayId)
static jclass m_bitmapDrawableClass
QT_END_NAMESPACE Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *)
static jmethodID m_createSurfaceMethodID
static void onNewIntent(JNIEnv *env, jclass, jobject data)
#define FIND_AND_CHECK_CLASS(CLASS_NAME)
static QtJniTypes::Activity m_activityObject
#define GET_AND_CHECK_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE)
static jobject m_classLoaderObject
int(* Main)(int, char **)
static jmethodID m_createBitmapMethodID
static void handleUiDarkModeChanged(JNIEnv *, jobject, jint newUiMode)
QHash< int, AndroidSurfaceClient * > m_surfaces
static void handleRefreshRateChanged(JNIEnv *, jclass, jfloat refreshRate)
static void startQtApplication(JNIEnv *, jclass)
static Q_CONSTINIT QBasicMutex m_surfacesMutex
static int m_availableHeightPixels
static void updateApplicationState(JNIEnv *, jobject, jint state)
static sem_t m_terminateSemaphore
static jclass m_bitmapClass
static void handleOrientationChanged(JNIEnv *, jobject, jint newRotation, jint nativeOrientation)
static jobject m_resourcesObj
static jobject m_RGB_565_BitmapConfigValue
static jclass m_applicationClass
static void terminateQt(JNIEnv *env, jclass)
static QtJniTypes::Service m_serviceObject
static jboolean startQtAndroidPlugin(JNIEnv *env, jobject, jstring paramsString)
static const char m_classErrorMsg[]
static int m_availableWidthPixels
static QT_BEGIN_NAMESPACE JavaVM * m_javaVM
static jmethodID m_destroySurfaceMethodID
static void handleScreenRemoved(JNIEnv *, jclass, jint displayId)
static double m_scaledDensity
static QAndroidPlatformIntegration * m_androidPlatformIntegration
static const char m_methodErrorMsg[]
static void setSurface(JNIEnv *env, jobject, jint id, jobject jSurface, jint w, jint h)
static void quitQtAndroidPlugin(JNIEnv *env, jclass)
static AndroidContentFileEngineHandler * m_androidContentFileEngineHandler
static void quitQtCoreApplication(JNIEnv *env, jclass)
static const char m_qtTag[]
static QList< QByteArray > m_applicationParams
static jobject onBind(JNIEnv *, jclass, jobject intent)
static void onActivityResult(JNIEnv *, jclass, jint requestCode, jint resultCode, jobject data)
static jmethodID m_setSurfaceGeometryMethodID
static AAssetManager * m_assetManager
static void updateWindow(JNIEnv *, jobject)
static void handleScreenAdded(JNIEnv *, jclass, jint displayId)
static QAndroidEventDispatcherStopper * instance()
void goingToStop(bool stop)
T loadAcquire() const noexcept
T fetchAndAddRelease(T valueToAdd) noexcept
char * data()
\macro QT_NO_CAST_FROM_BYTEARRAY
static void quit()
\threadsafe
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
static bool setCurrent(const QString &path)
Sets the application's current working directory to path.
static QString homePath()
Returns the absolute path of the user's home directory.
static QWindowList topLevelWindows()
Returns a list of the top-level windows in the application.
Format
The following image formats are available in Qt.
qsizetype size() const noexcept
qsizetype length() const noexcept
const T & constFirst() const noexcept
void append(parameter_type t)
void unlock() noexcept
Unlocks the mutex.
void lock() noexcept
Locks the mutex.
QThread * thread() const
Returns the thread in which the object lives.
Q_WEAK_OVERLOAD void setObjectName(const QString &name)
Sets the object's name to name.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr void getRect(int *x, int *y, int *w, int *h) const
Extracts the position of the rectangle's top-left corner to *x and *y, and its dimensions to *width a...
constexpr int height() const noexcept
Returns the height of the rectangle.
constexpr bool isNull() const noexcept
Returns true if the rectangle is a null rectangle, otherwise returns false.
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr int width() const noexcept
Returns the width of the rectangle.
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
The QRegion class specifies a clip region for a painter.
static bool registerResource(const QString &rccFilename, const QString &resourceRoot=QString())
Registers the resource with the given rccFileName at the location in the resource tree specified by m...
QRect geometry
the screen's geometry in pixels
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static void setPlatformSynthesizesMouse(bool v)
static bool handleExposeEvent(QWindow *window, const QRegion ®ion)
static void handleApplicationStateChanged(Qt::ApplicationState newState, bool forcePropagate=false)
QSet< QString >::iterator it
static bool registerNatives()
Combined button and popup list for selecting options.
bool registerNatives(JNIEnv *env)
bool registerNatives(JNIEnv *env)
bool registerNatives(JNIEnv *env)
Q_CORE_EXPORT jobject callOnBindListener(jobject intent)
Q_CORE_EXPORT void handleResume()
Q_CORE_EXPORT void handleNewIntent(JNIEnv *env, jobject intent)
Q_CORE_EXPORT void handlePause()
Q_CORE_EXPORT void handleActivityResult(jint requestCode, jint resultCode, jobject data)
Q_CORE_EXPORT void waitForServiceSetup()
const char * classErrorMsgFmt()
void notifyAccessibilityLocationChange(uint accessibilityObjectId)
int insertNativeView(jobject view, const QRect &geometry)
void setViewVisibility(jobject view, bool visible)
void destroySurface(int surfaceId)
void setAndroidPlatformIntegration(QAndroidPlatformIntegration *androidPlatformIntegration)
QBasicMutex * platformInterfaceMutex()
void notifyScrolledEvent(uint accessibilityObjectId)
void setSurfaceGeometry(int surfaceId, const QRect &geometry)
jobject createBitmap(QImage img, JNIEnv *env)
QWindow * topLevelWindowAt(const QPoint &globalPos)
QAndroidPlatformIntegration * androidPlatformIntegration()
void notifyObjectFocus(uint accessibilityObjectId)
void notifyValueChanged(uint accessibilityObjectId, jstring value)
void notifyQtAndroidPluginRunning(bool running)
int availableWidthPixels()
bool blockEventLoopsWhenSuspended()
void bringChildToFront(int surfaceId)
void setSystemUiVisibility(SystemUiVisibility uiVisibility)
int createSurface(AndroidSurfaceClient *client, const QRect &geometry, bool onTop, int imageDepth)
void bringChildToBack(int surfaceId)
jclass applicationClass()
QtJniTypes::Activity activity()
jobject createBitmapDrawable(jobject bitmap, JNIEnv *env)
QtJniTypes::Service service()
void notifyObjectHide(uint accessibilityObjectId, uint parentObjectId)
int availableHeightPixels()
AAssetManager * assetManager()
const char * methodErrorMsgFmt()
@ InvertedLandscapeOrientation
@ InvertedPortraitOrientation
QTextStream & endl(QTextStream &stream)
Writes '\n' to the stream and flushes the stream.
#define Q_BASIC_ATOMIC_INITIALIZER(a)
static Q_CONSTINIT QBasicAtomicInt running
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
int qRound(qfloat16 d) noexcept
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
#define Q_ARG(Type, data)
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum const void * pixels
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat GLfloat GLfloat h
GLsizei GLfixed GLfixed GLfixed GLfixed const GLubyte * bitmap
#define QStringLiteral(str)
Q_CORE_EXPORT bool qEnvironmentVariableIsSet(const char *varName) noexcept
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
QSqlQueryModel * model
[16]
QFileInfo info(fileName)
[8]