Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: convert java to kotlin and add support for kotlin #657

Merged
merged 3 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
buildscript {
// Buildscript is evaluated before everything else so we can't use safeExtGet
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : "1.8.0"
repositories {
maven {
url "https://plugins.gradle.org/m2/"
Expand All @@ -7,7 +9,8 @@ buildscript {
google()
}
dependencies {
classpath("com.android.tools.build:gradle:8.3.1")
classpath "com.android.tools.build:gradle:8.3.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

Expand All @@ -23,6 +26,7 @@ if (isNewArchitectureEnabled()) {
apply plugin: "com.facebook.react"
}
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

repositories {
google()
Expand All @@ -34,13 +38,13 @@ android {
if (project.android.hasProperty("namespace")) {
namespace = "com.oblador.keychain"
}
compileSdkVersion safeExtGet('compileSdkVersion', 33)
compileSdkVersion safeExtGet('compileSdkVersion', 34)
buildToolsVersion safeExtGet('buildToolsVersion', '33.0.0')

defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 23)
compileSdkVersion safeExtGet('compileSdkVersion', 33)
targetSdkVersion safeExtGet('targetSdkVersion', 33)
compileSdkVersion safeExtGet('compileSdkVersion', 34)
targetSdkVersion safeExtGet('targetSdkVersion', 34)
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
}

Expand All @@ -57,24 +61,20 @@ android {
disable "GradleCompatible"
abortOnError false
}

testOptions {
unitTests {
includeAndroidResources = true
}
}
}

repositories {
mavenCentral()
}

def kotlin_version = safeExtGet('kotlinVersion', '1.8.0')

dependencies {
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-android:+"

implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

// https://mvnrepository.com/artifact/androidx.biometric/biometric
implementation 'androidx.biometric:biometric:1.1.0@aar'
Expand Down
56 changes: 0 additions & 56 deletions android/src/main/java/com/oblador/keychain/DeviceAvailability.java

This file was deleted.

54 changes: 54 additions & 0 deletions android/src/main/java/com/oblador/keychain/DeviceAvailability.kt
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
}
}
Loading