Skip to content

Commit

Permalink
Merge pull request #6032 from opengisch/android_crash_fix
Browse files Browse the repository at this point in the history
Fix 3.5.0 crashes reported by Googe Play Store
  • Loading branch information
nirvn authored Feb 23, 2025
2 parents 6573c1d + f074876 commit c8a9bc6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void onDestroy() {
public int onStartCommand(Intent intent, int flags, int startId) {
Log.v("QFieldPositioningService", "onStartCommand triggered");

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

Notification notification = builder.build();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
startForeground(NOTIFICATION_ID, notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION);
} else {
startForeground(NOTIFICATION_ID, notification);
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
startForeground(NOTIFICATION_ID, notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION);
} else {
startForeground(NOTIFICATION_ID, notification);
}
} catch (SecurityException e) {
Log.v("QFieldPositioningService",
"Missing permission to launch the positioning service");
return START_NOT_STICKY;
}

return START_STICKY;
Expand Down
5 changes: 4 additions & 1 deletion src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function(create_executable)
qt_import_plugins(${exe_TARGET} INCLUDE Qt::QSvgPlugin)
qt_import_plugins(${exe_TARGET} INCLUDE Qt::Core5Compat)

if(IOS)
if(IOS OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
target_link_libraries(
${exe_TARGET}
PUBLIC Qt6::QDarwinCameraPermissionPlugin
Expand All @@ -121,6 +121,9 @@ function(create_executable)

set_target_properties(${exe_TARGET} PROPERTIES AUTORCC TRUE)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
# Handles platform-specific tasks, including insuring permission plugins
qt_finalize_executable(qfield)

set_target_properties(
${exe_TARGET}
PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "${PROJECT_NAME}"
Expand Down
1 change: 1 addition & 0 deletions src/core/qgismobileapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ void QgisMobileapp::onAfterFirstRendering()
}
}
}
rootObjects().first()->setProperty( "sceneLoaded", true );
mFirstRenderingFlag = false;
}
}
Expand Down
21 changes: 16 additions & 5 deletions src/qml/qgismobileapp.qml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,19 @@ ApplicationWindow {
Material.theme: Theme.darkTheme ? "Dark" : "Light"
Material.accent: Theme.mainColor

property bool sceneLoaded: false
property bool sceneBorderless: false
property double sceneTopMargin: platformUtilities.sceneMargins(mainWindow)["top"]
property double sceneBottomMargin: platformUtilities.sceneMargins(mainWindow)["bottom"]

onSceneLoadedChanged: {
// This requires the scene to be fully loaded not to crash due to possibility of
// a thread blocking permission request being thrown
if (positioningSettings.positioningActivated) {
positionSource.active = true;
}
}

Timer {
id: refreshSceneMargins
running: false
Expand Down Expand Up @@ -384,11 +393,13 @@ ApplicationWindow {
objectName: "positioningSettings"

onPositioningActivatedChanged: {
if (positioningActivated) {
displayToast(qsTr("Activating positioning service"));
positionSource.active = true;
} else {
positionSource.active = false;
if (mainWindow.sceneLoaded) {
if (positioningActivated) {
displayToast(qsTr("Activating positioning service"));
positionSource.active = true;
} else {
positionSource.active = false;
}
}
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

1 comment on commit c8a9bc6

@qfield-fairy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.