Bug 1075727 - Update rdsEnabled based on the return value of hal::EnableRDS, r=pzhang
authorMichael Wu <mwu@mozilla.com>
Wed, 01 Oct 2014 13:22:53 -0400
changeset 210376 28f02b49b5e6661398c51cb31b781060bc94c008
parent 210375 5f053be160fb41543c72b7074b48381393a30f85
child 210377 5eb54b0e4e07ecda78dd4e6d16ede7bd70f5b912
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerspzhang
bugs1075727
milestone36.0a1
Bug 1075727 - Update rdsEnabled based on the return value of hal::EnableRDS, r=pzhang
dom/fmradio/FMRadioService.cpp
--- a/dom/fmradio/FMRadioService.cpp
+++ b/dom/fmradio/FMRadioService.cpp
@@ -769,51 +769,61 @@ FMRadioService::CancelSeek(FMRadioReplyR
   aReplyRunnable->SetReply(SuccessResponse());
   NS_DispatchToMainThread(aReplyRunnable);
 }
 
 void
 FMRadioService::SetRDSGroupMask(uint32_t aRDSGroupMask)
 {
   mRDSGroupMask = aRDSGroupMask;
-  if (IsFMRadioOn()) {
-    hal::EnableRDS(mRDSGroupMask | DOM_PARSED_RDS_GROUPS);
+  if (IsFMRadioOn() && mRDSEnabled) {
+    bool enabled = hal::EnableRDS(mRDSGroupMask | DOM_PARSED_RDS_GROUPS);
+    MOZ_ASSERT(enabled);
   }
 }
 
 void
 FMRadioService::EnableRDS(FMRadioReplyRunnable* aReplyRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
   MOZ_ASSERT(aReplyRunnable);
 
+  if (IsFMRadioOn()) {
+    if (!hal::EnableRDS(mRDSGroupMask | DOM_PARSED_RDS_GROUPS)) {
+      aReplyRunnable->SetReply(
+        ErrorResponse(NS_LITERAL_STRING("Could not enable RDS")));
+      NS_DispatchToMainThread(aReplyRunnable);
+      return;
+    }
+  }
+
   mRDSEnabled = true;
-  if (IsFMRadioOn()) {
-    hal::EnableRDS(mRDSGroupMask | DOM_PARSED_RDS_GROUPS);
-  }
 
   aReplyRunnable->SetReply(SuccessResponse());
   NS_DispatchToMainThread(aReplyRunnable);
   NS_DispatchToMainThread(new NotifyRunnable(RDSEnabledChanged));
 }
 
 void
 FMRadioService::DisableRDS(FMRadioReplyRunnable* aReplyRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
   MOZ_ASSERT(aReplyRunnable);
 
-  mRDSEnabled = false;
   if (IsFMRadioOn()) {
     hal::DisableRDS();
   }
 
   aReplyRunnable->SetReply(SuccessResponse());
   NS_DispatchToMainThread(aReplyRunnable);
-  NS_DispatchToMainThread(new NotifyRunnable(RDSEnabledChanged));
+
+  if (mRDSEnabled) {
+    mRDSEnabled = false;
+    NS_DispatchToMainThread(new NotifyRunnable(RDSEnabledChanged));
+  }
 }
 
 NS_IMETHODIMP
 FMRadioService::Observe(nsISupports* aSubject,
                         const char* aTopic,
                         const char16_t* aData)
 {
   MOZ_ASSERT(NS_IsMainThread());
@@ -889,17 +899,20 @@ FMRadioService::Notify(const FMRadioOper
       mPendingFrequencyInKHz = GetFMRadioFrequency();
       UpdatePowerState();
 
       // The frequency was changed from '0' to some meaningful number, so we
       // should send the `FrequencyChanged` event manually.
       NotifyFMRadioEvent(FrequencyChanged);
 
       if (mRDSEnabled) {
-        hal::EnableRDS(mRDSGroupMask | DOM_PARSED_RDS_GROUPS);
+        mRDSEnabled = hal::EnableRDS(mRDSGroupMask | DOM_PARSED_RDS_GROUPS);
+        if (!mRDSEnabled) {
+          NotifyFMRadioEvent(RDSEnabledChanged);
+        }
       }
       break;
     case FM_RADIO_OPERATION_DISABLE:
       MOZ_ASSERT(mState == Disabling);
 
       mPISet = false;
       mPTYSet = false;
       memset(mPSName, 0, sizeof(mPSName));