summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Kast <julian.kast@live.com>2022-09-23 13:11:36 -0400
committerGitHub <noreply@github.com>2022-09-23 13:11:36 -0400
commit518da6e2c2c22a8fded40b1d0dc368a8f6bf33fc (patch)
tree32e8c2a347903aa417f2b5841e92238d0c53f759
parent2a0b6552d79e8f2de4904dc32f6cbb4e0824e605 (diff)
downloadsdl_android-518da6e2c2c22a8fded40b1d0dc368a8f6bf33fc.tar.gz
Bugfix/issue 1835 AlertManager File upload fix (#1836)
* Refactor logic to remove ! when checking if file has uploaded when deciding to add image to AlertRPC * update test to cover change in PresentAlertOperation * Update test case for adding imageRPC to Alert * Update Unit test to test no Icon capability when creating AlertRPC * Remove added unnecessary code * Change hasUploaded file to filesNeedsUpload * Fix unit test * Add boolean var to check if Alert icon has been uploaded * fix existing unit test base on changes made * test staticIcon file upload * Test removing unnecessary test * Clean up unit test * Remove unused import
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/PresentAlertOperationTest.java40
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/PresentAlertOperation.java21
2 files changed, 43 insertions, 18 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/PresentAlertOperationTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/PresentAlertOperationTest.java
index 5f69010f1..4e105e1f8 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/PresentAlertOperationTest.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/PresentAlertOperationTest.java
@@ -27,6 +27,7 @@ import com.smartdevicelink.proxy.rpc.WindowCapability;
import com.smartdevicelink.proxy.rpc.enums.FileType;
import com.smartdevicelink.proxy.rpc.enums.ImageFieldName;
import com.smartdevicelink.proxy.rpc.enums.SpeechCapabilities;
+import com.smartdevicelink.proxy.rpc.enums.StaticIconName;
import com.smartdevicelink.proxy.rpc.enums.TextFieldName;
import com.smartdevicelink.test.TestValues;
@@ -42,7 +43,6 @@ import java.util.List;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
import static junit.framework.TestCase.assertEquals;
-import static junit.framework.TestCase.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
@@ -167,7 +167,7 @@ public class PresentAlertOperationTest {
builder.setShowWaitIndicator(true);
alertView = builder.build();
- defaultMainWindowCapability = getWindowCapability(3);
+ defaultMainWindowCapability = getWindowCapability(3, true);
speechCapabilities = new ArrayList<SpeechCapabilities>();
speechCapabilities.add(SpeechCapabilities.FILE);
alertCompletionListener = new AlertCompletionListener() {
@@ -186,13 +186,13 @@ public class PresentAlertOperationTest {
// Same response works for uploading artworks as it does for files
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(6, 0));
- WindowCapability windowCapability = getWindowCapability(1);
+ WindowCapability windowCapability = getWindowCapability(1, true);
PresentAlertOperation presentAlertOperation = new PresentAlertOperation(internalInterface, alertView, windowCapability, speechCapabilities, fileManager, 1, alertCompletionListener, alertSoftButtonClearListener);
Alert alert = presentAlertOperation.alertRpc();
assertEquals(alert.getAlertText1(), alertView.getText() + " - " + alertView.getSecondaryText() + " - " + alertView.getTertiaryText());
- windowCapability = getWindowCapability(2);
+ windowCapability = getWindowCapability(2, true);
presentAlertOperation = new PresentAlertOperation(internalInterface, alertView, windowCapability, speechCapabilities, fileManager, 1, alertCompletionListener, alertSoftButtonClearListener);
alert = presentAlertOperation.alertRpc();
@@ -258,7 +258,23 @@ public class PresentAlertOperationTest {
verify(fileManager, times(1)).uploadArtworks(any(List.class), any(MultipleFileCompletionListener.class));
verify(internalInterface, times(1)).sendRPC(any(Alert.class));
}
+ @Test
+ public void testPresentStaticIcon() {
+ doAnswer(onAlertSuccess).when(internalInterface).sendRPC(any(Alert.class));
+ // Same response works for uploading artworks as it does for files
+ when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(6, 0));
+ when(fileManager.fileNeedsUpload(any(SdlFile.class))).thenReturn(false);
+
+ alertView.setIcon(new SdlArtwork(StaticIconName.LEFT));
+ PresentAlertOperation presentAlertOperationStaticIcon = new PresentAlertOperation(internalInterface, alertView, defaultMainWindowCapability, speechCapabilities, fileManager, 1, alertCompletionListener, alertSoftButtonClearListener);
+
+ // Test Images need to be uploaded, sending text and uploading images
+ presentAlertOperationStaticIcon.onExecute();
+ // Verifies that uploadArtworks gets called only with the fist presentAlertOperation.onExecute call
+ verify(fileManager, times(0)).uploadArtworks(any(List.class), any(MultipleFileCompletionListener.class));
+ verify(internalInterface, times(1)).sendRPC(any(Alert.class));
+ }
@Test
public void testCancelOperation() {
//Cancel right away
@@ -267,7 +283,7 @@ public class PresentAlertOperationTest {
verify(internalInterface, times(0)).sendRPC(any(Alert.class));
}
- private WindowCapability getWindowCapability(int numberOfAlertFields) {
+ private WindowCapability getWindowCapability(int numberOfAlertFields, boolean supportsAlertIcon) {
TextField alertText1 = new TextField();
alertText1.setName(TextFieldName.alertText1);
TextField alertText2 = new TextField();
@@ -294,13 +310,13 @@ public class PresentAlertOperationTest {
WindowCapability windowCapability = new WindowCapability();
windowCapability.setTextFields(returnList);
- ImageField imageField = new ImageField();
- imageField.setName(ImageFieldName.alertIcon);
- List<ImageField> imageFieldList = new ArrayList<>();
- imageFieldList.add(imageField);
- windowCapability.setImageFields(imageFieldList);
-
- windowCapability.setImageFields(imageFieldList);
+ if (supportsAlertIcon) {
+ ImageField imageField = new ImageField();
+ imageField.setName(ImageFieldName.alertIcon);
+ List<ImageField> imageFieldList = new ArrayList<>();
+ imageFieldList.add(imageField);
+ windowCapability.setImageFields(imageFieldList);
+ }
SoftButtonCapabilities softButtonCapabilities = new SoftButtonCapabilities();
softButtonCapabilities.setImageSupported(TestValues.GENERAL_BOOLEAN);
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/PresentAlertOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/PresentAlertOperation.java
index a85901d3c..31163627c 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/PresentAlertOperation.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/PresentAlertOperation.java
@@ -77,6 +77,8 @@ public class PresentAlertOperation extends Task {
boolean isAlertPresented;
static int SOFTBUTTON_COUNT = 4;
private BaseAlertManager.AlertSoftButtonClearListener alertSoftButtonClearListener;
+ Boolean alertIconUploaded;
+ private List<SdlArtwork> artworksToBeUploaded;
public PresentAlertOperation(ISdl internalInterface, AlertView alertView, WindowCapability currentCapabilities, List<SpeechCapabilities> speechCapabilities, FileManager fileManager, Integer cancelId, AlertCompletionListener listener, BaseAlertManager.AlertSoftButtonClearListener alertSoftButtonClearListener) {
super("PresentAlertOperation");
@@ -89,6 +91,7 @@ public class PresentAlertOperation extends Task {
this.cancelId = cancelId;
this.isAlertPresented = false;
this.alertSoftButtonClearListener = alertSoftButtonClearListener;
+ alertIconUploaded = false;
this.alertView.canceledListener = new AlertCanceledListener() {
@Override
@@ -237,10 +240,15 @@ public class PresentAlertOperation extends Task {
* @param listener - CompletionListener called when all images have been uploaded.
*/
private void uploadImages(final CompletionListener listener) {
- List<SdlArtwork> artworksToBeUploaded = new ArrayList<>();
+ artworksToBeUploaded = new ArrayList<>();
- if (supportsAlertIcon() && fileManager.get() != null && fileManager.get().fileNeedsUpload(alertView.getIcon())) {
- artworksToBeUploaded.add(alertView.getIcon());
+ if (supportsAlertIcon() && alertView.getIcon() != null && fileManager.get() != null) {
+ if (fileManager.get().fileNeedsUpload(alertView.getIcon())) {
+ artworksToBeUploaded.add(alertView.getIcon());
+
+ } else if (fileManager.get().hasUploadedFile(alertView.getIcon()) || alertView.getIcon().isStaticIcon()) {
+ alertIconUploaded = true;
+ }
}
if (alertView.getSoftButtons() != null) {
@@ -275,6 +283,9 @@ public class PresentAlertOperation extends Task {
} else {
DebugTool.logInfo(TAG, "All alert images uploaded");
}
+ if (artworksToBeUploaded.contains(alertView.getIcon()) && (errors == null || !errors.containsKey(alertView.getIcon().getName()))) {
+ alertIconUploaded = true;
+ }
listener.onComplete(true);
}
});
@@ -362,9 +373,7 @@ public class PresentAlertOperation extends Task {
alert = assembleAlertText(alert);
alert.setDuration(alertView.getTimeout() * 1000);
- if (alertView.getIcon() != null && supportsAlertIcon() && !(fileManager.get().hasUploadedFile(alertView.getIcon()))) {
- alert.setAlertIcon(alertView.getIcon().getImageRPC());
- }
+ alert.setAlertIcon(alertIconUploaded ? alertView.getIcon().getImageRPC() : null);
alert.setProgressIndicator(alertView.isShowWaitIndicator());
alert.setCancelID(this.cancelId);