summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvan Chu <evanchu@broadcom.com>2012-10-02 13:28:22 -0400
committerMartijn Coenen <maco@google.com>2012-10-03 14:07:53 -0700
commitc7d56f7e340c3c02359cac491e1a02156226975e (patch)
tree63f684e892edc99be5adfd0ea4e46d1db78d57fb
parente897cc402e50a06ccd08b03c8942a2f17e46daef (diff)
downloadpackages_apps_nfc-c7d56f7e340c3c02359cac491e1a02156226975e.zip
packages_apps_nfc-c7d56f7e340c3c02359cac491e1a02156226975e.tar.gz
packages_apps_nfc-c7d56f7e340c3c02359cac491e1a02156226975e.tar.bz2
Fix locking around power state.
Protect state against multi-threaded access. Bug: 7281263 Change-Id: I12735c725b6abf956cb7143f25397653839bc6e4
-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;
/*******************************************************************************