summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2022-09-23 09:22:53 -0400
committerGitHub <noreply@github.com>2022-09-23 09:22:53 -0400
commit7c031cb1a616cd361076368af18e6dd2bcdf6129 (patch)
treeeccc1fe75ea18e66c92e19d091a1c65316a28e84
parentbbdaa7bf0d24498cd6aefd4582d8128c23640e8e (diff)
parent58cd0a0e391348e3edfad5446b464324c14d8cd9 (diff)
downloadsdl_ios-7c031cb1a616cd361076368af18e6dd2bcdf6129.tar.gz
Merge pull request #2110 from smartdevicelink/bugfix/issue-2109-alert-overwrite-fail7.6.0-rc.1
Fix overwriting alert view images not being shown
-rw-r--r--SmartDeviceLink/private/SDLPresentAlertOperation.m18
-rw-r--r--SmartDeviceLinkTests/SDLPresentAlertOperationSpec.m39
2 files changed, 45 insertions, 12 deletions
diff --git a/SmartDeviceLink/private/SDLPresentAlertOperation.m b/SmartDeviceLink/private/SDLPresentAlertOperation.m
index 9359106f5..28ecec877 100644
--- a/SmartDeviceLink/private/SDLPresentAlertOperation.m
+++ b/SmartDeviceLink/private/SDLPresentAlertOperation.m
@@ -66,6 +66,7 @@ static const int SDLAlertSoftButtonCount = 4;
@property (assign, nonatomic) UInt16 cancelId;
@property (copy, nonatomic, nullable) NSError *internalError;
@property (assign, atomic) BOOL isAlertPresented;
+@property (assign, nonatomic) BOOL alertIconUploaded;
@end
@@ -90,6 +91,7 @@ static const int SDLAlertSoftButtonCount = 4;
_cancelId = cancelID;
_operationId = [NSUUID UUID];
_currentWindowCapability = currentWindowCapability;
+ _alertIconUploaded = NO;
return self;
}
@@ -193,8 +195,14 @@ 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.alertIconUploaded = YES;
+ }
}
// Don't upload artworks for buttons that will not be shown.
@@ -219,12 +227,16 @@ 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");
}
+ if ([artworkNames containsObject:strongself.alertView.icon.name]) {
+ strongself.alertIconUploaded = YES;
+ }
return handler();
}];
}
@@ -293,7 +305,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.alertIconUploaded ? 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..4173b923d 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 (assign, nonatomic) BOOL alertIconUploaded;
- (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.alertIconUploaded = YES;
+
SDLAlert *testAlert = testPresentAlertOperation.alertRPC;
- expect(testAlert.alertIcon).to(beNil());
+ expect(testAlert.alertIcon.value).to(equal(testAlertView.icon.name));
});
});
});
@@ -635,6 +636,25 @@ describe(@"SDLPresentAlertOperation", ^{
OCMVerifyAll(strictMockSystemCapabilityManager);
OCMVerifyAll(strictMockCurrentWindowCapability);
});
+
+ it(@"should not upload the image if the alert icon is a static icon", ^{
+ SDLAlertView *alertView = [[SDLAlertView alloc] initWithText:@"Test" secondaryText:nil tertiaryText:nil timeout:nil showWaitIndicator:nil audioIndication:nil buttons:nil icon:[SDLArtwork artworkWithStaticIcon:SDLStaticIconNameKey]];
+ testPresentAlertOperation = [[SDLPresentAlertOperation alloc] initWithConnectionManager:mockConnectionManager fileManager:strictMockFileManager systemCapabilityManager:strictMockSystemCapabilityManager currentWindowCapability:strictMockCurrentWindowCapability alertView:alertView cancelID:testCancelID];
+
+ OCMStub([strictMockCurrentWindowCapability hasImageFieldOfName:SDLImageFieldNameAlertIcon]).andReturn(YES);
+ OCMStub([strictMockFileManager hasUploadedFile:[OCMArg any]]).andReturn(NO);
+ OCMStub([strictMockFileManager fileNeedsUpload:[OCMArg any]]).andReturn(NO);
+
+ OCMReject([strictMockFileManager uploadArtworks:[OCMArg any] progressHandler:[OCMArg any] completionHandler:[OCMArg any]]);
+
+ [testPresentAlertOperation start];
+
+ OCMVerifyAll(strictMockFileManager);
+ OCMVerifyAll(strictMockSystemCapabilityManager);
+ OCMVerifyAll(strictMockCurrentWindowCapability);
+ expect(testPresentAlertOperation.alertIconUploaded).to(beTrue());
+ expect(testPresentAlertOperation.alertRPC.alertIcon).toNot(beNil());
+ });
});
});
@@ -781,6 +801,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.alertIconUploaded = YES;
testPresentAlertOperation.completionBlock = ^{
hasCalledOperationCompletionHandler = YES;
@@ -829,7 +850,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 +904,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];