Android: Call nsd.stopServiceDiscovery() when going to sleep

If Android is on it's way to suspend when stopBrowser() is called, we need
to call nsd.stopServiceDiscovery() synchronously to force it to run
before the device goes to sleep.

Was an issue on Android 10 on Levono Tab M10 FHD Plus
TB-X606FA_S300554-220630_BMP
This commit is contained in:
Jonathan Bagg
2023-05-22 15:48:52 -04:00
parent 4fada0fb2a
commit 65e0713bc3

View File

@ -123,9 +123,15 @@ void QZeroConfPrivate::startBrowser(QString type, QAbstractSocket::NetworkLayerP
void QZeroConfPrivate::stopBrowser()
{
QAndroidJniObject ref(nsdManager);
QtAndroid::runOnAndroidThread([ref]() {
// If Android is on it's way to suspend when stopBrowser() is called, we need to call nsd.stopServiceDiscovery() synchronously
// to force it to run before the device goes to sleep.
if (qGuiApp->applicationState() == Qt::ApplicationSuspended) {
ref.callMethod<void>("stopServiceDiscovery");
});
} else {
QtAndroid::runOnAndroidThread([ref]() {
ref.callMethod<void>("stopServiceDiscovery");
});
}
}
// Callbacks will come in from the android thread. So we're never accessing any of our members directly but instead