-
-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: convert java to kotlin and add support for kotlin (#657)
* refactor: convert java to kotlin and support for kotlin to the project * refactor: convert cipherStorage to kotlin * chore: reformat code
- Loading branch information
1 parent
f6bc521
commit a845361
Showing
39 changed files
with
2,811 additions
and
3,154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 0 additions & 56 deletions
56
android/src/main/java/com/oblador/keychain/DeviceAvailability.java
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
android/src/main/java/com/oblador/keychain/DeviceAvailability.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.oblador.keychain | ||
|
||
import android.Manifest | ||
import android.app.KeyguardManager | ||
import android.content.Context | ||
import android.content.pm.PackageManager | ||
import android.os.Build | ||
import androidx.biometric.BiometricManager | ||
|
||
/** | ||
* @see | ||
* [Biometric hardware](https://stackoverflow.com/questions/50968732/determine-if-biometric-hardware-is-present-and-the-user-has-enrolled-biometrics) | ||
*/ | ||
@Suppress("deprecation") | ||
object DeviceAvailability { | ||
fun isStrongBiometricAuthAvailable(context: Context): Boolean { | ||
return BiometricManager.from(context) | ||
.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_STRONG) == | ||
BiometricManager.BIOMETRIC_SUCCESS | ||
} | ||
|
||
fun isFingerprintAuthAvailable(context: Context): Boolean { | ||
return context.packageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT) | ||
} | ||
|
||
fun isFaceAuthAvailable(context: Context): Boolean { | ||
return context.packageManager.hasSystemFeature(PackageManager.FEATURE_FACE) | ||
} | ||
|
||
fun isIrisAuthAvailable(context: Context): Boolean { | ||
return context.packageManager.hasSystemFeature(PackageManager.FEATURE_IRIS) | ||
} | ||
|
||
/** Check is permissions granted for biometric things. */ | ||
@JvmStatic | ||
fun isPermissionsGranted(context: Context): Boolean { | ||
// before api23 no permissions for biometric, no hardware == no permissions | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { | ||
return false | ||
} | ||
val km = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager | ||
if (!km.isKeyguardSecure) return false | ||
|
||
// api28+ | ||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | ||
context.checkSelfPermission(Manifest.permission.USE_BIOMETRIC) == | ||
PackageManager.PERMISSION_GRANTED | ||
} else | ||
context.checkSelfPermission(Manifest.permission.USE_FINGERPRINT) == | ||
PackageManager.PERMISSION_GRANTED | ||
|
||
// before api28 | ||
} | ||
} |
Oops, something went wrong.