Вопрос

I am wondering when exactly the NFC Service is started and stopped. The source code for android 4.0.3 seems to state that the polling is dependent on a single 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 light is on, therefore the nfc service is active". BUT when the screen is locked, a NFC Tag wont be recognized, altough the screen is lit.

So I am curious: Is the NFC Service already deactivated when the lock screen appears, or is it still running but not processing the Tags?

Это было полезно?

Решение

Actually, I do not think that NFC Service is deactivated. When the screen has lower value then SCREEN_STATE_ON_UNLOCKED a device stops to ask NFC tags around. 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 util screen state is higher then 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 is started and stopped in other parts of this class.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top