diff options
author | Muller, Alexander (A.) <amulle19@ford.com> | 2017-03-02 14:26:58 -0800 |
---|---|---|
committer | Muller, Alexander (A.) <amulle19@ford.com> | 2017-03-02 14:26:58 -0800 |
commit | 7290569813ab6ad3e70dbc74361dc85251e82aba (patch) | |
tree | 4c60c272f6a1b978461800a0d38c7c3422ff0ac1 | |
parent | 708f085f5e3e976f0019e768e0cf5631b4575432 (diff) | |
download | sdl_ios-hotfix/issue_557.tar.gz |
Added support for throwing an error that SDLLifecycleManager receives if we get an invalid JSON format including NSNull objects that causes the app to properly disconnect and not attempt a reconnect.hotfix/issue_557
-rw-r--r-- | SmartDeviceLink/SDLLifecycleManager.m | 9 | ||||
-rw-r--r-- | SmartDeviceLink/SDLProxy.m | 8 | ||||
-rw-r--r-- | SmartDeviceLink/SDLRPCStruct.m | 20 |
3 files changed, 37 insertions, 0 deletions
diff --git a/SmartDeviceLink/SDLLifecycleManager.m b/SmartDeviceLink/SDLLifecycleManager.m index 29a6f7a6d..6364ac96e 100644 --- a/SmartDeviceLink/SDLLifecycleManager.m +++ b/SmartDeviceLink/SDLLifecycleManager.m @@ -107,6 +107,7 @@ SDLLifecycleState *const SDLLifecycleStateReady = @"Ready"; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(transportDidDisconnect) name:SDLTransportDidDisconnect object:_notificationDispatcher]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hmiStatusDidChange:) name:SDLDidChangeHMIStatusNotification object:_notificationDispatcher]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(remoteHardwareDidUnregister:) name:SDLDidReceiveAppUnregisteredNotification object:_notificationDispatcher]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveError:) name:SDLDidReceiveError object:_notificationDispatcher]; return self; } @@ -493,6 +494,14 @@ SDLLifecycleState *const SDLLifecycleStateReady = @"Ready"; } } +- (void)didReceiveError:(NSNotification *)notification { + NSError *error = notification.userInfo[SDLNotificationUserInfoObject]; + + [SDLDebugTool logFormat:@"Received an error: %@. Disconnecting…", error.localizedFailureReason]; + + [self.lifecycleStateMachine transitionToState:SDLLifecycleStateStopped]; +} + @end NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink/SDLProxy.m b/SmartDeviceLink/SDLProxy.m index e35df95ec..8ad02d056 100644 --- a/SmartDeviceLink/SDLProxy.m +++ b/SmartDeviceLink/SDLProxy.m @@ -54,6 +54,7 @@ const float startSessionTime = 10.0; const float notifyProxyClosedDelay = 0.1; const int POLICIES_CORRELATION_ID = 65535; +NSString *const SDLProxyErrorDomain = @"com.sdl.proxy"; @interface SDLProxy () { SDLLockScreenStatusManager *_lsm; @@ -303,6 +304,13 @@ const int POLICIES_CORRELATION_ID = 65535; - (void)handleRPCDictionary:(NSDictionary *)dict { SDLRPCMessage *message = [[SDLRPCMessage alloc] initWithDictionary:[dict mutableCopy]]; + + if (!message) { + NSException *exception = [NSException exceptionWithName:@"Invalid JSON" reason:@"Received invalid JSON from Core." userInfo:nil]; + [self onError:@"Invalid JSON" exception:exception]; + return; + } + NSString *functionName = [message getFunctionName]; NSString *messageType = [message messageType]; diff --git a/SmartDeviceLink/SDLRPCStruct.m b/SmartDeviceLink/SDLRPCStruct.m index cd0f4d481..0e83c51aa 100644 --- a/SmartDeviceLink/SDLRPCStruct.m +++ b/SmartDeviceLink/SDLRPCStruct.m @@ -12,6 +12,9 @@ - (id)initWithDictionary:(NSMutableDictionary *)dict { if (self = [super init]) { if (dict != nil) { + if (![self sdl_isDictionaryValid:dict]) { + return nil; + } store = dict; } else { store = [[NSMutableDictionary alloc] init]; @@ -85,4 +88,21 @@ store = nil; } +- (BOOL)sdl_isDictionaryValid:(NSMutableDictionary*)dict { + BOOL isValid = YES; + for (NSString *key in dict.allKeys) { + id value = dict[key]; + if ([value isKindOfClass:[NSDictionary class]]) { + isValid = [self sdl_isDictionaryValid:value]; + } else if ([value isKindOfClass:[NSNull class]]) { + isValid = NO; + } + + if (!isValid) { + break; + } + } + return isValid; +} + @end |