summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvan Chu <evanchu@broadcom.com>2012-10-03 14:23:59 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2012-10-03 14:23:59 -0700
commitfc388de82a3d26b31ceb4b7cb9ec147bf69cce21 (patch)
tree3b42b85e5967626108b43d4b6194439583fad193
parentef953e21ec44e2512ae2cae082d98cf8d492ef2a (diff)
parentc7d56f7e340c3c02359cac491e1a02156226975e (diff)
downloadpackages_apps_nfc-fc388de82a3d26b31ceb4b7cb9ec147bf69cce21.zip
packages_apps_nfc-fc388de82a3d26b31ceb4b7cb9ec147bf69cce21.tar.gz
packages_apps_nfc-fc388de82a3d26b31ceb4b7cb9ec147bf69cce21.tar.bz2
am c7d56f7e: Fix locking around power state.
* commit 'c7d56f7e340c3c02359cac491e1a02156226975e': Fix locking around power state.
-rwxr-xr-xnci/jni/NativeNfcManager.cpp1
-rwxr-xr-xnci/jni/PowerSwitch.cpp41
-rwxr-xr-xnci/jni/PowerSwitch.h2
3 files changed, 34 insertions, 10 deletions
diff --git a/nci/jni/NativeNfcManager.cpp b/nci/jni/NativeNfcManager.cpp
index 6625842..babe92a 100755
--- a/nci/jni/NativeNfcManager.cpp
+++ b/nci/jni/NativeNfcManager.cpp
@@ -111,7 +111,6 @@ static bool sIsNfaEnabled = false;
static bool sDiscoveryEnabled = false; //is polling for tag?
static bool sIsDisabling = false;
static bool sRfEnabled = false; // whether RF discovery is enabled
-#define NFA_DM_PWR_STATE_UNKNOWN (-1) // power off sleep state is unkown until is is reported back from NFA...
static int sConnlessSap = 0;
static int sConnlessLinkMiu = 0;
static bool sAbortConnlessWait = false;
diff --git a/nci/jni/PowerSwitch.cpp b/nci/jni/PowerSwitch.cpp
index f3fd316..9d58c74 100755
--- a/nci/jni/PowerSwitch.cpp
+++ b/nci/jni/PowerSwitch.cpp
@@ -46,9 +46,9 @@ const PowerSwitch::PowerActivity PowerSwitch::SE_CONNECTED=0x04;
*******************************************************************************/
PowerSwitch::PowerSwitch ()
: mCurrLevel (UNKNOWN_LEVEL),
- mCurrActivity(0),
mCurrDeviceMgtPowerState (NFA_DM_PWR_STATE_UNKNOWN),
- mDesiredScreenOffPowerState (0)
+ mDesiredScreenOffPowerState (0),
+ mCurrActivity(0)
{
}
@@ -94,8 +94,10 @@ PowerSwitch& PowerSwitch::getInstance ()
void PowerSwitch::initialize (PowerLevel level)
{
static const char fn [] = "PowerSwitch::initialize";
- ALOGD ("%s: level=%s (%u)", fn, powerLevelToString(level), level);
+ mMutex.lock ();
+
+ ALOGD ("%s: level=%s (%u)", fn, powerLevelToString(level), level);
GetNumValue (NAME_SCREEN_OFF_POWER_STATE, &mDesiredScreenOffPowerState, sizeof(mDesiredScreenOffPowerState));
ALOGD ("%s: desired screen-off state=%d", fn, mDesiredScreenOffPowerState);
@@ -115,6 +117,7 @@ void PowerSwitch::initialize (PowerLevel level)
ALOGE ("%s: not handled", fn);
break;
}
+ mMutex.unlock ();
}
@@ -129,7 +132,11 @@ void PowerSwitch::initialize (PowerLevel level)
*******************************************************************************/
PowerSwitch::PowerLevel PowerSwitch::getLevel ()
{
- return mCurrLevel;
+ PowerLevel level = UNKNOWN_LEVEL;
+ mMutex.lock ();
+ level = mCurrLevel;
+ mMutex.unlock ();
+ return level;
}
@@ -146,11 +153,16 @@ PowerSwitch::PowerLevel PowerSwitch::getLevel ()
bool PowerSwitch::setLevel (PowerLevel newLevel)
{
static const char fn [] = "PowerSwitch::setLevel";
- ALOGD ("%s: level=%s (%u)", fn, powerLevelToString(newLevel), newLevel);
bool retval = false;
+ mMutex.lock ();
+
+ ALOGD ("%s: level=%s (%u)", fn, powerLevelToString(newLevel), newLevel);
if (mCurrLevel == newLevel)
- return true;
+ {
+ retval = true;
+ goto TheEnd;
+ }
switch (newLevel)
{
@@ -174,6 +186,9 @@ bool PowerSwitch::setLevel (PowerLevel newLevel)
ALOGE ("%s: not handled", fn);
break;
}
+
+TheEnd:
+ mMutex.unlock ();
return retval;
}
@@ -188,9 +203,14 @@ bool PowerSwitch::setLevel (PowerLevel newLevel)
*******************************************************************************/
bool PowerSwitch::setModeOff (PowerActivity deactivated)
{
+ bool retVal = false;
+
+ mMutex.lock ();
mCurrActivity &= ~deactivated;
+ retVal = mCurrActivity != 0;
ALOGD ("PowerSwitch::setModeOff(deactivated=0x%x) : mCurrActivity=0x%x", deactivated, mCurrActivity);
- return (mCurrActivity != 0);
+ mMutex.unlock ();
+ return retVal;
}
@@ -205,9 +225,14 @@ bool PowerSwitch::setModeOff (PowerActivity deactivated)
*******************************************************************************/
bool PowerSwitch::setModeOn (PowerActivity activated)
{
+ bool retVal = false;
+
+ mMutex.lock ();
mCurrActivity |= activated;
+ retVal = mCurrActivity != 0;
ALOGD ("PowerSwitch::setModeOn(activated=0x%x) : mCurrActivity=0x%x", activated, mCurrActivity);
- return (mCurrActivity != 0);
+ mMutex.unlock ();
+ return retVal;
}
diff --git a/nci/jni/PowerSwitch.h b/nci/jni/PowerSwitch.h
index 28362ba..d311c23 100755
--- a/nci/jni/PowerSwitch.h
+++ b/nci/jni/PowerSwitch.h
@@ -209,13 +209,13 @@ public:
private:
PowerLevel mCurrLevel;
- bool mScreenState;
UINT8 mCurrDeviceMgtPowerState; //device management power state; such as NFA_DM_PWR_STATE_???
int mDesiredScreenOffPowerState; //read from .conf file; 0=power-off-sleep; 1=full power; 2=CE4 power
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;
+ Mutex mMutex;
/*******************************************************************************