Skip to content

Commit

Permalink
Merge d888ebe into 095d0a2
Browse files Browse the repository at this point in the history
  • Loading branch information
joeljfischer authored Sep 24, 2021
2 parents 095d0a2 + d888ebe commit 68547aa
Show file tree
Hide file tree
Showing 18 changed files with 121 additions and 20 deletions.
8 changes: 6 additions & 2 deletions SmartDeviceLink/private/SDLCheckChoiceVROptionalOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import "SDLCreateInteractionChoiceSet.h"
#import "SDLConnectionManagerType.h"
#import "SDLDeleteInteractionChoiceSet.h"
#import "SDLError.h"
#import "SDLLogMacros.h"

NS_ASSUME_NONNULL_BEGIN
Expand All @@ -28,9 +29,12 @@ @interface SDLCheckChoiceVROptionalOperation()

@implementation SDLCheckChoiceVROptionalOperation

- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager completionHandler:(nonnull SDLCheckChoiceVROptionalCompletionHandler)completionHandler {
- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager completionHandler:(SDLCheckChoiceVROptionalCompletionHandler)completionHandler {
self = [super init];
if (!self) { return nil; }
if (!self) {
completionHandler(NO, [NSError sdl_failedToCreateObjectOfClass:[SDLCheckChoiceVROptionalOperation class]]);
return nil;
}

_connectionManager = connectionManager;
_operationId = [NSUUID UUID];
Expand Down
11 changes: 10 additions & 1 deletion SmartDeviceLink/private/SDLChoiceSetManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,16 @@ - (void)deleteChoices:(NSArray<SDLChoiceCell *> *)choices {

- (void)preloadChoices:(NSArray<SDLChoiceCell *> *)choices withCompletionHandler:(nullable SDLPreloadChoiceCompletionHandler)handler {
SDLLogV(@"Request to preload choices: %@", choices);
if (choices.count == 0) { return; }
if (choices.count == 0) {
if (handler != nil) {
handler([NSError sdl_choiceSetManager_choiceUploadFailed:@{
NSLocalizedDescriptionKey: @"Choice upload failed",
NSLocalizedFailureReasonErrorKey: @"No choices were provided for upload",
NSLocalizedRecoverySuggestionErrorKey: @"Provide some choice cells to upload instead of an empty list"
}]);
}
return;
}
if (![self.currentState isEqualToString:SDLChoiceManagerStateReady]) {
NSError *error = [NSError sdl_choiceSetManager_incorrectState:self.currentState];
SDLLogE(@"Cannot preload choices when the manager isn't in the ready state: %@", error);
Expand Down
5 changes: 4 additions & 1 deletion SmartDeviceLink/private/SDLDeleteChoicesOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ @implementation SDLDeleteChoicesOperation

- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager cellsToDelete:(NSSet<SDLChoiceCell *> *)cellsToDelete loadedCells:(NSSet<SDLChoiceCell *> *)loadedCells completionHandler:(SDLDeleteChoicesCompletionHandler)completionHandler {
self = [super init];
if (!self) { return nil; }
if (!self) {
completionHandler(loadedCells, [NSError sdl_failedToCreateObjectOfClass:[SDLDeleteChoicesOperation class]]);
return nil;
}

_connectionManager = connectionManager;
_cellsToDelete = cellsToDelete;
Expand Down
4 changes: 4 additions & 0 deletions SmartDeviceLink/private/SDLDeleteFileOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "SDLConnectionManagerType.h"
#import "SDLDeleteFile.h"
#import "SDLDeleteFileResponse.h"
#import "SDLError.h"

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -28,6 +29,9 @@ @implementation SDLDeleteFileOperation
- (instancetype)initWithFileName:(NSString *)fileName connectionManager:(id<SDLConnectionManagerType>)connectionManager completionHandler:(nullable SDLFileManagerDeleteCompletionHandler)completionHandler {
self = [super init];
if (!self) {
if (completionHandler != nil) {
completionHandler(NO, NSNotFound, [NSError sdl_failedToCreateObjectOfClass:[SDLDeleteFileOperation class]]);
}
return nil;
}

Expand Down
5 changes: 5 additions & 0 deletions SmartDeviceLink/private/SDLError.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ NS_ASSUME_NONNULL_BEGIN

@interface NSError (SDLErrors)

+ (NSError *)sdl_failedToCreateObjectOfClass:(Class)objectClass;

#pragma mark SDLEncryptionLifecycleManager
+ (NSError *)sdl_encryption_lifecycle_notReadyError;
+ (NSError *)sdl_encryption_lifecycle_encryption_off;
Expand Down Expand Up @@ -56,6 +58,8 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSError *)sdl_softButtonManager_pendingUpdateSuperseded;
+ (NSError *)sdl_subscribeButtonManager_notSubscribed;
+ (NSError *)sdl_textAndGraphicManager_pendingUpdateSuperseded;
+ (NSError *)sdl_textAndGraphicManager_batchingUpdate;
+ (NSError *)sdl_textAndGraphicManager_nothingToUpdate;

#pragma mark Menu Manager

Expand Down Expand Up @@ -89,6 +93,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSError *)sdl_systemCapabilityManager_moduleDoesNotSupportSystemCapabilities;
+ (NSError *)sdl_systemCapabilityManager_cannotUpdateInHMINONE;
+ (NSError *)sdl_systemCapabilityManager_cannotUpdateTypeDISPLAYS;
+ (NSError *)sdl_systemCapabilityManager_unknownSystemCapabilityType;

#pragma mark Transport

Expand Down
32 changes: 32 additions & 0 deletions SmartDeviceLink/private/SDLError.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@

@implementation NSError (SDLErrors)

+ (NSError *)sdl_failedToCreateObjectOfClass:(Class)objectClass {
return [NSError errorWithDomain:SDLErrorDomainSystem code:SDLSystemErrorFailedToCreateObject userInfo:@{
NSLocalizedDescriptionKey: [NSString stringWithFormat: @"iOS system failed to create a new object of class: %@", objectClass],
NSLocalizedFailureReasonErrorKey: @"An unknown error caused iOS to fail to create an object",
NSLocalizedRecoverySuggestionErrorKey: @"There is no known way to fix this error"
}];
}

#pragma mark - SDLEncryptionLifecycleManager
+ (NSError *)sdl_encryption_lifecycle_notReadyError {
NSDictionary<NSString *, NSString *> *userInfo = @{
Expand Down Expand Up @@ -269,6 +277,22 @@ + (NSError *)sdl_subscribeButtonManager_notSubscribed {
return [NSError errorWithDomain:SDLErrorDomainSubscribeButtonManager code:SDLSubscribeButtonManagerErrorNotSubscribed userInfo:userInfo];
}

+ (NSError *)sdl_textAndGraphicManager_batchingUpdate {
return [NSError errorWithDomain:SDLErrorDomainTextAndGraphicManager code:SDLTextAndGraphicManagerErrorCurrentlyBatching userInfo:@{
NSLocalizedDescriptionKey: @"Update will not run because batching is enabled",
NSLocalizedFailureReasonErrorKey: @"Text and Graphic manager will not run this update and call this handler because its currently batching updates. The update will occur when batching ends.",
NSLocalizedRecoverySuggestionErrorKey: @"This callback shouldn't occur. Please open an issue on https://www.github.com/smartdevicelink/sdl_ios/ if it does"
}];
}

+ (NSError *)sdl_textAndGraphicManager_nothingToUpdate {
return [NSError errorWithDomain:SDLErrorDomainTextAndGraphicManager code:SDLTextAndGraphicManagerErrorNothingToUpdate userInfo:@{
NSLocalizedDescriptionKey: @"Update will not run because there's nothing to update",
NSLocalizedFailureReasonErrorKey: @"This callback shouldn't occur, so there's no known reason for this failure.",
NSLocalizedRecoverySuggestionErrorKey: @"This callback shouldn't occur. Please open an issue on https://www.github.com/smartdevicelink/sdl_ios/ if it does"
}];
}

#pragma mark Menu Manager

+ (NSError *)sdl_menuManager_configurationOperationLayoutsNotSupported {
Expand Down Expand Up @@ -446,6 +470,14 @@ + (NSError *)sdl_systemCapabilityManager_cannotUpdateTypeDISPLAYS {
return [NSError errorWithDomain:SDLErrorDomainSystemCapabilityManager code:SDLSystemCapabilityManagerErrorCannotUpdateTypeDisplays userInfo:userInfo];
}

+ (NSError *)sdl_systemCapabilityManager_unknownSystemCapabilityType {
return [NSError errorWithDomain:SDLErrorDomainSystemCapabilityManager code:SDLSystemCapabilityManagerErrorUnknownType userInfo:@{
NSLocalizedDescriptionKey: @"An unknown system capability type was received.",
NSLocalizedFailureReasonErrorKey: @"Failure reason unknown. If you see this, please open an issue on https://www.github.com/smartdevicelink/sdl_ios/",
NSLocalizedRecoverySuggestionErrorKey: @"Ensure you are only attempting to manually subscribe to known system capability types for the version of this library. You may also want to update this library to its latest version."
}];
}

#pragma mark Transport

+ (NSError *)sdl_transport_unknownError {
Expand Down
4 changes: 3 additions & 1 deletion SmartDeviceLink/private/SDLFileWrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "SDLFileWrapper.h"

#import "SDLError.h"
#import "SDLFile.h"


Expand All @@ -18,6 +19,7 @@ @implementation SDLFileWrapper
- (instancetype)initWithFile:(SDLFile *)file completionHandler:(SDLFileManagerUploadCompletionHandler)completionHandler {
self = [super init];
if (!self) {
completionHandler(NO, NSNotFound, [NSError sdl_failedToCreateObjectOfClass:[SDLFileWrapper class]]);
return nil;
}

Expand All @@ -33,4 +35,4 @@ + (instancetype)wrapperWithFile:(SDLFile *)file completionHandler:(SDLFileManage

@end

NS_ASSUME_NONNULL_END
NS_ASSUME_NONNULL_END
4 changes: 4 additions & 0 deletions SmartDeviceLink/private/SDLListFilesOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "SDLListFilesOperation.h"

#import "SDLConnectionManagerType.h"
#import "SDLError.h"
#import "SDLListFiles.h"
#import "SDLListFilesResponse.h"

Expand All @@ -29,6 +30,9 @@ @implementation SDLListFilesOperation
- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager completionHandler:(nullable SDLFileManagerListFilesCompletionHandler)completionHandler {
self = [super init];
if (!self) {
if (completionHandler != nil) {
completionHandler(NO, NSNotFound, @[], [NSError sdl_failedToCreateObjectOfClass:[SDLListFilesOperation class]]);
}
return nil;
}

Expand Down
7 changes: 5 additions & 2 deletions SmartDeviceLink/private/SDLMenuShowOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ @interface SDLMenuShowOperation ()

@implementation SDLMenuShowOperation

- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager toMenuCell:(nullable SDLMenuCell *)menuCell completionHandler:(nonnull SDLMenuShowCompletionBlock)completionHandler {
- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager toMenuCell:(nullable SDLMenuCell *)menuCell completionHandler:(SDLMenuShowCompletionBlock)completionHandler {
self = [super init];
if (!self) { return nil; }
if (!self) {
completionHandler([NSError sdl_failedToCreateObjectOfClass:[SDLMenuShowOperation class]]);
return nil;
}

_connectionManager = connectionManager;
_submenuCell = menuCell;
Expand Down
2 changes: 1 addition & 1 deletion SmartDeviceLink/private/SDLProtocolMessageAssembler.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ - (void)handleMessage:(SDLProtocolMessage *)message withCompletionHandler:(SDLMe
// Validate input
if (message.header.sessionID != self.sessionID) {
SDLLogE(@"Message part sent to the wrong assembler. This session id: %d, message session id: %d", self.sessionID, message.header.sessionID);
return;
return completionHandler(NO, nil);
}

if (self.parts == nil) {
Expand Down
7 changes: 6 additions & 1 deletion SmartDeviceLink/private/SDLSequentialRPCRequestOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ @implementation SDLSequentialRPCRequestOperation {

- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager requests:(NSArray<SDLRPCRequest *> *)requests progressHandler:(nullable SDLMultipleSequentialRequestProgressHandler)progressHandler completionHandler:(nullable SDLMultipleRequestCompletionHandler)completionHandler {
self = [super init];
if (!self) { return nil; }
if (!self) {
if (completionHandler != nil) {
completionHandler(NO);
}
return nil;
}

executing = NO;
finished = NO;
Expand Down
13 changes: 10 additions & 3 deletions SmartDeviceLink/private/SDLTextAndGraphicManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,18 @@ - (void)sdl_updateTransactionQueueSuspended {
#pragma mark - Upload / Send

- (void)updateWithCompletionHandler:(nullable SDLTextAndGraphicUpdateCompletionHandler)handler {
if (self.isBatchingUpdates) { return; }

if (self.isDirty) {
if (self.isBatchingUpdates) {
if (handler != nil) {
// This shouldn't be possible, but just in case
handler([NSError sdl_textAndGraphicManager_batchingUpdate]);
}
} else if (self.isDirty) {
self.isDirty = NO;
[self sdl_updateAndCancelPreviousOperations:YES completionHandler:handler];
} else {
if (handler != nil) {
handler([NSError sdl_textAndGraphicManager_nothingToUpdate]);
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion SmartDeviceLink/private/SDLVoiceCommandUpdateOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ @implementation SDLVoiceCommandUpdateOperation

- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager pendingVoiceCommands:(NSArray<SDLVoiceCommand *> *)pendingVoiceCommands oldVoiceCommands:(NSArray<SDLVoiceCommand *> *)oldVoiceCommands updateCompletionHandler:(SDLVoiceCommandUpdateCompletionHandler)completionHandler {
self = [self init];
if (!self) { return nil; }
if (!self) {
completionHandler(@[], [NSError sdl_failedToCreateObjectOfClass:[SDLVoiceCommandUpdateOperation class]]);
return nil;
}

_connectionManager = connectionManager;
_pendingVoiceCommands = pendingVoiceCommands;
Expand Down
22 changes: 20 additions & 2 deletions SmartDeviceLink/public/SDLErrorConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
/// A typedef declaration of the SDL error domain
typedef NSString SDLErrorDomain;

/// An error with the iOS system
extern SDLErrorDomain *const SDLErrorDomainSystem;

/// An error in the SDLAudioStreamManager
extern SDLErrorDomain *const SDLErrorDomainAudioStreamManager;

Expand Down Expand Up @@ -58,6 +61,12 @@ extern SDLErrorDomain *const SDLErrorDomainTransport;

#pragma mark Error Codes

/// Error associated with the underlying operating system
typedef NS_ENUM(NSInteger, SDLSystemError) {
/// iOS failed to create an object
SDLSystemErrorFailedToCreateObject = -1
};

/**
* Errors associated with the SDLManager class.
*/
Expand Down Expand Up @@ -168,7 +177,13 @@ typedef NS_ENUM(NSInteger, SDLFileManagerError) {
*/
typedef NS_ENUM(NSInteger, SDLTextAndGraphicManagerError) {
/// A pending update was superseded by a newer requested update. The old update will not be sent
SDLTextAndGraphicManagerErrorPendingUpdateSuperseded = -1
SDLTextAndGraphicManagerErrorPendingUpdateSuperseded = -1,

/// The manager is currently batching updates so the update will not yet be sent and the handler will not be called
SDLTextAndGraphicManagerErrorCurrentlyBatching = -2,

/// The manager could find nothing to update
SDLTextAndGraphicManagerErrorNothingToUpdate = -3,
};

/**
Expand Down Expand Up @@ -242,7 +257,10 @@ typedef NS_ENUM(NSInteger, SDLSystemCapabilityManagerError) {
SDLSystemCapabilityManagerErrorHMINone = -2,

/// You may not update the system capability type DISPLAYS because it is always subscribed
SDLSystemCapabilityManagerErrorCannotUpdateTypeDisplays = -3
SDLSystemCapabilityManagerErrorCannotUpdateTypeDisplays = -3,

/// The module sent an unknown system capability type
SDLSystemCapabilityManagerErrorUnknownType = -4,
};

/**
Expand Down
1 change: 1 addition & 0 deletions SmartDeviceLink/public/SDLErrorConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#pragma mark Error Domains

SDLErrorDomain *const SDLErrorDomainSystem = @"com.sdl.system.error";
SDLErrorDomain *const SDLErrorDomainAudioStreamManager = @"com.sdl.extension.pcmAudioStreamManager";
SDLErrorDomain *const SDLErrorDomainCacheFileManager = @"com.sdl.cachefilemanager.error";
SDLErrorDomain *const SDLErrorDomainChoiceSetManager = @"com.sdl.choicesetmanager.error";
Expand Down
5 changes: 2 additions & 3 deletions SmartDeviceLink/public/SDLFileManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ - (void)uploadFile:(SDLFile *)file completionHandler:(nullable SDLFileManagerUpl

- (void)sdl_uploadFile:(SDLFile *)file completionHandler:(nullable SDLFileManagerUploadCompletionHandler)handler {
__block NSString *fileName = file.name;
__block SDLFileManagerUploadCompletionHandler uploadCompletion = [handler copy];

__weak typeof(self) weakSelf = self;
SDLFileWrapper *fileWrapper = [SDLFileWrapper wrapperWithFile:file completionHandler:^(BOOL success, NSUInteger bytesAvailable, NSError *_Nullable error) {
Expand All @@ -425,8 +424,8 @@ - (void)sdl_uploadFile:(SDLFile *)file completionHandler:(nullable SDLFileManage
}
}

if (uploadCompletion != nil) {
uploadCompletion(success, bytesAvailable, error);
if (handler != nil) {
handler(success, bytesAvailable, error);
}
}];

Expand Down
4 changes: 3 additions & 1 deletion SmartDeviceLink/public/SDLSystemCapabilityManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,13 @@ - (BOOL)sdl_saveSystemCapability:(nullable SDLSystemCapability *)systemCapabilit
[self sdl_saveDisplayCapabilityListUpdate:systemCapability.displayCapabilities];
} else {
SDLLogW(@"Received response for unknown System Capability Type: %@", systemCapabilityType);
if (handler != nil) {
handler(systemCapability, NO, [NSError sdl_systemCapabilityManager_unknownSystemCapabilityType]);
}
return NO;
}

SDLLogD(@"Updated system capability manager with new data: %@", systemCapability);

[self sdl_callObserversForUpdate:systemCapability error:error handler:handler];
return YES;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ @interface SDLChoiceCell()
});
});

fcontext(@"when artworks are not already on the system", ^{
context(@"when artworks are not already on the system", ^{
beforeEach(^{
OCMStub([testFileManager hasUploadedFile:[OCMArg isNotNil]]).andReturn(NO);
});
Expand Down

0 comments on commit 68547aa

Please sign in to comment.