Bug 772750 - Get mobile connection technology from MobileConnectionService. r=garvank,echen
authorKan-Ru Chen <kanru@kanru.info>
Mon, 25 May 2015 19:27:24 +0800
changeset 268024 e41fd9a76d3e7db02c75c218c278e371a9cdf7f5
parent 268023 09185b830a3594759fb0e68ade5d455fed4cfcdf
child 268025 a727cfdf0133179aca069a5bd0a38fbfc2a44b5e
push id2294
push userbsmedberg@mozilla.com
push dateWed, 27 May 2015 15:05:10 +0000
reviewersgarvank, echen
bugs772750
milestone41.0a1
Bug 772750 - Get mobile connection technology from MobileConnectionService. r=garvank,echen
dom/system/gonk/GonkGPSGeolocationProvider.cpp
--- a/dom/system/gonk/GonkGPSGeolocationProvider.cpp
+++ b/dom/system/gonk/GonkGPSGeolocationProvider.cpp
@@ -504,45 +504,76 @@ GonkGPSGeolocationProvider::RequestSetID
       }
     }
   }
 
   NS_ConvertUTF16toUTF8 idBytes(id);
   mAGpsRilInterface->set_set_id(type, idBytes.get());
 }
 
+namespace {
+int
+ConvertToGpsRefLocationType(const nsAString& aConnectionType)
+{
+  const char* GSM_TYPES[] = { "gsm", "gprs", "edge" };
+  const char* UMTS_TYPES[] = { "umts", "hspda", "hsupa", "hspa", "hspa+" };
+
+  for (auto type: GSM_TYPES) {
+    if (aConnectionType.EqualsASCII(type)) {
+        return AGPS_REF_LOCATION_TYPE_GSM_CELLID;
+    }
+  }
+
+  for (auto type: UMTS_TYPES) {
+    if (aConnectionType.EqualsASCII(type)) {
+      return AGPS_REF_LOCATION_TYPE_UMTS_CELLID;
+    }
+  }
+
+  if (gDebug_isLoggingEnabled) {
+    nsContentUtils::LogMessageToConsole("geo: Unsupported connection type %s\n",
+                                        NS_ConvertUTF16toUTF8(aConnectionType).get());
+  }
+  return AGPS_REF_LOCATION_TYPE_GSM_CELLID;
+}
+} // anonymous namespace
+
 void
 GonkGPSGeolocationProvider::SetReferenceLocation()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (!mRadioInterface ||
       !mAGpsRilInterface) {
     return;
   }
 
   AGpsRefLocation location;
 
-  // TODO: Bug 772750 - get mobile connection technology from rilcontext
-  location.type = AGPS_REF_LOCATION_TYPE_UMTS_CELLID;
-
   nsCOMPtr<nsIMobileConnectionService> service =
     do_GetService(NS_MOBILE_CONNECTION_SERVICE_CONTRACTID);
   if (!service) {
     NS_WARNING("Cannot get MobileConnectionService");
     return;
   }
 
   nsCOMPtr<nsIMobileConnection> connection;
   service->GetItemByServiceId(mRilDataServiceId, getter_AddRefs(connection));
   NS_ENSURE_TRUE_VOID(connection);
 
   nsCOMPtr<nsIMobileConnectionInfo> voice;
   connection->GetVoice(getter_AddRefs(voice));
   if (voice) {
+    nsAutoString connectionType;
+    nsresult rv = voice->GetType(connectionType);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return;
+    }
+    location.type = ConvertToGpsRefLocationType(connectionType);
+
     nsCOMPtr<nsIMobileNetworkInfo> networkInfo;
     voice->GetNetwork(getter_AddRefs(networkInfo));
     if (networkInfo) {
       nsresult result;
       nsAutoString mcc, mnc;
 
       networkInfo->GetMcc(mcc);
       networkInfo->GetMnc(mnc);