skip to content

An Android app emulates an access card with host-based card emulation: what does requireDeviceUnlock control, and what does user presence leave open?

level: seniorimportance: should knowfreq 22%

answer

  1. a tap alone is not consent
  2. service-level attribute
  3. lock screen, screen off, wallet role
  4. convenience mode skips the check
  5. presence is not proximity

basics

~20 s

Setting android:requireDeviceUnlock to true makes Android require the device to be unlocked before the card-emulation service handles reader commands. It ties a tap to the holder, but does not prove the phone is near the reader.

solid answer

~40 s

In Android's host-based card emulation, the service's XML declares android:requireDeviceUnlock; when true, Android prompts the user to unlock after a reader selects the service's application identifier, then asks them to tap again. Its documented default is that unlock is not required. On Android 10 and higher, with Secure NFC on, card emulators are unavailable while the screen is off and HCE cannot work from the lock screen whatever the attribute says. On Android 15 and higher the default wallet app, when it uses Observe Mode, overrides unlock and screen-off behaviour. Apple's Express Mode, on by default for keys added to Wallet, likewise lets taps proceed without Face ID, Touch ID or a passcode. User presence stops an unattended or stolen phone being used; it does not prove proximity.

code

xml · 10 lines
xml
<host-apdu-service
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:description="@string/servicedesc"
    android:requireDeviceUnlock="true">
  <aid-group
      android:description="@string/aiddescription"
      android:category="other">
    <aid-filter android:name="F0010203040506"/>
  </aid-group>
</host-apdu-service>

go deeper

for a junior

Recall that user presence means the owner unlocked the phone, and that Android's attribute for it is off by default.

for a middle

Explain the Android version differences and Secure NFC, and what Apple's Express Mode does by default.

for a senior

Set a per-door policy for presence versus convenience, test it on each supported OS version, and name what presence does not prove.

for a principal

Own the exception register for express modes, and decide which doors need hardware with timing support rather than a phone-lock policy.

## The question behind the attribute A phone that acts as a card turns a possession credential into one with a screen, a lock and an owner. That allows a control a plastic card cannot offer: **user presence**, meaning the legitimate holder has deliberately unlocked the device before the credential answers. The review question is where a product turns that control on, where it deliberately skips it for convenience, and what each choice leaves open. ## What Android documents In host-based card emulation, an app's service is declared in an XML resource. The attribute that matters here is `android:requireDeviceUnlock` on the `host-apdu-service` element, which specifies that the device must be unlocked before Android invokes the service to handle APDUs. The platform page's own example sets it to `false`, and the page states that by default device unlock is not required and the service is invoked even if the device is locked. ```xml <host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android" android:description="@string/servicedesc" android:requireDeviceUnlock="true"> <aid-group android:description="@string/aiddescription" android:category="other"> <aid-filter android:name="F0010203040506"/> </aid-group> </host-apdu-service> ``` The documented behaviour depends on the Android version: 1. **Android 9 and lower.** The NFC controller and application processor are off when the screen is off, so HCE does not work then. HCE services can run from the lock screen unless `requireDeviceUnlock` is true; if it is, Android prompts the user to unlock when they tap a reader and the reader selects an application identifier that resolves to the service. After unlocking, Android shows a dialog asking the user to tap again, because the device may have moved away from the reader. 2. **Android 10 and higher.** Secure NFC adds a platform setting. While Secure NFC is on, all card emulators, host applications and off-host applications, are unavailable when the screen is off. With it on, HCE services cannot function from the lock screen regardless of `requireDeviceUnlock`; the attribute applies as described above only when Secure NFC is off. 3. **Android 12 and higher.** An app targeting API level 31 or higher can enable NFC payments without the screen on by setting `requireDeviceScreenOn` to `false`. 4. **Android 15 and higher.** A default wallet role exists, and **Observe Mode** lets the device observe polling loops before it responds. If the default wallet app turns on Observe Mode on a device that supports it, that app overrides unlock and screen-off behaviour because it controls when a transaction proceeds; some wallet apps still require unlock if Observe Mode did not detect an identifiable polling loop pattern. ## What Apple documents Apple's platform security guide describes a different model, and the answer should not be generalised across platforms. For payments, a payment can be made only after the Secure Element receives authorization from the Secure Enclave, which verifies the user has confirmed intent and authenticated by biometrics, device passcode or password, or a double-click of the side button on an unlocked Apple Watch. For access keys in Wallet, **Express Mode** is turned on by default when a key is added: keys in Express Mode interact with accepting terminals without Face ID, Touch ID, passcode or a double-click of the Watch's side button. The user can turn it off, and turning it back on requires Face ID, Touch ID or a passcode. Supported iPhones can also complete Express Card transactions on a power reserve when iOS is not running because the battery needs charging; in that state transactions are indicated only by haptic notification. ## What presence buys and what it leaves open | Control | Protects against | Leaves open | |---|---|---| | Unlock required per tap | A lost, stolen or unattended phone being used | A relay while the owner is unlocking and tapping | | Screen on / Secure NFC | Taps while the phone sits in a pocket or bag | Taps by an owner who holds the phone out | | Express Mode or an app's no-unlock setting | Friction at busy doors | Everything above, by design | Two points hold for every row. First, presence is not **proximity**: the person at the door is the person, but the exchange can still be forwarded; distance bounding is the control for that. Second, a setting that the platform lets another party override, such as a wallet app under Observe Mode, is not under your service's control, so the enforceable statement is the platform's documented behaviour, not your attribute alone. ## Decisions and evidence - **Policy per door tier.** Require presence at high-value doors and allow express taps where the cost of a wrong tap is low. Write the tiering down and have the owner sign for the exceptions. - **Test on each supported platform version.** The same attribute behaves differently on Android 9, 10 and higher, 12 and higher, and 15 and higher, and Secure NFC changes the outcome. Record the matrix as evidence. - **Inventory what the service declares.** A review can read the service XML in the app and confirm the attribute and the application identifier group. - **Compensating control.** Where presence is waived, rely on keyed credentials and anomaly review rather than on the phone's lock. ## Interview framing A strong answer names the attribute, its default, the Secure NFC and Observe Mode caveats, and compares it with a platform that offers an express setting, then says what presence does not prove. A weak answer says "the phone is locked so it is secure", or that unlock makes the tap local.

  • A product owner wants taps to work with the screen off. What do you check?
    Check the documented behaviour per Android version: with Secure NFC on, card emulators are unavailable when the screen is off, and on Android 12 and higher an app can set requireDeviceScreenOn to false for payments. Then decide per door tier whether skipping presence is acceptable, and record it as an exception.
  • Why is user presence not the same as the phone being at the door?
    Presence says the owner unlocked and acted. It does not measure the distance between card and reader, so a genuine exchange can still be forwarded. Only a timing-based measure such as distance bounding bounds distance; presence is a compensating control for stolen or unattended phones.

  • Says requireDeviceUnlock is on by default
  • Believes a locked phone cannot be relayed
  • Assumes the attribute binds the Android 15 default wallet app under Observe Mode
  • Generalises Apple's Express Mode behaviour to every phone
  • Treats user presence as proof of proximity