Bug 900316 - Enable geolocation reporting for non-GSM Android devices. r=blassey r=hanno
authorChris Peterson <cpeterson@mozilla.com>
Thu, 01 Aug 2013 16:14:42 -0700
changeset 141578 6d9203ca852e5946e331e2c470bfebf87745fc5b
parent 141577 e19118c912a1cbcc31632fb7a45fb8134a149a82
child 141579 9ffbe336a432b761c09d6e0cad0bd1f3dc218fbc
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersblassey, hanno
bugs900316
milestone26.0a1
Bug 900316 - Enable geolocation reporting for non-GSM Android devices. r=blassey r=hanno
mobile/android/base/GeckoApp.java
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -2442,28 +2442,28 @@ abstract public class GeckoApp
 
         } else if (sr.SSID != null && sr.SSID.endsWith(OPTOUT_SSID_SUFFIX)) {
             return false;
         } else {
             return true;
         }
     }
 
-
     private void collectAndReportLocInfo(Location location) {
         final JSONObject locInfo = new JSONObject();
         WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE);
         wm.startScan();
         try {
             JSONArray cellInfo = new JSONArray();
-            int radioType = getCellInfo(cellInfo);
-            if (radioType == TelephonyManager.PHONE_TYPE_GSM)
-                locInfo.put("radio", "gsm");
-            else
-                return; // we don't care about other radio types for now
+
+            String radioType = getRadioTypeName(getCellInfo(cellInfo));
+            if (radioType != null) {
+                locInfo.put("radio", radioType);
+            }
+
             locInfo.put("lon", location.getLongitude());
             locInfo.put("lat", location.getLatitude());
             locInfo.put("accuracy", (int)location.getAccuracy());
             locInfo.put("altitude", (int)location.getAltitude());
             DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
             locInfo.put("time", df.format(new Date(location.getTime())));
             locInfo.put("cell", cellInfo);
 
@@ -2489,19 +2489,21 @@ abstract public class GeckoApp
                     } catch (UnsupportedEncodingException uee) {
                         Log.w(LOGTAG, "can't encode the key", uee);
                     }
                 }
             }
             locInfo.put("wifi", wifiInfo);
         } catch (JSONException jsonex) {
             Log.w(LOGTAG, "json exception", jsonex);
+            return;
         } catch (NoSuchAlgorithmException nsae) {
-            Log.w(LOGTAG, "can't creat a SHA1", nsae);
+            Log.w(LOGTAG, "can't create a SHA1", nsae);
         }
+
         ThreadUtils.postToBackgroundThread(new Runnable() {
             public void run() {
                 try {
                     URL url = new URL(LOCATION_URL);
                     HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
                     try {
                         urlConnection.setDoOutput(true);
                         JSONArray batch = new JSONArray();
@@ -2522,16 +2524,35 @@ abstract public class GeckoApp
                     }
                 } catch (IOException ioex) {
                     Log.e(LOGTAG, "error submitting data", ioex);
                 }
             }
         });
     }
 
+    private static String getRadioTypeName(int phoneType) {
+        switch (phoneType) {
+            case TelephonyManager.PHONE_TYPE_CDMA:
+                return "cdma";
+
+            case TelephonyManager.PHONE_TYPE_GSM:
+                return "gsm";
+
+            case TelephonyManager.PHONE_TYPE_NONE:
+            case TelephonyManager.PHONE_TYPE_SIP:
+                // These devices have no radio.
+                return null;
+
+            default:
+                Log.e(LOGTAG, "", new IllegalArgumentException("Unexpected PHONE_TYPE: " + phoneType));
+                return null;
+        }
+    }
+
     @Override
     public void onProviderDisabled(String provider)
     {
     }
 
     @Override
     public void onProviderEnabled(String provider)
     {