Hello! I'm osi

I build and break things

(and pretend to be a bear on the internet)

osi, a bear with green ears and a purple stripe
← back to works

Puerta Kala

for Kalahari Disco

Puerta Kala is an Android app that runs on a handheld terminal at the door of Kalahari events. An operator logs in, picks the event of the night, types or scans a DNI, and gets a name with a green panel and a confirmation step, or a red panel with the reason. It works from a physical numeric keypad, on a device with no touch keyboard, and it keeps accepting people when the venue loses its connection. No store release is planned: the app ships as an APK installed on the terminal.

How it works

The app is one activity with five screens: admin login, event list, DNI entry, result and confirmation, plus a fullscreen loading overlay and a status line. A session moves through password, event, DNI and result, and an entry is only recorded after a Yes/No confirmation, so a misread code does not check anyone in.

The backend is a small PHP and SQLite service. Its public side handles event signup and validates DNI, birth date and sex against RENAPER before a name is accepted, with a capacity and a cutoff per event date. Its admin side manages events and lists, shows how many people have entered, toggles a check-in, prints the list and exports it as a text file. The terminal talks to the same service through a JSON API.

The guest list for an event is downloaded before the doors open and searched locally.

A keypad, not a touchscreen

All input is handled centrally in dispatchKeyEvent, because the device has no reliable soft keyboard. Digits go straight into the DNI field. The admin password is the only text entry and uses multi-tap: repeated presses of 2 cycle a, b, c, 2, and a different key or a pause locks the character. BACK deletes the last digit while typing a DNI and does nothing on the event list, so the terminal cannot be dismissed by accident. The confirmation step is a Yes/No choice with No focused first.

The same code runs on a tablet, where the keypad is drawn on screen and a Bluetooth scanner feeds the ID as keyboard events. A scanner configured without a suffix ends the payload after a 250 ms gap in the keystream:

private fun armScanTimeout() {
    cancelScanTimeout()
    scanTimeoutRunnable = Runnable { finalizeScan() }
    window.decorView.postDelayed(scanTimeoutRunnable!!, SCAN_IDLE_TIMEOUT_MS)
}

A door that keeps working

Login always needs the network and there is no local password verifier. After login, selecting an event downloads its full guest list with a percentage in the status line, and the copy is encrypted at rest with a key held in the Android Keystore. Searches then run against the server when it answers and against that copy when it does not.

A check-in made offline is written locally with the terminal's timestamp and queued. When the connection returns, the queue is pushed first and then every cached list is downloaded again, so un-check-ins, edits and removals made in the admin panel reach the terminal. A live search result always wins over the cache, so a stale queued entry cannot hide a change made on the server. A "Forzar sin conexión" checkbox covers the case of a link that exists but does not reach the server.

// Offline: record locally and queue for later sync.
val stamp = nowStamp()
cache.markLocalCheckedIn(date.id, signup.id, stamp)
cache.enqueue(PendingCheckin(date.id, signup.id, signup.dni, stamp))

The ID in the barcode

DNIs can be typed, read with the camera, or read by a Bluetooth scanner. The camera reads PDF417 and QR codes from an ID card or driver's licence. The payload is a set of @-separated fields, and the DNI is the first field of exactly eight digits after the first three, which keeps the 11-digit tracking number from being mistaken for it:

val dni = fields.drop(3)
    .firstOrNull { DNI_REGEX.matches(it.trim()) }?.trim() ?: return null

The birth date is the earliest date in the payload, because the issue date is always later. Two payload variants exist, one with a sex field and one without, and both are handled. A holder under 18 is stopped before the search runs, with its own panel. Payloads that fail to parse are written to a log in the Downloads folder, which is how new or damaged formats get identified.

When an entry is registered offline, the time the server keeps is the time the terminal recorded, not the time the sync happened. Each queued item carries its own timestamp, and the server accepts it only if it parses exactly; if the record was already checked in on another terminal, the existing time stands. A check-in queued at 23:40 and synced the next morning still reads 23:40 in the admin panel.