FM: Ensure scan state is kept in sync

In the middle of a scan, the user could navigate away from the activity,
during which the scan could've finished. The activity is no longer synchronized
with the service and causes issues where the dialog for scan keeps showing...etc

Fix this by syncing state in onResume

issue-id: CRACKLING-529
Change-Id: Ief3138e4d6e157ad0b060dc3aced18668959f4e1
diff --git a/fmapp2/src/com/caf/fmradio/FMRadio.java b/fmapp2/src/com/caf/fmradio/FMRadio.java
index 5358ae6..f6ed8b9 100644
--- a/fmapp2/src/com/caf/fmradio/FMRadio.java
+++ b/fmapp2/src/com/caf/fmradio/FMRadio.java
@@ -565,11 +565,25 @@
       }
    }
 
+    private void syncScanState() {
+        if (!mIsScaning || mService == null) {
+            return;
+        }
+        try {
+            if (!mService.isSearchInProgress()) {
+                resetSearch();
+            }
+        }catch (RemoteException e) {
+            e.printStackTrace();
+        }
+    }
+
    @Override
    public void onResume() {
       Log.d(LOGTAG, "FMRadio: onResume");
 
       super.onResume();
+      syncScanState();
 
       if (mService == null) {
           Log.d(LOGTAG,"bind callback has not received yet - wait for 100ms");
diff --git a/fmapp2/src/com/caf/fmradio/FMRadioService.java b/fmapp2/src/com/caf/fmradio/FMRadioService.java
index 0233a3d..12b9a0d 100644
--- a/fmapp2/src/com/caf/fmradio/FMRadioService.java
+++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java
@@ -2111,6 +2111,11 @@
          return(mService.get().isA2DPConnected());
       }
 
+      public boolean isSearchInProgress()
+      {
+         return(mService.get().isSearchInProgress());
+      }
+
       public int getExtenCountryCode()
       {
          return(mService.get().getExtenCountryCode());
@@ -2446,6 +2451,11 @@
       return(bStatus);
    }
 
+   public boolean isSearchInProgress() {
+      int state = mReceiver.getFMState();
+      return state == qcom.fmradio.FmTransceiver.FMState_Srch_InProg;
+   }
+
    public boolean isSSRInProgress() {
       return mIsSSRInProgress;
    }
diff --git a/fmapp2/src/com/caf/fmradio/IFMRadioService.aidl b/fmapp2/src/com/caf/fmradio/IFMRadioService.aidl
index 70d906e..faa9c89 100644
--- a/fmapp2/src/com/caf/fmradio/IFMRadioService.aidl
+++ b/fmapp2/src/com/caf/fmradio/IFMRadioService.aidl
@@ -75,6 +75,7 @@
     boolean isSSRInProgress();
     boolean isRtPlusSupported();
     boolean isA2DPConnected();
+    boolean isSearchInProgress();
     boolean getIntfDetLowTh();
     boolean getIntfDetHighTh();
     boolean getRxRepeatCount();