summaryrefslogtreecommitdiffstats
path: root/nci/jni/SecureElement.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'nci/jni/SecureElement.cpp')
-rwxr-xr-xnci/jni/SecureElement.cpp119
1 files changed, 71 insertions, 48 deletions
diff --git a/nci/jni/SecureElement.cpp b/nci/jni/SecureElement.cpp
index a4c4d57e..101bd38c 100755
--- a/nci/jni/SecureElement.cpp
+++ b/nci/jni/SecureElement.cpp
@@ -20,6 +20,7 @@
*/
#include <semaphore.h>
#include <errno.h>
+#include <ScopedLocalRef.h>
#include "OverrideLog.h"
#include "SecureElement.h"
#include "config.h"
@@ -40,6 +41,7 @@ bool gUseStaticPipe = false; // if true, use gGatePipe as static pipe id. if
namespace android
{
extern void startRfDiscovery (bool isStart);
+ extern void setUiccIdleTimeout (bool enable);
}
//////////////////////////////////////////////
@@ -149,7 +151,6 @@ bool SecureElement::initialize (nfc_jni_native_data* native)
{
static const char fn [] = "SecureElement::initialize";
tNFA_STATUS nfaStat;
- UINT8 xx = 0, yy = 0;
unsigned long num = 0;
ALOGD ("%s: enter", fn);
@@ -177,6 +178,8 @@ bool SecureElement::initialize (nfc_jni_native_data* native)
mbNewEE = true;
mNewPipeId = 0;
mNewSourceGate = 0;
+ mRfFieldIsOn = false;
+ mActivatedInListenMode = false;
mCurrentRouteSelection = NoRoute;
memset (mEeInfo, 0, sizeof(mEeInfo));
memset (&mUiccInfo, 0, sizeof(mUiccInfo));
@@ -201,7 +204,7 @@ bool SecureElement::initialize (nfc_jni_native_data* native)
}
// If the controller has an HCI Network, register for that
- for (xx = 0; xx < mActualNumEe; xx++)
+ for (size_t xx = 0; xx < mActualNumEe; xx++)
{
if ((mEeInfo[xx].num_interface > 0) && (mEeInfo[xx].ee_interface[0] == NCI_NFCEE_INTERFACE_HCI_ACCESS) )
{
@@ -245,7 +248,6 @@ void SecureElement::finalize ()
{
static const char fn [] = "SecureElement::finalize";
ALOGD ("%s: enter", fn);
- tNFA_STATUS nfaStat = NFA_STATUS_FAILED;
NFA_EeDeregister (nfaEeCallback);
@@ -281,7 +283,6 @@ bool SecureElement::getEeInfo()
static const char fn [] = "SecureElement::getEeInfo";
ALOGD ("%s: enter; mbNewEE=%d, mActualNumEe=%d", fn, mbNewEE, mActualNumEe);
tNFA_STATUS nfaStat = NFA_STATUS_FAILED;
- UINT8 xx = 0, yy = 0;
// If mbNewEE is true then there is new EE info.
if (mbNewEE)
@@ -309,7 +310,7 @@ bool SecureElement::getEeInfo()
fn, xx, mEeInfo[xx].ee_handle, eeStatusToString(mEeInfo[xx].ee_status), mEeInfo[xx].num_interface,
mEeInfo[xx].ee_interface[0], mEeInfo[xx].ee_interface[1], mEeInfo[xx].num_tlvs);
- for (yy = 0; yy < mEeInfo[xx].num_tlvs; yy++)
+ for (size_t yy = 0; yy < mEeInfo[xx].num_tlvs; yy++)
{
ALOGD ("%s: EE[%u] TLV[%u] Tag: 0x%02x Len: %u Values[]: 0x%02x 0x%02x 0x%02x ...",
fn, xx, yy, mEeInfo[xx].ee_tlv[yy].tag, mEeInfo[xx].ee_tlv[yy].len, mEeInfo[xx].ee_tlv[yy].info[0],
@@ -404,7 +405,6 @@ jintArray SecureElement::getListOfEeHandles (JNIEnv* e)
ALOGD ("%s: enter", fn);
if (mNumEePresent == 0)
return NULL;
- jintArray list = NULL;
if (!mIsInit)
{
@@ -416,7 +416,7 @@ jintArray SecureElement::getListOfEeHandles (JNIEnv* e)
if (! getEeInfo())
return (NULL);
- list = e->NewIntArray (mNumEePresent); //allocate array
+ jintArray list = e->NewIntArray (mNumEePresent); //allocate array
jint jj = 0;
int cnt = 0;
for (int ii = 0; ii < mActualNumEe && cnt < mNumEePresent; ii++)
@@ -430,7 +430,6 @@ jintArray SecureElement::getListOfEeHandles (JNIEnv* e)
jj = mEeInfo[ii].ee_handle & ~NFA_HANDLE_GROUP_EE;
e->SetIntArrayRegion (list, cnt++, 1, &jj);
}
- //e->DeleteLocalRef (list);
ALOGD("%s: exit", fn);
return list;
@@ -537,8 +536,6 @@ bool SecureElement::activate (jint seID)
bool SecureElement::deactivate (jint seID)
{
static const char fn [] = "SecureElement::deactivate";
- tNFA_STATUS nfaStat = NFA_STATUS_FAILED;
- int numDeactivatedEe = 0;
bool retval = false;
ALOGD ("%s: enter; seID=0x%X, mActiveEeHandle=0x%X", fn, seID, mActiveEeHandle);
@@ -588,41 +585,37 @@ void SecureElement::notifyTransactionListenersOfAid (const UINT8* aidBuffer, UIN
static const char fn [] = "SecureElement::notifyTransactionListenersOfAid";
ALOGD ("%s: enter; aid len=%u", fn, aidBufferLen);
- if (aidBufferLen == 0)
- return;
+ if (aidBufferLen == 0) {
+ return;
+ }
- jobject tlvJavaArray = NULL;
JNIEnv* e = NULL;
- UINT8* tlv = 0;
- const UINT16 tlvMaxLen = aidBufferLen + 10;
- UINT16 tlvActualLen = 0;
- bool stat = false;
-
- mNativeData->vm->AttachCurrentThread (&e, NULL);
+ ScopedAttach attach(mNativeData->vm, &e);
if (e == NULL)
{
ALOGE ("%s: jni env is null", fn);
return;
}
- tlv = new UINT8 [tlvMaxLen];
+ const UINT16 tlvMaxLen = aidBufferLen + 10;
+ UINT8* tlv = new UINT8 [tlvMaxLen];
if (tlv == NULL)
{
ALOGE ("%s: fail allocate tlv", fn);
- goto TheEnd;
+ return;
}
memcpy (tlv, aidBuffer, aidBufferLen);
- tlvActualLen = aidBufferLen;
+ UINT16 tlvActualLen = aidBufferLen;
- tlvJavaArray = e->NewByteArray (tlvActualLen);
- if (tlvJavaArray == NULL)
+ ScopedLocalRef<jobject> tlvJavaArray(e, e->NewByteArray(tlvActualLen));
+ if (tlvJavaArray.get() == NULL)
{
ALOGE ("%s: fail allocate array", fn);
goto TheEnd;
}
- e->SetByteArrayRegion ((jbyteArray)tlvJavaArray, 0, tlvActualLen, (jbyte *)tlv);
+ e->SetByteArrayRegion ((jbyteArray)tlvJavaArray.get(), 0, tlvActualLen, (jbyte *)tlv);
if (e->ExceptionCheck())
{
e->ExceptionClear();
@@ -630,7 +623,7 @@ void SecureElement::notifyTransactionListenersOfAid (const UINT8* aidBuffer, UIN
goto TheEnd;
}
- e->CallVoidMethod (mNativeData->manager, android::gCachedNfcManagerNotifyTransactionListeners, tlvJavaArray);
+ e->CallVoidMethod (mNativeData->manager, android::gCachedNfcManagerNotifyTransactionListeners, tlvJavaArray.get());
if (e->ExceptionCheck())
{
e->ExceptionClear();
@@ -639,9 +632,6 @@ void SecureElement::notifyTransactionListenersOfAid (const UINT8* aidBuffer, UIN
}
TheEnd:
- if (tlvJavaArray)
- e->DeleteLocalRef (tlvJavaArray);
- mNativeData->vm->DetachCurrentThread ();
delete [] tlv;
ALOGD ("%s: exit", fn);
}
@@ -698,6 +688,9 @@ bool SecureElement::connectEE ()
// Disable RF discovery completely while the DH is connected
android::startRfDiscovery(false);
+ // Disable UICC idle timeout while the DH is connected
+ android::setUiccIdleTimeout (false);
+
mNewSourceGate = 0;
if (gGatePipe == -1)
@@ -878,12 +871,17 @@ bool SecureElement::disconnectEE (jint seID)
else
ALOGE ("%s: fail dealloc gate; error=0x%X", fn, nfaStat);
}
+
mIsPiping = false;
+
+ // Re-enable UICC low-power mode
+ android::setUiccIdleTimeout (true);
// Re-enable RF discovery
// Note that it only effactuates the current configuration,
// so if polling/listening were configured OFF (forex because
// the screen was off), they will stay OFF with this call.
android::startRfDiscovery(true);
+
return true;
}
@@ -1007,11 +1005,11 @@ TheEnd:
*******************************************************************************/
void SecureElement::notifyListenModeState (bool isActivated) {
static const char fn [] = "SecureElement::notifyListenMode";
- JNIEnv *e = NULL;
ALOGD ("%s: enter; listen mode active=%u", fn, isActivated);
- mNativeData->vm->AttachCurrentThread (&e, NULL);
+ JNIEnv* e = NULL;
+ ScopedAttach attach(mNativeData->vm, &e);
if (e == NULL)
{
ALOGE ("%s: jni env is null", fn);
@@ -1032,7 +1030,6 @@ void SecureElement::notifyListenModeState (bool isActivated) {
ALOGE ("%s: fail notify", fn);
}
- mNativeData->vm->DetachCurrentThread ();
ALOGD ("%s: exit", fn);
}
@@ -1049,11 +1046,10 @@ void SecureElement::notifyListenModeState (bool isActivated) {
void SecureElement::notifyRfFieldEvent (bool isActive)
{
static const char fn [] = "SecureElement::notifyRfFieldEvent";
- JNIEnv *e = NULL;
-
ALOGD ("%s: enter; is active=%u", fn, isActive);
- mNativeData->vm->AttachCurrentThread (&e, NULL);
+ JNIEnv* e = NULL;
+ ScopedAttach attach(mNativeData->vm, &e);
if (e == NULL)
{
ALOGE ("%s: jni env is null", fn);
@@ -1081,7 +1077,33 @@ void SecureElement::notifyRfFieldEvent (bool isActive)
e->ExceptionClear();
ALOGE ("%s: fail notify", fn);
}
- mNativeData->vm->DetachCurrentThread ();
+ ALOGD ("%s: exit", fn);
+}
+
+/*******************************************************************************
+**
+** Function: resetRfFieldStatus
+**
+** Description: Resets the field status.
+** isActive: Whether any secure element is activated.
+**
+** Returns: None
+**
+*******************************************************************************/
+void SecureElement::resetRfFieldStatus ()
+{
+ static const char fn [] = "SecureElement::resetRfFieldStatus`";
+ ALOGD ("%s: enter;");
+
+ mMutex.lock();
+ mRfFieldIsOn = false;
+ int ret = clock_gettime (CLOCK_MONOTONIC, &mLastRfFieldToggle);
+ if (ret == -1) {
+ ALOGE("%s: clock_gettime failed", fn);
+ // There is no good choice here...
+ }
+ mMutex.unlock();
+
ALOGD ("%s: exit", fn);
}
@@ -1134,9 +1156,9 @@ bool SecureElement::getUiccId (tNFA_HANDLE eeHandle, jbyteArray& uid)
static const char fn [] = "SecureElement::getUiccId";
ALOGD ("%s: ee h=0x%X", fn, eeHandle);
bool retval = false;
- JNIEnv* e = NULL;
- mNativeData->vm->AttachCurrentThread (&e, NULL);
+ JNIEnv* e = NULL;
+ ScopedAttach attach(mNativeData->vm, &e);
if (e == NULL)
{
ALOGE ("%s: jni env is null", fn);
@@ -1146,8 +1168,9 @@ bool SecureElement::getUiccId (tNFA_HANDLE eeHandle, jbyteArray& uid)
findUiccByHandle (eeHandle);
//cannot get UID from the stack; nothing to do
-TheEnd:
- mNativeData->vm->DetachCurrentThread ();
+ // TODO: uid is unused --- bug?
+
+ // TODO: retval is always false --- bug?
ALOGD ("%s: exit; ret=%u", fn, retval);
return retval;
}
@@ -1169,10 +1192,9 @@ bool SecureElement::getTechnologyList (tNFA_HANDLE eeHandle, jintArray& techList
static const char fn [] = "SecureElement::getTechnologyList";
ALOGD ("%s: ee h=0x%X", fn, eeHandle);
bool retval = false;
- JNIEnv* e = NULL;
- jint theList = 0;
- mNativeData->vm->AttachCurrentThread (&e, NULL);
+ JNIEnv* e = NULL;
+ ScopedAttach attach(mNativeData->vm, &e);
if (e == NULL)
{
ALOGE ("%s: jni env is null", fn);
@@ -1181,6 +1203,8 @@ bool SecureElement::getTechnologyList (tNFA_HANDLE eeHandle, jintArray& techList
tNFA_EE_DISCOVER_INFO *pUICC = findUiccByHandle (eeHandle);
+ // TODO: theList is written but not set --- bug?
+ jint theList = 0;
if (pUICC->la_protocol != 0)
theList = TARGET_TYPE_ISO14443_3A;
else if (pUICC->lb_protocol != 0)
@@ -1192,8 +1216,9 @@ bool SecureElement::getTechnologyList (tNFA_HANDLE eeHandle, jintArray& techList
else
theList = TARGET_TYPE_UNKNOWN;
-TheEnd:
- mNativeData->vm->DetachCurrentThread ();
+ // TODO: techList is neither read nor written --- bug?
+
+ // TODO: retval is always false --- bug?
ALOGD ("%s: exit; ret=%u", fn, retval);
return retval;
}
@@ -1213,7 +1238,6 @@ void SecureElement::adjustRoutes (RouteSelection selection)
{
static const char fn [] = "SecureElement::adjustRoutes";
ALOGD ("%s: enter; selection=%u", fn, selection);
- tNFA_STATUS nfaStat = NFA_STATUS_FAILED;
RouteDataSet::Database* db = mRouteDataSet.getDatabase (RouteDataSet::DefaultRouteDatabase);
if (selection == SecElemRoute)
@@ -2035,7 +2059,7 @@ const char* SecureElement::eeStatusToString (UINT8 status)
** Returns: None
**
*******************************************************************************/
-void SecureElement::connectionEventHandler (UINT8 event, tNFA_CONN_EVT_DATA* eventData)
+void SecureElement::connectionEventHandler (UINT8 event, tNFA_CONN_EVT_DATA* /*eventData*/)
{
switch (event)
{
@@ -2176,4 +2200,3 @@ bool SecureElement::isBusy ()
ALOGD ("SecureElement::isBusy: %u", retval);
return retval;
}
-