summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2019-08-08 14:10:15 -0400
committerGitHub <noreply@github.com>2019-08-08 14:10:15 -0400
commit91be08ecabf722282c747bbc9f34ac92a81bd119 (patch)
tree0260569fe7f609d677b99c7b12f7a0340481fb45
parentf43c7f46c0e535a322afbd76afb312bfa1fdeedc (diff)
parentb49326faf6c036bbd6c87ffd23874f309d4bea03 (diff)
downloadsdl_ios-91be08ecabf722282c747bbc9f34ac92a81bd119.tar.gz
Merge pull request #1366 from smartdevicelink/feature/issue_1365_disable_dismiss_lockscreen_gesture
Add config option to disable lock screen dismiss gesture
-rw-r--r--SmartDeviceLink/SDLLockScreenConfiguration.h11
-rw-r--r--SmartDeviceLink/SDLLockScreenConfiguration.m17
-rw-r--r--SmartDeviceLink/SDLLockScreenManager.m3
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenConfigurationSpec.m20
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m57
5 files changed, 82 insertions, 26 deletions
diff --git a/SmartDeviceLink/SDLLockScreenConfiguration.h b/SmartDeviceLink/SDLLockScreenConfiguration.h
index 80575567a..854196520 100644
--- a/SmartDeviceLink/SDLLockScreenConfiguration.h
+++ b/SmartDeviceLink/SDLLockScreenConfiguration.h
@@ -14,9 +14,9 @@ NS_ASSUME_NONNULL_BEGIN
@interface SDLLockScreenConfiguration : NSObject <NSCopying>
/**
- * Whether or not the lock screen should be shown in the "lock screen optional" state. Defaults to false.
+ * Whether or not the lock screen should be shown in the "lock screen optional" state. Defaults to NO.
*
- * @discussion In order for the "lock screen optional" state to occur, the following must be true:
+ * In order for the "lock screen optional" state to occur, the following must be true:
* 1. The app should have received at least 1 driver distraction notification (i.e. a `OnDriverDistraction` notification) from SDL Core. Older versions of Core did not send a notification immediately on connection.
* 2. The driver is not distracted (i.e. the last `OnDriverDistraction` notification received was for a driver distraction state off).
* 3. The `hmiLevel` can not be `NONE`.
@@ -25,7 +25,12 @@ NS_ASSUME_NONNULL_BEGIN
@property (assign, nonatomic) BOOL showInOptionalState;
/**
- * If YES, the lock screen should be managed by SDL and automatically engage when necessary. If NO, then the lock screen will never be engaged.
+ If YES, then the lock screen can be dismissed with a downward swipe on compatible head units. Requires a connection of SDL 6.0+ and the head unit to enable the feature. Defaults to YES.
+ */
+@property (assign, nonatomic) BOOL enableDismissGesture;
+
+/**
+ * If YES, the lock screen should be managed by SDL and automatically engage when necessary. If NO, then the lock screen will never be engaged. Defaults to YES.
*/
@property (assign, nonatomic, readonly) BOOL enableAutomaticLockScreen;
diff --git a/SmartDeviceLink/SDLLockScreenConfiguration.m b/SmartDeviceLink/SDLLockScreenConfiguration.m
index 4f82c287a..4798cf9d4 100644
--- a/SmartDeviceLink/SDLLockScreenConfiguration.m
+++ b/SmartDeviceLink/SDLLockScreenConfiguration.m
@@ -20,7 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Lifecycle
-- (instancetype)initWithAutoLockScreen:(BOOL)enableAutomatic enableInOptional:(BOOL)enableOptional backgroundColor:(UIColor *)backgroundColor appIcon:(nullable UIImage *)appIcon viewController:(nullable UIViewController *)customViewController {
+- (instancetype)initWithAutoLockScreen:(BOOL)enableAutomatic enableInOptional:(BOOL)enableOptional enableDismissGesture:(BOOL)enableDismissGesture backgroundColor:(UIColor *)backgroundColor appIcon:(nullable UIImage *)appIcon viewController:(nullable UIViewController *)customViewController {
self = [super init];
if (!self) {
return nil;
@@ -28,6 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
_enableAutomaticLockScreen = enableAutomatic;
_showInOptionalState = enableOptional;
+ _enableDismissGesture = enableDismissGesture;
_backgroundColor = backgroundColor;
_appIcon = appIcon;
_customViewController = customViewController;
@@ -36,11 +37,11 @@ NS_ASSUME_NONNULL_BEGIN
}
+ (instancetype)disabledConfiguration {
- return [[self alloc] initWithAutoLockScreen:NO enableInOptional:NO backgroundColor:[self sdl_defaultBackgroundColor] appIcon:nil viewController:nil];
+ return [[self alloc] initWithAutoLockScreen:NO enableInOptional:NO enableDismissGesture:NO backgroundColor:[self sdl_defaultBackgroundColor] appIcon:nil viewController:nil];
}
+ (instancetype)enabledConfiguration {
- return [[self alloc] initWithAutoLockScreen:YES enableInOptional:NO backgroundColor:[self sdl_defaultBackgroundColor] appIcon:nil viewController:nil];
+ return [[self alloc] initWithAutoLockScreen:YES enableInOptional:NO enableDismissGesture:YES backgroundColor:[self sdl_defaultBackgroundColor] appIcon:nil viewController:nil];
}
+ (instancetype)enabledConfigurationWithAppIcon:(UIImage *)lockScreenAppIcon backgroundColor:(nullable UIColor *)lockScreenBackgroundColor {
@@ -48,11 +49,11 @@ NS_ASSUME_NONNULL_BEGIN
lockScreenBackgroundColor = [self.class sdl_defaultBackgroundColor];
}
- return [[self alloc] initWithAutoLockScreen:YES enableInOptional:NO backgroundColor:lockScreenBackgroundColor appIcon:lockScreenAppIcon viewController:nil];
+ return [[self alloc] initWithAutoLockScreen:YES enableInOptional:NO enableDismissGesture:YES backgroundColor:lockScreenBackgroundColor appIcon:lockScreenAppIcon viewController:nil];
}
+ (instancetype)enabledConfigurationWithViewController:(UIViewController *)viewController {
- return [[self alloc] initWithAutoLockScreen:YES enableInOptional:NO backgroundColor:[self.class sdl_defaultBackgroundColor] appIcon:nil viewController:viewController];
+ return [[self alloc] initWithAutoLockScreen:YES enableInOptional:NO enableDismissGesture:YES backgroundColor:[self.class sdl_defaultBackgroundColor] appIcon:nil viewController:viewController];
}
@@ -66,11 +67,7 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - NSCopying
- (id)copyWithZone:(nullable NSZone *)zone {
- SDLLockScreenConfiguration *new = [[SDLLockScreenConfiguration allocWithZone:zone] initWithAutoLockScreen : _enableAutomaticLockScreen
- enableInOptional : _showInOptionalState
- backgroundColor : _backgroundColor
- appIcon : _appIcon
- viewController : _customViewController];
+ SDLLockScreenConfiguration *new = [[SDLLockScreenConfiguration allocWithZone:zone] initWithAutoLockScreen:_enableAutomaticLockScreen enableInOptional:_showInOptionalState enableDismissGesture:_enableDismissGesture backgroundColor:_backgroundColor appIcon:_appIcon viewController:_customViewController];
return new;
}
diff --git a/SmartDeviceLink/SDLLockScreenManager.m b/SmartDeviceLink/SDLLockScreenManager.m
index 0ffba3f7c..3d8ca341a 100644
--- a/SmartDeviceLink/SDLLockScreenManager.m
+++ b/SmartDeviceLink/SDLLockScreenManager.m
@@ -172,7 +172,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)sdl_updateLockScreenDismissable {
if (self.lastDriverDistractionNotification == nil ||
self.lastDriverDistractionNotification.lockScreenDismissalEnabled == nil ||
- !self.lastDriverDistractionNotification.lockScreenDismissalEnabled.boolValue) {
+ !self.lastDriverDistractionNotification.lockScreenDismissalEnabled.boolValue ||
+ !self.config.enableDismissGesture) {
self.lockScreenDismissable = NO;
} else {
self.lockScreenDismissable = YES;
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenConfigurationSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenConfigurationSpec.m
index 59c3974df..f0a9bff24 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenConfigurationSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenConfigurationSpec.m
@@ -14,8 +14,9 @@ describe(@"a lock screen configuration", ^{
});
it(@"should properly set properties", ^{
- expect(@(testConfig.enableAutomaticLockScreen)).to(beFalsy());
- expect(@(testConfig.showInOptionalState)).to(beFalsy());
+ expect(testConfig.enableAutomaticLockScreen).to(beFalse());
+ expect(testConfig.showInOptionalState).to(beFalse());
+ expect(testConfig.enableDismissGesture).to(beFalse());
expect(testConfig.backgroundColor).to(equal([UIColor colorWithRed:(57.0/255.0) green:(78.0/255.0) blue:(96.0/255.0) alpha:1.0]));
expect(testConfig.appIcon).to(beNil());
expect(testConfig.customViewController).to(beNil());
@@ -28,8 +29,9 @@ describe(@"a lock screen configuration", ^{
});
it(@"should properly set properties", ^{
- expect(@(testConfig.enableAutomaticLockScreen)).to(beTruthy());
- expect(@(testConfig.showInOptionalState)).to(beFalsy());
+ expect(testConfig.enableAutomaticLockScreen).to(beTrue());
+ expect(testConfig.showInOptionalState).to(beFalse());
+ expect(testConfig.enableDismissGesture).to(beTrue());
expect(testConfig.backgroundColor).to(equal([UIColor colorWithRed:(57.0/255.0) green:(78.0/255.0) blue:(96.0/255.0) alpha:1.0]));
expect(testConfig.appIcon).to(beNil());
expect(testConfig.customViewController).to(beNil());
@@ -48,8 +50,9 @@ describe(@"a lock screen configuration", ^{
});
it(@"should properly set properties", ^{
- expect(@(testConfig.enableAutomaticLockScreen)).to(beTruthy());
- expect(@(testConfig.showInOptionalState)).to(beFalsy());
+ expect(testConfig.enableAutomaticLockScreen).to(beTrue());
+ expect(testConfig.showInOptionalState).to(beFalse());
+ expect(testConfig.enableDismissGesture).to(beTrue());
expect(testConfig.backgroundColor).to(equal([UIColor blueColor]));
expect(testConfig.appIcon).to(equal(testImage));
expect(testConfig.customViewController).to(beNil());
@@ -66,8 +69,9 @@ describe(@"a lock screen configuration", ^{
});
it(@"should properly set properties", ^{
- expect(@(testConfig.enableAutomaticLockScreen)).to(beTruthy());
- expect(@(testConfig.showInOptionalState)).to(beFalsy());
+ expect(testConfig.enableAutomaticLockScreen).to(beTrue());
+ expect(testConfig.showInOptionalState).to(beFalse());
+ expect(testConfig.enableDismissGesture).to(beTrue());
expect(testConfig.backgroundColor).to(equal([UIColor colorWithRed:(57.0/255.0) green:(78.0/255.0) blue:(96.0/255.0) alpha:1.0]));
expect(testConfig.appIcon).to(beNil());
expect(testConfig.customViewController).to(equal(testVC));
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m
index 542ce850b..596c863b1 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m
@@ -13,6 +13,22 @@
#import "SDLOnDriverDistraction.h"
#import "SDLRPCNotificationNotification.h"
+@interface SDLLockScreenManager ()
+
+@property (assign, nonatomic) BOOL canPresent;
+@property (strong, nonatomic, readwrite) SDLLockScreenConfiguration *config;
+@property (strong, nonatomic) id<SDLViewControllerPresentable> presenter;
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+@property (strong, nonatomic, nullable) SDLOnLockScreenStatus *lastLockNotification;
+#pragma clang diagnostic pop
+
+@property (strong, nonatomic, nullable) SDLOnDriverDistraction *lastDriverDistractionNotification;
+@property (assign, nonatomic, readwrite, getter=isLockScreenDismissable) BOOL lockScreenDismissable;
+@property (assign, nonatomic) BOOL lockScreenDismissedByUser;
+
+@end
QuickSpecBegin(SDLLockScreenManagerSpec)
@@ -32,7 +48,7 @@ describe(@"a lock screen manager", ^{
it(@"should set properties correctly", ^{
// Note: We can't check the "lockScreenPresented" flag on the Lock Screen Manager because it's a computer property checking the window
- expect(@(fakePresenter.presented)).to(beFalsy());
+ expect(fakePresenter.presented).to(beFalse());
expect(testManager.lockScreenViewController).to(beNil());
});
@@ -110,7 +126,7 @@ describe(@"a lock screen manager", ^{
});
it(@"should have presented the lock screen", ^{
- expect(@(fakePresenter.presented)).to(beTruthy());
+ expect(fakePresenter.presented).to(beTrue());
});
it(@"should not have a vehicle icon", ^{
@@ -146,10 +162,9 @@ describe(@"a lock screen manager", ^{
it(@"should be able to be dismissed", ^{
expect(testManager.isLockScreenDismissable).toEventually(equal(YES));
});
-
});
- describe(@"when a driver distraction notification is posted with lockScreenDismissableEnabled 0 bit", ^{
+ describe(@"when a driver distraction notification is posted with lockScreenDismissableEnabled as false", ^{
__block SDLRPCNotificationNotification *testDriverDistractionNotification = nil;
beforeEach(^{
@@ -277,6 +292,40 @@ describe(@"a lock screen manager", ^{
});
});
+ context(@"with a dismissable false configuration", ^{
+ beforeEach(^{
+ SDLLockScreenConfiguration *config = [SDLLockScreenConfiguration enabledConfiguration];
+ config.enableDismissGesture = NO;
+
+ testManager = [[SDLLockScreenManager alloc] initWithConfiguration:config notificationDispatcher:nil presenter:fakePresenter];
+ [testManager start];
+ });
+
+ describe(@"when a driver distraction notification is posted with lockScreenDismissableEnabled as true", ^{
+ __block SDLRPCNotificationNotification *testDriverDistractionNotification = nil;
+
+ beforeEach(^{
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ SDLOnLockScreenStatus *status = [[SDLOnLockScreenStatus alloc] init];
+#pragma clang diagnostic pop
+ status.lockScreenStatus = SDLLockScreenStatusRequired;
+ testManager.lastLockNotification = status;
+
+ SDLOnDriverDistraction *testDriverDistraction = [[SDLOnDriverDistraction alloc] init];
+ testDriverDistraction.lockScreenDismissalEnabled = @YES;
+
+ testDriverDistractionNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeDriverDistractionStateNotification object:nil rpcNotification:testDriverDistraction];
+
+ [[NSNotificationCenter defaultCenter] postNotification:testDriverDistractionNotification];
+ });
+
+ it(@"should not be able to be dismissed", ^{
+ expect(testManager.isLockScreenDismissable).toEventually(equal(NO));
+ });
+ });
+ });
+
describe(@"A lock screen status of OPTIONAL", ^{
__block SDLLockScreenManager *testLockScreenManager = nil;
__block SDLLockScreenConfiguration *testLockScreenConfig = nil;