From 0e79fb7b511602cf9251c8a229e6057058e307a2 Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Thu, 22 Oct 2020 11:19:51 +0200 Subject: [PATCH] Suppress NDEF tag handling when in foreground --- app/src/main/AndroidManifest.xml | 1 + .../keycard/connect/ui/ChangePINActivity.kt | 2 +- .../keycard/connect/ui/ChangePUKActivity.kt | 2 +- .../ui/ChangePairingPasswordActivity.kt | 2 +- .../status/keycard/connect/ui/InitActivity.kt | 2 +- .../keycard/connect/ui/LoadKeyActivity.kt | 2 +- .../status/keycard/connect/ui/MainActivity.kt | 72 ++++++++++++++----- .../keycard/connect/ui/NoNFCActivity.kt | 22 ++++++ .../status/keycard/connect/ui/PINActivity.kt | 2 +- .../status/keycard/connect/ui/PUKActivity.kt | 2 +- .../keycard/connect/ui/PairingActivity.kt | 2 +- .../keycard/connect/ui/QRCodeActivity.kt | 20 ++++++ .../keycard/connect/ui/ReinstallActivity.kt | 2 +- .../connect/ui/ShowMnemonicActivity.kt | 2 +- .../keycard/connect/ui/SignMessageActivity.kt | 2 +- .../connect/ui/SignTransactionActivity.kt | 2 +- 16 files changed, 109 insertions(+), 30 deletions(-) create mode 100644 app/src/main/java/im/status/keycard/connect/ui/NoNFCActivity.kt create mode 100644 app/src/main/java/im/status/keycard/connect/ui/QRCodeActivity.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c01d068..48e401c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -29,6 +29,7 @@ + Registry.scriptExecutor.onUserInteractionReturned(resultCode, data) + REQ_INTERACTIVE_SCRIPT -> Registry.scriptExecutor.onUserInteractionReturned( + resultCode, + data + ) REQ_WALLETCONNECT -> Registry.walletConnect.onUserInteractionReturned(resultCode, data) REQ_LOADKEY -> loadKeyHandler(resultCode, data) IntentIntegrator.REQUEST_CODE -> qrCodeScanned(resultCode, data) @@ -90,6 +105,7 @@ class MainActivity : AppCompatActivity(), ScriptListener, WalletConnectListener override fun onScriptStarted() { this.runOnUiThread { + activateNFC() viewSwitcher.showNext() } } @@ -119,6 +135,7 @@ class MainActivity : AppCompatActivity(), ScriptListener, WalletConnectListener fun connectWallet(view: View) { updateConnection(view) val integrator = IntentIntegrator(this) + integrator.captureActivity = QRCodeActivity::class.java integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE) integrator.setOrientationLocked(false) integrator.initiateScan() @@ -167,7 +184,14 @@ class MainActivity : AppCompatActivity(), ScriptListener, WalletConnectListener val loadType = data.getIntExtra(LOAD_TYPE, LOAD_NONE) val mnemonic = data.getStringExtra(LOAD_MNEMONIC) - Registry.scriptExecutor.runScript(scriptWithAuthentication().plus(LoadKeyCommand(loadType, mnemonic))) + Registry.scriptExecutor.runScript( + scriptWithAuthentication().plus( + LoadKeyCommand( + loadType, + mnemonic + ) + ) + ) } private fun startCommand(activity: KClass) { @@ -176,37 +200,49 @@ class MainActivity : AppCompatActivity(), ScriptListener, WalletConnectListener } private fun qrCodeScanned(resultCode: Int, data: Intent?) { - if (resultCode != Activity.RESULT_OK || data == null) return - - handleWCURI(data.getStringExtra(Intents.Scan.RESULT)) - + if (resultCode != Activity.RESULT_OK || data == null) { + Log.e(TAG, "QRCode result: $resultCode") + } else { + handleWCURI(data.getStringExtra(Intents.Scan.RESULT)) + } } private fun handleWCURI(uri: String?) { if (uri != null) { + Log.d(TAG, "Connecting to $uri") try { Registry.walletConnect.connect(fromWCUri(uri).toFullyQualifiedConfig()) - } catch (e: Exception) {} + } catch (e: Exception) { + Log.e(TAG, "Parsing $uri failed", e) + } + } else { + Log.e(TAG, "Null URI received") } } override fun onConnected() { - val button = findViewById