author | Chris Peterson <cpeterson@mozilla.com> |
Thu, 06 Feb 2014 20:25:35 -0800 | |
changeset 184955 | 41b171702ded1b0d99fd0d569ee636bfbf8e4151 |
parent 184954 | 2e9aacb1d0d117cbea6a5841f4439267ff34e78e |
child 184956 | 7133bb431ebaab7171d7937df79d3ca9f8c47dc9 |
push id | 3503 |
push user | raliiev@mozilla.com |
push date | Mon, 28 Apr 2014 18:51:11 +0000 |
treeherder | mozilla-beta@c95ac01e332e [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | blassey |
bugs | 950237 |
milestone | 30.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
|
--- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -107,18 +107,16 @@ import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URL; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -213,17 +211,17 @@ public abstract class GeckoApp private Telemetry.Timer mGeckoReadyStartupTimer; private String mPrivateBrowsingSession; private volatile HealthRecorder mHealthRecorder = null; private int mSignalStrenth; private PhoneStateListener mPhoneStateListener = null; - private boolean mShouldReportGeoData = false; + private boolean mShouldReportGeoData; abstract public int getLayout(); abstract public boolean hasTabsSideBar(); abstract protected String getDefaultProfileName(); private static final String RESTARTER_ACTION = "org.mozilla.gecko.restart"; private static final String RESTARTER_CLASS = "org.mozilla.gecko.Restarter"; @@ -2431,101 +2429,84 @@ public abstract class GeckoApp obj.put("asu", nci.getRssi()); cellInfo.put(obj); } catch(JSONException jsonex) {} } } return tm.getPhoneType(); } - - // copied from http://code.google.com/p/sensor-data-collection-library/source/browse/src/main/java/TextFileSensorLog.java#223, - // which is apache licensed - private static final Set<Character> AD_HOC_HEX_VALUES = - new HashSet<Character>(Arrays.asList('2','6', 'a', 'e', 'A', 'E')); - private static final String OPTOUT_SSID_SUFFIX = "_nomap"; - private static boolean shouldLog(final ScanResult sr) { - // We filter out any ad-hoc devices. Ad-hoc devices are identified by having a - // 2,6,a or e in the second nybble. - // See http://en.wikipedia.org/wiki/MAC_address -- ad hoc networks - // have the last two bits of the second nybble set to 10. - // Only apply this test if we have exactly 17 character long BSSID which should - // be the case. - final char secondNybble = sr.BSSID.length() == 17 ? sr.BSSID.charAt(1) : ' '; - - if(AD_HOC_HEX_VALUES.contains(secondNybble)) { - return false; - - } else if (sr.SSID != null && sr.SSID.endsWith(OPTOUT_SSID_SUFFIX)) { - return false; - } else { - return true; - } + return sr.SSID == null || !sr.SSID.endsWith("_nomap"); } private void collectAndReportLocInfo(Location location) { final JSONObject locInfo = new JSONObject(); WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE); wm.startScan(); try { JSONArray cellInfo = new JSONArray(); 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'"); + + // If we have an accuracy, round it up to the next meter. + if (location.hasAccuracy()) { + locInfo.put("accuracy", (int) Math.ceil(location.getAccuracy())); + } + + // If we have an altitude, round it to the nearest meter. + if (location.hasAltitude()) { + locInfo.put("altitude", Math.round(location.getAltitude())); + } + + // Reduce timestamp precision so as to expose less PII. + DateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.US); locInfo.put("time", df.format(new Date(location.getTime()))); locInfo.put("cell", cellInfo); - MessageDigest digest = MessageDigest.getInstance("SHA-1"); - JSONArray wifiInfo = new JSONArray(); List<ScanResult> aps = wm.getScanResults(); if (aps != null) { for (ScanResult ap : aps) { if (!shouldLog(ap)) continue; - StringBuilder sb = new StringBuilder(); - try { - byte[] result = digest.digest((ap.BSSID + ap.SSID).getBytes("UTF-8")); - for (byte b : result) sb.append(String.format("%02X", b)); - - JSONObject obj = new JSONObject(); - - obj.put("key", sb.toString()); - obj.put("frequency", ap.frequency); - obj.put("signal", ap.level); - wifiInfo.put(obj); - } catch (UnsupportedEncodingException uee) { - Log.w(LOGTAG, "can't encode the key", uee); - } + + JSONObject obj = new JSONObject(); + obj.put("key", ap.BSSID); + obj.put("frequency", ap.frequency); + obj.put("signal", ap.level); + wifiInfo.put(obj); } } locInfo.put("wifi", wifiInfo); } catch (JSONException jsonex) { Log.w(LOGTAG, "json exception", jsonex); return; - } catch (NoSuchAlgorithmException 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); + + // Workaround for a bug in Android HttpURLConnection. When the library + // reuses a stale connection, the connection may fail with an EOFException. + if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT <= 18) { + urlConnection.setRequestProperty("Connection", "Close"); + } + JSONArray batch = new JSONArray(); batch.put(locInfo); JSONObject wrapper = new JSONObject(); wrapper.put("items", batch); byte[] bytes = wrapper.toString().getBytes(); urlConnection.setFixedLengthStreamingMode(bytes.length); OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream()); out.write(bytes);