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>
71extern "C" typedef int (*
Main)(int,
char **);
96Q_DECLARE_JNI_CLASS(QtEmbeddedDelegateFactory,
"org/qtproject/qt/android/QtEmbeddedDelegateFactory")
143 if (
window->nativeViewId() == windowId)
193 using namespace QtJniTypes;
200 Traits<QtEmbeddedDelegateFactory>::className(),
201 "getActivityDelegate",
225 JNIEnv *env = QJniEnvironment::getJniEnv();
227 if (activity.isValid())
230 if (service.isValid())
242 void notifyObjectHide(
uint accessibilityObjectId,
uint parentObjectId)
245 accessibilityObjectId, parentObjectId);
248 void notifyObjectShow(
uint parentObjectId)
254 void notifyObjectFocus(
uint accessibilityObjectId)
259 void notifyValueChanged(
uint accessibilityObjectId, jstring
value)
264 void notifyScrolledEvent(
uint accessibilityObjectId)
272 "notifyNativePluginIntegrationReady",
294 AndroidBitmapInfo
info;
295 if (AndroidBitmap_getInfo(env,
bitmap, &
info) < 0) {
296 env->DeleteLocalRef(
bitmap);
301 if (AndroidBitmap_lockPixels(env,
bitmap, &
pixels) < 0) {
302 env->DeleteLocalRef(
bitmap);
315 memcpy(bmpPtr,
img.constScanLine(
y),
width);
317 AndroidBitmap_unlockPixels(env,
bitmap);
364 QString manufacturer = QJniObject::getStaticObjectField(
"android/os/Build",
"MANUFACTURER",
"Ljava/lang/String;").toString();
365 QString model = QJniObject::getStaticObjectField(
"android/os/Build",
"MODEL",
"Ljava/lang/String;").toString();
367 return manufacturer + u
' ' +
model;
374 "(Landroid/view/View;Z)V",
415 qCritical() <<
"dlopen failed:" << dlerror();
420 qWarning(
"No main library was specified; searching entire process (this is slow!)");
426 <<
"Could not find main method";
451 JNIEnv* env =
nullptr;
452 JavaVMAttachArgs
args;
453 args.version = JNI_VERSION_1_6;
454 args.name =
"QtMainThread";
456 JavaVM *vm = QJniEnvironment::javaVM();
458 vm->AttachCurrentThread(&env, &
args);
462 qRegisterMetaType<Qt::ScreenOrientation>(
"Qt::ScreenOrientation");
469 QVarLengthArray<char *> argv(argc + 1);
470 for (
int i = 0;
i < argc;
i++)
472 argv[argc] =
nullptr;
475 const int ret =
m_main(argc, argv.data());
476 qInfo() <<
"main() returned" <<
ret;
481 qWarning() <<
"dlclose failed:" << dlerror();
551 jint screenHeightPixels, jint availableLeftPixels,
552 jint availableTopPixels, jint availableWidthPixels,
553 jint availableHeightPixels, jdouble xdpi, jdouble ydpi,
554 jdouble scaledDensity, jdouble density, jfloat refreshRate)
564 const QSize screenSize(screenWidthPixels, screenHeightPixels);
566 const QRect availableGeometry(0, 0, availableWidthPixels, availableHeightPixels);
567 const QSize physicalSize(
qRound(
double(screenWidthPixels) / xdpi * 25.4),
568 qRound(
double(screenHeightPixels) / ydpi * 25.4));
573 availableGeometry.
left(), availableGeometry.
top(), availableGeometry.
width(),
597 QRect availableGeometry =
w->screen()->availableGeometry();
598 if (
w->geometry().width() > 0 &&
w->geometry().height() > 0 && availableGeometry.
width() > 0 && availableGeometry.
height() > 0)
730static jobject
onBind(JNIEnv *, jclass , jobject intent)
744 {
"onActivityResult",
"(IILandroid/content/Intent;)V", (
void *)
onActivityResult },
745 {
"onNewIntent",
"(Landroid/content/Intent;)V", (
void *)
onNewIntent },
746 {
"onBind",
"(Landroid/content/Intent;)Landroid/os/IBinder;", (
void *)
onBind }
749#define FIND_AND_CHECK_CLASS(CLASS_NAME) \
750clazz = env->FindClass(CLASS_NAME); \
752 __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_classErrorMsg, CLASS_NAME); \
756#define GET_AND_CHECK_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE) \
757VAR = env->GetMethodID(CLASS, METHOD_NAME, METHOD_SIGNATURE); \
759 __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_methodErrorMsg, METHOD_NAME, METHOD_SIGNATURE); \
763#define GET_AND_CHECK_STATIC_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE) \
764VAR = env->GetStaticMethodID(CLASS, METHOD_NAME, METHOD_SIGNATURE); \
766 __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_methodErrorMsg, METHOD_NAME, METHOD_SIGNATURE); \
770#define GET_AND_CHECK_FIELD(VAR, CLASS, FIELD_NAME, FIELD_SIGNATURE) \
771VAR = env->GetFieldID(CLASS, FIELD_NAME, FIELD_SIGNATURE); \
773 __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_methodErrorMsg, FIELD_NAME, FIELD_SIGNATURE); \
777#define GET_AND_CHECK_STATIC_FIELD(VAR, CLASS, FIELD_NAME, FIELD_SIGNATURE) \
778VAR = env->GetStaticFieldID(CLASS, FIELD_NAME, FIELD_SIGNATURE); \
780 __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_methodErrorMsg, FIELD_NAME, FIELD_SIGNATURE); \
794 __android_log_print(ANDROID_LOG_FATAL,
"Qt",
"RegisterNatives failed");
798 bool success = env.registerNativeMethods(
799 QtJniTypes::Traits<QtJniTypes::QtDisplayManager>::className(),
811 qCritical() <<
"QtDisplayManager: registerNativeMethods() failed";
818 if (!contextObject) {
823 if (!contextObject) {
824 __android_log_print(ANDROID_LOG_FATAL,
"Qt",
"Failed to get Activity or Service object");
827 const auto releaseContextObject =
qScopeGuard([&env, contextObject]{
828 env->DeleteLocalRef(contextObject);
838 m_assets = env->NewGlobalRef(env->CallObjectMethod(contextObject, methodID));
842 m_resourcesObj = env->NewGlobalRef(env->CallObjectMethod(contextObject, methodID));
845 m_bitmapClass =
static_cast<jclass
>(env->NewGlobalRef(clazz));
847 "createBitmap",
"(IILandroid/graphics/Bitmap$Config;)Landroid/graphics/Bitmap;");
859 "<init>",
"(Landroid/content/res/Resources;Landroid/graphics/Bitmap;)V");
873 static bool initialized =
false;
875 return JNI_VERSION_1_6;
881 if (!env.isValid()) {
883 __android_log_print(ANDROID_LOG_FATAL,
"Qt",
"Failed to initialize the JNI Environment");
895 __android_log_print(ANDROID_LOG_FATAL,
"Qt",
"registerNatives failed");
902 __android_log_print(ANDROID_LOG_INFO,
"Qt",
"qt started");
903 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 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)
static QtJniTypes::QtInputDelegate m_inputDelegate
#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 QtJniTypes::QtActivityDelegateBase m_activityDelegate
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)
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)
QWindow * topLevelWindowAt(const QPoint &globalPos)
QtJniTypes::QtActivityDelegateBase qtActivityDelegate()
QAndroidPlatformIntegration * androidPlatformIntegration()
QtJniTypes::QtInputDelegate qtInputDelegate()
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]
QT_BEGIN_NAMESPACE Q_DECLARE_JNI_CLASS(Environment, "android/os/Environment")
#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]