fix idm shadow bug; refactor log

master
wlt233 2 years ago
parent b53c2970ab
commit a480f15152

@ -8,6 +8,7 @@ import android.widget.Toast
class EmuCard : HostNfcFService() { class EmuCard : HostNfcFService() {
private lateinit var card: FelicaCard private lateinit var card: FelicaCard
private var TAG: String = "AICEmu-EmuCard"
// byte utils // byte utils
fun byteArrayOfInts(vararg ints: Int) = ByteArray(ints.size) { pos -> ints[pos].toByte() } fun byteArrayOfInts(vararg ints: Int) = ByteArray(ints.size) { pos -> ints[pos].toByte() }
@ -25,12 +26,12 @@ class EmuCard : HostNfcFService() {
override fun processNfcFPacket(commandPacket: ByteArray, extras: Bundle?): ByteArray? { override fun processNfcFPacket(commandPacket: ByteArray, extras: Bundle?): ByteArray? {
val commandHexStr = commandPacket.toHexString() val commandHexStr = commandPacket.toHexString()
Log.d("HCEFService", "processNfcFPacket NFCF") Log.d(TAG, "processNfcFPacket NFCF")
Log.d("HCEFService", "received $commandHexStr") Log.d(TAG, "received $commandHexStr")
//Toast.makeText(this, "received $commandHexStr", Toast.LENGTH_LONG).show() //Toast.makeText(this, "received $commandHexStr", Toast.LENGTH_LONG).show()
if (commandPacket.size < 1 + 1 + 8 || (commandPacket.size.toByte() != commandPacket[0])) { if (commandPacket.size < 1 + 1 + 8 || (commandPacket.size.toByte() != commandPacket[0])) {
Log.e("HCEFService", "processNfcFPacket: packet size error") Log.e(TAG, "processNfcFPacket: packet size error")
return null return null
} }
@ -39,7 +40,7 @@ class EmuCard : HostNfcFService() {
// val myNfcid2 = // val myNfcid2 =
// byteArrayOfInts(0x02, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00) // byteArrayOfInts(0x02, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
// if (!Arrays.equals(myNfcid2, nfcid2)) { // if (!Arrays.equals(myNfcid2, nfcid2)) {
// Log.e("HCEFService", "processNfcFPacket: nfcid2 error") // Log.e(TAG, "processNfcFPacket: nfcid2 error")
// return null // return null
// } // }
@ -53,7 +54,7 @@ class EmuCard : HostNfcFService() {
} }
val resp = packResponse(0x07.toByte(), nfcid2, payload) val resp = packResponse(0x07.toByte(), nfcid2, payload)
val respHexStr = resp.toHexString() val respHexStr = resp.toHexString()
Log.d("HCEFService", "send $respHexStr") Log.d(TAG, "send $respHexStr")
Toast.makeText(this, "Scanned", Toast.LENGTH_LONG).show() Toast.makeText(this, "Scanned", Toast.LENGTH_LONG).show()
//Toast.makeText(this, "received $commandHexStr\n\nsend $respHexStr", Toast.LENGTH_LONG).show() //Toast.makeText(this, "received $commandHexStr\n\nsend $respHexStr", Toast.LENGTH_LONG).show()
return resp return resp
@ -62,7 +63,7 @@ class EmuCard : HostNfcFService() {
val payload = ByteArray(2) val payload = ByteArray(2)
val resp = packResponse(0x09.toByte(), nfcid2, payload) val resp = packResponse(0x09.toByte(), nfcid2, payload)
val respHexStr = resp.toHexString() val respHexStr = resp.toHexString()
Log.d("HCEFService", "send $respHexStr") Log.d(TAG, "send $respHexStr")
//Toast.makeText(this, "received $commandHexStr\n\nsend $respHexStr", Toast.LENGTH_LONG).show() //Toast.makeText(this, "received $commandHexStr\n\nsend $respHexStr", Toast.LENGTH_LONG).show()
return resp return resp
} }
@ -76,7 +77,7 @@ class EmuCard : HostNfcFService() {
override fun onCreate() { override fun onCreate() {
Log.d("HCEFService", "onCreate NFCF") Log.d(TAG, "onCreate NFCF")
super.onCreate() super.onCreate()
val globalVar = this.applicationContext as GlobalVar val globalVar = this.applicationContext as GlobalVar
card = FelicaCard(this, globalVar.IDm) card = FelicaCard(this, globalVar.IDm)
@ -84,12 +85,12 @@ class EmuCard : HostNfcFService() {
} }
override fun onDestroy() { override fun onDestroy() {
Log.d("HCEFService", "onDestroy NFCF") Log.d(TAG, "onDestroy NFCF")
super.onDestroy() super.onDestroy()
// Toast.makeText(this, "onDestroy", Toast.LENGTH_LONG).show() // Toast.makeText(this, "onDestroy", Toast.LENGTH_LONG).show()
} }
override fun onDeactivated(reason: Int) { override fun onDeactivated(reason: Int) {
Log.d("HCEFService", "onDeactivated NFCF") Log.d(TAG, "onDeactivated NFCF")
// Toast.makeText(this, "onDeactivated", Toast.LENGTH_LONG).show() // Toast.makeText(this, "onDeactivated", Toast.LENGTH_LONG).show()
} }
} }

@ -125,8 +125,21 @@ class MainActivity : AppCompatActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) { return when (item.itemId) {
R.id.toolbar_menu_hide_id -> { R.id.toolbar_menu_hide_id -> {
val cardsLayout: ViewGroup = findViewById(R.id.mainList)
showCardID = !showCardID showCardID = !showCardID
checkCardIDShadow()
true
}
R.id.toolbar_menu_settings -> {
Toast.makeText(applicationContext, "还没做()\nUnder constuction...", Toast.LENGTH_LONG).show()
// TODO
true
}
else -> super.onOptionsItemSelected(item)
}
}
private fun checkCardIDShadow() {
val cardsLayout: ViewGroup = findViewById(R.id.mainList)
for (i in 0 until cardsLayout.childCount) { for (i in 0 until cardsLayout.childCount) {
val child = cardsLayout.getChildAt(i) val child = cardsLayout.getChildAt(i)
if (child is CardView) { if (child is CardView) {
@ -142,15 +155,6 @@ class MainActivity : AppCompatActivity() {
} }
} }
} }
true
}
R.id.toolbar_menu_settings -> {
Toast.makeText(applicationContext, "还没做()\nUnder constuction...", Toast.LENGTH_LONG).show()
// TODO
true
}
else -> super.onOptionsItemSelected(item)
}
} }
private fun showCardMenu(v: View, cardView: View) { private fun showCardMenu(v: View, cardView: View) {
@ -240,6 +244,7 @@ class MainActivity : AppCompatActivity() {
nameTextView.text = name nameTextView.text = name
val IDmTextView = cardView.findViewById<TextView>(R.id.card_id) val IDmTextView = cardView.findViewById<TextView>(R.id.card_id)
IDmTextView.text = IDm IDmTextView.text = IDm
checkCardIDShadow()
val menuButton: ImageButton = cardView.findViewById(R.id.card_menu_button) val menuButton: ImageButton = cardView.findViewById(R.id.card_menu_button)
menuButton.setOnClickListener { menuButton.setOnClickListener {
showCardMenu(it, cardView) showCardMenu(it, cardView)

@ -14,7 +14,7 @@ import android.widget.Toast
class ReadCard : Activity(), NfcAdapter.ReaderCallback{ class ReadCard : Activity(), NfcAdapter.ReaderCallback{
private var nfcAdapter: NfcAdapter? = null private var nfcAdapter: NfcAdapter? = null
private val TAG = "AICEmu" private val TAG = "AICEmu-ReadCard"
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -26,9 +26,7 @@ class ReadCard : Activity(), NfcAdapter.ReaderCallback{
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
nfcAdapter?.let { nfcAdapter?.let {
// 设置前台调度系统
val options = Bundle() val options = Bundle()
options.putInt(NfcAdapter.EXTRA_READER_PRESENCE_CHECK_DELAY, 5000) options.putInt(NfcAdapter.EXTRA_READER_PRESENCE_CHECK_DELAY, 5000)
it.enableReaderMode(this, this, NfcAdapter.FLAG_READER_NFC_F, options) it.enableReaderMode(this, this, NfcAdapter.FLAG_READER_NFC_F, options)
@ -44,7 +42,7 @@ class ReadCard : Activity(), NfcAdapter.ReaderCallback{
val nfcF = NfcF.get(tag) val nfcF = NfcF.get(tag)
nfcF?.let { nfcF?.let {
val idm = it.tag.id val idm = it.tag.id
val idmString = toHexString(idm) val idmString = idm.toHexString(false)
Log.d(TAG, "IDm: $idmString") Log.d(TAG, "IDm: $idmString")
runOnUiThread { runOnUiThread {
@ -56,12 +54,7 @@ class ReadCard : Activity(), NfcAdapter.ReaderCallback{
finish() finish()
} }
} }
fun ByteArray.toHexString(hasSpace: Boolean = true) = this.joinToString("") {
private fun toHexString(data: ByteArray): String { (it.toInt() and 0xFF).toString(16).padStart(2, '0').uppercase() + if (hasSpace) " " else ""
val sb = StringBuilder()
for (b in data) {
sb.append(String.format("%02X", b))
}
return sb.toString()
} }
} }

Loading…
Cancel
Save