Timeout Lock Service Documentation¶
The flows component of SAP SDK includes a feature that displays the sign-in screen when users bring the app back from the background after a certain period. Users need to unlock the app with a passcode before they can use it.
There may be cases where the client app wants to control whether the sign-in screen appears. For example, the client app might not want the sign-in screen to appear over the widget configuration activity or when switching back from another app.
To address these requirements, SAP SDK provides several APIs to assist customers.
Specify Activities¶
FlowActionHandler includes an open function that client code can override. For instance, if the client application does not want the sign-in screen to appear on top of the launcher or widget configuration activities, the following sample code can be used:
class DemoFlowActionHandler : FlowActionHandler() {
override fun shouldStartTimeoutFlow(activity: Activity): Boolean = when (activity) {
is WelcomeActivity -> false
is ODataWidgetConfigurationActivity -> false
else -> super.shouldStartTimeoutFlow(activity)
}
}
Temporarily Set the Timeout Settings¶
To address the case where the app is switched back from another app, you can use the following API:
@JvmStatic
fun updateOnetimeTimeoutSetting(timeoutLockTime: Int?) { ... }
As the function name suggests, the timeoutLockTime is used only once when the app is sent to the background after this call. After that, the timeout settings from the passcode policy will take effect. If timeoutLockTime is negative, the timeout service will be disabled.
This API is introduced in version 24.12 of SAP SDK.
Note
Call this API before navigating to another app to avoid displaying the sign-in screen when returning. If you call this API multiple times while the app is in the foreground, the last call takes precedence. When the app is in the background, calling the API clears the timeout setting once the app returns to the foreground, ignoring all previous calls.
Pause/Resume the Timeout Lock Service¶
Before the introduction of the API above, the following two APIs could be used to handle the case of returning from another app:
@JvmStatic fun pause() { ... }
@JvmStatic fun resume() { ... }
The client code must ensure that the service is resumed after calling pause. We recommend using the updateOnetimeTimeoutSetting method starting from version 24.12 of SAP SDK.
Idle Lock Service¶
IdleLockService monitors user interaction while the app is in the foreground. If the user has not interacted with the app for the duration specified by foregroundLockTimeout in the passcode policy, the service closes the user store and launches a verify flow requiring the user to re-authenticate.
This is distinct from the background timeout handled by FlowTimeoutLockService: the idle lock service triggers while the app remains in the foreground but the user is inactive.
Register the Service¶
To register IdleLockService, add it to the list of services passed to SDKInitializer.start() during application initialization:
SDKInitializer.start(
application = this,
services = arrayOf(loggingService, UserSessionService(), AppExtensionService(), IdleLockService())
)
Report User Activity¶
You should override onUserInteraction() in every Activity and call onUserActive() to reset the idle timer whenever the user interacts with the screen:
override fun onUserInteraction() {
super.onUserInteraction()
SDKInitializer.getService(IdleLockService::class)?.onUserActive()
}
If onUserInteraction() is not overridden in an activity, the idle timer will not reset for interactions in that activity, and the user may be prompted to re-authenticate unexpectedly.