mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-23 00:57:26 +03:00
workaround - restart nfc discovery for add account
This commit is contained in:
parent
4fc7db106c
commit
d064fe357f
@ -40,32 +40,45 @@ class MainActivity : FlutterFragmentActivity() {
|
||||
|
||||
viewModel.handleYubiKey.observe(this) {
|
||||
if (it) {
|
||||
Log.d(TAG, "Starting usb discovery")
|
||||
yubikit.startUsbDiscovery(UsbConfiguration()) { device ->
|
||||
viewModel.yubiKeyDevice.postValue(device)
|
||||
device.setOnClosed { viewModel.yubiKeyDevice.postValue(null) }
|
||||
}
|
||||
hasNfc = try {
|
||||
yubikit.startNfcDiscovery(nfcConfiguration, this) { device ->
|
||||
viewModel.yubiKeyDevice.apply {
|
||||
lifecycleScope.launch(Dispatchers.Main) {
|
||||
value = device
|
||||
postValue(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
true
|
||||
} catch (e: NfcNotAvailable) {
|
||||
false
|
||||
}
|
||||
hasNfc = startNfcDiscovery()
|
||||
} else {
|
||||
yubikit.stopNfcDiscovery(this)
|
||||
stopNfcDiscovery()
|
||||
yubikit.stopUsbDiscovery()
|
||||
Log.d(TAG, "Stopped usb discovery")
|
||||
}
|
||||
}
|
||||
|
||||
setupYubiKitLogger()
|
||||
}
|
||||
|
||||
fun startNfcDiscovery(): Boolean =
|
||||
try {
|
||||
Log.d(TAG, "Starting nfc discovery")
|
||||
yubikit.startNfcDiscovery(nfcConfiguration, this) { device ->
|
||||
viewModel.yubiKeyDevice.apply {
|
||||
lifecycleScope.launch(Dispatchers.Main) {
|
||||
value = device
|
||||
postValue(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
true
|
||||
} catch (e: NfcNotAvailable) {
|
||||
false
|
||||
}
|
||||
|
||||
fun stopNfcDiscovery() {
|
||||
if (hasNfc) {
|
||||
yubikit.stopNfcDiscovery(this)
|
||||
Log.d(TAG, "Stopped nfc discovery")
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupYubiKitLogger() {
|
||||
Logger.setLogger(object : Logger() {
|
||||
private val TAG = "yubikit"
|
||||
@ -85,6 +98,7 @@ class MainActivity : FlutterFragmentActivity() {
|
||||
private lateinit var oathManager: OathManager
|
||||
private lateinit var dialogManager: DialogManager
|
||||
private lateinit var flutterLog: FlutterLog
|
||||
private lateinit var nfcDiscoveryHelper: NfcDiscoveryHelper
|
||||
|
||||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||
super.configureFlutterEngine(flutterEngine)
|
||||
@ -94,8 +108,12 @@ class MainActivity : FlutterFragmentActivity() {
|
||||
flutterLog = FlutterLog(messenger)
|
||||
appContext = AppContext(messenger)
|
||||
dialogManager = DialogManager(messenger, this.lifecycleScope)
|
||||
nfcDiscoveryHelper = NfcDiscoveryHelper(this)
|
||||
|
||||
oathManager = OathManager(this, messenger, appContext, viewModel, dialogManager)
|
||||
oathManager = OathManager(this, messenger, appContext, viewModel, dialogManager, nfcDiscoveryHelper)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "MainActivity"
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
package com.yubico.authenticator
|
||||
|
||||
class NfcDiscoveryHelper(private val mainActivity: MainActivity) {
|
||||
private fun startDiscovery() {
|
||||
mainActivity.startNfcDiscovery()
|
||||
}
|
||||
|
||||
private fun stopDiscovery() {
|
||||
mainActivity.stopNfcDiscovery()
|
||||
}
|
||||
|
||||
fun restartDiscovery() {
|
||||
stopDiscovery()
|
||||
startDiscovery()
|
||||
}
|
||||
}
|
@ -30,7 +30,8 @@ class OathManager(
|
||||
messenger: BinaryMessenger,
|
||||
appContext: AppContext,
|
||||
private val appViewModel: MainViewModel,
|
||||
private val dialogManager: DialogManager
|
||||
private val dialogManager: DialogManager,
|
||||
private val nfcDiscoveryHelper: NfcDiscoveryHelper
|
||||
) : OathApi {
|
||||
|
||||
private val _dispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher()
|
||||
@ -229,6 +230,7 @@ class OathManager(
|
||||
requireTouch: Boolean,
|
||||
result: Result<String>
|
||||
) {
|
||||
nfcDiscoveryHelper.restartDiscovery()
|
||||
coroutineScope.launch {
|
||||
try {
|
||||
useOathSession("Add account", true) { session ->
|
||||
|
@ -1,8 +1,8 @@
|
||||
group 'com.yubico.authenticator.flutter_plugins.qrscanner_zxing'
|
||||
version '1.0-SNAPSHOT'
|
||||
version '1.0'
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.6.21'
|
||||
ext.kotlin_version = '1.7.10'
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
@ -46,7 +46,7 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
def camerax_version = "1.1.0-beta03"
|
||||
def camerax_version = "1.1.0"
|
||||
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
|
||||
implementation "androidx.camera:camera-view:${camerax_version}"
|
||||
implementation "androidx.camera:camera-camera2:${camerax_version}"
|
||||
|
Loading…
Reference in New Issue
Block a user