Skip to content

Commit

Permalink
Add logic to observe the LockScreenStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
SatbirTanda committed Jul 18, 2019
1 parent 1b35cff commit d1689a0
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 151 deletions.
1 change: 0 additions & 1 deletion SmartDeviceLink-iOS.podspec
Expand Up @@ -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',
Expand Down
8 changes: 0 additions & 8 deletions SmartDeviceLink-iOS.xcodeproj/project.pbxproj
Expand Up @@ -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, ); }; };
Expand Down Expand Up @@ -2396,8 +2394,6 @@
5D61FB251A84238B00846EE7 /* SDLOnKeyboardInput.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLOnKeyboardInput.m; sourceTree = "<group>"; };
5D61FB261A84238B00846EE7 /* SDLOnLanguageChange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLOnLanguageChange.h; sourceTree = "<group>"; };
5D61FB271A84238B00846EE7 /* SDLOnLanguageChange.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLOnLanguageChange.m; sourceTree = "<group>"; };
5D61FB281A84238B00846EE7 /* SDLOnLockScreenStatus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLOnLockScreenStatus.h; sourceTree = "<group>"; };
5D61FB291A84238B00846EE7 /* SDLOnLockScreenStatus.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLOnLockScreenStatus.m; sourceTree = "<group>"; };
5D61FB2A1A84238B00846EE7 /* SDLOnPermissionsChange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLOnPermissionsChange.h; sourceTree = "<group>"; };
5D61FB2B1A84238B00846EE7 /* SDLOnPermissionsChange.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLOnPermissionsChange.m; sourceTree = "<group>"; };
5D61FB2C1A84238B00846EE7 /* SDLOnSyncPData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLOnSyncPData.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
1 change: 0 additions & 1 deletion SmartDeviceLink.podspec
Expand Up @@ -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',
Expand Down
74 changes: 62 additions & 12 deletions SmartDeviceLink/SDLLockScreenManager.m
Expand Up @@ -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
Expand All @@ -28,7 +29,10 @@ @interface SDLLockScreenManager ()
@property (assign, nonatomic) BOOL canPresent;
@property (strong, nonatomic, readwrite) SDLLockScreenConfiguration *config;
@property (strong, nonatomic) id<SDLViewControllerPresentable> 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;

Expand All @@ -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];
Expand Down Expand Up @@ -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 {
Expand All @@ -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];
}
Expand Down Expand Up @@ -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
4 changes: 0 additions & 4 deletions SmartDeviceLink/SDLNotificationDispatcher.m
Expand Up @@ -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];
}
Expand Down
51 changes: 0 additions & 51 deletions SmartDeviceLink/SDLOnLockScreenStatus.h

This file was deleted.

65 changes: 0 additions & 65 deletions SmartDeviceLink/SDLOnLockScreenStatus.m

This file was deleted.

8 changes: 0 additions & 8 deletions SmartDeviceLink/SDLProxyListener.h
Expand Up @@ -65,7 +65,6 @@
@class SDLOnInteriorVehicleData;
@class SDLOnKeyboardInput;
@class SDLOnLanguageChange;
@class SDLOnLockScreenStatus;
@class SDLOnPermissionsChange;
@class SDLOnRCStatus;
@class SDLOnSyncPData;
Expand Down Expand Up @@ -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
*
Expand Down
1 change: 0 additions & 1 deletion SmartDeviceLink/SmartDeviceLink.h
Expand Up @@ -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"
Expand Down

0 comments on commit d1689a0

Please sign in to comment.