56 qCWarning(AndroidInterfaceLog) <<
"Storage permission request denied; disabling save to SD card";
58 (void)QMetaObject::invokeMethod(
62 if (!settingsManager) {
71 if (!appSettings->androidDontSaveToSDCard()->rawValue().toBool()) {
72 appSettings->androidDontSaveToSDCard()->setRawValue(
true);
75 Qt::QueuedConnection);
79 (void)QMetaObject::invokeMethod(
83 if (!settingsManager) {
88 if (!appSettings || appSettings->androidDontSaveToSDCard()->rawValue().toBool()) {
92 SettingsFact*
const savePathFact = qobject_cast<SettingsFact*>(appSettings->savePath());
97 const QString appName = QCoreApplication::applicationName();
98 const QString currentSavePath = savePathFact->
rawValue().toString();
99 const QString internalBasePath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
100 const QString internalSavePath = QDir(internalBasePath).filePath(appName);
102 if (!currentSavePath.isEmpty() && (currentSavePath != internalSavePath)) {
107 if (sdCardRootPath.isEmpty() || !QDir(sdCardRootPath).exists() || !QFileInfo(sdCardRootPath).isWritable()) {
111 const QString sdSavePath = QDir(sdCardRootPath).filePath(appName);
112 if (currentSavePath != sdSavePath) {
113 qCDebug(AndroidInterfaceLog) <<
"Applying SD card save path after permission grant:" << sdSavePath;
117 Qt::QueuedConnection);
122 const char*
const filePathCStr = env->GetStringUTFChars(filePathA,
nullptr);
123 const QString filePath = QString::fromUtf8(filePathCStr);
124 env->ReleaseStringUTFChars(filePathA, filePathCStr);
125 (void)QJniEnvironment::checkAndClearExceptions(env);
135 qCDebug(AndroidInterfaceLog) <<
"Registering Native Functions";
137 const JNINativeMethod javaMethods[]{
138 {
"qgcLogDebug",
"(Ljava/lang/String;)V",
reinterpret_cast<void*
>(
jniLogDebug)},
139 {
"qgcLogWarning",
"(Ljava/lang/String;)V",
reinterpret_cast<void*
>(
jniLogWarning)},
141 {
"onImportResult",
"(Ljava/lang/String;)V",
reinterpret_cast<void*
>(
jniOnImportResult)}};
147 qCDebug(AndroidInterfaceLog) <<
"Native Functions Registered";
196 const QJniObject jDestPath = QJniObject::fromString(destPath);
197 QJniObject::callStaticMethod<void>(
199 "openFileImportDialog",
200 "(Ljava/lang/String;)V",
201 jDestPath.object<jstring>());
204 if (env.checkAndClearExceptions()) {
205 qCWarning(AndroidInterfaceLog) <<
"Exception in openFileImportDialog";
234 static int s_activeWork = 0;
235 static QSharedPointer<QLocks::QLockBase> s_backgroundWakeLock;
236 static QSharedPointer<QLocks::QLockBase> s_backgroundWifiLock;
238 const bool wasActive = (s_activeWork != 0);
240 s_activeWork |=
static_cast<int>(work);
242 s_activeWork &= ~static_cast<int>(work);
244 const bool isActive = (s_activeWork != 0);
245 if (isActive == wasActive) {
250 s_backgroundWakeLock = QAndroidPartialWakeLocker::instance().getLock();
251 s_backgroundWifiLock = QAndroidWiFiLocker::instance().getLock();
252 const QJniObject channelName =
253 QJniObject::fromString(QCoreApplication::translate(
"AndroidInterface",
"Background activity"));
254 const QJniObject title = QJniObject::fromString(
255 QCoreApplication::translate(
"AndroidInterface",
"%1 is running").arg(QCoreApplication::applicationName()));
256 const QJniObject text = QJniObject::fromString(QCoreApplication::translate(
257 "AndroidInterface",
"Active in the background while a vehicle is connected or video is recording."));
259 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
260 channelName.object<jstring>(), title.object<jstring>(),
261 text.object<jstring>());
263 s_backgroundWakeLock.reset();
264 s_backgroundWifiLock.reset();
268 if (env.checkAndClearExceptions()) {
269 qCWarning(AndroidInterfaceLog) <<
"Exception while" << (isActive ?
"starting" :
"stopping")
270 <<
"the foreground service";
275 static bool s_askedForNotifications =
false;
276 if (isActive && !s_askedForNotifications && (QNativeInterface::QAndroidApplication::sdkVersion() >= 33)) {
277 s_askedForNotifications =
true;
278 (void) QtAndroidPrivate::requestPermission(QStringLiteral(
"android.permission.POST_NOTIFICATIONS"));