Commit 019544e2 authored by Volker Krause's avatar Volker Krause
Browse files

Adapt to Qt6 Android API changes

parent d3419674
Pipeline #186898 passed with stage
in 1 minute and 29 seconds
......@@ -5,3 +5,4 @@ include:
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/android.yml
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/linux.yml
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/freebsd.yml
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/linux-qt6.yml
......@@ -77,7 +77,10 @@ endif()
# runtime dependencies are build-time dependencies on Android
if (ANDROID)
find_package(Qt${QT_MAJOR_VERSION} REQUIRED COMPONENTS AndroidExtras Svg)
find_package(Qt${QT_MAJOR_VERSION} REQUIRED COMPONENTS Svg)
if (QT_MAJOR_VERSION EQUAL "5")
find_package(Qt5 REQUIRED COMPONENTS AndroidExtras)
endif()
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Archive Kirigami2 Prison)
if (NOT DEFINED BREEZEICONS_DIR AND EXISTS ${CMAKE_SOURCE_DIR}/../breeze-icons)
set(BREEZEICONS_DIR ${CMAKE_SOURCE_DIR}/../breeze-icons)
......
......@@ -104,9 +104,13 @@ target_link_libraries(itinerary-app PRIVATE
)
if (ANDROID)
target_include_directories(itinerary-app PRIVATE ${Qt5Core_PRIVATE_INCLUDE_DIRS})
target_link_libraries(itinerary PUBLIC KAndroidExtras)
if (QT_MAJOR_VERSION EQUAL "6")
target_link_libraries(itinerary PRIVATE Qt::CorePrivate)
target_link_libraries(itinerary-app PRIVATE Qt::CorePrivate)
endif()
# explicitly add runtime dependencies and transitive link dependencies,
# so androiddeployqt picks them up
target_link_libraries(itinerary PUBLIC Qt::AndroidExtras KAndroidExtras)
target_link_libraries(itinerary-app PRIVATE
KF5::Archive
KF5::Kirigami2
......
......@@ -13,7 +13,11 @@
#include <kandroidextras/androidtypes.h>
#include <kandroidextras/uri.h>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QtAndroid>
#else
#include <QCoreApplication>
#endif
JNI_TYPE(org, kde, itinerary, Activity)
......@@ -25,7 +29,13 @@ public:
JNI_METHOD(KAndroidExtras::Jni::Array<KAndroidExtras::java::lang::String>, attachmentsForIntent, KAndroidExtras::android::content::Intent)
JNI_METHOD(KAndroidExtras::android::net::Uri, openDocument, KAndroidExtras::java::lang::String)
private:
inline QAndroidJniObject jniHandle() const { return QtAndroid::androidActivity(); }
inline QAndroidJniObject jniHandle() const {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
return QtAndroid::androidActivity();
#else
return QNativeInterface::QAndroidApplication::context();
#endif
}
};
#endif
......@@ -77,8 +77,11 @@
#include <kandroidextras/manifestpermission.h>
#include <kandroidextras/uri.h>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QtAndroid>
#include <QAndroidJniObject>
#else
#include <private/qandroidextras_p.h>
#endif
#endif
#include <memory>
......@@ -504,11 +507,10 @@ void ApplicationController::checkCalendar()
{
#ifdef Q_OS_ANDROID
using namespace KAndroidExtras;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (QtAndroid::checkPermission(ManifestPermission::READ_CALENDAR) == QtAndroid::PermissionResult::Granted) {
const auto activity = QtAndroid::androidActivity();
if (activity.isValid()) {
activity.callMethod<void>("checkCalendar");
}
ItineraryActivity activity;
activity.checkCalendar();
} else {
QtAndroid::requestPermissions({ManifestPermission::READ_CALENDAR}, [this] (const QtAndroid::PermissionResultMap &result){
if (result[ManifestPermission::READ_CALENDAR] == QtAndroid::PermissionResult::Granted) {
......@@ -516,6 +518,14 @@ void ApplicationController::checkCalendar()
}
});
}
#else
if (QtAndroidPrivate::checkPermission(ManifestPermission::READ_CALENDAR).result() == QtAndroidPrivate::PermissionResult::Authorized) {
ItineraryActivity activity;
activity.checkCalendar();
} else if (QtAndroidPrivate::requestPermission(ManifestPermission::READ_CALENDAR).result() == QtAndroidPrivate::PermissionResult::Authorized) {
checkCalendar();
}
#endif
#endif
}
......
......@@ -7,6 +7,7 @@
#include "developmentmodecontroller.h"
#include <QByteArray>
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QFile>
......@@ -20,7 +21,11 @@
#include <kandroidextras/manifestpermission.h>
using namespace KAndroidExtras;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QtAndroid>
#else
#include <private/qandroidextras_p.h>
#endif
#endif
#include <csignal>
......@@ -28,6 +33,7 @@ using namespace KAndroidExtras;
void DevelopmentModeController::enablePublicTransportLogging()
{
#ifdef Q_OS_ANDROID
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (QtAndroid::checkPermission(ManifestPermission::WRITE_EXTERNAL_STORAGE) != QtAndroid::PermissionResult::Granted) {
QtAndroid::requestPermissions({ManifestPermission::WRITE_EXTERNAL_STORAGE}, [this] (const QtAndroid::PermissionResultMap &result){
if (result[ManifestPermission::WRITE_EXTERNAL_STORAGE] == QtAndroid::PermissionResult::Granted) {
......@@ -36,8 +42,22 @@ void DevelopmentModeController::enablePublicTransportLogging()
});
return;
}
#else
if (QtAndroidPrivate::checkPermission(ManifestPermission::WRITE_EXTERNAL_STORAGE).result() != QtAndroidPrivate::PermissionResult::Authorized) {
if (QtAndroidPrivate::requestPermission(ManifestPermission::WRITE_EXTERNAL_STORAGE).result() == QtAndroidPrivate::PermissionResult::Authorized) {
enablePublicTransportLogging();
} else {
return;
}
}
#endif
const auto f = QtAndroid::androidContext().callObjectMethod("getExternalFilesDir", Jni::signature<java::io::File(java::lang::String)>(), nullptr);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const auto context = QtAndroid::androidContext();
#else
const QJniObject context = QNativeInterface::QAndroidApplication::context();
#endif
const auto f = context.callObjectMethod("getExternalFilesDir", Jni::signature<java::io::File(java::lang::String)>(), nullptr);
const auto baseDir = f.callObjectMethod("getPath", Jni::signature<java::lang::String()>()).toString();
#else
const auto baseDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
......
......@@ -26,9 +26,6 @@
#include <kandroidextras/jnisignature.h>
#include <kandroidextras/javalocale.h>
#include <QtAndroid>
#include <QAndroidJniObject>
using namespace KAndroidExtras;
#endif
......
......@@ -76,9 +76,6 @@
#ifdef Q_OS_ANDROID
#include <kandroidextras/activity.h>
#include <kandroidextras/intent.h>
#include <QtAndroid>
#include <QAndroidJniObject>
#else
#include <QApplication>
#endif
......
......@@ -19,9 +19,6 @@
#ifdef Q_OS_ANDROID
#include <kandroidextras/activity.h>
#include <kandroidextras/intent.h>
#include <QtAndroid>
#include <QAndroidJniObject>
#else
#include <QGeoPositionInfo>
#include <QGeoPositionInfoSource>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment