Skip to content

In review · not yet published

7 min readLaunchapp

Running a restaurant's Android tablets like an IoT fleet

Device-owner mode, a locked kiosk, silent verified updates, mDNS discovery, a content-addressed LAN cache and ESC/POS printing, from one working restaurant.

A restaurant is a bad place for consumer tablets. Staff are busy, the network is whatever the building has, and nobody on shift is going to accept an update prompt or clear a storage warning. If the software only works when someone looks after the devices, it does not work.

Dina Cocina is a working restaurant in Querétaro that runs on software we built. The point of sale was built in days. The platform around it then grew through about three months of upgrades: live payments, a kitchen display, inventory and a fleet of tablets, TVs and printers. This post is about that last part, and the decision that made it manageable: treat every screen in the building as a managed device, the way you would treat a sensor in the field.

The fleet is a set of native Kotlin and Jetpack Compose apps. The pieces described here are the launcher that staff tablets boot into, the customer menu kiosk, the TV display, the staff time clock, a ticket and label designer, and a small library that lets devices share media with each other.

PL. 03Restaurant floor · device fleetPlan · not to scale
10 tablets · native Kotlin/Compose
Architecture from the real system. The update animation is a simulation.

Own the device, then decide what to lock

Android's device-owner mode gives one app administrative control of the tablet: it can install packages silently, pin the screen to chosen apps and survive a reboot as the home screen. Each tablet is provisioned once over adb, and the provisioning script refuses to enrol a tablet that still has user accounts on it, because Android will not grant device ownership in that state.

What we do with that ownership differs by device, and this is the part worth copying.

The customer kiosk is locked hard. It is a tablet customers touch, so it gets lock task mode with exactly one package allowlisted, itself. The check runs every time the activity resumes:

private fun lockDownIfOwner() {
    runCatching {
        val dpm = getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
        if (dpm.isDeviceOwnerApp(packageName)) {
            val admin = ComponentName(this, KioskDeviceAdminReceiver::class.java)
            runCatching { dpm.setLockTaskPackages(admin, arrayOf(packageName)) }
            startLockTask()
        }
    }
}

If the tablet is not a device owner, the kiosk falls back to being the home app in immersive mode. It degrades; it does not refuse to start.

Staff tablets are deliberately not locked. A kitchen needs a messaging app, a camera and whatever else the shift requires, and a tablet that fights its users gets unplugged. So the staff launcher uses device ownership for the opposite job: it clears lock task and a long list of user restrictions on every policy version bump, keeps the screen awake while charging, disables the keyguard, and holds itself as the persistent home activity. Control comes from what the launcher shows, not from what the operating system forbids.

Lock the screen a customer touches. Curate the screen your staff use. Those are different problems.

A launcher that shows only what the tablet is for

The staff launcher is the tablet's home screen. Its tiles are our own apps plus an allowlist of extra packages, and an app only appears if it is actually installed. The extra allowlist is edited on the tablet behind an admin PIN, so a manager can add an app for one tablet without a deploy.

Each tablet also has a station: kitchen, bar or register. The station changes the order of the tiles, so the register tablet leads with the register tools and the kitchen tablet leads with the kitchen ones. A few sensitive apps can require a PIN to open, checked against the server and falling back to a local PIN when the network is down.

That offline fallback is a theme. Every feature in the building is designed for the hour the internet drops during service.

Silent updates, verified four ways

There is no app store in this fleet and no staff action. The launcher checks in with the fleet API every ten minutes, or immediately when the server pushes a sync event. It reports the installed version of every managed app, and the server answers with the updates that tablet should take.

Installing an APK silently is a privilege worth being careful with. Before anything is installed, the download has to pass four checks:

val actualSha = sha256OfFile(dest)
if (!actualSha.equals(expectedSha, ignoreCase = true)) throw IllegalStateException("sha256 mismatch")
val archive = context.packageManager.getPackageArchiveInfo(dest.absolutePath, signingFlags())
    ?: throw IllegalStateException("invalid APK archive")
if (archive.packageName != pkg) throw IllegalStateException("APK package mismatch")
if (archiveVersionCode != expectedVersionCode) throw IllegalStateException("APK version mismatch")
val apkSigner = signerSha256(archive)
val installedSigner = pkgInfo(pkg, signingFlags())?.let { signerSha256(it) }
val ok = apkSigner != null && (apkSigner == PINNED_CERT_SHA256 || (installedSigner != null && apkSigner == installedSigner))

The file hash must match what the server promised. The package name must be the one requested. The version code must match exactly. And the signing certificate must be either a pinned release certificate or the certificate of the version already installed. Only then does the launcher open a PackageInstaller session, write the APK, commit it, and wait for the result.

Three details came from running it for real:

  • The launcher updates itself last. Installing yourself kills your own process, so every other app goes first.
  • A bad build is not retried in a loop. A failed hash is skipped for thirty minutes, and the error is reported on the next check-in, so a broken release shows up on a dashboard and not as a tablet stuck downloading.
  • The kiosk waits for a quiet moment. It only installs when it is idle with an empty cart. Nobody loses an order to an update.

One thing we have not built: rollback. A bad build is fixed by shipping a newer one, which the ten-minute check-in makes fast. We would add staged rollouts before we would add downgrade support.

Devices that find each other

Restaurant networks are not configured by network engineers. Static IPs and a hand-maintained device list would last about a week. So devices advertise and discover each other with mDNS, through Android's NsdManager.

Each service registers a type of the form _<service>._tcp. and publishes a few TXT attributes:

val info = NsdServiceInfo().apply {
    serviceName = "meshcache-$nodeId"
    serviceType = SERVICE_TYPE
    port = this@NsdDiscovery.port
    setAttribute("loc", locationTag)
    setAttribute("node", nodeId)
    setAttribute("v", PROTOCOL_VERSION)
}

The loc attribute is a short hash of the location id. A device only accepts peers with a matching tag, so two sites on one network would not mix. Two practical notes: discovery needs a Wi-Fi multicast lock on Android or it silently hears nothing, and NSD can die without telling you, so discovery is restarted on a timer.

A content-addressed cache on the LAN

Menus are full of photos and video. Every tablet downloading the same media from the cloud is slow on a good day and impossible on a bad one. So the devices share.

Every media file is named by the SHA-256 of its contents. Resolving a URL is then a short ladder:

  1. Is the blob already on this device?
  2. If not, ask the discovered peers which blobs they hold, and fetch it from the first peer that has it.
  3. Only then go to the cloud.

Because the name is the hash, the device verifies every download as it writes it, from a peer or from the cloud. A peer that sends bytes that do not match is rejected. Requests between peers are signed, and the cache evicts least-recently-used files once it passes its storage budget, except for the set the server has pinned for that location.

The effect in the building is simple: the first tablet to see a new menu photo pays for the download, and the rest get it over the local network. When the internet is down, media that any tablet already holds still loads everywhere.

Printing without a print server

Thermal printers speak ESC/POS, a byte protocol of commands such as initialise, align, bold, feed and cut. Our ticket designer builds those bytes from one ticket description, which also drives the on-screen preview, so what staff see is what prints.

No app talks to a printer directly. Each one posts its job to the launcher on the same tablet, and the launcher routes it: to a USB printer plugged into this tablet if there is one, otherwise to a tablet on the LAN that advertises a printer over mDNS. Jobs carry an id, and a retried job with the same id and the same bytes prints once. A kitchen that prints the same ticket twice has a worse problem than one that prints none.

The same fleet runs the TV menu displays, which stay in sync with each other by computing the current slide from a shared server clock, and the staff time clock.

What we would tell another team

  • Decide per device what "managed" means. Lock task mode for public screens, curation for staff screens.
  • Verify updates as if someone were trying to attack you. Hash, package, version, signer.
  • Make every device useful with the internet down.
  • Let devices find each other. Do not maintain a list.

What we built

The work behind this post: the restaurant tablet fleet, and the Dina Cocina platform it belongs to. The cards below link to both.

Proof

The work behind this post

  • Built

    Restaurant tablet fleet run like IoT devices

    The tablets, TVs and printers that run Dina Cocina are managed as a device fleet: locked-down launchers, silent over-the-air updates, and devices that find each other and share media on the local network.

  • Built

    Dina Cocina restaurant platform

    A working restaurant in Querétaro runs on a POS built in days, then about three months of upgrades into a full platform: live payments, kitchen display, inventory and a tablet fleet.

    to a working POS
    Days
    to a working POS
    native tablet apps
    10
    native tablet apps
    card payments in production
    Live
    card payments in production

Founder-led

Building something like this? A founder will reply personally.

Scope a project