summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nci/jni/NativeNfcManager.cpp19
-rw-r--r--src/com/android/nfc/NfcService.java43
2 files changed, 42 insertions, 20 deletions
diff --git a/nci/jni/NativeNfcManager.cpp b/nci/jni/NativeNfcManager.cpp
index 713886bb..962b67b1 100644
--- a/nci/jni/NativeNfcManager.cpp
+++ b/nci/jni/NativeNfcManager.cpp
@@ -1583,6 +1583,7 @@ static jboolean nfcManager_doDeinitialize(JNIEnv*, jobject) {
sAbortConnlessWait = true;
nativeLlcpConnectionlessSocket_abortWait();
sIsNfaEnabled = false;
+ sRoutingInitialized = false;
sDiscoveryEnabled = false;
sPollingEnabled = false;
sIsDisabling = false;
@@ -2109,18 +2110,28 @@ static void nfcManager_doStartStopPolling(JNIEnv* e, jobject o,
startStopPolling(start);
}
+/*******************************************************************************
+**
+** Function: nfcManager_doSetNfcSecure
+**
+** Description: Set NfcSecure enable/disable.
+** e: JVM environment.
+** o: Java object.
+** enable: Sets true/false to enable/disable NfcSecure
+** It only updates the routing table cache without commit to
+** NFCC.
+**
+** Returns: True always
+**
+*******************************************************************************/
static jboolean nfcManager_doSetNfcSecure(JNIEnv* e, jobject o,
jboolean enable) {
RoutingManager& routingManager = RoutingManager::getInstance();
routingManager.setNfcSecure(enable);
- bool rfEnabled = sRfEnabled;
if (sRoutingInitialized) {
routingManager.disableRoutingToHost();
- if (rfEnabled) startRfDiscovery(false);
routingManager.updateRoutingTable();
routingManager.enableRoutingToHost();
- routingManager.commitRouting();
- if (rfEnabled) startRfDiscovery(true);
}
return true;
}
diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java
index e52cd608..f780fb40 100644
--- a/src/com/android/nfc/NfcService.java
+++ b/src/com/android/nfc/NfcService.java
@@ -781,8 +781,9 @@ public class NfcService implements DeviceHostListener {
return true;
}
Log.i(TAG, "Enabling NFC");
- NfcStatsLog.write(
- NfcStatsLog.NFC_STATE_CHANGED, NfcStatsLog.NFC_STATE_CHANGED__STATE__ON);
+ NfcStatsLog.write(NfcStatsLog.NFC_STATE_CHANGED,
+ mIsSecureNfcEnabled ? NfcStatsLog.NFC_STATE_CHANGED__STATE__ON_LOCKED :
+ NfcStatsLog.NFC_STATE_CHANGED__STATE__ON);
updateState(NfcAdapter.STATE_TURNING_ON);
WatchDogThread watchDog = new WatchDogThread("enableInternal", INIT_WATCHDOG_MS);
@@ -1212,22 +1213,28 @@ public class NfcService implements DeviceHostListener {
}
synchronized (NfcService.this) {
+ if (mIsSecureNfcEnabled == enable) {
+ Log.e(TAG, "setNfcSecure error, can't apply the same state twice!");
+ return false;
+ }
Log.i(TAG, "setting Secure NFC " + enable);
mPrefsEditor.putBoolean(PREF_SECURE_NFC_ON, enable);
mPrefsEditor.apply();
mIsSecureNfcEnabled = enable;
mBackupManager.dataChanged();
mDeviceHost.setNfcSecure(enable);
+ if (mIsHceCapable) {
+ // update HCE/HCEF routing and commitRouting if Nfc is enabled
+ mCardEmulationManager.onSecureNfcToggled();
+ } else if (isNfcEnabled()) {
+ // commit only tech/protocol route without HCE support
+ mDeviceHost.commitRouting();
+ }
}
- if (mIsHceCapable) {
- mCardEmulationManager.onSecureNfcToggled();
- }
- if (enable)
- NfcStatsLog.write(NfcStatsLog.NFC_STATE_CHANGED,
- NfcStatsLog.NFC_STATE_CHANGED__STATE__ON_LOCKED);
- else
- NfcStatsLog.write(
- NfcStatsLog.NFC_STATE_CHANGED, NfcStatsLog.NFC_STATE_CHANGED__STATE__ON);
+
+ NfcStatsLog.write(NfcStatsLog.NFC_STATE_CHANGED,
+ mIsSecureNfcEnabled ? NfcStatsLog.NFC_STATE_CHANGED__STATE__ON_LOCKED :
+ NfcStatsLog.NFC_STATE_CHANGED__STATE__ON);
return true;
}
@@ -2506,17 +2513,18 @@ public class NfcService implements DeviceHostListener {
break;
}
case MSG_COMMIT_ROUTING: {
- boolean commit = false;
synchronized (NfcService.this) {
+ if (mState == NfcAdapter.STATE_OFF
+ || mState == NfcAdapter.STATE_TURNING_OFF) {
+ Log.d(TAG, "Skip commit routing when NFCC is off or turning off");
+ return;
+ }
if (mCurrentDiscoveryParameters.shouldEnableDiscovery()) {
- commit = true;
+ mDeviceHost.commitRouting();
} else {
Log.d(TAG, "Not committing routing because discovery is disabled.");
}
}
- if (commit) {
- mDeviceHost.commitRouting();
- }
break;
}
case MSG_MOCK_NDEF: {
@@ -3223,6 +3231,9 @@ public class NfcService implements DeviceHostListener {
return;
}
+ if (mCardEmulationManager == null) {
+ return;
+ }
if (action.equals(Intent.ACTION_MANAGED_PROFILE_ADDED) ||
action.equals(Intent.ACTION_MANAGED_PROFILE_AVAILABLE) ||
action.equals(Intent.ACTION_MANAGED_PROFILE_REMOVED) ||