Android: use QT_ANDROID_DEBUGGER_MAIN_THREAD_SLEEP_MS for debugging only

Enable the workaround to sleep and wait for the debugger to attach from
Qt Creator using QT_ANDROID_DEBUGGER_MAIN_THREAD_SLEEP_MS only when
running a debugger and not with all debug apps.

Fixes: QTBUG-128298
Pick-to: 6.7
Change-Id: I0a0866fada27de250fd6946a8ccfd254824d70e0
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
(cherry picked from commit e8a35410c4c699ea588791006b36dd363cc25d9c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Assam Boudjelthia 2024-08-22 22:53:08 +03:00 committed by Qt Cherry-pick Bot
parent 87b21e3ded
commit 03bf2cba3f
2 changed files with 19 additions and 16 deletions

View File

@ -11,7 +11,6 @@ import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.system.Os;
import android.util.Base64;
import android.util.DisplayMetrics;
import android.util.Log;
@ -113,14 +112,6 @@ class QtActivityLoader extends QtLoader {
String extraAppParams = extras.getString("extraappparams");
appendApplicationParameters(getDecodedUtfString(extraAppParams));
}
m_debuggerSleepMs = 3000;
if (Os.getenv("QT_ANDROID_DEBUGGER_MAIN_THREAD_SLEEP_MS") != null) {
try {
m_debuggerSleepMs = Integer.parseInt(Os.getenv("QT_ANDROID_DEBUGGER_MAIN_THREAD_SLEEP_MS"));
} catch (NumberFormatException ignored) {
}
}
} else {
Log.d(QtNative.QtTAG, "Not in debug mode! It is not allowed to use extra arguments " +
"in non-debug mode.");

View File

@ -17,6 +17,8 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.os.Debug;
import android.system.Os;
import android.util.Log;
import java.io.File;
@ -47,8 +49,6 @@ abstract class QtLoader {
protected String m_applicationParameters = "";
protected HashMap<String, String> m_environmentVariables = new HashMap<>();
protected int m_debuggerSleepMs = 0;
protected static QtLoader m_instance = null;
protected boolean m_librariesLoaded;
@ -440,11 +440,23 @@ abstract class QtLoader {
ArrayList<String> nativeLibraries = getQtLibrariesList();
nativeLibraries.addAll(getLocalLibrariesList());
if (m_debuggerSleepMs > 0) {
Log.i(QtTAG, "Sleeping for " + m_debuggerSleepMs +
"ms, helping the native debugger to settle. " +
"Use the env QT_ANDROID_DEBUGGER_MAIN_THREAD_SLEEP_MS variable to change this value.");
QtNative.getQtThread().sleep(m_debuggerSleepMs);
if (Debug.isDebuggerConnected()) {
final String debuggerSleepEnvVarName = "QT_ANDROID_DEBUGGER_MAIN_THREAD_SLEEP_MS";
int debuggerSleepMs = 3000;
if (Os.getenv(debuggerSleepEnvVarName) != null) {
try {
debuggerSleepMs = Integer.parseInt(Os.getenv(debuggerSleepEnvVarName));
} catch (NumberFormatException ignored) {
}
}
if (debuggerSleepMs > 0) {
Log.i(QtTAG, "Sleeping for " + debuggerSleepMs +
"ms, helping the native debugger to settle. " +
"Use the env " + debuggerSleepEnvVarName +
" variable to change this value.");
QtNative.getQtThread().sleep(debuggerSleepMs);
}
}
if (!loadLibraries(nativeLibraries)) {