When exactly is the NFC service disabled?

I am wondering exactly when the NFC service started and stopped. The source code for Android 4.0.3 seems to indicate that the poll depends on one constant (located in NfcService.java)

/** minimum screen state that enables NFC polling (discovery) */ static final int POLLING_MODE = SCREEN_STATE_ON_UNLOCKED; 

I would interpret this as "the screen lights up, so the nfc service is active." BUT, when the screen is locked, the NFC tag is not recognized, although the screen is lit.

So, I'm curious: is the NFC service already turned off when the lock screen appears, or is it still working but not processing tags?

+4
source share
2 answers

Actually, I do not think the NFC service is disabled. When the screen has a lower value, then the SCREEN_STATE_ON_UNLOCKED device stops requesting NFC tags. You can see this from this code:

  // configure NFC-C polling if (mScreenState >= POLLING_MODE) { if (force || !mNfcPollingEnabled) { Log.d(TAG, "NFC-C ON"); mNfcPollingEnabled = true; mDeviceHost.enableDiscovery(); } } else { if (force || mNfcPollingEnabled) { Log.d(TAG, "NFC-C OFF"); mNfcPollingEnabled = false; mDeviceHost.disableDiscovery(); } } 

But NFC-EE routing is enabled, and the on-screen state is higher than SCREEN_STATE_ON_LOCKED :

  // configure NFC-EE routing if (mScreenState >= SCREEN_STATE_ON_LOCKED && mEeRoutingState == ROUTE_ON_WHEN_SCREEN_ON) { if (force || !mNfceeRouteEnabled) { Log.d(TAG, "NFC-EE ON"); mNfceeRouteEnabled = true; mDeviceHost.doSelectSecureElement(); } } else { if (force || mNfceeRouteEnabled) { Log.d(TAG, "NFC-EE OFF"); mNfceeRouteEnabled = false; mDeviceHost.doDeselectSecureElement(); } } 

The service itself starts and stops in other parts of this class.

+3
source

Source: https://habr.com/ru/post/1414351/


All Articles