How snorsnor9998/sunmi-card-reader works
Project Type and Purpose
• This is a single‐module Android demo app (written in Kotlin/Java, Gradle‐based) whose sole purpose is to demonstrate how to integrate and use the Sunmi Pay SDK (AAR) for reading cards (IC/NFC/Magnetic), performing EMV transactions, prompting PIN entry, and extracting TLV data on a Sunmi P2 device. There is no separate backend or network service in this repo—everything runs locally on the device, driven by the SunmiPayKernel.
File Structure Analysis
• Top‐level Gradle project with one “app” module.
• app/libs/PayLib-release-1.4.43.aar: the core Sunmi Pay SDK library.
• src/main/java/com/snor/sunmicardreader:
• BaseApp.kt: global initialization and static SDK references.
• InitActivity.kt: calls SunmiPayKernel.initPaySDK(…)
• MainActivity.kt: user triggers card read / EMV flow.
• Callback/: custom subclasses of CheckCardCallback, EMVCallback, PinPadCallback.
• util/: ByteUtil, TLVUtil, EmvUtil, etc., for data conversion and EMV setup.
• Standard Android resources (layouts, drawables, manifest).
Key Architectural Patterns
• Layered separation:
• UI layer (Activities + XML layouts)
• SDK integration layer (SunmiPayKernel → mReadCardOptV2, mEMVOptV2, mPinPadOptV2)
• Hardware/Platform abstraction layer (AAR library talking to device hardware)
• Utility & Callback layer for processing TLV, byte conversions, and event handling
• Event‐driven via callbacks: CheckCardCallback, EMVCallback, PinPadCallback wire UI to SDK events.
Main Components and Interactions
a. Components:
• UI: InitActivity, MainActivity, Buttons (NFC/IC/Swipe triggers)
• SDK Core: SunmiPayKernel singleton (AAR)
• Module Interfaces: ReadCardOptV2, EMVOptV2, PinPadOptV2, BasicOptV2, SecurityOptV2
• Callback Handlers: CheckCardCallback, EMVCallback, PinPadCallback
• Utility Classes: EmvUtil, ByteUtil, TLVUtil
• Device Hardware: Card Reader, EMV Chip, PIN Pad
b. Data Flow & Relationships:
1) UI → SunmiPayKernel.initPaySDK → ConnectCallback
2) On success: BaseApp stores mReadCardOptV2, mEMVOptV2, mPinPadOptV2
3) UI triggers ReadCardOptV2.checkCard(…) → hardware scans card → CheckCardCallback callbacks
4) On IC/NFC found → call EMVOptV2.initEmvProcess() → EMVOptV2.transactProcess(...) → EMVCallback events (app select, TLV setup, PIN prompt, online processing)
5) PIN entry: PinPadOptV2.initPinPad(...) → PinPadCallback → EMVOptV2.importPinInputStatus(...)
6) EMV online: getTlvList(…) → TLVUtil parses → return TLV map → UI/log
c. Architectural Patterns:
• Singleton SDK gateway (SunmiPayKernel)
• Callback‐driven state machine for EMV transaction
• Utility modules abstract TLV/byte handling
d. Technologies & Frameworks:
• Android (Kotlin/Java, Gradle)
• Sunmi Pay AAR (PayLib-release-1.4.43.aar)
• EMV, ISO 4217/3166/8583, ISO 9564 standards for payment