From 27187b5e75217c331a42b7c7ad0e44879120df3b Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 22 Jul 2017 20:02:35 +0200 Subject: [PATCH] Bugfix: More reliable way to determine if the connection is ready to execute comands. --- .../jotomo/ruffyscripter/RuffyScripter.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java b/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java index 22a2da61a7..5022b0e6cf 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java @@ -293,14 +293,17 @@ public class RuffyScripter { boolean connectInitSuccessful = ruffyService.doRTConnect() == 0; log.debug("Connect init successful: " + connectInitSuccessful); - while (currentMenu == null) { - log.debug("Waiting for first menu update to be sent"); - // waitForMenuUpdate times out after 60s and throws a CommandException. - // if the user just pressed a button on the combo, the screen needs to time first - // before a connection is possible. In that case, it takes 45s before the - // connection comes up. - waitForMenuUpdate(90); - } + log.debug("Waiting for first menu update to be sent"); + // Note: there was an 'if(currentMenu == null)' around the next call, since + // the rtDisconnected callback sets currentMenu = null. However, there were + // race conditions, so it was removed. And really, waiting for an update + // to come in is a much safer bet. + + // waitForMenuUpdate times out after 60s and throws a CommandException. + // if the user just pressed a button on the combo, the screen needs to time first + // before a connection is possible. In that case, it takes 45s before the + // connection comes up. + waitForMenuUpdate(90); } catch (RemoteException e) { throw new CommandException().exception(e).message("Unexpected exception while initiating/restoring pump connection"); }