Skip to content

Commit c8a9bc6

Browse files
authored
Merge pull request #6032 from opengisch/android_crash_fix
Fix 3.5.0 crashes reported by Googe Play Store
2 parents 6573c1d + f074876 commit c8a9bc6

File tree

5 files changed

+33
-12
lines changed

5 files changed

+33
-12
lines changed

platform/android/src/ch/opengis/qfield/QFieldPositioningService.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void onDestroy() {
112112
public int onStartCommand(Intent intent, int flags, int startId) {
113113
Log.v("QFieldPositioningService", "onStartCommand triggered");
114114

115-
if (intent.hasExtra("content")) {
115+
if (intent != null && intent.hasExtra("content")) {
116116
ClipboardManager clipboard =
117117
(ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
118118
clipboard.setText(intent.getStringExtra("content"));
@@ -156,11 +156,17 @@ public int onStartCommand(Intent intent, int flags, int startId) {
156156

157157
Notification notification = builder.build();
158158

159-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
160-
startForeground(NOTIFICATION_ID, notification,
161-
ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION);
162-
} else {
163-
startForeground(NOTIFICATION_ID, notification);
159+
try {
160+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
161+
startForeground(NOTIFICATION_ID, notification,
162+
ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION);
163+
} else {
164+
startForeground(NOTIFICATION_ID, notification);
165+
}
166+
} catch (SecurityException e) {
167+
Log.v("QFieldPositioningService",
168+
"Missing permission to launch the positioning service");
169+
return START_NOT_STICKY;
164170
}
165171

166172
return START_STICKY;

src/app/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function(create_executable)
103103
qt_import_plugins(${exe_TARGET} INCLUDE Qt::QSvgPlugin)
104104
qt_import_plugins(${exe_TARGET} INCLUDE Qt::Core5Compat)
105105

106-
if(IOS)
106+
if(IOS OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
107107
target_link_libraries(
108108
${exe_TARGET}
109109
PUBLIC Qt6::QDarwinCameraPermissionPlugin
@@ -121,6 +121,9 @@ function(create_executable)
121121

122122
set_target_properties(${exe_TARGET} PROPERTIES AUTORCC TRUE)
123123
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
124+
# Handles platform-specific tasks, including insuring permission plugins
125+
qt_finalize_executable(qfield)
126+
124127
set_target_properties(
125128
${exe_TARGET}
126129
PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "${PROJECT_NAME}"

src/core/qgismobileapp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ void QgisMobileapp::onAfterFirstRendering()
688688
}
689689
}
690690
}
691+
rootObjects().first()->setProperty( "sceneLoaded", true );
691692
mFirstRenderingFlag = false;
692693
}
693694
}

src/qml/qgismobileapp.qml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,19 @@ ApplicationWindow {
4646
Material.theme: Theme.darkTheme ? "Dark" : "Light"
4747
Material.accent: Theme.mainColor
4848

49+
property bool sceneLoaded: false
4950
property bool sceneBorderless: false
5051
property double sceneTopMargin: platformUtilities.sceneMargins(mainWindow)["top"]
5152
property double sceneBottomMargin: platformUtilities.sceneMargins(mainWindow)["bottom"]
5253

54+
onSceneLoadedChanged: {
55+
// This requires the scene to be fully loaded not to crash due to possibility of
56+
// a thread blocking permission request being thrown
57+
if (positioningSettings.positioningActivated) {
58+
positionSource.active = true;
59+
}
60+
}
61+
5362
Timer {
5463
id: refreshSceneMargins
5564
running: false
@@ -384,11 +393,13 @@ ApplicationWindow {
384393
objectName: "positioningSettings"
385394

386395
onPositioningActivatedChanged: {
387-
if (positioningActivated) {
388-
displayToast(qsTr("Activating positioning service"));
389-
positionSource.active = true;
390-
} else {
391-
positionSource.active = false;
396+
if (mainWindow.sceneLoaded) {
397+
if (positioningActivated) {
398+
displayToast(qsTr("Activating positioning service"));
399+
positionSource.active = true;
400+
} else {
401+
positionSource.active = false;
402+
}
392403
}
393404
}
394405
}
2.14 KB
Loading

0 commit comments

Comments
 (0)