Skip to content

Commit

Permalink
Merge pull request #1293 from smartdevicelink/bugfix/issue_1290_sync3…
Browse files Browse the repository at this point in the history
…_choice_sets_fail

Fix ChoiceSetManager Bugs
  • Loading branch information
joeljfischer committed Jun 5, 2019
2 parents e16e360 + be493ea commit 03c394a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
6 changes: 5 additions & 1 deletion SmartDeviceLink/SDLChoiceSetManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ - (void)didEnterStateStartupError {
#pragma mark Upload / Delete

- (void)preloadChoices:(NSArray<SDLChoiceCell *> *)choices withCompletionHandler:(nullable SDLPreloadChoiceCompletionHandler)handler {
if (![self.currentState isEqualToString:SDLChoiceManagerStateReady]) { return; }
if (![self.currentState isEqualToString:SDLChoiceManagerStateReady]) {
NSError *error = [NSError sdl_choiceSetManager_incorrectState:self.currentState];
handler(error);
return;
}

NSMutableSet<SDLChoiceCell *> *choicesToUpload = [[self sdl_choicesToBeUploadedWithArray:choices] mutableCopy];
[choicesToUpload minusSet:self.preloadedMutableChoices];
Expand Down
1 change: 1 addition & 0 deletions SmartDeviceLink/SDLError.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ extern SDLErrorDomain *const SDLErrorDomainRPCStore;
+ (NSError *)sdl_choiceSetManager_choiceDeletionFailed:(NSDictionary *)userInfo;
+ (NSError *)sdl_choiceSetManager_choiceUploadFailed:(NSDictionary *)userInfo;
+ (NSError *)sdl_choiceSetManager_failedToCreateMenuItems;
+ (NSError *)sdl_choiceSetManager_incorrectState:(NSString *)state;

#pragma mark Transport

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

#import "SDLError.h"

#import "SDLChoiceSetManager.h"

NS_ASSUME_NONNULL_BEGIN

#pragma mark Error Domains
Expand Down Expand Up @@ -237,6 +239,16 @@ + (NSError *)sdl_choiceSetManager_failedToCreateMenuItems {
return [NSError errorWithDomain:SDLErrorDomainChoiceSetManager code:SDLChoiceSetManagerErrorFailedToCreateMenuItems userInfo:userInfo];
}

+ (NSError *)sdl_choiceSetManager_incorrectState:(SDLChoiceManagerState *)state {
NSString *errorString = [NSString stringWithFormat:@"Choice Set Manager error invalid state: %@", state];
NSDictionary<NSString *, NSString *> *userInfo = @{
NSLocalizedDescriptionKey: errorString,
NSLocalizedFailureReasonErrorKey: NSLocalizedString(@"The choice set manager could be in an invalid state because the head unit doesn't support choice sets or the manager failed to set up correctly.", nil),
NSLocalizedRecoverySuggestionErrorKey: NSLocalizedString(@"If you are setting the menuName, it is possible that the head unit is sending incorrect displayCapabilities.", nil)
};
return [NSError errorWithDomain:SDLErrorDomainChoiceSetManager code:SDLChoiceSetManagerErrorInvalidState userInfo:userInfo];
}

#pragma mark Transport

+ (NSError *)sdl_transport_unknownError {
Expand Down
3 changes: 2 additions & 1 deletion SmartDeviceLink/SDLErrorConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ typedef NS_ENUM(NSInteger, SDLChoiceSetManagerError) {
SDLChoiceSetManagerErrorPendingPresentationDeleted = -1,
SDLChoiceSetManagerErrorDeletionFailed = -2,
SDLChoiceSetManagerErrorUploadFailed = -3,
SDLChoiceSetManagerErrorFailedToCreateMenuItems = -4
SDLChoiceSetManagerErrorFailedToCreateMenuItems = -4,
SDLChoiceSetManagerErrorInvalidState = -5
};

/**
Expand Down
11 changes: 9 additions & 2 deletions SmartDeviceLink/SDLPreloadChoicesOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,15 @@ - (nullable SDLCreateInteractionChoiceSet *)sdl_choiceFromCell:(SDLChoiceCell *)
} else {
vrCommands = cell.voiceCommands;
}

NSString *menuName = [self.displayCapabilities hasTextFieldOfName:SDLTextFieldNameMenuName] ? cell.text : nil;

NSString *menuName = nil;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
if ([self.displayCapabilities.displayType isEqualToEnum:SDLDisplayTypeGen38Inch] || [self.displayCapabilities hasTextFieldOfName:SDLTextFieldNameMenuName]) {
menuName = cell.text;
}
#pragma clang diagnostic pop

if(!menuName) {
SDLLogE(@"Could not convert SDLChoiceCell to SDLCreateInteractionChoiceSet. It will not be shown. Cell: %@", cell);
return nil;
Expand Down

0 comments on commit 03c394a

Please sign in to comment.