Improve NFC history readers and prepare production build
This commit is contained in:
@ -12,6 +12,7 @@ public class BcaFlazzApi : UnifiedNfcApi {
|
||||
private let emoney: Emoney = Emoney()
|
||||
private var ef84Records: [RiwayatCard] = []
|
||||
private var extendedRecords: [RiwayatCard] = []
|
||||
private var historyRetryCount = 0
|
||||
|
||||
private let ef84MaxSlots = 10
|
||||
private let extendedMaxRecords = 256
|
||||
@ -74,6 +75,8 @@ public class BcaFlazzApi : UnifiedNfcApi {
|
||||
}
|
||||
|
||||
self.emoney.setBalance(self.uint32BE(bytes, offset: 0))
|
||||
self.historyRetryCount = 0
|
||||
self.resetHistoryState()
|
||||
self.readHistoryCheck()
|
||||
} else {
|
||||
self.apduRunner.invalidateSession(msg: "readFailed".localizeString(string: self.langCode!))
|
||||
@ -81,6 +84,22 @@ public class BcaFlazzApi : UnifiedNfcApi {
|
||||
})
|
||||
}
|
||||
|
||||
private func resetHistoryState() {
|
||||
ef84Records.removeAll()
|
||||
extendedRecords.removeAll()
|
||||
}
|
||||
|
||||
private func retryHistoryRead(reason: String) {
|
||||
if historyRetryCount < 1 {
|
||||
historyRetryCount += 1
|
||||
debugLog("Retrying Flazz history read: \(reason)")
|
||||
resetHistoryState()
|
||||
readHistoryCheck()
|
||||
} else {
|
||||
finishReading()
|
||||
}
|
||||
}
|
||||
|
||||
private func readHistoryCheck() {
|
||||
apduRunner.exchangeApdu(apduCommand: EmoneyApduCommands.BCA_APDU04, completionHandler: { response in
|
||||
let shouldReadExtended = response.sw1 == 0x90 && response.sw2 == 0x00
|
||||
@ -120,11 +139,7 @@ public class BcaFlazzApi : UnifiedNfcApi {
|
||||
self.finishReading()
|
||||
}
|
||||
} else {
|
||||
if shouldReadExtended {
|
||||
self.getChallenge()
|
||||
} else {
|
||||
self.finishReading()
|
||||
}
|
||||
self.retryHistoryRead(reason: "EF84 status \(response.sw1)-\(response.sw2) at slot \(slot)")
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -143,7 +158,7 @@ public class BcaFlazzApi : UnifiedNfcApi {
|
||||
if response.sw1 == 0x90 && response.sw2 == 0x00 {
|
||||
self.readExtendedRecord(index: 0)
|
||||
} else {
|
||||
self.finishReading()
|
||||
self.retryHistoryRead(reason: "challenge status \(response.sw1)-\(response.sw2)")
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -172,7 +187,7 @@ public class BcaFlazzApi : UnifiedNfcApi {
|
||||
} else if response.sw1 == 0x6A && response.sw2 == 0x80 {
|
||||
self.finishReading()
|
||||
} else {
|
||||
self.finishReading()
|
||||
self.retryHistoryRead(reason: "extended status \(response.sw1)-\(response.sw2) at index \(index)")
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -293,11 +308,11 @@ public class BcaFlazzApi : UnifiedNfcApi {
|
||||
dateComponents.year = 1980
|
||||
dateComponents.month = 1
|
||||
dateComponents.day = 1
|
||||
dateComponents.timeZone = TimeZone(identifier: "Asia/Jakarta")!
|
||||
dateComponents.timeZone = TimeZone(identifier: "Asia/Jakarta") ?? .current
|
||||
dateComponents.hour = 0
|
||||
dateComponents.minute = 0
|
||||
dateComponents.second = seconds
|
||||
return Calendar.current.date(from: dateComponents)!
|
||||
return Calendar.current.date(from: dateComponents) ?? Date.distantPast
|
||||
}
|
||||
|
||||
private func asciiString(_ bytes: [UInt8], start: Int, length: Int) -> String {
|
||||
|
||||
Reference in New Issue
Block a user