diff options
author | NicoleYarroch <nicole@livio.io> | 2019-08-02 15:37:25 -0400 |
---|---|---|
committer | NicoleYarroch <nicole@livio.io> | 2019-08-02 15:37:25 -0400 |
commit | 0223edf280af353308c861501ebaf768683a0803 (patch) | |
tree | 0fe082110dd9c61221deda435a2fff822a7abbc0 | |
parent | 007126dc75fb3c12bd9a33b10e5dd1941f12da4c (diff) | |
download | sdl_android-0223edf280af353308c861501ebaf768683a0803.tar.gz |
Fixed order of finishing for operations
5 files changed, 28 insertions, 49 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperationTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperationTests.java index c70946206..f132b8e71 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperationTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperationTests.java @@ -66,7 +66,6 @@ public class PresentChoiceSetOperationTests extends AndroidTestCase2 { private PresentChoiceSetOperation presentChoiceSetOperation; private ChoiceSet choiceSet; private ISdl internalInterface; - private Boolean hasCalledOperationCompletionHandler; @Override public void setUp() throws Exception{ @@ -74,26 +73,13 @@ public class PresentChoiceSetOperationTests extends AndroidTestCase2 { internalInterface = mock(ISdl.class); KeyboardListener keyboardListener = mock(KeyboardListener.class); - - ChoiceSetSelectionListener choiceSetSelectionListener = new ChoiceSetSelectionListener() { - @Override - public void onChoiceSelected(ChoiceCell choiceCell, TriggerSource triggerSource, int rowIndex) { - - } - - @Override - public void onError(String error) { - hasCalledOperationCompletionHandler = true; - } - }; + ChoiceSetSelectionListener choiceSetSelectionListener = mock(ChoiceSetSelectionListener.class); ChoiceCell cell1 = new ChoiceCell("Cell1"); cell1.setChoiceId(0); choiceSet = new ChoiceSet("Test", Collections.singletonList(cell1), choiceSetSelectionListener); presentChoiceSetOperation = new PresentChoiceSetOperation(internalInterface, choiceSet, InteractionMode.MANUAL_ONLY, getKeyBoardProperties(), keyboardListener, choiceSetSelectionListener); choiceSet.cancelID = Test.GENERAL_INTEGER; - hasCalledOperationCompletionHandler = false; - } @Override @@ -158,9 +144,8 @@ public class PresentChoiceSetOperationTests extends AndroidTestCase2 { choiceSet.cancel(); - assertEquals(hasCalledOperationCompletionHandler.booleanValue(), true); - assertEquals(presentChoiceSetOperation.isExecuting().booleanValue(), false); - assertEquals(presentChoiceSetOperation.isFinished().booleanValue(), true); + assertEquals(presentChoiceSetOperation.isExecuting().booleanValue(), true); + assertEquals(presentChoiceSetOperation.isFinished().booleanValue(), false); } public void testCancelingTheChoiceSetUnsuccessfullyIfThreadIsRunning(){ @@ -188,9 +173,8 @@ public class PresentChoiceSetOperationTests extends AndroidTestCase2 { choiceSet.cancel(); - assertEquals(hasCalledOperationCompletionHandler.booleanValue(), true); - assertEquals(presentChoiceSetOperation.isExecuting().booleanValue(), false); - assertEquals(presentChoiceSetOperation.isFinished().booleanValue(), true); + assertEquals(presentChoiceSetOperation.isExecuting().booleanValue(), true); + assertEquals(presentChoiceSetOperation.isFinished().booleanValue(), false); } public void testCancelingTheChoiceSetIfThreadHasFinished(){ @@ -204,7 +188,6 @@ public class PresentChoiceSetOperationTests extends AndroidTestCase2 { verify(internalInterface, never()).sendRPC(any(CancelInteraction.class)); - // assertEquals(hasCalledOperationCompletionHandler.booleanValue(), true); assertEquals(presentChoiceSetOperation.isExecuting().booleanValue(), false); assertEquals(presentChoiceSetOperation.isFinished().booleanValue(), true); } @@ -223,7 +206,6 @@ public class PresentChoiceSetOperationTests extends AndroidTestCase2 { // Make sure it doesn't sent a `CancelInteraction` RPC verify(internalInterface, never()).sendRPC(any(CancelInteraction.class)); - assertEquals(hasCalledOperationCompletionHandler.booleanValue(), true); assertEquals(presentChoiceSetOperation.isExecuting().booleanValue(), false); assertEquals(presentChoiceSetOperation.isFinished().booleanValue(), true); } diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperationTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperationTests.java index e04abc663..f56f12358 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperationTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperationTests.java @@ -137,8 +137,8 @@ public class PresentKeyboardOperationTests extends AndroidTestCase2 { presentKeyboardOperation.cancelKeyboard(); - assertEquals(presentKeyboardOperation.isExecuting().booleanValue(), false); - assertEquals(presentKeyboardOperation.isFinished().booleanValue(), true); + assertEquals(presentKeyboardOperation.isExecuting().booleanValue(), true); + assertEquals(presentKeyboardOperation.isFinished().booleanValue(), false); } public void testCancelingTheKeyboardUnsuccessfullyIfThreadIsRunning(){ @@ -166,8 +166,8 @@ public class PresentKeyboardOperationTests extends AndroidTestCase2 { presentKeyboardOperation.cancelKeyboard(); - assertEquals(presentKeyboardOperation.isExecuting().booleanValue(), false); - assertEquals(presentKeyboardOperation.isFinished().booleanValue(), true); + assertEquals(presentKeyboardOperation.isExecuting().booleanValue(), true); + assertEquals(presentKeyboardOperation.isFinished().booleanValue(), false); } public void testCancelingTheKeyboardIfThreadHasFinished(){ diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java index f656f78b2..9d8daa108 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java @@ -36,6 +36,7 @@ package com.smartdevicelink.managers.screen.choiceset; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.util.Log; import com.smartdevicelink.managers.BaseSubManager; import com.smartdevicelink.managers.CompletionListener; @@ -165,7 +166,7 @@ abstract class BaseChoiceSetManager extends BaseSubManager { @Override public void onError(String error) { - // At this point, there were errors trying to send a test CICS + // At this point, there were errors trying to send a test PICS // If we reach this state, we cannot use the manager DebugTool.logError(error); transitionToState(ERROR); @@ -399,6 +400,19 @@ abstract class BaseChoiceSetManager extends BaseSubManager { } public void dismissKeyboard() { + Thread thread = Thread.currentThread(); + if (Thread.currentThread().getClass().equals(PresentKeyboardOperation.class)) { + DebugTool.logInfo("Got something - Choice Set Manager"); + } + + if (pendingPresentOperation instanceof PresentKeyboardOperation) { + DebugTool.logInfo("Got something - Choice Set Manager"); + } + + if (pendingPresentOperation.getClass().equals(PresentKeyboardOperation.class)) { + DebugTool.logInfo("Got something - Choice Set Manager"); + } + for (Runnable operation : operationQueue){ if (!(operation instanceof PresentKeyboardOperation)){ continue; } ((PresentKeyboardOperation) operation).cancelKeyboard(); diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperation.java index 0a4cb7ad4..cbbd892ec 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperation.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentChoiceSetOperation.java @@ -226,9 +226,6 @@ class PresentChoiceSetOperation extends AsynchronousOperation { } else if (Thread.currentThread().isInterrupted()) { if (!isExecuting()) { return; } finishOperation(); - if (choiceSetSelectionListener != null) { - choiceSetSelectionListener.onError("Presenting the choice set was already canceled"); - } return; } else if (isExecuting()) { DebugTool.logInfo("Canceling the presented choice set interaction."); @@ -237,31 +234,21 @@ class PresentChoiceSetOperation extends AsynchronousOperation { cancelInteraction.setOnRPCResponseListener(new OnRPCResponseListener() { @Override public void onResponse(int correlationId, RPCResponse response) { - finishOperation(); - if (choiceSetSelectionListener != null) { - choiceSetSelectionListener.onError((response.getSuccess()) ? - "Presented choice set canceled successfully." : - "Error canceling the presented choice set " + response.getResultCode()); - } + DebugTool.logInfo("Canceled the presented choice set " + ((response.getResultCode() == Result.SUCCESS) ? "successfully" : "unsuccessfully")); } @Override public void onError(int correlationId, Result resultCode, String info){ - finishOperation(); - if (choiceSetSelectionListener != null) { - choiceSetSelectionListener.onError("Error canceling the presented choice set " + resultCode + " " + info); - } + DebugTool.logError("Error canceling the presented choice set " + resultCode + " " + info); }; }); + if (internalInterface.get() != null){ internalInterface.get().sendRPC(cancelInteraction); } else { DebugTool.logError("Internal interface null - could not send cancel interaction for choice set"); } } else { - if (choiceSetSelectionListener != null) { - choiceSetSelectionListener.onError("Canceling a choice set that has not yet been sent to Core"); - } Thread.currentThread().interrupt(); } } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperation.java index bbf1f7510..582054a4d 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperation.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PresentKeyboardOperation.java @@ -137,16 +137,12 @@ class PresentKeyboardOperation extends AsynchronousOperation { cancelInteraction.setOnRPCResponseListener(new OnRPCResponseListener() { @Override public void onResponse(int correlationId, RPCResponse response) { - if (!response.getSuccess()) { - DebugTool.logError("Error canceling the presented keyboard " + response.getResultCode()); - } - finishOperation(); + DebugTool.logInfo("Canceled the presented keyboard " + ((response.getResultCode() == Result.SUCCESS) ? "successfully" : "unsuccessfully")); } @Override public void onError(int correlationId, Result resultCode, String info){ DebugTool.logError("Error canceling the presented keyboard " + resultCode + " " + info); - finishOperation(); }; }); if (internalInterface.get() != null){ |