3#include <QAndroidScreen.h>
4#include <QtAndroidHelpers/QAndroidPartialWakeLocker.h>
5#include <QtAndroidHelpers/QAndroidWiFiLocker.h>
6#include <QtCore/QCoreApplication>
8#include <QtCore/QFileInfo>
9#include <QtCore/QJniEnvironment>
10#include <QtCore/QJniObject>
11#include <QtCore/QMetaObject>
12#include <QtCore/QSharedPointer>
13#include <QtCore/QStandardPaths>
29 qCDebug(AndroidInterfaceLog) << QJniObject(message).toString();
34 qCWarning(AndroidInterfaceLog) << QJniObject(message).toString();
40 qCWarning(AndroidInterfaceLog) <<
"Storage permission request denied";
48 (void)QMetaObject::invokeMethod(
52 if (!settingsManager) {
57 if (!appSettings || appSettings->androidDontSaveToSDCard()->rawValue().toBool()) {
61 SettingsFact*
const savePathFact = qobject_cast<SettingsFact*>(appSettings->savePath());
66 const QString appName = QCoreApplication::applicationName();
67 const QString currentSavePath = savePathFact->
rawValue().toString();
68 const QString internalBasePath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
69 const QString internalSavePath = QDir(internalBasePath).filePath(appName);
71 if (!currentSavePath.isEmpty() && (currentSavePath != internalSavePath)) {
76 if (sdCardRootPath.isEmpty() || !QDir(sdCardRootPath).exists() || !QFileInfo(sdCardRootPath).isWritable()) {
80 const QString sdSavePath = QDir(sdCardRootPath).filePath(appName);
81 if (currentSavePath != sdSavePath) {
82 qCDebug(AndroidInterfaceLog) <<
"Applying SD card save path after permission grant:" << sdSavePath;
86 Qt::QueuedConnection);
91 const char*
const filePathCStr = env->GetStringUTFChars(filePathA,
nullptr);
92 const QString filePath = QString::fromUtf8(filePathCStr);
93 env->ReleaseStringUTFChars(filePathA, filePathCStr);
94 (void)QJniEnvironment::checkAndClearExceptions(env);
104 qCDebug(AndroidInterfaceLog) <<
"Registering Native Functions";
106 const JNINativeMethod javaMethods[]{
107 {
"qgcLogDebug",
"(Ljava/lang/String;)V",
reinterpret_cast<void*
>(
jniLogDebug)},
108 {
"qgcLogWarning",
"(Ljava/lang/String;)V",
reinterpret_cast<void*
>(
jniLogWarning)},
110 {
"onImportResult",
"(Ljava/lang/String;)V",
reinterpret_cast<void*
>(
jniOnImportResult)}};
116 qCDebug(AndroidInterfaceLog) <<
"Native Functions Registered";
122 const bool hasPermission =
125 if (env.checkAndClearExceptions()) {
126 qCWarning(AndroidInterfaceLog) <<
"Exception in checkStoragePermissions";
131 qCDebug(AndroidInterfaceLog) <<
"Storage permissions granted";
133 qCWarning(AndroidInterfaceLog) <<
"Storage permissions not granted";
136 return hasPermission;
142 qCWarning(AndroidInterfaceLog) <<
"Storage Permission Denied";
146 const QJniObject result =
149 if (env.checkAndClearExceptions()) {
150 qCWarning(AndroidInterfaceLog) <<
"Exception in getSDCardPath";
153 if (!result.isValid()) {
154 qCWarning(AndroidInterfaceLog) <<
"Call to java getSDCardPath failed: Invalid Result";
158 return result.toString();
165 const QJniObject jDestPath = QJniObject::fromString(destPath);
166 QJniObject::callStaticMethod<void>(
168 "openFileImportDialog",
169 "(Ljava/lang/String;)V",
170 jDestPath.object<jstring>());
173 if (env.checkAndClearExceptions()) {
174 qCWarning(AndroidInterfaceLog) <<
"Exception in openFileImportDialog";
187 if (!QAndroidScreen::instance()) {
188 new QAndroidScreen(QCoreApplication::instance());
190 QAndroidScreen::instance()->keepScreenOn(on);
194 s_wifiLock = QAndroidWiFiLocker::instance().getLock();
#define QGC_LOGGING_CATEGORY(name, categoryStr)
void setRawValue(const QVariant &value)
QVariant rawValue() const
Value after translation.
A SettingsFact is Fact which holds a QSettings value.
Provides access to all app settings.
static SettingsManager * instance()
AppSettings * appSettings() const
static void jniOnImportResult(JNIEnv *env, jobject, jstring filePathA)
bool checkStoragePermissions()
static void jniLogDebug(JNIEnv *, jobject, jstring message)
static void jniStoragePermissionsResult(JNIEnv *, jobject, jboolean granted)
static std::function< void(const QString &)> s_importCallback
static void jniLogWarning(JNIEnv *, jobject, jstring message)
static QSharedPointer< QLocks::QLockBase > s_wifiLock
void openFileImportDialog(const QString &destPath, std::function< void(const QString &)> callback)
void setKeepScreenOn(bool on)
constexpr const char * kJniQGCActivityClassName
static QSharedPointer< QLocks::QLockBase > s_partialWakeLock