diff --git a/fmapp2/src/com/caf/fmradio/FMRadio.java b/fmapp2/src/com/caf/fmradio/FMRadio.java index c36488595cacea536047d4f9bad8f41c2c74dd28..76b961c393d653ee4688c4b5f91ef2a7e89e9a86 100644 --- a/fmapp2/src/com/caf/fmradio/FMRadio.java +++ b/fmapp2/src/com/caf/fmradio/FMRadio.java @@ -493,42 +493,54 @@ public class FMRadio extends Activity @Override public void onResume() { + Log.d(LOGTAG, "FMRadio: onResume"); + super.onResume(); + if (null == mService) { + Log.e(LOGTAG, "FM Service is not running, returning"); + return; + } + + // TODO: We should return on exception or continue? try { - if(mService != null) { - mService.registerCallbacks(mServiceCallbacks); - } - }catch (RemoteException e) { - e.printStackTrace(); + mService.registerCallbacks(mServiceCallbacks); + } catch (RemoteException e) { + e.printStackTrace(); } - if(isSleepTimerActive()) { + + if (isSleepTimerActive()) { Log.d(LOGTAG, "isSleepTimerActive is true"); try { - if(null != mService) { - mService.cancelDelayedStop(FMRadioService.STOP_SERVICE); - } + mService.cancelDelayedStop(FMRadioService.STOP_SERVICE); if(null != mSleepUpdateHandlerThread) { mSleepUpdateHandlerThread.interrupt(); } - }catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); } initiateSleepThread(); } - if(isRecording()) { + + if (isRecording()) { Log.d(LOGTAG,"isRecordTimerActive is true"); try { - if (null != mService) { - mService.cancelDelayedStop(FMRadioService.STOP_RECORD); - } - }catch (Exception e) { - e.printStackTrace(); + mService.cancelDelayedStop(FMRadioService.STOP_RECORD); + } catch (Exception e) { + e.printStackTrace(); } if(isRecording()) { initiateRecordThread(); } } - Log.d(LOGTAG, "FMRadio: onResume"); + + // we might lose audio focus between pause and restart, + // hence request it again + try { + mService.requestFocus(); + } catch (Exception e) { + e.printStackTrace(); + } + mStereo = FmSharedPreferences.getLastAudioMode(); mHandler.post(mUpdateProgramService); mHandler.post(mUpdateRadioText); @@ -958,9 +970,10 @@ public class FMRadio extends Activity String action = data.getAction(); if (action != null) { if (action.equals(Settings.RESTORE_FACTORY_DEFAULT_ACTION)) { + disableRadio(); RestoreDefaults(); - enableRadioOnOffUI(); - tuneRadio(FmSharedPreferences.DEFAULT_NO_FREQUENCY); + FmSharedPreferences.setTunedFrequency(FmSharedPreferences.DEFAULT_NO_FREQUENCY); + enableRadio(); FmSharedPreferences.addStation("", FmSharedPreferences.DEFAULT_NO_FREQUENCY, 0); } } diff --git a/fmapp2/src/com/caf/fmradio/FMRadioService.java b/fmapp2/src/com/caf/fmradio/FMRadioService.java index a774f31261033bb13e9dd76171575d4b865eb03d..6f6f25755520caa5ea9748e100cf90c7c2c2f6b5 100644 --- a/fmapp2/src/com/caf/fmradio/FMRadioService.java +++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java @@ -506,7 +506,13 @@ public class FMRadioService extends Service " mA2dpConnected:" + mA2dpConnected + " isRecordSinking" + isRecordSinking() + " mIsFMDeviceLoopbackActive:" + mIsFMDeviceLoopbackActive); + if (enable) { + if (mStoppedOnFocusLoss == true) { + Log.d(LOGTAG, "FM does not have audio focus, not enabling " + + "audio path"); + return; + } // stop existing playback path before starting new one if (mA2dpConnected && mIsFMDeviceLoopbackActive) { // on BT but earlier device loopback is active