Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * A FingerprintAuth handles communication with a specific fingerprint api,
- * MarshmallowDelegate and SpassDelegate,
- * also by FingerprintAuthManager that is exposed to client.
- */
- interface FingerprintAuth {
- companion object {
- /**
- * Factory method:
- * first tries to take MarshmallowDelegate
- * if failed - device doesn't support Android's Fingerprint Authentication Api
- * than takes SpassDelegate.
- * if failed - device doesn't have fingerprint scanning sensor,
- * than StubDelegate is return
- */
- fun getDelegate(context: Context) =
- take { MarshmallowDelegate(context) }
- ?: take { SpassDelegate(context) }
- ?: take { StubDelegate() }
- private fun <T> take (create: () -> T): T? {
- return try {
- create.invoke()
- } catch (ignored: Exception) {
- null
- }
- }
- }
- /**
- * Checks if device has fingerprint scanning sensor
- */
- fun isSupportedByPlatform(): Boolean
- /**
- * Checks if the feature is usable: enabled and enrolled
- */
- fun isUsable(): Boolean
- /**
- * Start a fingerprint authentication request
- * if both isSupportedByPlatform() and isUsable() return true
- * it should be possible to call this method
- *
- * @param callback A listener that will be notified of the authentication result.
- */
- fun startFingerprintScan(callback: AuthCallback)
- /**
- * Stop a fingerprint authentication request
- */
- fun stopFingerprintScan()
- interface AuthCallback {
- /**
- * Fingerprint successfully validated callback
- */
- fun onAuthenticationSucceeded()
- /**
- * Unrecoverable error callback
- * @param error unified error that is exposed to user
- * @param type retry auth on {@link Type.RECOVERABLE}
- * restart auth on {@link Type.UNRECOVERABLE}
- */
- fun onAuthenticationError (error: AuthError, type: Type)
- /**
- * Fingerprint auth failed callback
- */
- fun onAuthenticationFailed()
- }
- }
Add Comment
Please, Sign In to add comment