From d1689a097a55b774529cc17a940edb99a873928f Mon Sep 17 00:00:00 2001 From: Satbir Tanda Date: Thu, 18 Jul 2019 16:54:43 -0700 Subject: [PATCH] Add logic to observe the LockScreenStatus --- SmartDeviceLink-iOS.podspec | 1 - SmartDeviceLink-iOS.xcodeproj/project.pbxproj | 8 -- SmartDeviceLink.podspec | 1 - SmartDeviceLink/SDLLockScreenManager.m | 74 ++++++++++++++++--- SmartDeviceLink/SDLNotificationDispatcher.m | 4 - SmartDeviceLink/SDLOnLockScreenStatus.h | 51 ------------- SmartDeviceLink/SDLOnLockScreenStatus.m | 65 ---------------- SmartDeviceLink/SDLProxyListener.h | 8 -- SmartDeviceLink/SmartDeviceLink.h | 1 - 9 files changed, 62 insertions(+), 151 deletions(-) delete mode 100644 SmartDeviceLink/SDLOnLockScreenStatus.h delete mode 100644 SmartDeviceLink/SDLOnLockScreenStatus.m diff --git a/SmartDeviceLink-iOS.podspec b/SmartDeviceLink-iOS.podspec index 0b91c7649..69de6afbc 100644 --- a/SmartDeviceLink-iOS.podspec +++ b/SmartDeviceLink-iOS.podspec @@ -233,7 +233,6 @@ ss.public_header_files = [ 'SmartDeviceLink/SDLOnHMIStatus.h', 'SmartDeviceLink/SDLOnKeyboardInput.h', 'SmartDeviceLink/SDLOnLanguageChange.h', -'SmartDeviceLink/SDLOnLockScreenStatus.h', 'SmartDeviceLink/SDLOnPermissionsChange.h', 'SmartDeviceLink/SDLOnRCStatus.h', 'SmartDeviceLink/SDLOnSyncPData.h', diff --git a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj index f4457eee9..562670db2 100644 --- a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj +++ b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj @@ -747,8 +747,6 @@ 5D61FD121A84238C00846EE7 /* SDLOnKeyboardInput.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D61FB251A84238B00846EE7 /* SDLOnKeyboardInput.m */; }; 5D61FD131A84238C00846EE7 /* SDLOnLanguageChange.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D61FB261A84238B00846EE7 /* SDLOnLanguageChange.h */; settings = {ATTRIBUTES = (Public, ); }; }; 5D61FD141A84238C00846EE7 /* SDLOnLanguageChange.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D61FB271A84238B00846EE7 /* SDLOnLanguageChange.m */; }; - 5D61FD151A84238C00846EE7 /* SDLOnLockScreenStatus.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D61FB281A84238B00846EE7 /* SDLOnLockScreenStatus.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 5D61FD161A84238C00846EE7 /* SDLOnLockScreenStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D61FB291A84238B00846EE7 /* SDLOnLockScreenStatus.m */; }; 5D61FD171A84238C00846EE7 /* SDLOnPermissionsChange.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D61FB2A1A84238B00846EE7 /* SDLOnPermissionsChange.h */; settings = {ATTRIBUTES = (Public, ); }; }; 5D61FD181A84238C00846EE7 /* SDLOnPermissionsChange.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D61FB2B1A84238B00846EE7 /* SDLOnPermissionsChange.m */; }; 5D61FD191A84238C00846EE7 /* SDLOnSyncPData.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D61FB2C1A84238B00846EE7 /* SDLOnSyncPData.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -2396,8 +2394,6 @@ 5D61FB251A84238B00846EE7 /* SDLOnKeyboardInput.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLOnKeyboardInput.m; sourceTree = ""; }; 5D61FB261A84238B00846EE7 /* SDLOnLanguageChange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLOnLanguageChange.h; sourceTree = ""; }; 5D61FB271A84238B00846EE7 /* SDLOnLanguageChange.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLOnLanguageChange.m; sourceTree = ""; }; - 5D61FB281A84238B00846EE7 /* SDLOnLockScreenStatus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLOnLockScreenStatus.h; sourceTree = ""; }; - 5D61FB291A84238B00846EE7 /* SDLOnLockScreenStatus.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLOnLockScreenStatus.m; sourceTree = ""; }; 5D61FB2A1A84238B00846EE7 /* SDLOnPermissionsChange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLOnPermissionsChange.h; sourceTree = ""; }; 5D61FB2B1A84238B00846EE7 /* SDLOnPermissionsChange.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLOnPermissionsChange.m; sourceTree = ""; }; 5D61FB2C1A84238B00846EE7 /* SDLOnSyncPData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLOnSyncPData.h; sourceTree = ""; }; @@ -4837,8 +4833,6 @@ 5D61FB251A84238B00846EE7 /* SDLOnKeyboardInput.m */, 5D61FB261A84238B00846EE7 /* SDLOnLanguageChange.h */, 5D61FB271A84238B00846EE7 /* SDLOnLanguageChange.m */, - 5D61FB281A84238B00846EE7 /* SDLOnLockScreenStatus.h */, - 5D61FB291A84238B00846EE7 /* SDLOnLockScreenStatus.m */, 5D61FB2A1A84238B00846EE7 /* SDLOnPermissionsChange.h */, 5D61FB2B1A84238B00846EE7 /* SDLOnPermissionsChange.m */, 1EAA47092032BAE5000FE74B /* SDLOnRCStatus.h */, @@ -6231,7 +6225,6 @@ 8817C2802289F4B900DB2DEC /* SDLIAPDataSessionDelegate.h in Headers */, 5D61FC841A84238C00846EE7 /* SDLDeviceLevelStatus.h in Headers */, 5DB92D321AC9C8BA00C15BB0 /* SDLRPCStruct.h in Headers */, - 5D61FD151A84238C00846EE7 /* SDLOnLockScreenStatus.h in Headers */, 5D61FD291A84238C00846EE7 /* SDLPerformInteraction.h in Headers */, 884E702321FBA952008D53BA /* SDLAppServiceType.h in Headers */, DAC572571D1067270004288B /* SDLTouchManager.h in Headers */, @@ -7207,7 +7200,6 @@ 5D00AC681F140F0A004000D9 /* SDLSystemCapabilityType.m in Sources */, E9C32B9D1AB20C5900F283AF /* EAAccessory+SDLProtocols.m in Sources */, 5D61FCC61A84238C00846EE7 /* SDLHMIZoneCapabilities.m in Sources */, - 5D61FD161A84238C00846EE7 /* SDLOnLockScreenStatus.m in Sources */, 5D61FDAE1A84238C00846EE7 /* SDLSubscribeButton.m in Sources */, DA9F7E6C1DCBFB0700ACAE48 /* SDLDeliveryMode.m in Sources */, 5D61FC581A84238C00846EE7 /* SDLButtonPressMode.m in Sources */, diff --git a/SmartDeviceLink.podspec b/SmartDeviceLink.podspec index 17fa2cfc8..93920663e 100644 --- a/SmartDeviceLink.podspec +++ b/SmartDeviceLink.podspec @@ -234,7 +234,6 @@ sdefault.public_header_files = [ 'SmartDeviceLink/SDLOnHMIStatus.h', 'SmartDeviceLink/SDLOnKeyboardInput.h', 'SmartDeviceLink/SDLOnLanguageChange.h', -'SmartDeviceLink/SDLOnLockScreenStatus.h', 'SmartDeviceLink/SDLOnPermissionsChange.h', 'SmartDeviceLink/SDLOnRCStatus.h', 'SmartDeviceLink/SDLOnSyncPData.h', diff --git a/SmartDeviceLink/SDLLockScreenManager.m b/SmartDeviceLink/SDLLockScreenManager.m index 083b6c136..d072e80e0 100644 --- a/SmartDeviceLink/SDLLockScreenManager.m +++ b/SmartDeviceLink/SDLLockScreenManager.m @@ -14,11 +14,12 @@ #import "SDLLockScreenStatus.h" #import "SDLLockScreenViewController.h" #import "SDLNotificationConstants.h" -#import "SDLOnLockScreenStatus.h" #import "SDLOnDriverDistraction.h" #import "SDLRPCNotificationNotification.h" #import "SDLScreenshotViewController.h" #import "SDLViewControllerPresentable.h" +#import "SDLOnHMIStatus.h" +#import "SDLHMILevel.h" NS_ASSUME_NONNULL_BEGIN @@ -28,7 +29,10 @@ @interface SDLLockScreenManager () @property (assign, nonatomic) BOOL canPresent; @property (strong, nonatomic, readwrite) SDLLockScreenConfiguration *config; @property (strong, nonatomic) id presenter; -@property (strong, nonatomic, nullable) SDLOnLockScreenStatus *lastLockNotification; +@property (copy, nonatomic, nullable) SDLHMILevel hmiLevel; +@property (assign, nonatomic) BOOL userSelected; +@property (assign, nonatomic) BOOL driverDistracted; +@property (assign, nonatomic) BOOL haveDriverDistractionStatus; @property (strong, nonatomic, nullable) SDLOnDriverDistraction *lastDriverDistractionNotification; @property (assign, nonatomic, readwrite, getter=isLockScreenDismissable) BOOL lockScreenDismissable; @@ -44,11 +48,15 @@ - (instancetype)initWithConfiguration:(SDLLockScreenConfiguration *)config notif } _canPresent = NO; + _hmiLevel = nil; + _userSelected = NO; + _driverDistracted = NO; + _haveDriverDistractionStatus = NO; _lockScreenDismissable = NO; _config = config; _presenter = presenter; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_lockScreenStatusDidChange:) name:SDLDidChangeLockScreenStatusNotification object:dispatcher]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_hmiLevelDidChange:) name:SDLDidChangeHMIStatusNotification object:dispatcher]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_lockScreenIconReceived:) name:SDLDidReceiveLockScreenIcon object:dispatcher]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_appDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_driverDistractionStateDidChange:) name:SDLDidChangeDriverDistractionStateNotification object:dispatcher]; @@ -98,13 +106,19 @@ - (nullable UIViewController *)lockScreenViewController { #pragma mark - Notification Selectors -- (void)sdl_lockScreenStatusDidChange:(SDLRPCNotificationNotification *)notification { - if (![notification isNotificationMemberOfClass:[SDLOnLockScreenStatus class]]) { +- (void)sdl_hmiLevelDidChange:(SDLRPCNotificationNotification *)notification { + if (![notification isNotificationMemberOfClass:[SDLOnHMIStatus class]]) { return; } - - self.lastLockNotification = notification.notification; - [self sdl_checkLockScreen]; + + SDLOnHMIStatus *hmiStatus = notification.notification; + + self.hmiLevel = hmiStatus.hmiLevel; + if ([self.hmiLevel isEqualToEnum:SDLHMILevelFull] || [self.hmiLevel isEqualToEnum:SDLHMILevelLimited]) { + self.userSelected = YES; + } else if ([self.hmiLevel isEqualToEnum:SDLHMILevelNone]) { + self.userSelected = NO; + } } - (void)sdl_lockScreenIconReceived:(NSNotification *)notification { @@ -131,29 +145,32 @@ - (void)sdl_driverDistractionStateDidChange:(SDLRPCNotificationNotification *)no } self.lastDriverDistractionNotification = notification.notification; + self.haveDriverDistractionStatus = YES; + self.driverDistracted = [self.lastDriverDistractionNotification.state isEqualToEnum:SDLDriverDistractionStateOn] ? YES : NO; + [self sdl_checkLockScreen]; [self sdl_updateLockScreenDismissable]; } #pragma mark - Private Helpers - (void)sdl_checkLockScreen { - if (self.lockScreenViewController == nil || self.lastLockNotification == nil) { + if (self.lockScreenViewController == nil) { return; } // Present the VC depending on the lock screen status BOOL lockScreenDismissableEnabled = [self.lastDriverDistractionNotification.lockScreenDismissalEnabled boolValue]; - if ([self.lastLockNotification.lockScreenStatus isEqualToEnum:SDLLockScreenStatusRequired]) { + if ([self.lockScreenStatus isEqualToEnum:SDLLockScreenStatusRequired]) { if (!self.presenter.presented && self.canPresent && !lockScreenDismissableEnabled) { [self.presenter present]; } - } else if ([self.lastLockNotification.lockScreenStatus isEqualToEnum:SDLLockScreenStatusOptional]) { + } else if ([self.lockScreenStatus isEqualToEnum:SDLLockScreenStatusOptional]) { if (self.config.showInOptionalState && !self.presenter.presented && self.canPresent && !lockScreenDismissableEnabled) { [self.presenter present]; } else if (!self.config.showInOptionalState && self.presenter.presented) { [self.presenter dismiss]; } - } else if ([self.lastLockNotification.lockScreenStatus isEqualToEnum:SDLLockScreenStatusOff]) { + } else if ([self.lockScreenStatus isEqualToEnum:SDLLockScreenStatusOff]) { if (self.presenter.presented) { [self.presenter dismiss]; } @@ -195,6 +212,39 @@ - (void)sdl_updateLockscreenViewControllerWithDismissableState:(BOOL)enabled { }); } +- (SDLLockScreenStatus)lockScreenStatus { + if (self.hmiLevel == nil || [self.hmiLevel isEqualToEnum:SDLHMILevelNone]) { + // App is not active on the car + return SDLLockScreenStatusOff; + } else if ([self.hmiLevel isEqualToEnum:SDLHMILevelBackground]) { + // App is in the background on the car + if (self.userSelected) { + // It was user selected + if (self.haveDriverDistractionStatus && !self.driverDistracted) { + // We have the distraction status, and the driver is not distracted + return SDLLockScreenStatusOptional; + } else { + // We don't have the distraction status, and/or the driver is distracted + return SDLLockScreenStatusRequired; + } + } else { + return SDLLockScreenStatusOff; + } + } else if ([self.hmiLevel isEqualToEnum:SDLHMILevelFull] || [self.hmiLevel isEqualToEnum:SDLHMILevelLimited]) { + // App is in the foreground on the car in some manner + if (self.haveDriverDistractionStatus && !self.driverDistracted) { + // We have the distraction status, and the driver is not distracted + return SDLLockScreenStatusOptional; + } else { + // We don't have the distraction status, and/or the driver is distracted + return SDLLockScreenStatusRequired; + } + } else { + // This shouldn't be possible. + return SDLLockScreenStatusOff; + } +} + @end NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink/SDLNotificationDispatcher.m b/SmartDeviceLink/SDLNotificationDispatcher.m index 809f3170f..976193424 100644 --- a/SmartDeviceLink/SDLNotificationDispatcher.m +++ b/SmartDeviceLink/SDLNotificationDispatcher.m @@ -583,10 +583,6 @@ - (void)onOnLanguageChange:(SDLOnLanguageChange *)notification { [self postRPCNotificationNotification:SDLDidChangeLanguageNotification notification:notification]; } -- (void)onOnLockScreenNotification:(SDLOnLockScreenStatus *)notification { - [self postRPCNotificationNotification:SDLDidChangeLockScreenStatusNotification notification:notification]; -} - - (void)onOnPermissionsChange:(SDLOnPermissionsChange *)notification { [self postRPCNotificationNotification:SDLDidChangePermissionsNotification notification:notification]; } diff --git a/SmartDeviceLink/SDLOnLockScreenStatus.h b/SmartDeviceLink/SDLOnLockScreenStatus.h deleted file mode 100644 index 255c0d71f..000000000 --- a/SmartDeviceLink/SDLOnLockScreenStatus.h +++ /dev/null @@ -1,51 +0,0 @@ -// -// SDLOnLockScreenStatus.h -// SmartDeviceLink -// - -#import "SDLRPCNotification.h" - -#import "SDLHMILevel.h" -#import "SDLLockScreenStatus.h" - - -/** - To help prevent driver distraction, any SmartDeviceLink application is required to implement a lockscreen that must be enforced while the application is active on the system while the vehicle is in motion. - - This lockscreen must perform the following: - - Limit all application control usability from the mobile device with a full-screen static image overlay or separate view. - - For simplicity, the `OnLockScreenStatus` RPC will be provided via the `onOnLockScreenNotification` call back. The call back will include the LockScreenStatus enum which indicates if the lockscreen is required, optional or not required. - - The call back also includes details regarding the current HMI_Status level, driver distraction status and user selection status of the application. - */ - -NS_ASSUME_NONNULL_BEGIN - -@interface SDLOnLockScreenStatus : SDLRPCNotification - -/** - Get the current driver distraction status(i.e. whether driver distraction rules are in effect, or not) - */ -@property (strong, nonatomic) NSNumber *driverDistractionStatus; - -/** - Get user selection status for the application (has the app been selected via hmi or voice command) - */ - -@property (strong, nonatomic) NSNumber *userSelected; - -/** - Indicates if the lockscreen should be required, optional or off - */ -@property (strong, nonatomic) SDLLockScreenStatus lockScreenStatus; - -/** - Get HMILevel in effect for the application - */ -@property (strong, nonatomic) SDLHMILevel hmiLevel; - -@end - -NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink/SDLOnLockScreenStatus.m b/SmartDeviceLink/SDLOnLockScreenStatus.m deleted file mode 100644 index 563b593bb..000000000 --- a/SmartDeviceLink/SDLOnLockScreenStatus.m +++ /dev/null @@ -1,65 +0,0 @@ -// -// SDLOnLockScreenStatus.m -// SmartDeviceLink -// - -#import "SDLOnLockScreenStatus.h" - -#import "NSMutableDictionary+Store.h" -#import "SDLHMILevel.h" -#import "SDLLockScreenStatus.h" -#import "SDLRPCParameterNames.h" -#import "SDLRPCFunctionNames.h" - -NS_ASSUME_NONNULL_BEGIN - -@implementation SDLOnLockScreenStatus - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" -- (instancetype)init { - if (self = [super initWithName:SDLRPCFunctionNameOnLockScreenStatus]) { - } - return self; -} -#pragma clang diagnostic pop - -- (void)setLockScreenStatus:(SDLLockScreenStatus)lockScreenStatus { - [self.parameters sdl_setObject:lockScreenStatus forName:SDLRPCParameterNameOnLockScreenStatus]; -} - -- (SDLLockScreenStatus)lockScreenStatus { - NSError *error = nil; - return [self.parameters sdl_enumForName:SDLRPCParameterNameOnLockScreenStatus error:&error]; -} - -- (void)setHmiLevel:(SDLHMILevel)hmiLevel { - [self.parameters sdl_setObject:hmiLevel forName:SDLRPCParameterNameHMILevel]; -} - -- (SDLHMILevel)hmiLevel { - NSError *error = nil; - return [self.parameters sdl_enumForName:SDLRPCParameterNameHMILevel error:&error]; -} - -- (void)setUserSelected:(NSNumber *)userSelected { - [self.parameters sdl_setObject:userSelected forName:SDLRPCParameterNameUserSelected]; -} - -- (NSNumber *)userSelected { - NSError *error = nil; - return [self.parameters sdl_objectForName:SDLRPCParameterNameUserSelected ofClass:NSNumber.class error:&error]; -} - -- (void)setDriverDistractionStatus:(NSNumber *)driverDistractionStatus { - [self.parameters sdl_setObject:driverDistractionStatus forName:SDLRPCParameterNameDriverDistractionStatus]; -} - -- (NSNumber *)driverDistractionStatus { - NSError *error = nil; - return [self.parameters sdl_objectForName:SDLRPCParameterNameDriverDistractionStatus ofClass:NSNumber.class error:&error]; -} - -@end - -NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink/SDLProxyListener.h b/SmartDeviceLink/SDLProxyListener.h index 7625d46a2..13bd3dd33 100644 --- a/SmartDeviceLink/SDLProxyListener.h +++ b/SmartDeviceLink/SDLProxyListener.h @@ -65,7 +65,6 @@ @class SDLOnInteriorVehicleData; @class SDLOnKeyboardInput; @class SDLOnLanguageChange; -@class SDLOnLockScreenStatus; @class SDLOnPermissionsChange; @class SDLOnRCStatus; @class SDLOnSyncPData; @@ -1028,13 +1027,6 @@ NS_ASSUME_NONNULL_BEGIN */ - (void)onOnLanguageChange:(SDLOnLanguageChange *)notification; -/** - * Called when an On Lock Screen notification is received from Core - * - * @param notification A SDLOnLockScreenStatus object - */ -- (void)onOnLockScreenNotification:(SDLOnLockScreenStatus *)notification; - /** * Called when an On Permissions Change notification is received from Core * diff --git a/SmartDeviceLink/SmartDeviceLink.h b/SmartDeviceLink/SmartDeviceLink.h index 59b4763c1..c291bb80b 100644 --- a/SmartDeviceLink/SmartDeviceLink.h +++ b/SmartDeviceLink/SmartDeviceLink.h @@ -146,7 +146,6 @@ FOUNDATION_EXPORT const unsigned char SmartDeviceLinkVersionString[]; #import "SDLOnInteriorVehicleData.h" #import "SDLOnKeyboardInput.h" #import "SDLOnLanguageChange.h" -#import "SDLOnLockScreenStatus.h" #import "SDLOnPermissionsChange.h" #import "SDLOnRCStatus.h" #import "SDLOnSyncPData.h"