Skip to content

Commit 518da6e

Browse files
authored
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
1 parent 2a0b655 commit 518da6e

File tree

2 files changed

+43
-18
lines changed

2 files changed

+43
-18
lines changed

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/PresentAlertOperationTest.java

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.smartdevicelink.proxy.rpc.enums.FileType;
2828
import com.smartdevicelink.proxy.rpc.enums.ImageFieldName;
2929
import com.smartdevicelink.proxy.rpc.enums.SpeechCapabilities;
30+
import com.smartdevicelink.proxy.rpc.enums.StaticIconName;
3031
import com.smartdevicelink.proxy.rpc.enums.TextFieldName;
3132
import com.smartdevicelink.test.TestValues;
3233

@@ -42,7 +43,6 @@
4243

4344
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
4445
import static junit.framework.TestCase.assertEquals;
45-
import static junit.framework.TestCase.assertTrue;
4646
import static org.mockito.ArgumentMatchers.any;
4747
import static org.mockito.Mockito.doAnswer;
4848
import static org.mockito.Mockito.mock;
@@ -167,7 +167,7 @@ public void onEvent(SoftButtonObject softButtonObject, OnButtonEvent onButtonEve
167167
builder.setShowWaitIndicator(true);
168168
alertView = builder.build();
169169

170-
defaultMainWindowCapability = getWindowCapability(3);
170+
defaultMainWindowCapability = getWindowCapability(3, true);
171171
speechCapabilities = new ArrayList<SpeechCapabilities>();
172172
speechCapabilities.add(SpeechCapabilities.FILE);
173173
alertCompletionListener = new AlertCompletionListener() {
@@ -186,13 +186,13 @@ public void testPresentAlertTruncatedText() {
186186
// Same response works for uploading artworks as it does for files
187187

188188
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(6, 0));
189-
WindowCapability windowCapability = getWindowCapability(1);
189+
WindowCapability windowCapability = getWindowCapability(1, true);
190190
PresentAlertOperation presentAlertOperation = new PresentAlertOperation(internalInterface, alertView, windowCapability, speechCapabilities, fileManager, 1, alertCompletionListener, alertSoftButtonClearListener);
191191
Alert alert = presentAlertOperation.alertRpc();
192192

193193
assertEquals(alert.getAlertText1(), alertView.getText() + " - " + alertView.getSecondaryText() + " - " + alertView.getTertiaryText());
194194

195-
windowCapability = getWindowCapability(2);
195+
windowCapability = getWindowCapability(2, true);
196196

197197
presentAlertOperation = new PresentAlertOperation(internalInterface, alertView, windowCapability, speechCapabilities, fileManager, 1, alertCompletionListener, alertSoftButtonClearListener);
198198
alert = presentAlertOperation.alertRpc();
@@ -258,7 +258,23 @@ public void testPresentAlertNoImages() {
258258
verify(fileManager, times(1)).uploadArtworks(any(List.class), any(MultipleFileCompletionListener.class));
259259
verify(internalInterface, times(1)).sendRPC(any(Alert.class));
260260
}
261+
@Test
262+
public void testPresentStaticIcon() {
263+
doAnswer(onAlertSuccess).when(internalInterface).sendRPC(any(Alert.class));
264+
// Same response works for uploading artworks as it does for files
265+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(6, 0));
266+
when(fileManager.fileNeedsUpload(any(SdlFile.class))).thenReturn(false);
267+
268+
alertView.setIcon(new SdlArtwork(StaticIconName.LEFT));
269+
PresentAlertOperation presentAlertOperationStaticIcon = new PresentAlertOperation(internalInterface, alertView, defaultMainWindowCapability, speechCapabilities, fileManager, 1, alertCompletionListener, alertSoftButtonClearListener);
270+
271+
// Test Images need to be uploaded, sending text and uploading images
272+
presentAlertOperationStaticIcon.onExecute();
261273

274+
// Verifies that uploadArtworks gets called only with the fist presentAlertOperation.onExecute call
275+
verify(fileManager, times(0)).uploadArtworks(any(List.class), any(MultipleFileCompletionListener.class));
276+
verify(internalInterface, times(1)).sendRPC(any(Alert.class));
277+
}
262278
@Test
263279
public void testCancelOperation() {
264280
//Cancel right away
@@ -267,7 +283,7 @@ public void testCancelOperation() {
267283
verify(internalInterface, times(0)).sendRPC(any(Alert.class));
268284
}
269285

270-
private WindowCapability getWindowCapability(int numberOfAlertFields) {
286+
private WindowCapability getWindowCapability(int numberOfAlertFields, boolean supportsAlertIcon) {
271287
TextField alertText1 = new TextField();
272288
alertText1.setName(TextFieldName.alertText1);
273289
TextField alertText2 = new TextField();
@@ -294,13 +310,13 @@ private WindowCapability getWindowCapability(int numberOfAlertFields) {
294310
WindowCapability windowCapability = new WindowCapability();
295311
windowCapability.setTextFields(returnList);
296312

297-
ImageField imageField = new ImageField();
298-
imageField.setName(ImageFieldName.alertIcon);
299-
List<ImageField> imageFieldList = new ArrayList<>();
300-
imageFieldList.add(imageField);
301-
windowCapability.setImageFields(imageFieldList);
302-
303-
windowCapability.setImageFields(imageFieldList);
313+
if (supportsAlertIcon) {
314+
ImageField imageField = new ImageField();
315+
imageField.setName(ImageFieldName.alertIcon);
316+
List<ImageField> imageFieldList = new ArrayList<>();
317+
imageFieldList.add(imageField);
318+
windowCapability.setImageFields(imageFieldList);
319+
}
304320

305321
SoftButtonCapabilities softButtonCapabilities = new SoftButtonCapabilities();
306322
softButtonCapabilities.setImageSupported(TestValues.GENERAL_BOOLEAN);

base/src/main/java/com/smartdevicelink/managers/screen/PresentAlertOperation.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public class PresentAlertOperation extends Task {
7777
boolean isAlertPresented;
7878
static int SOFTBUTTON_COUNT = 4;
7979
private BaseAlertManager.AlertSoftButtonClearListener alertSoftButtonClearListener;
80+
Boolean alertIconUploaded;
81+
private List<SdlArtwork> artworksToBeUploaded;
8082

8183
public PresentAlertOperation(ISdl internalInterface, AlertView alertView, WindowCapability currentCapabilities, List<SpeechCapabilities> speechCapabilities, FileManager fileManager, Integer cancelId, AlertCompletionListener listener, BaseAlertManager.AlertSoftButtonClearListener alertSoftButtonClearListener) {
8284
super("PresentAlertOperation");
@@ -89,6 +91,7 @@ public PresentAlertOperation(ISdl internalInterface, AlertView alertView, Window
8991
this.cancelId = cancelId;
9092
this.isAlertPresented = false;
9193
this.alertSoftButtonClearListener = alertSoftButtonClearListener;
94+
alertIconUploaded = false;
9295

9396
this.alertView.canceledListener = new AlertCanceledListener() {
9497
@Override
@@ -237,10 +240,15 @@ public void onComplete(Map<String, String> errors) {
237240
* @param listener - CompletionListener called when all images have been uploaded.
238241
*/
239242
private void uploadImages(final CompletionListener listener) {
240-
List<SdlArtwork> artworksToBeUploaded = new ArrayList<>();
243+
artworksToBeUploaded = new ArrayList<>();
241244

242-
if (supportsAlertIcon() && fileManager.get() != null && fileManager.get().fileNeedsUpload(alertView.getIcon())) {
243-
artworksToBeUploaded.add(alertView.getIcon());
245+
if (supportsAlertIcon() && alertView.getIcon() != null && fileManager.get() != null) {
246+
if (fileManager.get().fileNeedsUpload(alertView.getIcon())) {
247+
artworksToBeUploaded.add(alertView.getIcon());
248+
249+
} else if (fileManager.get().hasUploadedFile(alertView.getIcon()) || alertView.getIcon().isStaticIcon()) {
250+
alertIconUploaded = true;
251+
}
244252
}
245253

246254
if (alertView.getSoftButtons() != null) {
@@ -275,6 +283,9 @@ public void onComplete(Map<String, String> errors) {
275283
} else {
276284
DebugTool.logInfo(TAG, "All alert images uploaded");
277285
}
286+
if (artworksToBeUploaded.contains(alertView.getIcon()) && (errors == null || !errors.containsKey(alertView.getIcon().getName()))) {
287+
alertIconUploaded = true;
288+
}
278289
listener.onComplete(true);
279290
}
280291
});
@@ -362,9 +373,7 @@ Alert alertRpc() {
362373
alert = assembleAlertText(alert);
363374
alert.setDuration(alertView.getTimeout() * 1000);
364375

365-
if (alertView.getIcon() != null && supportsAlertIcon() && !(fileManager.get().hasUploadedFile(alertView.getIcon()))) {
366-
alert.setAlertIcon(alertView.getIcon().getImageRPC());
367-
}
376+
alert.setAlertIcon(alertIconUploaded ? alertView.getIcon().getImageRPC() : null);
368377

369378
alert.setProgressIndicator(alertView.isShowWaitIndicator());
370379
alert.setCancelID(this.cancelId);

0 commit comments

Comments
 (0)