summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicoleYarroch <nicole@livio.io>2018-09-11 10:55:52 -0400
committerNicoleYarroch <nicole@livio.io>2018-09-11 10:55:52 -0400
commite6a7a2450a956e2535070d6e9023f54a150b6dea (patch)
tree72a0e63fffafa4d98a89f843edb2e320081414b5
parent914360e56fd8b95859e927d669d7facfd5e8ae18 (diff)
downloadsdl_ios-e6a7a2450a956e2535070d6e9023f54a150b6dea.tar.gz
Fixed lock screen optional logic
Signed-off-by: NicoleYarroch <nicole@livio.io>
-rw-r--r--SmartDeviceLink/SDLLockScreenManager.m49
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m135
2 files changed, 34 insertions, 150 deletions
diff --git a/SmartDeviceLink/SDLLockScreenManager.m b/SmartDeviceLink/SDLLockScreenManager.m
index 692505a1e..2e6e784e0 100644
--- a/SmartDeviceLink/SDLLockScreenManager.m
+++ b/SmartDeviceLink/SDLLockScreenManager.m
@@ -140,7 +140,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 && [self.class sdl_canDismissLockScreenWithLockScreenStatus:self.lastLockNotification previousHMILevel:self.previousHMILevel showInOptionalState:self.config.showInOptionalState]) {
+ } else if (!self.config.showInOptionalState && self.presenter.presented) {
[self.presenter dismiss];
}
} else if ([self.lastLockNotification.lockScreenStatus isEqualToEnum:SDLLockScreenStatusOff]) {
@@ -150,53 +150,6 @@ NS_ASSUME_NONNULL_BEGIN
}
}
-/**
- * Checks if the lock screen can be dismissed. If the the app is currently in the "lock screen optional" state and the `showInOptionalState` has been set to true, then the lock screen should not be dismissed.
- *
- * @param lockScreenStatus The most recent lock screen status received from SDL Core
- * @param previousHMILevel The previous `hmiLevel`
- * @param showInOptionalState Whether or not the lock screen should be shown in the "lock screen optional" state
- * @return True if the lock screen can be dismissed; false if not
- */
-+ (BOOL)sdl_canDismissLockScreenWithLockScreenStatus:(nullable SDLOnLockScreenStatus *)lockScreenStatus previousHMILevel:(nullable SDLHMILevel)previousHMILevel showInOptionalState:(BOOL)showInOptionalState {
- BOOL currentlyInShowInOptionalState = [self sdl_inLockScreenOptionalStateForLockScreenStatus:lockScreenStatus previousHMILevel:previousHMILevel];
-
- if (currentlyInShowInOptionalState && showInOptionalState) {
- return false;
- }
-
- return true;
-}
-
-/**
- * Checks if the app is currently in the "lock screen optional" state.
- *
- * @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).
- *
- * @param lockScreenStatus The most recent lock screen status received from SDL Core
- * @param previousHMILevel The previous `hmiLevel`
- * @return True if currently if the "lock screen optional" state; false if not
- */
-+ (BOOL)sdl_inLockScreenOptionalStateForLockScreenStatus:(nullable SDLOnLockScreenStatus *)lockScreenStatus previousHMILevel:(nullable SDLHMILevel)previousHMILevel {
- if (lockScreenStatus == nil ||
- lockScreenStatus.driverDistractionStatus.boolValue ||
- [lockScreenStatus.hmiLevel isEqualToEnum:SDLHMILevelNone]) {
- return false;
- }
-
- if ([lockScreenStatus.hmiLevel isEqualToEnum:SDLHMILevelFull] || [lockScreenStatus.hmiLevel isEqualToEnum:SDLHMILevelLimited]) {
- return true;
- } else if ([lockScreenStatus.hmiLevel isEqualToEnum:SDLHMILevelBackground] && ([previousHMILevel isEqualToEnum:SDLHMILevelLimited] || [previousHMILevel isEqualToEnum:SDLHMILevelFull])) {
- return true;
- }
-
- return false;
-}
-
@end
NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m
index d29f56e67..b3a083b55 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m
@@ -13,13 +13,6 @@
#import "SDLRPCNotificationNotification.h"
-@interface SDLLockScreenManager ()
-
-+ (BOOL)sdl_canDismissLockScreenWithLockScreenStatus:(SDLOnLockScreenStatus *)lockScreenStatus previousHMILevel:(SDLHMILevel)previousHMILevel showInOptionalState:(BOOL)showInOptionalState;
-+ (BOOL)sdl_inLockScreenOptionalStateForLockScreenStatus:(nullable SDLOnLockScreenStatus *)lockScreenStatus previousHMILevel:(nullable SDLHMILevel)previousHMILevel;
-
-@end
-
QuickSpecBegin(SDLLockScreenManagerSpec)
describe(@"a lock screen manager", ^{
@@ -211,124 +204,62 @@ describe(@"a lock screen manager", ^{
});
});
-describe(@"The lock screen's show in optional state configuration", ^{
- __block id mockLockScreenManager = nil;
- __block SDLOnLockScreenStatus *testLockScreenStatus = nil;
- __block SDLHMILevel testPreviousHMILevel = nil;
+describe(@"A lock screen status of OPTIONAL", ^{
+ __block SDLLockScreenManager *testLockScreenManager = nil;
+ __block SDLLockScreenConfiguration *testLockScreenConfig = nil;
+ __block id mockViewControllerPresenter = nil;
+ __block SDLOnLockScreenStatus *testOptionalStatus = nil;
beforeEach(^{
- mockLockScreenManager = OCMClassMock([SDLLockScreenManager class]);
-
- testLockScreenStatus = [[SDLOnLockScreenStatus alloc] init];
- testLockScreenStatus.userSelected = @NO;
- testLockScreenStatus.lockScreenStatus = SDLLockScreenStatusOptional;
-
- testPreviousHMILevel = nil;
+ mockViewControllerPresenter = OCMClassMock([SDLFakeViewControllerPresenter class]);
});
- context(@"Check if app in the lock screen optional state", ^{
- it(@"is not in the lock screen optional state if the lock screen status is nil", ^{
- BOOL inLockScreenOptionalState = [SDLLockScreenManager sdl_inLockScreenOptionalStateForLockScreenStatus:nil previousHMILevel:nil];
-
- expect(inLockScreenOptionalState).to(beFalse());
- });
-
- it(@"is not in the lock screen optional state if the driver is distracted", ^{
- testLockScreenStatus.driverDistractionStatus = @YES;
- testLockScreenStatus.hmiLevel = SDLHMILevelFull;
+ context(@"showInOptionalState is true", ^{
+ beforeEach(^{
+ testLockScreenConfig = [SDLLockScreenConfiguration enabledConfiguration];
+ testLockScreenConfig.showInOptionalState = true;
- BOOL inLockScreenOptionalState = [SDLLockScreenManager sdl_inLockScreenOptionalStateForLockScreenStatus:testLockScreenStatus previousHMILevel:nil];
+ testLockScreenManager = [[SDLLockScreenManager alloc] initWithConfiguration:testLockScreenConfig notificationDispatcher:nil presenter:mockViewControllerPresenter];
- expect(inLockScreenOptionalState).to(beFalse());
+ [testLockScreenManager start];
});
- context(@"When the driver is not distracted", ^{
- beforeEach(^{
- testLockScreenStatus.driverDistractionStatus = @NO;
- });
-
- it(@"is in the lock screen optional state if the hmi level is FULL", ^{
- testLockScreenStatus.hmiLevel = SDLHMILevelFull;
-
- BOOL inLockScreenOptionalState = [SDLLockScreenManager sdl_inLockScreenOptionalStateForLockScreenStatus:testLockScreenStatus previousHMILevel:nil];
-
- expect(inLockScreenOptionalState).to(beTrue());
- });
-
- it(@"is in the lock screen optional state if the hmi level is LIMITED", ^{
- testLockScreenStatus.hmiLevel = SDLHMILevelLimited;
-
- BOOL inLockScreenOptionalState = [SDLLockScreenManager sdl_inLockScreenOptionalStateForLockScreenStatus:testLockScreenStatus previousHMILevel:nil];
-
- expect(inLockScreenOptionalState).to(beTrue());
- });
-
- it(@"is not in the lock screen optional state if the hmi level is NONE", ^{
- testLockScreenStatus.hmiLevel = SDLHMILevelNone;
-
- BOOL inLockScreenOptionalState = [SDLLockScreenManager sdl_inLockScreenOptionalStateForLockScreenStatus:testLockScreenStatus previousHMILevel:nil];
-
- expect(inLockScreenOptionalState).to(beFalse());
- });
-
- context(@"When the current hmi level is BACKGROUND", ^{
- beforeEach(^{
- testLockScreenStatus.hmiLevel = SDLHMILevelBackground;
- });
- it(@"is in the lock screen optional state if the hmi level is BACKGROUND and the previous hmi level was LIMITED", ^{
- BOOL inLockScreenOptionalState = [SDLLockScreenManager sdl_inLockScreenOptionalStateForLockScreenStatus:testLockScreenStatus previousHMILevel:SDLHMILevelLimited];
+ it(@"should present the lock screen if not already presented", ^{
+ OCMStub([mockViewControllerPresenter lockViewController]).andReturn([OCMArg any]);
+ OCMStub([mockViewControllerPresenter presented]).andReturn(false);
- expect(inLockScreenOptionalState).to(beTrue());
- });
+ testOptionalStatus = [[SDLOnLockScreenStatus alloc] init];
+ testOptionalStatus.lockScreenStatus = SDLLockScreenStatusOptional;
- it(@"is in the lock screen optional state if the hmi level is BACKGROUND and the previous hmi level was FULL", ^{
- BOOL inLockScreenOptionalState = [SDLLockScreenManager sdl_inLockScreenOptionalStateForLockScreenStatus:testLockScreenStatus previousHMILevel:SDLHMILevelFull];
-
- expect(inLockScreenOptionalState).to(beTrue());
- });
+ SDLRPCNotificationNotification *testLockStatusNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeLockScreenStatusNotification object:nil rpcNotification:testOptionalStatus];
+ [[NSNotificationCenter defaultCenter] postNotification:testLockStatusNotification];
- it(@"is not in the lock screen optional state if the hmi level is BACKGROUND and the previous hmi level was NONE", ^{
- BOOL inLockScreenOptionalState = [SDLLockScreenManager sdl_inLockScreenOptionalStateForLockScreenStatus:testLockScreenStatus previousHMILevel:SDLHMILevelNone];
-
- expect(inLockScreenOptionalState).to(beFalse());
- });
- });
+ OCMVerify([mockViewControllerPresenter present]);
});
});
- context(@"Check if the lock screen can be dismissed", ^{
+ context(@"showInOptionalState is false", ^{
beforeEach(^{
- testLockScreenStatus.userSelected = @NO;
- testLockScreenStatus.lockScreenStatus = SDLLockScreenStatusOptional;
- testLockScreenStatus.hmiLevel = SDLHMILevelLimited;
- testLockScreenStatus.driverDistractionStatus = @NO;
-
- testPreviousHMILevel = SDLHMILevelLimited;
- });
+ testLockScreenConfig = [SDLLockScreenConfiguration enabledConfiguration];
+ testLockScreenConfig.showInOptionalState = false;
- it(@"can be dismissed if the show in optional state has been set to false", ^{
- OCMStub([mockLockScreenManager sdl_inLockScreenOptionalStateForLockScreenStatus:[OCMArg any] previousHMILevel:[OCMArg any]]).andReturn(YES);
+ testLockScreenManager = [[SDLLockScreenManager alloc] initWithConfiguration:testLockScreenConfig notificationDispatcher:nil presenter:mockViewControllerPresenter];
- BOOL canDismissLockScreen = [SDLLockScreenManager sdl_canDismissLockScreenWithLockScreenStatus:testLockScreenStatus previousHMILevel:testPreviousHMILevel showInOptionalState:false];
-
- expect(canDismissLockScreen).to(beTrue());
+ [testLockScreenManager start]; // Sets `canPresent` to `true`
});
- it(@"can be dismissed the SDL app is not in the lock screen optional state", ^{
- OCMStub([mockLockScreenManager sdl_inLockScreenOptionalStateForLockScreenStatus:[OCMArg any] previousHMILevel:[OCMArg any]]).andReturn(NO);
-
- BOOL canDismissLockScreen = [SDLLockScreenManager sdl_canDismissLockScreenWithLockScreenStatus:testLockScreenStatus previousHMILevel:testPreviousHMILevel showInOptionalState:true];
-
- expect(canDismissLockScreen).to(beTrue());
- });
+ it(@"should dismiss the lock screen if already presented", ^{
+ OCMStub([mockViewControllerPresenter lockViewController]).andReturn([OCMArg any]);
+ OCMStub([mockViewControllerPresenter presented]).andReturn(true);
- it(@"can not be dismissed if the show in optional state has been set to true and the SDL app is in the lock screen optional state", ^{
- OCMStub([mockLockScreenManager sdl_inLockScreenOptionalStateForLockScreenStatus:[OCMArg any] previousHMILevel:[OCMArg any]]).andReturn(YES);
+ testOptionalStatus = [[SDLOnLockScreenStatus alloc] init];
+ testOptionalStatus.lockScreenStatus = SDLLockScreenStatusOptional;
- BOOL canDismissLockScreen = [SDLLockScreenManager sdl_canDismissLockScreenWithLockScreenStatus:testLockScreenStatus previousHMILevel:testPreviousHMILevel showInOptionalState:true];
+ SDLRPCNotificationNotification *testLockStatusNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeLockScreenStatusNotification object:nil rpcNotification:testOptionalStatus];
+ [[NSNotificationCenter defaultCenter] postNotification:testLockStatusNotification];
- expect(canDismissLockScreen).to(beFalse());
+ OCMVerify([mockViewControllerPresenter dismiss]);
});
});
});