-
-
Notifications
You must be signed in to change notification settings - Fork 250
/
LaunchActivity.kt
77 lines (69 loc) · 2.38 KB
/
LaunchActivity.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
* SPDX-License-Identifier: GPL-3.0-only
*/
package app.passwordstore.ui.main
import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.edit
import app.passwordstore.ui.crypto.BasePGPActivity
import app.passwordstore.ui.crypto.DecryptActivity
import app.passwordstore.ui.passwords.PasswordStore
import app.passwordstore.util.auth.BiometricAuthenticator
import app.passwordstore.util.auth.BiometricAuthenticator.Result
import app.passwordstore.util.extensions.sharedPrefs
import app.passwordstore.util.settings.PreferenceKeys
@SuppressLint("CustomSplashScreen")
class LaunchActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val prefs = sharedPrefs
if (prefs.getBoolean(PreferenceKeys.BIOMETRIC_AUTH, false)) {
BiometricAuthenticator.authenticate(this) { result ->
when (result) {
is Result.Success -> {
startTargetActivity(false)
}
is Result.HardwareUnavailableOrDisabled -> {
prefs.edit { remove(PreferenceKeys.BIOMETRIC_AUTH) }
startTargetActivity(false)
}
is Result.Failure,
Result.Cancelled -> {
finish()
}
is Result.Retry -> {}
}
}
} else {
startTargetActivity(true)
}
}
private fun getDecryptIntent(): Intent {
return Intent(this, DecryptActivity::class.java)
}
private fun startTargetActivity(noAuth: Boolean) {
val intentToStart =
if (intent.action == ACTION_DECRYPT_PASS)
getDecryptIntent().apply {
putExtra(
BasePGPActivity.EXTRA_FILE_PATH,
intent.getStringExtra(BasePGPActivity.EXTRA_FILE_PATH)
)
putExtra(
BasePGPActivity.EXTRA_REPO_PATH,
intent.getStringExtra(BasePGPActivity.EXTRA_REPO_PATH)
)
}
else Intent(this, PasswordStore::class.java).setAction(Intent.ACTION_VIEW)
startActivity(intentToStart)
Handler(Looper.getMainLooper()).postDelayed({ finish() }, if (noAuth) 0L else 500L)
}
companion object {
const val ACTION_DECRYPT_PASS = "DECRYPT_PASS"
}
}