summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2022-09-21 15:52:41 -0400
committerJoel Fischer <joeljfischer@gmail.com>2022-09-21 15:52:41 -0400
commit3c6d4a016b8e06360e8d1bc827f4efc89c2d6149 (patch)
tree76df6741a65b64ef1fb828fce0cf7b7af91a93bc
parent9aec1f6391d109faabbfe335f3bf90e5a5e00ac1 (diff)
downloadsdl_ios-3c6d4a016b8e06360e8d1bc827f4efc89c2d6149.tar.gz
Issue #2109 - Track uploaded image names
* If the alert icon image wasn't successfully uploaded, don't show it (fixes a case where an overwriting image could fail and the old image could show) * Fix tests
-rw-r--r--SmartDeviceLink/private/SDLPresentAlertOperation.m25
-rw-r--r--SmartDeviceLinkTests/SDLPresentAlertOperationSpec.m20
2 files changed, 31 insertions, 14 deletions
diff --git a/SmartDeviceLink/private/SDLPresentAlertOperation.m b/SmartDeviceLink/private/SDLPresentAlertOperation.m
index 9359106f5..386b8d0a1 100644
--- a/SmartDeviceLink/private/SDLPresentAlertOperation.m
+++ b/SmartDeviceLink/private/SDLPresentAlertOperation.m
@@ -67,6 +67,8 @@ static const int SDLAlertSoftButtonCount = 4;
@property (copy, nonatomic, nullable) NSError *internalError;
@property (assign, atomic) BOOL isAlertPresented;
+@property (strong, nonatomic) NSMutableSet<NSString *> *uploadedImageNames;
+
@end
@implementation SDLPresentAlertOperation
@@ -90,6 +92,7 @@ static const int SDLAlertSoftButtonCount = 4;
_cancelId = cancelID;
_operationId = [NSUUID UUID];
_currentWindowCapability = currentWindowCapability;
+ _uploadedImageNames = [NSMutableSet set];
return self;
}
@@ -193,15 +196,25 @@ static const int SDLAlertSoftButtonCount = 4;
/// @param handler Called when all images have been uploaded.
- (void)sdl_uploadImagesWithCompletionHandler:(void (^)(void))handler {
NSMutableArray<SDLArtwork *> *artworksToBeUploaded = [NSMutableArray array];
- if ([self sdl_supportsAlertIcon] && [self.fileManager fileNeedsUpload:self.alertView.icon]) {
- [artworksToBeUploaded addObject:self.alertView.icon];
+ if ([self sdl_supportsAlertIcon] && (self.alertView.icon != nil)) {
+ if ([self.fileManager fileNeedsUpload:self.alertView.icon]) {
+ // If the file is not uploaded, attempt to upload it
+ [artworksToBeUploaded addObject:self.alertView.icon];
+ } else if ([self.fileManager hasUploadedFile:self.alertView.icon] || self.alertView.icon.isStaticIcon) {
+ // If the file is already uploaded, add it to the uploaded set so we can show it
+ [self.uploadedImageNames addObject:self.alertView.icon.name];
+ }
}
// Don't upload artworks for buttons that will not be shown.
for (NSUInteger i = 0; i < [self sdl_softButtonCount]; i++) {
SDLSoftButtonObject *object = self.alertView.softButtons[i];
- if ([self sdl_supportsSoftButtonImages] && [self.fileManager fileNeedsUpload:object.currentState.artwork]) {
- [artworksToBeUploaded addObject:object.currentState.artwork];
+ if ([self sdl_supportsSoftButtonImages]) {
+ if ([self.fileManager fileNeedsUpload:object.currentState.artwork]) {
+ [artworksToBeUploaded addObject:object.currentState.artwork];
+ } else if ([self.fileManager hasUploadedFile:object.currentState.artwork] || object.currentState.artwork.isStaticIcon) {
+ [self.uploadedImageNames addObject:self.alertView.icon.name];
+ }
}
}
@@ -219,12 +232,14 @@ static const int SDLAlertSoftButtonCount = 4;
return YES;
} completionHandler:^(NSArray<NSString *> * _Nonnull artworkNames, NSError * _Nullable error) {
+ __strong typeof(weakself) strongself = weakself;
if (error != nil) {
SDLLogE(@"Error uploading alert images: %@", error);
} else {
SDLLogD(@"All alert images uploaded");
}
+ [strongself.uploadedImageNames addObjectsFromArray:artworkNames];
return handler();
}];
}
@@ -293,7 +308,7 @@ static const int SDLAlertSoftButtonCount = 4;
SDLAlert *alert = [[SDLAlert alloc] init];
[self sdl_assembleAlertText:alert];
alert.duration = @((NSUInteger)(self.alertView.timeout * 1000));
- alert.alertIcon = ([self sdl_supportsAlertIcon] && ![self.fileManager fileNeedsUpload:self.alertView.icon]) ? self.alertView.icon.imageRPC : nil;
+ alert.alertIcon = [self.uploadedImageNames containsObject:self.alertView.icon.name] ? self.alertView.icon.imageRPC : nil;
alert.progressIndicator = @(self.alertView.showWaitIndicator);
alert.cancelID = @(self.cancelId);
diff --git a/SmartDeviceLinkTests/SDLPresentAlertOperationSpec.m b/SmartDeviceLinkTests/SDLPresentAlertOperationSpec.m
index 78dda1e82..b464a37fd 100644
--- a/SmartDeviceLinkTests/SDLPresentAlertOperationSpec.m
+++ b/SmartDeviceLinkTests/SDLPresentAlertOperationSpec.m
@@ -42,6 +42,7 @@
@property (strong, nonatomic, readwrite) SDLAlertView *alertView;
@property (assign, nonatomic) UInt16 cancelId;
@property (copy, nonatomic, nullable) NSError *internalError;
+@property (strong, nonatomic) NSSet<NSString *> *uploadedImageNames;
- (nullable NSError *)sdl_isValidAlertViewData:(SDLAlertView *)alertView;
- (SDLAlert *)alertRPC;
@@ -365,16 +366,16 @@ describe(@"SDLPresentAlertOperation", ^{
testPresentAlertOperation = [[SDLPresentAlertOperation alloc] initWithConnectionManager:mockConnectionManager fileManager:mockFileManager systemCapabilityManager:mockSystemCapabilityManager currentWindowCapability:mockCurrentWindowCapability alertView:testAlertView cancelID:testCancelID];
});
- it(@"should set the image if icons are supported on the module", ^{
- OCMStub([mockCurrentWindowCapability hasImageFieldOfName:SDLImageFieldNameAlertIcon]).andReturn(YES);
+ it(@"should not set the image if it fails to upload to the module", ^{
SDLAlert *testAlert = testPresentAlertOperation.alertRPC;
- expect(testAlert.alertIcon.value).to(equal(testAlertView.icon.name));
+ expect(testAlert.alertIcon.value).to(beNil());
});
- it(@"should not set the image if icons are not supported on the module", ^{
- OCMStub([mockCurrentWindowCapability hasImageFieldOfName:SDLImageFieldNameAlertIcon]).andReturn(NO);
+ it(@"should set the image if it is uploaded to the module", ^{
+ testPresentAlertOperation.uploadedImageNames = [NSSet setWithObject:testAlertView.icon.name];
+
SDLAlert *testAlert = testPresentAlertOperation.alertRPC;
- expect(testAlert.alertIcon).to(beNil());
+ expect(testAlert.alertIcon.value).to(equal(testAlertView.icon.name));
});
});
});
@@ -781,6 +782,7 @@ describe(@"SDLPresentAlertOperation", ^{
testAlertViewWithExtraSoftButtons = [[SDLAlertView alloc] initWithText:@"text" secondaryText:@"secondaryText" tertiaryText:@"tertiaryText" timeout:@(4) showWaitIndicator:@(YES) audioIndication:testAlertAudioData buttons:@[testAlertSoftButton1, testAlertSoftButton2, testAlertSoftButton3, testAlertSoftButton4, testAlertSoftButton5, testAlertSoftButton6] icon:testAlertIcon];
testPresentAlertOperation = [[SDLPresentAlertOperation alloc] initWithConnectionManager:mockConnectionManager fileManager:mockFileManager systemCapabilityManager:mockSystemCapabilityManager currentWindowCapability:mockCurrentWindowCapability alertView:testAlertViewWithExtraSoftButtons cancelID:testCancelID];
+ testPresentAlertOperation.uploadedImageNames = [NSSet setWithObject:testAlertViewWithExtraSoftButtons.icon.name];
testPresentAlertOperation.completionBlock = ^{
hasCalledOperationCompletionHandler = YES;
@@ -829,7 +831,7 @@ describe(@"SDLPresentAlertOperation", ^{
testSoftButtonCapabilities.imageSupported = @YES;
OCMStub([mockCurrentWindowCapability softButtonCapabilities]).andReturn(@[testSoftButtonCapabilities]);
OCMStub([mockFileManager fileNeedsUpload:[OCMArg any]]).andReturn(YES);
- OCMStub([mockFileManager uploadArtworks:[OCMArg any] progressHandler:[OCMArg invokeBlock] completionHandler:([OCMArg invokeBlockWithArgs: @[testAlertView.icon.name], [NSNull null], nil])]);
+ OCMStub([mockFileManager uploadArtworks:[OCMArg any] progressHandler:[OCMArg invokeBlock] completionHandler:([OCMArg invokeBlockWithArgs: @[], [NSNull null], nil])]);
OCMStub([mockFileManager uploadFiles:[OCMArg any] progressHandler:[OCMArg invokeBlock] completionHandler:[OCMArg invokeBlock]]);
SDLVersion *supportedVersion = [SDLVersion versionWithMajor:6 minor:3 patch:0];
@@ -883,8 +885,8 @@ describe(@"SDLPresentAlertOperation", ^{
SDLSoftButtonCapabilities *testSoftButtonCapabilities = [[SDLSoftButtonCapabilities alloc] init];
testSoftButtonCapabilities.imageSupported = @YES;
OCMStub([mockCurrentWindowCapability softButtonCapabilities]).andReturn(@[testSoftButtonCapabilities]);
- OCMStub([mockFileManager fileNeedsUpload:[OCMArg any]]).andReturn(NO);
- OCMStub([mockFileManager uploadArtworks:[OCMArg any] progressHandler:[OCMArg invokeBlock] completionHandler:[OCMArg invokeBlock]]);
+ OCMStub([mockFileManager fileNeedsUpload:[OCMArg any]]).andReturn(YES);
+ OCMStub([mockFileManager uploadArtworks:[OCMArg any] progressHandler:[OCMArg invokeBlock] completionHandler:([OCMArg invokeBlockWithArgs: @[testAlertView.icon.name], [NSNull null], nil])]);
OCMStub([mockFileManager uploadFiles:[OCMArg any] progressHandler:[OCMArg invokeBlock] completionHandler:[OCMArg invokeBlock]]);
SDLVersion *supportedVersion = [SDLVersion versionWithMajor:6 minor:3 patch:0];