Being able to disable the keyguard can be useful in some situations. For instance, you may want to keep your device unlock when staying at home. The common way to do this is to use the Tasker plugin SecureTask. The plugin has first to be set as device owner (see baldapps.altervista.org/deviceowner.html for the details). Unfortunately, some of the Samsung devices with Oreo do not allow device administrator. The device is locked with the following message "Unauthorized software has been installed on your device. Workspace has been locked to prevent unauthorized access. Contant your admin".
I found another way to disable the keyguard with the command "locksettings" for devices with Android Oreo or newer. To create a action to disable the keyguard, you have to choose: Create a new Action -> Category Code -> Run Shell. Then, the command text field should contain the following code: "locksettings clear --old XXXX" with XXXX being your pin code. For the action to enable the keyguard, the code should be "locksettings set-pin XXXX". You have to use root for both of these actions. "locksettings" can also be used with pattern and password. See here: android.googlesource.com/platform/frameworks/base/+/android-8.0.0_r1/cmds/locksettings/src/com/android/commands/locksettings/LockSettingsCmd.java.