2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 BogDan Vatra <bog_dan_ro@yahoo.com>
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
|
#include "androidconfigurations.h"
|
2016-01-29 14:05:00 +02:00
|
|
|
#include "androidrunnable.h"
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2015-06-29 10:36:29 +03:00
|
|
|
#include <projectexplorer/runconfiguration.h>
|
2015-08-10 17:43:58 +02:00
|
|
|
#include <qmldebug/qmldebugcommandlinearguments.h>
|
2013-05-03 12:41:58 +02:00
|
|
|
|
2016-06-08 16:57:32 +02:00
|
|
|
#include <QFutureInterface>
|
2012-04-18 20:30:57 +03:00
|
|
|
#include <QObject>
|
|
|
|
|
#include <QTimer>
|
2014-11-18 15:14:40 +01:00
|
|
|
#include <QTcpSocket>
|
2012-04-18 20:30:57 +03:00
|
|
|
#include <QThread>
|
|
|
|
|
#include <QProcess>
|
|
|
|
|
#include <QMutex>
|
|
|
|
|
|
|
|
|
|
namespace Android {
|
2014-07-04 14:28:55 +02:00
|
|
|
class AndroidRunConfiguration;
|
|
|
|
|
|
2012-04-18 20:30:57 +03:00
|
|
|
namespace Internal {
|
2012-08-09 01:56:51 +02:00
|
|
|
|
2012-04-18 20:30:57 +03:00
|
|
|
class AndroidRunner : public QThread
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
2014-11-18 15:14:40 +01:00
|
|
|
enum DebugHandShakeType {
|
|
|
|
|
PingPongFiles,
|
|
|
|
|
SocketHandShake
|
|
|
|
|
};
|
|
|
|
|
|
2012-04-18 20:30:57 +03:00
|
|
|
public:
|
2013-05-03 12:41:58 +02:00
|
|
|
AndroidRunner(QObject *parent, AndroidRunConfiguration *runConfig,
|
2015-06-29 10:36:29 +03:00
|
|
|
Core::Id runMode);
|
2012-04-18 20:30:57 +03:00
|
|
|
~AndroidRunner();
|
|
|
|
|
|
|
|
|
|
QString displayName() const;
|
2016-01-29 14:05:00 +02:00
|
|
|
void setRunnable(const AndroidRunnable &runnable);
|
|
|
|
|
const AndroidRunnable &runnable() const { return m_androidRunnable; }
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2016-06-26 22:52:59 +03:00
|
|
|
public:
|
2012-04-18 20:30:57 +03:00
|
|
|
void start();
|
2012-12-18 14:25:07 +02:00
|
|
|
void stop();
|
2013-04-18 10:01:05 +02:00
|
|
|
void handleRemoteDebuggerRunning();
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
|
signals:
|
2013-02-27 15:12:36 +01:00
|
|
|
void remoteServerRunning(const QByteArray &serverChannel, int pid);
|
2016-04-19 16:43:30 +02:00
|
|
|
void remoteProcessStarted(Utils::Port gdbServerPort, Utils::Port qmlPort);
|
2012-04-18 20:30:57 +03:00
|
|
|
void remoteProcessFinished(const QString &errString = QString());
|
|
|
|
|
|
2015-06-12 15:36:04 +02:00
|
|
|
void remoteOutput(const QString &output);
|
|
|
|
|
void remoteErrorOutput(const QString &output);
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2016-06-26 22:52:59 +03:00
|
|
|
private:
|
2012-04-18 20:30:57 +03:00
|
|
|
void checkPID();
|
|
|
|
|
void logcatReadStandardError();
|
|
|
|
|
void logcatReadStandardOutput();
|
|
|
|
|
void asyncStart();
|
Android: Run stop() asynchronously
Running SynchronousProcess (for adb) on the GUI thread is dangerous as
it might process unrelated events without returning, breaking
assumptions in other parts of Qt Creator. Rather run those things on a
worker thread, with a separate event loop, like we already do it when
starting processes.
Furthermore, returning, from start() or stop() while a thread is
running that accesses internals of AndroidRunner is also dangerous,
because most methods of AndroidRunner are not protected by relevant
mutexes and especially the destructor might get invoked while the
worker thread is still runnig. Thus, wait for the worker threads to
finish, in start() and stop().
This is a crutch, of course, as with proper locking we could keep the
GUI thread responsive while the adb commands are running, but just
serializing the execution reduces the risk of further breakage for now.
Change-Id: Ife92dc19aa8111374413590c3156027ba759746f
Task-number: QTCREATORBUG-16667
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
2016-07-27 15:58:28 +02:00
|
|
|
void asyncStop();
|
2016-06-08 16:57:32 +02:00
|
|
|
Q_INVOKABLE void launchAVDProcesses();
|
2013-02-27 15:12:36 +01:00
|
|
|
void adbKill(qint64 pid);
|
|
|
|
|
QStringList selector() const { return m_selector; }
|
|
|
|
|
void forceStop();
|
|
|
|
|
void findPs();
|
2014-03-13 17:33:47 +01:00
|
|
|
void logcatProcess(const QByteArray &text, QByteArray &buffer, bool onlyError);
|
2015-09-23 09:25:50 +02:00
|
|
|
bool adbShellAmNeedsQuotes();
|
2016-06-08 16:57:32 +02:00
|
|
|
void launchAVD();
|
2016-04-29 16:52:58 +02:00
|
|
|
bool runAdb(const QStringList &args, QString *errorMessage = nullptr, int timeoutS = 10);
|
2016-06-08 16:57:32 +02:00
|
|
|
private:
|
|
|
|
|
AndroidRunConfiguration *m_runConfig;
|
|
|
|
|
QString m_launchedAVDName;
|
|
|
|
|
QFutureInterface<bool> m_avdFutureInterface;
|
2012-04-18 20:30:57 +03:00
|
|
|
QProcess m_adbLogcatProcess;
|
2016-03-07 18:49:09 +02:00
|
|
|
QProcess m_psProc;
|
2013-02-27 15:12:36 +01:00
|
|
|
QTimer m_checkPIDTimer;
|
|
|
|
|
bool m_wasStarted;
|
2014-02-12 12:24:56 +01:00
|
|
|
int m_tries;
|
2014-03-13 17:33:47 +01:00
|
|
|
QByteArray m_stdoutBuffer;
|
|
|
|
|
QByteArray m_stderrBuffer;
|
2016-01-29 14:05:00 +02:00
|
|
|
AndroidRunnable m_androidRunnable;
|
2012-04-18 20:30:57 +03:00
|
|
|
qint64 m_processPID;
|
2012-06-24 19:32:45 -07:00
|
|
|
bool m_useCppDebugger;
|
2015-08-10 17:43:58 +02:00
|
|
|
QmlDebug::QmlDebugServicesPreset m_qmlDebugServices;
|
2016-04-19 16:43:30 +02:00
|
|
|
Utils::Port m_localGdbServerPort; // Local end of forwarded debug socket.
|
|
|
|
|
Utils::Port m_qmlPort;
|
2013-02-27 15:12:36 +01:00
|
|
|
QString m_pingFile;
|
|
|
|
|
QString m_pongFile;
|
|
|
|
|
QString m_gdbserverPath;
|
|
|
|
|
QString m_gdbserverSocket;
|
|
|
|
|
QString m_adb;
|
|
|
|
|
bool m_isBusyBox;
|
|
|
|
|
QStringList m_selector;
|
2012-04-18 20:30:57 +03:00
|
|
|
QMutex m_mutex;
|
2015-06-12 15:36:04 +02:00
|
|
|
QRegExp m_logCatRegExp;
|
2016-06-10 11:36:37 +03:00
|
|
|
DebugHandShakeType m_handShakeMethod = SocketHandShake;
|
2014-11-18 15:14:40 +01:00
|
|
|
QTcpSocket *m_socket;
|
|
|
|
|
bool m_customPort;
|
2012-04-18 20:30:57 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Android
|