🐞 fix(文件传输): 修复获取剩余有效空间错误问题
This commit is contained in:
parent
36098a469d
commit
79c5b6b3b5
|
@ -22,7 +22,9 @@ const QString USER_NAME = "kylin";
|
|||
const int PASSWORD_COUNT = 10;
|
||||
const std::string CONNECTIVITY_ID_FILEPATH = getenv("HOME") + std::string("/.connectivitycache/ConnectivityId");
|
||||
|
||||
GenerateTools::GenerateTools() {}
|
||||
GenerateTools::GenerateTools()
|
||||
{
|
||||
}
|
||||
|
||||
QPixmap GenerateTools::getCode(QString info, int width, int height, bool *ok)
|
||||
{
|
||||
|
@ -46,7 +48,7 @@ QPixmap GenerateTools::getCode(QString info, int width, int height, bool *ok)
|
|||
painter.setBrush(background);
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.drawRect(0, 0, temp_width, temp_height);
|
||||
QColor foreground(Qt::black); // 二维码颜色
|
||||
QColor foreground(Qt::black); // 二维码颜色
|
||||
painter.setBrush(foreground);
|
||||
for (qint32 y = 0; y < qrcode_width; y++) {
|
||||
for (qint32 x = 0; x < qrcode_width; x++) {
|
||||
|
@ -175,22 +177,23 @@ QString GenerateTools::getCodetoIp(QString code)
|
|||
return request;
|
||||
}
|
||||
|
||||
quint64 GenerateTools::getVfsFreeSize(QString path)
|
||||
bool GenerateTools::isEnough(qint64 size)
|
||||
{
|
||||
int state = 0;
|
||||
struct statvfs vfs;
|
||||
fsblkcnt_t block_size = 0;
|
||||
fsblkcnt_t free_size = 0;
|
||||
qint64 block_size = 0;
|
||||
qint64 free_size = 0;
|
||||
|
||||
state = statvfs(path.toStdString().c_str(), &vfs);
|
||||
state = statvfs("/data", &vfs);
|
||||
if (state < 0) {
|
||||
qCritical() << "read error!";
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
block_size = vfs.f_bsize; // 块大小
|
||||
free_size = vfs.f_bfree * block_size;
|
||||
|
||||
return free_size;
|
||||
block_size = vfs.f_bsize; // 块大小
|
||||
free_size = (vfs.f_bavail * block_size) >> 10;
|
||||
|
||||
return free_size > size;
|
||||
}
|
||||
|
||||
QString GenerateTools::intSizeToString(qint64 size)
|
||||
|
|
|
@ -9,8 +9,8 @@ class GenerateTools
|
|||
{
|
||||
public:
|
||||
enum KEY_USERPASS {
|
||||
KEY_USER = 0, // 用户名
|
||||
KEY_PASSWORD // 密码
|
||||
KEY_USER = 0, // 用户名
|
||||
KEY_PASSWORD // 密码
|
||||
};
|
||||
|
||||
GenerateTools();
|
||||
|
@ -29,9 +29,9 @@ public:
|
|||
|
||||
static QString getCodetoIp(QString code);
|
||||
|
||||
static quint64 getVfsFreeSize(QString path);
|
||||
static bool isEnough(qint64 size);
|
||||
|
||||
static QString intSizeToString(qint64 size);
|
||||
};
|
||||
|
||||
#endif // GENERATEQRCODE_H
|
||||
#endif // GENERATEQRCODE_H
|
||||
|
|
|
@ -302,156 +302,157 @@ void ConnectionService::onMessageReadyRead()
|
|||
}
|
||||
|
||||
switch (reply.status()) {
|
||||
case ReplyMessage::ERROR: {
|
||||
// 错误消息
|
||||
qInfo() << "ERROR:" << QString::fromStdString(reply.error_string());
|
||||
} break;
|
||||
case ReplyMessage::CONNECTED: {
|
||||
// CONNECTED 发送设备信息
|
||||
qInfo() << "Generate device information and send it to remote host.";
|
||||
// 发送设备信息
|
||||
sendDeviceInfo();
|
||||
} break;
|
||||
case ReplyMessage::REFUSE: {
|
||||
qInfo() << "The remote host refused the connection.";
|
||||
Q_EMIT sigConnectDenied();
|
||||
deleteSocket();
|
||||
} break;
|
||||
case ReplyMessage::DISCONNECTED: {
|
||||
// DISCONNECTED 断开连接
|
||||
m_isRemoteDisconnect = true;
|
||||
qInfo() << "Remote host disconnected.";
|
||||
disconnectSocket();
|
||||
} break;
|
||||
case ReplyMessage::DEVICEINFO: {
|
||||
// DEVICEINFO 读取设备信息DeviceInfo 记录设备信息
|
||||
qInfo() << "Received device sent by remote host.";
|
||||
receiveDeviceInfo(reply);
|
||||
} break;
|
||||
case ReplyMessage::DATA: {
|
||||
// DATA 接收字节数据
|
||||
qInfo() << "Byte data transfer will be performed.";
|
||||
if (m_dataType != DataType::FREE) {
|
||||
// 正在进行其他任务
|
||||
sendBusyMessage();
|
||||
return;
|
||||
}
|
||||
m_dataType = DataType::BYTE_DATA;
|
||||
m_dataSize = reply.datasize();
|
||||
ReplyMessage replyMessage;
|
||||
replyMessage.set_status(ReplyMessage::DATAREADY);
|
||||
sendMessage(replyMessage);
|
||||
} break;
|
||||
case ReplyMessage::DATAREADY: {
|
||||
int sendRe = -1;
|
||||
if (m_dataTcpSocket != nullptr) {
|
||||
sendRe = m_dataTcpSocket->write(m_data.data(), m_dataSize);
|
||||
}
|
||||
if (sendRe == -1) {
|
||||
qInfo() << "Byte data sending failed!";
|
||||
} else {
|
||||
qInfo() << "Byte data sent successfully!";
|
||||
}
|
||||
} break;
|
||||
case ReplyMessage::FILEINFO: {
|
||||
qInfo() << "File data transfer is about to take place.";
|
||||
if (m_dataType != DataType::FREE) {
|
||||
sendBusyMessage();
|
||||
return;
|
||||
}
|
||||
m_dataType = DataType::FILE_DATA;
|
||||
// FILEINFO 接收文件信息
|
||||
m_filesInfo = reply.files_info();
|
||||
m_dataSize = 0;
|
||||
m_data.clear();
|
||||
m_currentFileIndex = 0;
|
||||
m_writeSize = 0;
|
||||
ReplyMessage replyMessage;
|
||||
// 获取所有文件大小,并且计算0kb文件数量
|
||||
int zeroFileNum = 0;
|
||||
for (int i = 0; i < m_filesInfo.file_info_size(); i++) {
|
||||
qint64 size = m_filesInfo.file_info(i).size();
|
||||
if (size == 0) {
|
||||
zeroFileNum++;
|
||||
}
|
||||
m_dataSize += size;
|
||||
}
|
||||
// 处理0kb文件
|
||||
if (zeroFileNum == m_filesInfo.file_info_size()) {
|
||||
for (int i = 0; i < m_filesInfo.file_info_size(); i++) {
|
||||
qWarning() << "An empty file was received!";
|
||||
QFile *file = new QFile(m_fileSavePath + QString::fromStdString(m_filesInfo.file_info(i).name()));
|
||||
bool openFlag = file->open(QIODevice::WriteOnly);
|
||||
if (!openFlag) {
|
||||
// 打开文件失败
|
||||
qCritical() << "Fail to open file:" + QString::fromStdString(m_filesInfo.file_info(i).name());
|
||||
delete file;
|
||||
continue;
|
||||
}
|
||||
file->write("", 0);
|
||||
file->flush();
|
||||
file->close();
|
||||
delete file;
|
||||
}
|
||||
m_dataType = DataType::FREE;
|
||||
m_filesInfo.clear_file_info();
|
||||
m_filesInfo.Clear();
|
||||
replyMessage.set_status(ReplyMessage::FILEREADY);
|
||||
sendMessage(replyMessage);
|
||||
break;
|
||||
}
|
||||
// 判断本地空间是否充足
|
||||
if (m_dataSize >= GenerateTools::getVfsFreeSize(m_fileSavePath)) {
|
||||
m_dataType = DataType::FREE;
|
||||
replyMessage.set_status(ReplyMessage::ERROR);
|
||||
replyMessage.set_error_string(QString("接收端可用存储空间不足").toStdString().c_str());
|
||||
} else {
|
||||
replyMessage.set_status(ReplyMessage::FILEREADY);
|
||||
}
|
||||
sendMessage(replyMessage);
|
||||
} break;
|
||||
case ReplyMessage::FILEREADY: {
|
||||
// FILEREADY 发送文件内容
|
||||
QByteArray arr;
|
||||
for (int i = 0; i < m_filePathList.size(); i++) {
|
||||
QFile *file = new QFile(m_filePathList.value(i));
|
||||
bool openFlag = file->open(QIODevice::ReadOnly);
|
||||
if (!openFlag) {
|
||||
// 打开文件失败
|
||||
qCritical() << m_filePathList.value(i) << " file open failed";
|
||||
delete file;
|
||||
file = nullptr;
|
||||
case ReplyMessage::ERROR: {
|
||||
// 错误消息
|
||||
qInfo() << "ERROR:" << QString::fromStdString(reply.error_string());
|
||||
} break;
|
||||
case ReplyMessage::CONNECTED: {
|
||||
// CONNECTED 发送设备信息
|
||||
qInfo() << "Generate device information and send it to remote host.";
|
||||
// 发送设备信息
|
||||
sendDeviceInfo();
|
||||
} break;
|
||||
case ReplyMessage::REFUSE: {
|
||||
qInfo() << "The remote host refused the connection.";
|
||||
Q_EMIT sigConnectDenied();
|
||||
deleteSocket();
|
||||
} break;
|
||||
case ReplyMessage::DISCONNECTED: {
|
||||
// DISCONNECTED 断开连接
|
||||
m_isRemoteDisconnect = true;
|
||||
qInfo() << "Remote host disconnected.";
|
||||
disconnectSocket();
|
||||
} break;
|
||||
case ReplyMessage::DEVICEINFO: {
|
||||
// DEVICEINFO 读取设备信息DeviceInfo 记录设备信息
|
||||
qInfo() << "Received device sent by remote host.";
|
||||
receiveDeviceInfo(reply);
|
||||
} break;
|
||||
case ReplyMessage::DATA: {
|
||||
// DATA 接收字节数据
|
||||
qInfo() << "Byte data transfer will be performed.";
|
||||
if (m_dataType != DataType::FREE) {
|
||||
// 正在进行其他任务
|
||||
sendBusyMessage();
|
||||
return;
|
||||
}
|
||||
arr.append(file->readAll());
|
||||
}
|
||||
int sendRe = -1;
|
||||
if (m_dataTcpSocket != nullptr) {
|
||||
sendRe = m_dataTcpSocket->write(arr.data(), arr.size());
|
||||
}
|
||||
if (sendRe == -1) {
|
||||
qInfo() << "File content sending failed!";
|
||||
} else {
|
||||
qInfo() << "File content sent successfully!";
|
||||
}
|
||||
} break;
|
||||
case ReplyMessage::STREAM: {
|
||||
qInfo() << "Streaming data will be transmitted.";
|
||||
if (m_dataType != DataType::FREE) {
|
||||
sendBusyMessage();
|
||||
return;
|
||||
}
|
||||
m_dataType = DataType::STREAM_DATA;
|
||||
// STREAM 准备接受流数据
|
||||
m_dataType = DataType::BYTE_DATA;
|
||||
m_dataSize = reply.datasize();
|
||||
ReplyMessage replyMessage;
|
||||
replyMessage.set_status(ReplyMessage::DATAREADY);
|
||||
sendMessage(replyMessage);
|
||||
} break;
|
||||
case ReplyMessage::DATAREADY: {
|
||||
int sendRe = -1;
|
||||
if (m_dataTcpSocket != nullptr) {
|
||||
sendRe = m_dataTcpSocket->write(m_data.data(), m_dataSize);
|
||||
}
|
||||
if (sendRe == -1) {
|
||||
qInfo() << "Byte data sending failed!";
|
||||
} else {
|
||||
qInfo() << "Byte data sent successfully!";
|
||||
}
|
||||
} break;
|
||||
case ReplyMessage::FILEINFO: {
|
||||
qInfo() << "File data transfer is about to take place.";
|
||||
if (m_dataType != DataType::FREE) {
|
||||
sendBusyMessage();
|
||||
return;
|
||||
}
|
||||
m_dataType = DataType::FILE_DATA;
|
||||
// FILEINFO 接收文件信息
|
||||
m_filesInfo = reply.files_info();
|
||||
m_dataSize = 0;
|
||||
m_data.clear();
|
||||
m_currentFileIndex = 0;
|
||||
m_writeSize = 0;
|
||||
ReplyMessage replyMessage;
|
||||
// 获取所有文件大小,并且计算0kb文件数量
|
||||
int zeroFileNum = 0;
|
||||
for (int i = 0; i < m_filesInfo.file_info_size(); i++) {
|
||||
qint64 size = m_filesInfo.file_info(i).size();
|
||||
if (size == 0) {
|
||||
zeroFileNum++;
|
||||
}
|
||||
m_dataSize += size;
|
||||
}
|
||||
// 处理0kb文件
|
||||
if (zeroFileNum == m_filesInfo.file_info_size()) {
|
||||
for (int i = 0; i < m_filesInfo.file_info_size(); i++) {
|
||||
qWarning() << "An empty file was received!";
|
||||
QFile *file = new QFile(m_fileSavePath + QString::fromStdString(m_filesInfo.file_info(i).name()));
|
||||
bool openFlag = file->open(QIODevice::WriteOnly);
|
||||
if (!openFlag) {
|
||||
// 打开文件失败
|
||||
qCritical() << "Fail to open file:" + QString::fromStdString(m_filesInfo.file_info(i).name());
|
||||
delete file;
|
||||
continue;
|
||||
}
|
||||
file->write("", 0);
|
||||
file->flush();
|
||||
file->close();
|
||||
delete file;
|
||||
}
|
||||
m_dataType = DataType::FREE;
|
||||
m_filesInfo.clear_file_info();
|
||||
m_filesInfo.Clear();
|
||||
replyMessage.set_status(ReplyMessage::FILEREADY);
|
||||
sendMessage(replyMessage);
|
||||
break;
|
||||
}
|
||||
// 判断本地空间是否充足
|
||||
if (!GenerateTools::isEnough(m_dataSize)) {
|
||||
qInfo() << "Insufficient valid local space!";
|
||||
m_dataType = DataType::FREE;
|
||||
replyMessage.set_status(ReplyMessage::ERROR);
|
||||
replyMessage.set_error_string(QString("接收端可用存储空间不足").toStdString().c_str());
|
||||
} else {
|
||||
replyMessage.set_status(ReplyMessage::FILEREADY);
|
||||
}
|
||||
sendMessage(replyMessage);
|
||||
} break;
|
||||
case ReplyMessage::FILEREADY: {
|
||||
// FILEREADY 发送文件内容
|
||||
QByteArray arr;
|
||||
for (int i = 0; i < m_filePathList.size(); i++) {
|
||||
QFile *file = new QFile(m_filePathList.value(i));
|
||||
bool openFlag = file->open(QIODevice::ReadOnly);
|
||||
if (!openFlag) {
|
||||
// 打开文件失败
|
||||
qCritical() << m_filePathList.value(i) << " file open failed";
|
||||
delete file;
|
||||
file = nullptr;
|
||||
return;
|
||||
}
|
||||
arr.append(file->readAll());
|
||||
}
|
||||
int sendRe = -1;
|
||||
if (m_dataTcpSocket != nullptr) {
|
||||
sendRe = m_dataTcpSocket->write(arr.data(), arr.size());
|
||||
}
|
||||
if (sendRe == -1) {
|
||||
qInfo() << "File content sending failed!";
|
||||
} else {
|
||||
qInfo() << "File content sent successfully!";
|
||||
}
|
||||
} break;
|
||||
case ReplyMessage::STREAM: {
|
||||
qInfo() << "Streaming data will be transmitted.";
|
||||
if (m_dataType != DataType::FREE) {
|
||||
sendBusyMessage();
|
||||
return;
|
||||
}
|
||||
m_dataType = DataType::STREAM_DATA;
|
||||
// STREAM 准备接受流数据
|
||||
|
||||
} break;
|
||||
case ReplyMessage::STREAMREADY: {
|
||||
// STREAMREADY 发送流数据
|
||||
} break;
|
||||
case ReplyMessage::BUSY: {
|
||||
qInfo() << "The remote host is busy.";
|
||||
// BUSY 繁忙处理
|
||||
} break;
|
||||
} break;
|
||||
case ReplyMessage::STREAMREADY: {
|
||||
// STREAMREADY 发送流数据
|
||||
} break;
|
||||
case ReplyMessage::BUSY: {
|
||||
qInfo() << "The remote host is busy.";
|
||||
// BUSY 繁忙处理
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -468,44 +469,44 @@ void ConnectionService::onDataReadyRead()
|
|||
memset(buf, '\0', sizeof(buf));
|
||||
}
|
||||
switch (m_dataType) {
|
||||
case DataType::BYTE_DATA: {
|
||||
if (m_data.size() >= m_dataSize) {
|
||||
qInfo() << "Byte data transmission finish!";
|
||||
Q_EMIT sigByteReceived(QString(m_data));
|
||||
m_data.clear();
|
||||
m_dataType = DataType::FREE;
|
||||
}
|
||||
} break;
|
||||
case DataType::FILE_DATA: {
|
||||
if (m_writeFile == nullptr) {
|
||||
openWriteFile();
|
||||
}
|
||||
if (m_writeSize < m_filesInfo.file_info(m_currentFileIndex).size()) {
|
||||
if (m_data.size() <= (m_filesInfo.file_info(m_currentFileIndex).size() - m_writeSize)) {
|
||||
m_writeFile->write(m_data.data(), m_data.size());
|
||||
m_writeSize += m_data.size();
|
||||
case DataType::BYTE_DATA: {
|
||||
if (m_data.size() >= m_dataSize) {
|
||||
qInfo() << "Byte data transmission finish!";
|
||||
Q_EMIT sigByteReceived(QString(m_data));
|
||||
m_data.clear();
|
||||
} else {
|
||||
while (m_data.size() >= (m_filesInfo.file_info(m_currentFileIndex).size() - m_writeSize)) {
|
||||
// 切割单个文件数据
|
||||
int index = m_filesInfo.file_info(m_currentFileIndex).size() - m_writeSize;
|
||||
QByteArray fileDate = m_data.mid(0, index);
|
||||
m_writeFile->write(fileDate.data(), fileDate.size());
|
||||
m_writeSize += fileDate.size();
|
||||
m_data = m_data.mid(index, m_data.size() - index);
|
||||
if (m_writeSize == m_filesInfo.file_info(m_currentFileIndex).size()) {
|
||||
endFile();
|
||||
m_dataType = DataType::FREE;
|
||||
}
|
||||
} break;
|
||||
case DataType::FILE_DATA: {
|
||||
if (m_writeFile == nullptr) {
|
||||
openWriteFile();
|
||||
}
|
||||
if (m_writeSize < m_filesInfo.file_info(m_currentFileIndex).size()) {
|
||||
if (m_data.size() <= (m_filesInfo.file_info(m_currentFileIndex).size() - m_writeSize)) {
|
||||
m_writeFile->write(m_data.data(), m_data.size());
|
||||
m_writeSize += m_data.size();
|
||||
m_data.clear();
|
||||
} else {
|
||||
while (m_data.size() >= (m_filesInfo.file_info(m_currentFileIndex).size() - m_writeSize)) {
|
||||
// 切割单个文件数据
|
||||
int index = m_filesInfo.file_info(m_currentFileIndex).size() - m_writeSize;
|
||||
QByteArray fileDate = m_data.mid(0, index);
|
||||
m_writeFile->write(fileDate.data(), fileDate.size());
|
||||
m_writeSize += fileDate.size();
|
||||
m_data = m_data.mid(index, m_data.size() - index);
|
||||
if (m_writeSize == m_filesInfo.file_info(m_currentFileIndex).size()) {
|
||||
endFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_writeSize == m_filesInfo.file_info(m_currentFileIndex).size()) {
|
||||
endFile();
|
||||
}
|
||||
} break;
|
||||
case DataType::STREAM_DATA: {
|
||||
} break;
|
||||
if (m_writeSize == m_filesInfo.file_info(m_currentFileIndex).size()) {
|
||||
endFile();
|
||||
}
|
||||
} break;
|
||||
case DataType::STREAM_DATA: {
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -545,7 +546,7 @@ void ConnectionService::onHeartbeatReadyRead()
|
|||
// 当前为服务端端,收到客户端心跳回复,重置标志位
|
||||
#ifdef NDEBUG
|
||||
qDebug() << "receive heartbeat<<<<<<<<<<<<<<<<<<<<<<<<<<<";
|
||||
#endif // !NDEBUG
|
||||
#endif // !NDEBUG
|
||||
m_isAgainSendHeartbeat = true;
|
||||
m_isSurvival = true;
|
||||
}
|
||||
|
@ -576,116 +577,117 @@ void ConnectionService::onAdbExec(AdbProcess::ADB_EXEC_RESULT processResult)
|
|||
QStringList args = m_adb->arguments();
|
||||
|
||||
switch (processResult) {
|
||||
case AdbProcess::AER_ERROR_START: {
|
||||
qWarning() << "adb run error";
|
||||
handleWifiConnection();
|
||||
break;
|
||||
}
|
||||
case AdbProcess::AER_SUCCESS_START: {
|
||||
break;
|
||||
}
|
||||
case AdbProcess::AER_ERROR_EXEC: {
|
||||
qWarning() << "adb exec error";
|
||||
handleWifiConnection();
|
||||
if (args.contains("com.kylin.mobileassistant")) {
|
||||
qWarning() << "Not Found Apk";
|
||||
Q_EMIT sigNotFountApk();
|
||||
case AdbProcess::AER_ERROR_START: {
|
||||
qWarning() << "adb run error";
|
||||
handleWifiConnection();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case AdbProcess::AER_ERROR_MISSING_BINARY: {
|
||||
qInfo() << "adb not find";
|
||||
handleWifiConnection();
|
||||
break;
|
||||
}
|
||||
case AdbProcess::AER_SUCCESS_EXEC: {
|
||||
if (args.contains("devices")) {
|
||||
// 当前执行为updatedevices
|
||||
qInfo() << "adb devices";
|
||||
// 获取设备列表
|
||||
QStringList devices = m_adb->getDevicesSerialFromStdOut();
|
||||
m_deviceSerialList.clear();
|
||||
for (auto &item : devices) {
|
||||
m_deviceSerialList.append(item);
|
||||
}
|
||||
// 多个adb设备
|
||||
if (m_deviceSerialList.size() > 1) {
|
||||
qInfo() << "There are currently multiple wired devices!";
|
||||
if (m_messageTcpSocket != nullptr) {
|
||||
// 已存在连接,说明为WiFi连接
|
||||
qInfo() << "Currently, there are multiple wired devices, and WiFi anti control is not supported "
|
||||
"temporarily!";
|
||||
m_androidConnType = AndroidConnType::CONNECTWIFI;
|
||||
handleConnected();
|
||||
} else {
|
||||
// 不存在连接,当前有多个adb设备连接,暂时不处理
|
||||
Q_EMIT sigDeviceRedundancy();
|
||||
}
|
||||
case AdbProcess::AER_SUCCESS_START: {
|
||||
break;
|
||||
}
|
||||
case AdbProcess::AER_ERROR_EXEC: {
|
||||
qWarning() << "adb exec error";
|
||||
handleWifiConnection();
|
||||
if (args.contains("com.kylin.mobileassistant")) {
|
||||
qWarning() << "Not Found Apk";
|
||||
Q_EMIT sigNotFountApk();
|
||||
break;
|
||||
}
|
||||
if (!m_deviceSerialList.isEmpty()) {
|
||||
if (m_messageTcpSocket != nullptr) {
|
||||
// 当前为无线连接
|
||||
// 判断当前有线设备和扫码设备是否是同一设备 uuid是否一致
|
||||
if (isSameDevice(m_deviceSerialList.at(0))) {
|
||||
// 同一设备
|
||||
m_isSupportADB = true;
|
||||
m_androidConnType = AndroidConnType::WIFIADB;
|
||||
} else {
|
||||
m_isSupportADB = false;
|
||||
break;
|
||||
}
|
||||
case AdbProcess::AER_ERROR_MISSING_BINARY: {
|
||||
qInfo() << "adb not find";
|
||||
handleWifiConnection();
|
||||
break;
|
||||
}
|
||||
case AdbProcess::AER_SUCCESS_EXEC: {
|
||||
if (args.contains("devices")) {
|
||||
// 当前执行为updatedevices
|
||||
qInfo() << "adb devices";
|
||||
// 获取设备列表
|
||||
QStringList devices = m_adb->getDevicesSerialFromStdOut();
|
||||
m_deviceSerialList.clear();
|
||||
for (auto &item : devices) {
|
||||
m_deviceSerialList.append(item);
|
||||
}
|
||||
// 多个adb设备
|
||||
if (m_deviceSerialList.size() > 1) {
|
||||
qInfo() << "There are currently multiple wired devices!";
|
||||
if (m_messageTcpSocket != nullptr) {
|
||||
// 已存在连接,说明为WiFi连接
|
||||
qInfo()
|
||||
<< "Currently, there are multiple wired devices, and WiFi anti control is not supported "
|
||||
"temporarily!";
|
||||
m_androidConnType = AndroidConnType::CONNECTWIFI;
|
||||
handleConnected();
|
||||
} else {
|
||||
// 不存在连接,当前有多个adb设备连接,暂时不处理
|
||||
Q_EMIT sigDeviceRedundancy();
|
||||
}
|
||||
handleConnected();
|
||||
} else {
|
||||
// 当前为有线设备连接
|
||||
m_connectInfo.connectType = ConnectType::USB;
|
||||
m_isSupportADB = true;
|
||||
m_adb->reverse(m_deviceSerialList.at(0), SOCKET_NAME, LISTEN_PORT);
|
||||
GenerateTools::delayMs(500);
|
||||
m_adb->reverse(m_deviceSerialList.at(0), FTPSERVERPORT, FTPSERVERPORT);
|
||||
GenerateTools::delayMs(500);
|
||||
checkApk(m_deviceSerialList.at(0));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// 当前没有usb连接
|
||||
if (m_messageTcpSocket != nullptr) {
|
||||
// 当前为无线连接
|
||||
handleWifiConnection();
|
||||
if (!m_deviceSerialList.isEmpty()) {
|
||||
if (m_messageTcpSocket != nullptr) {
|
||||
// 当前为无线连接
|
||||
// 判断当前有线设备和扫码设备是否是同一设备 uuid是否一致
|
||||
if (isSameDevice(m_deviceSerialList.at(0))) {
|
||||
// 同一设备
|
||||
m_isSupportADB = true;
|
||||
m_androidConnType = AndroidConnType::WIFIADB;
|
||||
} else {
|
||||
m_isSupportADB = false;
|
||||
m_androidConnType = AndroidConnType::CONNECTWIFI;
|
||||
}
|
||||
handleConnected();
|
||||
} else {
|
||||
// 当前为有线设备连接
|
||||
m_connectInfo.connectType = ConnectType::USB;
|
||||
m_isSupportADB = true;
|
||||
m_adb->reverse(m_deviceSerialList.at(0), SOCKET_NAME, LISTEN_PORT);
|
||||
GenerateTools::delayMs(500);
|
||||
m_adb->reverse(m_deviceSerialList.at(0), FTPSERVERPORT, FTPSERVERPORT);
|
||||
GenerateTools::delayMs(500);
|
||||
checkApk(m_deviceSerialList.at(0));
|
||||
}
|
||||
} else {
|
||||
// 当前没有设备连接
|
||||
qInfo() << "There are currently no wired devices!";
|
||||
Q_EMIT sigNoUsbDevice();
|
||||
// 当前没有usb连接
|
||||
if (m_messageTcpSocket != nullptr) {
|
||||
// 当前为无线连接
|
||||
handleWifiConnection();
|
||||
} else {
|
||||
// 当前没有设备连接
|
||||
qInfo() << "There are currently no wired devices!";
|
||||
Q_EMIT sigNoUsbDevice();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (args.contains("com.kylin.mobileassistant")) {
|
||||
// 当前为调起pp命令
|
||||
QString checkApkOut = m_adb->getStdOut();
|
||||
if (!checkApkOut.isEmpty()) {
|
||||
setMapPort();
|
||||
startApp(m_deviceSerialList.at(0));
|
||||
}
|
||||
}
|
||||
if (args.contains("connect")) {
|
||||
// 当前为adbconnect命令
|
||||
QString connectResult = m_adb->getStdOut();
|
||||
QString testResult = "connected to " + m_connectInfo.address + ":5555";
|
||||
if (connectResult.contains(testResult)) {
|
||||
updateDevice();
|
||||
} else {
|
||||
// 当前没有usb连接
|
||||
if (m_messageTcpSocket != nullptr) {
|
||||
// 当前为无线连接
|
||||
handleWifiConnection();
|
||||
} else {
|
||||
// 当前没有设备连接
|
||||
qInfo() << "There are currently no wired devices!";
|
||||
if (args.contains("com.kylin.mobileassistant")) {
|
||||
// 当前为调起pp命令
|
||||
QString checkApkOut = m_adb->getStdOut();
|
||||
if (!checkApkOut.isEmpty()) {
|
||||
setMapPort();
|
||||
startApp(m_deviceSerialList.at(0));
|
||||
}
|
||||
}
|
||||
if (args.contains("connect")) {
|
||||
// 当前为adbconnect命令
|
||||
QString connectResult = m_adb->getStdOut();
|
||||
QString testResult = "connected to " + m_connectInfo.address + ":5555";
|
||||
if (connectResult.contains(testResult)) {
|
||||
updateDevice();
|
||||
} else {
|
||||
// 当前没有usb连接
|
||||
if (m_messageTcpSocket != nullptr) {
|
||||
// 当前为无线连接
|
||||
handleWifiConnection();
|
||||
} else {
|
||||
// 当前没有设备连接
|
||||
qInfo() << "There are currently no wired devices!";
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -793,7 +795,6 @@ void ConnectionService::openWriteFile()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void ConnectionService::endFile()
|
||||
{
|
||||
m_currentFileIndex++;
|
||||
|
@ -821,15 +822,15 @@ bool ConnectionService::sendStartAudioMessage()
|
|||
ReplyMessage replyMessage;
|
||||
replyMessage.set_status(ReplyMessage::STARTAUDIOSERVER);
|
||||
switch (m_androidConnType) {
|
||||
case AndroidConnType::ADB:
|
||||
replyMessage.set_conn_type(ReplyMessage::ADB);
|
||||
break;
|
||||
case AndroidConnType::CONNECTWIFI:
|
||||
replyMessage.set_conn_type(ReplyMessage::WIFI);
|
||||
break;
|
||||
case AndroidConnType::WIFIADB:
|
||||
replyMessage.set_conn_type(ReplyMessage::WIFIADB);
|
||||
break;
|
||||
case AndroidConnType::ADB:
|
||||
replyMessage.set_conn_type(ReplyMessage::ADB);
|
||||
break;
|
||||
case AndroidConnType::CONNECTWIFI:
|
||||
replyMessage.set_conn_type(ReplyMessage::WIFI);
|
||||
break;
|
||||
case AndroidConnType::WIFIADB:
|
||||
replyMessage.set_conn_type(ReplyMessage::WIFIADB);
|
||||
break;
|
||||
}
|
||||
bool sendRe = sendMessage(replyMessage);
|
||||
return sendRe;
|
||||
|
@ -840,19 +841,19 @@ void ConnectionService::sendDeviceInfo()
|
|||
ReplyMessage replyMessage;
|
||||
replyMessage.set_status(ReplyMessage::DEVICEINFO);
|
||||
switch (m_androidConnType) {
|
||||
case AndroidConnType::ADB:
|
||||
replyMessage.set_conn_type(ReplyMessage::ADB);
|
||||
break;
|
||||
case AndroidConnType::CONNECTWIFI:
|
||||
replyMessage.set_conn_type(ReplyMessage::WIFI);
|
||||
break;
|
||||
case AndroidConnType::WIFIADB:
|
||||
replyMessage.set_conn_type(ReplyMessage::WIFIADB);
|
||||
break;
|
||||
case AndroidConnType::NOTANDROID:
|
||||
// 不是安卓设备默认为WIFI连接
|
||||
replyMessage.set_conn_type(ReplyMessage::WIFI);
|
||||
break;
|
||||
case AndroidConnType::ADB:
|
||||
replyMessage.set_conn_type(ReplyMessage::ADB);
|
||||
break;
|
||||
case AndroidConnType::CONNECTWIFI:
|
||||
replyMessage.set_conn_type(ReplyMessage::WIFI);
|
||||
break;
|
||||
case AndroidConnType::WIFIADB:
|
||||
replyMessage.set_conn_type(ReplyMessage::WIFIADB);
|
||||
break;
|
||||
case AndroidConnType::NOTANDROID:
|
||||
// 不是安卓设备默认为WIFI连接
|
||||
replyMessage.set_conn_type(ReplyMessage::WIFI);
|
||||
break;
|
||||
}
|
||||
DeviceInfo *deviceInfo = replyMessage.mutable_device_info();
|
||||
deviceInfo->set_uuid(GenerateTools::getUuid());
|
||||
|
@ -879,24 +880,24 @@ void ConnectionService::receiveDeviceInfo(const ReplyMessage &reply)
|
|||
m_connectInfo.usernamePwd.username = QString::fromStdString(userpwd.username());
|
||||
m_connectInfo.usernamePwd.pwd = QString::fromStdString(userpwd.pwd());
|
||||
switch (deviceInfo.device_role()) {
|
||||
case DeviceInfo::INITIATOR:
|
||||
m_connectInfo.deviceRole = DeviceRole::INITIATOR;
|
||||
break;
|
||||
case DeviceInfo::RECIPIENT:
|
||||
m_connectInfo.deviceRole = DeviceRole::RECIPIENT;
|
||||
break;
|
||||
case DeviceInfo::INITIATOR:
|
||||
m_connectInfo.deviceRole = DeviceRole::INITIATOR;
|
||||
break;
|
||||
case DeviceInfo::RECIPIENT:
|
||||
m_connectInfo.deviceRole = DeviceRole::RECIPIENT;
|
||||
break;
|
||||
}
|
||||
switch (deviceInfo.device_type()) {
|
||||
case DeviceInfo::PC:
|
||||
m_connectInfo.deviceType = DeviceType::PC;
|
||||
break;
|
||||
case DeviceInfo::ANDROID:
|
||||
m_connectInfo.deviceType = DeviceType::ANDROID;
|
||||
break;
|
||||
default:
|
||||
qWarning() << "";
|
||||
m_connectInfo.deviceType = DeviceType::UNKNOWN;
|
||||
break;
|
||||
case DeviceInfo::PC:
|
||||
m_connectInfo.deviceType = DeviceType::PC;
|
||||
break;
|
||||
case DeviceInfo::ANDROID:
|
||||
m_connectInfo.deviceType = DeviceType::ANDROID;
|
||||
break;
|
||||
default:
|
||||
qWarning() << "";
|
||||
m_connectInfo.deviceType = DeviceType::UNKNOWN;
|
||||
break;
|
||||
}
|
||||
if (!m_isClient) {
|
||||
// 服务端, 收到客户端请求,发送信号,让使用者验证
|
||||
|
@ -961,13 +962,13 @@ void ConnectionService::sendHeartbeat(bool isServer)
|
|||
if (isServer) {
|
||||
#ifdef NDEBUG
|
||||
qDebug() << "URGENTSERVER>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
|
||||
#endif // !NDEBUG
|
||||
#endif // !NDEBUG
|
||||
replyMessage.set_status(ReplyMessage::URGENTSERVER);
|
||||
replyMessage.SerializeToString(&str);
|
||||
} else {
|
||||
#ifdef NDEBUG
|
||||
qDebug() << "URGENTCLIENT>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
|
||||
#endif // !NDEBUG
|
||||
#endif // !NDEBUG
|
||||
replyMessage.set_status(ReplyMessage::URGENTCLIENT);
|
||||
replyMessage.SerializeToString(&str);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue