diff options
author | Martijn Coenen <maco@google.com> | 2011-07-20 16:05:29 +0200 |
---|---|---|
committer | Martijn Coenen <maco@google.com> | 2011-07-20 20:00:36 +0200 |
commit | 358d8b6ad611aba11e69a3b1dd9d132dbc9a7605 (patch) | |
tree | 2d5de796184da30ca93bdff30135a61decf14f23 | |
parent | a39fb7629fdaafbf728cc484facac6d64d2f2170 (diff) | |
download | packages_apps_nfc-358d8b6ad611aba11e69a3b1dd9d132dbc9a7605.zip packages_apps_nfc-358d8b6ad611aba11e69a3b1dd9d132dbc9a7605.tar.gz packages_apps_nfc-358d8b6ad611aba11e69a3b1dd9d132dbc9a7605.tar.bz2 |
Support for getTimeout() (NFC service).
Bug: 4492175
Change-Id: I289e40d1527e7b570e8fd46f9968094b92a31902
-rw-r--r-- | jni/com_android_nfc_NativeNfcManager.cpp | 68 | ||||
-rw-r--r-- | src/com/android/nfc/DeviceHost.java | 2 | ||||
-rwxr-xr-x | src/com/android/nfc/NfcService.java | 7 | ||||
-rwxr-xr-x | src/com/android/nfc/nxp/NativeNfcManager.java | 5 |
4 files changed, 71 insertions, 11 deletions
diff --git a/jni/com_android_nfc_NativeNfcManager.cpp b/jni/com_android_nfc_NativeNfcManager.cpp index 904d3fa..de1627f 100644 --- a/jni/com_android_nfc_NativeNfcManager.cpp +++ b/jni/com_android_nfc_NativeNfcManager.cpp @@ -1563,26 +1563,25 @@ static unsigned int log2(int value) { return ret; } +// The Iso/Mifare Xchg timeout in PN544 is a non-linear function over X +// spanning 0 - 4.9s: timeout in seconds = (256 * 16 / 13560000) * 2 ^ X +// +// We keep the constant part of the formula in a static; note the factor +// 1000 off, which is due to the fact that the formula calculates seconds, +// but this method gets milliseconds as an argument. +static double nxp_nfc_timeout_factor = (256 * 16) / 13560.0; + static int calcTimeout(int timeout_in_ms) { - // The Iso/Mifare Xchg timeout in PN544 is a non-linear function over X - // spanning 0 - 4.9s: timeout in seconds = (256 * 16 / 13560000) * 2 ^ X - // - // We keep the constant part of the formula in a static; note the factor - // 1000 off, which is due to the fact that the formula calculates seconds, - // but this method gets milliseconds as an argument. - static double factor = (256 * 16) / 13560.0; // timeout = (256 * 16 / 13560000) * 2 ^ X // First find the first X for which timeout > requested timeout - return (log2(ceil(((double) timeout_in_ms) / factor))); + return (log2(ceil(((double) timeout_in_ms) / nxp_nfc_timeout_factor))); } static void setIsoDepTimeout(jint timeout) { - static double factor = (256 * 16) / 13560.0; - if (timeout <= 4900) { int value = calcTimeout(timeout); // Then re-compute the actual timeout based on X - double actual_timeout = factor * (1 << value); + double actual_timeout = nxp_nfc_timeout_factor * (1 << value); // Set the sw watchdog a bit longer (The PN544 timeout is very accurate, // but it will take some time to get back through the sw layers. // 500 ms should be enough). @@ -1646,6 +1645,50 @@ static bool com_android_nfc_NfcManager_doSetTimeout( JNIEnv *e, jobject o, return success; } +static jint com_android_nfc_NfcManager_doGetTimeout( JNIEnv *e, jobject o, + jint tech) { + int timeout = -1; + CONCURRENCY_LOCK(); + switch (tech) { + case TARGET_TYPE_MIFARE_CLASSIC: + case TARGET_TYPE_MIFARE_UL: + // Intentional fall-through, Mifare UL, Classic + // transceive just uses raw 3A frames + case TARGET_TYPE_ISO14443_3A: + timeout = phLibNfc_GetMifareRawTimeout(); + if (timeout == 0) { + timeout = phLibNfc_GetHciTimeout(); + } else { + // Timeout returned from libnfc needs conversion to ms + timeout = (nxp_nfc_timeout_factor * (1 << timeout)); + } + break; + case TARGET_TYPE_ISO14443_4: + timeout = phLibNfc_GetIsoXchgTimeout() & 0x0F; // lower 4 bits only + if (timeout == 0) { + timeout = phLibNfc_GetHciTimeout(); + } else { + // Timeout returned from libnfc needs conversion to ms + timeout = (nxp_nfc_timeout_factor * (1 << timeout)); + } + break; + case TARGET_TYPE_FELICA: + timeout = phLibNfc_GetFelicaTimeout(); + if (timeout == 0) { + timeout = phLibNfc_GetHciTimeout(); + } else { + // Felica timeout already in ms + } + break; + default: + LOGW("doGetTimeout: Timeout not supported for tech %d", tech); + break; + } + CONCURRENCY_UNLOCK(); + return timeout; +} + + static jboolean com_android_nfc_NfcManager_init_native_struc(JNIEnv *e, jobject o) { NFCSTATUS status; @@ -2442,6 +2485,9 @@ static JNINativeMethod gMethods[] = {"doSetTimeout", "(II)Z", (void *)com_android_nfc_NfcManager_doSetTimeout}, + {"doGetTimeout", "(I)I", + (void *)com_android_nfc_NfcManager_doGetTimeout}, + {"doResetTimeouts", "()V", (void *)com_android_nfc_NfcManager_doResetTimeouts}, diff --git a/src/com/android/nfc/DeviceHost.java b/src/com/android/nfc/DeviceHost.java index 4456d98..9693446 100644 --- a/src/com/android/nfc/DeviceHost.java +++ b/src/com/android/nfc/DeviceHost.java @@ -151,4 +151,6 @@ public interface DeviceHost { public void resetTimeouts(); public boolean setTimeout(int technology, int timeout); + + public int getTimeout(int technology); } diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java index 31e9a60..10f4115 100755 --- a/src/com/android/nfc/NfcService.java +++ b/src/com/android/nfc/NfcService.java @@ -1407,6 +1407,13 @@ public class NfcService extends Application implements DeviceHostListener { } @Override + public int getTimeout(int tech) throws RemoteException { + mContext.enforceCallingOrSelfPermission(NFC_PERM, NFC_PERM_ERROR); + + return mDeviceHost.getTimeout(tech); + } + + @Override public void resetTimeouts() throws RemoteException { mContext.enforceCallingOrSelfPermission(NFC_PERM, NFC_PERM_ERROR); diff --git a/src/com/android/nfc/nxp/NativeNfcManager.java b/src/com/android/nfc/nxp/NativeNfcManager.java index 59a1ac1..8a59370 100755 --- a/src/com/android/nfc/nxp/NativeNfcManager.java +++ b/src/com/android/nfc/nxp/NativeNfcManager.java @@ -100,6 +100,11 @@ public class NativeNfcManager implements DeviceHost { return doSetTimeout(tech, timeout); } + private native int doGetTimeout(int tech); + @Override + public int getTimeout(int tech) { + return doGetTimeout(tech); + } /** * Notifies Ndef Message (TODO: rename into notifyTargetDiscovered) |