Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LockScreen Changes #1153

Merged
merged 6 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.smartdevicelink.AndroidTestCase2;
import com.smartdevicelink.test.Test;


/**
* This is a unit test class for the SmartDeviceLink library manager class :
* {@link com.smartdevicelink.managers.lockscreen.LockScreenConfig}
Expand All @@ -25,6 +24,7 @@ public void setUp() throws Exception {
lockScreenConfig.setBackgroundColor(Test.GENERAL_INT);
lockScreenConfig.showDeviceLogo(true);
lockScreenConfig.setEnabled(true);
lockScreenConfig.setDisplayMode(LockScreenConfig.DISPLAY_MODE_OPTIONAL_OR_REQUIRED);
}

@Override
Expand All @@ -38,8 +38,9 @@ public void testLockScreenConfig() {
assertEquals(Test.GENERAL_INT, lockScreenConfig.getCustomView());
assertEquals(Test.GENERAL_INT, lockScreenConfig.getAppIcon());
assertEquals(Test.GENERAL_INT, lockScreenConfig.getBackgroundColor());
assertEquals(true, lockScreenConfig.isEnabled());
assertEquals(true, lockScreenConfig.isDeviceLogoEnabled());
assertTrue(lockScreenConfig.isEnabled());
assertTrue(lockScreenConfig.isDeviceLogoEnabled());
assertEquals(LockScreenConfig.DISPLAY_MODE_OPTIONAL_OR_REQUIRED, lockScreenConfig.getDisplayMode());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@
import android.content.Context;

import com.smartdevicelink.AndroidTestCase2;
import com.smartdevicelink.protocol.enums.FunctionID;
import com.smartdevicelink.proxy.interfaces.ISdl;
import com.smartdevicelink.proxy.rpc.OnDriverDistraction;
import com.smartdevicelink.proxy.rpc.enums.DriverDistractionState;
import com.smartdevicelink.proxy.rpc.enums.HMILevel;
import com.smartdevicelink.proxy.rpc.enums.LockScreenStatus;
import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener;
import com.smartdevicelink.test.Test;

import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;

/**
Expand All @@ -16,13 +27,24 @@
public class LockScreenManagerTests extends AndroidTestCase2 {

private LockScreenManager lockScreenManager;
private OnRPCNotificationListener onDDListener;

@Override
public void setUp() throws Exception{
super.setUp();

ISdl internalInterface = mock(ISdl.class);

Answer<Void> onDDStatusAnswer = new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
onDDListener = (OnRPCNotificationListener) args[1];
return null;
}
};
doAnswer(onDDStatusAnswer).when(internalInterface).addOnRPCNotificationListener(eq(FunctionID.ON_DRIVER_DISTRACTION), any(OnRPCNotificationListener.class));

Context context = getContext();
// create config
LockScreenConfig lockScreenConfig = new LockScreenConfig();
Expand All @@ -31,6 +53,7 @@ public void setUp() throws Exception{
lockScreenConfig.setBackgroundColor(Test.GENERAL_INT);
lockScreenConfig.showDeviceLogo(true);
lockScreenConfig.setEnabled(true);
lockScreenConfig.setDisplayMode(LockScreenConfig.DISPLAY_MODE_OPTIONAL_OR_REQUIRED);

lockScreenManager = new LockScreenManager(lockScreenConfig, context, internalInterface);
}
Expand All @@ -44,13 +67,92 @@ public void testVariables() {
assertEquals(Test.GENERAL_INT, lockScreenManager.customView);
assertEquals(Test.GENERAL_INT, lockScreenManager.lockScreenIcon);
assertEquals(Test.GENERAL_INT, lockScreenManager.lockScreenColor);
assertEquals(true, lockScreenManager.deviceLogoEnabled);
assertEquals(true, lockScreenManager.lockScreenEnabled);
assertTrue(lockScreenManager.deviceLogoEnabled);
assertTrue(lockScreenManager.lockScreenEnabled);
assertNull(lockScreenManager.deviceLogo);
assertEquals(LockScreenConfig.DISPLAY_MODE_OPTIONAL_OR_REQUIRED, lockScreenManager.displayMode);
}

public void testGetLockScreenStatusHmiNoneDDOff(){
lockScreenManager.driverDistStatus = false;
lockScreenManager.hmiLevel = HMILevel.HMI_NONE;
assertEquals(LockScreenStatus.OFF, lockScreenManager.getLockScreenStatus());
}

public void testGetLockScreenStatus(){
public void testGetLockScreenStatusHmiBackgroundDDOff(){
lockScreenManager.driverDistStatus = false;
lockScreenManager.hmiLevel = HMILevel.HMI_BACKGROUND;
assertEquals(LockScreenStatus.OFF, lockScreenManager.getLockScreenStatus());
}

}
public void testGetLockScreenStatusHmiNoneDDOn(){
lockScreenManager.driverDistStatus = true;
lockScreenManager.hmiLevel = HMILevel.HMI_BACKGROUND;
assertEquals(LockScreenStatus.REQUIRED, lockScreenManager.getLockScreenStatus());
}

public void testGetLockScreenStatusHmiFullDDOff(){
lockScreenManager.driverDistStatus = false;
lockScreenManager.hmiLevel = HMILevel.HMI_FULL;
assertEquals(LockScreenStatus.OPTIONAL, lockScreenManager.getLockScreenStatus());
}

public void testGetLockScreenStatusHmiFullDDOn(){
lockScreenManager.driverDistStatus = true;
lockScreenManager.hmiLevel = HMILevel.HMI_FULL;
assertEquals(LockScreenStatus.REQUIRED, lockScreenManager.getLockScreenStatus());
}

public void testGetLockScreenStatusHmiLimitedDDOff(){
lockScreenManager.driverDistStatus = false;
lockScreenManager.hmiLevel = HMILevel.HMI_LIMITED;
assertEquals(LockScreenStatus.OPTIONAL, lockScreenManager.getLockScreenStatus());
}

public void testGetLockScreenStatusHmiLimitedDDOn(){
lockScreenManager.driverDistStatus = true;
lockScreenManager.hmiLevel = HMILevel.HMI_LIMITED;
assertEquals(LockScreenStatus.REQUIRED, lockScreenManager.getLockScreenStatus());
}

public void testLockScreenDismissibleWithEnableTrueAndDismissibilityTrue(){
lockScreenManager.enableDismissGesture = true;
OnDriverDistraction onDriverDistraction = new OnDriverDistraction();
onDriverDistraction.setLockscreenDismissibility(true);
onDriverDistraction.setState(DriverDistractionState.DD_ON);
onDDListener.onNotified(onDriverDistraction);
assertTrue(lockScreenManager.enableDismissGesture);
assertTrue(lockScreenManager.mIsLockscreenDismissible);
}

public void testLockScreenDismissibleWithEnableFalseAndDismissibilityFalse(){
lockScreenManager.enableDismissGesture = false;
OnDriverDistraction onDriverDistraction = new OnDriverDistraction();
onDriverDistraction.setLockscreenDismissibility(true);
onDriverDistraction.setState(DriverDistractionState.DD_ON);
onDDListener.onNotified(onDriverDistraction);
assertFalse(lockScreenManager.enableDismissGesture);
assertFalse(lockScreenManager.mIsLockscreenDismissible);
}

public void testLockScreenDismissibleWithEnableTrueAndDismissibilityFalse(){
lockScreenManager.enableDismissGesture = true;
OnDriverDistraction onDriverDistraction = new OnDriverDistraction();
onDriverDistraction.setLockscreenDismissibility(false);
onDriverDistraction.setState(DriverDistractionState.DD_ON);
onDDListener.onNotified(onDriverDistraction);
assertTrue(lockScreenManager.enableDismissGesture);
assertFalse(lockScreenManager.mIsLockscreenDismissible);
}

public void testLockScreenDismissibleWithEnableFalseAndDismissibilityTrue(){
lockScreenManager.enableDismissGesture = false;
OnDriverDistraction onDriverDistraction = new OnDriverDistraction();
onDriverDistraction.setLockscreenDismissibility(true);
onDriverDistraction.setState(DriverDistractionState.DD_ON);
onDDListener.onNotified(onDriverDistraction);
assertFalse(lockScreenManager.enableDismissGesture);
assertFalse(lockScreenManager.mIsLockscreenDismissible);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@

package com.smartdevicelink.managers.lockscreen;

import android.support.annotation.IntDef;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
* <strong>LockScreenConfig</strong> <br>
*
Expand All @@ -47,32 +52,61 @@
* <li> customView - If you would like to provide your own view, you can pass it in here.</li>
*
* <li> deviceLogo - On by default. If available, will show the device or OEMs logo on the lockscreen</li>
*
* <li> displayMode - Describes when the lock screen will be displayed. Defaults to `DISPLAY_MODE_REQUIRED_ONLY`.</li>
*
* <li> enableDismissGesture - If true, 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 true.</li>
*/
public class LockScreenConfig {

private boolean enable, deviceLogo;
private boolean enable, deviceLogo, enableDismissGesture;
private int backgroundColor, appIconInt, customViewInt;
private @DisplayMode int displayMode;

/**
* DISPLAY_MODE_NEVER - The lock screen should never be shown. This should almost always mean that you will build your own lock screen.
* DISPLAY_MODE_REQUIRED_ONLY - The lock screen should only be shown when it is required by the head unit.
* DISPLAY_MODE_OPTIONAL_OR_REQUIRED - The lock screen should be shown when required by the head unit or when the head unit says that
* its optional, but *not* in other cases, such as before the user has interacted with your app on the head unit.
* DISPLAY_MODE_ALWAYS - The lock screen should always be shown after connection.
*/
@IntDef({DISPLAY_MODE_NEVER, DISPLAY_MODE_REQUIRED_ONLY, DISPLAY_MODE_OPTIONAL_OR_REQUIRED, DISPLAY_MODE_ALWAYS})
@Retention(RetentionPolicy.SOURCE)
public @interface DisplayMode {}
public static final int DISPLAY_MODE_NEVER = 0;
public static final int DISPLAY_MODE_REQUIRED_ONLY = 1;
public static final int DISPLAY_MODE_OPTIONAL_OR_REQUIRED = 2;
public static final int DISPLAY_MODE_ALWAYS = 3;

public LockScreenConfig(){
// set default values
this.enable = true;
this.deviceLogo = true;
this.displayMode = DISPLAY_MODE_REQUIRED_ONLY;
this.enableDismissGesture = true;
}

/**
* If set to true, SDL will manage the showing and dismissing of the lock screen for you. <br>
*
* If false, you must manage the lock screen
* @param enable boolean
*
* @deprecated to disable the lockscreen, use setDisplayMode with DISPLAY_MODE_NEVER instead
*/
@Deprecated
public void setEnabled(boolean enable){
this.enable = enable;
}

/**
* Gets whether the lock screen is being managed for you
* @return boolean
*
* @deprecated to disable the lockscreen, use setDisplayMode with DISPLAY_MODE_NEVER instead
*/
@Deprecated
public boolean isEnabled() {
return enable;
}
Expand Down Expand Up @@ -145,4 +179,39 @@ public boolean isDeviceLogoEnabled() {
return deviceLogo;
}


/**
* Set the displayMode to be used
* @param displayMode - Describes when the lock screen will be displayed. Defaults to `DISPLAY_MODE_REQUIRED_ONLY`.
*/
public void setDisplayMode(@DisplayMode int displayMode){
this.displayMode = displayMode;
}

/**
* Get the displayMode to be used
* @return displayMode - Describes when the lock screen will be displayed. Defaults to `DISPLAY_MODE_REQUIRED_ONLY`.
*/
public @DisplayMode int getDisplayMode(){
return this.displayMode;
}

/**
* If true, 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 true.
* @param enableDismissGesture - enable or disable this feature
*/
public void enableDismissGesture(boolean enableDismissGesture) {
this.enableDismissGesture = enableDismissGesture;
}

/**
* If true, 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 true.
* @return - whether or not this is enabled or disabled
*/
public boolean enableDismissGesture() {
return enableDismissGesture;
}

}
Loading