mirror of
https://github.com/status-im/keycard-connect.git
synced 2025-01-09 18:45:58 +00:00
Suppress NDEF tag handling when in foreground
This commit is contained in:
parent
416f18f328
commit
0e79fb7b51
@ -29,6 +29,7 @@
|
||||
<activity android:name=".ui.PairingActivity" />
|
||||
<activity android:name=".ui.PINActivity" />
|
||||
<activity android:name=".ui.ReinstallActivity" />
|
||||
<activity android:name=".ui.QRCodeActivity" />
|
||||
<activity
|
||||
android:name=".ui.MainActivity"
|
||||
android:label="@string/app_name"
|
||||
|
@ -12,7 +12,7 @@ import im.status.keycard.connect.card.ChangePINCommand
|
||||
import im.status.keycard.connect.card.scriptWithAuthentication
|
||||
import im.status.keycard.connect.data.isValidPIN
|
||||
|
||||
class ChangePINActivity : AppCompatActivity() {
|
||||
class ChangePINActivity : NoNFCActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_change_pin)
|
||||
|
@ -12,7 +12,7 @@ import im.status.keycard.connect.card.ChangePUKCommand
|
||||
import im.status.keycard.connect.card.scriptWithAuthentication
|
||||
import im.status.keycard.connect.data.isValidPUK
|
||||
|
||||
class ChangePUKActivity : AppCompatActivity() {
|
||||
class ChangePUKActivity : NoNFCActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_change_puk)
|
||||
|
@ -12,7 +12,7 @@ import im.status.keycard.connect.card.ChangePairingPasswordCommand
|
||||
import im.status.keycard.connect.card.scriptWithAuthentication
|
||||
import im.status.keycard.connect.data.isValidPUK
|
||||
|
||||
class ChangePairingPasswordActivity : AppCompatActivity() {
|
||||
class ChangePairingPasswordActivity : NoNFCActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_change_pairing_password)
|
||||
|
@ -15,7 +15,7 @@ import im.status.keycard.connect.data.INIT_ACTIVITY_PIN
|
||||
import im.status.keycard.connect.data.INIT_ACTIVITY_PUK
|
||||
import im.status.keycard.globalplatform.Crypto
|
||||
|
||||
class InitActivity : AppCompatActivity() {
|
||||
class InitActivity : NoNFCActivity() {
|
||||
private lateinit var pin: String
|
||||
private lateinit var puk: String
|
||||
private lateinit var pairing: String
|
||||
|
@ -10,7 +10,7 @@ import im.status.keycard.connect.R
|
||||
import im.status.keycard.connect.data.*
|
||||
import java.util.*
|
||||
|
||||
class LoadKeyActivity : AppCompatActivity() {
|
||||
class LoadKeyActivity : NoNFCActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -4,6 +4,7 @@ import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.nfc.NfcAdapter
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
@ -18,6 +19,8 @@ import im.status.keycard.connect.net.WalletConnectListener
|
||||
import org.walletconnect.Session.Config.Companion.fromWCUri
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
private const val TAG = "MainActivity"
|
||||
|
||||
class MainActivity : AppCompatActivity(), ScriptListener, WalletConnectListener {
|
||||
private lateinit var viewSwitcher: ViewSwitcher
|
||||
private lateinit var networkSpinner: Spinner
|
||||
@ -48,9 +51,18 @@ class MainActivity : AppCompatActivity(), ScriptListener, WalletConnectListener
|
||||
handleIntent(intent)
|
||||
}
|
||||
|
||||
private fun activateNFC() {
|
||||
Registry.nfcAdapter.enableReaderMode(
|
||||
this,
|
||||
Registry.cardManager,
|
||||
NfcAdapter.FLAG_READER_NFC_A or NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK,
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
Registry.nfcAdapter.enableReaderMode(this, Registry.cardManager,NfcAdapter.FLAG_READER_NFC_A or NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK, null)
|
||||
activateNFC()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
@ -81,7 +93,10 @@ class MainActivity : AppCompatActivity(), ScriptListener, WalletConnectListener
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
|
||||
when (requestCode) {
|
||||
REQ_INTERACTIVE_SCRIPT -> 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<out Activity>) {
|
||||
@ -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<Button>(R.id.walletConnectButton)
|
||||
button.setOnClickListener(this::disconnectWallet)
|
||||
button.text = getString(R.string.disconnect_wallet)
|
||||
this.runOnUiThread {
|
||||
val button = findViewById<Button>(R.id.walletConnectButton)
|
||||
button.setOnClickListener(this::disconnectWallet)
|
||||
button.text = getString(R.string.disconnect_wallet)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDisconnected() {
|
||||
val button = findViewById<Button>(R.id.walletConnectButton)
|
||||
button.setOnClickListener(this::connectWallet)
|
||||
button.text = getString(R.string.connect_wallet)
|
||||
this.runOnUiThread {
|
||||
val button = findViewById<Button>(R.id.walletConnectButton)
|
||||
button.setOnClickListener(this::connectWallet)
|
||||
button.text = getString(R.string.connect_wallet)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAccountChanged(account: String?) {
|
||||
if (account == null) {
|
||||
findViewById<TextView>(R.id.walletAddress).text = getString(R.string.wallet_not_connected)
|
||||
} else {
|
||||
findViewById<TextView>(R.id.walletAddress).text = account
|
||||
this.runOnUiThread {
|
||||
if (account == null) {
|
||||
findViewById<TextView>(R.id.walletAddress).text = getString(R.string.wallet_not_connected)
|
||||
} else {
|
||||
findViewById<TextView>(R.id.walletAddress).text = account
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
package im.status.keycard.connect.ui
|
||||
|
||||
import android.nfc.NfcAdapter
|
||||
import android.nfc.NfcAdapter.ReaderCallback
|
||||
import android.nfc.Tag
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import im.status.keycard.connect.Registry
|
||||
|
||||
|
||||
open class NoNFCActivity : AppCompatActivity(), ReaderCallback {
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
Registry.nfcAdapter.enableReaderMode(this, this, NfcAdapter.FLAG_READER_NFC_A or NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK, null)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
Registry.nfcAdapter.disableReaderMode(this)
|
||||
}
|
||||
|
||||
override fun onTagDiscovered(tag: Tag?) {}
|
||||
}
|
@ -14,7 +14,7 @@ import im.status.keycard.connect.data.PIN_ACTIVITY_ATTEMPTS
|
||||
import im.status.keycard.connect.data.PIN_ACTIVITY_CARD_UID
|
||||
import im.status.keycard.connect.data.isValidPIN
|
||||
|
||||
class PINActivity : AppCompatActivity() {
|
||||
class PINActivity : NoNFCActivity() {
|
||||
private lateinit var cardUID: ByteArray
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
@ -14,7 +14,7 @@ import im.status.keycard.connect.data.PUK_ACTIVITY_ATTEMPTS
|
||||
import im.status.keycard.connect.data.isValidPIN
|
||||
import im.status.keycard.connect.data.isValidPUK
|
||||
|
||||
class PUKActivity : AppCompatActivity() {
|
||||
class PUKActivity : NoNFCActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -11,7 +11,7 @@ import androidx.core.widget.doAfterTextChanged
|
||||
import im.status.keycard.connect.R
|
||||
import im.status.keycard.connect.data.PAIRING_ACTIVITY_PASSWORD
|
||||
|
||||
class PairingActivity : AppCompatActivity() {
|
||||
class PairingActivity : NoNFCActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -0,0 +1,20 @@
|
||||
package im.status.keycard.connect.ui
|
||||
|
||||
import android.nfc.NfcAdapter
|
||||
import android.nfc.Tag
|
||||
import com.journeyapps.barcodescanner.CaptureActivity
|
||||
import im.status.keycard.connect.Registry
|
||||
|
||||
class QRCodeActivity : CaptureActivity(), NfcAdapter.ReaderCallback {
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
Registry.nfcAdapter.enableReaderMode(this, this, NfcAdapter.FLAG_READER_NFC_A or NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK, null)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
Registry.nfcAdapter.disableReaderMode(this)
|
||||
}
|
||||
|
||||
override fun onTagDiscovered(tag: Tag?) {}
|
||||
}
|
@ -10,7 +10,7 @@ import im.status.keycard.connect.Registry
|
||||
import im.status.keycard.connect.card.ReinstallCommand
|
||||
import im.status.keycard.connect.data.REQ_APPLET_FILE
|
||||
|
||||
class ReinstallActivity : AppCompatActivity() {
|
||||
class ReinstallActivity : NoNFCActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_reinstall)
|
||||
|
@ -7,7 +7,7 @@ import androidx.appcompat.app.AppCompatActivity
|
||||
import im.status.keycard.connect.R
|
||||
import im.status.keycard.connect.data.MNEMONIC_PHRASE
|
||||
|
||||
class ShowMnemonicActivity : AppCompatActivity() {
|
||||
class ShowMnemonicActivity : NoNFCActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_show_mnemonic)
|
||||
|
@ -8,7 +8,7 @@ import androidx.appcompat.app.AppCompatActivity
|
||||
import im.status.keycard.connect.R
|
||||
import im.status.keycard.connect.data.SIGN_TEXT_MESSAGE
|
||||
|
||||
class SignMessageActivity : AppCompatActivity() {
|
||||
class SignMessageActivity : NoNFCActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -11,7 +11,7 @@ import im.status.keycard.connect.data.SIGN_TX_CURRENCY
|
||||
import im.status.keycard.connect.data.SIGN_TX_DATA
|
||||
import im.status.keycard.connect.data.SIGN_TX_TO
|
||||
|
||||
class SignTransactionActivity : AppCompatActivity() {
|
||||
class SignTransactionActivity : NoNFCActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
Loading…
x
Reference in New Issue
Block a user