Make access to RuffyScripter.currentMenu safer.

This commit is contained in:
Johannes Mockenhaupt 2017-09-06 12:40:42 +02:00
parent dc7dd15571
commit 09f834d990
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
3 changed files with 8 additions and 14 deletions

View file

@ -488,7 +488,7 @@ public class RuffyScripter {
if (System.currentTimeMillis() > timeout) { if (System.currentTimeMillis() > timeout) {
throw new CommandException().message("Unable to read current menu"); throw new CommandException().message("Unable to read current menu");
} }
log.error("currentMenu == null, waiting"); log.debug("currentMenu == null, waiting");
waitForMenuUpdate(); waitForMenuUpdate();
} }
return currentMenu; return currentMenu;
@ -634,10 +634,10 @@ public class RuffyScripter {
} }
public void navigateToMenu(MenuType desiredMenu) { public void navigateToMenu(MenuType desiredMenu) {
MenuType startedFrom = currentMenu.getType(); MenuType startedFrom = getCurrentMenu().getType();
boolean movedOnce = false; boolean movedOnce = false;
while (currentMenu.getType() != desiredMenu) { while (getCurrentMenu().getType() != desiredMenu) {
MenuType currentMenuType = currentMenu.getType(); MenuType currentMenuType = getCurrentMenu().getType();
log.debug("Navigating to menu " + desiredMenu + ", currenty menu: " + currentMenuType); log.debug("Navigating to menu " + desiredMenu + ", currenty menu: " + currentMenuType);
if (movedOnce && currentMenuType == startedFrom) { if (movedOnce && currentMenuType == startedFrom) {
throw new CommandException().message("Menu not found searching for " + desiredMenu throw new CommandException().message("Menu not found searching for " + desiredMenu
@ -652,7 +652,7 @@ public class RuffyScripter {
/** Wait till a menu changed has completed, "away" from the menu provided as argument. */ /** Wait till a menu changed has completed, "away" from the menu provided as argument. */
public void waitForMenuToBeLeft(MenuType menuType) { public void waitForMenuToBeLeft(MenuType menuType) {
long timeout = System.currentTimeMillis() + 60 * 1000; long timeout = System.currentTimeMillis() + 60 * 1000;
while (currentMenu.getType() == menuType) { while (getCurrentMenu().getType() == menuType) {
if (System.currentTimeMillis() > timeout) { if (System.currentTimeMillis() > timeout) {
throw new CommandException().message("Timeout waiting for menu " + menuType + " to be left"); throw new CommandException().message("Timeout waiting for menu " + menuType + " to be left");
} }
@ -666,7 +666,7 @@ public class RuffyScripter {
public void verifyMenuIsDisplayed(MenuType expectedMenu, String failureMessage) { public void verifyMenuIsDisplayed(MenuType expectedMenu, String failureMessage) {
int retries = 600; int retries = 600;
while (currentMenu.getType() != expectedMenu) { while (getCurrentMenu().getType() != expectedMenu) {
if (retries > 0) { if (retries > 0) {
SystemClock.sleep(100); SystemClock.sleep(100);
retries = retries - 1; retries = retries - 1;
@ -682,9 +682,9 @@ public class RuffyScripter {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T> T readBlinkingValue(Class<T> expectedType, MenuAttribute attribute) { public <T> T readBlinkingValue(Class<T> expectedType, MenuAttribute attribute) {
int retries = 5; int retries = 5;
Object value = currentMenu.getAttribute(attribute); Object value = getCurrentMenu().getAttribute(attribute);
while (!expectedType.isInstance(value)) { while (!expectedType.isInstance(value)) {
value = currentMenu.getAttribute(attribute); value = getCurrentMenu().getAttribute(attribute);
waitForScreenUpdate(1000); waitForScreenUpdate(1000);
retries--; retries--;
if (retries == 0) { if (retries == 0) {

View file

@ -1,10 +1,5 @@
package info.nightscout.androidaps.plugins.PumpCombo.scripter.commands; package info.nightscout.androidaps.plugins.PumpCombo.scripter.commands;
import android.os.SystemClock;
import org.monkey.d.ruffy.ruffy.driver.display.MenuAttribute;
import org.monkey.d.ruffy.ruffy.driver.display.MenuType;
import info.nightscout.androidaps.plugins.PumpCombo.scripter.RuffyScripter; import info.nightscout.androidaps.plugins.PumpCombo.scripter.RuffyScripter;
public abstract class BaseCommand implements Command { public abstract class BaseCommand implements Command {

View file

@ -11,7 +11,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import info.nightscout.androidaps.plugins.PumpCombo.scripter.PumpState;
import info.nightscout.androidaps.plugins.PumpCombo.scripter.RuffyScripter; import info.nightscout.androidaps.plugins.PumpCombo.scripter.RuffyScripter;
import static info.nightscout.androidaps.plugins.PumpCombo.scripter.commands.ExperimentalBolusCommand.ProgressReportCallback.State.DELIVERED; import static info.nightscout.androidaps.plugins.PumpCombo.scripter.commands.ExperimentalBolusCommand.ProgressReportCallback.State.DELIVERED;