From 9a2f237246a743e5cec0eabe7d0027721aa97b2f Mon Sep 17 00:00:00 2001 From: Smriti Gupta <smritig@codeaurora.org> Date: Wed, 31 Aug 2016 13:40:24 +0530 Subject: [PATCH] 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 --- fmapp2/src/com/caf/fmradio/FMRadioService.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 @@ public class FMRadioService extends Service //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 @@ public class FMRadioService extends Service 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 { -- GitLab