🐞 fix(Ftp): USB连接时需要处理端口
USB连接时需要使用adb将ftp监听的端口以及被动模式随机分配的端口进行映射
This commit is contained in:
parent
a918f47a99
commit
4ae1fa64d7
|
@ -173,6 +173,15 @@ void AdbProcess::reverse(const QString &serial, const QString &deviceSocketName,
|
|||
execute(serial, adbArgs);
|
||||
}
|
||||
|
||||
void AdbProcess::reverse(const QString &serial, quint16 localPort, quint16 phonePort)
|
||||
{
|
||||
QStringList adbArgs;
|
||||
adbArgs << "reverse";
|
||||
adbArgs << QString("tcp:%1").arg(localPort);
|
||||
adbArgs << QString("tcp:%1").arg(phonePort);
|
||||
execute(serial, adbArgs);
|
||||
}
|
||||
|
||||
void AdbProcess::reverseRemove(const QString &serial, const QString &deviceSocketName)
|
||||
{
|
||||
QStringList adbArgs;
|
||||
|
|
|
@ -30,6 +30,8 @@ public:
|
|||
|
||||
void reverse(const QString &serial, const QString &deviceSocketName, quint16 localPort);
|
||||
|
||||
void reverse(const QString &serial, quint16 localPort, quint16 phonePort);
|
||||
|
||||
void reverseRemove(const QString &serial, const QString &deviceSocketName);
|
||||
|
||||
void push(const QString &serial, const QString &local, const QString &remote);
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
const QString SOCKET_NAME = "KYLIN";
|
||||
const int LISTEN_PORT = 27188;
|
||||
const int FTPPORT = 27184;
|
||||
const int FTPSERVERPORT = 27189;
|
||||
const int FORWARD_PORT = 2300;
|
||||
const int FORWARD_PORT1 = 2301;
|
||||
const int HEARTBEAT_PORT = 27181;
|
||||
|
@ -20,6 +21,7 @@ const int HEART_RATE = 10000;
|
|||
const QString FILE_SAVE_PATH = getenv("HOME") + QString("/下载/");
|
||||
const QString UUID_FILE_LOACLPATH = getenv("HOME") + QString("/.connectivitycache/UUID");
|
||||
const QString UUID_FILE_REMOTEPATH = QString("/storage/emulated/0/Android/data/com.kylin.mobileassistant/cache/UUID");
|
||||
const QString DEVICEID_FILE_LOACLPATH = getenv("HOME") + QString("/.connectivitycache/DeviceId");
|
||||
|
||||
ConnectionService::ConnectionService(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
@ -105,6 +107,13 @@ void ConnectionService::setConnectionRespond(bool isAgree)
|
|||
// 当前为wifi连接,尝试连接adb
|
||||
m_adb->connectAdbd(m_connectInfo.address);
|
||||
} else {
|
||||
if (m_connectInfo.connectType == ConnectType::USB) {
|
||||
QFile file(DEVICEID_FILE_LOACLPATH);
|
||||
//打开文件,不存在则创建
|
||||
file.open(QIODevice::ReadWrite | QIODevice::Text);
|
||||
file.write(m_deviceSerialList.value(0).toUtf8());
|
||||
file.close();
|
||||
}
|
||||
m_androidConnType = AndroidConnType::ADB;
|
||||
sendDeviceInfo();
|
||||
Q_EMIT sigConnectInfo(m_connectInfo);
|
||||
|
@ -648,6 +657,8 @@ void ConnectionService::onAdbExec(AdbProcess::ADB_EXEC_RESULT processResult)
|
|||
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 {
|
||||
|
@ -863,7 +874,7 @@ void ConnectionService::receiveDeviceInfo(const ReplyMessage &reply)
|
|||
}
|
||||
if (!m_isClient) {
|
||||
// 服务端, 收到客户端请求,发送信号,让使用者验证
|
||||
Q_EMIT sigConnectRequest(m_connectInfo.deviceName, m_connectInfo.deviceType);
|
||||
Q_EMIT sigConnectRequest(m_connectInfo.deviceName);
|
||||
} else {
|
||||
connectDataSocket();
|
||||
// 客户端, 服务端同意请求,通知使用者
|
||||
|
@ -977,6 +988,9 @@ void ConnectionService::clearConnectionInfo()
|
|||
m_connectInfo.connectType = ConnectType::NOTCONNECT;
|
||||
m_connectInfo.usernamePwd.username.clear();
|
||||
m_connectInfo.usernamePwd.pwd.clear();
|
||||
if (QFileInfo().exists(DEVICEID_FILE_LOACLPATH)) {
|
||||
QFile::remove(DEVICEID_FILE_LOACLPATH);
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionService::updateDevice()
|
||||
|
|
|
@ -91,7 +91,7 @@ public:
|
|||
};
|
||||
|
||||
Q_SIGNALS:
|
||||
void sigConnectRequest(QString, ConnectionService::DeviceType);
|
||||
void sigConnectRequest(QString);
|
||||
void sigConnectDenied();
|
||||
void sigConnectInfo(const ConnectionInfo &);
|
||||
void sigDisconnect();
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
namespace fineftp
|
||||
{
|
||||
|
||||
const std::string DEVICEID_FILE_LOACLPATH = getenv("HOME") + std::string("/.connectivitycache/DeviceId");
|
||||
|
||||
FtpSession::FtpSession(asio::io_service &io_service, const UserDatabase &user_database,
|
||||
const std::function<void()> &completion_handler)
|
||||
: completion_handler_(completion_handler), user_database_(user_database), io_service_(io_service),
|
||||
|
@ -351,11 +353,26 @@ void FtpSession::handleFtpCommandPASV(const std::string & /*param*/)
|
|||
for (size_t i = 0; i < 4; i++) {
|
||||
stream << static_cast<int>(ip_bytes[i]) << ",";
|
||||
}
|
||||
stream << ((port >> 8) & 0xff) << "," << (port & 0xff) << ")";
|
||||
std::ifstream file;
|
||||
|
||||
file.open(DEVICEID_FILE_LOACLPATH, std::ios_base::in);
|
||||
|
||||
if (file.is_open()) {
|
||||
std::string deviceId;
|
||||
getline(file, deviceId);
|
||||
std::cout << deviceId << std::endl;
|
||||
if (!deviceId.empty()) {
|
||||
std::string common = std::string("adb -s ") + deviceId + std::string(" reverse tcp:") + std::to_string(port)
|
||||
+ std::string(" tcp:") + std::to_string(port);
|
||||
std::cout << common << std::endl;
|
||||
system(common.c_str());
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
|
||||
sendFtpMessage(FtpReplyCode::ENTERING_PASSIVE_MODE, "Entering passive mode " + stream.str());
|
||||
return;
|
||||
}
|
||||
} // namespace fineftp
|
||||
|
||||
void FtpSession::handleFtpCommandTYPE(const std::string ¶m)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue