diff options
author | Chloe Matthews <77455275+ChloeMJM@users.noreply.github.com> | 2022-09-21 15:22:23 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-21 15:22:23 -0400 |
commit | 44b38cb3766f2685aee586db0ede1d00dffd19e4 (patch) | |
tree | e6605cc1f651e9b07d4ba21d89f6d90a66a8bb0e | |
parent | 6e6040d1cc5c285a11b037555715466a699bae7f (diff) | |
download | sdl_android-44b38cb3766f2685aee586db0ede1d00dffd19e4.tar.gz |
Bugfix/issue 1828 Good text failing (#1831)
* Added updateTargetStateWithErrorState() method
* Added updatePendingOperationsWithFailedScreenState method.
* Added testUpdateTargetStateWithErrorSendingBadData() testing method.
* Testing cleanup for clarity
* Added null checks for references in updateTargetStateWithErrorState
* Added additional tests.
* Modified updateTargetStateWithErrorState method to use null safe Objects.equals()
* Applying feedback: Made suggested formatting changes. Removed unused supersedePreviousOperations and currentOperationListener variables. Changed passed in reference from updatedState to null for currentScreenDataListener.onError() when text update has not been sent.
* Adjusted when updateTargetStateWithErrorState is called. Modified currentScreenDataUpdateListener.onError(updatedState) from null to updatedState.
3 files changed, 280 insertions, 59 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperationTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperationTest.java index 4af040863..464dbb11f 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperationTest.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperationTest.java @@ -52,20 +52,24 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import junit.framework.TestCase; + @RunWith(AndroidJUnit4.class) public class TextAndGraphicUpdateOperationTest { private TextAndGraphicUpdateOperation textAndGraphicUpdateOperation; private String textField1, textField2, textField3, textField4, mediaTrackField, title; - private MetadataType textField1Type, textField2Type, textField3Type, textField4Type; - private SdlArtwork testArtwork1, testArtwork2, testArtwork3, testArtwork4; - private TextAlignment textAlignment; + private String textField1Fail, textField2Fail, textField3Fail, textField4Fail, mediaTrackFieldFail, titleFail; + private MetadataType textField1Type, textField2Type, textField3Type, textField4Type, textFieldFailType; + private SdlArtwork testArtwork1, testArtwork2, testArtwork3, testArtwork4, testArtworkFail; + private TextAlignment textAlignment, textAlignmentFail; private WindowCapability defaultMainWindowCapability; private TextAndGraphicState currentScreenData; + private TextAndGraphicState errorTestState, errorTestState2; private CompletionListener listener; private TextAndGraphicManager.CurrentScreenDataUpdatedListener currentScreenDataUpdatedListener; private SdlArtwork blankArtwork; - private TemplateConfiguration configuration; + private TemplateConfiguration configuration, configurationFail; ISdl internalInterface; FileManager fileManager; @@ -188,6 +192,13 @@ public class TextAndGraphicUpdateOperationTest { mediaTrackField = "dudes"; title = "dudes"; + textField1Fail = "It is\nbad data"; + textField2Fail = "Wednesday\nbad data"; + textField3Fail = "My\nbad data"; + textField4Fail = "Dudes\nbad data"; + mediaTrackFieldFail = "dudes\nbad data"; + titleFail = "dudes\nbad data"; + blankArtwork = new SdlArtwork(); blankArtwork.setType(FileType.GRAPHIC_PNG); blankArtwork.setName("blankArtwork"); @@ -197,9 +208,10 @@ public class TextAndGraphicUpdateOperationTest { textField2Type = MetadataType.MEDIA_TITLE; textField3Type = MetadataType.MEDIA_TITLE; textField4Type = MetadataType.MEDIA_TITLE; - + textFieldFailType = MetadataType.valueForString("failType"); textAlignment = TextAlignment.CENTERED; + textAlignmentFail = TextAlignment.valueForString("failAlignment"); testArtwork1 = new SdlArtwork(); testArtwork1.setName("testFile1"); @@ -225,9 +237,37 @@ public class TextAndGraphicUpdateOperationTest { testArtwork4.setUri(uri4); testArtwork4.setType(FileType.GRAPHIC_PNG); + testArtworkFail = new SdlArtwork(); + testArtworkFail.setName("testFileFail"); + Uri uriFail = Uri.parse("android.resource://" + mTestContext.getPackageName() + "/no_file"); + testArtworkFail.setUri(uriFail); + testArtworkFail.setType(FileType.GRAPHIC_PNG); + configuration = new TemplateConfiguration(); configuration.setTemplate(PredefinedLayout.GRAPHIC_WITH_TEXT.toString()); + configurationFail = new TemplateConfiguration(); + configurationFail.setTemplate("failConfiguration"); + + errorTestState = new TextAndGraphicState(); + errorTestState2 = new TextAndGraphicState(); + + errorTestState2.setTextField1(textField1); + errorTestState2.setTextField2(textField2); + errorTestState2.setTextField3(textField3Fail); + errorTestState2.setTextField4(textField4Fail); + errorTestState2.setTextField1Type(textFieldFailType); + errorTestState2.setTextField2Type(textFieldFailType); + errorTestState2.setTextField3Type(textFieldFailType); + errorTestState2.setTextField4Type(textFieldFailType); + errorTestState2.setMediaTrackTextField(mediaTrackFieldFail); + errorTestState2.setTitle(titleFail); + errorTestState2.setPrimaryGraphic(testArtworkFail); + errorTestState2.setSecondaryGraphic(testArtworkFail); + errorTestState2.setTextAlignment(textAlignmentFail); + errorTestState2.setTemplateConfiguration(configurationFail); + + currentScreenData = new TextAndGraphicState(); currentScreenData.setTextField1("Old"); currentScreenData.setTextField2("Text"); @@ -241,12 +281,10 @@ public class TextAndGraphicUpdateOperationTest { currentScreenDataUpdatedListener = new TextAndGraphicManager.CurrentScreenDataUpdatedListener() { @Override public void onUpdate(TextAndGraphicState newState) { - } @Override - public void onError() { - + public void onError(TextAndGraphicState errorState) { } }; @@ -257,7 +295,6 @@ public class TextAndGraphicUpdateOperationTest { textAndGraphicUpdateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager, defaultMainWindowCapability, currentScreenData, textsAndGraphicsState, listener, currentScreenDataUpdatedListener); } - private void setUpCompletionListener() { listener = new CompletionListener() { @Override @@ -1017,4 +1054,152 @@ public class TextAndGraphicUpdateOperationTest { } + @Test + public void testOnShowFailBadDataDoesNotUpdateScreen(){ + doAnswer(onShowFail).when(internalInterface).sendRPC(any(Show.class)); + doAnswer(onArtworkUploadSuccess).when(fileManager).uploadArtworks(any(List.class), any(MultipleFileCompletionListener.class)); + when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(4, 0)); + + TextAndGraphicState textsAndGraphicsState = new TextAndGraphicState(textField1Fail, textField2Fail, textField3Fail, textField4Fail, + mediaTrackFieldFail, titleFail, testArtworkFail, testArtworkFail, textAlignmentFail, textFieldFailType, textFieldFailType, textFieldFailType, textFieldFailType, configurationFail); + textAndGraphicUpdateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager, defaultMainWindowCapability, currentScreenData, textsAndGraphicsState, listener, currentScreenDataUpdatedListener); + + // Test Images need to be uploaded, sending text and uploading images + textAndGraphicUpdateOperation.onExecute(); + + // Sending in bad data should result in no updates to the current screen + assertEquals("Old", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField1()); + assertEquals("Text", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField2()); + assertEquals("Not", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField3()); + assertEquals("Important", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField4()); + TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getMediaTrackTextField()); + assertEquals(testArtwork1, textAndGraphicUpdateOperation.getCurrentScreenData().getPrimaryGraphic()); + assertEquals(testArtwork2, textAndGraphicUpdateOperation.getCurrentScreenData().getSecondaryGraphic()); + TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextAlignment()); + TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField1Type()); + TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField2Type()); + TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField3Type()); + TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField4Type()); + assertEquals(configuration, textAndGraphicUpdateOperation.getCurrentScreenData().getTemplateConfiguration()); + } + + @Test + public void testUpdateTargetStateWithErrorStateNullDoesNotUpdateCurrentScreen() { + when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(4, 0)); + + errorTestState.setTextField1(null); + errorTestState.setTextField2(null); + errorTestState.setTextField3(null); + errorTestState.setTextField4(null); + errorTestState.setTextField1Type(null); + errorTestState.setTextField2Type(null); + errorTestState.setTextField3Type(null); + errorTestState.setTextField4Type(null); + errorTestState.setMediaTrackTextField(null); + errorTestState.setTitle(null); + errorTestState.setPrimaryGraphic(null); + errorTestState.setSecondaryGraphic(null); + errorTestState.setTextAlignment(null); + errorTestState.setTemplateConfiguration(null); + + textAndGraphicUpdateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager, defaultMainWindowCapability, currentScreenData, errorTestState, listener, currentScreenDataUpdatedListener); + // Testing updateTargetStateWithErrorState method + textAndGraphicUpdateOperation.updateTargetStateWithErrorState(errorTestState); + textAndGraphicUpdateOperation.onExecute(); + + // Setting fields to null should result in no updates to the current screen + assertEquals("Old", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField1()); + assertEquals("Text", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField2()); + assertEquals("Not", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField3()); + assertEquals("Important", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField4()); + TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getMediaTrackTextField()); + assertEquals(testArtwork1, textAndGraphicUpdateOperation.getCurrentScreenData().getPrimaryGraphic()); + assertEquals(testArtwork2, textAndGraphicUpdateOperation.getCurrentScreenData().getSecondaryGraphic()); + TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextAlignment()); + TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField1Type()); + TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField2Type()); + TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField3Type()); + TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField4Type()); + assertEquals(configuration, textAndGraphicUpdateOperation.getCurrentScreenData().getTemplateConfiguration()); + } + + @Test + public void testUpdateTargetStateWithErrorBadDataDoesNotUpdateCurrentScreen() { + when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(4, 0)); + + errorTestState.setTextField1(textField1Fail); + errorTestState.setTextField2(textField2Fail); + errorTestState.setTextField3(textField3Fail); + errorTestState.setTextField4(textField4Fail); + errorTestState.setTextField1Type(textFieldFailType); + errorTestState.setTextField2Type(textFieldFailType); + errorTestState.setTextField3Type(textFieldFailType); + errorTestState.setTextField4Type(textFieldFailType); + errorTestState.setMediaTrackTextField(mediaTrackFieldFail); + errorTestState.setTitle(titleFail); + errorTestState.setPrimaryGraphic(testArtworkFail); + errorTestState.setSecondaryGraphic(testArtworkFail); + errorTestState.setTextAlignment(textAlignmentFail); + errorTestState.setTemplateConfiguration(configurationFail); + + textAndGraphicUpdateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager, defaultMainWindowCapability, currentScreenData, errorTestState, listener, currentScreenDataUpdatedListener); + // Testing updateTargetStateWithErrorState method + textAndGraphicUpdateOperation.updateTargetStateWithErrorState(errorTestState); + textAndGraphicUpdateOperation.onExecute(); + + // Setting bad data should result in no updates to the current screen + assertEquals("Old", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField1()); + assertEquals("Text", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField2()); + assertEquals("Not", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField3()); + assertEquals("Important", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField4()); + TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getMediaTrackTextField()); + assertEquals(testArtwork1, textAndGraphicUpdateOperation.getCurrentScreenData().getPrimaryGraphic()); + assertEquals(testArtwork2, textAndGraphicUpdateOperation.getCurrentScreenData().getSecondaryGraphic()); + TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextAlignment()); + TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField1Type()); + TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField2Type()); + TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField3Type()); + TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField4Type()); + assertEquals(configuration, textAndGraphicUpdateOperation.getCurrentScreenData().getTemplateConfiguration()); + } + + @Test + public void testUpdateTargetStateWithErrorBadDataAndGoodData() { + when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(4, 0)); + + errorTestState2.setTextField1(textField1Fail); + errorTestState2.setTextField2(textField2); + errorTestState2.setTextField3(null); + errorTestState2.setTextField4(textField4Fail); + errorTestState2.setTextField1Type(textFieldFailType); + errorTestState2.setTextField2Type(textFieldFailType); + errorTestState2.setTextField3Type(textFieldFailType); + errorTestState2.setTextField4Type(textFieldFailType); + errorTestState2.setMediaTrackTextField(mediaTrackFieldFail); + errorTestState2.setTitle(titleFail); + errorTestState2.setPrimaryGraphic(testArtworkFail); + errorTestState2.setSecondaryGraphic(testArtworkFail); + errorTestState2.setTextAlignment(textAlignmentFail); + errorTestState2.setTemplateConfiguration(configurationFail); + + textAndGraphicUpdateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager, defaultMainWindowCapability, currentScreenData, errorTestState2, listener, currentScreenDataUpdatedListener); + // Testing updateTargetStateWithErrorState method + textAndGraphicUpdateOperation.updateTargetStateWithErrorState(errorTestState2); + textAndGraphicUpdateOperation.onExecute(); + + // Setting mix of good and bad data should result in only updates to those fields with good data + assertEquals("Old", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField1()); + assertEquals(errorTestState2.getTextField2(), textAndGraphicUpdateOperation.getCurrentScreenData().getTextField2()); + assertEquals("Not", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField3()); + assertEquals("Important", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField4()); + TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getMediaTrackTextField()); + assertEquals(errorTestState2.getPrimaryGraphic(), textAndGraphicUpdateOperation.getCurrentScreenData().getPrimaryGraphic()); + assertEquals(errorTestState2.getSecondaryGraphic(), textAndGraphicUpdateOperation.getCurrentScreenData().getSecondaryGraphic()); + TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextAlignment()); + TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField1Type()); + TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField2Type()); + TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField3Type()); + TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField4Type()); + assertEquals(configuration, textAndGraphicUpdateOperation.getCurrentScreenData().getTemplateConfiguration()); + } } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java index 0a201fc22..92bc82817 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java @@ -87,7 +87,6 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager { private MetadataType textField1Type, textField2Type, textField3Type, textField4Type; private TemplateConfiguration templateConfiguration; TextAndGraphicUpdateOperation updateOperation; - private CompletionListener currentOperationListener; Queue transactionQueue; //Constructors @@ -175,36 +174,13 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager { } if (isDirty) { isDirty = false; - sdlUpdate(true, listener); + sdlUpdate(listener); } else if (listener != null) { listener.onComplete(true); } } - private synchronized void sdlUpdate(Boolean supersedePreviousOperations, final CompletionListener listener) { - if (this.transactionQueue.getTasksAsList().size() > 0 && supersedePreviousOperations) { - // Transactions already in queue, we need to clear it out - transactionQueue.clear(); - updateOperation = null; - if (currentOperationListener != null) { - currentOperationListener.onComplete(false); - } - } - - // Task can be READY, about to start and popped of the queue, so we have to cancel it, to prevent it from starting - if (updateOperation != null && updateOperation.getState() == Task.READY && supersedePreviousOperations) { - updateOperation.cancelTask(); - if (currentOperationListener != null) { - currentOperationListener.onComplete(false); - } - } - - // If Task is IN_PROGRESS, it’s not on the queue, we need to mark it as cancelled. The task will return at some point when it checks its status and call the listener back - if (updateOperation != null && updateOperation.getState() == Task.IN_PROGRESS && supersedePreviousOperations) { - updateOperation.cancelTask(); - } - - currentOperationListener = listener; + private synchronized void sdlUpdate(final CompletionListener listener) { CurrentScreenDataUpdatedListener currentScreenDataUpdateListener = new CurrentScreenDataUpdatedListener() { @Override @@ -217,13 +193,16 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager { } @Override - public void onError() { + public void onError(TextAndGraphicState errorState) { // Invalidate data that's different from our current screen data resetFieldsToCurrentScreenData(); + if (errorState != null) { + updatePendingOperationsWithFailedScreenState(errorState); + } } }; - updateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager.get(), defaultMainWindowCapability, currentScreenData, currentState(), currentOperationListener, currentScreenDataUpdateListener); + updateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager.get(), defaultMainWindowCapability, currentScreenData, currentState(), listener, currentScreenDataUpdateListener); transactionQueue.add(updateOperation, false); } @@ -257,10 +236,20 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager { } } + void updatePendingOperationsWithFailedScreenState(TextAndGraphicState errorState) { + for (Task task : transactionQueue.getTasksAsList()) { + if (!(task instanceof TextAndGraphicUpdateOperation)) { + continue; + } + ((TextAndGraphicUpdateOperation) task).setCurrentScreenData(currentScreenData); + ((TextAndGraphicUpdateOperation) task).updateTargetStateWithErrorState(errorState); + } + } + interface CurrentScreenDataUpdatedListener { void onUpdate(TextAndGraphicState newState); - void onError(); + void onError(TextAndGraphicState errorState); } @@ -317,7 +306,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager { this.textAlignment = textAlignment; // If we aren't batching, send the update immediately, if we are, set ourselves as dirty (so we know we should send an update after the batch ends) if (!batchingUpdates) { - sdlUpdate(true, null); + sdlUpdate(null); } else { isDirty = true; } @@ -330,7 +319,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager { void setMediaTrackTextField(String mediaTrackTextField) { this.mediaTrackTextField = mediaTrackTextField; if (!batchingUpdates) { - sdlUpdate(true, null); + sdlUpdate(null); } else { isDirty = true; } @@ -343,7 +332,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager { void setTextField1(String textField1) { this.textField1 = textField1; if (!batchingUpdates) { - sdlUpdate(true, null); + sdlUpdate(null); } else { isDirty = true; } @@ -356,7 +345,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager { void setTextField2(String textField2) { this.textField2 = textField2; if (!batchingUpdates) { - sdlUpdate(true, null); + sdlUpdate(null); } else { isDirty = true; } @@ -369,7 +358,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager { void setTextField3(String textField3) { this.textField3 = textField3; if (!batchingUpdates) { - sdlUpdate(true, null); + sdlUpdate(null); } else { isDirty = true; } @@ -382,7 +371,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager { void setTextField4(String textField4) { this.textField4 = textField4; if (!batchingUpdates) { - sdlUpdate(true, null); + sdlUpdate(null); } else { isDirty = true; } @@ -395,7 +384,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager { void setTextField1Type(MetadataType textField1Type) { this.textField1Type = textField1Type; if (!batchingUpdates) { - sdlUpdate(true, null); + sdlUpdate(null); } else { isDirty = true; } @@ -408,7 +397,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager { void setTextField2Type(MetadataType textField2Type) { this.textField2Type = textField2Type; if (!batchingUpdates) { - sdlUpdate(true, null); + sdlUpdate(null); } else { isDirty = true; } @@ -421,7 +410,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager { void setTextField3Type(MetadataType textField3Type) { this.textField3Type = textField3Type; if (!batchingUpdates) { - sdlUpdate(true, null); + sdlUpdate(null); } else { isDirty = true; } @@ -434,7 +423,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager { void setTextField4Type(MetadataType textField4Type) { this.textField4Type = textField4Type; if (!batchingUpdates) { - sdlUpdate(true, null); + sdlUpdate(null); } else { isDirty = true; } @@ -447,7 +436,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager { void setTitle(String title) { this.title = title; if (!batchingUpdates) { - sdlUpdate(true, null); + sdlUpdate(null); } else { isDirty = true; } @@ -460,7 +449,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager { void setPrimaryGraphic(SdlArtwork primaryGraphic) { this.primaryGraphic = primaryGraphic; if (!batchingUpdates) { - sdlUpdate(true, null); + sdlUpdate(null); } else { isDirty = true; } @@ -473,7 +462,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager { void setSecondaryGraphic(SdlArtwork secondaryGraphic) { this.secondaryGraphic = secondaryGraphic; if (!batchingUpdates) { - sdlUpdate(true, null); + sdlUpdate(null); } else { isDirty = true; } @@ -491,7 +480,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager { void changeLayout(TemplateConfiguration templateConfiguration, CompletionListener listener) { setTemplateConfiguration(templateConfiguration); if (!batchingUpdates) { - sdlUpdate(true, listener); + sdlUpdate(listener); } else { isDirty = true; } @@ -554,7 +543,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager { updateTransactionQueueSuspended(); if (hasData()) { // HAX: Capability updates cannot supersede earlier updates because of the case where a developer batched a `changeLayout` call w/ T&G changes on < 6.0 systems could cause this to come in before the operation completes. That would cause the operation to report a "failure" (because it was superseded by this call) when in fact the operation didn't fail at all and is just being adjusted. - sdlUpdate(false, null); + sdlUpdate(null); } } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperation.java index 683820ee5..729b81e1c 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperation.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperation.java @@ -1,5 +1,7 @@ package com.smartdevicelink.managers.screen; +import androidx.annotation.NonNull; + import com.livio.taskmaster.Task; import com.smartdevicelink.managers.CompletionListener; import com.smartdevicelink.managers.ISdl; @@ -24,6 +26,8 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Objects; + /** * Created by Julian Kast on 8/23/20. @@ -92,6 +96,51 @@ class TextAndGraphicUpdateOperation extends Task { } } + void updateTargetStateWithErrorState(@NonNull TextAndGraphicState errorState){ + if (Objects.equals(errorState.getTextField1(), updatedState.getTextField1())){ + updatedState.setTextField1(currentScreenData.getTextField1()); + } + if (Objects.equals(errorState.getTextField2(), updatedState.getTextField2())){ + updatedState.setTextField2(currentScreenData.getTextField2()); + } + if (Objects.equals(errorState.getTextField3(), updatedState.getTextField3())){ + updatedState.setTextField3(currentScreenData.getTextField3()); + } + if (Objects.equals(errorState.getTextField4(), updatedState.getTextField4())){ + updatedState.setTextField4(currentScreenData.getTextField4()); + } + if (Objects.equals(errorState.getMediaTrackTextField(), updatedState.getMediaTrackTextField())){ + updatedState.setMediaTrackTextField(currentScreenData.getMediaTrackTextField()); + } + if (Objects.equals(errorState.getTitle(), updatedState.getTitle())){ + updatedState.setTitle(currentScreenData.getTitle()); + } + if (Objects.equals(errorState.getPrimaryGraphic(), updatedState.getPrimaryGraphic())){ + updatedState.setPrimaryGraphic(currentScreenData.getPrimaryGraphic()); + } + if (Objects.equals(errorState.getSecondaryGraphic(), updatedState.getSecondaryGraphic())){ + updatedState.setSecondaryGraphic(currentScreenData.getSecondaryGraphic()); + } + if (Objects.equals(errorState.getTextAlignment(), updatedState.getTextAlignment())){ + updatedState.setTextAlignment(currentScreenData.getTextAlignment()); + } + if (Objects.equals(errorState.getTextField1Type(), updatedState.getTextField1Type())){ + updatedState.setTextField1Type(currentScreenData.getTextField1Type()); + } + if (Objects.equals(errorState.getTextField2Type(), updatedState.getTextField2Type())){ + updatedState.setTextField2Type(currentScreenData.getTextField2Type()); + } + if (Objects.equals(errorState.getTextField3Type(), updatedState.getTextField3Type())){ + updatedState.setTextField3Type(currentScreenData.getTextField3Type()); + } + if (Objects.equals(errorState.getTextField4Type(), updatedState.getTextField4Type())){ + updatedState.setTextField4Type(currentScreenData.getTextField4Type()); + } + if (Objects.equals(errorState.getTemplateConfiguration(), updatedState.getTemplateConfiguration())){ + updatedState.setTemplateConfiguration(currentScreenData.getTemplateConfiguration()); + } + } + void updateGraphicsAndShow(Show show) { if (!shouldUpdatePrimaryImage() && !shouldUpdateSecondaryImage()) { DebugTool.logInfo(TAG, "No images to send, sending text"); @@ -129,7 +178,6 @@ class TextAndGraphicUpdateOperation extends Task { finishOperation(success); } }); - } }); } @@ -144,7 +192,7 @@ class TextAndGraphicUpdateOperation extends Task { updateCurrentScreenDataFromShow(show); } else { DebugTool.logInfo(TAG, "Text and Graphic Show failed"); - currentScreenDataUpdateListener.onError(); + currentScreenDataUpdateListener.onError(updatedState); } listener.onComplete(response.getSuccess()); @@ -154,11 +202,10 @@ class TextAndGraphicUpdateOperation extends Task { internalInterface.get().sendRPC(show); } else { DebugTool.logInfo(TAG, "ISdl is null Text and Graphic update failed"); - currentScreenDataUpdateListener.onError(); + currentScreenDataUpdateListener.onError(updatedState); finishOperation(false); return; } - } @SuppressWarnings("deprecation") @@ -171,7 +218,7 @@ class TextAndGraphicUpdateOperation extends Task { updateCurrentScreenDataFromSetDisplayLayout(setLayout); } else { DebugTool.logInfo(TAG, "Text and Graphic SetDisplayLayout failed"); - currentScreenDataUpdateListener.onError(); + currentScreenDataUpdateListener.onError(updatedState); } listener.onComplete(response.getSuccess()); } @@ -180,7 +227,7 @@ class TextAndGraphicUpdateOperation extends Task { internalInterface.get().sendRPC(setLayout); } else { DebugTool.logInfo(TAG, "ISdl is null Text and Graphic update failed"); - currentScreenDataUpdateListener.onError(); + currentScreenDataUpdateListener.onError(updatedState); finishOperation(false); return; } |