diff --git a/SmartDeviceLink/private/SDLLockScreenManager.m b/SmartDeviceLink/private/SDLLockScreenManager.m index 58dd92445..a4a626a0c 100644 --- a/SmartDeviceLink/private/SDLLockScreenManager.m +++ b/SmartDeviceLink/private/SDLLockScreenManager.m @@ -17,6 +17,7 @@ #import "SDLNotificationDispatcher.h" #import "SDLLockScreenStatusInfo.h" #import "SDLOnDriverDistraction.h" +#import "SDLOnHMIStatus.h" #import "SDLRPCNotificationNotification.h" #import "SDLViewControllerPresentable.h" @@ -52,7 +53,8 @@ - (instancetype)initWithConfiguration:(SDLLockScreenConfiguration *)config notif _presenter = presenter; _lockScreenDismissedByUser = NO; _statusManager = [[SDLLockScreenStatusManager alloc] initWithNotificationDispatcher:dispatcher]; - + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_hmiStatusDidChange:) name:SDLDidChangeHMIStatusNotification object:dispatcher]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_lockScreenStatusDidChange:) name:SDLDidChangeLockScreenStatusNotification object:dispatcher]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_lockScreenIconReceived:) name:SDLDidReceiveLockScreenIcon object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_appDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil]; @@ -131,7 +133,6 @@ - (void)sdl_lockScreenStatusDidChange:(SDLRPCNotificationNotification *)notifica if (lockScreenStatus == nil) { return; } self.lastLockNotification = lockScreenStatus; - [self sdl_checkLockScreen]; } @@ -161,10 +162,15 @@ - (void)sdl_appDidBecomeActive:(NSNotification *)notification { }); } +- (void)sdl_hmiStatusDidChange:(SDLRPCNotificationNotification *)notification { + if (![notification isNotificationMemberOfClass:[SDLOnHMIStatus class]]) { return; } + + [self.statusManager updateHMIStatus:notification.notification]; +} + - (void)sdl_driverDistractionStateDidChange:(SDLRPCNotificationNotification *)notification { - if (![notification isNotificationMemberOfClass:[SDLOnDriverDistraction class]]) { - return; - } + if (![notification isNotificationMemberOfClass:[SDLOnDriverDistraction class]]) { return; } + // When an `OnDriverDistraction` notification is sent with a `lockScreenDismissalEnabled` value, keep track of said value if subsequent `OnDriverDistraction`s are missing the `lockScreenDismissalEnabled` value. This is done because the `lockScreenDismissalEnabled` state is assumed to be the same value until a new `lockScreenDismissalEnabled` value is received. SDLOnDriverDistraction *currentDriverDistraction = notification.notification; if (currentDriverDistraction.lockScreenDismissalEnabled == nil && self.lastDriverDistractionNotification.lockScreenDismissalEnabled != nil){ @@ -172,7 +178,10 @@ - (void)sdl_driverDistractionStateDidChange:(SDLRPCNotificationNotification *)no currentDriverDistraction.lockScreenDismissalWarning = self.lastDriverDistractionNotification.lockScreenDismissalWarning; } self.lastDriverDistractionNotification = currentDriverDistraction; + + // Update dismissible state, then update the lock screen status itself [self sdl_updateLockScreenDismissable]; + [self.statusManager updateDriverDistractionState:currentDriverDistraction]; } #pragma mark - Private Helpers diff --git a/SmartDeviceLink/private/SDLLockScreenStatusInfo.m b/SmartDeviceLink/private/SDLLockScreenStatusInfo.m index d7395c11f..9ff6460ea 100644 --- a/SmartDeviceLink/private/SDLLockScreenStatusInfo.m +++ b/SmartDeviceLink/private/SDLLockScreenStatusInfo.m @@ -37,7 +37,15 @@ - (instancetype)initWithDriverDistractionStatus:(nullable NSNumber *)dr } - (NSString *)description { - return [NSString stringWithFormat:@"driverDistractionStatus: %@, userSelected: %@, lockScreenStatus: %lu, hmiLevel: %@", self.driverDistractionStatus, self.userSelected, (unsigned long)self.lockScreenStatus, self.hmiLevel]; + return [NSString stringWithFormat:@"driverDistractionStatus: %@, userSelected: %@, lockScreenStatus: %@, hmiLevel: %@", (self.driverDistractionStatus ? @"ON" : @"OFF"), (self.userSelected ? @"YES" : @"NO"), [self descriptionForStatus:self.lockScreenStatus], self.hmiLevel]; +} + +- (NSString *)descriptionForStatus:(SDLLockScreenStatus)status { + switch (status) { + case SDLLockScreenStatusOff: return @"Off"; + case SDLLockScreenStatusOptional: return @"Optional"; + case SDLLockScreenStatusRequired: return @"Required"; + } } @end diff --git a/SmartDeviceLink/private/SDLLockScreenStatusManager.h b/SmartDeviceLink/private/SDLLockScreenStatusManager.h index fd8cff605..e94aaa1b7 100644 --- a/SmartDeviceLink/private/SDLLockScreenStatusManager.h +++ b/SmartDeviceLink/private/SDLLockScreenStatusManager.h @@ -8,8 +8,10 @@ #import "SDLHMILevel.h" #import "SDLLockScreenConstants.h" -@class SDLNotificationDispatcher; @class SDLLockScreenStatusInfo; +@class SDLNotificationDispatcher; +@class SDLOnDriverDistraction; +@class SDLOnHMIStatus; NS_ASSUME_NONNULL_BEGIN @@ -27,6 +29,9 @@ static NSString *const SDLDidChangeLockScreenStatusNotification = @"com.sdl.noti - (instancetype)init NS_UNAVAILABLE; - (instancetype)initWithNotificationDispatcher:(SDLNotificationDispatcher *)dispatcher; +- (void)updateHMIStatus:(SDLOnHMIStatus *)hmiStatus; +- (void)updateDriverDistractionState:(SDLOnDriverDistraction *)driverDistraction; + @end NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink/private/SDLLockScreenStatusManager.m b/SmartDeviceLink/private/SDLLockScreenStatusManager.m index 3b15b60ff..d4d3a0f3f 100644 --- a/SmartDeviceLink/private/SDLLockScreenStatusManager.m +++ b/SmartDeviceLink/private/SDLLockScreenStatusManager.m @@ -31,17 +31,25 @@ - (instancetype)initWithNotificationDispatcher:(SDLNotificationDispatcher *)disp self = [super init]; if (!self) { return nil; } + _notificationDispatcher = dispatcher; _userSelected = NO; _driverDistracted = NO; _haveDriverDistractionStatus = NO; - _notificationDispatcher = dispatcher; - - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_hmiStatusDidUpdate:) name:SDLDidChangeHMIStatusNotification object:dispatcher]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_driverDistractionDidUpdate:) name:SDLDidChangeDriverDistractionStateNotification object:dispatcher]; return self; } +#pragma mark - Component Updates + +- (void)updateHMIStatus:(SDLOnHMIStatus *)hmiStatus { + self.hmiLevel = hmiStatus.hmiLevel; + [self sdl_postLockScreenStatus:self.lockScreenStatusNotification]; +} + +- (void)updateDriverDistractionState:(SDLOnDriverDistraction *)driverDistraction { + self.driverDistracted = [driverDistraction.state isEqualToEnum:SDLDriverDistractionStateOn]; + [self sdl_postLockScreenStatus:self.lockScreenStatusNotification]; +} #pragma mark - Getters / Setters #pragma mark Custom setters @@ -112,22 +120,6 @@ - (void)sdl_postLockScreenStatus:(SDLLockScreenStatusInfo *)statusNotification { [self.notificationDispatcher postNotificationName:SDLDidChangeLockScreenStatusNotification infoObject:statusNotification]; } -#pragma mark - Observers - -- (void)sdl_hmiStatusDidUpdate:(SDLRPCNotificationNotification *)notification { - SDLOnHMIStatus *hmiStatus = notification.notification; - - self.hmiLevel = hmiStatus.hmiLevel; - [self sdl_postLockScreenStatus:self.lockScreenStatusNotification]; -} - -- (void)sdl_driverDistractionDidUpdate:(SDLRPCNotificationNotification *)notification { - SDLOnDriverDistraction *driverDistraction = notification.notification; - - self.driverDistracted = [driverDistraction.state isEqualToEnum:SDLDriverDistractionStateOn]; - [self sdl_postLockScreenStatus:self.lockScreenStatusNotification]; -} - @end NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLinkTests/ProxySpecs/SDLLockScreenStatusManagerSpec.m b/SmartDeviceLinkTests/ProxySpecs/SDLLockScreenStatusManagerSpec.m index 7bca387e4..ee650ae96 100644 --- a/SmartDeviceLinkTests/ProxySpecs/SDLLockScreenStatusManagerSpec.m +++ b/SmartDeviceLinkTests/ProxySpecs/SDLLockScreenStatusManagerSpec.m @@ -270,8 +270,7 @@ }]]); SDLOnHMIStatus *hmiStatus = [[SDLOnHMIStatus alloc] initWithHMILevel:SDLHMILevelFull systemContext:SDLSystemContextMain audioStreamingState:SDLAudioStreamingStateAudible videoStreamingState:nil windowID:nil]; - SDLRPCNotificationNotification *hmiStatusNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeHMIStatusNotification object:mockDispatcher rpcNotification:hmiStatus]; - [[NSNotificationCenter defaultCenter] postNotification:hmiStatusNotification]; + [testManager updateHMIStatus:hmiStatus]; }); it(@"should update the driver distraction status and send a notification", ^{ @@ -290,8 +289,7 @@ SDLOnDriverDistraction *driverDistraction = [[SDLOnDriverDistraction alloc] init]; driverDistraction.state = SDLDriverDistractionStateOn; - SDLRPCNotificationNotification *driverDistractionStateNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeDriverDistractionStateNotification object:mockDispatcher rpcNotification:driverDistraction]; - [[NSNotificationCenter defaultCenter] postNotification:driverDistractionStateNotification]; + [testManager updateDriverDistractionState:driverDistraction]; }); it(@"should update the driver distraction status and send a notification", ^{