mirror of
https://github.com/iDescriptor/iDescriptor.git
synced 2026-06-21 19:35:49 +08:00
feat: enhance device management
This commit is contained in:
+33
-48
@@ -48,9 +48,10 @@ void AppContext::cachePairedDevices()
|
||||
{
|
||||
|
||||
/*
|
||||
does not work on macOS because we cannot read /var/db/lockdown without root perm
|
||||
does not work on macOS because we cannot read /var/db/lockdown without root
|
||||
perm
|
||||
*/
|
||||
#ifndef __APPLE__
|
||||
#ifndef __APPLE__
|
||||
QDir lockdowndir(LOCKDOWN_PATH);
|
||||
if (!lockdowndir.exists()) {
|
||||
return;
|
||||
@@ -176,7 +177,8 @@ void AppContext::cachePairedDevices()
|
||||
|
||||
void AppContext::addDevice(QString udid,
|
||||
DeviceMonitorThread::IdeviceConnectionType conn_type,
|
||||
AddType addType, QString wifiMacAddress)
|
||||
AddType addType, QString wifiMacAddress,
|
||||
QString ipAddress)
|
||||
{
|
||||
|
||||
try {
|
||||
@@ -184,73 +186,43 @@ void AppContext::addDevice(QString udid,
|
||||
auto initResult = std::make_shared<iDescriptorInitDeviceResult>();
|
||||
QFuture<void> future = QtConcurrent::run([this, udid, conn_type,
|
||||
addType, wifiMacAddress,
|
||||
initResult]() {
|
||||
ipAddress, initResult]() {
|
||||
if (addType == AddType::UpgradeToWireless) {
|
||||
// udid is mac address here
|
||||
qDebug() << "AddType::UpgradeToWireless";
|
||||
// FIXME: udid is actually macAddress here
|
||||
const QString _pairingFilePath = getCachedPairingFile(udid);
|
||||
|
||||
if (_pairingFilePath.isEmpty()) {
|
||||
qDebug() << "Cannot upgrade to wireless, no cached pairing "
|
||||
"file for"
|
||||
<< udid;
|
||||
emitNoPairingFileForWirelessDevice(udid);
|
||||
return;
|
||||
}
|
||||
|
||||
QList<NetworkDevice> networkDevices =
|
||||
NetworkDeviceManager::sharedInstance()
|
||||
->m_networkProvider->getNetworkDevices();
|
||||
*initResult = init_idescriptor_device(
|
||||
udid, {ipAddress, _pairingFilePath});
|
||||
|
||||
auto it = std::find_if(
|
||||
networkDevices.constBegin(), networkDevices.constEnd(),
|
||||
[wifiMacAddress](const NetworkDevice &device) {
|
||||
return device.macAddress.compare(
|
||||
wifiMacAddress, Qt::CaseInsensitive) == 0;
|
||||
});
|
||||
|
||||
if (it != networkDevices.constEnd()) {
|
||||
|
||||
*initResult = init_idescriptor_device(
|
||||
udid, {it->address, _pairingFilePath});
|
||||
} else {
|
||||
qDebug() << "No network device found with MAC address:"
|
||||
<< wifiMacAddress;
|
||||
return;
|
||||
}
|
||||
} else if (addType == AddType::Wireless) {
|
||||
// FIXME: its not udid here its macAddress
|
||||
qDebug() << "AddType::Wireless";
|
||||
// FIXME: udid is actually macAddress here
|
||||
const QString _pairingFilePath = getCachedPairingFile(udid);
|
||||
|
||||
if (_pairingFilePath.isEmpty()) {
|
||||
qDebug() << "Cannot upgrade to wireless, no cached pairing "
|
||||
"file for"
|
||||
<< udid;
|
||||
emitNoPairingFileForWirelessDevice(udid);
|
||||
return;
|
||||
}
|
||||
|
||||
QList<NetworkDevice> networkDevices =
|
||||
NetworkDeviceManager::sharedInstance()
|
||||
->m_networkProvider->getNetworkDevices();
|
||||
*initResult = init_idescriptor_device(
|
||||
udid, {ipAddress, _pairingFilePath});
|
||||
|
||||
// todo : retry logic if not found
|
||||
auto it = std::find_if(
|
||||
networkDevices.constBegin(), networkDevices.constEnd(),
|
||||
[wifiMacAddress](const NetworkDevice &device) {
|
||||
return device.macAddress.compare(
|
||||
wifiMacAddress, Qt::CaseInsensitive) == 0;
|
||||
});
|
||||
|
||||
if (it != networkDevices.constEnd()) {
|
||||
*initResult = init_idescriptor_device(
|
||||
udid, {it->address, _pairingFilePath});
|
||||
} else {
|
||||
qDebug() << "No network device found with MAC address:"
|
||||
<< wifiMacAddress;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
qDebug() << "AddType::Regular";
|
||||
*initResult = init_idescriptor_device(udid, {nullptr, nullptr});
|
||||
}
|
||||
});
|
||||
@@ -266,6 +238,7 @@ void AppContext::addDevice(QString udid,
|
||||
if (!initResult->success) {
|
||||
qDebug() << "Failed to initialize device with UDID: "
|
||||
<< udid;
|
||||
emit initFailed(udid);
|
||||
return;
|
||||
}
|
||||
// if (!initResult.success) {
|
||||
@@ -405,11 +378,14 @@ void AppContext::removeDevice(QString _udid)
|
||||
iDescriptorDevice *device = m_devices[udid];
|
||||
m_devices.remove(udid);
|
||||
|
||||
emit deviceRemoved(udid, device->deviceInfo.wifiMacAddress);
|
||||
emit deviceRemoved(udid, device->deviceInfo.wifiMacAddress,
|
||||
device->deviceInfo.ipAddress,
|
||||
device->deviceInfo.isWireless);
|
||||
emit deviceChange();
|
||||
|
||||
std::lock_guard<std::recursive_mutex> lock(device->mutex);
|
||||
|
||||
// FIXME: implement proper cleanup
|
||||
if (device->afcClient)
|
||||
afc_client_free(device->afcClient);
|
||||
if (device->afc2Client)
|
||||
@@ -506,9 +482,12 @@ void AppContext::addRecoveryDevice(uint64_t ecid)
|
||||
|
||||
AppContext::~AppContext()
|
||||
{
|
||||
// FIXME: mutex?
|
||||
// FIXME: deviceRemoved can trigger, new devices being added while we are
|
||||
// trying to clean up
|
||||
for (auto device : m_devices) {
|
||||
emit deviceRemoved(device->udid, device->deviceInfo.wifiMacAddress);
|
||||
emit deviceRemoved(device->udid, device->deviceInfo.wifiMacAddress,
|
||||
device->deviceInfo.ipAddress,
|
||||
device->deviceInfo.isWireless);
|
||||
if (device->afcClient)
|
||||
afc_client_free(device->afcClient);
|
||||
if (device->afc2Client)
|
||||
@@ -624,4 +603,10 @@ void AppContext::tryToConnectToNetworkDevice(const QString &macAddress)
|
||||
} else {
|
||||
qDebug() << "No network device found with MAC address:" << macAddress;
|
||||
}
|
||||
}
|
||||
|
||||
// this is required because cannot emit signals from qfuture
|
||||
void AppContext::emitNoPairingFileForWirelessDevice(const QString &udid)
|
||||
{
|
||||
emit noPairingFileForWirelessDevice(udid);
|
||||
}
|
||||
+9
-2
@@ -59,9 +59,11 @@ private:
|
||||
DeviceSelection m_currentSelection = DeviceSelection("");
|
||||
QMap<QString, QString> m_pairingFileCache;
|
||||
void cachePairedDevices();
|
||||
void emitNoPairingFileForWirelessDevice(const QString &udid);
|
||||
signals:
|
||||
void deviceAdded(iDescriptorDevice *device);
|
||||
void deviceRemoved(const std::string &udid, const std::string &macAddress);
|
||||
void deviceRemoved(const std::string &udid, const std::string &macAddress,
|
||||
const std::string &ipAddress, bool wasWireless);
|
||||
void devicePaired(iDescriptorDevice *device);
|
||||
void devicePasswordProtected(const QString &udid);
|
||||
// #ifdef ENABLE_RECOVERY_DEVICE_SUPPORT
|
||||
@@ -70,6 +72,10 @@ signals:
|
||||
// #endif
|
||||
void devicePairPending(const QString &udid);
|
||||
void devicePairingExpired(const QString &udid);
|
||||
// only fired on wireless devices when we have no pairing file for them
|
||||
void noPairingFileForWirelessDevice(const QString &macAddress);
|
||||
void initFailed(const QString &udid);
|
||||
|
||||
void systemSleepStarting();
|
||||
void systemWakeup();
|
||||
/*
|
||||
@@ -86,7 +92,8 @@ public slots:
|
||||
void removeDevice(QString udid);
|
||||
void addDevice(QString udid,
|
||||
DeviceMonitorThread::IdeviceConnectionType connType,
|
||||
AddType addType, QString wifiMacAddress = QString());
|
||||
AddType addType, QString wifiMacAddress = QString(),
|
||||
QString ipAddress = QString());
|
||||
void heartbeatFailed(const QString &macAddress, int tries);
|
||||
// void heartbeatThreadExited(const QString &macAddress);
|
||||
#ifdef ENABLE_RECOVERY_DEVICE_SUPPORT
|
||||
|
||||
Reference in New Issue
Block a user