Android: Prevent Qt apps from running in the background

Previously, the environment variable QT_BLOCK_EVENT_LOOPS_WHEN_SUSPENDED
was set to an empty string, which allowed QAndroidEventDispatcherStopper
to keep the application running in the background when it entered the
suspended state (onStop).
To address this issue, the isBackgroundRunningBlocked() function has
been added to validate the proper value when getMetaData(..) returns a
value.

Fixes: QTBUG-125496
Pick-to: 6.7 6.8
Change-Id: I541af3bb1f4e239ee8ba2be32583b91afc7a43e2
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
This commit is contained in:
Ahmed El Khazari 2024-07-25 20:16:20 +03:00
parent 98ffe407fa
commit 1f1f726c79

View File

@ -107,12 +107,18 @@ abstract class QtLoader {
setEnvironmentVariable("QT_ANDROID_FONTS_SERIF", "Droid Serif");
setEnvironmentVariable("HOME", m_context.getFilesDir().getAbsolutePath());
setEnvironmentVariable("TMPDIR", m_context.getCacheDir().getAbsolutePath());
String backgroundRunning = getMetaData("android.app.background_running");
setEnvironmentVariable("QT_BLOCK_EVENT_LOOPS_WHEN_SUSPENDED", backgroundRunning);
setEnvironmentVariable("QT_BLOCK_EVENT_LOOPS_WHEN_SUSPENDED", isBackgroundRunningBlocked());
setEnvironmentVariable("QTRACE_LOCATION", getMetaData("android.app.trace_location"));
appendApplicationParameters(getMetaData("android.app.arguments"));
}
private String isBackgroundRunningBlocked() {
final String backgroundRunning = getMetaData("android.app.background_running");
if (backgroundRunning.compareTo("true") == 0)
return "0";
return "1";
}
private ArrayList<String> preferredAbiLibs(String[] libs) {
HashMap<String, ArrayList<String>> abiLibs = new HashMap<>();
for (String lib : libs) {