summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Chaisson <pchaisson@broadcom.com>2012-09-30 22:03:59 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2012-09-30 22:03:59 -0700
commit717dc3ec10d938b81989e2e5f5153b87551468d3 (patch)
tree191321406397bc1cf39cb786113d698f25ba1f6b
parent1d79d84ba427b6cd2bfdd5b8b9a411847ad01d43 (diff)
parent43727fbb7cc3b799a46c3d6ddeff24dd83081449 (diff)
downloadpackages_apps_nfc-717dc3ec10d938b81989e2e5f5153b87551468d3.zip
packages_apps_nfc-717dc3ec10d938b81989e2e5f5153b87551468d3.tar.gz
packages_apps_nfc-717dc3ec10d938b81989e2e5f5153b87551468d3.tar.bz2
am 43727fbb: Power up the NFCC when DH wants to talk to the SE.
* commit '43727fbb7cc3b799a46c3d6ddeff24dd83081449': Power up the NFCC when DH wants to talk to the SE.
-rwxr-xr-xnci/jni/NativeNfcManager.cpp34
-rwxr-xr-xnci/jni/NativeSecureElement.cpp16
-rwxr-xr-xnci/jni/PowerSwitch.cpp32
-rwxr-xr-xnci/jni/PowerSwitch.h42
-rwxr-xr-xnci/src/com/android/nfc/dhimpl/NativeNfcManager.java2
5 files changed, 73 insertions, 53 deletions
diff --git a/nci/jni/NativeNfcManager.cpp b/nci/jni/NativeNfcManager.cpp
index e65e30e..4ff03f7 100755
--- a/nci/jni/NativeNfcManager.cpp
+++ b/nci/jni/NativeNfcManager.cpp
@@ -808,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__);
}
@@ -853,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:
@@ -1171,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) {
@@ -1192,6 +1196,8 @@ static void nfcManager_doSelectSecureElement(JNIEnv *e, jobject o)
TheEnd:
startRfDiscovery (true);
+ PowerSwitch::getInstance ().setModeOn (PowerSwitch::SE_ROUTING);
+
ALOGD ("%s: exit", __FUNCTION__);
}
@@ -1234,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__);
}
@@ -1459,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
@@ -1548,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/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();