Android: don't rely on implicit cast of declared QtJniTypes to jobject

The operator jobject() should be removed from declared QtJniTypes in
qtbase, as it's dangerous. Prepare for that by calling object(), which
returns the wrapped jobject as well, or isValid() where previously the
implicit conversion to jobject also enabled implicit conversion to bool.

Change-Id: I00cf6f1463dd5ab5cbaf03d9e77bfff3bced9b15
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
Volker Hilsheimer 2023-10-26 18:33:33 +02:00
parent 703614f03b
commit 8c9f5fba03
5 changed files with 14 additions and 14 deletions

View File

@ -68,7 +68,7 @@ QtJniTypes::Context QNativeInterface::QAndroidApplication::context()
*/
bool QNativeInterface::QAndroidApplication::isActivityContext()
{
return QtAndroidPrivate::activity();
return QtAndroidPrivate::activity().isValid();
}
/*!

View File

@ -484,7 +484,7 @@ static void waitForServiceSetup(JNIEnv *env, jclass /*clazz*/)
Q_UNUSED(env);
// The service must wait until the QCoreApplication starts otherwise onBind will be
// called too early
if (QtAndroidPrivate::service())
if (QtAndroidPrivate::service().isValid())
QtAndroidPrivate::waitForServiceSetup();
}

View File

@ -19,7 +19,7 @@ static jclass g_messageDialogHelperClass = nullptr;
QAndroidPlatformMessageDialogHelper::QAndroidPlatformMessageDialogHelper()
: m_javaMessageDialog(g_messageDialogHelperClass, "(Landroid/app/Activity;)V",
static_cast<jobject>(QtAndroidPrivate::activity()))
QtAndroidPrivate::activity().object())
{
}

View File

@ -320,11 +320,11 @@ bool QAndroidPlatformIntegration::hasCapability(Capability cap) const
switch (cap) {
case ApplicationState: return true;
case ThreadedPixmaps: return true;
case NativeWidgets: return QtAndroidPrivate::activity();
case OpenGL: return QtAndroidPrivate::activity();
case ForeignWindows: return QtAndroidPrivate::activity();
case ThreadedOpenGL: return !needsBasicRenderloopWorkaround() && QtAndroidPrivate::activity();
case RasterGLSurface: return QtAndroidPrivate::activity();
case NativeWidgets: return QtAndroidPrivate::activity().isValid();
case OpenGL: return QtAndroidPrivate::activity().isValid();
case ForeignWindows: return QtAndroidPrivate::activity().isValid();
case ThreadedOpenGL: return !needsBasicRenderloopWorkaround() && QtAndroidPrivate::activity().isValid();
case RasterGLSurface: return QtAndroidPrivate::activity().isValid();
case TopStackedNativeChildWindows: return false;
case MaximizeUsingFullscreenGeometry: return true;
default:
@ -334,7 +334,7 @@ bool QAndroidPlatformIntegration::hasCapability(Capability cap) const
QPlatformBackingStore *QAndroidPlatformIntegration::createPlatformBackingStore(QWindow *window) const
{
if (!QtAndroidPrivate::activity())
if (!QtAndroidPrivate::activity().isValid())
return nullptr;
return new QAndroidPlatformBackingStore(window);
@ -342,7 +342,7 @@ QPlatformBackingStore *QAndroidPlatformIntegration::createPlatformBackingStore(Q
QPlatformOpenGLContext *QAndroidPlatformIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
{
if (!QtAndroidPrivate::activity())
if (!QtAndroidPrivate::activity().isValid())
return nullptr;
QSurfaceFormat format(context->format());
format.setAlphaBufferSize(8);
@ -360,7 +360,7 @@ QOpenGLContext *QAndroidPlatformIntegration::createOpenGLContext(EGLContext cont
QPlatformOffscreenSurface *QAndroidPlatformIntegration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const
{
if (!QtAndroidPrivate::activity())
if (!QtAndroidPrivate::activity().isValid())
return nullptr;
QSurfaceFormat format(surface->requestedFormat());
@ -374,7 +374,7 @@ QPlatformOffscreenSurface *QAndroidPlatformIntegration::createPlatformOffscreenS
QOffscreenSurface *QAndroidPlatformIntegration::createOffscreenSurface(ANativeWindow *nativeSurface) const
{
if (!QtAndroidPrivate::activity() || !nativeSurface)
if (!QtAndroidPrivate::activity().isValid() || !nativeSurface)
return nullptr;
auto *surface = new QOffscreenSurface;
@ -385,7 +385,7 @@ QOffscreenSurface *QAndroidPlatformIntegration::createOffscreenSurface(ANativeWi
QPlatformWindow *QAndroidPlatformIntegration::createPlatformWindow(QWindow *window) const
{
if (!QtAndroidPrivate::activity())
if (!QtAndroidPrivate::activity().isValid())
return nullptr;
#if QT_CONFIG(vulkan)

View File

@ -368,7 +368,7 @@ int QAndroidPlatformScreen::rasterSurfaces()
void QAndroidPlatformScreen::doRedraw(QImage* screenGrabImage)
{
PROFILE_SCOPE;
if (!QtAndroidPrivate::activity())
if (!QtAndroidPrivate::activity().isValid())
return;
if (m_dirtyRect.isEmpty())