FM: FMRadio will wait for the focus from telecom repeatedly

Whenever call is getting ended, FM requests Audio Focus
before Telecom abandons it, There is delay for about 50ms.
Now, with this change FMRadio will wait for 300 ms to get the
focus back from the telecom.

Generally, both FM and Playing Tone for call end are dependent on
call state changed, so the progress of receiving is in parallel.
But due FM gets callback via remote calling, it is always slower
than Telecom. Currently for N, the audio_focus_release had been
moved into state machine (in work thread), so the issue becomes
easy to see.

We cannot serial the call_status_change and the audio_focus_release.
Because Telecom also need to wait DISCONNECTED to paly tone, after
completed to abandon it.
So need FM needs to handle it by waiting for some more time.

CRs-fixed: 1061550
Change-Id: I7676b6816d5c89934bf2360811ea0b1bb2fb850b
diff --git a/fmapp2/src/com/caf/fmradio/FMRadioService.java b/fmapp2/src/com/caf/fmradio/FMRadioService.java
index a095d11..9546cd3 100644
--- a/fmapp2/src/com/caf/fmradio/FMRadioService.java
+++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java
@@ -1441,6 +1441,7 @@
    //any. Similarly once call is ended FM should be unmuted.
        AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        mCallStatus = state;
+       int granted = AudioManager.AUDIOFOCUS_REQUEST_FAILED, count = 0;
 
        if((TelephonyManager.CALL_STATE_OFFHOOK == state)||
           (TelephonyManager.CALL_STATE_RINGING == state)) {
@@ -1475,9 +1476,21 @@
               if (isAntennaAvailable() && (!isFmOn()) && mServiceInUse)
               {
                    Log.d(LOGTAG, "Resuming after call:");
+                   do {
+                       granted = audioManager.requestAudioFocus(mAudioFocusListener,
+                               AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
+                       ++count;
+                       try {
+                           Thread.sleep(100);
+                       } catch (Exception ex) {
+                           Log.d( LOGTAG, "InterruptedException");
+                       }
+                   } while(granted != AudioManager.AUDIOFOCUS_REQUEST_GRANTED && count != 3);
+
                    if(true != fmOn()) {
                        return;
                    }
+
                    mResumeAfterCall = false;
                    if(mCallbacks != null) {
                       try {