Skip to content

Commit c1d4d3c

Browse files
authored
Merge pull request #561 from smartdevicelink/bugfix/alert-manager-image-show-fix
Apply fix to alert icon not uploading
2 parents 63d3870 + 3f0a865 commit c1d4d3c

2 files changed

Lines changed: 86 additions & 22 deletions

File tree

lib/js/src/manager/screen/utils/_PresentAlertOperation.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class _PresentAlertOperation extends _Task {
6363
this._listener = listener;
6464
this._isAlertPresented = false;
6565
this._alertSoftButtonClearListener = alertSoftButtonClearListener;
66+
this._alertIconUploaded = false;
6667

6768
this._alertView.canceledListener = () => {
6869
this.cancelAlert();
@@ -168,7 +169,7 @@ class _PresentAlertOperation extends _Task {
168169

169170
console.log('Uploading audio files for alert');
170171

171-
if (this._fileManager !== null || this._fileManager !== undefined) {
172+
if (this._fileManager !== null) {
172173
const successes = await this._fileManager.uploadFiles(filesToBeUploaded);
173174

174175
if (this.getState() === _Task.CANCELED) {
@@ -192,15 +193,19 @@ class _PresentAlertOperation extends _Task {
192193
async uploadImages (listener) {
193194
const artworksToBeUploaded = [];
194195

195-
if (this.supportsAlertIcon() && this._fileManager !== null && this._fileManager.fileNeedsUpload(this._alertView.getIcon())) {
196-
artworksToBeUploaded.push(this._alertView.getIcon());
196+
if (this.supportsAlertIcon() && this._alertView.getIcon() !== null && this._alertView.getIcon() !== undefined && this._fileManager !== null) {
197+
if (this._fileManager.fileNeedsUpload(this._alertView.getIcon())) {
198+
artworksToBeUploaded.push(this._alertView.getIcon());
199+
} else if (this._fileManager.hasUploadedFile(this._alertView.getIcon()) || this._alertView.getIcon().isStaticIcon()) {
200+
this._alertIconUploaded = true;
201+
}
197202
}
198203

199204
if (this._alertView.getSoftButtons() !== null && this._alertView.getSoftButtons() !== undefined) {
200205
for (let index = 0; index < this._getSoftButtonCount(); index++) {
201-
const object = this._alertView.getSoftButtons()[index];
202-
if (this.supportsSoftButtonImages() && object.getCurrentState() !== null && object.getCurrentState() !== undefined && this._fileManager !== null && this._fileManager.fileNeedsUpload(object.getCurrentState().getArtwork())) {
203-
artworksToBeUploaded.push(object.getCurrentState().getArtwork());
206+
const objectState = this._alertView.getSoftButtons()[index].getCurrentState();
207+
if (this.supportsSoftButtonImages() && objectState !== null && objectState !== undefined && this._fileManager !== null && this._fileManager.fileNeedsUpload(objectState.getArtwork())) {
208+
artworksToBeUploaded.push(objectState.getArtwork());
204209
}
205210
}
206211
}
@@ -213,7 +218,7 @@ class _PresentAlertOperation extends _Task {
213218

214219
console.log('Uploading images for alert');
215220

216-
if (this._fileManager !== null && this._fileManager !== undefined) {
221+
if (this._fileManager !== null) {
217222
const successes = await this._fileManager.uploadArtworks(artworksToBeUploaded);
218223
if (this.getState() === _Task.CANCELED) {
219224
console.log('Operation canceled');
@@ -227,6 +232,17 @@ class _PresentAlertOperation extends _Task {
227232
} else {
228233
console.log('All alert images uploaded');
229234
}
235+
236+
const artworkNamesSuccessfullyUploaded = [];
237+
for (let index = 0; index < successes.length; index++) {
238+
// only keep artworks that have been uploaded successfully by the file manager
239+
if (successes[index]) {
240+
artworkNamesSuccessfullyUploaded.push(artworksToBeUploaded[index].getName());
241+
}
242+
}
243+
if (artworkNamesSuccessfullyUploaded.includes(this._alertView.getIcon().getName())) {
244+
this._alertIconUploaded = true;
245+
}
230246
listener(true);
231247
return;
232248
}
@@ -301,7 +317,7 @@ class _PresentAlertOperation extends _Task {
301317
alert = this.assembleAlertText(alert);
302318
alert.setDuration(this._alertView.getTimeout() * 1000);
303319

304-
if (this._alertView.getIcon() !== null && this._alertView.getIcon() !== undefined && this.supportsAlertIcon() && !this._fileManager.hasUploadedFile(this._alertView.getIcon())) {
320+
if (this._alertIconUploaded) {
305321
alert.setAlertIcon(this._alertView.getIcon().getImageRPC());
306322
}
307323

tests/managers/screen/PresentAlertOperationTests.js

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ module.exports = function (appClient) {
2323
speechCapabilities,
2424
alertCompletionListener,
2525
alertSoftButtonClearListener;
26+
2627
/**
2728
* Gets the windowCapability
2829
* @param {Number} numberOfAlertFields - number of lines
30+
* @param {Boolean} supportsAlertIcon - whether alert icon is supported by the capability
2931
* @returns {WindowCapability} - the capability
3032
*/
31-
function getWindowCapability (numberOfAlertFields) {
33+
function getWindowCapability (numberOfAlertFields, supportsAlertIcon) {
3234
const alertText1 = new SDL.rpc.structs.TextField();
3335
alertText1.setNameParam(SDL.rpc.enums.TextFieldName.alertText1);
3436
const alertText2 = new SDL.rpc.structs.TextField();
@@ -55,13 +57,13 @@ module.exports = function (appClient) {
5557
const windowCapability = new SDL.rpc.structs.WindowCapability();
5658
windowCapability.setTextFields(returnList);
5759

58-
const imageField = new SDL.rpc.structs.ImageField();
59-
imageField.setNameParam(SDL.rpc.enums.ImageFieldName.alertIcon);
60-
const imageFieldList = [];
61-
imageFieldList.push(imageField);
62-
windowCapability.setImageFields(imageFieldList);
63-
64-
windowCapability.setImageFields(imageFieldList);
60+
if (supportsAlertIcon) {
61+
const imageField = new SDL.rpc.structs.ImageField();
62+
imageField.setNameParam(SDL.rpc.enums.ImageFieldName.alertIcon);
63+
const imageFieldList = [];
64+
imageFieldList.push(imageField);
65+
windowCapability.setImageFields(imageFieldList);
66+
}
6567

6668
const softButtonCapabilities = new SDL.rpc.structs.SoftButtonCapabilities();
6769
softButtonCapabilities.setImageSupported(true);
@@ -135,7 +137,7 @@ module.exports = function (appClient) {
135137
alertView.setShowWaitIndicator(true);
136138
alertView.canceledListener = () => {};
137139

138-
defaultMainWindowCapability = getWindowCapability(3);
140+
defaultMainWindowCapability = getWindowCapability(3, true);
139141
speechCapabilities = [];
140142
speechCapabilities.push(SDL.rpc.enums.SpeechCapabilities.FILE);
141143
alertCompletionListener = new SDL.manager.screen.utils.AlertCompletionListener().setOnComplete((success, tryAgainTime) => {});
@@ -158,13 +160,13 @@ module.exports = function (appClient) {
158160
.setMinorVersion(0)
159161
.setPatchVersion(0);
160162
});
161-
let windowCapability = getWindowCapability(1);
163+
let windowCapability = getWindowCapability(1, true);
162164
let presentAlertOperation = new SDL.manager.screen.utils._PresentAlertOperation(lifecycleManager, alertView, windowCapability, speechCapabilities, fileManager, 1, () => {}, new SDL.manager.screen._AlertManagerBase._AlertSoftButtonClearListener().setOnButtonClear(() => {}));
163165
let alert = presentAlertOperation.alertRpc();
164166

165167
Validator.assertEquals(alert.getAlertText1(), `${alertView.getText()} - ${alertView.getSecondaryText()} - ${alertView.getTertiaryText()}`);
166168

167-
windowCapability = getWindowCapability(2);
169+
windowCapability = getWindowCapability(2, true);
168170

169171
presentAlertOperation = new SDL.manager.screen.utils._PresentAlertOperation(lifecycleManager, alertView, windowCapability, speechCapabilities, fileManager, 1, () => {}, new SDL.manager.screen._AlertManagerBase._AlertSoftButtonClearListener().setOnButtonClear(() => {}));
170172
alert = presentAlertOperation.alertRpc();
@@ -199,7 +201,7 @@ module.exports = function (appClient) {
199201
// Test Images need to be uploaded, sending text and uploading images
200202
await presentAlertOperation.onExecute();
201203

202-
// Verifies that uploadArtworks gets called only with the fist presentAlertOperation.onExecute call
204+
// Verifies that uploadArtworks gets called only with the first presentAlertOperation.onExecute call
203205
Validator.assertTrue(artStub.calledOnce);
204206
Validator.assertTrue(fileStub.calledOnce);
205207
Validator.assertTrue(alertStub.calledOnce);
@@ -234,7 +236,7 @@ module.exports = function (appClient) {
234236
// Test Images need to be uploaded, sending text and uploading images
235237
await presentAlertOperation._start();
236238

237-
// Verifies that uploadArtworks gets called only with the fist presentAlertOperation.onExecute call
239+
// Verifies that uploadArtworks gets called only with the first presentAlertOperation.onExecute call
238240
Validator.assertTrue(artStub.notCalled);
239241
Validator.assertTrue(fileStub.notCalled);
240242
Validator.assertTrue(alertStub.calledOnce);
@@ -262,7 +264,7 @@ module.exports = function (appClient) {
262264
// Test Images need to be uploaded, sending text and uploading images
263265
await presentAlertOperation._start();
264266

265-
// Verifies that uploadArtworks gets called only with the fist presentAlertOperation.onExecute call
267+
// Verifies that uploadArtworks gets called only with the first presentAlertOperation.onExecute call
266268
Validator.assertTrue(artStub.calledOnce);
267269
Validator.assertTrue(alertStub.calledOnce);
268270

@@ -281,5 +283,51 @@ module.exports = function (appClient) {
281283
Validator.assertTrue(callback.notCalled);
282284
stub.restore();
283285
});
286+
287+
it('testNoImageSetOnFailedUpload', async function () {
288+
const alertRpc = presentAlertOperation.alertRpc();
289+
Validator.assertNull(alertRpc.getAlertIcon());
290+
});
291+
292+
it('testImageSetOnSuccessfulUpload', async function () {
293+
presentAlertOperation._alertIconUploaded = true;
294+
const alertRpc = presentAlertOperation.alertRpc();
295+
Validator.assertEquals(alertRpc.getAlertIcon().getValueParam(), alertView.getIcon().getName());
296+
});
297+
298+
it('testPresentStaticIcon', async function () {
299+
const alertStub = sinon.stub(lifecycleManager, 'sendRpcResolve')
300+
.callsFake(onAlertSuccess);
301+
const artStub = sinon.stub(fileManager, 'uploadArtworks')
302+
.callsFake(onArtworkUploadSuccess);
303+
const fileStub = sinon.stub(fileManager, 'uploadFiles')
304+
.callsFake(onArtworkUploadSuccess);
305+
const versionStub = sinon.stub(lifecycleManager, 'getSdlMsgVersion')
306+
.callsFake(function () {
307+
return new SDL.rpc.structs.SdlMsgVersion()
308+
.setMajorVersion(6)
309+
.setMinorVersion(0)
310+
.setPatchVersion(0);
311+
});
312+
313+
314+
testAlertArtwork = new SDL.manager.file.filetypes.SdlArtwork(SDL.manager.file.enums.StaticIconName.LEFT);
315+
testAlertArtwork.setStaticIcon(true);
316+
alertView.setIcon(testAlertArtwork);
317+
alertView.setSoftButtons([]);
318+
319+
presentAlertOperation = new SDL.manager.screen.utils._PresentAlertOperation(lifecycleManager, alertView, defaultMainWindowCapability, speechCapabilities, fileManager, 1, alertCompletionListener, alertSoftButtonClearListener);
320+
// Test Images need to be uploaded, sending text and uploading images
321+
await presentAlertOperation._start();
322+
323+
// upload artworks should not be called since this is a static icon
324+
Validator.assertTrue(artStub.notCalled);
325+
Validator.assertTrue(alertStub.calledOnce);
326+
327+
versionStub.restore();
328+
fileStub.restore();
329+
artStub.restore();
330+
alertStub.restore();
331+
});
284332
});
285333
};

0 commit comments

Comments
 (0)