From 957ff86fa10c36126e4623a6bdf720400da402b6 Mon Sep 17 00:00:00 2001 From: TwistedUmbrellaX Date: Sat, 10 Aug 2024 06:46:55 -0400 Subject: [PATCH] Add a parameter for skipping lock info write --- .github/FUNDING.yml | 2 +- .../com/hiddenramblings/tagmo/NFCIntent.kt | 1 + .../tagmo/nfctech/NfcActivity.kt | 10 ++++- .../tagmo/nfctech/TagWriter.kt | 40 ++++++++++--------- app/src/main/res/values/strings.xml | 1 + 5 files changed, 33 insertions(+), 21 deletions(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 82fa7f056..026b2ab70 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,3 +1,3 @@ github: AbandonedCart -buy_me_a_coffee: tagmo +buy_me_a_coffee: abandonedcart custom: ['https://paypal.me/twistedumbrella'] diff --git a/app/src/main/java/com/hiddenramblings/tagmo/NFCIntent.kt b/app/src/main/java/com/hiddenramblings/tagmo/NFCIntent.kt index b60f183bb..2b81ecb29 100644 --- a/app/src/main/java/com/hiddenramblings/tagmo/NFCIntent.kt +++ b/app/src/main/java/com/hiddenramblings/tagmo/NFCIntent.kt @@ -35,4 +35,5 @@ object NFCIntent { const val EXTRA_ACTIVE_BANK = BuildConfig.APPLICATION_ID + ".EXTRA_ACTIVE_BANK" const val EXTRA_BANK_COUNT = BuildConfig.APPLICATION_ID + ".EXTRA_BANK_COUNT" const val EXTRA_CURRENT_BANK = BuildConfig.APPLICATION_ID + ".EXTRA_CURRENT_BANK" + const val EXTRA_SKIP_LOCK_INFO = BuildConfig.APPLICATION_ID + ".EXTRA_SKIP_LOCK_INFO" } \ No newline at end of file diff --git a/app/src/main/java/com/hiddenramblings/tagmo/nfctech/NfcActivity.kt b/app/src/main/java/com/hiddenramblings/tagmo/nfctech/NfcActivity.kt index 7be7c42ee..7e0233d51 100644 --- a/app/src/main/java/com/hiddenramblings/tagmo/nfctech/NfcActivity.kt +++ b/app/src/main/java/com/hiddenramblings/tagmo/nfctech/NfcActivity.kt @@ -66,6 +66,7 @@ class NfcActivity : AppCompatActivity() { private var isEliteIntent = false private var isEliteDevice = false + private var skipLockInfo = false private var ntag215: NTAG215? = null private var skylanders: Skylanders? = null private var infinity: Infinity? = null @@ -111,6 +112,7 @@ class NfcActivity : AppCompatActivity() { val commandIntent = this.intent val mode = commandIntent.action isEliteIntent = commandIntent.hasExtra(NFCIntent.EXTRA_SIGNATURE) + skipLockInfo = commandIntent.hasExtra(NFCIntent.EXTRA_SKIP_LOCK_INFO) when { commandIntent.hasExtra(NFCIntent.EXTRA_CURRENT_BANK) -> { val position = bankPicker.getPositionByValue(bankPicker.value) @@ -306,7 +308,9 @@ class NfcActivity : AppCompatActivity() { when (mode) { NFCIntent.ACTION_WRITE_TAG_RAW -> { update = TagReader.readFromTag(mifare) - TagWriter.writeToTagRaw(mifare, data!!, prefs.tagTypeValidation()) + TagWriter.writeToTagRaw( + mifare, data!!, prefs.tagTypeValidation(), skipLockInfo + ) setResult(RESULT_OK) } NFCIntent.ACTION_WRITE_TAG_FULL -> { @@ -341,7 +345,9 @@ class NfcActivity : AppCompatActivity() { }) } else { update = TagReader.readFromTag(mifare) - TagWriter.writeToTagAuto(mifare, data!!, keyManager, prefs.tagTypeValidation()) + TagWriter.writeToTagAuto( + mifare, data!!, keyManager, prefs.tagTypeValidation(), skipLockInfo + ) setResult(RESULT_OK) } } diff --git a/app/src/main/java/com/hiddenramblings/tagmo/nfctech/TagWriter.kt b/app/src/main/java/com/hiddenramblings/tagmo/nfctech/TagWriter.kt index c5042869d..705c97c5e 100644 --- a/app/src/main/java/com/hiddenramblings/tagmo/nfctech/TagWriter.kt +++ b/app/src/main/java/com/hiddenramblings/tagmo/nfctech/TagWriter.kt @@ -35,7 +35,7 @@ object TagWriter { @Throws(Exception::class) fun writeToTagRaw( - mifare: NTAG215, tagData: ByteArray, validateNtag: Boolean + mifare: NTAG215, tagData: ByteArray, validateNtag: Boolean, skipLock: Boolean = false ) { val context = TagMo.appContext TagArray.validateNtag(mifare, tagData, validateNtag) @@ -53,13 +53,15 @@ object TagWriter { } catch (e: Exception) { throw Exception(context.getString(R.string.error_password_write), e) } - if (true) { - try { - writeLockInfo(mifare) - Debug.verbose(TagWriter::class.java, R.string.lock_write) - } catch (e: Exception) { - throw Exception(context.getString(R.string.error_lock_write), e) - } + if (skipLock) { + Debug.verbose(TagWriter::class.java, R.string.lock_skipped) + return + } + try { + writeLockInfo(mifare) + Debug.verbose(TagWriter::class.java, R.string.lock_write) + } catch (e: Exception) { + throw Exception(context.getString(R.string.error_lock_write), e) } } @@ -83,26 +85,28 @@ object TagWriter { } @Throws(Exception::class) - private fun writePasswordLockInfo(mifare: NTAG215) { + private fun writePasswordLockInfo(mifare: NTAG215, skipLock: Boolean) { try { writePassword(mifare) Debug.verbose(TagWriter::class.java, R.string.password_write) } catch (e: Exception) { throw Exception(TagMo.appContext.getString(R.string.error_password_write), e) } - if (true) { - try { - writeLockInfo(mifare) - Debug.verbose(TagWriter::class.java, R.string.lock_write) - } catch (e: Exception) { - throw Exception(TagMo.appContext.getString(R.string.error_lock_write), e) - } + if (skipLock) { + Debug.verbose(TagWriter::class.java, R.string.lock_skipped) + return + } + try { + writeLockInfo(mifare) + Debug.verbose(TagWriter::class.java, R.string.lock_write) + } catch (e: Exception) { + throw Exception(TagMo.appContext.getString(R.string.error_lock_write), e) } } @Throws(Exception::class) fun writeToTagAuto( - mifare: NTAG215, tagData: ByteArray, keyManager: KeyManager, validateNtag: Boolean + mifare: NTAG215, tagData: ByteArray, keyManager: KeyManager, validateNtag: Boolean, skipLock: Boolean = false ) { val idPages = mifare.readPages(0) if (null == idPages || idPages.size != NfcByte.PAGE_SIZE * 4) @@ -157,7 +161,7 @@ object TagWriter { } catch (e: Exception) { throw Exception(TagMo.appContext.getString(R.string.error_data_write), e) } - writePasswordLockInfo(mifare) + writePasswordLockInfo(mifare, skipLock) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fb2ba05de..b8ab38659 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -370,6 +370,7 @@ Wrote main data Wrote password Wrote lock info + Lock info skipped Auth response %1$s Password: %1$s