diff --git a/fmapp2/src/com/caf/fmradio/FMRadioService.java b/fmapp2/src/com/caf/fmradio/FMRadioService.java index 7c897097883c6d94f87edd87430e2894f60a04eb..2d157c675ce51382c462ba80bf1c6209f00fa1ec 100644 --- a/fmapp2/src/com/caf/fmradio/FMRadioService.java +++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java @@ -224,6 +224,7 @@ public class FMRadioService extends Service private static Object mNotchFilterLock = new Object(); private boolean mFmA2dpDisabled; + private boolean mEventReceived = false; public FMRadioService() { } @@ -2124,6 +2125,27 @@ public class FMRadioService extends Service 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 @@ public class FMRadioService extends Service 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 @@ public class FMRadioService extends Service 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 @@ public class FMRadioService extends Service // 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 class FMRadioService extends Service 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()