forked from SmartisanTech/Wrench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adbvncthread.cpp
109 lines (85 loc) · 2.74 KB
/
adbvncthread.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "adbvncthread.hpp"
#include <QtCore/QProcess>
#include <QtCore/QProcessEnvironment>
#include <QtCore/QFile>
#include <QtCore/QDir>
#include <cassert>
#include <QtDebug>
#include <QtCore/QThread>
#include "bhj_help.hpp"
#include "wrench.h"
#include "wrenchext.h"
#include <QTime>
#include "adbclient.h"
AdbVncThread::AdbVncThread(QObject* parent)
: QThread(parent)
{
mAdbVncCmd = NULL;
mAdbVncCmdFinished = false;
mConnectTimer = NULL;
}
AdbVncThread::~AdbVncThread()
{
}
void AdbVncThread::onVncCmdDataReady()
{
qDebug() << mAdbVncCmd->getSock()->readAll();
emit adbVncUpdate("Online");
}
void AdbVncThread::vncCmdServerFinished()
{
mAdbVncCmdFinished = true;
}
void AdbVncThread::onDisconnected()
{
if (!mConnectTimer) {
mConnectTimer = new QTimer(this);
mConnectTimer->setSingleShot(true);
connect(mConnectTimer, SIGNAL(timeout()), this, SLOT(onDisconnected()));
}
if (!gPhoneScreenSyncOn) {
mConnectTimer->start(1000);
return;
}
// at the start, suppose the adb not connected.
QStringList args1 = QStringList() << "sh" << "-c" << "if test \"$(getprop sys.boot_completed)\" = 1; then { echo -n Lin && echo -n ux; /data/data/com.android.shell/busybox killall androidvncserver; }; fi";
QString uname = adb_quote_shell(args1);
static QString lastAdbVnc;
emit adbVncUpdate("Offline");
if (!uname.contains("Linux")) {
lastAdbVnc = "Offline";
mConnectTimer->start(1000);
return;
}
if (lastAdbVnc != "Online") {
lastAdbVnc = "Online";
}
if (!mAdbVncCmd || mAdbVncCmd && mAdbVncCmdFinished) {
if (mAdbVncCmd) {
delete mAdbVncCmd;
mAdbVncCmd = NULL;
}
WrenchExt wrenchExt;
QString vncCommand = wrenchExt.getConfig("vnc-server-command");
if (vncCommand.isEmpty()) {
vncCommand = "/data/data/com.android.shell/androidvncserver";
}
mAdbVncCmd = AdbClient::doAdbPipe(vncCommand);
mAdbVncCmdFinished = false;
connect(mAdbVncCmd->getSock(), SIGNAL(readyRead()), this, SLOT(onVncCmdDataReady()));
connect(mAdbVncCmd->getSock(), SIGNAL(readChannelFinished()), this, SLOT(vncCmdServerFinished()));
connect(mAdbVncCmd->getSock(), SIGNAL(readChannelFinished()), this, SLOT(onDisconnected()), Qt::QueuedConnection);
}
QString adb_serial = AdbClient::getAdbSerial();
if (adb_serial.isEmpty()) {
AdbClient::doAdbForward("host:forward:tcp:5901;tcp:5901");
} else {
AdbClient::doAdbForward("host-serial:" + adb_serial + ":forward:tcp:5901;tcp:5901");
}
}
void AdbVncThread::run()
{
this->moveToThread(this);
QTimer::singleShot(0, this, SLOT(onDisconnected()));
exec();
}