Bug 949855 - No sound comes out when FM Radio is first time started. r=mchen
authorPin Zhang <pzhang@mozilla.com>
Wed, 18 Dec 2013 13:30:56 +0800
changeset 161045 65d1f561cce39707b1b45699946a7c94a5e2e991
parent 161044 06fed52e21b595e6eecf961ffac788e2311cbb41
child 161046 5fd559709de7c48a30450c3e0381411ebc65f6cb
push id3383
push userryanvm@gmail.com
push dateWed, 18 Dec 2013 17:37:09 +0000
treeherderb2g-inbound@65d1f561cce3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmchen
bugs949855
milestone29.0a1
Bug 949855 - No sound comes out when FM Radio is first time started. r=mchen
dom/fmradio/FMRadioService.cpp
--- a/dom/fmradio/FMRadioService.cpp
+++ b/dom/fmradio/FMRadioService.cpp
@@ -118,17 +118,16 @@ public:
   NS_IMETHOD Run()
   {
     FMRadioSettings info;
     info.upperLimit() = mUpperLimit;
     info.lowerLimit() = mLowerLimit;
     info.spaceType() = mSpaceType;
 
     EnableFMRadio(info);
-    IFMRadioService::Singleton()->EnableAudio(true);
 
     return NS_OK;
   }
 
 private:
   int32_t mUpperLimit;
   int32_t mLowerLimit;
   int32_t mSpaceType;
@@ -297,19 +296,19 @@ FMRadioService::EnableAudio(bool aAudioE
   MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
 
   nsCOMPtr<nsIAudioManager> audioManager =
     do_GetService("@mozilla.org/telephony/audiomanager;1");
   if (!audioManager) {
     return;
   }
 
-  bool AudioEnabled;
-  audioManager->GetFmRadioAudioEnabled(&AudioEnabled);
-  if (AudioEnabled != aAudioEnabled) {
+  bool audioEnabled;
+  audioManager->GetFmRadioAudioEnabled(&audioEnabled);
+  if (audioEnabled != aAudioEnabled) {
     audioManager->SetFmRadioAudioEnabled(aAudioEnabled);
   }
 }
 
 /**
  * Round the frequency to match the range of frequency and the channel width. If
  * the given frequency is out of range, return 0. For example:
  *  - lower: 87500KHz, upper: 108000KHz, channel width: 200KHz
@@ -731,16 +730,22 @@ FMRadioService::Notify(const FMRadioOper
 
       // Fire success callback on the enable request.
       TransitionState(SuccessResponse(), Enabled);
 
       // To make sure the FM app will get the right frequency after the FM
       // radio is enabled, we have to set the frequency first.
       SetFMRadioFrequency(mPendingFrequencyInKHz);
 
+      // Bug 949855: enable audio after the FM radio HW is enabled, to make sure
+      // 'hw.fm.isAnalog' could be detected as |true| during first time launch.
+      // This case is for audio output on analog path, i.e. 'ro.moz.fm.noAnalog'
+      // is not |true|.
+      EnableAudio(true);
+
       // Update the current frequency without sending the`FrequencyChanged`
       // event, to make sure the FM app will get the right frequency when the
       // `EnabledChange` event is sent.
       mPendingFrequencyInKHz = GetFMRadioFrequency();
       UpdatePowerState();
 
       // The frequency was changed from '0' to some meaningful number, so we
       // should send the `FrequencyChanged` event manually.