24#include <android/api-level.h>
25#include <android/asset_manager_jni.h>
26#include <android/bitmap.h>
28#include <QtCore/private/qjnihelpers_p.h>
29#include <QtCore/qbasicatomic.h>
30#include <QtCore/qjnienvironment.h>
31#include <QtCore/qjniobject.h>
32#include <QtCore/qprocess.h>
33#include <QtCore/qresource.h>
34#include <QtCore/qscopeguard.h>
35#include <QtCore/qthread.h>
36#include <QtGui/private/qguiapplication_p.h>
37#include <QtGui/private/qhighdpiscaling_p.h>
39#include <qpa/qwindowsysteminterface.h>
68extern "C" typedef int (*
Main)(int,
char **);
141 if (
window->nativeViewId() == windowId)
186 reg->callInterface<QtJniTypes::QtWindowInterface,
void>(
"setSystemUiVisibility",
196 JNIEnv *env = QJniEnvironment::getJniEnv();
198 if (activity.isValid())
201 if (service.isValid())
211 "initializeAccessibility");
217 "notifyLocationChange", accessibilityObjectId);
220 void notifyObjectHide(
uint accessibilityObjectId,
uint parentObjectId)
223 "notifyObjectHide", accessibilityObjectId, parentObjectId);
226 void notifyObjectShow(
uint parentObjectId)
229 "notifyObjectShow", parentObjectId);
232 void notifyObjectFocus(
uint accessibilityObjectId)
235 "notifyObjectFocus", accessibilityObjectId);
238 void notifyValueChanged(
uint accessibilityObjectId, jstring
value)
241 "notifyValueChanged", accessibilityObjectId,
value);
244 void notifyScrolledEvent(
uint accessibilityObjectId)
247 "notifyScrolledEvent", accessibilityObjectId);
253 "notifyNativePluginIntegrationReady",
275 AndroidBitmapInfo
info;
276 if (AndroidBitmap_getInfo(env,
bitmap, &
info) < 0) {
277 env->DeleteLocalRef(
bitmap);
282 if (AndroidBitmap_lockPixels(env,
bitmap, &
pixels) < 0) {
283 env->DeleteLocalRef(
bitmap);
296 memcpy(bmpPtr,
img.constScanLine(
y),
width);
298 AndroidBitmap_unlockPixels(env,
bitmap);
345 QString manufacturer = QJniObject::getStaticObjectField(
"android/os/Build",
"MANUFACTURER",
"Ljava/lang/String;").toString();
346 QString model = QJniObject::getStaticObjectField(
"android/os/Build",
"MODEL",
"Ljava/lang/String;").toString();
348 return manufacturer + u
' ' +
model;
355 "(Landroid/view/View;Z)V",
402 qCritical() <<
"dlopen failed:" << dlerror();
407 qWarning(
"No main library was specified; searching entire process (this is slow!)");
413 <<
"Could not find main method";
438 JNIEnv* env =
nullptr;
439 JavaVMAttachArgs
args;
440 args.version = JNI_VERSION_1_6;
441 args.name =
"QtMainThread";
443 JavaVM *vm = QJniEnvironment::javaVM();
445 vm->AttachCurrentThread(&env, &
args);
449 qRegisterMetaType<Qt::ScreenOrientation>(
"Qt::ScreenOrientation");
456 QVarLengthArray<char *> argv(argc + 1);
457 for (
int i = 0;
i < argc;
i++)
459 argv[argc] =
nullptr;
462 const int ret =
m_main(argc, argv.data());
463 qInfo() <<
"main() returned" <<
ret;
468 qWarning() <<
"dlclose failed:" << dlerror();
540 jint screenHeightPixels, jint availableLeftPixels,
541 jint availableTopPixels, jint availableWidthPixels,
542 jint availableHeightPixels, jdouble xdpi, jdouble ydpi,
543 jdouble scaledDensity, jdouble density, jfloat refreshRate)
553 const QSize screenSize(screenWidthPixels, screenHeightPixels);
555 const QRect availableGeometry(0, 0, availableWidthPixels, availableHeightPixels);
556 const QSize physicalSize(
qRound(
double(screenWidthPixels) / xdpi * 25.4),
557 qRound(
double(screenHeightPixels) / ydpi * 25.4));
562 availableGeometry.
left(), availableGeometry.
top(), availableGeometry.
width(),
586 QRect availableGeometry =
w->screen()->availableGeometry();
587 if (
w->geometry().width() > 0 &&
w->geometry().height() > 0 && availableGeometry.
width() > 0 && availableGeometry.
height() > 0)
719static jobject
onBind(JNIEnv *, jclass , jobject intent)
733 {
"onActivityResult",
"(IILandroid/content/Intent;)V", (
void *)
onActivityResult },
734 {
"onNewIntent",
"(Landroid/content/Intent;)V", (
void *)
onNewIntent },
735 {
"onBind",
"(Landroid/content/Intent;)Landroid/os/IBinder;", (
void *)
onBind }
738#define FIND_AND_CHECK_CLASS(CLASS_NAME) \
739clazz = env->FindClass(CLASS_NAME); \
741 __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_classErrorMsg, CLASS_NAME); \
745#define GET_AND_CHECK_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE) \
746VAR = env->GetMethodID(CLASS, METHOD_NAME, METHOD_SIGNATURE); \
748 __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_methodErrorMsg, METHOD_NAME, METHOD_SIGNATURE); \
752#define GET_AND_CHECK_STATIC_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE) \
753VAR = env->GetStaticMethodID(CLASS, METHOD_NAME, METHOD_SIGNATURE); \
755 __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_methodErrorMsg, METHOD_NAME, METHOD_SIGNATURE); \
759#define GET_AND_CHECK_FIELD(VAR, CLASS, FIELD_NAME, FIELD_SIGNATURE) \
760VAR = env->GetFieldID(CLASS, FIELD_NAME, FIELD_SIGNATURE); \
762 __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_methodErrorMsg, FIELD_NAME, FIELD_SIGNATURE); \
766#define GET_AND_CHECK_STATIC_FIELD(VAR, CLASS, FIELD_NAME, FIELD_SIGNATURE) \
767VAR = env->GetStaticFieldID(CLASS, FIELD_NAME, FIELD_SIGNATURE); \
769 __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_methodErrorMsg, FIELD_NAME, FIELD_SIGNATURE); \
783 __android_log_print(ANDROID_LOG_FATAL,
"Qt",
"RegisterNatives failed");
787 bool success = env.registerNativeMethods(
788 QtJniTypes::Traits<QtJniTypes::QtDisplayManager>::className(),
800 qCritical() <<
"QtDisplayManager: registerNativeMethods() failed";
807 if (!contextObject) {
812 if (!contextObject) {
813 __android_log_print(ANDROID_LOG_FATAL,
"Qt",
"Failed to get Activity or Service object");
816 const auto releaseContextObject =
qScopeGuard([&env, contextObject]{
817 env->DeleteLocalRef(contextObject);
827 m_assets = env->NewGlobalRef(env->CallObjectMethod(contextObject, methodID));
831 m_resourcesObj = env->NewGlobalRef(env->CallObjectMethod(contextObject, methodID));
834 m_bitmapClass =
static_cast<jclass
>(env->NewGlobalRef(clazz));
836 "createBitmap",
"(IILandroid/graphics/Bitmap$Config;)Landroid/graphics/Bitmap;");
848 "<init>",
"(Landroid/content/res/Resources;Landroid/graphics/Bitmap;)V");
862 static bool initialized =
false;
864 return JNI_VERSION_1_6;
870 if (!env.isValid()) {
872 __android_log_print(ANDROID_LOG_FATAL,
"Qt",
"Failed to initialize the JNI Environment");
885 __android_log_print(ANDROID_LOG_FATAL,
"Qt",
"registerNatives failed");
892 __android_log_print(ANDROID_LOG_INFO,
"Qt",
"qt started");
893 return JNI_VERSION_1_6;
static int m_pendingApplicationState
static jclass m_qtServiceClass
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 AndroidBackendRegister * m_backendRegister
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 void onNewIntent(JNIEnv *env, jclass, jobject data)
#define FIND_AND_CHECK_CLASS(CLASS_NAME)
#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)
static void handleRefreshRateChanged(JNIEnv *, jclass, jfloat refreshRate)
static void startQtApplication(JNIEnv *, jclass)
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 jboolean startQtAndroidPlugin(JNIEnv *env, jobject, jstring paramsString)
static const char m_classErrorMsg[]
static jclass m_qtActivityClass
static int m_availableWidthPixels
static QT_BEGIN_NAMESPACE JavaVM * m_javaVM
static void handleScreenRemoved(JNIEnv *, jclass, jint displayId)
static double m_scaledDensity
static QAndroidPlatformIntegration * m_androidPlatformIntegration
static const char m_methodErrorMsg[]
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 AAssetManager * m_assetManager
static void updateWindow(JNIEnv *, jobject)
static void handleScreenAdded(JNIEnv *, jclass, jint displayId)
Q_DECLARE_JNI_CLASS(QtAccessibilityInterface, "org/qtproject/qt/android/QtAccessibilityInterface")
static bool registerNatives()
static QAndroidEventDispatcherStopper * instance()
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.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr int height() const noexcept
Returns the height of the rectangle.
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 width() const noexcept
Returns the width of the rectangle.
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...
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QThread * currentThread()
static void setPlatformSynthesizesMouse(bool v)
static bool handleExposeEvent(QWindow *window, const QRegion ®ion)
static void handleApplicationStateChanged(Qt::ApplicationState newState, bool forcePropagate=false)
static bool registerNatives()
Combined button and popup list for selecting options.
bool registerNatives(QJniEnvironment &env)
bool registerNatives(QJniEnvironment &env)
bool registerNatives(QJniEnvironment &env)
Q_CORE_EXPORT jobject callOnBindListener(jobject intent)
Q_CORE_EXPORT void handleResume()
Q_CORE_EXPORT QtJniTypes::Activity activity()
Q_CORE_EXPORT void handleNewIntent(JNIEnv *env, jobject intent)
Q_CORE_EXPORT void handlePause()
Q_CORE_EXPORT QtJniTypes::Service service()
Q_CORE_EXPORT void handleActivityResult(jint requestCode, jint resultCode, jobject data)
Q_CORE_EXPORT void waitForServiceSetup()
bool registerNatives(QJniEnvironment &env)
const char * classErrorMsgFmt()
void notifyAccessibilityLocationChange(uint accessibilityObjectId)
void setViewVisibility(jobject view, bool visible)
void setAndroidPlatformIntegration(QAndroidPlatformIntegration *androidPlatformIntegration)
QBasicMutex * platformInterfaceMutex()
jobject createBitmap(QImage img, JNIEnv *env)
void initializeAccessibility()
QWindow * topLevelWindowAt(const QPoint &globalPos)
QAndroidPlatformIntegration * androidPlatformIntegration()
AndroidBackendRegister * backendRegister()
int availableWidthPixels()
bool blockEventLoopsWhenSuspended()
void setSystemUiVisibility(SystemUiVisibility uiVisibility)
QWindow * windowFromId(int windowId)
jclass applicationClass()
jobject createBitmapDrawable(jobject bitmap, JNIEnv *env)
void notifyNativePluginIntegrationReady(bool ready)
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)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
int qRound(qfloat16 d) noexcept
constexpr const T & qMin(const T &a, const T &b)
#define Q_ARG(Type, data)
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
GLsizei GLfixed GLfixed GLfixed GLfixed const GLubyte * bitmap
QScopeGuard< typename std::decay< F >::type > qScopeGuard(F &&f)
[qScopeGuard]
#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]
char * toString(const MyType &t)
[31]