-
Notifications
You must be signed in to change notification settings - Fork 1
/
AdbWrapper.cpp
100 lines (83 loc) · 2.64 KB
/
AdbWrapper.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
#include "AdbWrapper.h"
#include <QProcess>
#include <QDebug>
#include <QApplication>
AdbWrapper::AdbWrapper(QObject *parent) :
QObject(parent)
{
m_adbProgram = QApplication::applicationDirPath() + "/adb";
}
void AdbWrapper::resetAdb()
{
QStringList arguments;
arguments << "kill-server";
QProcess *myProcess = new QProcess(this);
myProcess->start(m_adbProgram, arguments);
myProcess->waitForFinished();
delete myProcess;
arguments.clear();
arguments << "start-server";
myProcess = new QProcess(this);
myProcess->start(m_adbProgram, arguments);
myProcess->waitForFinished();
delete myProcess;
}
QStringList AdbWrapper::deviceList()
{
QStringList arguments;
arguments << "devices" << "-l";
QProcess *myProcess = new QProcess(this);
myProcess->start(m_adbProgram, arguments);
QStringList deviceList;
if( myProcess->waitForFinished() )
{
QString res = myProcess->readAll();
QString listStart = QString( "List of devices attached\r\n" );
//qDebug() << res;
QString listString = res.right( res.size() - listStart.size() - res.indexOf( listStart ) );
//ui->textEdit->setText( listString );
while( listString.right(1) == "\n" || listString.right(1) == "\r" ) listString.chop( 1 );
if( !listString.isEmpty() ) deviceList = listString.split( "\r\n" );
//qDebug() << deviceList << deviceList.size();
}
delete myProcess;
return deviceList;
}
QStringList AdbWrapper::trackList(QString deviceId)
{
QStringList trackList;
QStringList arguments;
arguments << "-s" << deviceId << "shell" << "ls" << "/sdcard/exports";
QProcess *myProcess = new QProcess(this);
myProcess->start(m_adbProgram, arguments);
if( !myProcess->waitForFinished() )
{
delete myProcess;
return trackList;
}
QString res = myProcess->readAll();
delete myProcess;
while( res.right(1) == "\n" || res.right(1) == "\r" ) res.chop( 1 );
if( !res.isEmpty() )
{
if( res.indexOf( "\r\n" ) >= 0 ) trackList = res.split( "\r\n" );
else trackList = res.split( "\n" );
}
//qDebug() << trackList.size() << trackList;
return trackList;
}
bool AdbWrapper::downloadTrack(QString deviceId, QString name, QString dst)
{
QStringList arguments;
arguments<< "-s" << deviceId << "pull" << "/sdcard/exports/" + name << dst;
//qDebug() << arguments;
QProcess *myProcess = new QProcess(this);
myProcess->start(m_adbProgram, arguments);
if( !myProcess->waitForFinished() )
{
delete myProcess;
return false;
}
delete myProcess;
return true;
}