12#include <QtCore/private/qcoreapplication_p.h>
13#include <QtCore/private/qlocking_p.h>
15#include <android/log.h>
46 jclass jQtNative = env->FindClass(
"org/qtproject/qt/android/QtNative");
47 if (QJniEnvironment::checkAndClearExceptions(env))
50 jmethodID activityMethodID =
51 env->GetStaticMethodID(jQtNative,
"activity",
"()Landroid/app/Activity;");
52 if (QJniEnvironment::checkAndClearExceptions(env))
55 jobject activity = env->CallStaticObjectMethod(jQtNative, activityMethodID);
56 if (QJniEnvironment::checkAndClearExceptions(env))
68 env->DeleteLocalRef(activity);
71 env->DeleteLocalRef(jQtNative);
72 if (QJniEnvironment::checkAndClearExceptions(env))
79 class ActivityResultListeners
83 QList<QtAndroidPrivate::ActivityResultListener *>
listeners;
92 g_activityResultListeners()->listeners.append(listener);
98 g_activityResultListeners()->listeners.removeAll(listener);
104 const QList<QtAndroidPrivate::ActivityResultListener *> &
listeners = g_activityResultListeners()->listeners;
106 if (
listeners.at(
i)->handleActivityResult(requestCode, resultCode,
data))
112 class NewIntentListeners
116 QList<QtAndroidPrivate::NewIntentListener *>
listeners;
125 g_newIntentListeners()->listeners.append(listener);
131 g_newIntentListeners()->listeners.removeAll(listener);
137 const QList<QtAndroidPrivate::NewIntentListener *> &
listeners = g_newIntentListeners()->listeners;
139 if (
listeners.at(
i)->handleNewIntent(env, intent))
145 class ResumePauseListeners
149 QList<QtAndroidPrivate::ResumePauseListener *>
listeners;
158 g_resumePauseListeners()->listeners.append(listener);
164 g_resumePauseListeners()->listeners.removeAll(listener);
170 const QList<QtAndroidPrivate::ResumePauseListener *> &
listeners = g_resumePauseListeners()->listeners;
178 const QList<QtAndroidPrivate::ResumePauseListener *> &
listeners = g_resumePauseListeners()->listeners;
187 jclass jQtNative = env->FindClass(
"org/qtproject/qt/android/QtNative");
189 if (QJniEnvironment::checkAndClearExceptions(env))
192 jmethodID activityMethodID = env->GetStaticMethodID(jQtNative,
194 "()Landroid/app/Activity;");
196 if (QJniEnvironment::checkAndClearExceptions(env))
199 jobject
activity = env->CallStaticObjectMethod(jQtNative, activityMethodID);
201 if (QJniEnvironment::checkAndClearExceptions(env))
204 jmethodID serviceMethodID = env->GetStaticMethodID(jQtNative,
206 "()Landroid/app/Service;");
208 if (QJniEnvironment::checkAndClearExceptions(env))
211 jobject
service = env->CallStaticObjectMethod(jQtNative, serviceMethodID);
213 if (QJniEnvironment::checkAndClearExceptions(env))
216 jmethodID classLoaderMethodID = env->GetStaticMethodID(jQtNative,
218 "()Ljava/lang/ClassLoader;");
220 if (QJniEnvironment::checkAndClearExceptions(env))
223 jobject
classLoader = env->CallStaticObjectMethod(jQtNative, classLoaderMethodID);
224 if (QJniEnvironment::checkAndClearExceptions(env))
238 static const JNINativeMethod
methods[] = {
242 const bool regOk = (env->RegisterNatives(jQtNative,
methods,
sizeof(
methods) /
sizeof(
methods[0])) == JNI_OK);
243 env->DeleteLocalRef(jQtNative);
244 if (!regOk && QJniEnvironment::checkAndClearExceptions(env))
306 static jint sdkVersion = 0;
308 sdkVersion = QJniObject::getStaticField<jint>(
"android/os/Build$VERSION",
"SDK_INT");
314 g_waitForServiceSetupSemaphore->acquire();
328 g_waitForServiceSetupSemaphore->release();
357 static const char logTag[] =
"QtCore";
358 static bool initialized =
false;
360 return JNI_VERSION_1_6;
368 __android_log_print(ANDROID_LOG_INFO,
logTag,
"Start");
373 if (vm->GetEnv(&uenv.venv, JNI_VERSION_1_6) != JNI_OK) {
374 __android_log_print(ANDROID_LOG_FATAL,
logTag,
"GetEnv failed");
378 JNIEnv *env = uenv.nenv;
381 __android_log_print(ANDROID_LOG_FATAL,
logTag,
"initJNI failed");
385 return JNI_VERSION_1_6;
static JNINativeMethod methods[]
virtual ~ActivityResultListener()
virtual ~NewIntentListener()
virtual void handlePause()
virtual void handleResume()
virtual ~ResumePauseListener()
static const char logTag[]
Combined button and popup list for selecting options.
\preliminary \inmodule QtCorePrivate
Q_CORE_EXPORT void unregisterNewIntentListener(NewIntentListener *listener)
Q_CORE_EXPORT int acuqireServiceSetup(int flags)
Q_CORE_EXPORT jobject callOnBindListener(jobject intent)
Q_CORE_EXPORT jint initJNI(JavaVM *vm, JNIEnv *env)
Q_CORE_EXPORT jint androidSdkVersion()
bool registerNativeInterfaceNatives(QJniEnvironment &env)
Posts the function runnable to the Android thread.
Q_CORE_EXPORT void unregisterResumePauseListener(ResumePauseListener *listener)
Q_CORE_EXPORT bool acquireAndroidDeadlockProtector()
Q_CORE_EXPORT QtJniTypes::Context context()
bool registerExtrasNatives(QJniEnvironment &env)
bool registerPermissionNatives(QJniEnvironment &env)
Q_CORE_EXPORT void handleResume()
Q_CORE_EXPORT QtJniTypes::Activity activity()
Q_CORE_EXPORT void releaseAndroidDeadlockProtector()
Q_CORE_EXPORT void handleNewIntent(JNIEnv *env, jobject intent)
Q_CORE_EXPORT void setOnBindListener(OnBindListener *listener)
Q_CORE_EXPORT void handlePause()
Q_CORE_EXPORT void unregisterActivityResultListener(ActivityResultListener *listener)
Q_CORE_EXPORT QtJniTypes::Service service()
Q_CORE_EXPORT JavaVM * javaVM()
Q_CORE_EXPORT void handleActivityResult(jint requestCode, jint resultCode, jobject data)
Q_CORE_EXPORT void waitForServiceSetup()
#define Q_BASIC_ATOMIC_INITIALIZER(a)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
static jobject g_jService
static Q_CONSTINIT QtAndroidPrivate::OnBindListener * g_onBindListener
Q_CORE_EXPORT jobject qt_androidActivity()
static jobject g_jClassLoader
static jobject g_jActivity
QT_END_NAMESPACE JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
static Q_CONSTINIT QBasicMutex g_onBindListenerMutex
static Q_CONSTINIT QBasicAtomicInt g_androidDeadlockProtector
static jboolean updateNativeActivity(JNIEnv *env, jclass=nullptr)
Q_CORE_EXPORT jobject qt_androidService()
static Q_CONSTINIT QBasicAtomicInt g_serviceSetupLockers
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data