mirror of
https://gitlab.com/eql/lqml.git
synced 2025-12-15 14:51:14 -08:00
prepare android version for Qt6
This commit is contained in:
parent
33b00e4300
commit
a18e49e138
9 changed files with 146 additions and 16 deletions
|
|
@ -58,7 +58,7 @@ win32 {
|
|||
}
|
||||
|
||||
android {
|
||||
QT += androidextras remoteobjects
|
||||
QT += remoteobjects
|
||||
DEFINES += INI_ASDF
|
||||
DEFINES -= DESKTOP_APP
|
||||
INCLUDEPATH = $$ECL/include
|
||||
|
|
@ -69,6 +69,13 @@ android {
|
|||
LIBS += -lasdf -lecl-help -ldeflate -lecl-cdb -lecl-curl -lql-minitar -lsockets
|
||||
LIBS += -L../../../platforms/android/lib
|
||||
|
||||
equals(QT_MAJOR_VERSION, 6) {
|
||||
QT += core-private
|
||||
}
|
||||
lessThan(QT_MAJOR_VERSION, 6) {
|
||||
QT += androidextras
|
||||
}
|
||||
|
||||
SOURCES += cpp/android.cpp
|
||||
|
||||
REPC_REPLICA += cpp/android_service/qtandroidservice.rep
|
||||
|
|
@ -82,9 +89,9 @@ android {
|
|||
# https://github.com/KDAB/android_openssl/tree/master/latest
|
||||
# required for downloading map tiles, please note naming convention for Qt:
|
||||
32bit {
|
||||
SSL_PATH = ../../../platforms/android/lib32
|
||||
SSL_PATH = $$PWD/../../platforms/android/lib32
|
||||
} else {
|
||||
SSL_PATH = ../../../platforms/android/lib
|
||||
SSL_PATH = $$PWD/../../platforms/android/lib
|
||||
}
|
||||
ANDROID_EXTRA_LIBS += $$SSL_PATH/libcrypto_1_1.so $$SSL_PATH/libssl_1_1.so
|
||||
|
||||
|
|
@ -126,9 +133,21 @@ ios {
|
|||
}
|
||||
|
||||
32bit {
|
||||
LIBS += -llqml32 -llisp32
|
||||
equals(QT_MAJOR_VERSION, 6) {
|
||||
LIBS += -llqml32_armeabi-v7a
|
||||
}
|
||||
lessThan(QT_MAJOR_VERSION, 6) {
|
||||
LIBS += -llqml32
|
||||
}
|
||||
LIBS += -llisp32
|
||||
} else {
|
||||
LIBS += -llqml -llisp
|
||||
equals(QT_MAJOR_VERSION, 6) {
|
||||
LIBS += -llqml_arm64-v8a
|
||||
}
|
||||
lessThan(QT_MAJOR_VERSION, 6) {
|
||||
LIBS += -llqml
|
||||
}
|
||||
LIBS += -llisp
|
||||
}
|
||||
|
||||
LIBS += -Ltmp -lapp
|
||||
|
|
|
|||
|
|
@ -1,10 +1,16 @@
|
|||
#include "qt.h"
|
||||
#include <QtAndroid>
|
||||
#include <QAndroidJniEnvironment>
|
||||
|
||||
#if (QT_VERSION < 0x060000)
|
||||
#include <QAndroidService>
|
||||
#include <QAndroidJniEnvironment>
|
||||
#else
|
||||
#include <QtCore/private/qandroidextras_p.h>
|
||||
#endif
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
QVariant QT::keepScreenOn(const QVariant& on) {
|
||||
#if (QT_VERSION < 0x060000)
|
||||
QtAndroid::runOnAndroidThread([&] {
|
||||
QAndroidJniObject activity = QtAndroid::androidActivity();
|
||||
if (activity.isValid()) {
|
||||
|
|
@ -20,6 +26,23 @@ QVariant QT::keepScreenOn(const QVariant& on) {
|
|||
env->ExceptionClear();
|
||||
}
|
||||
});
|
||||
#else
|
||||
QNativeInterface::QAndroidApplication::runOnAndroidMainThread([&] {
|
||||
QJniObject activity = QtAndroidPrivate::activity();
|
||||
if (activity.isValid()) {
|
||||
QJniObject window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;");
|
||||
if (window.isValid()) {
|
||||
const int FLAG_KEEP_SCREEN_ON = 128;
|
||||
const char* method = on.toBool() ? "addFlags" : "clearFlags";
|
||||
window.callMethod<void>(method, "(I)V", FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
}
|
||||
QJniEnvironment env;
|
||||
if (env->ExceptionCheck()) {
|
||||
env->ExceptionClear();
|
||||
}
|
||||
});
|
||||
#endif
|
||||
return on;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
#include "qtandroidservice_ro.h"
|
||||
#include "../ble/ble_meshtastic.h"
|
||||
#include <QAndroidService>
|
||||
|
||||
#if (QT_VERSION < 0x060000)
|
||||
#include <QAndroidService>
|
||||
#else
|
||||
#include <QtCore/private/qandroidextras_p.h>
|
||||
#endif
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
QAndroidService app(argc, argv);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,18 @@
|
|||
QT += core androidextras bluetooth remoteobjects
|
||||
QT += core bluetooth remoteobjects
|
||||
TEMPLATE = lib
|
||||
CONFIG += dll
|
||||
CONFIG += c++17 dll
|
||||
INCLUDEPATH += $$PWD
|
||||
TARGET = service
|
||||
DESTDIR = ../../build-android
|
||||
OBJECTS_DIR = ./tmp
|
||||
MOC_DIR = ./tmp
|
||||
|
||||
equals(QT_MAJOR_VERSION, 6) {
|
||||
QT += core-private
|
||||
}
|
||||
lessThan(QT_MAJOR_VERSION, 6) {
|
||||
QT += androidextras
|
||||
}
|
||||
|
||||
HEADERS += \
|
||||
../ble/ble.h \
|
||||
|
|
|
|||
|
|
@ -93,7 +93,12 @@ void BLE::scanServices() {
|
|||
connect(controller, QOverload<QLowEnergyController::Error>::of(&QLowEnergyController::error),
|
||||
this, &BLE::errorReceived);
|
||||
#else
|
||||
connect(controller, &QLowEnergyController::errorOccurred, this, &BLE::errorReceived);
|
||||
connect(controller, &QLowEnergyController::errorOccurred,
|
||||
this, &BLE::errorReceived);
|
||||
connect(controller, &QLowEnergyController::mtuChanged,
|
||||
[](int mtu) {
|
||||
qDebug() << "MTU changed to:" << mtu;
|
||||
});
|
||||
#endif
|
||||
connect(controller, &QLowEnergyController::disconnected,
|
||||
this, &BLE::deviceDisconnected);
|
||||
|
|
@ -130,6 +135,9 @@ void BLE::serviceScanDone() {
|
|||
scanned = true;
|
||||
Q_EMIT mainServiceReady();
|
||||
qDebug() << "service scan done";
|
||||
#if QT_VERSION >= 0x060000
|
||||
qDebug() << "MTU:" << controller->mtu();
|
||||
#endif
|
||||
}
|
||||
|
||||
void BLE::connectToService(const QString& uuid) {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@
|
|||
|
||||
#ifdef Q_OS_ANDROID
|
||||
#include "../android_service/qtandroidservice_ro.h"
|
||||
#include <QAndroidService>
|
||||
#if (QT_VERSION < 0x060000)
|
||||
#include <QAndroidService>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// service
|
||||
|
|
|
|||
|
|
@ -14,8 +14,12 @@
|
|||
|
||||
#ifdef Q_OS_ANDROID
|
||||
#include "rep_qtandroidservice_replica.h"
|
||||
#include <QtAndroid>
|
||||
#include <QAndroidJniEnvironment>
|
||||
#if (QT_VERSION < 0x060000)
|
||||
#include <QAndroidService>
|
||||
#include <QAndroidJniEnvironment>
|
||||
#else
|
||||
#include <QtCore/private/qandroidextras_p.h>
|
||||
#endif
|
||||
#else
|
||||
#include "ble/ble_meshtastic.h"
|
||||
#endif
|
||||
|
|
@ -154,30 +158,50 @@ QVariant QT::setBackgroundMode(const QVariant& vBackground) {
|
|||
|
||||
#ifdef Q_OS_ANDROID
|
||||
static void clearEventualExceptions() {
|
||||
#if (QT_VERSION < 0x060000)
|
||||
QAndroidJniEnvironment env;
|
||||
#else
|
||||
QJniEnvironment env;
|
||||
#endif
|
||||
if (env->ExceptionCheck()) {
|
||||
env->ExceptionClear();
|
||||
}
|
||||
}
|
||||
|
||||
static qlonglong getLongField(const char* name) {
|
||||
#if (QT_VERSION < 0x060000)
|
||||
QAndroidJniObject activity = QtAndroid::androidActivity();
|
||||
#else
|
||||
QJniObject activity = QtAndroidPrivate::activity();
|
||||
#endif
|
||||
return static_cast<qlonglong>(activity.getField<jlong>(name));
|
||||
}
|
||||
|
||||
static double getDoubleField(const char* name) {
|
||||
#if (QT_VERSION < 0x060000)
|
||||
QAndroidJniObject activity = QtAndroid::androidActivity();
|
||||
#else
|
||||
QJniObject activity = QtAndroidPrivate::activity();
|
||||
#endif
|
||||
return static_cast<double>(activity.getField<jdouble>(name));
|
||||
}
|
||||
#endif
|
||||
|
||||
QVariant QT::iniPositioning() {
|
||||
#ifdef Q_OS_ANDROID
|
||||
#if (QT_VERSION < 0x060000)
|
||||
QtAndroid::runOnAndroidThread([] {
|
||||
QAndroidJniObject activity = QtAndroid::androidActivity();
|
||||
activity.callMethod<void>("iniLocation", "()V");
|
||||
clearEventualExceptions();
|
||||
});
|
||||
#else
|
||||
QNativeInterface::QAndroidApplication::runOnAndroidMainThread([&] {
|
||||
QJniObject activity = QtAndroidPrivate::activity();
|
||||
activity.callMethod<void>("iniLocation", "()V");
|
||||
clearEventualExceptions();
|
||||
});
|
||||
#endif
|
||||
#endif
|
||||
return QVariant();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,11 @@
|
|||
#include <QtQuick/QQuickView>
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
#include <QtAndroid>
|
||||
#if (QT_VERSION < 0x060000)
|
||||
#include <QAndroidService>
|
||||
#else
|
||||
#include <QtCore/private/qandroidextras_p.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
|
@ -746,6 +750,9 @@ cl_object ensure_permissions2(cl_object l_permissions) {
|
|||
cl_object l_granted = ECL_NIL;
|
||||
QList<StringInt> deniedSI;
|
||||
QStringList denied;
|
||||
|
||||
#if QT_VERSION < 0x060000
|
||||
// for Qt5
|
||||
for (StringInt p : qAsConst(permissions)) {
|
||||
if (QtAndroid::checkPermission(p.first) == QtAndroid::PermissionResult::Granted) {
|
||||
l_granted = CONS(cl_nth(ecl_make_fixnum(p.second), l_permissions),
|
||||
|
|
@ -768,6 +775,33 @@ cl_object ensure_permissions2(cl_object l_permissions) {
|
|||
});
|
||||
loop.exec(QEventLoop::ExcludeUserInputEvents);
|
||||
}
|
||||
#else
|
||||
// for Qt6
|
||||
for (StringInt p : qAsConst(permissions)) {
|
||||
if (QtAndroidPrivate::checkPermission(p.first).result() == QtAndroidPrivate::Authorized) {
|
||||
l_granted = CONS(cl_nth(ecl_make_fixnum(p.second), l_permissions),
|
||||
l_granted);
|
||||
} else {
|
||||
deniedSI << p;
|
||||
denied << p.first;
|
||||
}
|
||||
}
|
||||
if (!denied.isEmpty()) {
|
||||
QStringList granted;
|
||||
for (auto permission : qAsConst(denied)) {
|
||||
if (QtAndroidPrivate::requestPermission(permission).result() == QtAndroidPrivate::Authorized) {
|
||||
granted << permission;
|
||||
}
|
||||
}
|
||||
for (StringInt p : qAsConst(deniedSI)) {
|
||||
if (granted.contains(p.first)) {
|
||||
l_granted = CONS(cl_nth(ecl_make_fixnum(p.second), l_permissions),
|
||||
l_granted);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
l_ret = cl_nreverse(l_granted);
|
||||
#endif
|
||||
ecl_return1(ecl_process_env(), l_ret);
|
||||
|
|
|
|||
|
|
@ -33,11 +33,17 @@ android {
|
|||
} else {
|
||||
ECL = $$(ECL_ANDROID)
|
||||
}
|
||||
QT += androidextras
|
||||
INCLUDEPATH = $$ECL/include
|
||||
LIBS = -L$$ECL/lib -lecl
|
||||
DESTDIR = ../../platforms/android/lib
|
||||
|
||||
equals(QT_MAJOR_VERSION, 6) {
|
||||
QT += core-private
|
||||
}
|
||||
lessThan(QT_MAJOR_VERSION, 6) {
|
||||
QT += androidextras
|
||||
}
|
||||
|
||||
32bit {
|
||||
ANDROID_ABIS = "armeabi-v7a"
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue