Fm: synchronize the FM Off and Scan cancel functionality

Issue :
When FM off is triggred from FM App during the on going
search operation it leads to update the incorrect FM state.
Due to incorrect FM state enableStereo command is sent after
FM Turned off And This causes the crash at HIDL layer.

Fix:
While disabling the FM if search operation is on going then
cancel the Search and Wait for the state to change from
Search ---> FMRxOn. Intiate the disbale commnd once FM state
is set back to On.
synchronize the FM Off and Scan cancel functionality.

CRs-Fixed: 2752868
Change-Id: I7a19bef537418d0deb001a04c8dca1e51b4b8009
diff --git a/fmapp2/src/com/caf/fmradio/FMRadioService.java b/fmapp2/src/com/caf/fmradio/FMRadioService.java
index 8d261eb..861e4aa 100644
--- a/fmapp2/src/com/caf/fmradio/FMRadioService.java
+++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java
@@ -2378,6 +2378,12 @@
       // This will disable the FM radio device
       if (mReceiver != null)
       {
+         if(mReceiver.getFMState() == mReceiver.FMState_Srch_InProg) {
+             Log.d(LOGTAG, "Cancelling the on going search operation prior to disabling FM");
+             mEventReceived = false;
+             cancelSearch();
+             waitForEvent();
+         }
          mEventReceived = false;
          bStatus = mReceiver.disable(this);
          if (bStatus &&
@@ -3381,6 +3387,10 @@
             {
                mCallbacks.onSearchComplete();
             }
+            synchronized (mEventWaitLock) {
+               mEventReceived = true;
+               mEventWaitLock.notify();
+            }
             /* Update the frequency in the StatusBar's Notification */
             startNotification();
          }