From 2135a25d9ac49730833eb85caae42f42c35e2de7 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Sun, 4 Dec 2016 11:52:28 -0800 Subject: [PATCH] Android build stop serial probe after first connect --- src/comm/LinkManager.cc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/comm/LinkManager.cc b/src/comm/LinkManager.cc index 34a0320fd..fb9056cbc 100644 --- a/src/comm/LinkManager.cc +++ b/src/comm/LinkManager.cc @@ -490,7 +490,16 @@ void LinkManager::_updateAutoConnectLinks(void) #ifndef NO_SERIAL_LINK QStringList currentPorts; - QList portList = QGCSerialPortInfo::availablePorts(); + QList portList; + +#ifdef __android__ + // Android builds only support a single serial connection. Repeatedly calling availablePorts after that one serial + // port is connected leaks file handles due to a bug somewhere in android serial code. In order to work around that + // bug after we connect the first serial port we stop probing for additional ports. + if (!_autoconnectConfigurations.count()) { + portList = QGCSerialPortInfo::availablePorts(); + } +#endif // Iterate Comm Ports foreach (QGCSerialPortInfo portInfo, portList) { @@ -601,6 +610,13 @@ void LinkManager::_updateAutoConnectLinks(void) } } +#ifndef __android__ + // Android builds only support a single serial connection. Repeatedly calling availablePorts after that one serial + // port is connected leaks file handles due to a bug somewhere in android serial code. In order to work around that + // bug after we connect the first serial port we stop probing for additional ports. The means we must rely on + // the port disconnecting itself when the radio is pulled to signal communication list as opposed to automatically + // closing the Link. + // Now we go through the current configuration list and make sure any dynamic config has gone away QList _confToDelete; for (int i=0; i<_autoconnectConfigurations.count(); i++) { @@ -633,6 +649,7 @@ void LinkManager::_updateAutoConnectLinks(void) } delete pDeleteConfig; } +#endif #endif // NO_SERIAL_LINK } -- 2.22.0