Bug 1159267: Share Bluedroid's HFP manager between Bluetooth v1 and v2, r=btian
authorThomas Zimmermann <tdz@users.sourceforge.net>
Wed, 06 May 2015 09:58:04 +0200
changeset 273894 3698cc94f038209804463850c6e273ce2046df8c
parent 273893 e0b4026e42f6fce516e612b7e8b1d6f40c30f18c
child 273895 45ae8fa4b2e65ce896e65955782d12b6b394bf82
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbtian
bugs1159267
milestone40.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1159267: Share Bluedroid's HFP manager between Bluetooth v1 and v2, r=btian The implementation of the Bluedroid HFP manager in Bluetoth v1 and v2 differs by a number of interface changes. This patch merges both variants into a single one, were possible.
dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp
dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.h
--- a/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp
+++ b/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp
@@ -203,37 +203,16 @@ BluetoothHfpManager::ResetCallArray()
   Call call;
   mCurrentCallArray.AppendElement(call);
 
   if (mPhoneType == PhoneType::CDMA) {
     mCdmaSecondCall.Reset();
   }
 }
 
-#ifdef MOZ_B2G_BT_API_V2
-void
-BluetoothHfpManager::Reset()
-{
-  mReceiveVgsFlag = false;
-  mDialingRequestProcessed = true;
-
-  mConnectionState = HFP_CONNECTION_STATE_DISCONNECTED;
-  mPrevConnectionState = HFP_CONNECTION_STATE_DISCONNECTED;
-  mAudioState = HFP_AUDIO_STATE_DISCONNECTED;
-
-  // Phone & Device CIND
-  ResetCallArray();
-  mBattChg = 5;
-  mService = HFP_NETWORK_STATE_NOT_AVAILABLE;
-  mRoam = HFP_SERVICE_TYPE_HOME;
-  mSignal = 0;
-
-  mController = nullptr;
-}
-#else
 void
 BluetoothHfpManager::Cleanup()
 {
   mReceiveVgsFlag = false;
   mDialingRequestProcessed = true;
 
   mConnectionState = HFP_CONNECTION_STATE_DISCONNECTED;
   mPrevConnectionState = HFP_CONNECTION_STATE_DISCONNECTED;
@@ -250,27 +229,22 @@ BluetoothHfpManager::Reset()
 {
   mFirstCKPD = false;
   // Phone & Device CIND
   ResetCallArray();
   // Clear Sco state
   mAudioState = HFP_AUDIO_STATE_DISCONNECTED;
   Cleanup();
 }
-#endif
 
 bool
 BluetoothHfpManager::Init()
 {
-#ifdef MOZ_B2G_BT_API_V2
   // The function must run at b2g process since it would access SettingsService.
   MOZ_ASSERT(IsMainProcess());
-#else
-  // Missing on bluetooth1
-#endif
 
   MOZ_ASSERT(NS_IsMainThread());
 
   nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
   NS_ENSURE_TRUE(obs, false);
 
   if (NS_FAILED(obs->AddObserver(this, MOZSETTINGS_CHANGED_ID, false)) ||
       NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) {
@@ -619,21 +593,17 @@ BluetoothHfpManager::NotifyConnectionSta
         // Bug 979160: This implies the outgoing connection failure.
         // When the outgoing hfp connection fails, state changes to disconnected
         // state. Since bluedroid would not report connecting state, but only
         // report connected/disconnected.
         OnConnect(NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
       } else {
         OnDisconnect(EmptyString());
       }
-#ifdef MOZ_B2G_BT_API_V2
-      Reset();
-#else
       Cleanup();
-#endif
     }
   }
 }
 
 void
 BluetoothHfpManager::NotifyDialer(const nsAString& aCommand)
 {
   NS_NAMED_LITERAL_STRING(type, "bluetooth-dialer-command");
@@ -714,34 +684,24 @@ BluetoothHfpManager::HandleVoiceConnecti
   bool roaming;
   voiceInfo->GetRoaming(&roaming);
   mRoam = (roaming) ? HFP_SERVICE_TYPE_ROAMING : HFP_SERVICE_TYPE_HOME;
 
   // Service
   nsString regState;
   voiceInfo->GetState(regState);
 
-#ifdef MOZ_B2G_BT_API_V2
   BluetoothHandsfreeNetworkState service =
     (regState.EqualsLiteral("registered")) ? HFP_NETWORK_STATE_AVAILABLE :
                                              HFP_NETWORK_STATE_NOT_AVAILABLE;
   if (service != mService) {
     // Notify BluetoothRilListener of service change
     mListener->ServiceChanged(aClientId, service);
   }
   mService = service;
-#else
-  int service = (regState.EqualsLiteral("registered")) ? 1 : 0;
-  if (service != mService) {
-    // Notify BluetoothRilListener of service change
-    mListener->ServiceChanged(aClientId, service);
-  }
-  mService = service ? HFP_NETWORK_STATE_AVAILABLE :
-                       HFP_NETWORK_STATE_NOT_AVAILABLE;
-#endif
 
   // Signal
   JS::Rooted<JS::Value> value(nsContentUtils::RootingCxForThread());
   voiceInfo->GetRelSignalStrength(&value);
   NS_ENSURE_TRUE_VOID(value.isNumber());
   mSignal = (int)ceil(value.toNumber() / 20.0);
 
   UpdateDeviceCIND();
--- a/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.h
+++ b/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.h
@@ -167,21 +167,17 @@ private:
   friend class GetVolumeTask;
   friend class CloseScoTask;
   friend class RespondToBLDNTask;
   friend class MainThreadTask;
 
   BluetoothHfpManager();
   bool Init();
 
-#ifdef MOZ_B2G_BT_API_V2
-  // Removed in bluetooth2
-#else
   void Cleanup();
-#endif
 
   void HandleShutdown();
   void HandleVolumeChanged(nsISupports* aSubject);
   void Notify(const hal::BatteryInformation& aBatteryInfo);
 
   void NotifyConnectionStateChanged(const nsAString& aType);
   void NotifyDialer(const nsAString& aCommand);