Merge "fm: wait for enable event to complete" into fm.lnx.2.1-dev
diff --git a/fmapp2/src/com/caf/fmradio/FMRadioService.java b/fmapp2/src/com/caf/fmradio/FMRadioService.java
index 7c89709..2d157c6 100644
--- a/fmapp2/src/com/caf/fmradio/FMRadioService.java
+++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java
@@ -224,6 +224,7 @@
private static Object mNotchFilterLock = new Object();
private boolean mFmA2dpDisabled;
+ private boolean mEventReceived = false;
public FMRadioService() {
}
@@ -2124,6 +2125,27 @@
misAnalogPathEnabled = analogMode;
return true;
}
+ private boolean waitForEvent() {
+ boolean status = false;
+
+ synchronized (mEventWaitLock) {
+ Log.d(LOGTAG, "waiting for event");
+ try {
+ if (mEventReceived == false)
+ mEventWaitLock.wait(RADIO_TIMEOUT);
+ if (mEventReceived == true)
+ status = true;
+ } catch (IllegalMonitorStateException e) {
+ Log.e(LOGTAG, "Exception caught while waiting for event");
+ e.printStackTrace();
+ } catch (InterruptedException ex) {
+ Log.e(LOGTAG, "Exception caught while waiting for event");
+ ex.printStackTrace();
+ }
+ }
+ return status;
+ }
+
/*
* Turn ON FM: Powers up FM hardware, and initializes the FM module
* .
@@ -2165,7 +2187,12 @@
Log.d(LOGTAG, "fmOn: RdsStd :"+ config.getRdsStd());
Log.d(LOGTAG, "fmOn: LowerLimit :"+ config.getLowerLimit());
Log.d(LOGTAG, "fmOn: UpperLimit :"+ config.getUpperLimit());
+ mEventReceived = false;
bStatus = mReceiver.enable(FmSharedPreferences.getFMConfiguration(), this);
+
+ if (mReceiver.isCherokeeChip()) {
+ bStatus = waitForEvent();
+ }
if (isSpeakerEnabled()) {
setAudioPath(false);
} else {
@@ -2325,21 +2352,6 @@
if (mReceiver != null)
{
bStatus = mReceiver.disable(this);
- if (bStatus &&
- (mReceiver.getFMState() == mReceiver.subPwrLevel_FMTurning_Off)) {
- synchronized (mEventWaitLock) {
- Log.d(LOGTAG, "waiting for disable event");
- try {
- mEventWaitLock.wait(RADIO_TIMEOUT);
- } catch (IllegalMonitorStateException e) {
- Log.e(LOGTAG, "Exception caught while waiting for event");
- e.printStackTrace();
- } catch (InterruptedException ex) {
- Log.e(LOGTAG, "Exception caught while waiting for event");
- ex.printStackTrace();
- }
- }
- }
mReceiver = null;
}
fmOperationsOff();
@@ -2362,21 +2374,11 @@
// This will disable the FM radio device
if (mReceiver != null)
{
+ mEventReceived = false;
bStatus = mReceiver.disable(this);
if (bStatus &&
(mReceiver.getFMState() == mReceiver.subPwrLevel_FMTurning_Off)) {
- synchronized (mEventWaitLock) {
- Log.d(LOGTAG, "waiting for disable event");
- try {
- mEventWaitLock.wait(RADIO_TIMEOUT);
- } catch (IllegalMonitorStateException e) {
- Log.e(LOGTAG, "Exception caught while waiting for event");
- e.printStackTrace();
- } catch (InterruptedException ex) {
- Log.e(LOGTAG, "Exception caught while waiting for event");
- ex.printStackTrace();
- }
- }
+ bStatus = waitForEvent();
}
mReceiver = null;
}
@@ -3125,14 +3127,23 @@
public void FmRxEvEnableReceiver() {
Log.d(LOGTAG, "FmRxEvEnableReceiver");
mReceiver.setRawRdsGrpMask();
+ if (mReceiver != null && mReceiver.isCherokeeChip()) {
+ synchronized(mEventWaitLock) {
+ mEventReceived = true;
+ mEventWaitLock.notify();
+ }
+ }
}
public void FmRxEvDisableReceiver()
{
Log.d(LOGTAG, "FmRxEvDisableReceiver");
mFMOn = false;
FmSharedPreferences.clearTags();
- synchronized (mEventWaitLock) {
- mEventWaitLock.notify();
+ if (mReceiver != null && mReceiver.isCherokeeChip()) {
+ synchronized (mEventWaitLock) {
+ mEventReceived = true;
+ mEventWaitLock.notify();
+ }
}
}
public void FmRxEvRadioReset()