summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/android/androidjnimain.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/android/androidjnimain.cpp')
-rw-r--r--src/plugins/platforms/android/androidjnimain.cpp129
1 files changed, 73 insertions, 56 deletions
diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp
index c571e16062..6df9f56c2c 100644
--- a/src/plugins/platforms/android/androidjnimain.cpp
+++ b/src/plugins/platforms/android/androidjnimain.cpp
@@ -40,21 +40,10 @@
**
****************************************************************************/
-#include <QtGui/private/qguiapplication_p.h>
-
#include <dlfcn.h>
#include <pthread.h>
-#include <qcoreapplication.h>
-#include <qimage.h>
-#include <qpoint.h>
#include <qplugin.h>
-#include <qsemaphore.h>
-#include <qmutex.h>
#include <qdebug.h>
-#include <qglobal.h>
-#include <qobjectdefs.h>
-#include <QtCore/private/qjni_p.h>
-#include <stdlib.h>
#include "androidjnimain.h"
#include "androidjniaccessibility.h"
@@ -63,14 +52,16 @@
#include "androidjnimenu.h"
#include "qandroidplatformdialoghelpers.h"
#include "qandroidplatformintegration.h"
-
-#include <qabstracteventdispatcher.h>
+#include "qandroidassetsfileenginehandler.h"
#include <android/bitmap.h>
#include <android/asset_manager_jni.h>
-#include "qandroidassetsfileenginehandler.h"
+#include "qandroideventdispatcher.h"
#include <android/api-level.h>
+
#include <QtCore/private/qjnihelpers_p.h>
+#include <QtCore/private/qjni_p.h>
+#include <QtGui/private/qguiapplication_p.h>
#include <qpa/qwindowsysteminterface.h>
@@ -78,42 +69,42 @@ Q_IMPORT_PLUGIN(QAndroidPlatformIntegrationPlugin)
QT_BEGIN_NAMESPACE
-static JavaVM *m_javaVM = NULL;
-static jclass m_applicationClass = NULL;
-static jobject m_classLoaderObject = NULL;
-static jmethodID m_loadClassMethodID = NULL;
-static AAssetManager *m_assetManager = NULL;
-static jobject m_resourcesObj;
-static jobject m_activityObject = NULL;
-static jmethodID m_createSurfaceMethodID = 0;
-static jmethodID m_insertNativeViewMethodID = 0;
-static jmethodID m_setSurfaceGeometryMethodID = 0;
-static jmethodID m_destroySurfaceMethodID = 0;
+static JavaVM *m_javaVM = Q_NULLPTR;
+static jclass m_applicationClass = Q_NULLPTR;
+static jobject m_classLoaderObject = Q_NULLPTR;
+static jmethodID m_loadClassMethodID = Q_NULLPTR;
+static AAssetManager *m_assetManager = Q_NULLPTR;
+static jobject m_resourcesObj = Q_NULLPTR;
+static jobject m_activityObject = Q_NULLPTR;
+static jmethodID m_createSurfaceMethodID = Q_NULLPTR;
+static jmethodID m_insertNativeViewMethodID = Q_NULLPTR;
+static jmethodID m_setSurfaceGeometryMethodID = Q_NULLPTR;
+static jmethodID m_destroySurfaceMethodID = Q_NULLPTR;
static bool m_activityActive = true; // defaults to true because when the platform plugin is
// initialized, QtActivity::onResume() has already been called
-static jclass m_bitmapClass = 0;
-static jmethodID m_createBitmapMethodID = 0;
-static jobject m_ARGB_8888_BitmapConfigValue = 0;
-static jobject m_RGB_565_BitmapConfigValue = 0;
+static jclass m_bitmapClass = Q_NULLPTR;
+static jmethodID m_createBitmapMethodID = Q_NULLPTR;
+static jobject m_ARGB_8888_BitmapConfigValue = Q_NULLPTR;
+static jobject m_RGB_565_BitmapConfigValue = Q_NULLPTR;
-jmethodID m_setFullScreenMethodID = 0;
+jmethodID m_setFullScreenMethodID = Q_NULLPTR;
static bool m_statusBarShowing = true;
-static jclass m_bitmapDrawableClass = 0;
-static jmethodID m_bitmapDrawableConstructorMethodID = 0;
+static jclass m_bitmapDrawableClass = Q_NULLPTR;
+static jmethodID m_bitmapDrawableConstructorMethodID = Q_NULLPTR;
extern "C" typedef int (*Main)(int, char **); //use the standard main method to start the application
-static Main m_main = NULL;
-static void *m_mainLibraryHnd = NULL;
+static Main m_main = Q_NULLPTR;
+static void *m_mainLibraryHnd = Q_NULLPTR;
static QList<QByteArray> m_applicationParams;
struct SurfaceData
{
~SurfaceData() { delete surface; }
- QJNIObjectPrivate *surface = 0;
- AndroidSurfaceClient *client = 0;
+ QJNIObjectPrivate *surface = Q_NULLPTR;
+ AndroidSurfaceClient *client = Q_NULLPTR;
};
QHash<int, AndroidSurfaceClient *> m_surfaces;
@@ -121,11 +112,8 @@ QHash<int, AndroidSurfaceClient *> m_surfaces;
static QMutex m_surfacesMutex;
static int m_surfaceId = 1;
-static QSemaphore m_quitAppSemaphore;
-static QSemaphore m_pauseApplicationSemaphore;
-static QMutex m_pauseApplicationMutex;
-static QAndroidPlatformIntegration *m_androidPlatformIntegration = 0;
+static QAndroidPlatformIntegration *m_androidPlatformIntegration = Q_NULLPTR;
static int m_desktopWidthPixels = 0;
static int m_desktopHeightPixels = 0;
@@ -133,7 +121,7 @@ static double m_scaledDensity = 0;
static volatile bool m_pauseApplication;
-static AndroidAssetsFileEngineHandler *m_androidAssetsFileEngineHandler = 0;
+static AndroidAssetsFileEngineHandler *m_androidAssetsFileEngineHandler = Q_NULLPTR;
@@ -212,7 +200,7 @@ namespace QtAndroid
return;
QtAndroid::AttachedJNIEnv env;
- if (env.jniEnv == 0) {
+ if (!env.jniEnv) {
qWarning("Failed to get JNI Environment.");
return;
}
@@ -227,7 +215,7 @@ namespace QtAndroid
return;
QtAndroid::AttachedJNIEnv env;
- if (env.jniEnv == 0) {
+ if (!env.jniEnv) {
qWarning("Failed to get JNI Environment.");
return;
}
@@ -392,6 +380,9 @@ namespace QtAndroid
void setSurfaceGeometry(int surfaceId, const QRect &geometry)
{
+ if (surfaceId == -1)
+ return;
+
QJNIEnvironmentPrivate env;
if (!env)
return;
@@ -411,10 +402,15 @@ namespace QtAndroid
void destroySurface(int surfaceId)
{
+ if (surfaceId == -1)
+ return;
+
QMutexLocker lock(&m_surfacesMutex);
const auto &it = m_surfaces.find(surfaceId);
if (it != m_surfaces.end())
m_surfaces.remove(surfaceId);
+ if (m_surfaces.isEmpty())
+ m_surfaceId = 1;
QJNIEnvironmentPrivate env;
if (!env)
@@ -425,12 +421,18 @@ namespace QtAndroid
surfaceId);
}
+ bool blockEventLoopsWhenSuspended()
+ {
+ static bool block = qgetenv("QT_BLOCK_EVENT_LOOPS_WHEN_SUSPENDED").toInt();
+ return block;
+ }
+
} // namespace QtAndroid
static jboolean startQtAndroidPlugin(JNIEnv* /*env*/, jobject /*object*//*, jobject applicationAssetManager*/)
{
- m_androidPlatformIntegration = 0;
+ m_androidPlatformIntegration = Q_NULLPTR;
m_androidAssetsFileEngineHandler = new AndroidAssetsFileEngineHandler();
return true;
}
@@ -449,7 +451,8 @@ static void *startMainMethod(void */*data*/)
if (res < 0)
qWarning() << "dlclose failed:" << dlerror();
}
-
+ m_mainLibraryHnd = Q_NULLPTR;
+ m_main = Q_NULLPTR;
QtAndroid::AttachedJNIEnv env;
if (!env.jniEnv)
return 0;
@@ -464,7 +467,7 @@ static void *startMainMethod(void */*data*/)
static jboolean startQtApplication(JNIEnv *env, jobject /*object*/, jstring paramsString, jstring environmentString)
{
- m_mainLibraryHnd = NULL;
+ m_mainLibraryHnd = Q_NULLPTR;
{ // Set env. vars
const char *nativeString = env->GetStringUTFChars(environmentString, 0);
const QList<QByteArray> envVars = QByteArray(nativeString).split('\t');
@@ -490,7 +493,7 @@ static jboolean startQtApplication(JNIEnv *env, jobject /*object*/, jstring para
// Obtain a handle to the main library (the library that contains the main() function).
// This library should already be loaded, and calling dlopen() will just return a reference to it.
m_mainLibraryHnd = dlopen(m_applicationParams.first().data(), 0);
- if (m_mainLibraryHnd == NULL) {
+ if (m_mainLibraryHnd == Q_NULLPTR) {
qCritical() << "dlopen failed:" << dlerror();
return false;
}
@@ -507,15 +510,16 @@ static jboolean startQtApplication(JNIEnv *env, jobject /*object*/, jstring para
}
pthread_t appThread;
- return pthread_create(&appThread, NULL, startMainMethod, NULL) == 0;
+ return pthread_create(&appThread, Q_NULLPTR, startMainMethod, Q_NULLPTR) == 0;
}
static void quitQtAndroidPlugin(JNIEnv *env, jclass /*clazz*/)
{
Q_UNUSED(env);
- m_androidPlatformIntegration = 0;
+ m_androidPlatformIntegration = Q_NULLPTR;
delete m_androidAssetsFileEngineHandler;
+ m_androidAssetsFileEngineHandler = Q_NULLPTR;
}
static void terminateQt(JNIEnv *env, jclass /*clazz*/)
@@ -534,8 +538,9 @@ static void terminateQt(JNIEnv *env, jclass /*clazz*/)
env->DeleteGlobalRef(m_RGB_565_BitmapConfigValue);
if (m_bitmapDrawableClass)
env->DeleteGlobalRef(m_bitmapDrawableClass);
- m_androidPlatformIntegration = 0;
+ m_androidPlatformIntegration = Q_NULLPTR;
delete m_androidAssetsFileEngineHandler;
+ m_androidAssetsFileEngineHandler = Q_NULLPTR;
}
static void setSurface(JNIEnv *env, jobject /*thiz*/, jint id, jobject jSurface, jint w, jint h)
@@ -584,11 +589,11 @@ static void updateWindow(JNIEnv */*env*/, jobject /*thiz*/)
if (!m_androidPlatformIntegration)
return;
- if (QGuiApplication::instance() != 0) {
+ if (QGuiApplication::instance() != Q_NULLPTR) {
foreach (QWindow *w, QGuiApplication::topLevelWindows()) {
QRect availableGeometry = w->screen()->availableGeometry();
if (w->geometry().width() > 0 && w->geometry().height() > 0 && availableGeometry.width() > 0 && availableGeometry.height() > 0)
- QWindowSystemInterface::handleExposeEvent(w, QRegion(w->geometry()));
+ QWindowSystemInterface::handleExposeEvent(w, QRegion(QRect(QPoint(), w->geometry().size())));
}
}
@@ -601,10 +606,22 @@ static void updateApplicationState(JNIEnv */*env*/, jobject /*thiz*/, jint state
{
m_activityActive = (state == Qt::ApplicationActive);
- if (!m_androidPlatformIntegration || !QGuiApplicationPrivate::platformIntegration())
+ if (!m_main || !m_androidPlatformIntegration || !QGuiApplicationPrivate::platformIntegration())
return;
- QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationState(state));
+ if (state <= Qt::ApplicationInactive) {
+ // Don't send timers and sockets events anymore if we are going to hide all windows
+ QAndroidEventDispatcherStopper::instance()->goingToStop(true);
+ QCoreApplication::processEvents();
+ QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationState(state));
+ QWindowSystemInterface::flushWindowSystemEvents();
+ if (state == Qt::ApplicationSuspended)
+ QAndroidEventDispatcherStopper::instance()->stopAll();
+ } else {
+ QAndroidEventDispatcherStopper::instance()->startAll();
+ QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationState(state));
+ QAndroidEventDispatcherStopper::instance()->goingToStop(false);
+ }
}
static void handleOrientationChanged(JNIEnv */*env*/, jobject /*thiz*/, jint newRotation, jint nativeOrientation)
@@ -767,8 +784,8 @@ Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void */*reserved*/)
__android_log_print(ANDROID_LOG_INFO, "Qt", "qt start");
UnionJNIEnvToVoid uenv;
- uenv.venv = NULL;
- m_javaVM = 0;
+ uenv.venv = Q_NULLPTR;
+ m_javaVM = Q_NULLPTR;
if (vm->GetEnv(&uenv.venv, JNI_VERSION_1_4) != JNI_OK) {
__android_log_print(ANDROID_LOG_FATAL, "Qt", "GetEnv failed");