From 15446c9e3f069c883c5348a520254f04b707dd4a Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Wed, 15 May 2024 20:20:35 +0200 Subject: [PATCH] Android: Don't crash when dis- and reconnecting phone via USB When ADB signals a change about the list of connected devices, the whole build/run steps tree gets deleted and recreated. The AndroidBuildApkStep is a part of that tree and starts one or more "keytool" processes on creation/init. They were started with their own event loop. Those synthetic event loops caused a change in order of deletion which led to crashes with obscure backtraces. This change removes the event loop creation from "keytool" calls. The crash is avoided. The calls take ~0.5 seconds. The short UI freeze should be an acceptable hotfix trade-off for a crash in QtC13. If 0.5 seconds freeze seem too much, a better fix could be done in QtC 14. Fixes: QTCREATORBUG-30645 Fixes: QTCREATORBUG-30770 Change-Id: I8842dc87023142ae75572bf255c7f1ec808d9bab Reviewed-by: Jarek Kobus --- src/plugins/android/androidbuildapkstep.cpp | 2 +- src/plugins/android/androidcreatekeystorecertificate.cpp | 2 +- src/plugins/android/androidmanager.cpp | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/plugins/android/androidbuildapkstep.cpp b/src/plugins/android/androidbuildapkstep.cpp index c57d008705d..c73cc916f70 100644 --- a/src/plugins/android/androidbuildapkstep.cpp +++ b/src/plugins/android/androidbuildapkstep.cpp @@ -1002,7 +1002,7 @@ QAbstractItemModel *AndroidBuildApkStep::keystoreCertificates() Process keytoolProc; keytoolProc.setCommand({androidConfig().keytoolPath(), params}); using namespace std::chrono_literals; - keytoolProc.runBlocking(30s, EventLoopMode::On); + keytoolProc.runBlocking(30s); if (keytoolProc.result() > ProcessResult::FinishedWithError) QMessageBox::critical(nullptr, Tr::tr("Error"), Tr::tr("Failed to run keytool.")); else diff --git a/src/plugins/android/androidcreatekeystorecertificate.cpp b/src/plugins/android/androidcreatekeystorecertificate.cpp index 7a6fd7cf593..f0b5f7c00ce 100644 --- a/src/plugins/android/androidcreatekeystorecertificate.cpp +++ b/src/plugins/android/androidcreatekeystorecertificate.cpp @@ -275,7 +275,7 @@ void AndroidCreateKeystoreCertificate::buttonBoxAccepted() Process genKeyCertProc; genKeyCertProc.setCommand(command); using namespace std::chrono_literals; - genKeyCertProc.runBlocking(15s, EventLoopMode::On); + genKeyCertProc.runBlocking(15s); if (genKeyCertProc.result() != ProcessResult::FinishedWithSuccess) { QMessageBox::critical(this, Tr::tr("Error"), diff --git a/src/plugins/android/androidmanager.cpp b/src/plugins/android/androidmanager.cpp index bd230c76af7..d2d4d1c7894 100644 --- a/src/plugins/android/androidmanager.cpp +++ b/src/plugins/android/androidmanager.cpp @@ -614,7 +614,7 @@ bool checkKeystorePassword(const FilePath &keystorePath, const QString &keystore "--storepass", keystorePasswd}); Process proc; proc.setCommand(cmd); - proc.runBlocking(10s, EventLoopMode::On); + proc.runBlocking(10s); return proc.result() == ProcessResult::FinishedWithSuccess; } @@ -631,7 +631,7 @@ bool checkCertificatePassword(const FilePath &keystorePath, const QString &keyst Process proc; proc.setCommand({androidConfig().keytoolPath(), arguments}); - proc.runBlocking(10s, EventLoopMode::On); + proc.runBlocking(10s); return proc.result() == ProcessResult::FinishedWithSuccess; } @@ -644,7 +644,7 @@ bool checkCertificateExists(const FilePath &keystorePath, const QString &keystor Process proc; proc.setCommand({androidConfig().keytoolPath(), arguments}); - proc.runBlocking(10s, EventLoopMode::On); + proc.runBlocking(10s); return proc.result() == ProcessResult::FinishedWithSuccess; }