Guest User

Untitled

a guest
Jun 25th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. /**
  2. * A FingerprintAuth handles communication with a specific fingerprint api,
  3. * MarshmallowDelegate and SpassDelegate,
  4. * also by FingerprintAuthManager that is exposed to client.
  5. */
  6.  
  7. interface FingerprintAuth {
  8.  
  9. companion object {
  10. /**
  11. * Factory method:
  12. * first tries to take MarshmallowDelegate
  13. * if failed - device doesn't support Android's Fingerprint Authentication Api
  14. * than takes SpassDelegate.
  15. * if failed - device doesn't have fingerprint scanning sensor,
  16. * than StubDelegate is return
  17. */
  18. fun getDelegate(context: Context) =
  19. take { MarshmallowDelegate(context) }
  20. ?: take { SpassDelegate(context) }
  21. ?: take { StubDelegate() }
  22.  
  23. private fun <T> take (create: () -> T): T? {
  24. return try {
  25. create.invoke()
  26. } catch (ignored: Exception) {
  27. null
  28. }
  29. }
  30. }
  31.  
  32. /**
  33. * Checks if device has fingerprint scanning sensor
  34. */
  35. fun isSupportedByPlatform(): Boolean
  36.  
  37. /**
  38. * Checks if the feature is usable: enabled and enrolled
  39. */
  40. fun isUsable(): Boolean
  41.  
  42. /**
  43. * Start a fingerprint authentication request
  44. * if both isSupportedByPlatform() and isUsable() return true
  45. * it should be possible to call this method
  46. *
  47. * @param callback A listener that will be notified of the authentication result.
  48. */
  49. fun startFingerprintScan(callback: AuthCallback)
  50.  
  51. /**
  52. * Stop a fingerprint authentication request
  53. */
  54. fun stopFingerprintScan()
  55.  
  56.  
  57. interface AuthCallback {
  58. /**
  59. * Fingerprint successfully validated callback
  60. */
  61. fun onAuthenticationSucceeded()
  62. /**
  63. * Unrecoverable error callback
  64. * @param error unified error that is exposed to user
  65. * @param type retry auth on {@link Type.RECOVERABLE}
  66. * restart auth on {@link Type.UNRECOVERABLE}
  67. */
  68. fun onAuthenticationError (error: AuthError, type: Type)
  69. /**
  70. * Fingerprint auth failed callback
  71. */
  72. fun onAuthenticationFailed()
  73. }
  74.  
  75. }
Add Comment
Please, Sign In to add comment