mirror of https://github.com/x13a/Wasted.git
biometric
This commit is contained in:
parent
b5bebfe838
commit
5763de5cbd
|
@ -10,8 +10,8 @@ android {
|
|||
applicationId "me.lucky.wasted"
|
||||
minSdk 23
|
||||
targetSdk 32
|
||||
versionCode 32
|
||||
versionName "1.5.3"
|
||||
versionCode 33
|
||||
versionName "1.5.4"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ dependencies {
|
|||
|
||||
implementation 'androidx.security:security-crypto:1.0.0'
|
||||
implementation 'androidx.preference:preference-ktx:1.2.0'
|
||||
implementation 'androidx.biometric:biometric:1.1.0'
|
||||
implementation 'androidx.drawerlayout:drawerlayout:1.1.1'
|
||||
implementation 'info.guardianproject.panic:panic:1.0'
|
||||
}
|
|
@ -2,6 +2,9 @@ package me.lucky.wasted
|
|||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.biometric.BiometricManager
|
||||
import androidx.biometric.BiometricPrompt
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
|
||||
import me.lucky.wasted.databinding.ActivityMainBinding
|
||||
|
@ -17,18 +20,60 @@ open class MainActivity : AppCompatActivity() {
|
|||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
init()
|
||||
init1()
|
||||
if (initBiometric()) return
|
||||
init2()
|
||||
setup()
|
||||
}
|
||||
|
||||
private fun init() {
|
||||
private fun init1() {
|
||||
prefs = Preferences(this)
|
||||
prefsdb = Preferences(this, encrypted = false)
|
||||
prefs.copyTo(prefsdb)
|
||||
NotificationManager(this).createNotificationChannels()
|
||||
}
|
||||
|
||||
private fun init2() {
|
||||
replaceFragment(MainFragment())
|
||||
}
|
||||
|
||||
private fun initBiometric(): Boolean {
|
||||
val authenticators = BiometricManager.Authenticators.BIOMETRIC_STRONG or
|
||||
BiometricManager.Authenticators.DEVICE_CREDENTIAL
|
||||
when (BiometricManager
|
||||
.from(this)
|
||||
.canAuthenticate(authenticators))
|
||||
{
|
||||
BiometricManager.BIOMETRIC_SUCCESS -> {}
|
||||
else -> return false
|
||||
}
|
||||
val executor = ContextCompat.getMainExecutor(this)
|
||||
val prompt = BiometricPrompt(
|
||||
this,
|
||||
executor,
|
||||
object : BiometricPrompt.AuthenticationCallback()
|
||||
{
|
||||
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
|
||||
super.onAuthenticationError(errorCode, errString)
|
||||
finishAndRemoveTask()
|
||||
}
|
||||
|
||||
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
|
||||
super.onAuthenticationSucceeded(result)
|
||||
init2()
|
||||
setup()
|
||||
}
|
||||
})
|
||||
try {
|
||||
prompt.authenticate(BiometricPrompt.PromptInfo.Builder()
|
||||
.setTitle(getString(R.string.authentication))
|
||||
.setConfirmationRequired(false)
|
||||
.setAllowedAuthenticators(authenticators)
|
||||
.build())
|
||||
} catch (exc: Exception) { return false }
|
||||
return true
|
||||
}
|
||||
|
||||
private fun setup() = binding.apply {
|
||||
appBar.setNavigationOnClickListener {
|
||||
drawer.open()
|
||||
|
|
|
@ -19,7 +19,7 @@ class BroadcastReceiver : BroadcastReceiver() {
|
|||
if (!prefs.isEnabled) return
|
||||
val secret = prefs.secret
|
||||
assert(secret.isNotEmpty())
|
||||
if (intent.getStringExtra(KEY) != secret) return
|
||||
if (intent.getStringExtra(KEY)?.trim() != secret) return
|
||||
val admin = DeviceAdminManager(context)
|
||||
try {
|
||||
admin.lockNow()
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
android:padding="16dp"
|
||||
android:textAlignment="center"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/black"
|
||||
android:textAppearance="?attr/textAppearanceTitleLarge" />
|
||||
|
||||
<Space
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
<string name="main">Main</string>
|
||||
<string name="settings">Settings</string>
|
||||
<string name="goto_button">GOTO</string>
|
||||
<string name="authentication">Authentication</string>
|
||||
<string name="trigger_panic_kit_description">Enable panic responder. PanicKit is a collection of tools for creating “panic buttons” that can trigger a system-wide response when the user is in an anxious or dangerous situation. It enables trigger apps and responder apps to safely and easily connect to each other. The user engages with the trigger app when in a panic situation. The responder apps receive that trigger signal, and individually execute the steps that they were configured to do.</string>
|
||||
<string name="trigger_tile_description">Enable tile service. It is a button in quick settings panel when you swipe from the top of the screen. This button will mimic to the airplane mode.</string>
|
||||
<string name="trigger_shortcut_description">Enable icon shortcut. It is a button you will see when you make a long tap on the Wasted icon.</string>
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
biometric
|
Loading…
Reference in New Issue