summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2018-09-14 13:52:55 -0400
committerGitHub <noreply@github.com>2018-09-14 13:52:55 -0400
commitba71c667ad97f7409330cf7d350f3f581a7cf9f8 (patch)
tree17ac27e601d49904f17d14ce2c18bfa3a201cd5f
parente431c90d0163f26985559ca61ac8adc6efa61298 (diff)
parent776e70261ff70cc9d4367c2412193a02534904f1 (diff)
downloadsdl_ios-ba71c667ad97f7409330cf7d350f3f581a7cf9f8.tar.gz
Merge pull request #1073 from smartdevicelink/bugfix/issue_1070_lock_screen_visibility_can_not_be_toggled
Fixed the lock screen configuration's show in optional state
-rw-r--r--SmartDeviceLink/SDLLockScreenConfiguration.h8
-rw-r--r--SmartDeviceLink/SDLLockScreenManager.m2
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m56
3 files changed, 64 insertions, 2 deletions
diff --git a/SmartDeviceLink/SDLLockScreenConfiguration.h b/SmartDeviceLink/SDLLockScreenConfiguration.h
index cf1287cc3..80575567a 100644
--- a/SmartDeviceLink/SDLLockScreenConfiguration.h
+++ b/SmartDeviceLink/SDLLockScreenConfiguration.h
@@ -14,7 +14,13 @@ 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 'NO'.
+ * Whether or not the lock screen should be shown in the "lock screen optional" state. Defaults to false.
+ *
+ * @discussion 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`.
+ * 4. If the `hmiLevel` is currently `BACKGROUND` then the previous `hmiLevel` should have been `FULL` or `LIMITED` (i.e. the user should have interacted with app before it was backgrounded).
*/
@property (assign, nonatomic) BOOL showInOptionalState;
diff --git a/SmartDeviceLink/SDLLockScreenManager.m b/SmartDeviceLink/SDLLockScreenManager.m
index c15c5318c..a8c8c3758 100644
--- a/SmartDeviceLink/SDLLockScreenManager.m
+++ b/SmartDeviceLink/SDLLockScreenManager.m
@@ -137,7 +137,7 @@ NS_ASSUME_NONNULL_BEGIN
} else if ([self.lastLockNotification.lockScreenStatus isEqualToEnum:SDLLockScreenStatusOptional]) {
if (self.config.showInOptionalState && !self.presenter.presented && self.canPresent) {
[self.presenter present];
- } else if (self.presenter.presented) {
+ } else if (!self.config.showInOptionalState && self.presenter.presented) {
[self.presenter dismiss];
}
} else if ([self.lastLockNotification.lockScreenStatus isEqualToEnum:SDLLockScreenStatusOff]) {
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m
index 3889c37d1..489de7fb0 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m
@@ -1,5 +1,6 @@
#import <Quick/Quick.h>
#import <Nimble/Nimble.h>
+#import <OCMock/OCMock.h>
#import "SDLFakeViewControllerPresenter.h"
#import "SDLLockScreenConfiguration.h"
@@ -201,6 +202,61 @@ describe(@"a lock screen manager", ^{
});
});
});
+
+ describe(@"A lock screen status of OPTIONAL", ^{
+ __block SDLLockScreenManager *testLockScreenManager = nil;
+ __block SDLLockScreenConfiguration *testLockScreenConfig = nil;
+ __block id mockViewControllerPresenter = nil;
+ __block SDLRPCNotificationNotification *testLockStatusNotification = nil;
+
+ beforeEach(^{
+ mockViewControllerPresenter = OCMClassMock([SDLFakeViewControllerPresenter class]);
+
+ SDLOnLockScreenStatus *testOptionalStatus = [[SDLOnLockScreenStatus alloc] init];
+ testOptionalStatus.lockScreenStatus = SDLLockScreenStatusOptional;
+ testLockStatusNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeLockScreenStatusNotification object:nil rpcNotification:testOptionalStatus];
+
+ testLockScreenConfig = [SDLLockScreenConfiguration enabledConfiguration];
+ });
+
+ context(@"showInOptionalState is true", ^{
+ beforeEach(^{
+ testLockScreenConfig.showInOptionalState = true;
+
+ testLockScreenManager = [[SDLLockScreenManager alloc] initWithConfiguration:testLockScreenConfig notificationDispatcher:nil presenter:mockViewControllerPresenter];
+
+ [testLockScreenManager start]; // Sets `canPresent` to `true`
+ });
+
+ it(@"should present the lock screen if not already presented", ^{
+ OCMStub([mockViewControllerPresenter lockViewController]).andReturn([OCMArg any]);
+ OCMStub([mockViewControllerPresenter presented]).andReturn(false);
+
+ [[NSNotificationCenter defaultCenter] postNotification:testLockStatusNotification];
+
+ OCMVerify([mockViewControllerPresenter present]);
+ });
+ });
+
+ context(@"showInOptionalState is false", ^{
+ beforeEach(^{
+ testLockScreenConfig.showInOptionalState = false;
+
+ testLockScreenManager = [[SDLLockScreenManager alloc] initWithConfiguration:testLockScreenConfig notificationDispatcher:nil presenter:mockViewControllerPresenter];
+
+ [testLockScreenManager start]; // Sets `canPresent` to `true`
+ });
+
+ it(@"should dismiss the lock screen if already presented", ^{
+ OCMStub([mockViewControllerPresenter lockViewController]).andReturn([OCMArg any]);
+ OCMStub([mockViewControllerPresenter presented]).andReturn(true);
+
+ [[NSNotificationCenter defaultCenter] postNotification:testLockStatusNotification];
+
+ OCMVerify([mockViewControllerPresenter dismiss]);
+ });
+ });
+ });
});
QuickSpecEnd