diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2017-05-11 09:56:35 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-11 09:56:35 -0400 |
commit | b0dcd377c5fb4f026014251a8a0ed651d9f1e19f (patch) | |
tree | 13b59f5b017cff7310d234cae860472032d1eaab | |
parent | 75dddd41e007f470c441cd4589d2b530dc18f682 (diff) | |
parent | 2f0b85dc9393753bd769fe0dbb2d4cf9def5f222 (diff) | |
download | sdl_ios-b0dcd377c5fb4f026014251a8a0ed651d9f1e19f.tar.gz |
Merge pull request #615 from smartdevicelink/bugfix/issue_540
Guarantee that HMI status is set for ready handler success
-rw-r--r-- | SmartDeviceLink/SDLLifecycleManager.h | 3 | ||||
-rw-r--r-- | SmartDeviceLink/SDLLifecycleManager.m | 30 | ||||
-rw-r--r-- | SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleManagerSpec.m | 37 |
3 files changed, 62 insertions, 8 deletions
diff --git a/SmartDeviceLink/SDLLifecycleManager.h b/SmartDeviceLink/SDLLifecycleManager.h index 9332d5d9d..f09d18aaf 100644 --- a/SmartDeviceLink/SDLLifecycleManager.h +++ b/SmartDeviceLink/SDLLifecycleManager.h @@ -42,7 +42,8 @@ extern SDLLifecycleState *const SDLLifecycleStateReconnecting; extern SDLLifecycleState *const SDLLifecycleStateConnected; extern SDLLifecycleState *const SDLLifecycleStateRegistered; extern SDLLifecycleState *const SDLLifecycleStateSettingUpManagers; -extern SDLLifecycleState *const SDLLifecycleStatePostManagerProcessing; +extern SDLLifecycleState *const SDLLifecycleStateSettingUpAppIcon; +extern SDLLifecycleState *const SDLLifecycleStateSettingUpHMI; extern SDLLifecycleState *const SDLLifecycleStateUnregistering; extern SDLLifecycleState *const SDLLifecycleStateReady; diff --git a/SmartDeviceLink/SDLLifecycleManager.m b/SmartDeviceLink/SDLLifecycleManager.m index a060cecdf..185822148 100644 --- a/SmartDeviceLink/SDLLifecycleManager.m +++ b/SmartDeviceLink/SDLLifecycleManager.m @@ -49,7 +49,8 @@ SDLLifecycleState *const SDLLifecycleStateReconnecting = @"Reconnecting"; SDLLifecycleState *const SDLLifecycleStateConnected = @"Connected"; SDLLifecycleState *const SDLLifecycleStateRegistered = @"Registered"; SDLLifecycleState *const SDLLifecycleStateSettingUpManagers = @"SettingUpManagers"; -SDLLifecycleState *const SDLLifecycleStatePostManagerProcessing = @"PostManagerProcessing"; +SDLLifecycleState *const SDLLifecycleStateSettingUpAppIcon = @"SettingUpAppIcon"; +SDLLifecycleState *const SDLLifecycleStateSettingUpHMI = @"SettingUpHMI"; SDLLifecycleState *const SDLLifecycleStateUnregistering = @"Unregistering"; SDLLifecycleState *const SDLLifecycleStateReady = @"Ready"; @@ -151,8 +152,9 @@ SDLLifecycleState *const SDLLifecycleStateReady = @"Ready"; SDLLifecycleStateReconnecting: @[SDLLifecycleStateStarted, SDLLifecycleStateStopped], SDLLifecycleStateConnected: @[SDLLifecycleStateStopped, SDLLifecycleStateReconnecting, SDLLifecycleStateRegistered], SDLLifecycleStateRegistered: @[SDLLifecycleStateStopped, SDLLifecycleStateReconnecting, SDLLifecycleStateSettingUpManagers], - SDLLifecycleStateSettingUpManagers: @[SDLLifecycleStateStopped, SDLLifecycleStateReconnecting, SDLLifecycleStatePostManagerProcessing], - SDLLifecycleStatePostManagerProcessing: @[SDLLifecycleStateStopped, SDLLifecycleStateReconnecting, SDLLifecycleStateReady], + SDLLifecycleStateSettingUpManagers: @[SDLLifecycleStateStopped, SDLLifecycleStateReconnecting, SDLLifecycleStateSettingUpAppIcon], + SDLLifecycleStateSettingUpAppIcon: @[SDLLifecycleStateStopped, SDLLifecycleStateReconnecting, SDLLifecycleStateSettingUpHMI], + SDLLifecycleStateSettingUpHMI: @[SDLLifecycleStateStopped, SDLLifecycleStateReconnecting, SDLLifecycleStateReady], SDLLifecycleStateUnregistering: @[SDLLifecycleStateStopped], SDLLifecycleStateReady: @[SDLLifecycleStateUnregistering, SDLLifecycleStateStopped, SDLLifecycleStateReconnecting] }; @@ -263,18 +265,28 @@ SDLLifecycleState *const SDLLifecycleStateReady = @"Ready"; // When done, we want to transition, even if there were errors. They may be expected, e.g. on head units that do not support files. dispatch_group_notify(managerGroup, dispatch_get_main_queue(), ^{ - [self.lifecycleStateMachine transitionToState:SDLLifecycleStatePostManagerProcessing]; + [self.lifecycleStateMachine transitionToState:SDLLifecycleStateSettingUpAppIcon]; }); } -- (void)didEnterStatePostManagerProcessing { - // We only want to send the app icon when the file manager is complete, and when that's done, set the state to ready +- (void)didEnterStateSettingUpAppIcon { + // We only want to send the app icon when the file manager is complete, and when that's done, wait for hmi status to be ready [self sdl_sendAppIcon:self.configuration.lifecycleConfig.appIcon withCompletion:^{ - [self.lifecycleStateMachine transitionToState:SDLLifecycleStateReady]; + [self.lifecycleStateMachine transitionToState:SDLLifecycleStateSettingUpHMI]; }]; } +- (void)didEnterStateSettingUpHMI{ + // We want to make sure we've gotten a SDLOnHMIStatus notification + if (self.hmiLevel == nil) { + // If nil, return and wait until we get a notification + return; + } + // We are sure to have a HMIStatus, set state to ready + [self.lifecycleStateMachine transitionToState:SDLLifecycleStateReady]; +} + - (void)didEnterStateReady { SDLResult *registerResult = self.registerResponse.resultCode; NSString *registerInfo = self.registerResponse.info; @@ -466,6 +478,10 @@ SDLLifecycleState *const SDLLifecycleStateReady = @"Ready"; SDLOnHMIStatus *hmiStatusNotification = notification.notification; SDLHMILevel *oldHMILevel = self.hmiLevel; self.hmiLevel = hmiStatusNotification.hmiLevel; + + if ([self.lifecycleStateMachine isCurrentState:SDLLifecycleStateSettingUpHMI]) { + [self.lifecycleStateMachine transitionToState:SDLLifecycleStateReady]; + } if (![self.lifecycleStateMachine isCurrentState:SDLLifecycleStateReady]) { return; diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleManagerSpec.m index c4ddf3be5..593e99941 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleManagerSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleManagerSpec.m @@ -263,6 +263,43 @@ xdescribe(@"a lifecycle manager", ^{ }); }); }); + + describe(@"transitioning to the Setting Up HMI state", ^{ + context(@"before register response is a success", ^{ + it(@"ready handler should not be called yet", ^{ + SDLRegisterAppInterfaceResponse *response = [[SDLRegisterAppInterfaceResponse alloc] init]; + response.resultCode = [SDLResult SUCCESS]; + testManager.registerResponse = response; + + [testManager.lifecycleStateMachine setToState:SDLLifecycleStateSettingUpHMI fromOldState:nil callEnterTransition:YES]; + + expect(@(readyHandlerSuccess)).to(equal(@NO)); + expect(readyHandlerError).to(beNil()); + }); + }); + + context(@"assume hmi status is nil", ^{ + it(@"mock notification and ensure state changes to ready", ^{ + __block SDLOnHMIStatus *testHMIStatus = nil; + __block SDLHMILevel *testHMILevel = nil; + testHMIStatus = [[SDLOnHMIStatus alloc] init]; + + SDLRegisterAppInterfaceResponse *response = [[SDLRegisterAppInterfaceResponse alloc] init]; + response.resultCode = [SDLResult SUCCESS]; + testManager.registerResponse = response; + + [testManager.lifecycleStateMachine setToState:SDLLifecycleStateSettingUpHMI fromOldState:nil callEnterTransition:YES]; + + testHMILevel = [SDLHMILevel FULL]; + testHMIStatus.hmiLevel = testHMILevel; + + [testManager.notificationDispatcher postRPCNotificationNotification:SDLDidChangeHMIStatusNotification notification:testHMIStatus]; + + expect(@(readyHandlerSuccess)).to(equal(@YES)); + expect(readyHandlerError).toNot(beNil()); + }); + }); + }); describe(@"transitioning to the ready state", ^{ context(@"when the register response is a success", ^{ |