From 0799bcbe2469aa6a88c6cbdf0cdee5b50e1994f0 Mon Sep 17 00:00:00 2001 From: Andres Morales Date: Wed, 18 Dec 2013 13:07:41 -0800 Subject: Refactoring NfcService routing logic. Currently, routing logic contains a lot of nested conditionals and causes unnecessary work to occur, particularly in enabling reader mode. This CL moves this logic to a state object that contains all necessary information to transfer from one routing state to another, leading to fewer calls to the NFCC, eliminating duplicate work, and making the code more readable. Change-Id: I6a8758e61cc0cbb015d618575da35386eadf7d3a --- nxp/jni/com_android_nfc_NativeNfcManager.cpp | 80 +++++++--------------- .../com/android/nfc/dhimpl/NativeNfcManager.java | 39 +++-------- 2 files changed, 34 insertions(+), 85 deletions(-) (limited to 'nxp') diff --git a/nxp/jni/com_android_nfc_NativeNfcManager.cpp b/nxp/jni/com_android_nfc_NativeNfcManager.cpp index 27061c57..489a615b 100644 --- a/nxp/jni/com_android_nfc_NativeNfcManager.cpp +++ b/nxp/jni/com_android_nfc_NativeNfcManager.cpp @@ -1356,7 +1356,7 @@ static void com_android_nfc_NfcManager_disableDiscovery(JNIEnv *e, jobject o) // TODO: use enable_lptd static void com_android_nfc_NfcManager_enableDiscovery(JNIEnv *e, jobject o, jint modes, - jboolean enable_lptd) + jboolean, jboolean reader_mode, jboolean restart) { NFCSTATUS ret; struct nfc_jni_native_data *nat; @@ -1387,17 +1387,30 @@ static void com_android_nfc_NfcManager_enableDiscovery(JNIEnv *e, jobject o, jin nat->registry_info.NFC==TRUE?"P2P":"", nat->registry_info.ISO15693==TRUE?"R":"", ret); + if (modes != 0) + { + if (reader_mode) + { + nat->p2p_initiator_modes = 0; + nat->p2p_target_modes = 0; + nat->discovery_cfg.PollDevInfo.PollCfgInfo.DisableCardEmulation = TRUE; + nat->discovery_cfg.Duration = 200000; /* in ms */ + } + else + { + nat->p2p_initiator_modes = phNfc_eP2P_ALL; + nat->p2p_target_modes = 0x0E; // All passive except 106, active + nat->discovery_cfg.PollDevInfo.PollCfgInfo.DisableCardEmulation = FALSE; + nat->discovery_cfg.Duration = 300000; /* in ms */ + } + nat->discovery_cfg.PollDevInfo.PollCfgInfo.EnableIso14443A = (modes & 0x01) != 0; + nat->discovery_cfg.PollDevInfo.PollCfgInfo.EnableIso14443B = (modes & 0x02) != 0; + nat->discovery_cfg.PollDevInfo.PollCfgInfo.EnableFelica212 = (modes & 0x04) != 0; + nat->discovery_cfg.PollDevInfo.PollCfgInfo.EnableFelica424 = (modes & 0x04) != 0; + nat->discovery_cfg.PollDevInfo.PollCfgInfo.EnableIso15693 = (modes & 0x08) != 0; + } - if (modes != 0) - { - nat->discovery_cfg.PollDevInfo.PollCfgInfo.EnableIso14443A = (modes & 0x01) != 0; - nat->discovery_cfg.PollDevInfo.PollCfgInfo.EnableIso14443B = (modes & 0x02) != 0; - nat->discovery_cfg.PollDevInfo.PollCfgInfo.EnableFelica212 = (modes & 0x04) != 0; - nat->discovery_cfg.PollDevInfo.PollCfgInfo.EnableFelica424 = (modes & 0x04) != 0; - nat->discovery_cfg.PollDevInfo.PollCfgInfo.EnableIso15693 = (modes & 0x08) != 0; - } - - nfc_jni_start_discovery_locked(nat, false); + nfc_jni_start_discovery_locked(nat, restart); clean_and_return: CONCURRENCY_UNLOCK(); } @@ -2196,43 +2209,6 @@ static void com_android_nfc_NfcManager_doAbort(JNIEnv*, jobject) emergency_recovery(NULL); } -static void com_android_nfc_NfcManager_doEnableReaderMode(JNIEnv *e, jobject o, - jint modes) -{ - struct nfc_jni_native_data *nat = NULL; - nat = nfc_jni_get_nat(e, o); - CONCURRENCY_LOCK(); - nat->p2p_initiator_modes = 0; - nat->p2p_target_modes = 0; - nat->discovery_cfg.PollDevInfo.PollCfgInfo.DisableCardEmulation = TRUE; - nat->discovery_cfg.Duration = 200000; /* in ms */ - nat->discovery_cfg.PollDevInfo.PollCfgInfo.EnableIso14443A = (modes & 0x01) != 0; - nat->discovery_cfg.PollDevInfo.PollCfgInfo.EnableIso14443B = (modes & 0x02) != 0; - nat->discovery_cfg.PollDevInfo.PollCfgInfo.EnableFelica212 = (modes & 0x04) != 0; - nat->discovery_cfg.PollDevInfo.PollCfgInfo.EnableFelica424 = (modes & 0x04) != 0; - nat->discovery_cfg.PollDevInfo.PollCfgInfo.EnableIso15693 = (modes & 0x08) != 0; - nfc_jni_start_discovery_locked(nat, FALSE); - CONCURRENCY_UNLOCK(); -} - -static void com_android_nfc_NfcManager_doDisableReaderMode(JNIEnv *e, jobject o) -{ - struct nfc_jni_native_data *nat = NULL; - nat = nfc_jni_get_nat(e, o); - CONCURRENCY_LOCK(); - nat->p2p_initiator_modes = phNfc_eP2P_ALL; - nat->p2p_target_modes = 0x0E; // All passive except 106, active - nat->discovery_cfg.PollDevInfo.PollCfgInfo.DisableCardEmulation = FALSE; - nat->discovery_cfg.Duration = 300000; /* in ms */ - nat->discovery_cfg.PollDevInfo.PollCfgInfo.EnableIso14443A = TRUE; - nat->discovery_cfg.PollDevInfo.PollCfgInfo.EnableIso14443B = TRUE; - nat->discovery_cfg.PollDevInfo.PollCfgInfo.EnableFelica212 = TRUE; - nat->discovery_cfg.PollDevInfo.PollCfgInfo.EnableFelica424 = TRUE; - nat->discovery_cfg.PollDevInfo.PollCfgInfo.EnableIso15693 = TRUE; - nfc_jni_start_discovery_locked(nat, FALSE); - CONCURRENCY_UNLOCK(); -} - static void com_android_nfc_NfcManager_doSetP2pInitiatorModes(JNIEnv *e, jobject o, jint modes) { @@ -2383,7 +2359,7 @@ static JNINativeMethod gMethods[] = {"doDeinitialize", "()Z", (void *)com_android_nfc_NfcManager_deinitialize}, - {"enableDiscovery", "(IZ)V", + {"doEnableDiscovery", "(IZZZ)V", (void *)com_android_nfc_NfcManager_enableDiscovery}, {"doCheckLlcp", "()Z", @@ -2425,12 +2401,6 @@ static JNINativeMethod gMethods[] = {"doSetP2pTargetModes","(I)V", (void *)com_android_nfc_NfcManager_doSetP2pTargetModes}, - {"doEnableReaderMode","(I)V", - (void *)com_android_nfc_NfcManager_doEnableReaderMode}, - - {"doDisableReaderMode","()V", - (void *)com_android_nfc_NfcManager_doDisableReaderMode}, - {"doDump", "()Ljava/lang/String;", (void *)com_android_nfc_NfcManager_doDump}, }; diff --git a/nxp/src/com/android/nfc/dhimpl/NativeNfcManager.java b/nxp/src/com/android/nfc/dhimpl/NativeNfcManager.java index a69e3b53..9d2ebeae 100755 --- a/nxp/src/com/android/nfc/dhimpl/NativeNfcManager.java +++ b/nxp/src/com/android/nfc/dhimpl/NativeNfcManager.java @@ -27,6 +27,7 @@ import android.nfc.ErrorCodes; import android.nfc.tech.Ndef; import android.nfc.tech.TagTechnology; import android.util.Log; +import com.android.nfc.NfcDiscoveryParameters; import java.io.File; @@ -151,23 +152,18 @@ public class NativeNfcManager implements DeviceHost { return false; } + private native void doEnableDiscovery(int techMask, + boolean enableLowPowerPolling, + boolean enableReaderMode, + boolean restart); @Override - public native void enableDiscovery(int techMask, boolean enableLowPowerDiscovery); - - @Override - public native void disableDiscovery(); - - @Override - public void enableRoutingToHost() - { - + public void enableDiscovery(NfcDiscoveryParameters params, boolean restart) { + doEnableDiscovery(params.getTechMask(), params.shouldEnableLowPowerDiscovery(), + params.shouldEnableReaderMode(), restart); } @Override - public void disableRoutingToHost() - { - - } + public native void disableDiscovery(); private native NativeLlcpConnectionlessSocket doCreateLlcpConnectionlessSocket(int nSap, String sn); @@ -315,18 +311,6 @@ public class NativeNfcManager implements DeviceHost { doSetP2pTargetModes(modes); } - private native void doEnableReaderMode(int technologies); - public boolean enableReaderMode(int technologies) { - doEnableReaderMode(technologies); - return true; - } - - private native void doDisableReaderMode(); - public boolean disableReaderMode() { - doDisableReaderMode(); - return true; - } - @Override public boolean enableScreenOffSuspend() { // Snooze mode not supported on NXP silicon @@ -347,11 +331,6 @@ public class NativeNfcManager implements DeviceHost { return false; } - @Override - public boolean enablePN544Quirks() { - return true; - } - @Override public int getDefaultLlcpMiu() { return DEFAULT_LLCP_MIU; -- cgit v1.2.3