Skip to content

Commit

Permalink
Add a parameter for skipping lock info write
Browse files Browse the repository at this point in the history
  • Loading branch information
AbandonedCart committed Aug 10, 2024
1 parent a010252 commit 957ff86
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
github: AbandonedCart
buy_me_a_coffee: tagmo
buy_me_a_coffee: abandonedcart
custom: ['https://paypal.me/twistedumbrella']
1 change: 1 addition & 0 deletions app/src/main/java/com/hiddenramblings/tagmo/NFCIntent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 -> {
Expand Down Expand Up @@ -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)
}
}
Expand Down
40 changes: 22 additions & 18 deletions app/src/main/java/com/hiddenramblings/tagmo/nfctech/TagWriter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}

Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@
<string name="data_write">Wrote main data</string>
<string name="password_write">Wrote password</string>
<string name="lock_write">Wrote lock info</string>
<string name="lock_skipped">Lock info skipped</string>

<string name="auth_response">Auth response %1$s</string>
<string name="password">Password: %1$s</string>
Expand Down

0 comments on commit 957ff86

Please sign in to comment.