summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xnci/jni/NativeNfcManager.cpp44
-rwxr-xr-xnci/jni/NativeSecureElement.cpp16
-rwxr-xr-xnci/jni/PowerSwitch.cpp32
-rwxr-xr-xnci/jni/PowerSwitch.h42
-rw-r--r--nci/jni/RouteDataSet.h2
-rwxr-xr-xnci/src/com/android/nfc/dhimpl/NativeNfcManager.java2
6 files changed, 82 insertions, 56 deletions
diff --git a/nci/jni/NativeNfcManager.cpp b/nci/jni/NativeNfcManager.cpp
index 99ffc77..4ff03f7 100755
--- a/nci/jni/NativeNfcManager.cpp
+++ b/nci/jni/NativeNfcManager.cpp
@@ -267,7 +267,10 @@ static void nfaConnectionCallback (UINT8 connEvent, tNFA_CONN_EVT_DATA* eventDat
break;
case NFA_SELECT_RESULT_EVT: // NFC link/protocol discovery select response
- ALOGD("%s: NFA_SELECT_RESULT_EVT: status = %d, gIsSelectingRfInterface = %d", __FUNCTION__, eventData->status, gIsSelectingRfInterface);
+ ALOGD("%s: NFA_SELECT_RESULT_EVT: status = %d, gIsSelectingRfInterface = %d, sIsDisabling=%d", __FUNCTION__, eventData->status, gIsSelectingRfInterface, sIsDisabling);
+
+ if (sIsDisabling)
+ break;
if (eventData->status != NFA_STATUS_OK)
{
@@ -286,7 +289,10 @@ static void nfaConnectionCallback (UINT8 connEvent, tNFA_CONN_EVT_DATA* eventDat
break;
case NFA_ACTIVATED_EVT: // NFC link/protocol activated
- ALOGD("%s: NFA_ACTIVATED_EVT: gIsSelectingRfInterface=%d", __FUNCTION__, gIsSelectingRfInterface);
+ ALOGD("%s: NFA_ACTIVATED_EVT: gIsSelectingRfInterface=%d, sIsDisabling=%d", __FUNCTION__, gIsSelectingRfInterface, sIsDisabling);
+ if (sIsDisabling)
+ break;
+
NfcTag::getInstance().setActivationState ();
if (gIsSelectingRfInterface)
{
@@ -802,6 +808,8 @@ static void nfcManager_enableDiscovery (JNIEnv* e, jobject o)
// Actually start discovery.
startRfDiscovery (true);
+ PowerSwitch::getInstance ().setModeOn (PowerSwitch::DISCOVERY);
+
ALOGD ("%s: exit", __FUNCTION__);
}
@@ -847,7 +855,8 @@ void nfcManager_disableDiscovery (JNIEnv* e, jobject o)
PeerToPeer::getInstance().enableP2pListening (false);
- if (!sIsSecElemSelected)
+ //if nothing is active after this, then tell the controller to power down
+ if (! PowerSwitch::getInstance ().setModeOff (PowerSwitch::DISCOVERY))
PowerSwitch::getInstance ().setLevel (PowerSwitch::LOW_POWER);
TheEnd:
@@ -1165,6 +1174,7 @@ static void nfcManager_doSelectSecureElement(JNIEnv *e, jobject o)
{
ALOGD ("%s: enter", __FUNCTION__);
bool stat = true;
+
PowerSwitch::getInstance ().setLevel (PowerSwitch::FULL_POWER);
if (sRfEnabled) {
@@ -1186,6 +1196,8 @@ static void nfcManager_doSelectSecureElement(JNIEnv *e, jobject o)
TheEnd:
startRfDiscovery (true);
+ PowerSwitch::getInstance ().setModeOn (PowerSwitch::SE_ROUTING);
+
ALOGD ("%s: exit", __FUNCTION__);
}
@@ -1228,10 +1240,10 @@ static void nfcManager_doDeselectSecureElement(JNIEnv *e, jobject o)
SecureElement::getInstance().deactivate (0xABCDEF);
TheEnd:
- //if power level was changed at the top of this method,
- //then restore to low power
- if (!sDiscoveryEnabled)
+ //if nothing is active after this, then tell the controller to power down
+ if (! PowerSwitch::getInstance ().setModeOff (PowerSwitch::SE_ROUTING))
PowerSwitch::getInstance ().setLevel (PowerSwitch::LOW_POWER);
+
ALOGD ("%s: exit", __FUNCTION__);
}
@@ -1453,23 +1465,6 @@ static void nfcManager_doSetP2pTargetModes (JNIEnv *e, jobject o, jint modes)
//this function is not called by the NFC service nor exposed by public API.
}
-/*******************************************************************************
-**
-** Function nfcManager_doSetScreenState
-**
-** Description Forward the Screen On/Off state to native code for enhanced
-** power saving mode.
-**
-** Returns true
-**
-*******************************************************************************/
-jboolean nfcManager_doSetScreenState(JNIEnv *e, jobject o, jboolean screenState)
-{
- ALOGD ("%s(%d)", __FUNCTION__, screenState);
- PowerSwitch::getInstance().setScreenState(screenState == JNI_TRUE);
- return JNI_TRUE;
-}
-
/*****************************************************************************
**
** JNI functions for android-4.0.1_r1
@@ -1542,9 +1537,6 @@ static JNINativeMethod gMethods[] =
{"doDump", "()Ljava/lang/String;",
(void *)nfcManager_doDump},
-
- {"doSetScreenState", "(Z)Z",
- (void *)nfcManager_doSetScreenState},
};
diff --git a/nci/jni/NativeSecureElement.cpp b/nci/jni/NativeSecureElement.cpp
index 8379162..104d4ea 100755
--- a/nci/jni/NativeSecureElement.cpp
+++ b/nci/jni/NativeSecureElement.cpp
@@ -16,6 +16,7 @@
#include "OverrideLog.h"
#include "SecureElement.h"
#include "JavaClassConstants.h"
+#include "PowerSwitch.h"
namespace android
@@ -44,6 +45,10 @@ static jint nativeNfcSecureElement_doOpenSecureElementConnection (JNIEnv* e, job
bool stat = true;
jint secElemHandle = 0;
+ //tell the controller to power up to get ready for sec elem operations
+ PowerSwitch::getInstance ().setLevel (PowerSwitch::FULL_POWER);
+ PowerSwitch::getInstance ().setModeOn (PowerSwitch::SE_CONNECTED);
+
//if controller is not routing AND there is no pipe connected,
//then turn on the sec elem
if (! SecureElement::getInstance().isBusy())
@@ -59,6 +64,13 @@ static jint nativeNfcSecureElement_doOpenSecureElementConnection (JNIEnv* e, job
SecureElement::getInstance().deactivate (0);
}
+ //if code fails to connect to the secure element, and nothing is active, then
+ //tell the controller to power down
+ if ((!stat) && (! PowerSwitch::getInstance ().setModeOff (PowerSwitch::SE_CONNECTED)))
+ {
+ PowerSwitch::getInstance ().setLevel (PowerSwitch::LOW_POWER);
+ }
+
TheEnd:
ALOGD("%s: exit; return handle=0x%X", __FUNCTION__, secElemHandle);
return secElemHandle;
@@ -89,6 +101,10 @@ static jboolean nativeNfcSecureElement_doDisconnectSecureElementConnection (JNIE
if (! SecureElement::getInstance().isBusy())
SecureElement::getInstance().deactivate (handle);
+ //if nothing is active after this, then tell the controller to power down
+ if (! PowerSwitch::getInstance ().setModeOff (PowerSwitch::SE_CONNECTED))
+ PowerSwitch::getInstance ().setLevel (PowerSwitch::LOW_POWER);
+
ALOGD("%s: exit", __FUNCTION__);
return stat ? JNI_TRUE : JNI_FALSE;
}
diff --git a/nci/jni/PowerSwitch.cpp b/nci/jni/PowerSwitch.cpp
index 6c1df71..f3fd316 100755
--- a/nci/jni/PowerSwitch.cpp
+++ b/nci/jni/PowerSwitch.cpp
@@ -31,6 +31,9 @@ namespace android
PowerSwitch PowerSwitch::sPowerSwitch;
+const PowerSwitch::PowerActivity PowerSwitch::DISCOVERY=0x01;
+const PowerSwitch::PowerActivity PowerSwitch::SE_ROUTING=0x02;
+const PowerSwitch::PowerActivity PowerSwitch::SE_CONNECTED=0x04;
/*******************************************************************************
**
@@ -43,7 +46,7 @@ PowerSwitch PowerSwitch::sPowerSwitch;
*******************************************************************************/
PowerSwitch::PowerSwitch ()
: mCurrLevel (UNKNOWN_LEVEL),
- mScreenState (true),
+ mCurrActivity(0),
mCurrDeviceMgtPowerState (NFA_DM_PWR_STATE_UNKNOWN),
mDesiredScreenOffPowerState (0)
{
@@ -176,35 +179,38 @@ bool PowerSwitch::setLevel (PowerLevel newLevel)
/*******************************************************************************
**
-** Function: isScreenOn
+** Function: setModeOff
**
-** Description: Get the current platform power level.
+** Description: Set a mode to be deactive.
**
-** Returns: true if screen is on (locked or unlocked).
+** Returns: True if any mode is still active.
**
*******************************************************************************/
-bool PowerSwitch::isScreenOn ()
+bool PowerSwitch::setModeOff (PowerActivity deactivated)
{
- return mScreenState;
+ mCurrActivity &= ~deactivated;
+ ALOGD ("PowerSwitch::setModeOff(deactivated=0x%x) : mCurrActivity=0x%x", deactivated, mCurrActivity);
+ return (mCurrActivity != 0);
}
/*******************************************************************************
**
-** Function: setScreenState
+** Function: setModeOn
**
-** Description: Set the Platform's screen state
-** state: true for screen on, flase for screem off
+** Description: Set a mode to be active.
**
-** Returns: True if ok.
+** Returns: True if any mode is active.
**
*******************************************************************************/
-bool PowerSwitch::setScreenState(bool state)
+bool PowerSwitch::setModeOn (PowerActivity activated)
{
- mScreenState = state;
- return true;
+ mCurrActivity |= activated;
+ ALOGD ("PowerSwitch::setModeOn(activated=0x%x) : mCurrActivity=0x%x", activated, mCurrActivity);
+ return (mCurrActivity != 0);
}
+
/*******************************************************************************
**
** Function: setPowerOffSleepState
diff --git a/nci/jni/PowerSwitch.h b/nci/jni/PowerSwitch.h
index 5c939ee..28362ba 100755
--- a/nci/jni/PowerSwitch.h
+++ b/nci/jni/PowerSwitch.h
@@ -45,6 +45,18 @@ public:
/*******************************************************************************
**
+ ** Description: DISCOVERY: Discovery is enabled
+ ** SE_ROUTING: Routing to SE is enabled.
+ ** SE_CONNECTED: SE is connected.
+ **
+ *******************************************************************************/
+ typedef int PowerActivity;
+ static const PowerActivity DISCOVERY;
+ static const PowerActivity SE_ROUTING;
+ static const PowerActivity SE_CONNECTED;
+
+ /*******************************************************************************
+ **
** Description: Platform Power Level, copied from NativeNfcBrcmPowerMode.java.
** UNKNOWN_LEVEL: power level is unknown.
** POWER_OFF: The phone is turned OFF
@@ -123,39 +135,40 @@ public:
/*******************************************************************************
**
- ** Function: isScreenOn
+ ** Function: setLevel
**
- ** Description: Get the current screen state of the platform host.
+ ** Description: Set the controller's power level.
+ ** level: power level.
**
- ** Returns: true if screen if on, (locked or unlocked).
+ ** Returns: True if ok.
**
*******************************************************************************/
- bool isScreenOn ();
+ bool setLevel (PowerLevel level);
/*******************************************************************************
**
- ** Function: setLevel
+ ** Function: setModeOff
**
- ** Description: Set the controller's power level.
- ** level: power level.
+ ** Description: Set a mode to be deactive.
**
- ** Returns: True if ok.
+ ** Returns: True if any mode is still active.
**
*******************************************************************************/
- bool setLevel (PowerLevel level);
+ bool setModeOff (PowerActivity deactivated);
+
/*******************************************************************************
**
- ** Function: setScreenState
+ ** Function: setModeOn
**
- ** Description: Set the Platform's screen state
- ** state: true for screen on, flase for screem off
+ ** Description: Set a mode to be active.
**
- ** Returns: True if ok.
+ ** Returns: True if any mode is active.
**
*******************************************************************************/
- bool setScreenState (bool state);
+ bool setModeOn (PowerActivity activated);
+
/*******************************************************************************
**
@@ -202,6 +215,7 @@ private:
static PowerSwitch sPowerSwitch; //singleton object
static const UINT8 NFA_DM_PWR_STATE_UNKNOWN = -1; //device management power state power state is unknown
SyncEvent mPowerStateEvent;
+ PowerActivity mCurrActivity;
/*******************************************************************************
diff --git a/nci/jni/RouteDataSet.h b/nci/jni/RouteDataSet.h
index d937dec..d2a09b8 100644
--- a/nci/jni/RouteDataSet.h
+++ b/nci/jni/RouteDataSet.h
@@ -152,7 +152,7 @@ private:
** Name: RouteDataSet
**
** Description: Import and export general routing data using a XML file.
-** See /data/bcmnfc/param/route.xml
+** See /data/bcm/param/route.xml
**
*****************************************************************************/
class RouteDataSet
diff --git a/nci/src/com/android/nfc/dhimpl/NativeNfcManager.java b/nci/src/com/android/nfc/dhimpl/NativeNfcManager.java
index 8e53ad1..921e266 100755
--- a/nci/src/com/android/nfc/dhimpl/NativeNfcManager.java
+++ b/nci/src/com/android/nfc/dhimpl/NativeNfcManager.java
@@ -57,8 +57,6 @@ public class NativeNfcManager implements DeviceHost {
mContext = context;
}
- public static native boolean doSetScreenState(boolean state);
-
public native boolean initializeNativeStructure();
private native boolean doDownload();