Skip to content

Commit a0aa7fe

Browse files
pprabhu-ossGerrit Code Review
authored and
Gerrit Code Review
committed
Merge "[Emulib] Report error when screenshot grabbing fails due to bad Sdk path" into emu-master-dev
2 parents f668758 + 58c3c28 commit a0aa7fe

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

android/skin/qt/emulator-qt-window.cpp

+38-5
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,13 @@ EmulatorQtWindow::EmulatorQtWindow(QWidget *parent) :
127127
QObject::connect(QApplication::instance(), &QCoreApplication::aboutToQuit, this, &EmulatorQtWindow::slot_clearInstance);
128128

129129
QObject::connect(&mScreencapProcess, SIGNAL(finished(int)), this, SLOT(slot_screencapFinished(int)));
130+
QObject::connect(&mScreencapPullProcess,
131+
SIGNAL(error(QProcess::ProcessError)), this,
132+
SLOT(slot_showProcessErrorDialog(QProcess::ProcessError)));
130133
QObject::connect(&mScreencapPullProcess, SIGNAL(finished(int)), this, SLOT(slot_screencapPullFinished(int)));
134+
QObject::connect(&mScreencapPullProcess,
135+
SIGNAL(error(QProcess::ProcessError)), this,
136+
SLOT(slot_showProcessErrorDialog(QProcess::ProcessError)));
131137

132138
QObject::connect(mContainer.horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(slot_horizontalScrollChanged(int)));
133139
QObject::connect(mContainer.verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(slot_verticalScrollChanged(int)));
@@ -206,6 +212,26 @@ void EmulatorQtWindow::showAvdArchWarning()
206212
}
207213
}
208214

215+
void EmulatorQtWindow::slot_showProcessErrorDialog(
216+
QProcess::ProcessError exitStatus) {
217+
QString msg;
218+
switch (exitStatus) {
219+
case QProcess::Timedout:
220+
// Our wait for process starting is best effort. If we timed out,
221+
// meh.
222+
return;
223+
case QProcess::FailedToStart:
224+
msg =
225+
tr("Failed to start process.<br/>"
226+
"Check settings to verify that your chosen SDK path "
227+
"is valid.");
228+
break;
229+
default:
230+
msg = tr("Unexpected error occured while grabbing screenshot.");
231+
}
232+
showErrorDialog(msg, tr("Screenshot"));
233+
}
234+
209235
void EmulatorQtWindow::slot_startupTick() {
210236
// It's been a while since we were launched, and the main
211237
// window still hasn't appeared.
@@ -740,9 +766,12 @@ void EmulatorQtWindow::screenshot()
740766
mOverlay.showAsFlash();
741767
mFlashAnimation.start();
742768

743-
// Keep track of this process
744769
mScreencapProcess.start(command, args);
745-
mScreencapProcess.waitForStarted();
770+
// TODO(pprabhu): It is a bad idea to call |waitForStarted| from the GUI
771+
// thread, because it can freeze the UI till timeout.
772+
if (!mScreencapProcess.waitForStarted(5000)) {
773+
slot_showProcessErrorDialog(mScreencapProcess.error());
774+
}
746775
}
747776

748777

@@ -754,7 +783,6 @@ void EmulatorQtWindow::slot_screencapFinished(int exitStatus)
754783
QString msg = tr("The screenshot could not be captured. Output:<br/><br/>") + QString(er);
755784
showErrorDialog(msg, tr("Screenshot"));
756785
} else {
757-
758786
// Pull the image from its remote location to the desired location
759787
QStringList args;
760788
QString command = tool_window->getAdbFullPath(&args);
@@ -777,9 +805,14 @@ void EmulatorQtWindow::slot_screencapFinished(int exitStatus)
777805

778806
args << fileName;
779807

780-
// Use a different process to avoid infinite looping when pulling the file
808+
// Use a different process to avoid infinite looping when pulling the
809+
// file.
781810
mScreencapPullProcess.start(command, args);
782-
mScreencapPullProcess.waitForStarted();
811+
// TODO(pprabhu): It is a bad idea to call |waitForStarted| from the GUI
812+
// thread, because it can freeze the UI till timeout.
813+
if (!mScreencapPullProcess.waitForStarted(5000)) {
814+
slot_showProcessErrorDialog(mScreencapPullProcess.error());
815+
}
783816
}
784817
}
785818

android/skin/qt/emulator-qt-window.h

+2
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ private slots:
196196

197197
void slot_resizeDone();
198198

199+
void slot_showProcessErrorDialog(QProcess::ProcessError exitStatus);
200+
199201
/*
200202
Here are conventional slots that perform interesting high-level functions in the emulator. These can be hooked up to signals
201203
from UI elements or called independently.

0 commit comments

Comments
 (0)