Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;

Expand All @@ -42,7 +43,6 @@

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;
Expand Down Expand Up @@ -167,7 +167,7 @@ public void onEvent(SoftButtonObject softButtonObject, OnButtonEvent onButtonEve
builder.setShowWaitIndicator(true);
alertView = builder.build();

defaultMainWindowCapability = getWindowCapability(3);
defaultMainWindowCapability = getWindowCapability(3, true);
speechCapabilities = new ArrayList<SpeechCapabilities>();
speechCapabilities.add(SpeechCapabilities.FILE);
alertCompletionListener = new AlertCompletionListener() {
Expand All @@ -186,13 +186,13 @@ public void testPresentAlertTruncatedText() {
// 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();
Expand Down Expand Up @@ -258,7 +258,23 @@ public void testPresentAlertNoImages() {
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
Expand All @@ -267,7 +283,7 @@ public void testCancelOperation() {
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();
Expand All @@ -294,13 +310,13 @@ private WindowCapability getWindowCapability(int numberOfAlertFields) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -89,6 +91,7 @@ public PresentAlertOperation(ISdl internalInterface, AlertView alertView, Window
this.cancelId = cancelId;
this.isAlertPresented = false;
this.alertSoftButtonClearListener = alertSoftButtonClearListener;
alertIconUploaded = false;

this.alertView.canceledListener = new AlertCanceledListener() {
@Override
Expand Down Expand Up @@ -237,10 +240,15 @@ public void onComplete(Map<String, String> errors) {
* @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) {
Expand Down Expand Up @@ -275,6 +283,9 @@ public void onComplete(Map<String, String> errors) {
} 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);
}
});
Expand Down Expand Up @@ -362,9 +373,7 @@ Alert alertRpc() {
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);
Expand Down