summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSatbir Tanda <satbirtanda@gmail.com>2019-06-08 03:00:02 -0700
committerSatbir Tanda <satbirtanda@gmail.com>2019-06-08 03:00:02 -0700
commit96b618a0ef53d2bf1b19c5847c697a08eff8c93a (patch)
tree279c248d9dcc158b8ea51216b5f17340ff94714e
parentfe9fa9801a2d218f88f47bc5fd50ec893065f132 (diff)
downloadsdl_ios-96b618a0ef53d2bf1b19c5847c697a08eff8c93a.tar.gz
Update SDLLockScreenManagerSpec.m
Add readonly lockScreenDismissableEnabled property in SDLLockScreenManager.h Refactor SDLLockScreenManager.m
-rw-r--r--SmartDeviceLink/SDLLockScreenManager.h5
-rw-r--r--SmartDeviceLink/SDLLockScreenManager.m53
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m65
3 files changed, 101 insertions, 22 deletions
diff --git a/SmartDeviceLink/SDLLockScreenManager.h b/SmartDeviceLink/SDLLockScreenManager.h
index f709c53ee..8d48a63b8 100644
--- a/SmartDeviceLink/SDLLockScreenManager.h
+++ b/SmartDeviceLink/SDLLockScreenManager.h
@@ -23,6 +23,11 @@ NS_ASSUME_NONNULL_BEGIN
@property (assign, nonatomic, readonly) BOOL lockScreenPresented;
/**
+ * Whether or not the lock screen is currently dismissable
+ */
+@property (assign, nonatomic, readonly) BOOL lockScreenDismissableEnabled;
+
+/**
* The lock screen configuration used to set up the manager
*/
@property (strong, nonatomic, readonly) SDLLockScreenConfiguration *config;
diff --git a/SmartDeviceLink/SDLLockScreenManager.m b/SmartDeviceLink/SDLLockScreenManager.m
index 110f93926..72d99f1e8 100644
--- a/SmartDeviceLink/SDLLockScreenManager.m
+++ b/SmartDeviceLink/SDLLockScreenManager.m
@@ -31,6 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (strong, nonatomic, nullable) SDLOnLockScreenStatus *lastLockNotification;
@property (strong, nonatomic, nullable) SDLOnDriverDistraction *lastDriverDistractionNotification;
@property (strong, nonatomic) UISwipeGestureRecognizer *swipeGesture;
+@property (assign, nonatomic) BOOL lockScreenDismissableEnabled;
@end
@@ -44,10 +45,10 @@ NS_ASSUME_NONNULL_BEGIN
}
_canPresent = NO;
+ _lockScreenDismissableEnabled = NO;
_config = config;
_presenter = presenter;
-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_lockScreenStatusDidChange:) name:SDLDidChangeLockScreenStatusNotification 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];
@@ -56,16 +57,6 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
-// Lazy init of swipe gesture
-- (UISwipeGestureRecognizer *)swipeGesture {
- if (!_swipeGesture) {
- UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeDown:)];
- [swipeGesture setDirection: UISwipeGestureRecognizerDirectionDown];
- _swipeGesture = swipeGesture;
- }
- return _swipeGesture;
-}
-
- (void)start {
self.canPresent = NO;
@@ -106,6 +97,15 @@ NS_ASSUME_NONNULL_BEGIN
return self.presenter.lockViewController;
}
+// Lazy init of swipe gesture
+- (UISwipeGestureRecognizer *)swipeGesture {
+ if (!_swipeGesture) {
+ UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeDown:)];
+ [swipeGesture setDirection: UISwipeGestureRecognizerDirectionDown];
+ _swipeGesture = swipeGesture;
+ }
+ return _swipeGesture;
+}
#pragma mark - Notification Selectors
@@ -171,18 +171,29 @@ NS_ASSUME_NONNULL_BEGIN
}
- (void)sdl_toggleLockscreenDismissalableState {
- SDLLockScreenManager *__weak weakSelf = self;
- if (self.lastDriverDistractionNotification == nil || self.lastDriverDistractionNotification.lockScreenDismissalEnabled == nil) {
- dispatch_async(dispatch_get_main_queue(), ^{
- SDLLockScreenManager *strongSelf = weakSelf;
- [strongSelf.lockScreenViewController.view removeGestureRecognizer:strongSelf.swipeGesture];
- });
+ if (self.lastDriverDistractionNotification == nil || self.lastDriverDistractionNotification.lockScreenDismissalEnabled == nil ||
+ ![self.lastDriverDistractionNotification.lockScreenDismissalEnabled boolValue]) {
+ self.lockScreenDismissableEnabled = NO;
} else {
- dispatch_async(dispatch_get_main_queue(), ^{
- SDLLockScreenManager *strongSelf = weakSelf;
- [strongSelf.lockScreenViewController.view addGestureRecognizer:strongSelf.swipeGesture];
- });
+ self.lockScreenDismissableEnabled = YES;
+ }
+ [self sdl_toggleLockscreenDismissalableWithState:self.lockScreenDismissableEnabled];
+}
+
+- (void)sdl_toggleLockscreenDismissalableWithState:(BOOL)enabled {
+ if (![self.lockScreenViewController isKindOfClass:[UIViewController class]]) {
+ return;
}
+
+ SDLLockScreenManager *__weak weakSelf = self;
+ dispatch_async(dispatch_get_main_queue(), ^{
+ SDLLockScreenManager *strongSelf = weakSelf;
+ if (enabled) {
+ [strongSelf.lockScreenViewController.view addGestureRecognizer:strongSelf.swipeGesture];
+ } else {
+ [strongSelf.lockScreenViewController.view removeGestureRecognizer:strongSelf.swipeGesture];
+ }
+ });
}
- (void)didSwipeDown:(UISwipeGestureRecognizer *)gesture {
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m
index 489de7fb0..5096babd9 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m
@@ -10,6 +10,7 @@
#import "SDLNotificationConstants.h"
#import "SDLNotificationDispatcher.h"
#import "SDLOnLockScreenStatus.h"
+#import "SDLOnDriverDistraction.h"
#import "SDLRPCNotificationNotification.h"
@@ -85,13 +86,22 @@ describe(@"a lock screen manager", ^{
describe(@"when the lock screen status becomes REQUIRED", ^{
__block SDLOnLockScreenStatus *testRequiredStatus = nil;
-
+ __block SDLOnDriverDistraction *testDriverDistraction = nil;
+ __block SDLRPCNotificationNotification *testDriverDistractionNotification = nil;
+
beforeEach(^{
testRequiredStatus = [[SDLOnLockScreenStatus alloc] init];
testRequiredStatus.lockScreenStatus = SDLLockScreenStatusRequired;
SDLRPCNotificationNotification *testLockStatusNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeLockScreenStatusNotification object:nil rpcNotification:testRequiredStatus];
[[NSNotificationCenter defaultCenter] postNotification:testLockStatusNotification];
+
+ testDriverDistraction = [[SDLOnDriverDistraction alloc] init];
+ testDriverDistraction.lockScreenDismissalEnabled = @1;
+
+ testDriverDistractionNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeDriverDistractionStateNotification object:nil rpcNotification:testDriverDistraction];
+
+ [[NSNotificationCenter defaultCenter] postNotification:testDriverDistractionNotification];
});
it(@"should have presented the lock screen", ^{
@@ -116,6 +126,59 @@ describe(@"a lock screen manager", ^{
});
});
+ describe(@"when a driver distraction notification is posted with lockScreenDismissableEnabled 1 bit", ^{
+ __block SDLRPCNotificationNotification *testDriverDistractionNotification = nil;
+
+ beforeEach(^{
+ testDriverDistraction = [[SDLOnDriverDistraction alloc] init];
+ testDriverDistraction.lockScreenDismissalEnabled = @1;
+
+ testDriverDistractionNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeDriverDistractionStateNotification object:nil rpcNotification:testDriverDistraction];
+
+ [[NSNotificationCenter defaultCenter] postNotification:testDriverDistractionNotification];
+ });
+
+ it(@"should be able to be dismissed", ^{
+ expect(testManager.lockScreenDismissableEnabled).toEventually(equal(YES));
+ });
+
+ });
+
+ describe(@"when a driver distraction notification is posted with lockScreenDismissableEnabled 0 bit", ^{
+ __block SDLRPCNotificationNotification *testDriverDistractionNotification = nil;
+
+ beforeEach(^{
+ testDriverDistraction = [[SDLOnDriverDistraction alloc] init];
+ testDriverDistraction.lockScreenDismissalEnabled = @0;
+
+ testDriverDistractionNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeDriverDistractionStateNotification object:nil rpcNotification:testDriverDistraction];
+
+ [[NSNotificationCenter defaultCenter] postNotification:testDriverDistractionNotification];
+ });
+
+ it(@"should not be able to be dismissed", ^{
+ expect(testManager.lockScreenDismissableEnabled).toEventually(equal(NO));
+ });
+
+ });
+
+ describe(@"when a driver distraction notification is posted with lockScreenDismissableEnabled nil bit", ^{
+ __block SDLRPCNotificationNotification *testDriverDistractionNotification = nil;
+
+ beforeEach(^{
+ testDriverDistraction = [[SDLOnDriverDistraction alloc] init];
+
+ testDriverDistractionNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeDriverDistractionStateNotification object:nil rpcNotification:testDriverDistraction];
+
+ [[NSNotificationCenter defaultCenter] postNotification:testDriverDistractionNotification];
+ });
+
+ it(@"should not be able to be dismissed", ^{
+ expect(testManager.lockScreenDismissableEnabled).toEventually(equal(NO));
+ });
+
+ });
+
describe(@"then the manager is stopped", ^{
beforeEach(^{
[testManager stop];